Skip to content

Commit

Permalink
test: integrate abort_controller tests from wpt
Browse files Browse the repository at this point in the history
Refs: web-platform-tests/wpt#9361

PR-URL: #35869
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>
  • Loading branch information
watilde authored and targos committed Nov 3, 2020
1 parent d2f574b commit da612df
Show file tree
Hide file tree
Showing 6 changed files with 87 additions and 1 deletion.
1 change: 1 addition & 0 deletions test/fixtures/wpt/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ Last update:
- html/webappapis/timers: https://github.com/web-platform-tests/wpt/tree/264f12bc7b/html/webappapis/timers
- hr-time: https://github.com/web-platform-tests/wpt/tree/a5d1774ecf/hr-time
- common: https://github.com/web-platform-tests/wpt/tree/4dacb6e2ff/common
- dom/abort: https://github.com/web-platform-tests/wpt/tree/7caa3de747/dom/abort

[Web Platform Tests]: https://github.com/web-platform-tests/wpt
[`git node wpt`]: https://github.com/nodejs/node-core-utils/blob/master/docs/git-node.md#git-node-wpt
67 changes: 67 additions & 0 deletions test/fixtures/wpt/dom/abort/event.any.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
test(t => {
const c = new AbortController(),
s = c.signal;
let state = "begin";

assert_false(s.aborted);

s.addEventListener("abort",
t.step_func(e => {
assert_equals(state, "begin");
state = "aborted";
})
);
c.abort();

assert_equals(state, "aborted");
assert_true(s.aborted);

c.abort();
}, "AbortController abort() should fire event synchronously");

test(t => {
const controller = new AbortController();
const signal = controller.signal;
assert_equals(controller.signal, signal,
"value of controller.signal should not have changed");
controller.abort();
assert_equals(controller.signal, signal,
"value of controller.signal should still not have changed");
}, "controller.signal should always return the same object");

test(t => {
const controller = new AbortController();
const signal = controller.signal;
let eventCount = 0;
signal.onabort = () => {
++eventCount;
};
controller.abort();
assert_true(signal.aborted);
assert_equals(eventCount, 1, "event handler should have been called once");
controller.abort();
assert_true(signal.aborted);
assert_equals(eventCount, 1,
"event handler should not have been called again");
}, "controller.abort() should do nothing the second time it is called");

test(t => {
const controller = new AbortController();
controller.abort();
controller.signal.onabort =
t.unreached_func("event handler should not be called");
}, "event handler should not be called if added after controller.abort()");

test(t => {
const controller = new AbortController();
const signal = controller.signal;
signal.onabort = t.step_func(e => {
assert_equals(e.type, "abort", "event type should be abort");
assert_equals(e.target, signal, "event target should be signal");
assert_false(e.bubbles, "event should not bubble");
assert_true(e.isTrusted, "event should be trusted");
});
controller.abort();
}, "the abort event should have the right properties");

done();
6 changes: 5 additions & 1 deletion test/fixtures/wpt/versions.json
Original file line number Diff line number Diff line change
Expand Up @@ -34,5 +34,9 @@
"common": {
"commit": "4dacb6e2ff8dbabbe328fde2d8c75491598e4c10",
"path": "common"
},
"dom/abort": {
"commit": "7caa3de7471cf19b78ee9efa313c7341a462b5e3",
"path": "dom/abort"
}
}
}
6 changes: 6 additions & 0 deletions test/parallel/test-eventtarget.js
Original file line number Diff line number Diff line change
Expand Up @@ -479,3 +479,9 @@ let asyncTest = Promise.resolve();
throws(() => eventTarget.addEventListener('foo', Symbol()), TypeError);
});
}
{
const eventTarget = new EventTarget();
const event = new Event('foo');
eventTarget.dispatchEvent(event);
strictEqual(event.target, eventTarget);
}
1 change: 1 addition & 0 deletions test/wpt/status/dom/abort.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{}
7 changes: 7 additions & 0 deletions test/wpt/test-abort.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
'use strict';
require('../common');
const { WPTRunner } = require('../common/wpt');

const runner = new WPTRunner('dom/abort');

runner.runJsTests();

0 comments on commit da612df

Please sign in to comment.