Skip to content

Commit 88f4261

Browse files
watildetargos
authored andcommitted
test: integrate abort_controller tests from wpt
Refs: web-platform-tests/wpt#9361 PR-URL: #35869 Backport-PR-URL: #38386 Refs: https://github.com/web-platform-tests/wpt/blob/master/dom/abort/event.any.js Reviewed-By: Rich Trott <rtrott@gmail.com> Reviewed-By: Michaël Zasso <targos@protonmail.com> Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com>
1 parent b2f8e8d commit 88f4261

File tree

6 files changed

+89
-1
lines changed

6 files changed

+89
-1
lines changed

test/fixtures/wpt/README.md

+1
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ Last update:
1818
- html/webappapis/microtask-queuing: https://github.com/web-platform-tests/wpt/tree/0c3bed38df/html/webappapis/microtask-queuing
1919
- html/webappapis/timers: https://github.com/web-platform-tests/wpt/tree/ddfe9c089b/html/webappapis/timers
2020
- hr-time: https://github.com/web-platform-tests/wpt/tree/a5d1774ecf/hr-time
21+
- dom/abort: https://github.com/web-platform-tests/wpt/tree/7caa3de747/dom/abort
2122

2223
[Web Platform Tests]: https://github.com/web-platform-tests/wpt
2324
[`git node wpt`]: https://github.com/nodejs/node-core-utils/blob/master/docs/git-node.md#git-node-wpt
+67
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
test(t => {
2+
const c = new AbortController(),
3+
s = c.signal;
4+
let state = "begin";
5+
6+
assert_false(s.aborted);
7+
8+
s.addEventListener("abort",
9+
t.step_func(e => {
10+
assert_equals(state, "begin");
11+
state = "aborted";
12+
})
13+
);
14+
c.abort();
15+
16+
assert_equals(state, "aborted");
17+
assert_true(s.aborted);
18+
19+
c.abort();
20+
}, "AbortController abort() should fire event synchronously");
21+
22+
test(t => {
23+
const controller = new AbortController();
24+
const signal = controller.signal;
25+
assert_equals(controller.signal, signal,
26+
"value of controller.signal should not have changed");
27+
controller.abort();
28+
assert_equals(controller.signal, signal,
29+
"value of controller.signal should still not have changed");
30+
}, "controller.signal should always return the same object");
31+
32+
test(t => {
33+
const controller = new AbortController();
34+
const signal = controller.signal;
35+
let eventCount = 0;
36+
signal.onabort = () => {
37+
++eventCount;
38+
};
39+
controller.abort();
40+
assert_true(signal.aborted);
41+
assert_equals(eventCount, 1, "event handler should have been called once");
42+
controller.abort();
43+
assert_true(signal.aborted);
44+
assert_equals(eventCount, 1,
45+
"event handler should not have been called again");
46+
}, "controller.abort() should do nothing the second time it is called");
47+
48+
test(t => {
49+
const controller = new AbortController();
50+
controller.abort();
51+
controller.signal.onabort =
52+
t.unreached_func("event handler should not be called");
53+
}, "event handler should not be called if added after controller.abort()");
54+
55+
test(t => {
56+
const controller = new AbortController();
57+
const signal = controller.signal;
58+
signal.onabort = t.step_func(e => {
59+
assert_equals(e.type, "abort", "event type should be abort");
60+
assert_equals(e.target, signal, "event target should be signal");
61+
assert_false(e.bubbles, "event should not bubble");
62+
assert_true(e.isTrusted, "event should be trusted");
63+
});
64+
controller.abort();
65+
}, "the abort event should have the right properties");
66+
67+
done();

test/fixtures/wpt/versions.json

+5-1
Original file line numberDiff line numberDiff line change
@@ -30,5 +30,9 @@
3030
"hr-time": {
3131
"commit": "a5d1774ecf41751d1c9357c27c709ee33bf3e279",
3232
"path": "hr-time"
33+
},
34+
"dom/abort": {
35+
"commit": "7caa3de7471cf19b78ee9efa313c7341a462b5e3",
36+
"path": "dom/abort"
3337
}
34-
}
38+
}

test/parallel/test-eventtarget.js

+6
Original file line numberDiff line numberDiff line change
@@ -479,3 +479,9 @@ let asyncTest = Promise.resolve();
479479
throws(() => eventTarget.addEventListener('foo', Symbol()), TypeError);
480480
});
481481
}
482+
{
483+
const eventTarget = new EventTarget();
484+
const event = new Event('foo');
485+
eventTarget.dispatchEvent(event);
486+
strictEqual(event.target, eventTarget);
487+
}

test/wpt/status/dom/abort.json

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
{}

test/wpt/test-abort.js

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
'use strict';
2+
require('../common');
3+
const { WPTRunner } = require('../common/wpt');
4+
5+
const runner = new WPTRunner('dom/abort');
6+
7+
runner.setFlags(['--experimental-abortcontroller']);
8+
9+
runner.runJsTests();

0 commit comments

Comments
 (0)