<!doctype html>
<html>
  <head>
    <title>XMLHttpRequest: overrideMimeType() in HEADERS RECEIVED state, enforcing Shift-JIS encoding</title>
    <meta charset="utf-8">
    <script src="/js-test-resources/testharness.js"></script>
    <script src="/js-test-resources/testharnessreport.js"></script>
    <link rel="help" href="http://dvcs.w3.org/hg/xhr/raw-file/tip/Overview.html#the-overridemimetype()-method" data-tested-assertations="/following::ol/li[1] /following::ol/li[4]" />
    <!-- similar to http://w3c-test.org/XMLHttpRequest/overridemimetype-headers-received-state-force-shiftjis.htm -->
  </head>
  <body>
    <div id="log"></div>
    <script>
      var test = async_test();
      var client = new XMLHttpRequest();
      var readyState2Reached = false;
      client.onreadystatechange = test.step_func( function() {
        if(client.readyState===2){
          readyState2Reached = true;
          try{
            client.overrideMimeType('text/plain;charset=Shift-JIS');
          }catch(e){
            assert_unreached('overrideMimeType should not throw in state 2');
          }
        }
        if (client.readyState !== 4) return;
        assert_equals( readyState2Reached, true, "readyState = 2 event fired" );
        assert_equals( client.responseText, 'テスト', 'overrideMimeType() in HEADERS RECEIVED state set encoding' );
        test.done();
      });
      client.open("GET", "resources/get-content.py?type="+encodeURIComponent('text/html;charset=UTF-8')+'&content=%83%65%83%58%83%67');
      client.send( '' );
    </script>
  </body>
</html>
