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