From a78d5ced645f51903831a28310566bc8d9d31a39 Mon Sep 17 00:00:00 2001 From: Adam Rice Date: Tue, 27 Feb 2018 16:15:27 +0000 Subject: [PATCH] Bug 1441488 [wpt PR 9361] - Implement AbortController and AbortSignal, a=testonly Automatic update from web-platform-tests Also adjust layout tests expectations to match the new behaviour. One fetch() wpt test that previously failed due to AbortController being undefined now times out because the "signal" properties in fetch options doesn't do anything yet. This will be fixed once it is implemented. Spec: https://dom.spec.whatwg.org/#aborting-ongoing-activities Design doc: https://docs.google.com/document/d/1OuoCG2uiijbAwbCw9jaS7tHEO0LBO_4gMNio1ox0qlY/edit Intent to Ship: https://groups.google.com/a/chromium.org/d/msg/blink-dev/9vNZh4fhV2U/ZVxD2iQACgAJ BUG=750599 Change-Id: I0e504bbf7f8552d602913ee2069bbf90f95deaff Reviewed-on: https://chromium-review.googlesource.com/896669 Commit-Queue: Adam Rice Reviewed-by: Kent Tamura Reviewed-by: Hayato Ito Reviewed-by: Joshua Bell Cr-Commit-Position: refs/heads/master@{#534352} wpt-commits: 7caa3de7471cf19b78ee9efa313c7341a462b5e3 wpt-pr: 9361 reapplied-commits: 370e267e160568862f1fd9ec246ab5bb840f586e, fe4514c84e7ad28e46bad5da93381deb99b177f3, 7806af854343c043a2645a4034fdc7812f65daad, 9ddfd21554293dec5a4bf2e5375ae4f3c9f2ded0, 75f63c4d1ebc949647184fd60972fc7b9fd4affb, 1f3a5b496acd2288cc8cf0c32af86cb35157ea4e, 88b42bd5847abac58a62c4d6b33c1509bfce5f3d, 15c2e4c690700c6c115f8afe5e44ded10d943538, c8d461ef1437641ae7d4ea1d21e1e60cd62910b0, a6088a5f48ee299386a84d2f771902267d7355b1, 0634cd8f08ebe0905a9188fb1398c7b5f889c5dc, c8ee4a012dae506ae06bb5b2ad50942b04c1aaaa, c2c352456a4cf62dcc12f851138b04397675a445, b93a8879555d2fa7e7d4e00a275513a3a6338b35, b86e1331cb36634fd33677043b61fc0c1d8485bc, 44ddf14fd3346658c3223f13652073fafbfa48fa, a1a5840a6bb53e305ba02bcbeb215659342d0edb, 7465cb110ae5ec2e2ca73182caf5293f0efc8fd5, aad5349b3458bc3414e274b33fa86a1123901ff2, eca0907980d2769c449894a6277c60c1a306792f, 38626987c0cfd6e715cfcc6f4f1a1209191a03c5, e4a67f7ddcde6cd99348e9104bd7ed07074da44a, bb3c9990840a0fae2afc840b5952d7874785b112, 042d7adef0bdb9dc80e825c3997ace7519477c42, 99f1ea44fc7915b8b7b33bce4732fa8765fd3ac2 --- testing/web-platform/meta/MANIFEST.json | 4 +- .../web-platform/tests/dom/abort/event.any.js | 47 ++++++++++++++++++- .../web-platform/tests/dom/interfaces.html | 17 +++++-- 3 files changed, 61 insertions(+), 7 deletions(-) diff --git a/testing/web-platform/meta/MANIFEST.json b/testing/web-platform/meta/MANIFEST.json index 813b2f5939ea..66da0804a449 100644 --- a/testing/web-platform/meta/MANIFEST.json +++ b/testing/web-platform/meta/MANIFEST.json @@ -537402,7 +537402,7 @@ "support" ], "dom/abort/event.any.js": [ - "25e9c1104acb9b0092d1303190588a3953cf635d", + "d41904ddfc56e5ef3e89d965a4e5fa392e996ef9", "testharness" ], "dom/collections/HTMLCollection-as-proto-length-get-throws.html": [ @@ -537634,7 +537634,7 @@ "testharness" ], "dom/interfaces.html": [ - "7d00e3a778083a91156f4e042c7abd270060a7fc", + "3308c9f3341c12ce99217309eba608e50cca669d", "testharness" ], "dom/lists/DOMTokenList-Iterable.html": [ diff --git a/testing/web-platform/tests/dom/abort/event.any.js b/testing/web-platform/tests/dom/abort/event.any.js index 3b25702c2e4c..a67e6f400fcf 100644 --- a/testing/web-platform/tests/dom/abort/event.any.js +++ b/testing/web-platform/tests/dom/abort/event.any.js @@ -17,6 +17,51 @@ test(t => { assert_true(s.aborted); c.abort(); -}, "AbortController() basics"); +}, "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/testing/web-platform/tests/dom/interfaces.html b/testing/web-platform/tests/dom/interfaces.html index 8e9572d0f09c..3cb08f405a5a 100644 --- a/testing/web-platform/tests/dom/interfaces.html +++ b/testing/web-platform/tests/dom/interfaces.html @@ -18,8 +18,12 @@ element.setAttribute("bar", "baz"); var idlArray = new IdlArray(); -function doTest(idl) { - idlArray.add_idls(idl); +function doTest([html, dom]) { + // HTML is needed for EventHandler. Provide a dummy interface for + // LinkStyle which HTML depends on but we're not testing. + idlArray.add_untested_idls('interface LinkStyle {};'); + idlArray.add_untested_idls(html); + idlArray.add_idls(dom); idlArray.add_objects({ EventTarget: ['new EventTarget()'], Event: ['document.createEvent("Event")', 'new Event("foo")'], @@ -46,8 +50,13 @@ function doTest(idl) { idlArray.test(); } +function fetchText(url) { + return fetch(url).then((response) => response.text()); +} + promise_test(function() { - return fetch("/interfaces/dom.idl").then(response => response.text()) - .then(doTest); + return Promise.all(['/interfaces/html.idl', + '/interfaces/dom.idl'].map(fetchText)) + .then(doTest); }, "Test driver");