|
1 <?xml version="1.0"?> |
|
2 <?xml-stylesheet href="chrome://global/skin" type="text/css"?> |
|
3 <?xml-stylesheet href="chrome://mochikit/content/tests/SimpleTest/test.css" |
|
4 type="text/css"?> |
|
5 |
|
6 <!-- |
|
7 Any copyright is dedicated to the Public Domain. |
|
8 http://creativecommons.org/publicdomain/zero/1.0/ |
|
9 --> |
|
10 <window title="Test SharedFrame - Bug 811247" |
|
11 xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul" |
|
12 onload="runTest();"> |
|
13 |
|
14 <script type="application/javascript" |
|
15 src="chrome://mochikit/content/tests/SimpleTest/SimpleTest.js"/> |
|
16 <script type="application/javascript" |
|
17 src="chrome://mochikit/content/tests/SimpleTest/EventUtils.js"/> |
|
18 <script type="application/javascript"> |
|
19 <![CDATA[ |
|
20 |
|
21 function is(a,b,c) opener.wrappedJSObject.is(a,b,c); |
|
22 function ok(a,b) opener.wrappedJSObject.ok(a,b); |
|
23 function done() opener.wrappedJSObject.done(); |
|
24 |
|
25 Components.utils.import("resource:///modules/SharedFrame.jsm"); |
|
26 ok(SharedFrame, "SharedFrame module exists"); |
|
27 |
|
28 let box, gGen; |
|
29 function runTest() { |
|
30 box = document.getElementById("frames-container"); |
|
31 gGen = test_module(); |
|
32 gGen.next(); |
|
33 } |
|
34 |
|
35 function test_module() { |
|
36 // note: no 'src' attribute means aPreload = false; |
|
37 let frame1 = SharedFrame.createFrame("group1", box, {id: "group1-frame1", type: "content"}); |
|
38 let frame2 = SharedFrame.createFrame("group1", box, {id: "group1-frame2", type: "content"}); |
|
39 let frame3 = SharedFrame.createFrame("group1", box, {id: "group1-frame3", type: "content"}); |
|
40 |
|
41 // Check proper attribute assignment |
|
42 is(frame1.id, "group1-frame1", "correct id"); |
|
43 is(frame2.id, "group1-frame2", "correct id"); |
|
44 is(frame3.id, "group1-frame3", "correct id"); |
|
45 |
|
46 is(frame1.getAttribute("type"), "content", "correct type"); |
|
47 is(frame2.getAttribute("type"), "content", "correct type"); |
|
48 is(frame3.getAttribute("type"), "content", "correct type"); |
|
49 |
|
50 //-------------------------- |
|
51 yield waitForLoad([frame1, frame2, frame3]); |
|
52 |
|
53 // Check for unloaded in the src URL |
|
54 ok(/Unloaded/.test(frame1.contentDocument.location), "frame 1 is unloaded"); |
|
55 ok(/Unloaded/.test(frame2.contentDocument.location), "frame 2 is unloaded"); |
|
56 ok(/Unloaded/.test(frame3.contentDocument.location), "frame 3 is unloaded"); |
|
57 |
|
58 // Check that there is no frame alive in the group |
|
59 ok(!SharedFrame.isGroupAlive("group1"), "group 1 is not alive"); |
|
60 |
|
61 // Set the URL and load the group |
|
62 SharedFrame.updateURL("group1", "http://www.example.com"); |
|
63 SharedFrame.preload("group1", frame1); |
|
64 |
|
65 //-------------------------- |
|
66 yield waitForLoad([frame1]); |
|
67 |
|
68 // Check that frame 1 was properly loaded and the group is alive |
|
69 ok(SharedFrame.isGroupAlive("group1"), "group 1 is now alive"); |
|
70 ok(!/Unloaded/.test(frame1.contentDocument.location), "frame 1 is now loaded"); |
|
71 ok(/Unloaded/.test(frame2.contentDocument.location), "frame 2 is unloaded"); |
|
72 ok(/Unloaded/.test(frame3.contentDocument.location), "frame 3 is unloaded"); |
|
73 |
|
74 // Move content to frame 2 |
|
75 SharedFrame.setOwner("group1", frame2); |
|
76 |
|
77 ok(/Unloaded/.test(frame1.contentDocument.location), "frame 1 is unloaded"); |
|
78 ok(!/Unloaded/.test(frame2.contentDocument.location), "content was transfered to frame 2"); |
|
79 ok(/Unloaded/.test(frame3.contentDocument.location), "frame 3 is unloaded"); |
|
80 |
|
81 // Update URL and check that new content got loaded |
|
82 SharedFrame.updateURL("group1", "http://www.example.com/new"); |
|
83 |
|
84 //-------------------------- |
|
85 yield waitForLoad([frame2]); |
|
86 |
|
87 ok(/new$/.test(frame2.contentDocument.location), "new url loaded"); |
|
88 |
|
89 // Now remove the loaded content and check if the group is properly reported as unloaded |
|
90 box.removeChild(frame2); |
|
91 ok(!SharedFrame.isGroupAlive("group1"), "group 1 is not alive"); |
|
92 |
|
93 // And see if setOwnering will reload the group |
|
94 SharedFrame.setOwner("group1", frame3); |
|
95 |
|
96 //-------------------------- |
|
97 yield waitForLoad([frame3]); |
|
98 |
|
99 ok(SharedFrame.isGroupAlive("group1"), "group 1 is alive"); |
|
100 ok(/new$/.test(frame3.contentDocument.location), "content was transfered to frame 3"); |
|
101 |
|
102 // Create a second group to verify it doesn't interact with the first one. Also test |
|
103 // that preloading works |
|
104 let frame4 = SharedFrame.createFrame("group2", box, {src: "http://www.example.com/group2", type: "content"}); |
|
105 let frame5 = SharedFrame.createFrame("group2", box, {src: "http://www.example.com/group2", type: "content"}); |
|
106 |
|
107 //-------------------------- |
|
108 yield waitForLoad([frame4, frame5]); |
|
109 |
|
110 ok(SharedFrame.isGroupAlive("group2"), "group 2 was preloaded due to the src attribute"); |
|
111 |
|
112 // Check for unloaded in the src URL |
|
113 ok(/group2$/.test(frame4.contentDocument.location), "frame 4 is loaded"); |
|
114 ok(/Unloaded/.test(frame5.contentDocument.location), "frame 5 is unloaded"); |
|
115 |
|
116 SharedFrame.setOwner("group2", frame5); |
|
117 |
|
118 ok(/Unloaded/.test(frame4.contentDocument.location), "frame 4 is unloaded"); |
|
119 ok(/group2$/.test(frame5.contentDocument.location), "frame 5 is loaded"); |
|
120 |
|
121 SharedFrame.updateURL("group2", "http://www.example.com/new2"); |
|
122 |
|
123 //-------------------------- |
|
124 yield waitForLoad([frame5]); |
|
125 |
|
126 ok(/new2$/.test(frame5.contentDocument.location), "frame 5 changed"); |
|
127 ok(/Unloaded/.test(frame1.contentDocument.location), "frame 1 still has its previous value"); |
|
128 ok(/new$/.test(frame3.contentDocument.location), "frame 3 still has its previous value"); |
|
129 |
|
130 //And now check that aPreload parameter works |
|
131 let frame7 = SharedFrame.createFrame("group3", box, {src: "http://www.example.com/group3", type: "content"}, false); |
|
132 |
|
133 //-------------------------- |
|
134 yield waitForLoad([frame7]); |
|
135 |
|
136 ok(!SharedFrame.isGroupAlive("group3"), "aPreload = false works"); |
|
137 ok(/Unloaded/.test(frame7.contentDocument.location), "frame 7 is unloaded"); |
|
138 |
|
139 let frame8 = SharedFrame.createFrame("group3", box, {src: "http://www.example.com/group3", type: "content"}); |
|
140 |
|
141 //-------------------------- |
|
142 yield waitForLoad([frame8]); |
|
143 |
|
144 ok(SharedFrame.isGroupAlive("group3"), "aPreload defauls to true"); |
|
145 ok(/group3/.test(frame8.contentDocument.location), "aPreload + src loads/reloads group"); |
|
146 |
|
147 done(); |
|
148 } |
|
149 |
|
150 |
|
151 function waitForLoad(frames) { |
|
152 let count = frames.length; |
|
153 for (let frame of frames) { |
|
154 let f = frame; |
|
155 f.addEventListener("DOMContentLoaded", function frameloaded(event) { |
|
156 f.removeEventListener("DOMContentLoaded", frameloaded, false); |
|
157 if (--count == 0) { |
|
158 try { gGen.next() } catch (ex if ex instanceof StopIteration) { } |
|
159 } |
|
160 }, false); |
|
161 } |
|
162 } |
|
163 ]]> |
|
164 </script> |
|
165 |
|
166 <box id="frames-container"/> |
|
167 |
|
168 <body xmlns="http://www.w3.org/1999/xhtml"> |
|
169 <p id="display"></p> |
|
170 <div id="content" style="display:none;"></div> |
|
171 <pre id="test"></pre> |
|
172 </body> |
|
173 <label id="test-result"/> |
|
174 </window> |