dom/events/test/test_bug517851.html

Wed, 31 Dec 2014 06:09:35 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Wed, 31 Dec 2014 06:09:35 +0100
changeset 0
6474c204b198
permissions
-rw-r--r--

Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.

michael@0 1 <!DOCTYPE HTML>
michael@0 2 <html>
michael@0 3 <!--
michael@0 4 https://bugzilla.mozilla.org/show_bug.cgi?id=517851
michael@0 5 -->
michael@0 6 <head>
michael@0 7 <title>Test for Bug 517851</title>
michael@0 8 <script type="application/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
michael@0 9 <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css"/>
michael@0 10 </head>
michael@0 11 <body>
michael@0 12 <a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=517851">Mozilla Bug 517851</a>
michael@0 13 <p id="display"></p>
michael@0 14 <div id="content" style="display: none">
michael@0 15 <iframe id="subframe"></iframe>
michael@0 16 </div>
michael@0 17 <pre id="test">
michael@0 18 <script type="application/javascript">
michael@0 19
michael@0 20 /** Test for Bug 517851 **/
michael@0 21 SimpleTest.waitForExplicitFinish();
michael@0 22
michael@0 23 addLoadEvent(function() {
michael@0 24 window.handledCount = 0;
michael@0 25 window.testReturnValue = false;
michael@0 26 var target = document.createElement("div");
michael@0 27 var target2 = $("subframe").contentDocument.body;
michael@0 28 target.setAttribute("onerror", "++window.handledCount; return window.testReturnValue;");
michael@0 29 target.setAttribute("onmouseover", "++window.handledCount; return window.testReturnValue;");
michael@0 30 target.setAttribute("onbeforeunload", "++window.handledCount; return window.testReturnValue;");
michael@0 31 target2.setAttribute("onbeforeunload", "++window.parent.handledCount; return window.parent.testReturnValue;");
michael@0 32 target.setAttribute("onmousemove", "++window.handledCount; return window.testReturnValue;");
michael@0 33
michael@0 34 var e = document.createEvent("Event");
michael@0 35 e.initEvent("error", true, true);
michael@0 36 window.testReturnValue = false;
michael@0 37 is(target.dispatchEvent(e), !window.testReturnValue,
michael@0 38 "error event should have reverse return value handling!");
michael@0 39 is(handledCount, 1, "Wrong event count!");
michael@0 40 window.testReturnValue = true;
michael@0 41 is(target.dispatchEvent(e), !window.testReturnValue,
michael@0 42 "error event should have reverse return value handling (2)!");
michael@0 43 is(handledCount, 2, "Wrong event count!");
michael@0 44
michael@0 45 e = document.createEvent("MouseEvent");
michael@0 46 e.initEvent("mouseover", true, true);
michael@0 47 window.testReturnValue = false;
michael@0 48 is(target.dispatchEvent(e), !window.testReturnValue,
michael@0 49 "mouseover event should have reverse return value handling!");
michael@0 50 is(handledCount, 3, "Wrong event count!");
michael@0 51 window.testReturnValue = true;
michael@0 52 is(target.dispatchEvent(e), !window.testReturnValue,
michael@0 53 "mouseover event should have reverse return value handling (2)!");
michael@0 54 is(handledCount, 4, "Wrong event count!");
michael@0 55
michael@0 56 e = document.createEvent("BeforeUnloadEvent");
michael@0 57 e.initEvent("beforeunload", true, true);
michael@0 58 window.testReturnValue = true;
michael@0 59 is(target.dispatchEvent(e), true,
michael@0 60 "beforeunload event on random element should not be prevented!");
michael@0 61 is(handledCount, 4, "Wrong event count; handler should not have run!");
michael@0 62 is(target2.dispatchEvent(e), false,
michael@0 63 "beforeunload event should be prevented!");
michael@0 64 is(handledCount, 5, "Wrong event count!");
michael@0 65 window.testReturnValue = false;
michael@0 66 is(target.dispatchEvent(e), true,
michael@0 67 "beforeunload event on random element should not be prevented (2)!");
michael@0 68 is(handledCount, 5, "Wrong event count; handler should not have run! (2)");
michael@0 69 is(target2.dispatchEvent(e), false,
michael@0 70 "beforeunload event should be prevented (2)!");
michael@0 71 is(handledCount, 6, "Wrong event count!");
michael@0 72
michael@0 73 // Create normal event for beforeunload.
michael@0 74 e = document.createEvent("Event");
michael@0 75 e.initEvent("beforeunload", true, true);
michael@0 76 window.testReturnValue = true;
michael@0 77 is(target.dispatchEvent(e), true,
michael@0 78 "beforeunload event shouldn't be prevented (3)!");
michael@0 79 is(handledCount, 6, "Wrong event count: handler should not have run(3)!");
michael@0 80 is(target2.dispatchEvent(e), true,
michael@0 81 "beforeunload event shouldn't be prevented (3)!");
michael@0 82 is(handledCount, 7, "Wrong event count!");
michael@0 83
michael@0 84 e = document.createEvent("MouseEvent");
michael@0 85 e.initEvent("mousemove", true, true);
michael@0 86 window.testReturnValue = true;
michael@0 87 is(target.dispatchEvent(e), window.testReturnValue,
michael@0 88 "mousemove event shouldn't have reverse return value handling!");
michael@0 89 is(handledCount, 8, "Wrong event count!");
michael@0 90 window.testReturnValue = false;
michael@0 91 is(target.dispatchEvent(e), window.testReturnValue,
michael@0 92 "mousemove event shouldn't have reverse return value handling (2)!");
michael@0 93 is(handledCount, 9, "Wrong event count!");
michael@0 94
michael@0 95 // Now unhook the beforeunload handler in the subframe, so we don't prompt to
michael@0 96 // unload.
michael@0 97 target2.onbeforeunload = null;
michael@0 98
michael@0 99 SimpleTest.finish();
michael@0 100 });
michael@0 101 </script>
michael@0 102 </pre>
michael@0 103 </body>
michael@0 104 </html>

mercurial