-
Notifications
You must be signed in to change notification settings - Fork 30.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
test: integrate abort_controller tests from wpt
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
Showing
6 changed files
with
87 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
{} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); |