mirror of
https://github.com/mozilla/gecko-dev.git
synced 2024-11-24 13:21:05 +00:00
Bug 1345996 followup. Update some tests for the new event behavior.
MozReview-Commit-ID: 1OAR6YcoiF3
This commit is contained in:
parent
9eca2208bd
commit
b95ec5c51f
@ -26,57 +26,69 @@ window.testReturnValue = false;
|
||||
var target = document.createElement("div");
|
||||
var target2 = $("subframe").contentDocument.body;
|
||||
target.setAttribute("onerror", "++window.handledCount; return window.testReturnValue;");
|
||||
target2.setAttribute("onerror", "++window.parent.handledCount; return window.parent.testReturnValue;");
|
||||
target.setAttribute("onmouseover", "++window.handledCount; return window.testReturnValue;");
|
||||
target.setAttribute("onbeforeunload", "++window.handledCount; return window.testReturnValue;");
|
||||
target2.setAttribute("onbeforeunload", "++window.parent.handledCount; return window.parent.testReturnValue;");
|
||||
target.setAttribute("onmousemove", "++window.handledCount; return window.testReturnValue;");
|
||||
|
||||
var e = document.createEvent("Event");
|
||||
var e = document.createEvent("ErrorEvent");
|
||||
e.initEvent("error", true, true);
|
||||
window.testReturnValue = true;
|
||||
is(target.dispatchEvent(e), window.testReturnValue,
|
||||
"error event should not have reverse return value handling on div!");
|
||||
is(handledCount, 1, "Wrong event count!");
|
||||
window.testReturnValue = false;
|
||||
is(target.dispatchEvent(e), window.testReturnValue,
|
||||
"error event should not have reverse return value handling on div (2)!");
|
||||
is(handledCount, 2, "Wrong event count!");
|
||||
|
||||
var e = document.createEvent("ErrorEvent");
|
||||
e.initEvent("error", true, true);
|
||||
window.testReturnValue = false;
|
||||
is(target.dispatchEvent(e), !window.testReturnValue,
|
||||
is(target2.dispatchEvent(e), !window.testReturnValue,
|
||||
"error event should have reverse return value handling!");
|
||||
is(handledCount, 1, "Wrong event count!");
|
||||
is(handledCount, 3, "Wrong event count!");
|
||||
window.testReturnValue = true;
|
||||
is(target.dispatchEvent(e), !window.testReturnValue,
|
||||
is(target2.dispatchEvent(e), !window.testReturnValue,
|
||||
"error event should have reverse return value handling (2)!");
|
||||
is(handledCount, 2, "Wrong event count!");
|
||||
is(handledCount, 4, "Wrong event count!");
|
||||
|
||||
e = document.createEvent("MouseEvent");
|
||||
e.initEvent("mouseover", true, true);
|
||||
window.testReturnValue = false;
|
||||
is(target.dispatchEvent(e), !window.testReturnValue,
|
||||
"mouseover event should have reverse return value handling!");
|
||||
is(handledCount, 3, "Wrong event count!");
|
||||
window.testReturnValue = true;
|
||||
is(target.dispatchEvent(e), !window.testReturnValue,
|
||||
"mouseover event should have reverse return value handling (2)!");
|
||||
is(handledCount, 4, "Wrong event count!");
|
||||
is(target.dispatchEvent(e), window.testReturnValue,
|
||||
"mouseover event should not have reverse return value handling!");
|
||||
is(handledCount, 5, "Wrong event count!");
|
||||
window.testReturnValue = false;
|
||||
is(target.dispatchEvent(e), window.testReturnValue,
|
||||
"mouseover event should not have reverse return value handling (2)!");
|
||||
is(handledCount, 6, "Wrong event count!");
|
||||
|
||||
e = document.createEvent("BeforeUnloadEvent");
|
||||
e.initEvent("beforeunload", true, true);
|
||||
window.testReturnValue = true;
|
||||
is(target.dispatchEvent(e), true,
|
||||
"beforeunload event on random element should not be prevented!");
|
||||
is(handledCount, 4, "Wrong event count; handler should not have run!");
|
||||
is(handledCount, 6, "Wrong event count; handler should not have run!");
|
||||
is(target2.dispatchEvent(e), false,
|
||||
"beforeunload event should be prevented!");
|
||||
is(handledCount, 5, "Wrong event count!");
|
||||
is(handledCount, 7, "Wrong event count!");
|
||||
window.testReturnValue = false;
|
||||
is(target.dispatchEvent(e), false,
|
||||
"beforeunload event on random element should be prevented because the event was already cancelled!");
|
||||
is(handledCount, 5, "Wrong event count; handler should not have run! (2)");
|
||||
is(handledCount, 7, "Wrong event count; handler should not have run! (2)");
|
||||
|
||||
e = document.createEvent("BeforeUnloadEvent");
|
||||
e.initEvent("beforeunload", true, true);
|
||||
window.testReturnValue = false;
|
||||
is(target.dispatchEvent(e), true,
|
||||
"beforeunload event on random element should not be prevented (2)!");
|
||||
is(handledCount, 5, "Wrong event count; handler should not have run! (2)");
|
||||
is(handledCount, 7, "Wrong event count; handler should not have run! (2)");
|
||||
|
||||
is(target2.dispatchEvent(e), false,
|
||||
"beforeunload event should be prevented (2)!");
|
||||
is(handledCount, 6, "Wrong event count!");
|
||||
is(handledCount, 8, "Wrong event count!");
|
||||
|
||||
// Create normal event for beforeunload.
|
||||
e = document.createEvent("Event");
|
||||
@ -84,21 +96,21 @@ e.initEvent("beforeunload", true, true);
|
||||
window.testReturnValue = true;
|
||||
is(target.dispatchEvent(e), true,
|
||||
"beforeunload event shouldn't be prevented (3)!");
|
||||
is(handledCount, 6, "Wrong event count: handler should not have run(3)!");
|
||||
is(handledCount, 8, "Wrong event count: handler should not have run(3)!");
|
||||
is(target2.dispatchEvent(e), true,
|
||||
"beforeunload event shouldn't be prevented (3)!");
|
||||
is(handledCount, 7, "Wrong event count!");
|
||||
is(handledCount, 9, "Wrong event count!");
|
||||
|
||||
e = document.createEvent("MouseEvent");
|
||||
e.initEvent("mousemove", true, true);
|
||||
window.testReturnValue = true;
|
||||
is(target.dispatchEvent(e), window.testReturnValue,
|
||||
"mousemove event shouldn't have reverse return value handling!");
|
||||
is(handledCount, 8, "Wrong event count!");
|
||||
is(handledCount, 10, "Wrong event count!");
|
||||
window.testReturnValue = false;
|
||||
is(target.dispatchEvent(e), window.testReturnValue,
|
||||
"mousemove event shouldn't have reverse return value handling (2)!");
|
||||
is(handledCount, 9, "Wrong event count!");
|
||||
is(handledCount, 11, "Wrong event count!");
|
||||
|
||||
// Now unhook the beforeunload handler in the subframe, so we don't prompt to
|
||||
// unload.
|
||||
|
@ -33,25 +33,37 @@ https://bugzilla.mozilla.org/show_bug.cgi?id=985988
|
||||
t.dispatchEvent(e);
|
||||
ok(!e.defaultPrevented, "Shouldn't have prevented default handling.");
|
||||
|
||||
// mouseover has reversed meaning for handler return value.
|
||||
t.onmouseover = reversedHandler;
|
||||
t.onmouseover = handler;
|
||||
e = new MouseEvent("mouseover", {cancelable: true});
|
||||
t.dispatchEvent(e);
|
||||
ok(e.defaultPrevented, "Should have prevented default handling.");
|
||||
|
||||
t.onmouseover = handler;
|
||||
t.onmouseover = reversedHandler;
|
||||
e = new MouseEvent("mouseover", {cancelable: true});
|
||||
t.dispatchEvent(e);
|
||||
ok(!e.defaultPrevented, "Shouldn't have prevented default handling.");
|
||||
|
||||
// error has reversed meaning for handler return value.
|
||||
// error does not have reversed meaning for handler return value on
|
||||
// non-globals.
|
||||
t.onerror = handler;
|
||||
e = new ErrorEvent("error", {cancelable: true});
|
||||
t.dispatchEvent(e);
|
||||
ok(e.defaultPrevented, "Should have prevented default handling.");
|
||||
|
||||
t.onerror = reversedHandler;
|
||||
e = new ErrorEvent("error", {cancelable: true});
|
||||
t.dispatchEvent(e);
|
||||
ok(!e.defaultPrevented, "Shouldn't have prevented default handling.");
|
||||
|
||||
// error has reversed meaning for handler return value on globals.
|
||||
t = document.getElementById("testtarget2").contentWindow;
|
||||
t.onerror = reversedHandler;
|
||||
e = new ErrorEvent("error", {cancelable: true});
|
||||
t.dispatchEvent(e);
|
||||
ok(e.defaultPrevented, "Should have prevented default handling.");
|
||||
|
||||
t.onerror = handler;
|
||||
e = new MouseEvent("error", {cancelable: true});
|
||||
e = new ErrorEvent("error", {cancelable: true});
|
||||
t.dispatchEvent(e);
|
||||
ok(!e.defaultPrevented, "Shouldn't have prevented default handling.");
|
||||
|
||||
@ -70,6 +82,7 @@ https://bugzilla.mozilla.org/show_bug.cgi?id=985988
|
||||
|
||||
</div>
|
||||
<a href="#" id="testtarget">test target</a>
|
||||
<iframe id="testtarget2"></iframe>
|
||||
<pre id="test">
|
||||
</pre>
|
||||
</body>
|
||||
|
@ -83,7 +83,8 @@
|
||||
if (event.message == "uncaught exception: 7.5 million years for that?" ||
|
||||
event.message == "uncaught exception: Just following orders, sir!") {
|
||||
// We throw those on purpose in the worker, so ignore them.
|
||||
return true;
|
||||
event.preventDefault();
|
||||
return;
|
||||
}
|
||||
ok(false, "Worker had an error: " + event.message);
|
||||
worker.terminate();
|
||||
|
Loading…
Reference in New Issue
Block a user