docshell/test/chrome/test_bug608669.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" type="text/css"?>
     4 <!--
     5 https://bugzilla.mozilla.org/show_bug.cgi?id=608669
     6 -->
     7 <window title="Mozilla Bug 608669"
     8   xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul">
     9   <script type="application/javascript"
    10           src="chrome://mochikit/content/tests/SimpleTest/SimpleTest.js"></script>
    12   <!-- test results are displayed in the html:body -->
    13   <body xmlns="http://www.w3.org/1999/xhtml">
    14   <a href="https://bugzilla.mozilla.org/show_bug.cgi?id=608669"
    15      target="_blank">Mozilla Bug 608669</a>
    16   </body>
    18   <!-- test code goes here -->
    19   <script type="application/javascript"><![CDATA[
    21 var gOrigMaxTotalViewers = undefined;
    22 function setCachePref(enabled) {
    23   var prefBranch = Components.classes["@mozilla.org/preferences-service;1"]
    24                              .getService(Components.interfaces.nsIPrefBranch);
    25   if (enabled) {
    26     is(typeof gOrigMaxTotalViewers, "undefined", "don't double-enable bfcache");
    27     prefBranch.setBoolPref("browser.sessionhistory.cache_subframes", true);
    28     gOrigMaxTotalViewers = prefBranch.getIntPref("browser.sessionhistory.max_total_viewers");
    29     prefBranch.setIntPref("browser.sessionhistory.max_total_viewers", 10);
    30   }
    31   else {
    32     is(typeof gOrigMaxTotalViewers, "number", "don't double-disable bfcache");
    33     prefBranch.setIntPref("browser.sessionhistory.max_total_viewers", gOrigMaxTotalViewers);
    34     gOrigMaxTotalViewers = undefined;
    35     try {
    36       prefBranch.clearUserPref("browser.sessionhistory.cache_subframes");
    37     } catch (e) { /* Pref didn't exist, meh */ }
    38   }
    39 }
    42 /** Test for Bug 608669 **/
    43 SimpleTest.waitForExplicitFinish();
    45 addLoadEvent(nextTest);
    47 gen = doTest();
    49 function nextTest() {
    50   gen.next();
    51 }
    53 function doTest() {
    54   var container = document.getElementById('container');
    56   setCachePref(true);
    58   var notificationCount = 0;
    59   var observer = {
    60     observe: function(aSubject, aTopic, aData) {
    61       is(aTopic, "chrome-document-global-created",
    62          "correct topic");
    63       is(aData, "null",
    64          "correct data");
    65       notificationCount++;
    66     }
    67   };
    69   var os = Components.classes["@mozilla.org/observer-service;1"].
    70     getService(Components.interfaces.nsIObserverService);
    71   os.addObserver(observer, "chrome-document-global-created", false);
    72   os.addObserver(observer, "content-document-global-created", false);
    74   is(notificationCount, 0, "initial count");
    76   // create a new iframe
    77   var iframe = document.createElement("iframe");
    78   container.appendChild(iframe);
    79   iframe.contentWindow.x = "y";
    80   is(notificationCount, 1, "after created iframe");
    82   // Try loading in an iframe
    83   iframe.setAttribute("src", "bug608669.xul");
    84   iframe.onload = nextTest;
    85   yield undefined;
    86   is(notificationCount, 1, "after first load");
    87   is(iframe.contentWindow.x, "y", "reused window");
    89   // Try loading again in an iframe
    90   iframe.setAttribute("src", "bug608669.xul?x");
    91   iframe.onload = nextTest;
    92   yield undefined;
    93   is(notificationCount, 2, "after second load");
    94   is("x" in iframe.contentWindow, false, "didn't reuse window");
    96   // Open a new window using window.open
    97   popup = window.open("bug608669.xul", "bug 608669",
    98                       "chrome,width=600,height=600");
    99   popup.onload = nextTest;
   100   yield undefined;
   101   is(notificationCount, 3, "after window.open load");
   102   popup.close();
   104   setCachePref(false);
   105   os.removeObserver(observer, "chrome-document-global-created");
   106   os.removeObserver(observer, "content-document-global-created");
   107   SimpleTest.finish();
   108   yield undefined;
   109 }
   113   ]]></script>
   114   <vbox id="container" flex="1">
   115     <description>Below will an iframe be added</description>
   116   </vbox>
   117 </window>

mercurial