Branch data Line data Source code
1 [ + ]: 1 : import assert from 'node:assert/strict';
2 : 1 : import { XMLHttpRequest } from '../../../lib/whatwg-xhr.js';
3 : 1 :
4 [ + ]: 1 : export default (activeURL) => {
5 : 1 :
6 : 1 : let xhr = new XMLHttpRequest();
7 : 1 :
8 : 1 : let expected = ['a1', 'b1', 'c1', 'a2', 'b2', 'c2', 'a3', 'c3', 'a4', 'c4'];
9 : 1 : let result = [];
10 : 1 :
11 [ + ]: 1 : xhr.onreadystatechange = () => {
12 : 4 : result.push('a' + xhr.readyState);
13 : 1 : };
14 : 1 :
15 : 1 : let callback;
16 : 1 :
17 [ + ]: 1 : xhr.addEventListener('readystatechange', callback = () => {
18 : 2 : result.push('b' + xhr.readyState)
19 : 2 :
20 : 2 : if(xhr.readyState === xhr.LOADING)
21 [ - ]: 2 : assert(false);
22 : 1 : });
23 : 1 :
24 [ + ]: 1 : xhr.addEventListener('readystatechange', () => {
25 : 4 : result.push('c' + xhr.readyState);
26 : 4 :
27 : 4 : if(xhr.readyState === xhr.HEADERS_RECEIVED)
28 [ + ]: 4 : xhr.removeEventListener('readystatechange', callback);
29 : 4 :
30 : 4 : if(xhr.readyState === xhr.DONE)
31 [ + ]: 4 : assert.deepStrictEqual(result, expected);
32 : 1 : });
33 : 1 :
34 : 1 : xhr.open('GET', `${activeURL.replace('/resources', '') + '/folder.txt'}`);
35 : 1 : xhr.send();
36 : 1 : }
37 : 1 :
38 : 1 : /*
39 : 1 : * xmlhttprequest-eventtarget.htm
40 : 1 : *
41 : 1 :
42 : 1 : <!doctype html>
43 : 1 : <html>
44 : 1 : <head>
45 : 1 : <title>XMLHttpRequest: implements EventTarget</title>
46 : 1 : <script src="/resources/testharness.js"></script>
47 : 1 : <script src="/resources/testharnessreport.js"></script>
48 : 1 : <link rel="help" href="https://xhr.spec.whatwg.org/#xmlhttprequesteventtarget" data-tested-assertations=".." />
49 : 1 : <!-- Obviously, most of the stuff actually being tested here is covered in the DOM events spec, not in the XHR spec -->
50 : 1 : </head>
51 : 1 : <body>
52 : 1 : <div id="log"></div>
53 : 1 : <script>
54 : 1 : var test = async_test(),
55 : 1 : x = null,
56 : 1 : expected = ["a1", "b1", "c1", "a2", "b2", "c2", "a3", "c3", "a4", "c4"],
57 : 1 : result = []
58 : 1 : function callback(e) {
59 : 1 : result.push("b" + x.readyState)
60 : 1 : test.step(function() {
61 : 1 : if(x.readyState == 3)
62 : 1 : assert_unreached()
63 : 1 : })
64 : 1 : }
65 : 1 : test.step(function() {
66 : 1 : x = new XMLHttpRequest()
67 : 1 : x.onreadystatechange = function() {
68 : 1 : test.step(function() {
69 : 1 : result.push("a" + x.readyState)
70 : 1 : })
71 : 1 : }
72 : 1 : x.addEventListener("readystatechange", callback, false)
73 : 1 : x.addEventListener("readystatechange", function() {
74 : 1 : test.step(function() {
75 : 1 : result.push("c" + x.readyState)
76 : 1 : if(x.readyState == 2)
77 : 1 : x.removeEventListener("readystatechange", callback, false)
78 : 1 : if(x.readyState == 4) {
79 : 1 : assert_array_equals(result, expected)
80 : 1 : test.done()
81 : 1 : }
82 : 1 : })
83 : 1 : }, false)
84 : 1 : x.open("GET", "folder.txt")
85 : 1 : x.send(null)
86 : 1 : })
87 : 1 : </script>
88 : 1 : </body>
89 : 1 : </html>
90 : 1 :
91 : 1 : *
92 : 1 : * xmlhttprequest-eventtarget.htm
93 : 1 : */
|