browser/modules/test/chrome/sharedframe.xul

Thu, 22 Jan 2015 13:21:57 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Thu, 22 Jan 2015 13:21:57 +0100
branch
TOR_BUG_9701
changeset 15
b8a032363ba2
permissions
-rw-r--r--

Incorporate requested changes from Mozilla in review:
https://bugzilla.mozilla.org/show_bug.cgi?id=1123480#c6

     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"?>
     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();">
    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[
    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();
    25     Components.utils.import("resource:///modules/SharedFrame.jsm");
    26     ok(SharedFrame, "SharedFrame module exists");
    28     let box, gGen;
    29     function runTest() {
    30       box = document.getElementById("frames-container");
    31       gGen = test_module();
    32       gGen.next();
    33     }
    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"});
    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");
    46       is(frame1.getAttribute("type"), "content", "correct type");
    47       is(frame2.getAttribute("type"), "content", "correct type");
    48       is(frame3.getAttribute("type"), "content", "correct type");
    50       //--------------------------
    51       yield waitForLoad([frame1, frame2, frame3]);
    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");
    58       // Check that there is no frame alive in the group
    59       ok(!SharedFrame.isGroupAlive("group1"), "group 1 is not alive");
    61       // Set the URL and load the group
    62       SharedFrame.updateURL("group1", "http://www.example.com");
    63       SharedFrame.preload("group1", frame1);
    65       //--------------------------
    66       yield waitForLoad([frame1]);
    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");
    74       // Move content to frame 2
    75       SharedFrame.setOwner("group1", frame2);
    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");
    81       // Update URL and check that new content got loaded
    82       SharedFrame.updateURL("group1", "http://www.example.com/new");
    84       //--------------------------
    85       yield waitForLoad([frame2]);
    87       ok(/new$/.test(frame2.contentDocument.location), "new url loaded");
    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");
    93       // And see if setOwnering will reload the group
    94       SharedFrame.setOwner("group1", frame3);
    96       //--------------------------
    97       yield waitForLoad([frame3]);
    99       ok(SharedFrame.isGroupAlive("group1"), "group 1 is alive");
   100       ok(/new$/.test(frame3.contentDocument.location), "content was transfered to frame 3");
   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"});
   107       //--------------------------
   108       yield waitForLoad([frame4, frame5]);
   110       ok(SharedFrame.isGroupAlive("group2"), "group 2 was preloaded due to the src attribute");
   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");
   116       SharedFrame.setOwner("group2", frame5);
   118       ok(/Unloaded/.test(frame4.contentDocument.location), "frame 4 is unloaded");
   119       ok(/group2$/.test(frame5.contentDocument.location), "frame 5 is loaded");
   121       SharedFrame.updateURL("group2", "http://www.example.com/new2");
   123       //--------------------------
   124       yield waitForLoad([frame5]);
   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");
   130       //And now check that aPreload parameter works
   131       let frame7 = SharedFrame.createFrame("group3", box, {src: "http://www.example.com/group3", type: "content"}, false);
   133       //--------------------------
   134       yield waitForLoad([frame7]);
   136       ok(!SharedFrame.isGroupAlive("group3"), "aPreload = false works");
   137       ok(/Unloaded/.test(frame7.contentDocument.location), "frame 7 is unloaded");
   139       let frame8 = SharedFrame.createFrame("group3", box, {src: "http://www.example.com/group3", type: "content"});
   141       //--------------------------
   142       yield waitForLoad([frame8]);
   144       ok(SharedFrame.isGroupAlive("group3"), "aPreload defauls to true");
   145       ok(/group3/.test(frame8.contentDocument.location), "aPreload + src loads/reloads group");
   147       done();
   148     }
   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>
   166   <box id="frames-container"/>
   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>

mercurial