2009-10-24 19:39:28 +04:00
|
|
|
<!DOCTYPE HTML>
|
|
|
|
<html>
|
|
|
|
<!--
|
|
|
|
https://bugzilla.mozilla.org/show_bug.cgi?id=517851
|
|
|
|
-->
|
|
|
|
<head>
|
|
|
|
<title>Test for Bug 517851</title>
|
|
|
|
<script type="application/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
|
|
|
|
<link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css"/>
|
|
|
|
</head>
|
|
|
|
<body>
|
|
|
|
<a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=517851">Mozilla Bug 517851</a>
|
|
|
|
<p id="display"></p>
|
|
|
|
<div id="content" style="display: none">
|
2012-11-14 22:05:41 +04:00
|
|
|
<iframe id="subframe"></iframe>
|
2009-10-24 19:39:28 +04:00
|
|
|
</div>
|
|
|
|
<pre id="test">
|
|
|
|
<script type="application/javascript">
|
|
|
|
|
|
|
|
/** Test for Bug 517851 **/
|
2012-11-14 22:05:41 +04:00
|
|
|
SimpleTest.waitForExplicitFinish();
|
2009-10-24 19:39:28 +04:00
|
|
|
|
2012-11-14 22:05:41 +04:00
|
|
|
addLoadEvent(function() {
|
2009-10-24 19:39:28 +04:00
|
|
|
window.handledCount = 0;
|
|
|
|
window.testReturnValue = false;
|
|
|
|
var target = document.createElement("div");
|
2012-11-14 22:05:41 +04:00
|
|
|
var target2 = $("subframe").contentDocument.body;
|
2009-10-24 19:39:28 +04:00
|
|
|
target.setAttribute("onerror", "++window.handledCount; return window.testReturnValue;");
|
2017-03-11 10:33:58 +03:00
|
|
|
target2.setAttribute("onerror", "++window.parent.handledCount; return window.parent.testReturnValue;");
|
2009-10-24 19:39:28 +04:00
|
|
|
target.setAttribute("onmouseover", "++window.handledCount; return window.testReturnValue;");
|
|
|
|
target.setAttribute("onbeforeunload", "++window.handledCount; return window.testReturnValue;");
|
2012-11-14 22:05:41 +04:00
|
|
|
target2.setAttribute("onbeforeunload", "++window.parent.handledCount; return window.parent.testReturnValue;");
|
2009-10-24 19:39:28 +04:00
|
|
|
target.setAttribute("onmousemove", "++window.handledCount; return window.testReturnValue;");
|
|
|
|
|
2017-08-07 21:19:59 +03:00
|
|
|
var e = new ErrorEvent("error", {bubbles: true, cancelable: true});
|
2017-03-11 10:33:58 +03:00
|
|
|
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!");
|
|
|
|
|
2017-08-07 21:19:59 +03:00
|
|
|
var e = new ErrorEvent("error", {bubbles: true, cancelable: true});
|
2009-10-24 19:39:28 +04:00
|
|
|
window.testReturnValue = false;
|
2017-03-11 10:33:58 +03:00
|
|
|
is(target2.dispatchEvent(e), !window.testReturnValue,
|
2009-10-24 19:39:28 +04:00
|
|
|
"error event should have reverse return value handling!");
|
2017-03-11 10:33:58 +03:00
|
|
|
is(handledCount, 3, "Wrong event count!");
|
2009-10-24 19:39:28 +04:00
|
|
|
window.testReturnValue = true;
|
2017-03-11 10:33:58 +03:00
|
|
|
is(target2.dispatchEvent(e), !window.testReturnValue,
|
2009-10-24 19:39:28 +04:00
|
|
|
"error event should have reverse return value handling (2)!");
|
2017-03-11 10:33:58 +03:00
|
|
|
is(handledCount, 4, "Wrong event count!");
|
2009-10-24 19:39:28 +04:00
|
|
|
|
|
|
|
e = document.createEvent("MouseEvent");
|
|
|
|
e.initEvent("mouseover", true, true);
|
|
|
|
window.testReturnValue = true;
|
2017-03-11 10:33:58 +03:00
|
|
|
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!");
|
2009-10-24 19:39:28 +04:00
|
|
|
|
|
|
|
e = document.createEvent("BeforeUnloadEvent");
|
|
|
|
e.initEvent("beforeunload", true, true);
|
|
|
|
window.testReturnValue = true;
|
2012-11-14 22:05:41 +04:00
|
|
|
is(target.dispatchEvent(e), true,
|
|
|
|
"beforeunload event on random element should not be prevented!");
|
2017-03-11 10:33:58 +03:00
|
|
|
is(handledCount, 6, "Wrong event count; handler should not have run!");
|
2012-11-14 22:05:41 +04:00
|
|
|
is(target2.dispatchEvent(e), false,
|
2009-10-24 19:39:28 +04:00
|
|
|
"beforeunload event should be prevented!");
|
2017-03-11 10:33:58 +03:00
|
|
|
is(handledCount, 7, "Wrong event count!");
|
2009-10-24 19:39:28 +04:00
|
|
|
window.testReturnValue = false;
|
2016-04-07 15:49:12 +03:00
|
|
|
is(target.dispatchEvent(e), false,
|
|
|
|
"beforeunload event on random element should be prevented because the event was already cancelled!");
|
2017-03-11 10:33:58 +03:00
|
|
|
is(handledCount, 7, "Wrong event count; handler should not have run! (2)");
|
2016-04-07 15:49:12 +03:00
|
|
|
|
|
|
|
e = document.createEvent("BeforeUnloadEvent");
|
|
|
|
e.initEvent("beforeunload", true, true);
|
|
|
|
window.testReturnValue = false;
|
2012-11-14 22:05:41 +04:00
|
|
|
is(target.dispatchEvent(e), true,
|
|
|
|
"beforeunload event on random element should not be prevented (2)!");
|
2017-03-11 10:33:58 +03:00
|
|
|
is(handledCount, 7, "Wrong event count; handler should not have run! (2)");
|
2016-04-07 15:49:12 +03:00
|
|
|
|
2012-11-14 22:05:41 +04:00
|
|
|
is(target2.dispatchEvent(e), false,
|
2009-10-24 19:39:28 +04:00
|
|
|
"beforeunload event should be prevented (2)!");
|
2017-03-11 10:33:58 +03:00
|
|
|
is(handledCount, 8, "Wrong event count!");
|
2009-10-24 19:39:28 +04:00
|
|
|
|
|
|
|
// Create normal event for beforeunload.
|
|
|
|
e = document.createEvent("Event");
|
|
|
|
e.initEvent("beforeunload", true, true);
|
|
|
|
window.testReturnValue = true;
|
|
|
|
is(target.dispatchEvent(e), true,
|
|
|
|
"beforeunload event shouldn't be prevented (3)!");
|
2017-03-11 10:33:58 +03:00
|
|
|
is(handledCount, 8, "Wrong event count: handler should not have run(3)!");
|
2012-11-14 22:05:41 +04:00
|
|
|
is(target2.dispatchEvent(e), true,
|
|
|
|
"beforeunload event shouldn't be prevented (3)!");
|
2017-03-11 10:33:58 +03:00
|
|
|
is(handledCount, 9, "Wrong event count!");
|
2009-10-24 19:39:28 +04:00
|
|
|
|
|
|
|
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!");
|
2017-03-11 10:33:58 +03:00
|
|
|
is(handledCount, 10, "Wrong event count!");
|
2009-10-24 19:39:28 +04:00
|
|
|
window.testReturnValue = false;
|
|
|
|
is(target.dispatchEvent(e), window.testReturnValue,
|
|
|
|
"mousemove event shouldn't have reverse return value handling (2)!");
|
2017-03-11 10:33:58 +03:00
|
|
|
is(handledCount, 11, "Wrong event count!");
|
2009-10-24 19:39:28 +04:00
|
|
|
|
2012-11-14 22:05:41 +04:00
|
|
|
// Now unhook the beforeunload handler in the subframe, so we don't prompt to
|
|
|
|
// unload.
|
|
|
|
target2.onbeforeunload = null;
|
|
|
|
|
|
|
|
SimpleTest.finish();
|
|
|
|
});
|
2009-10-24 19:39:28 +04:00
|
|
|
</script>
|
|
|
|
</pre>
|
|
|
|
</body>
|
|
|
|
</html>
|