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