Sync web-platform-tests up to revision a5b95cb31914507088a4eda16f7674bbc6f3313f
[WebKit-https.git] / LayoutTests / imported / w3c / web-platform-tests / XMLHttpRequest / loadstart-and-state.html
1 <!doctype html>
2 <title>XMLHttpRequest: loadstart event corner cases</title>
3 <script src=/resources/testharness.js></script>
4 <script src=/resources/testharnessreport.js></script>
5 <div id=log></div>
6 <script>
7 async_test(t => {
8   const client = new XMLHttpRequest
9   client.onloadstart = t.step_func(() => {
10     assert_throws("InvalidStateError", () => client.setRequestHeader("General", "Organa"))
11     assert_throws("InvalidStateError", () => client.withCredentials = true)
12     assert_throws("InvalidStateError", () => client.send())
13     client.onloadstart = null
14     client.open("GET", "data:,BB-8")
15     client.send()
16   })
17   client.onload = t.step_func_done(() => {
18     assert_equals(client.responseText, "BB-8")
19   })
20   client.open("GET", "data:,R2-D2")
21   client.send()
22 }, "open() during loadstart")
23
24 async_test(t => {
25   const client = new XMLHttpRequest
26   let abortFired = false
27   client.onloadstart = t.step_func_done(() => {
28     assert_equals(client.readyState, 1)
29     client.abort()
30     assert_true(abortFired)
31     assert_equals(client.readyState, 0)
32   })
33   client.onabort = t.step_func(() => {
34     abortFired = true
35     assert_equals(client.readyState, 4)
36   })
37   client.open("GET", "data:,K-2SO")
38   client.send()
39 }, "abort() during loadstart")
40 </script>