// We now have both "click" and "fooevent" listeners.
// Get the new set of listener infos, because we'll want to flip certain
// "click" event listeners on and off in the tests below.
// The order of event types is not guaranteed by getListenerInfoFor; but the
// order of listeners for a single event is guaranteed. So we filter the infos
// by event type.
const combinedListenerInfos = [...els.getListenerInfoFor(root)];
const clickInfos = combinedListenerInfos.filter((info) => info.type == "click");
// Use a child node to dispatch events so that both capturing and bubbling
// listeners get called.
l2 = document.getElementById("testlevel2");
l2.click();
ok(handlerCalled);
ok(capturingListenerCalled);
ok(bubblingListenerCalled);
clearListenerStates();
root.onclick = l;
infos = els.getListenerInfoFor(root);
is(infos.length, 1, "Element should have listeners (3)");
is(infos[0].toSource(), '(function (e) { alert(e); })', "Unexpected serialization (4)");
is(infos[0].type, "click", "Wrong type (4)");
is(infos[0].capturing, false, "Wrong phase (4)");
is(infos[0].allowsUntrusted, true, "Should allow untrusted events (3)");
is(SpecialPowers.unwrap(infos[0].listenerObject), l, "Should have the right listener object (4)");
l3 = document.getElementById("testlevel3");
try {
els.getListenerInfoFor(null);
ok(false, "Should have thrown an exception.");
} catch (ex) {
ok(true, "We should be still running.");
}
setTimeout(testAllListener, 0);
}
function dispatchTrusted(t, o) {
SpecialPowers.dispatchEvent(window, t, new Event("testevent", o));
}
els.addListenerForAllEvents(root, allListener, false, true); var infos = els.getListenerInfoFor(root); var nullTypes = 0;
for (var i = 0; i < infos.length; ++i) {
if (infos[i].type == null) {
++nullTypes;
}
}
is(nullTypes, 1, "Should have one all-event-listener!");
// Test the order of event listeners. var clickListenerCalled = false; var allListenerCalled = false;
function clickListener() {
clickListenerCalled = true;
ok(allListenerCalled, "Should have called '*' listener before normal listener!");
}
function allListener2() {
allListenerCalled = true;
ok(!clickListenerCalled, "Shouldn't have called click listener before '*' listener!");
}
root.onclick = null; // Remove the listener added in earlier tests.
root.addEventListener("click", clickListener);
els.addListenerForAllEvents(root, allListener2, false, true);
l3.dispatchEvent(new MouseEvent("click", { bubbles: true }));
root.removeEventListener("click", clickListener);
els.removeListenerForAllEvents(root, allListener2, false);
ok(allListenerCalled, "Should have called '*' listener");
ok(clickListenerCalled, "Should have called click listener");
is(results.length, expectedResults.length, "count");
for (var i = 0; i < expectedResults.length; ++i) {
for (var p in expectedResults[i]) {
is(results[i][p], expectedResults[i][p], p);
}
}
SimpleTest.finish();
}
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.