Skip to content

Commit 2e4b6f9

Browse files
riceachromium-wpt-export-bot
authored andcommitted
Implement AbortController and AbortSignal
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
1 parent b210660 commit 2e4b6f9

File tree

2 files changed

+59
-5
lines changed

2 files changed

+59
-5
lines changed

dom/abort/event.any.js

Lines changed: 46 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,51 @@ test(t => {
1717
assert_true(s.aborted);
1818

1919
c.abort();
20-
}, "AbortController() basics");
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");
2166

2267
done();

dom/interfaces.html

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,12 @@ <h1>DOM IDL tests</h1>
1818

1919
var idlArray = new IdlArray();
2020

21-
function doTest(idl) {
22-
idlArray.add_idls(idl);
21+
function doTest([html, dom]) {
22+
// HTML is needed for EventHandler. Provide a dummy interface for
23+
// LinkStyle which HTML depends on but we're not testing.
24+
idlArray.add_untested_idls('interface LinkStyle {};');
25+
idlArray.add_untested_idls(html);
26+
idlArray.add_idls(dom);
2327
idlArray.add_objects({
2428
EventTarget: ['new EventTarget()'],
2529
Event: ['document.createEvent("Event")', 'new Event("foo")'],
@@ -46,8 +50,13 @@ <h1>DOM IDL tests</h1>
4650
idlArray.test();
4751
}
4852

53+
function fetchText(url) {
54+
return fetch(url).then((response) => response.text());
55+
}
56+
4957
promise_test(function() {
50-
return fetch("/interfaces/dom.idl").then(response => response.text())
51-
.then(doTest);
58+
return Promise.all(['/interfaces/html.idl',
59+
'/interfaces/dom.idl'].map(fetchText))
60+
.then(doTest);
5261
}, "Test driver");
5362
</script>

0 commit comments

Comments
 (0)