Skip to content

Commit

Permalink
Implement AbortController and AbortSignal
Browse files Browse the repository at this point in the history
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 <ricea@chromium.org>
Reviewed-by: Kent Tamura <tkent@chromium.org>
Reviewed-by: Hayato Ito <hayato@chromium.org>
Reviewed-by: Joshua Bell <jsbell@chromium.org>
Cr-Commit-Position: refs/heads/master@{#534352}
  • Loading branch information
ricea authored and chromium-wpt-export-bot committed Feb 5, 2018
1 parent b210660 commit 6fd9710
Show file tree
Hide file tree
Showing 2 changed files with 59 additions and 5 deletions.
47 changes: 46 additions & 1 deletion dom/abort/event.any.js
Original file line number Diff line number Diff line change
Expand Up @@ -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();
17 changes: 13 additions & 4 deletions dom/interfaces.html
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,12 @@ <h1>DOM IDL tests</h1>

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")'],
Expand All @@ -46,8 +50,13 @@ <h1>DOM IDL tests</h1>
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");
</script>

0 comments on commit 6fd9710

Please sign in to comment.