docshell/test/chrome/test_bug608669.xul

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/docshell/test/chrome/test_bug608669.xul	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,117 @@
     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" type="text/css"?>
     1.7 +<!--
     1.8 +https://bugzilla.mozilla.org/show_bug.cgi?id=608669
     1.9 +-->
    1.10 +<window title="Mozilla Bug 608669"
    1.11 +  xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul">
    1.12 +  <script type="application/javascript"
    1.13 +          src="chrome://mochikit/content/tests/SimpleTest/SimpleTest.js"></script>
    1.14 +
    1.15 +  <!-- test results are displayed in the html:body -->
    1.16 +  <body xmlns="http://www.w3.org/1999/xhtml">
    1.17 +  <a href="https://bugzilla.mozilla.org/show_bug.cgi?id=608669"
    1.18 +     target="_blank">Mozilla Bug 608669</a>
    1.19 +  </body>
    1.20 +
    1.21 +  <!-- test code goes here -->
    1.22 +  <script type="application/javascript"><![CDATA[
    1.23 +
    1.24 +var gOrigMaxTotalViewers = undefined;
    1.25 +function setCachePref(enabled) {
    1.26 +  var prefBranch = Components.classes["@mozilla.org/preferences-service;1"]
    1.27 +                             .getService(Components.interfaces.nsIPrefBranch);
    1.28 +  if (enabled) {
    1.29 +    is(typeof gOrigMaxTotalViewers, "undefined", "don't double-enable bfcache");
    1.30 +    prefBranch.setBoolPref("browser.sessionhistory.cache_subframes", true);
    1.31 +    gOrigMaxTotalViewers = prefBranch.getIntPref("browser.sessionhistory.max_total_viewers");
    1.32 +    prefBranch.setIntPref("browser.sessionhistory.max_total_viewers", 10);
    1.33 +  }
    1.34 +  else {
    1.35 +    is(typeof gOrigMaxTotalViewers, "number", "don't double-disable bfcache");
    1.36 +    prefBranch.setIntPref("browser.sessionhistory.max_total_viewers", gOrigMaxTotalViewers);
    1.37 +    gOrigMaxTotalViewers = undefined;
    1.38 +    try {
    1.39 +      prefBranch.clearUserPref("browser.sessionhistory.cache_subframes");
    1.40 +    } catch (e) { /* Pref didn't exist, meh */ }
    1.41 +  }
    1.42 +}
    1.43 +
    1.44 +
    1.45 +/** Test for Bug 608669 **/
    1.46 +SimpleTest.waitForExplicitFinish();
    1.47 +
    1.48 +addLoadEvent(nextTest);
    1.49 +
    1.50 +gen = doTest();
    1.51 +
    1.52 +function nextTest() {
    1.53 +  gen.next();
    1.54 +}
    1.55 +
    1.56 +function doTest() {
    1.57 +  var container = document.getElementById('container');
    1.58 +
    1.59 +  setCachePref(true);
    1.60 +
    1.61 +  var notificationCount = 0;
    1.62 +  var observer = {
    1.63 +    observe: function(aSubject, aTopic, aData) {
    1.64 +      is(aTopic, "chrome-document-global-created",
    1.65 +         "correct topic");
    1.66 +      is(aData, "null",
    1.67 +         "correct data");
    1.68 +      notificationCount++;
    1.69 +    }
    1.70 +  };
    1.71 +
    1.72 +  var os = Components.classes["@mozilla.org/observer-service;1"].
    1.73 +    getService(Components.interfaces.nsIObserverService);
    1.74 +  os.addObserver(observer, "chrome-document-global-created", false);
    1.75 +  os.addObserver(observer, "content-document-global-created", false);
    1.76 +
    1.77 +  is(notificationCount, 0, "initial count");
    1.78 +
    1.79 +  // create a new iframe
    1.80 +  var iframe = document.createElement("iframe");
    1.81 +  container.appendChild(iframe);
    1.82 +  iframe.contentWindow.x = "y";
    1.83 +  is(notificationCount, 1, "after created iframe");
    1.84 +  
    1.85 +  // Try loading in an iframe
    1.86 +  iframe.setAttribute("src", "bug608669.xul");
    1.87 +  iframe.onload = nextTest;
    1.88 +  yield undefined;
    1.89 +  is(notificationCount, 1, "after first load");
    1.90 +  is(iframe.contentWindow.x, "y", "reused window");
    1.91 +
    1.92 +  // Try loading again in an iframe
    1.93 +  iframe.setAttribute("src", "bug608669.xul?x");
    1.94 +  iframe.onload = nextTest;
    1.95 +  yield undefined;
    1.96 +  is(notificationCount, 2, "after second load");
    1.97 +  is("x" in iframe.contentWindow, false, "didn't reuse window");
    1.98 +
    1.99 +  // Open a new window using window.open
   1.100 +  popup = window.open("bug608669.xul", "bug 608669",
   1.101 +                      "chrome,width=600,height=600");
   1.102 +  popup.onload = nextTest;
   1.103 +  yield undefined;
   1.104 +  is(notificationCount, 3, "after window.open load");
   1.105 +  popup.close();
   1.106 +
   1.107 +  setCachePref(false);
   1.108 +  os.removeObserver(observer, "chrome-document-global-created");
   1.109 +  os.removeObserver(observer, "content-document-global-created");
   1.110 +  SimpleTest.finish();
   1.111 +  yield undefined;
   1.112 +}
   1.113 +
   1.114 +
   1.115 +
   1.116 +  ]]></script>
   1.117 +  <vbox id="container" flex="1">
   1.118 +    <description>Below will an iframe be added</description>
   1.119 +  </vbox>
   1.120 +</window>

mercurial