dom/events/test/test_bug517851.html

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/dom/events/test/test_bug517851.html	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,104 @@
     1.4 +<!DOCTYPE HTML>
     1.5 +<html>
     1.6 +<!--
     1.7 +https://bugzilla.mozilla.org/show_bug.cgi?id=517851
     1.8 +-->
     1.9 +<head>
    1.10 +  <title>Test for Bug 517851</title>
    1.11 +  <script type="application/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
    1.12 +  <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css"/>
    1.13 +</head>
    1.14 +<body>
    1.15 +<a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=517851">Mozilla Bug 517851</a>
    1.16 +<p id="display"></p>
    1.17 +<div id="content" style="display: none">
    1.18 +  <iframe id="subframe"></iframe>
    1.19 +</div>
    1.20 +<pre id="test">
    1.21 +<script type="application/javascript">
    1.22 +
    1.23 +/** Test for Bug 517851 **/
    1.24 +SimpleTest.waitForExplicitFinish();
    1.25 +
    1.26 +addLoadEvent(function() {
    1.27 +window.handledCount = 0;
    1.28 +window.testReturnValue = false;
    1.29 +var target = document.createElement("div");
    1.30 +var target2 = $("subframe").contentDocument.body;
    1.31 +target.setAttribute("onerror", "++window.handledCount; return window.testReturnValue;");
    1.32 +target.setAttribute("onmouseover", "++window.handledCount; return window.testReturnValue;");
    1.33 +target.setAttribute("onbeforeunload", "++window.handledCount; return window.testReturnValue;");
    1.34 +target2.setAttribute("onbeforeunload", "++window.parent.handledCount; return window.parent.testReturnValue;");
    1.35 +target.setAttribute("onmousemove", "++window.handledCount; return window.testReturnValue;");                     
    1.36 +
    1.37 +var e = document.createEvent("Event");
    1.38 +e.initEvent("error", true, true);
    1.39 +window.testReturnValue = false;
    1.40 +is(target.dispatchEvent(e), !window.testReturnValue,
    1.41 +   "error event should have reverse return value handling!");
    1.42 +is(handledCount, 1, "Wrong event count!");
    1.43 +window.testReturnValue = true;
    1.44 +is(target.dispatchEvent(e), !window.testReturnValue,
    1.45 +   "error event should have reverse return value handling (2)!");
    1.46 +is(handledCount, 2, "Wrong event count!");
    1.47 +
    1.48 +e = document.createEvent("MouseEvent");
    1.49 +e.initEvent("mouseover", true, true);
    1.50 +window.testReturnValue = false;
    1.51 +is(target.dispatchEvent(e), !window.testReturnValue,
    1.52 +   "mouseover event should have reverse return value handling!");
    1.53 +is(handledCount, 3, "Wrong event count!");
    1.54 +window.testReturnValue = true;
    1.55 +is(target.dispatchEvent(e), !window.testReturnValue,
    1.56 +   "mouseover event should have reverse return value handling (2)!");
    1.57 +is(handledCount, 4, "Wrong event count!");
    1.58 +
    1.59 +e = document.createEvent("BeforeUnloadEvent");
    1.60 +e.initEvent("beforeunload", true, true);
    1.61 +window.testReturnValue = true;
    1.62 +is(target.dispatchEvent(e), true,
    1.63 +   "beforeunload event on random element should not be prevented!");
    1.64 +is(handledCount, 4, "Wrong event count; handler should not have run!");
    1.65 +is(target2.dispatchEvent(e), false,
    1.66 +   "beforeunload event should be prevented!");
    1.67 +is(handledCount, 5, "Wrong event count!");
    1.68 +window.testReturnValue = false;
    1.69 +is(target.dispatchEvent(e), true,
    1.70 +   "beforeunload event on random element should not be prevented (2)!");
    1.71 +is(handledCount, 5, "Wrong event count; handler should not have run! (2)");
    1.72 +is(target2.dispatchEvent(e), false,
    1.73 +   "beforeunload event should be prevented (2)!");
    1.74 +is(handledCount, 6, "Wrong event count!");
    1.75 +
    1.76 +// Create normal event for beforeunload.
    1.77 +e = document.createEvent("Event");
    1.78 +e.initEvent("beforeunload", true, true);
    1.79 +window.testReturnValue = true;
    1.80 +is(target.dispatchEvent(e), true,
    1.81 +   "beforeunload event shouldn't be prevented (3)!");
    1.82 +is(handledCount, 6, "Wrong event count: handler should not have run(3)!");
    1.83 +is(target2.dispatchEvent(e), true,
    1.84 +   "beforeunload event shouldn't be prevented (3)!");
    1.85 +is(handledCount, 7, "Wrong event count!");
    1.86 +
    1.87 +e = document.createEvent("MouseEvent");
    1.88 +e.initEvent("mousemove", true, true);
    1.89 +window.testReturnValue = true;
    1.90 +is(target.dispatchEvent(e), window.testReturnValue,
    1.91 +   "mousemove event shouldn't have reverse return value handling!");
    1.92 +is(handledCount, 8, "Wrong event count!");
    1.93 +window.testReturnValue = false;
    1.94 +is(target.dispatchEvent(e), window.testReturnValue,
    1.95 +   "mousemove event shouldn't have reverse return value handling (2)!");
    1.96 +is(handledCount, 9, "Wrong event count!");
    1.97 +
    1.98 +// Now unhook the beforeunload handler in the subframe, so we don't prompt to
    1.99 +// unload.
   1.100 +target2.onbeforeunload = null;
   1.101 +
   1.102 +SimpleTest.finish();
   1.103 +});
   1.104 +</script>
   1.105 +</pre>
   1.106 +</body>
   1.107 +</html>

mercurial