mirror of
https://github.com/servo/servo.git
synced 2025-08-03 12:40:06 +01:00
Test event dispatching in documents without a browsing context
This commit is contained in:
parent
d85ee09bc7
commit
0455b0b301
2 changed files with 48 additions and 35 deletions
|
@ -1,5 +1,5 @@
|
||||||
[Event-dispatch-bubbles-false.html]
|
[Event-dispatch-bubbles-false.html]
|
||||||
type: testharness
|
type: testharness
|
||||||
[Event.dispatchEvent with Event.bubbles set to false.]
|
[In document with a browsing context: Event.dispatchEvent with Event.bubbles set to false.]
|
||||||
expected: FAIL
|
expected: FAIL
|
||||||
|
|
||||||
|
|
|
@ -19,50 +19,63 @@
|
||||||
</tbody>
|
</tbody>
|
||||||
</table>
|
</table>
|
||||||
<script>
|
<script>
|
||||||
test(function() {
|
function targetsForDocumentChain(document) {
|
||||||
var event_type = "click";
|
return [
|
||||||
var target = document.getElementById("target");
|
|
||||||
var targets = [
|
|
||||||
window,
|
|
||||||
document,
|
document,
|
||||||
document.documentElement,
|
document.documentElement,
|
||||||
document.body,
|
document.body,
|
||||||
document.getElementById("table"),
|
document.getElementById("table"),
|
||||||
document.getElementById("table-body"),
|
document.getElementById("table-body"),
|
||||||
document.getElementById("parent"),
|
document.getElementById("parent")
|
||||||
target,
|
|
||||||
];
|
|
||||||
var expected_targets = targets.concat(target);
|
|
||||||
var phases = [
|
|
||||||
Event.CAPTURING_PHASE,
|
|
||||||
Event.CAPTURING_PHASE,
|
|
||||||
Event.CAPTURING_PHASE,
|
|
||||||
Event.CAPTURING_PHASE,
|
|
||||||
Event.CAPTURING_PHASE,
|
|
||||||
Event.CAPTURING_PHASE,
|
|
||||||
Event.CAPTURING_PHASE,
|
|
||||||
Event.AT_TARGET,
|
|
||||||
Event.AT_TARGET,
|
|
||||||
];
|
];
|
||||||
|
}
|
||||||
|
|
||||||
|
function testChain(document, targetParents, phases, label) {
|
||||||
|
test(function() {
|
||||||
|
var event_type = "click";
|
||||||
|
var target = document.getElementById("target");
|
||||||
|
var targets = targetParents.concat(target);
|
||||||
|
var expected_targets = targets.concat(target);
|
||||||
|
|
||||||
var actual_targets = [], actual_phases = [];
|
var actual_targets = [], actual_phases = [];
|
||||||
var test_event = function(evt) {
|
var test_event = function(evt) {
|
||||||
actual_targets.push(evt.currentTarget);
|
actual_targets.push(evt.currentTarget);
|
||||||
actual_phases.push(evt.eventPhase);
|
actual_phases.push(evt.eventPhase);
|
||||||
}
|
}
|
||||||
|
|
||||||
for (var i = 0; i < targets.length; i++) {
|
for (var i = 0; i < targets.length; i++) {
|
||||||
targets[i].addEventListener(event_type, test_event, true);
|
targets[i].addEventListener(event_type, test_event, true);
|
||||||
targets[i].addEventListener(event_type, test_event, false);
|
targets[i].addEventListener(event_type, test_event, false);
|
||||||
}
|
}
|
||||||
|
|
||||||
var evt = document.createEvent("Event");
|
var evt = document.createEvent("Event");
|
||||||
evt.initEvent(event_type, false, true);
|
evt.initEvent(event_type, false, true);
|
||||||
|
|
||||||
target.dispatchEvent(evt);
|
target.dispatchEvent(evt);
|
||||||
|
|
||||||
assert_array_equals(actual_targets, expected_targets, "targets");
|
assert_array_equals(actual_targets, expected_targets, "targets");
|
||||||
assert_array_equals(actual_phases, phases, "phases");
|
assert_array_equals(actual_phases, phases, "phases");
|
||||||
}, "Event.dispatchEvent with Event.bubbles set to false.");
|
}, label + ": Event.dispatchEvent with Event.bubbles set to false.");
|
||||||
|
}
|
||||||
|
|
||||||
|
var phasesForDocumentChain = [
|
||||||
|
Event.CAPTURING_PHASE,
|
||||||
|
Event.CAPTURING_PHASE,
|
||||||
|
Event.CAPTURING_PHASE,
|
||||||
|
Event.CAPTURING_PHASE,
|
||||||
|
Event.CAPTURING_PHASE,
|
||||||
|
Event.CAPTURING_PHASE,
|
||||||
|
Event.AT_TARGET,
|
||||||
|
Event.AT_TARGET,
|
||||||
|
];
|
||||||
|
|
||||||
|
chainWithWindow = [window].concat(targetsForDocumentChain(document));
|
||||||
|
testChain(
|
||||||
|
document, chainWithWindow, [Event.CAPTURING_PHASE].concat(phasesForDocumentChain),
|
||||||
|
"In document with a browsing context");
|
||||||
|
|
||||||
|
var documentClone = document.cloneNode(true);
|
||||||
|
testChain(
|
||||||
|
documentClone, targetsForDocumentChain(documentClone), phasesForDocumentChain,
|
||||||
|
"In document without a browsing context");
|
||||||
</script>
|
</script>
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue