1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/browser/modules/test/chrome/sharedframe.xul Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,174 @@ 1.4 +<?xml version="1.0"?> 1.5 +<?xml-stylesheet href="chrome://global/skin" type="text/css"?> 1.6 +<?xml-stylesheet href="chrome://mochikit/content/tests/SimpleTest/test.css" 1.7 + type="text/css"?> 1.8 + 1.9 +<!-- 1.10 + Any copyright is dedicated to the Public Domain. 1.11 + http://creativecommons.org/publicdomain/zero/1.0/ 1.12 +--> 1.13 +<window title="Test SharedFrame - Bug 811247" 1.14 + xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul" 1.15 + onload="runTest();"> 1.16 + 1.17 + <script type="application/javascript" 1.18 + src="chrome://mochikit/content/tests/SimpleTest/SimpleTest.js"/> 1.19 + <script type="application/javascript" 1.20 + src="chrome://mochikit/content/tests/SimpleTest/EventUtils.js"/> 1.21 + <script type="application/javascript"> 1.22 + <![CDATA[ 1.23 + 1.24 + function is(a,b,c) opener.wrappedJSObject.is(a,b,c); 1.25 + function ok(a,b) opener.wrappedJSObject.ok(a,b); 1.26 + function done() opener.wrappedJSObject.done(); 1.27 + 1.28 + Components.utils.import("resource:///modules/SharedFrame.jsm"); 1.29 + ok(SharedFrame, "SharedFrame module exists"); 1.30 + 1.31 + let box, gGen; 1.32 + function runTest() { 1.33 + box = document.getElementById("frames-container"); 1.34 + gGen = test_module(); 1.35 + gGen.next(); 1.36 + } 1.37 + 1.38 + function test_module() { 1.39 + // note: no 'src' attribute means aPreload = false; 1.40 + let frame1 = SharedFrame.createFrame("group1", box, {id: "group1-frame1", type: "content"}); 1.41 + let frame2 = SharedFrame.createFrame("group1", box, {id: "group1-frame2", type: "content"}); 1.42 + let frame3 = SharedFrame.createFrame("group1", box, {id: "group1-frame3", type: "content"}); 1.43 + 1.44 + // Check proper attribute assignment 1.45 + is(frame1.id, "group1-frame1", "correct id"); 1.46 + is(frame2.id, "group1-frame2", "correct id"); 1.47 + is(frame3.id, "group1-frame3", "correct id"); 1.48 + 1.49 + is(frame1.getAttribute("type"), "content", "correct type"); 1.50 + is(frame2.getAttribute("type"), "content", "correct type"); 1.51 + is(frame3.getAttribute("type"), "content", "correct type"); 1.52 + 1.53 + //-------------------------- 1.54 + yield waitForLoad([frame1, frame2, frame3]); 1.55 + 1.56 + // Check for unloaded in the src URL 1.57 + ok(/Unloaded/.test(frame1.contentDocument.location), "frame 1 is unloaded"); 1.58 + ok(/Unloaded/.test(frame2.contentDocument.location), "frame 2 is unloaded"); 1.59 + ok(/Unloaded/.test(frame3.contentDocument.location), "frame 3 is unloaded"); 1.60 + 1.61 + // Check that there is no frame alive in the group 1.62 + ok(!SharedFrame.isGroupAlive("group1"), "group 1 is not alive"); 1.63 + 1.64 + // Set the URL and load the group 1.65 + SharedFrame.updateURL("group1", "http://www.example.com"); 1.66 + SharedFrame.preload("group1", frame1); 1.67 + 1.68 + //-------------------------- 1.69 + yield waitForLoad([frame1]); 1.70 + 1.71 + // Check that frame 1 was properly loaded and the group is alive 1.72 + ok(SharedFrame.isGroupAlive("group1"), "group 1 is now alive"); 1.73 + ok(!/Unloaded/.test(frame1.contentDocument.location), "frame 1 is now loaded"); 1.74 + ok(/Unloaded/.test(frame2.contentDocument.location), "frame 2 is unloaded"); 1.75 + ok(/Unloaded/.test(frame3.contentDocument.location), "frame 3 is unloaded"); 1.76 + 1.77 + // Move content to frame 2 1.78 + SharedFrame.setOwner("group1", frame2); 1.79 + 1.80 + ok(/Unloaded/.test(frame1.contentDocument.location), "frame 1 is unloaded"); 1.81 + ok(!/Unloaded/.test(frame2.contentDocument.location), "content was transfered to frame 2"); 1.82 + ok(/Unloaded/.test(frame3.contentDocument.location), "frame 3 is unloaded"); 1.83 + 1.84 + // Update URL and check that new content got loaded 1.85 + SharedFrame.updateURL("group1", "http://www.example.com/new"); 1.86 + 1.87 + //-------------------------- 1.88 + yield waitForLoad([frame2]); 1.89 + 1.90 + ok(/new$/.test(frame2.contentDocument.location), "new url loaded"); 1.91 + 1.92 + // Now remove the loaded content and check if the group is properly reported as unloaded 1.93 + box.removeChild(frame2); 1.94 + ok(!SharedFrame.isGroupAlive("group1"), "group 1 is not alive"); 1.95 + 1.96 + // And see if setOwnering will reload the group 1.97 + SharedFrame.setOwner("group1", frame3); 1.98 + 1.99 + //-------------------------- 1.100 + yield waitForLoad([frame3]); 1.101 + 1.102 + ok(SharedFrame.isGroupAlive("group1"), "group 1 is alive"); 1.103 + ok(/new$/.test(frame3.contentDocument.location), "content was transfered to frame 3"); 1.104 + 1.105 + // Create a second group to verify it doesn't interact with the first one. Also test 1.106 + // that preloading works 1.107 + let frame4 = SharedFrame.createFrame("group2", box, {src: "http://www.example.com/group2", type: "content"}); 1.108 + let frame5 = SharedFrame.createFrame("group2", box, {src: "http://www.example.com/group2", type: "content"}); 1.109 + 1.110 + //-------------------------- 1.111 + yield waitForLoad([frame4, frame5]); 1.112 + 1.113 + ok(SharedFrame.isGroupAlive("group2"), "group 2 was preloaded due to the src attribute"); 1.114 + 1.115 + // Check for unloaded in the src URL 1.116 + ok(/group2$/.test(frame4.contentDocument.location), "frame 4 is loaded"); 1.117 + ok(/Unloaded/.test(frame5.contentDocument.location), "frame 5 is unloaded"); 1.118 + 1.119 + SharedFrame.setOwner("group2", frame5); 1.120 + 1.121 + ok(/Unloaded/.test(frame4.contentDocument.location), "frame 4 is unloaded"); 1.122 + ok(/group2$/.test(frame5.contentDocument.location), "frame 5 is loaded"); 1.123 + 1.124 + SharedFrame.updateURL("group2", "http://www.example.com/new2"); 1.125 + 1.126 + //-------------------------- 1.127 + yield waitForLoad([frame5]); 1.128 + 1.129 + ok(/new2$/.test(frame5.contentDocument.location), "frame 5 changed"); 1.130 + ok(/Unloaded/.test(frame1.contentDocument.location), "frame 1 still has its previous value"); 1.131 + ok(/new$/.test(frame3.contentDocument.location), "frame 3 still has its previous value"); 1.132 + 1.133 + //And now check that aPreload parameter works 1.134 + let frame7 = SharedFrame.createFrame("group3", box, {src: "http://www.example.com/group3", type: "content"}, false); 1.135 + 1.136 + //-------------------------- 1.137 + yield waitForLoad([frame7]); 1.138 + 1.139 + ok(!SharedFrame.isGroupAlive("group3"), "aPreload = false works"); 1.140 + ok(/Unloaded/.test(frame7.contentDocument.location), "frame 7 is unloaded"); 1.141 + 1.142 + let frame8 = SharedFrame.createFrame("group3", box, {src: "http://www.example.com/group3", type: "content"}); 1.143 + 1.144 + //-------------------------- 1.145 + yield waitForLoad([frame8]); 1.146 + 1.147 + ok(SharedFrame.isGroupAlive("group3"), "aPreload defauls to true"); 1.148 + ok(/group3/.test(frame8.contentDocument.location), "aPreload + src loads/reloads group"); 1.149 + 1.150 + done(); 1.151 + } 1.152 + 1.153 + 1.154 + function waitForLoad(frames) { 1.155 + let count = frames.length; 1.156 + for (let frame of frames) { 1.157 + let f = frame; 1.158 + f.addEventListener("DOMContentLoaded", function frameloaded(event) { 1.159 + f.removeEventListener("DOMContentLoaded", frameloaded, false); 1.160 + if (--count == 0) { 1.161 + try { gGen.next() } catch (ex if ex instanceof StopIteration) { } 1.162 + } 1.163 + }, false); 1.164 + } 1.165 + } 1.166 + ]]> 1.167 + </script> 1.168 + 1.169 + <box id="frames-container"/> 1.170 + 1.171 + <body xmlns="http://www.w3.org/1999/xhtml"> 1.172 + <p id="display"></p> 1.173 + <div id="content" style="display:none;"></div> 1.174 + <pre id="test"></pre> 1.175 + </body> 1.176 + <label id="test-result"/> 1.177 +</window>