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

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

mercurial