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