browser/components/sessionstore/test/browser_480148.js

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 /* 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 function test() {
michael@0 6 /** Test for Bug 484108 **/
michael@0 7 waitForExplicitFinish();
michael@0 8 requestLongerTimeout(5);
michael@0 9
michael@0 10 // builds the tests state based on a few parameters
michael@0 11 function buildTestState(num, selected, hidden, pinned) {
michael@0 12 let state = { windows: [ { "tabs": [], "selected": selected + 1 } ] };
michael@0 13 while (num--) {
michael@0 14 state.windows[0].tabs.push({
michael@0 15 entries: [
michael@0 16 { url: "http://example.com/?t=" + state.windows[0].tabs.length }
michael@0 17 ]
michael@0 18 });
michael@0 19 let i = state.windows[0].tabs.length - 1;
michael@0 20 if (hidden.length > 0 && i == hidden[0]) {
michael@0 21 state.windows[0].tabs[i].hidden = true;
michael@0 22 hidden.splice(0, 1);
michael@0 23 }
michael@0 24 if (pinned.length > 0 && i == pinned[0]) {
michael@0 25 state.windows[0].tabs[i].pinned = true;
michael@0 26 pinned.splice(0, 1);
michael@0 27 }
michael@0 28 }
michael@0 29 return state;
michael@0 30 }
michael@0 31
michael@0 32 let tests = [
michael@0 33 { testNum: 1,
michael@0 34 totalTabs: 13,
michael@0 35 selectedTab: 0,
michael@0 36 shownTabs: 6,
michael@0 37 hiddenTabs: [],
michael@0 38 pinnedTabs: [],
michael@0 39 order: [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12]
michael@0 40 },
michael@0 41 { testNum: 2,
michael@0 42 totalTabs: 13,
michael@0 43 selectedTab: 12,
michael@0 44 shownTabs: 6,
michael@0 45 hiddenTabs: [],
michael@0 46 pinnedTabs: [],
michael@0 47 order: [12, 7, 8, 9, 10, 11, 0, 1, 2, 3, 4, 5, 6]
michael@0 48 },
michael@0 49 { testNum: 3,
michael@0 50 totalTabs: 13,
michael@0 51 selectedTab: 3,
michael@0 52 shownTabs: 6,
michael@0 53 hiddenTabs: [],
michael@0 54 pinnedTabs: [],
michael@0 55 order: [3, 4, 5, 6, 7, 8, 0, 1, 2, 9, 10, 11, 12]
michael@0 56 },
michael@0 57 { testNum: 4,
michael@0 58 totalTabs: 13,
michael@0 59 selectedTab: 10,
michael@0 60 shownTabs: 6,
michael@0 61 hiddenTabs: [],
michael@0 62 pinnedTabs: [],
michael@0 63 order: [10, 7, 8, 9, 11, 12, 0, 1, 2, 3, 4, 5, 6]
michael@0 64 },
michael@0 65 { testNum: 5,
michael@0 66 totalTabs: 13,
michael@0 67 selectedTab: 12,
michael@0 68 shownTabs: 6,
michael@0 69 hiddenTabs: [0, 4, 9],
michael@0 70 pinnedTabs: [],
michael@0 71 order: [12, 6, 7, 8, 10, 11, 1, 2, 3, 5, 0, 4, 9]
michael@0 72 },
michael@0 73 { testNum: 6,
michael@0 74 totalTabs: 13,
michael@0 75 selectedTab: 3,
michael@0 76 shownTabs: 6,
michael@0 77 hiddenTabs: [1, 7, 12],
michael@0 78 pinnedTabs: [],
michael@0 79 order: [3, 4, 5, 6, 8, 9, 0, 2, 10, 11, 1, 7, 12]
michael@0 80 },
michael@0 81 { testNum: 7,
michael@0 82 totalTabs: 13,
michael@0 83 selectedTab: 3,
michael@0 84 shownTabs: 6,
michael@0 85 hiddenTabs: [0, 1, 2],
michael@0 86 pinnedTabs: [],
michael@0 87 order: [3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 0, 1, 2]
michael@0 88 },
michael@0 89 { testNum: 8,
michael@0 90 totalTabs: 13,
michael@0 91 selectedTab: 0,
michael@0 92 shownTabs: 6,
michael@0 93 hiddenTabs: [],
michael@0 94 pinnedTabs: [0],
michael@0 95 order: [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12]
michael@0 96 },
michael@0 97 { testNum: 9,
michael@0 98 totalTabs: 13,
michael@0 99 selectedTab: 1,
michael@0 100 shownTabs: 6,
michael@0 101 hiddenTabs: [],
michael@0 102 pinnedTabs: [0],
michael@0 103 order: [1, 0, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12]
michael@0 104 },
michael@0 105 { testNum: 10,
michael@0 106 totalTabs: 13,
michael@0 107 selectedTab: 3,
michael@0 108 shownTabs: 6,
michael@0 109 hiddenTabs: [2],
michael@0 110 pinnedTabs: [0,1],
michael@0 111 order: [3, 0, 1, 4, 5, 6, 7, 8, 9, 10, 11, 12, 2]
michael@0 112 },
michael@0 113 { testNum: 11,
michael@0 114 totalTabs: 13,
michael@0 115 selectedTab: 12,
michael@0 116 shownTabs: 6,
michael@0 117 hiddenTabs: [],
michael@0 118 pinnedTabs: [0,1,2],
michael@0 119 order: [12, 0, 1, 2, 7, 8, 9, 10, 11, 3, 4, 5, 6]
michael@0 120 },
michael@0 121 { testNum: 12,
michael@0 122 totalTabs: 13,
michael@0 123 selectedTab: 6,
michael@0 124 shownTabs: 6,
michael@0 125 hiddenTabs: [3,4,5],
michael@0 126 pinnedTabs: [0,1,2],
michael@0 127 order: [6, 0, 1, 2, 7, 8, 9, 10, 11, 12, 3, 4, 5]
michael@0 128 },
michael@0 129 { testNum: 13,
michael@0 130 totalTabs: 13,
michael@0 131 selectedTab: 1,
michael@0 132 shownTabs: 6,
michael@0 133 hiddenTabs: [3,4,5],
michael@0 134 pinnedTabs: [0,1,2],
michael@0 135 order: [1, 0, 2, 6, 7, 8, 9, 10, 11, 12, 3, 4, 5]
michael@0 136 },
michael@0 137 { testNum: 14,
michael@0 138 totalTabs: 13,
michael@0 139 selectedTab: 2,
michael@0 140 shownTabs: 6,
michael@0 141 hiddenTabs: [],
michael@0 142 pinnedTabs: [0,1,2],
michael@0 143 order: [2, 0, 1, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12]
michael@0 144 },
michael@0 145 { testNum: 15,
michael@0 146 totalTabs: 13,
michael@0 147 selectedTab: 3,
michael@0 148 shownTabs: 6,
michael@0 149 hiddenTabs: [1,4],
michael@0 150 pinnedTabs: [0,1,2],
michael@0 151 order: [3, 0, 1, 2, 5, 6, 7, 8, 9, 10, 11, 12, 4]
michael@0 152 }
michael@0 153 ];
michael@0 154
michael@0 155 let tabMinWidth =
michael@0 156 parseInt(getComputedStyle(gBrowser.selectedTab, null).minWidth);
michael@0 157 let testIndex = 0;
michael@0 158
michael@0 159 function runNextTest() {
michael@0 160 if (tests.length == 0) {
michael@0 161 finish();
michael@0 162 return;
michael@0 163 }
michael@0 164
michael@0 165 let wu = window.QueryInterface(Components.interfaces.nsIInterfaceRequestor)
michael@0 166 .getInterface(Components.interfaces.nsIDOMWindowUtils);
michael@0 167 wu.garbageCollect();
michael@0 168
michael@0 169 setTimeout(function() {
michael@0 170 info ("Starting test " + (++testIndex));
michael@0 171 let test = tests.shift();
michael@0 172 let state = buildTestState(test.totalTabs, test.selectedTab,
michael@0 173 test.hiddenTabs, test.pinnedTabs);
michael@0 174 let tabbarWidth = Math.floor((test.shownTabs - 0.5) * tabMinWidth);
michael@0 175 let win = openDialog(location, "_blank", "chrome,all,dialog=no");
michael@0 176 let tabsRestored = [];
michael@0 177
michael@0 178 win.addEventListener("SSTabRestoring", function onSSTabRestoring(aEvent) {
michael@0 179 let tab = aEvent.originalTarget;
michael@0 180 let tabLink = tab.linkedBrowser.currentURI.spec;
michael@0 181 let tabIndex =
michael@0 182 tabLink.substring(tabLink.indexOf("?t=") + 3, tabLink.length);
michael@0 183
michael@0 184 // we need to compare with the tab's restoring index, no with the
michael@0 185 // position index, since the pinned tabs change the positions in the
michael@0 186 // tabbar.
michael@0 187 tabsRestored.push(tabIndex);
michael@0 188
michael@0 189 if (tabsRestored.length < state.windows[0].tabs.length)
michael@0 190 return;
michael@0 191
michael@0 192 // all of the tabs should be restoring or restored by now
michael@0 193 is(tabsRestored.length, state.windows[0].tabs.length,
michael@0 194 "Test #" + testIndex + ": Number of restored tabs is as expected");
michael@0 195
michael@0 196 is(tabsRestored.join(" "), test.order.join(" "),
michael@0 197 "Test #" + testIndex + ": 'visible' tabs restored first");
michael@0 198
michael@0 199 // cleanup
michael@0 200 win.removeEventListener("SSTabRestoring", onSSTabRestoring, false);
michael@0 201 win.close();
michael@0 202 executeSoon(runNextTest);
michael@0 203 }, false);
michael@0 204
michael@0 205 whenWindowLoaded(win, function(aEvent) {
michael@0 206 let extent =
michael@0 207 win.outerWidth - win.gBrowser.tabContainer.mTabstrip.scrollClientSize;
michael@0 208 let windowWidth = tabbarWidth + extent;
michael@0 209 win.resizeTo(windowWidth, win.outerHeight);
michael@0 210 ss.setWindowState(win, JSON.stringify(state), true);
michael@0 211 });
michael@0 212 }, 1000);
michael@0 213 };
michael@0 214
michael@0 215 runNextTest();
michael@0 216 }

mercurial