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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
|
<!DOCTYPE HTML>
<html>
<head>
<meta charset="utf-8">
<title>Test for sync XHR into sync XHRs</title>
<script src="/tests/SimpleTest/SimpleTest.js"></script>
<link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css"/>
</head>
<body>
<script type="application/javascript">
let xhr = new XMLHttpRequest();
let testCompleted = false;
let frame = document.createElement('frame');
frame.addEventListener('load', function() {
if (testCompleted) {
return;
}
try {
xhr.responseType = "blob";
ok(false, "xhr.responseType cannot be settable");
} catch(e) {
ok(true, "xhr.responseType cannot be settable");
}
try {
xhr.abort();
ok(false, "xhr.abort should throw");
} catch(e) {
ok(true, "xhr.abort should throw");
}
try {
xhr.getAllResponseHeaders();
ok(false, "xhr.getAllResponseHeaders should throw");
} catch(e) {
ok(true, "xhr.getAllResponseHeaders should throw");
}
try {
xhr.getResponseHeader("foo");
ok(false, "xhr.getResponseHeader should throw");
} catch(e) {
ok(true, "xhr.getResponseHeader should throw");
}
try {
xhr.open('POST', location, false);
ok(false, "xhr.open should throw");
} catch(e) {
ok(true, "xhr.open should throw");
}
try {
xhr.send();
ok(false, "xhr.send should throw");
} catch(e) {
ok(true, "xhr.send should throw");
}
try {
xhr.timeout = 42;
ok(false, "xhr.timeout cannot be settable");
} catch(e) {
ok(true, "xhr.timeout cannot be settable");
}
try {
xhr.withCredentials = false;
ok(false, "xhr.withCredentials cannot be settable");
} catch(e) {
ok(true, "xhr.withCredentials cannot be settable");
}
try {
xhr.overrideMimeType("wow")
ok(false, "xhr.overrideMimeType should throw");
} catch(e) {
ok(true, "xhr.overrideMimeType should throw");
}
}, { once: true });
// This test is racy because we try to check that the loading of the frame
// happens during a sync XHR. If the loading happens after, we still need to
// consider the test passed.
ok(xhr, "We have an XHR.");
document.documentElement.appendChild(frame);
xhr.open('POST', location, false);
xhr.send('X');
// Nothing can guarantee that the frame is loaded during the sync XHR.
testCompleted = true;
frame.remove();
</script>
</body>
</html>
|