Wed, 31 Dec 2014 06:09:35 +0100
Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.
1 /* This Source Code Form is subject to the terms of the Mozilla Public
2 * License, v. 2.0. If a copy of the MPL was not distributed with this
3 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
5 let HTTPROOT = "http://example.com/browser/browser/base/content/test/general/";
7 function maxSnapshotOverride() {
8 return 5;
9 }
11 function test() {
12 waitForExplicitFinish();
14 BrowserOpenTab();
15 let tab = gBrowser.selectedTab;
16 registerCleanupFunction(function () { gBrowser.removeTab(tab); });
18 ok(gHistorySwipeAnimation, "gHistorySwipeAnimation exists.");
20 if (!gHistorySwipeAnimation._isSupported()) {
21 is(gHistorySwipeAnimation.active, false, "History swipe animation is not " +
22 "active when not supported by the platform.");
23 finish();
24 return;
25 }
27 gHistorySwipeAnimation._getMaxSnapshots = maxSnapshotOverride;
28 gHistorySwipeAnimation.init();
30 is(gHistorySwipeAnimation.active, true, "History swipe animation support " +
31 "was successfully initialized when supported.");
33 cleanupArray();
34 load(gBrowser.selectedTab, HTTPROOT + "browser_bug678392-2.html", test0);
35 }
37 function load(aTab, aUrl, aCallback) {
38 aTab.linkedBrowser.addEventListener("load", function onload(aEvent) {
39 aEvent.currentTarget.removeEventListener("load", onload, true);
40 waitForFocus(aCallback, content);
41 }, true);
42 aTab.linkedBrowser.loadURI(aUrl);
43 }
45 function cleanupArray() {
46 let arr = gHistorySwipeAnimation._trackedSnapshots;
47 while (arr.length > 0) {
48 delete arr[0].browser.snapshots[arr[0].index]; // delete actual snapshot
49 arr.splice(0, 1);
50 }
51 }
53 function testArrayCleanup() {
54 // Test cleanup of array of tracked snapshots.
55 let arr = gHistorySwipeAnimation._trackedSnapshots;
56 is(arr.length, 0, "Snapshots were removed correctly from the array of " +
57 "tracked snapshots.");
58 }
60 function test0() {
61 // Test growing of array of tracked snapshots.
62 let tab = gBrowser.selectedTab;
64 load(tab, HTTPROOT + "browser_bug678392-1.html", function() {
65 ok(gHistorySwipeAnimation._trackedSnapshots, "Array for snapshot " +
66 "tracking is initialized.");
67 is(gHistorySwipeAnimation._trackedSnapshots.length, 1, "Snapshot array " +
68 "has correct length of 1 after loading one page.");
69 load(tab, HTTPROOT + "browser_bug678392-2.html", function() {
70 is(gHistorySwipeAnimation._trackedSnapshots.length, 2, "Snapshot array " +
71 " has correct length of 2 after loading two pages.");
72 load(tab, HTTPROOT + "browser_bug678392-1.html", function() {
73 is(gHistorySwipeAnimation._trackedSnapshots.length, 3, "Snapshot " +
74 "array has correct length of 3 after loading three pages.");
75 load(tab, HTTPROOT + "browser_bug678392-2.html", function() {
76 is(gHistorySwipeAnimation._trackedSnapshots.length, 4, "Snapshot " +
77 "array has correct length of 4 after loading four pages.");
78 cleanupArray();
79 testArrayCleanup();
80 test1();
81 });
82 });
83 });
84 });
85 }
87 function verifyRefRemoved(aIndex, aBrowser) {
88 let wasFound = false;
89 let arr = gHistorySwipeAnimation._trackedSnapshots;
90 for (let i = 0; i < arr.length; i++) {
91 if (arr[i].index == aIndex && arr[i].browser == aBrowser)
92 wasFound = true;
93 }
94 is(wasFound, false, "The reference that was previously removed was " +
95 "still found in the array of tracked snapshots.");
96 }
98 function test1() {
99 // Test presence of snpashots in per-tab array of snapshots and removal of
100 // individual snapshots (and corresponding references in the array of
101 // tracked snapshots).
102 let tab = gBrowser.selectedTab;
104 load(tab, HTTPROOT + "browser_bug678392-1.html", function() {
105 var historyIndex = gBrowser.webNavigation.sessionHistory.index - 1;
106 load(tab, HTTPROOT + "browser_bug678392-2.html", function() {
107 load(tab, HTTPROOT + "browser_bug678392-1.html", function() {
108 load(tab, HTTPROOT + "browser_bug678392-2.html", function() {
109 let browser = gBrowser.selectedBrowser;
110 ok(browser.snapshots, "Array of snapshots exists in browser.");
111 ok(browser.snapshots[historyIndex], "First page exists in snapshot " +
112 "array.");
113 ok(browser.snapshots[historyIndex + 1], "Second page exists in " +
114 "snapshot array.");
115 ok(browser.snapshots[historyIndex + 2], "Third page exists in " +
116 "snapshot array.");
117 ok(browser.snapshots[historyIndex + 3], "Fourth page exists in " +
118 "snapshot array.");
119 is(gHistorySwipeAnimation._trackedSnapshots.length, 4, "Length of " +
120 "array of tracked snapshots is equal to 4 after loading four " +
121 "pages.");
123 // Test removal of reference in the middle of the array.
124 gHistorySwipeAnimation._removeTrackedSnapshot(historyIndex + 1,
125 browser);
126 verifyRefRemoved(historyIndex + 1, browser);
127 is(gHistorySwipeAnimation._trackedSnapshots.length, 3, "Length of " +
128 "array of tracked snapshots is equal to 3 after removing one" +
129 "reference from the array with length 4.");
131 // Test removal of reference at end of array.
132 gHistorySwipeAnimation._removeTrackedSnapshot(historyIndex + 3,
133 browser);
134 verifyRefRemoved(historyIndex + 3, browser);
135 is(gHistorySwipeAnimation._trackedSnapshots.length, 2, "Length of " +
136 "array of tracked snapshots is equal to 2 after removing two" +
137 "references from the array with length 4.");
139 // Test removal of reference at head of array.
140 gHistorySwipeAnimation._removeTrackedSnapshot(historyIndex,
141 browser);
142 verifyRefRemoved(historyIndex, browser);
143 is(gHistorySwipeAnimation._trackedSnapshots.length, 1, "Length of " +
144 "array of tracked snapshots is equal to 1 after removing three" +
145 "references from the array with length 4.");
147 cleanupArray();
148 test2();
149 });
150 });
151 });
152 });
153 }
155 function test2() {
156 // Test growing of snapshot array across tabs.
157 let tab = gBrowser.selectedTab;
159 load(tab, HTTPROOT + "browser_bug678392-1.html", function() {
160 var historyIndex = gBrowser.webNavigation.sessionHistory.index - 1;
161 load(tab, HTTPROOT + "browser_bug678392-2.html", function() {
162 is(gHistorySwipeAnimation._trackedSnapshots.length, 2, "Length of " +
163 "snapshot array is equal to 2 after loading two pages");
164 let prevTab = tab;
165 tab = gBrowser.addTab("about:newtab");
166 gBrowser.selectedTab = tab;
167 load(tab, HTTPROOT + "browser_bug678392-2.html" /* initial page */,
168 function() {
169 load(tab, HTTPROOT + "browser_bug678392-1.html", function() {
170 load(tab, HTTPROOT + "browser_bug678392-2.html", function() {
171 is(gHistorySwipeAnimation._trackedSnapshots.length, 4, "Length " +
172 "of snapshot array is equal to 4 after loading two pages in " +
173 "two tabs each.");
174 gBrowser.removeCurrentTab();
175 gBrowser.selectedTab = prevTab;
176 cleanupArray();
177 test3();
178 });
179 });
180 });
181 });
182 });
183 }
185 function test3() {
186 // Test uninit of gHistorySwipeAnimation.
187 // This test MUST be the last one to execute.
188 gHistorySwipeAnimation.uninit();
189 is(gHistorySwipeAnimation.active, false, "History swipe animation support " +
190 "was successfully uninitialized");
191 finish();
192 }