1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/docshell/test/chrome/bug396519_window.xul Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,169 @@ 1.4 +<?xml version="1.0"?> 1.5 + 1.6 +<!-- This Source Code Form is subject to the terms of the Mozilla Public 1.7 + - License, v. 2.0. If a copy of the MPL was not distributed with this 1.8 + - file, You can obtain one at http://mozilla.org/MPL/2.0/. --> 1.9 + 1.10 +<?xml-stylesheet href="chrome://global/skin" type="text/css"?> 1.11 + 1.12 +<window id="396519Test" 1.13 + xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul" 1.14 + width="600" 1.15 + height="600" 1.16 + onload="onLoad();" 1.17 + title="396519 test"> 1.18 + 1.19 + <script type="application/javascript"><![CDATA[ 1.20 + 1.21 + const LISTEN_EVENTS = ["pageshow"]; 1.22 + 1.23 + const Cc = Components.classes; 1.24 + const Ci = Components.interfaces; 1.25 + 1.26 + var gBrowser; 1.27 + var gTestCount = 0; 1.28 + var gTestsIterator; 1.29 + var gExpected = []; 1.30 + 1.31 + function ok(condition, message) { 1.32 + window.opener.wrappedJSObject.SimpleTest.ok(condition, message); 1.33 + } 1.34 + function is(a, b, message) { 1.35 + window.opener.wrappedJSObject.SimpleTest.is(a, b, message); 1.36 + } 1.37 + function finish() { 1.38 + for each (let eventType in LISTEN_EVENTS) { 1.39 + gBrowser.removeEventListener(eventType, eventListener, true); 1.40 + } 1.41 + 1.42 + window.close(); 1.43 + window.opener.wrappedJSObject.SimpleTest.finish(); 1.44 + } 1.45 + 1.46 + function onLoad() { 1.47 + gBrowser = document.getElementById("content"); 1.48 + 1.49 + for each (let eventType in LISTEN_EVENTS) { 1.50 + gBrowser.addEventListener(eventType, eventListener, true); 1.51 + } 1.52 + 1.53 + gTestsIterator = testsIterator(); 1.54 + nextTest(); 1.55 + } 1.56 + 1.57 + function eventListener(event) { 1.58 + // we're in pageshow, but we need to let that finish 1.59 + // content eviction and saving happen during pageshow, so when doTest 1.60 + // runs, we should should be in a testable state 1.61 + setTimeout(doTest, 0); 1.62 + } 1.63 + 1.64 + function doTest() { 1.65 + var history = gBrowser.webNavigation.sessionHistory; 1.66 + if (history.count == gExpected.length) { 1.67 + for (var i=0; i<history.count; i++) { 1.68 + var shEntry = history.getEntryAtIndex(i,false). 1.69 + QueryInterface(Components.interfaces.nsISHEntry); 1.70 + is(!!shEntry.contentViewer, gExpected[i], "content viewer "+i+", test "+gTestCount); 1.71 + } 1.72 + 1.73 + // Make sure none of the SHEntries share bfcache entries with one 1.74 + // another. 1.75 + for (var i = 0; i < history.count; i++) { 1.76 + for (var j = 0; j < history.count; j++) { 1.77 + if (j == i) 1.78 + continue; 1.79 + 1.80 + let shentry1 = history.getEntryAtIndex(i, false) 1.81 + .QueryInterface(Ci.nsISHEntry); 1.82 + let shentry2 = history.getEntryAtIndex(j, false) 1.83 + .QueryInterface(Ci.nsISHEntry); 1.84 + ok(!shentry1.sharesDocumentWith(shentry2), 1.85 + 'Test ' + gTestCount + ': shentry[' + i + "] shouldn't " + 1.86 + "share document with shentry[" + j + ']'); 1.87 + } 1.88 + } 1.89 + } 1.90 + else { 1.91 + is(history.count, gExpected.length, "Wrong history length in test "+gTestCount); 1.92 + } 1.93 + 1.94 + setTimeout(nextTest, 0); 1.95 + } 1.96 + 1.97 + function nextTest() { 1.98 + try { 1.99 + gTestsIterator.next(); 1.100 + } catch (err if err instanceof StopIteration) { 1.101 + finish(); 1.102 + } 1.103 + } 1.104 + 1.105 + function testsIterator() { 1.106 + 1.107 + // Tests 1 + 2: 1.108 + // Back/forward between two simple documents. Bfcache will be used. 1.109 + 1.110 + var test1Doc = "data:text/html,<html><head><title>test1</title></head>" + 1.111 + "<body>test1</body></html>"; 1.112 + 1.113 + gTestCount++; 1.114 + gExpected = [false]; 1.115 + gBrowser.loadURI(test1Doc); 1.116 + yield undefined; 1.117 + 1.118 + gTestCount++; 1.119 + gExpected = [true, false]; 1.120 + var test2Doc = test1Doc.replace(/1/,"2"); 1.121 + gBrowser.loadURI(test2Doc); 1.122 + yield undefined; 1.123 + 1.124 + gTestCount++; 1.125 + gExpected = [true, true, false]; 1.126 + gBrowser.loadURI(test1Doc); 1.127 + yield undefined; 1.128 + 1.129 + gTestCount++; 1.130 + gExpected = [true, true, true, false]; 1.131 + gBrowser.loadURI(test2Doc); 1.132 + yield undefined; 1.133 + 1.134 + gTestCount++; 1.135 + gExpected = [false, true, true, true, false]; 1.136 + gBrowser.loadURI(test1Doc); 1.137 + yield undefined; 1.138 + 1.139 + gTestCount++; 1.140 + gExpected = [false, false, true, true, true, false]; 1.141 + gBrowser.loadURI(test2Doc); 1.142 + yield undefined; 1.143 + 1.144 + gTestCount++; 1.145 + gExpected = [false, false, true, true, false, true]; 1.146 + gBrowser.goBack(); 1.147 + yield undefined; 1.148 + 1.149 + gTestCount++; 1.150 + gExpected = [false, false, true, true, true, false]; 1.151 + gBrowser.goForward(); 1.152 + yield undefined; 1.153 + 1.154 + gTestCount++; 1.155 + gExpected = [false, false, true, true, true, false]; 1.156 + gBrowser.gotoIndex(1); 1.157 + yield undefined; 1.158 + 1.159 + gTestCount++; 1.160 + gExpected = [false, true, true, true, false, false]; 1.161 + gBrowser.goBack(); 1.162 + yield undefined; 1.163 + 1.164 + gTestCount++; 1.165 + gExpected = [false, false, true, true, false, false]; 1.166 + gBrowser.gotoIndex(5); 1.167 + yield undefined; 1.168 + } 1.169 + ]]></script> 1.170 + 1.171 + <browser type="content-primary" flex="1" id="content" src="about:blank"/> 1.172 +</window>