docshell/test/chrome/bug396519_window.xul

Wed, 31 Dec 2014 06:09:35 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Wed, 31 Dec 2014 06:09:35 +0100
changeset 0
6474c204b198
permissions
-rw-r--r--

Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.

michael@0 1 <?xml version="1.0"?>
michael@0 2
michael@0 3 <!-- This Source Code Form is subject to the terms of the Mozilla Public
michael@0 4 - License, v. 2.0. If a copy of the MPL was not distributed with this
michael@0 5 - file, You can obtain one at http://mozilla.org/MPL/2.0/. -->
michael@0 6
michael@0 7 <?xml-stylesheet href="chrome://global/skin" type="text/css"?>
michael@0 8
michael@0 9 <window id="396519Test"
michael@0 10 xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul"
michael@0 11 width="600"
michael@0 12 height="600"
michael@0 13 onload="onLoad();"
michael@0 14 title="396519 test">
michael@0 15
michael@0 16 <script type="application/javascript"><![CDATA[
michael@0 17
michael@0 18 const LISTEN_EVENTS = ["pageshow"];
michael@0 19
michael@0 20 const Cc = Components.classes;
michael@0 21 const Ci = Components.interfaces;
michael@0 22
michael@0 23 var gBrowser;
michael@0 24 var gTestCount = 0;
michael@0 25 var gTestsIterator;
michael@0 26 var gExpected = [];
michael@0 27
michael@0 28 function ok(condition, message) {
michael@0 29 window.opener.wrappedJSObject.SimpleTest.ok(condition, message);
michael@0 30 }
michael@0 31 function is(a, b, message) {
michael@0 32 window.opener.wrappedJSObject.SimpleTest.is(a, b, message);
michael@0 33 }
michael@0 34 function finish() {
michael@0 35 for each (let eventType in LISTEN_EVENTS) {
michael@0 36 gBrowser.removeEventListener(eventType, eventListener, true);
michael@0 37 }
michael@0 38
michael@0 39 window.close();
michael@0 40 window.opener.wrappedJSObject.SimpleTest.finish();
michael@0 41 }
michael@0 42
michael@0 43 function onLoad() {
michael@0 44 gBrowser = document.getElementById("content");
michael@0 45
michael@0 46 for each (let eventType in LISTEN_EVENTS) {
michael@0 47 gBrowser.addEventListener(eventType, eventListener, true);
michael@0 48 }
michael@0 49
michael@0 50 gTestsIterator = testsIterator();
michael@0 51 nextTest();
michael@0 52 }
michael@0 53
michael@0 54 function eventListener(event) {
michael@0 55 // we're in pageshow, but we need to let that finish
michael@0 56 // content eviction and saving happen during pageshow, so when doTest
michael@0 57 // runs, we should should be in a testable state
michael@0 58 setTimeout(doTest, 0);
michael@0 59 }
michael@0 60
michael@0 61 function doTest() {
michael@0 62 var history = gBrowser.webNavigation.sessionHistory;
michael@0 63 if (history.count == gExpected.length) {
michael@0 64 for (var i=0; i<history.count; i++) {
michael@0 65 var shEntry = history.getEntryAtIndex(i,false).
michael@0 66 QueryInterface(Components.interfaces.nsISHEntry);
michael@0 67 is(!!shEntry.contentViewer, gExpected[i], "content viewer "+i+", test "+gTestCount);
michael@0 68 }
michael@0 69
michael@0 70 // Make sure none of the SHEntries share bfcache entries with one
michael@0 71 // another.
michael@0 72 for (var i = 0; i < history.count; i++) {
michael@0 73 for (var j = 0; j < history.count; j++) {
michael@0 74 if (j == i)
michael@0 75 continue;
michael@0 76
michael@0 77 let shentry1 = history.getEntryAtIndex(i, false)
michael@0 78 .QueryInterface(Ci.nsISHEntry);
michael@0 79 let shentry2 = history.getEntryAtIndex(j, false)
michael@0 80 .QueryInterface(Ci.nsISHEntry);
michael@0 81 ok(!shentry1.sharesDocumentWith(shentry2),
michael@0 82 'Test ' + gTestCount + ': shentry[' + i + "] shouldn't " +
michael@0 83 "share document with shentry[" + j + ']');
michael@0 84 }
michael@0 85 }
michael@0 86 }
michael@0 87 else {
michael@0 88 is(history.count, gExpected.length, "Wrong history length in test "+gTestCount);
michael@0 89 }
michael@0 90
michael@0 91 setTimeout(nextTest, 0);
michael@0 92 }
michael@0 93
michael@0 94 function nextTest() {
michael@0 95 try {
michael@0 96 gTestsIterator.next();
michael@0 97 } catch (err if err instanceof StopIteration) {
michael@0 98 finish();
michael@0 99 }
michael@0 100 }
michael@0 101
michael@0 102 function testsIterator() {
michael@0 103
michael@0 104 // Tests 1 + 2:
michael@0 105 // Back/forward between two simple documents. Bfcache will be used.
michael@0 106
michael@0 107 var test1Doc = "data:text/html,<html><head><title>test1</title></head>" +
michael@0 108 "<body>test1</body></html>";
michael@0 109
michael@0 110 gTestCount++;
michael@0 111 gExpected = [false];
michael@0 112 gBrowser.loadURI(test1Doc);
michael@0 113 yield undefined;
michael@0 114
michael@0 115 gTestCount++;
michael@0 116 gExpected = [true, false];
michael@0 117 var test2Doc = test1Doc.replace(/1/,"2");
michael@0 118 gBrowser.loadURI(test2Doc);
michael@0 119 yield undefined;
michael@0 120
michael@0 121 gTestCount++;
michael@0 122 gExpected = [true, true, false];
michael@0 123 gBrowser.loadURI(test1Doc);
michael@0 124 yield undefined;
michael@0 125
michael@0 126 gTestCount++;
michael@0 127 gExpected = [true, true, true, false];
michael@0 128 gBrowser.loadURI(test2Doc);
michael@0 129 yield undefined;
michael@0 130
michael@0 131 gTestCount++;
michael@0 132 gExpected = [false, true, true, true, false];
michael@0 133 gBrowser.loadURI(test1Doc);
michael@0 134 yield undefined;
michael@0 135
michael@0 136 gTestCount++;
michael@0 137 gExpected = [false, false, true, true, true, false];
michael@0 138 gBrowser.loadURI(test2Doc);
michael@0 139 yield undefined;
michael@0 140
michael@0 141 gTestCount++;
michael@0 142 gExpected = [false, false, true, true, false, true];
michael@0 143 gBrowser.goBack();
michael@0 144 yield undefined;
michael@0 145
michael@0 146 gTestCount++;
michael@0 147 gExpected = [false, false, true, true, true, false];
michael@0 148 gBrowser.goForward();
michael@0 149 yield undefined;
michael@0 150
michael@0 151 gTestCount++;
michael@0 152 gExpected = [false, false, true, true, true, false];
michael@0 153 gBrowser.gotoIndex(1);
michael@0 154 yield undefined;
michael@0 155
michael@0 156 gTestCount++;
michael@0 157 gExpected = [false, true, true, true, false, false];
michael@0 158 gBrowser.goBack();
michael@0 159 yield undefined;
michael@0 160
michael@0 161 gTestCount++;
michael@0 162 gExpected = [false, false, true, true, false, false];
michael@0 163 gBrowser.gotoIndex(5);
michael@0 164 yield undefined;
michael@0 165 }
michael@0 166 ]]></script>
michael@0 167
michael@0 168 <browser type="content-primary" flex="1" id="content" src="about:blank"/>
michael@0 169 </window>

mercurial