[XHR] overrideMimeType() should be able to change encoding in HEADERS RECEIVED state
[WebKit-https.git] / LayoutTests / http / tests / xmlhttprequest / overridemimetype-headers-received-state-force-shiftjis.html
1 <!doctype html>
2 <html>
3   <head>
4     <title>XMLHttpRequest: overrideMimeType() in HEADERS RECEIVED state, enforcing Shift-JIS encoding</title>
5     <meta charset="utf-8">
6     <script src="/js-test-resources/testharness.js"></script>
7     <script src="/js-test-resources/testharnessreport.js"></script>
8     <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]" />
9     <!-- similar to http://w3c-test.org/XMLHttpRequest/overridemimetype-headers-received-state-force-shiftjis.htm -->
10   </head>
11   <body>
12     <div id="log"></div>
13     <script>
14       var test = async_test();
15       var client = new XMLHttpRequest();
16       var readyState2Reached = false;
17       client.onreadystatechange = test.step_func( function() {
18         if(client.readyState===2){
19           readyState2Reached = true;
20           try{
21             client.overrideMimeType('text/plain;charset=Shift-JIS');
22           }catch(e){
23             assert_unreached('overrideMimeType should not throw in state 2');
24           }
25         }
26         if (client.readyState !== 4) return;
27         assert_equals( readyState2Reached, true, "readyState = 2 event fired" );
28         assert_equals( client.responseText, 'ใƒ†ใ‚นใƒˆ', 'overrideMimeType() in HEADERS RECEIVED state set encoding' );
29         test.done();
30       });
31       client.open("GET", "resources/get-content.php?type="+encodeURIComponent('text/html;charset=UTF-8')+'&content=%83%65%83%58%83%67');
32       client.send( '' );
33     </script>
34   </body>
35 </html>