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
102
103
104
105
106
107
108
|
<script>
function ok(a, msg) {
parent.postMessage({ type: "check", status: !!a, message: msg }, "*");
}
function is(a, b, msg) {
ok(a === b, msg);
}
function testWebIDL() {
ok("FetchController" in self, "We have a FetchController prototype");
ok("FetchSignal" in self, "We have a FetchSignal prototype");
var fc = new FetchController();
ok(!!fc, "FetchController can be created");
ok(fc instanceof FetchController, "FetchController is a FetchController");
ok(!!fc.signal, "FetchController has a signal");
ok(fc.signal instanceof FetchSignal, "fetchSignal is a FetchSignal");
is(fc.signal.aborted, false, "By default FetchSignal.aborted is false");
next();
}
function testUpdateData() {
var fc = new FetchController();
is(fc.signal.aborted, false, "By default FetchSignal.aborted is false");
fc.abort();
is(fc.signal.aborted, true, "Signal is aborted");
next();
}
function testFollowingOurself() {
// Let's follow ourself
var fc = new FetchController();
fc.follow(fc.signal);
fc.abort();
is(fc.signal.aborted, true, "Signal is aborted");
next();
}
function testFollowingOther() {
// Let's follow another one
var fc1 = new FetchController();
var fc2 = new FetchController();
fc1.follow(fc2.signal);
fc2.abort();
is(fc1.signal.aborted, true, "Signal is aborted");
is(fc2.signal.aborted, true, "Signal is aborted");
next();
}
function testFollowingLoop() {
// fc1 -> fc2 -> fc3 -> fc1
var fc1 = new FetchController();
var fc2 = new FetchController();
var fc3 = new FetchController();
fc1.follow(fc2.signal);
fc2.follow(fc3.signal);
fc3.follow(fc1.signal);
fc3.abort();
is(fc1.signal.aborted, true, "Signal is aborted");
is(fc2.signal.aborted, true, "Signal is aborted");
is(fc3.signal.aborted, true, "Signal is aborted");
next();
}
function testAbortEvent() {
var fc = new FetchController();
fc.signal.onabort = function(e) {
is(e.type, "abort", "Abort received");
next();
}
fc.abort();
}
var steps = [
testWebIDL,
testUpdateData,
testFollowingOurself,
testFollowingOther,
testFollowingLoop,
testAbortEvent,
];
function next() {
if (!steps.length) {
parent.postMessage({ type: "finish" }, "*");
return;
}
var step = steps.shift();
step();
}
next();
</script>
|