summaryrefslogtreecommitdiffstats
path: root/testing/web-platform/tests/XMLHttpRequest/response-invalid-responsetype.htm
blob: 603c4cd0ed77f41172a1f80a731ba4584fa6456a (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
<!doctype html>
<html>
  <head>
    <title>XMLHttpRequest: response is plain text if responseType is set to an invalid string</title>
    <script src="/resources/testharness.js"></script>
    <script src="/resources/testharnessreport.js"></script>
    <link rel="help" href="https://xhr.spec.whatwg.org/#the-response-attribute" data-tested-assertations="following::dd[2]/ol[1]/li[2]" />
    <link rel="help" href="https://xhr.spec.whatwg.org/#the-responsetype-attribute" data-tested-assertations="following::ol[1]/li[4]" /><!-- Not quite - but this is handled in WebIDL, not the XHR spec -->
  </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
          assert_equals(client.responseType, '')
          client.open("GET", "resources/folder.txt", true)
          client.onload = function(){
            test.step(function(){
                assert_equals(client.responseType, '')
                assert_equals(client.response, 'bottom\n')
                assert_equals(typeof client.response, 'string')
                test.done()
            })
          }
          client.send(null)
        })
      }
      request("arrayBuffer") // case sensitive
      request("JSON") // case sensitive
      request("glob")
      request("txt")
      request("text/html")
    </script>
  </body>
</html>