diff --git a/test/fixtures/wpt/README.md b/test/fixtures/wpt/README.md index e0880c0efd1d22..096c876f7b2956 100644 --- a/test/fixtures/wpt/README.md +++ b/test/fixtures/wpt/README.md @@ -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 diff --git a/test/fixtures/wpt/dom/abort/event.any.js b/test/fixtures/wpt/dom/abort/event.any.js new file mode 100644 index 00000000000000..a67e6f400fcf1d --- /dev/null +++ b/test/fixtures/wpt/dom/abort/event.any.js @@ -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(); diff --git a/test/fixtures/wpt/versions.json b/test/fixtures/wpt/versions.json index 49a6b702ba414a..e18a5e0213fb3e 100644 --- a/test/fixtures/wpt/versions.json +++ b/test/fixtures/wpt/versions.json @@ -34,5 +34,9 @@ "common": { "commit": "4dacb6e2ff8dbabbe328fde2d8c75491598e4c10", "path": "common" + }, + "dom/abort": { + "commit": "7caa3de7471cf19b78ee9efa313c7341a462b5e3", + "path": "dom/abort" } -} \ No newline at end of file +} diff --git a/test/parallel/test-eventtarget.js b/test/parallel/test-eventtarget.js index 9487c22e26d1af..786cbc65f3371b 100644 --- a/test/parallel/test-eventtarget.js +++ b/test/parallel/test-eventtarget.js @@ -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); +} diff --git a/test/wpt/status/dom/abort.json b/test/wpt/status/dom/abort.json new file mode 100644 index 00000000000000..0967ef424bce67 --- /dev/null +++ b/test/wpt/status/dom/abort.json @@ -0,0 +1 @@ +{} diff --git a/test/wpt/test-abort.js b/test/wpt/test-abort.js new file mode 100644 index 00000000000000..11960351b756e6 --- /dev/null +++ b/test/wpt/test-abort.js @@ -0,0 +1,7 @@ +'use strict'; +require('../common'); +const { WPTRunner } = require('../common/wpt'); + +const runner = new WPTRunner('dom/abort'); + +runner.runJsTests();