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