summaryrefslogtreecommitdiffstats
path: root/testing/web-platform/tests/XMLHttpRequest/responsexml-non-document-types.htm
blob: 84d90a8d35ae1d3da3494cd2681ed1ef8b7debc6 (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
35
36
37
38
39
40
41
42
43
44
45
<!doctype html>
<html>
  <head>
    <title>XMLHttpRequest: responseXML/responseText on other responseType</title>
    <script src="/resources/testharness.js"></script>
    <script src="/resources/testharnessreport.js"></script>
    <link rel="help" href="https://xhr.spec.whatwg.org/#the-responsexml-attribute" data-tested-assertations="following::ol[1]/li[1]" />
    <link rel="help" href="https://xhr.spec.whatwg.org/#the-responsetext-attribute" data-tested-assertations="following::ol[1]/li[1]" />
    <link rel="help" href="https://xhr.spec.whatwg.org/#the-responsetype-attribute" data-tested-assertations="following::ol[1]/li[4]" />
  </head>
  <body>
    <div id="log"></div>
    <script>
      function request(type) {
        var test = async_test(document.title+' ('+type+')')
        test.step(function() {
          var client = new XMLHttpRequest()
          client.responseType = type
          client.open("GET", "resources/well-formed.xml", true)
          client.onload = function(){
            test.step(function(){
                if(type !== 'document'){
                  assert_throws("InvalidStateError", function() {
                    var x = client.responseXML;
                  }, 'responseXML throw for '+type)
                }
                if(type !== 'text'){
                  assert_throws("InvalidStateError", function() {
                    var x = client.responseText;
                  }, 'responseText throws for '+type)
                }
                test.done()
            })
          }
          client.send(null)
        })
      }
      request("arraybuffer")
      request("blob")
      request("json")
      request("text")
      request("document")
    </script>
  </body>
</html>