|
1 var testUrls = |
|
2 [ |
|
3 "data:text/html,<script>" + |
|
4 "function handle(evt) {" + |
|
5 "evt.target.removeEventListener(evt.type, handle, true);" + |
|
6 "try { alert('This should NOT appear'); } catch(e) { }" + |
|
7 "}" + |
|
8 "window.addEventListener('pagehide', handle, true);" + |
|
9 "window.addEventListener('beforeunload', handle, true);" + |
|
10 "window.addEventListener('unload', handle, true);" + |
|
11 "</script><body>Testing alert during pagehide/beforeunload/unload</body>", |
|
12 "data:text/html,<script>" + |
|
13 "function handle(evt) {" + |
|
14 "evt.target.removeEventListener(evt.type, handle, true);" + |
|
15 "try { prompt('This should NOT appear'); } catch(e) { }" + |
|
16 "}" + |
|
17 "window.addEventListener('pagehide', handle, true);" + |
|
18 "window.addEventListener('beforeunload', handle, true);" + |
|
19 "window.addEventListener('unload', handle, true);" + |
|
20 "</script><body>Testing prompt during pagehide/beforeunload/unload</body>", |
|
21 "data:text/html,<script>" + |
|
22 "function handle(evt) {" + |
|
23 "evt.target.removeEventListener(evt.type, handle, true);" + |
|
24 "try { confirm('This should NOT appear'); } catch(e) { }" + |
|
25 "}" + |
|
26 "window.addEventListener('pagehide', handle, true);" + |
|
27 "window.addEventListener('beforeunload', handle, true);" + |
|
28 "window.addEventListener('unload', handle, true);" + |
|
29 "</script><body>Testing confirm during pagehide/beforeunload/unload</body>", |
|
30 ]; |
|
31 var testsDone = 0; |
|
32 |
|
33 function test() |
|
34 { |
|
35 waitForExplicitFinish(); |
|
36 runTest(); |
|
37 } |
|
38 |
|
39 function runTest() |
|
40 { |
|
41 whenNewTabLoaded(window, function() { |
|
42 gBrowser.selectedBrowser.addEventListener("load", onLoad, true); |
|
43 executeSoon(function() { |
|
44 info("Loading page with pagehide, beforeunload, and unload handlers that attempt to create dialogs"); |
|
45 gBrowser.selectedBrowser.loadURI(testUrls[testsDone]); |
|
46 }); |
|
47 }); |
|
48 } |
|
49 |
|
50 function onLoad(event) |
|
51 { |
|
52 info("Page loaded"); |
|
53 |
|
54 event.target.removeEventListener("load", onLoad, true); |
|
55 gBrowser.selectedBrowser.addEventListener("unload", done, true); |
|
56 |
|
57 executeSoon(function () { |
|
58 info("Closing page"); |
|
59 gBrowser.removeCurrentTab(); |
|
60 }); |
|
61 } |
|
62 |
|
63 function done() { |
|
64 ok(true, "Page closed (hopefully) without timeout"); |
|
65 |
|
66 testsDone++; |
|
67 if (testsDone == testUrls.length) { |
|
68 finish(); |
|
69 return; |
|
70 } |
|
71 |
|
72 executeSoon(runTest); |
|
73 } |