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 expect = [4, '', 'upload.timeout', 'upload.loadend', 'timeout', 'loadend'];
9 : 1 : let actual = [];
10 : 1 :
11 [ + ]: 1 : xhr.onreadystatechange = () => {
12 [ + ]: 2 : if(xhr.readyState === 4) {
13 : 1 : actual.push(xhr.readyState, xhr.response);
14 : 1 : }
15 : 1 : };
16 : 1 :
17 [ + ]: 1 : xhr.onloadend = (e) => {
18 : 1 : assert.strictEqual(e.loaded, 0);
19 : 1 : assert.strictEqual(e.total, 0);
20 : 1 :
21 : 1 : actual.push(e.type);
22 : 1 :
23 : 1 : assert.deepStrictEqual(actual, expect);
24 : 1 : };
25 : 1 :
26 [ + ]: 1 : xhr.ontimeout = (e) => {
27 : 1 : assert.strictEqual(e.loaded, 0);
28 : 1 : assert.strictEqual(e.total, 0);
29 : 1 :
30 : 1 : actual.push(e.type);
31 : 1 : };
32 : 1 :
33 [ + ]: 1 : xhr.upload.onloadend = (e) => {
34 : 1 : assert.strictEqual(e.loaded, 0);
35 : 1 : assert.strictEqual(e.total, 0);
36 : 1 :
37 : 1 : actual.push('upload.' + e.type);
38 : 1 : };
39 : 1 :
40 [ + ]: 1 : xhr.upload.ontimeout = (e) => {
41 : 1 : assert.strictEqual(e.loaded, 0);
42 : 1 : assert.strictEqual(e.total, 0);
43 : 1 :
44 : 1 : actual.push('upload.' + e.type);
45 : 1 : };
46 : 1 :
47 : 1 : let content = '';
48 [ + ]: 1 : for (let i = 0; i < 121026; i++) {
49 : 121026 : content += '[' + i + ']';
50 : 121026 : }
51 : 1 :
52 : 1 : xhr.open('POST', `${activeURL}/trickle.py`);
53 : 1 :
54 : 1 : xhr.timeout = 1;
55 : 1 : xhr.send(content);
56 : 1 : }
57 : 1 :
58 : 1 : /*
59 : 1 : * send-timeout-events.htm
60 : 1 : *
61 : 1 :
62 : 1 : <!DOCTYPE html>
63 : 1 : <html>
64 : 1 : <head>
65 : 1 : <script src="/resources/testharness.js"></script>
66 : 1 : <script src="/resources/testharnessreport.js"></script>
67 : 1 : <title>XMLHttpRequest: The send() method: timeout is not 0 </title>
68 : 1 : </head>
69 : 1 :
70 : 1 : <body>
71 : 1 : <div id="log"></div>
72 : 1 :
73 : 1 : <script type="text/javascript">
74 : 1 : async_test(t => {
75 : 1 : const xhr = new XMLHttpRequest(),
76 : 1 : expect = [4, "", "upload.timeout", "upload.loadend", "timeout", "loadend"];
77 : 1 : let actual = [];
78 : 1 :
79 : 1 : xhr.onreadystatechange = t.step_func(() => {
80 : 1 : if (xhr.readyState == 4) {
81 : 1 : actual.push(xhr.readyState, xhr.response);
82 : 1 : }
83 : 1 : });
84 : 1 :
85 : 1 : xhr.onloadend = t.step_func_done(e => {
86 : 1 : assert_equals(e.loaded, 0);
87 : 1 : assert_equals(e.total, 0);
88 : 1 : actual.push(e.type);
89 : 1 : assert_array_equals(actual, expect);
90 : 1 : });
91 : 1 :
92 : 1 : xhr.ontimeout = t.step_func(e => {
93 : 1 : assert_equals(e.loaded, 0);
94 : 1 : assert_equals(e.total, 0);
95 : 1 : actual.push(e.type);
96 : 1 : });
97 : 1 :
98 : 1 : xhr.upload.onloadend = t.step_func(e => {
99 : 1 : assert_equals(e.loaded, 0);
100 : 1 : assert_equals(e.total, 0);
101 : 1 : actual.push("upload." + e.type);
102 : 1 : });
103 : 1 :
104 : 1 : xhr.upload.ontimeout = t.step_func(e => {
105 : 1 : assert_equals(e.loaded, 0);
106 : 1 : assert_equals(e.total, 0);
107 : 1 : actual.push("upload." + e.type);
108 : 1 : });
109 : 1 :
110 : 1 : let content = "";
111 : 1 : for (var i = 0; i < 121026; i++) {
112 : 1 : content += "[" + i + "]";
113 : 1 : }
114 : 1 :
115 : 1 : xhr.open("POST", "./resources/trickle.py", true);
116 : 1 : xhr.timeout = 1;
117 : 1 : xhr.send(content);
118 : 1 : });
119 : 1 : </script>
120 : 1 : </body>
121 : 1 : </html>
122 : 1 :
123 : 1 : *
124 : 1 : * send-timeout-events.htm
125 : 1 : */
|