summaryrefslogtreecommitdiffstats
path: root/testing/web-platform/tests/xhr/overridemimetype-open-state-force-xml.htm
blob: 00a4c0dd43de1f618208818d56b812b34757fc40 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
<!doctype html>
<html>
  <head>
    <title>XMLHttpRequest: overrideMimeType() in open state, XML MIME type with UTF-8 charset</title>
    <meta charset="utf-8">
    <script src="/resources/testharness.js"></script>
    <script src="/resources/testharnessreport.js"></script>
    <link rel="help" href="https://xhr.spec.whatwg.org/#the-overridemimetype()-method" data-tested-assertations="/following::ol/li[3] /following::ol/li[4]" />
  </head>
  <body>
    <div id="log"></div>
    <script>
      var test = async_test();
      test.step(function() {
        var client = new XMLHttpRequest();
        client.onreadystatechange = function() {
          if (client.readyState !== 4) return;
          try{
            var str = client.responseXML.documentElement.tagName+client.responseXML.documentElement.firstChild.tagName+client.responseXML.documentElement.firstChild.textContent;
          }catch(e){
            assert_unreached('Exception when reading responseXML');
          }
          assert_equals( client.responseXML.documentElement.tagName,  'test' );
          assert_equals( client.responseXML.documentElement.firstChild.tagName,  'message' );
          assert_equals( client.responseXML.documentElement.firstChild.textContent,  'Hello World!' );
          test.done();
        };
        client.open("GET", "resources/status.py?type="+encodeURIComponent('text/plain;charset=Shift-JIS')+'&content='+encodeURIComponent('<test><message>Hello World!</message></test>'));
        client.overrideMimeType('application/xml;charset=UTF-8');
        client.send();
      });
    </script>
  </body>
</html>