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