https://github.com/web-platform-tests/wpt
Raw File
Tip revision: 42f30b2f712820a5aa481a0f9b61f24516cece77 authored by plehegar on 19 June 2016, 18:35:55 UTC
Avoid the charset warning
Tip revision: 42f30b2
overridemimetype-open-state-force-xml.htm
<!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>
back to top