docshell/test/chrome/bug449778_window.xul

changeset 0
6474c204b198
equal deleted inserted replaced
-1:000000000000 0:9752185327d3
1 <?xml version="1.0"?>
2 <?xml-stylesheet href="chrome://global/skin" type="text/css"?>
3 <window title="Mozilla Bug 449778" onload="doTheTest()"
4 xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul">
5
6 <hbox id="parent">
7 </hbox>
8
9 <!-- test code goes here -->
10 <script type="application/javascript"><![CDATA[
11 var imports = [ "SimpleTest", "is", "isnot", "ok", "onerror" ];
12 for each (var name in imports) {
13 window[name] = window.opener.wrappedJSObject[name];
14 }
15
16 function $(id) {
17 return document.getElementById(id);
18 }
19
20 function addBrowser(parent, id, width, height) {
21 var b =
22 document.createElementNS("http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul", "browser");
23 b.setAttribute("type", "content");
24 b.setAttribute("id", id);
25 b.setAttribute("width", width);
26 b.setAttribute("height", height);
27 $(parent).appendChild(b);
28 }
29 addBrowser("parent", "f1", 300, 200);
30 addBrowser("parent", "f2", 300, 200);
31
32 /** Test for Bug 449778 **/
33 var doc1 = "data:text/html,<html><body>This is a test</body></html>";
34 var doc2 = "data:text/html,<html><body>This is a second test</body></html>";
35 var doc3 = "data:text/html,<html><body>This is a <script>var evt = document.createEvent('Events'); evt.initEvent('testEvt', true, true); document.dispatchEvent(evt);</script>third test</body></html>";
36
37
38 $("f1").setAttribute("src", doc1);
39 $("f2").setAttribute("src", doc2);
40
41 function doTheTest() {
42 var strs = { "f1": "", "f2" : "" };
43 function attachListener(node, type) {
44 var listener = function(e) {
45 if (strs[node.id]) strs[node.id] += " ";
46 strs[node.id] += node.id + ".page" + type;
47 }
48 node.addEventListener("page" + type, listener, false);
49
50 listener.detach = function() {
51 node.removeEventListener("page" + type, listener, false);
52 }
53 return listener;
54 }
55
56 var l1 = attachListener($("f1"), "show");
57 var l2 = attachListener($("f1"), "hide");
58 var l3 = attachListener($("f2"), "show");
59 var l4 = attachListener($("f2"), "hide");
60
61 $("f1").swapDocShells($("f2"));
62
63 is(strs["f1"], "f1.pagehide f1.pageshow",
64 "Expected hide then show on first loaded page");
65 is(strs["f2"], "f2.pagehide f2.pageshow",
66 "Expected hide then show on second loaded page");
67
68 function listener2() {
69 $("f2").removeEventListener("testEvt", listener2, false);
70
71 strs = { "f1": "", "f2" : "" };
72
73 $("f1").swapDocShells($("f2"));
74 is(strs["f1"], "f1.pagehide",
75 "Expected hide on already-loaded page, then nothing");
76 is(strs["f2"], "f2.pageshow f2.pagehide f2.pageshow",
77 "Expected show on still-loading page, then hide on it, then show " +
78 "on already-loaded page");
79
80 strs = { "f1": "", "f2" : "" };
81
82 $("f1").addEventListener("pageshow", listener3, false);
83 }
84
85 function listener3() {
86 $("f1").removeEventListener("pageshow", listener3, false);
87
88 is(strs["f1"], "f1.pageshow",
89 "Expected show as our page finishes loading");
90 is(strs["f2"], "", "Expected no more events here.");
91
92 l1.detach();
93 l2.detach();
94 l3.detach();
95 l4.detach();
96
97 window.close();
98 SimpleTest.finish();
99 }
100
101 $("f2").addEventListener("testEvt", listener2, false, true);
102 $("f2").setAttribute("src", doc3);
103 }
104
105 ]]></script>
106 </window>

mercurial