2020-06-10 21:08:58 +00:00
|
|
|
<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();
|
|
|
|
|
}
|
|
|
|
|
|
2020-06-10 21:33:28 +00:00
|
|
|
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();
|
|
|
|
|
}
|
|
|
|
|
|
2020-06-10 21:08:58 +00:00
|
|
|
var steps = [
|
|
|
|
|
testWebIDL,
|
2020-06-10 21:33:28 +00:00
|
|
|
testUpdateData,
|
|
|
|
|
testFollowingOurself,
|
|
|
|
|
testFollowingOther,
|
|
|
|
|
testFollowingLoop,
|
|
|
|
|
testAbortEvent,
|
2020-06-10 21:08:58 +00:00
|
|
|
];
|
|
|
|
|
|
|
|
|
|
function next() {
|
|
|
|
|
if (!steps.length) {
|
|
|
|
|
parent.postMessage({ type: "finish" }, "*");
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
var step = steps.shift();
|
|
|
|
|
step();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
next();
|
|
|
|
|
|
|
|
|
|
</script>
|