mirror of
https://github.com/servo/servo.git
synced 2025-09-08 05:58:20 +01:00
Update web-platform-tests to revision dc5cbf088edcdb266541d4e5a76149a2c6e716a0
This commit is contained in:
parent
1d40075f03
commit
079092dfea
2381 changed files with 90360 additions and 17722 deletions
|
@ -0,0 +1,81 @@
|
|||
<!DOCTYPE html>
|
||||
<meta charset="utf-8">
|
||||
<title>AddEventListenerOptions.once</title>
|
||||
<link rel="author" title="Xidorn Quan" href="https://www.upsuper.org">
|
||||
<link rel="help" href="https://dom.spec.whatwg.org/#dom-addeventlisteneroptions-once">
|
||||
<script src="/resources/testharness.js"></script>
|
||||
<script src="/resources/testharnessreport.js"></script>
|
||||
<div id="log"></div>
|
||||
<script>
|
||||
|
||||
test(function() {
|
||||
var invoked_once = false;
|
||||
var invoked_normal = false;
|
||||
function handler_once() {
|
||||
invoked_once = true;
|
||||
}
|
||||
function handler_normal() {
|
||||
invoked_normal = true;
|
||||
}
|
||||
|
||||
document.addEventListener('test', handler_once, {once: true});
|
||||
document.addEventListener('test', handler_normal);
|
||||
document.dispatchEvent(new Event('test'));
|
||||
assert_equals(invoked_once, true, "Once handler should be invoked");
|
||||
assert_equals(invoked_normal, true, "Normal handler should be invoked");
|
||||
|
||||
invoked_once = false;
|
||||
invoked_normal = false;
|
||||
document.dispatchEvent(new Event('test'));
|
||||
assert_equals(invoked_once, false, "Once handler shouldn't be invoked again");
|
||||
assert_equals(invoked_normal, true, "Normal handler should be invoked again");
|
||||
document.removeEventListener('test', handler_normal);
|
||||
}, "Once listener should be invoked only once");
|
||||
|
||||
test(function() {
|
||||
var invoked_count = 0;
|
||||
function handler() {
|
||||
invoked_count++;
|
||||
if (invoked_count == 1)
|
||||
document.dispatchEvent(new Event('test'));
|
||||
}
|
||||
document.addEventListener('test', handler, {once: true});
|
||||
document.dispatchEvent(new Event('test'));
|
||||
assert_equals(invoked_count, 1, "Once handler should only be invoked once");
|
||||
|
||||
invoked_count = 0;
|
||||
function handler2() {
|
||||
invoked_count++;
|
||||
if (invoked_count == 1)
|
||||
document.addEventListener('test', handler2, {once: true});
|
||||
if (invoked_count <= 2)
|
||||
document.dispatchEvent(new Event('test'));
|
||||
}
|
||||
document.addEventListener('test', handler2, {once: true});
|
||||
document.dispatchEvent(new Event('test'));
|
||||
assert_equals(invoked_count, 2, "Once handler should only be invoked once after each adding");
|
||||
}, "Once listener should be invoked only once even if the event is nested");
|
||||
|
||||
test(function() {
|
||||
var invoked_count = 0;
|
||||
function handler() {
|
||||
invoked_count++;
|
||||
}
|
||||
|
||||
document.addEventListener('test', handler, {once: true});
|
||||
document.addEventListener('test', handler);
|
||||
document.dispatchEvent(new Event('test'));
|
||||
assert_equals(invoked_count, 1, "The handler should only be added once");
|
||||
|
||||
invoked_count = 0;
|
||||
document.dispatchEvent(new Event('test'));
|
||||
assert_equals(invoked_count, 0, "The handler was added as a once listener");
|
||||
|
||||
invoked_count = 0;
|
||||
document.addEventListener('test', handler, {once: true});
|
||||
document.removeEventListener('test', handler);
|
||||
document.dispatchEvent(new Event('test'));
|
||||
assert_equals(invoked_count, 0, "The handler should have been removed");
|
||||
}, "Once listener should be added / removed like normal listeners");
|
||||
|
||||
</script>
|
|
@ -13,7 +13,7 @@ booleans.forEach(function(bubbles) {
|
|||
e.initEvent("type", bubbles, cancelable)
|
||||
|
||||
// Step 3.
|
||||
// Can't test the stop propagation flag and stop immediate propagation flag.
|
||||
// Stop (immediate) propagation flag is tested later
|
||||
assert_equals(e.defaultPrevented, false, "defaultPrevented")
|
||||
// Step 4.
|
||||
assert_equals(e.isTrusted, false, "isTrusted")
|
||||
|
@ -78,31 +78,28 @@ async_test(function() {
|
|||
this.done()
|
||||
}, "Calling initEvent must not have an effect during dispatching.")
|
||||
|
||||
async_test(function() {
|
||||
test(function() {
|
||||
var e = document.createEvent("Event")
|
||||
e.initEvent("type", false, false)
|
||||
e.stopPropagation()
|
||||
|
||||
var target = document.createElement("div")
|
||||
target.addEventListener("type", this.step_func(function() {
|
||||
assert_unreached("")
|
||||
}), false)
|
||||
assert_equals(target.dispatchEvent(e), true, "dispatchEvent must return true")
|
||||
assert_equals(target.dispatchEvent(e), true, "dispatchEvent must return true")
|
||||
|
||||
e.initEvent("type", false, false)
|
||||
var called = false
|
||||
var target = document.createElement("div")
|
||||
target.addEventListener("type", this.step_func(function() {
|
||||
called = true
|
||||
}), false)
|
||||
assert_false(called)
|
||||
assert_equals(target.dispatchEvent(e), true, "dispatchEvent must return true")
|
||||
assert_true(called)
|
||||
|
||||
this.done()
|
||||
var called = false
|
||||
target.addEventListener("type", function() { called = true }, false)
|
||||
assert_true(target.dispatchEvent(e), "dispatchEvent must return true")
|
||||
assert_true(called, "Listener must be called")
|
||||
}, "Calling initEvent must unset the stop propagation flag.")
|
||||
|
||||
test(function() {
|
||||
var e = document.createEvent("Event")
|
||||
e.stopImmediatePropagation()
|
||||
e.initEvent("type", false, false)
|
||||
var target = document.createElement("div")
|
||||
var called = false
|
||||
target.addEventListener("type", function() { called = true }, false)
|
||||
assert_true(target.dispatchEvent(e), "dispatchEvent must return true")
|
||||
assert_true(called, "Listener must be called")
|
||||
}, "Calling initEvent must unset the stop immediate propagation flag.")
|
||||
|
||||
async_test(function() {
|
||||
var e = document.createEvent("Event")
|
||||
e.initEvent("type", false, false)
|
||||
|
|
|
@ -13,10 +13,11 @@ function testPropagationFlag(ev, expected, desc) {
|
|||
var callback = function() { called = true };
|
||||
document.head.addEventListener("foo", callback);
|
||||
document.head.dispatchEvent(ev);
|
||||
// Gecko resets the flags after dispatching; it will happily dispatch
|
||||
assert_equals(called, expected, "Propagation flag");
|
||||
// dispatchEvent resets the propagation flags so it will happily dispatch
|
||||
// the event the second time around.
|
||||
document.head.dispatchEvent(ev);
|
||||
assert_equals(called, expected, "Propagation flag");
|
||||
assert_equals(called, true, "Propagation flag after first dispatch");
|
||||
document.head.removeEventListener("foo", callback);
|
||||
}, desc);
|
||||
}
|
||||
|
|
|
@ -17,13 +17,13 @@ test(function() {
|
|||
assert_throws(new TypeError(), function() { document.dispatchEvent(null) })
|
||||
}, "Calling dispatchEvent(null).")
|
||||
|
||||
aliases.forEach(function(alias) {
|
||||
for (var alias in aliases) {
|
||||
test(function() {
|
||||
var e = document.createEvent(alias[0])
|
||||
var e = document.createEvent(alias)
|
||||
assert_equals(e.type, "", "Event type should be empty string before initialization")
|
||||
assert_throws("InvalidStateError", function() { document.dispatchEvent(e) })
|
||||
}, "If the event's initialized flag is not set, an InvalidStateError must be thrown (" + alias [0] + ").")
|
||||
})
|
||||
}, "If the event's initialized flag is not set, an InvalidStateError must be thrown (" + alias + ").")
|
||||
}
|
||||
|
||||
var dispatch_dispatch = async_test("If the event's dispatch flag is set, an InvalidStateError must be thrown.")
|
||||
dispatch_dispatch.step(function() {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue