|
1 /* Any copyright is dedicated to the Public Domain. |
|
2 http://creativecommons.org/publicdomain/zero/1.0/ */ |
|
3 |
|
4 function test() { |
|
5 let tests = []; |
|
6 |
|
7 let getContentWindow = function (aWindow) { |
|
8 return aWindow.TabView.getContentWindow(); |
|
9 } |
|
10 |
|
11 let assertOneSingleGroupItem = function (aWindow) { |
|
12 is(getContentWindow(aWindow).GroupItems.groupItems.length, 1, 'There is one single groupItem'); |
|
13 } |
|
14 |
|
15 let assertNumberOfVisibleTabs = function (aWindow, numTabs) { |
|
16 is(aWindow.gBrowser.visibleTabs.length, numTabs, 'There should be ' + numTabs + ' visible tabs'); |
|
17 } |
|
18 |
|
19 let next = function (aWindow) { |
|
20 while (aWindow.gBrowser.tabs.length-1) |
|
21 aWindow.gBrowser.removeTab(aWindow.gBrowser.tabs[1]); |
|
22 |
|
23 hideTabView(function() { |
|
24 let callback = tests.shift(); |
|
25 |
|
26 if (!callback) { |
|
27 executeSoon(function() { |
|
28 assertOneSingleGroupItem(aWindow); |
|
29 aWindow.close(); |
|
30 finish(); |
|
31 }); |
|
32 } else { |
|
33 assertOneSingleGroupItem(aWindow); |
|
34 callback(aWindow); |
|
35 } |
|
36 }, aWindow); |
|
37 } |
|
38 |
|
39 // [624265] testing undo close tab |
|
40 let testUndoCloseTabs = function (aWindow) { |
|
41 aWindow.gBrowser.loadOneTab('http://mochi.test:8888/', {inBackground: true}); |
|
42 aWindow.gBrowser.loadOneTab('http://mochi.test:8888/', {inBackground: true}); |
|
43 |
|
44 afterAllTabsLoaded(function () { |
|
45 assertNumberOfVisibleTabs(aWindow, 3); |
|
46 |
|
47 aWindow.gBrowser.removeTab(aWindow.gBrowser.tabs[1]); |
|
48 aWindow.gBrowser.selectedTab = aWindow.gBrowser.tabs[1]; |
|
49 |
|
50 restoreTab(function () { |
|
51 assertNumberOfVisibleTabs(aWindow, 3); |
|
52 assertOneSingleGroupItem(aWindow); |
|
53 next(aWindow); |
|
54 }, 0, aWindow); |
|
55 }, aWindow); |
|
56 } |
|
57 |
|
58 // [623792] duplicating tab via middle click on reload button |
|
59 let testDuplicateTab = function (aWindow) { |
|
60 aWindow.gBrowser.loadOneTab('http://mochi.test:8888/', {inBackground: true}); |
|
61 |
|
62 afterAllTabsLoaded(function () { |
|
63 // Valid choices for 'where' are window|tabshifted|tab |
|
64 aWindow.duplicateTabIn(aWindow.gBrowser.selectedTab, 'tab'); |
|
65 |
|
66 afterAllTabsLoaded(function () { |
|
67 assertNumberOfVisibleTabs(aWindow, 3); |
|
68 assertOneSingleGroupItem(aWindow); |
|
69 next(aWindow); |
|
70 }, aWindow); |
|
71 }, aWindow); |
|
72 } |
|
73 |
|
74 // [623792] duplicating tabs via middle click on forward/back buttons |
|
75 let testBackForwardDuplicateTab = function (aWindow) { |
|
76 let tab = aWindow.gBrowser.loadOneTab('http://mochi.test:8888/#1', {inBackground: true}); |
|
77 aWindow.gBrowser.selectedTab = tab; |
|
78 |
|
79 afterAllTabsLoaded(function () { |
|
80 tab.linkedBrowser.loadURI('http://mochi.test:8888/#2'); |
|
81 |
|
82 afterAllTabsLoaded(function () { |
|
83 ok(aWindow.gBrowser.canGoBack, 'browser can go back in history'); |
|
84 aWindow.BrowserBack({button: 1}); |
|
85 |
|
86 afterAllTabsLoaded(function () { |
|
87 assertNumberOfVisibleTabs(aWindow, 3); |
|
88 |
|
89 ok(aWindow.gBrowser.canGoForward, 'browser can go forward in history'); |
|
90 aWindow.BrowserForward({button: 1}); |
|
91 |
|
92 afterAllTabsLoaded(function () { |
|
93 assertNumberOfVisibleTabs(aWindow, 4); |
|
94 assertOneSingleGroupItem(aWindow); |
|
95 next(aWindow); |
|
96 }, aWindow); |
|
97 }, aWindow); |
|
98 }, aWindow); |
|
99 }, aWindow); |
|
100 } |
|
101 |
|
102 // [624102] check state after return from private browsing |
|
103 let testPrivateBrowsing = function (aWindow) { |
|
104 aWindow.gBrowser.loadOneTab('http://mochi.test:8888/#1', {inBackground: true}); |
|
105 aWindow.gBrowser.loadOneTab('http://mochi.test:8888/#2', {inBackground: true}); |
|
106 |
|
107 let cw = getContentWindow(aWindow); |
|
108 let box = new cw.Rect(20, 20, 250, 200); |
|
109 let groupItem = new cw.GroupItem([], {bounds: box, immediately: true}); |
|
110 cw.UI.setActive(groupItem); |
|
111 |
|
112 aWindow.gBrowser.selectedTab = aWindow.gBrowser.loadOneTab('http://mochi.test:8888/#3', {inBackground: true}); |
|
113 aWindow.gBrowser.loadOneTab('http://mochi.test:8888/#4', {inBackground: true}); |
|
114 |
|
115 afterAllTabsLoaded(function () { |
|
116 assertNumberOfVisibleTabs(aWindow, 2); |
|
117 |
|
118 enterAndLeavePrivateBrowsing(function () { |
|
119 assertNumberOfVisibleTabs(aWindow, 2); |
|
120 aWindow.gBrowser.selectedTab = aWindow.gBrowser.tabs[0]; |
|
121 closeGroupItem(cw.GroupItems.groupItems[1], function() { |
|
122 next(aWindow); |
|
123 }); |
|
124 }); |
|
125 }, aWindow); |
|
126 } |
|
127 |
|
128 function testOnWindow(aIsPrivate, aCallback) { |
|
129 let win = OpenBrowserWindow({private: aIsPrivate}); |
|
130 win.addEventListener("load", function onLoad() { |
|
131 win.removeEventListener("load", onLoad, false); |
|
132 executeSoon(function() { aCallback(win) }); |
|
133 }, false); |
|
134 } |
|
135 |
|
136 function enterAndLeavePrivateBrowsing(callback) { |
|
137 testOnWindow(true, function (aWindow) { |
|
138 aWindow.close(); |
|
139 callback(); |
|
140 }); |
|
141 } |
|
142 |
|
143 waitForExplicitFinish(); |
|
144 |
|
145 // Tests for #624265 |
|
146 tests.push(testUndoCloseTabs); |
|
147 |
|
148 // Tests for #623792 |
|
149 tests.push(testDuplicateTab); |
|
150 tests.push(testBackForwardDuplicateTab); |
|
151 |
|
152 // Tests for #624102 |
|
153 tests.push(testPrivateBrowsing); |
|
154 |
|
155 testOnWindow(false, function(aWindow) { |
|
156 loadTabView(function() { |
|
157 next(aWindow); |
|
158 }, aWindow); |
|
159 }); |
|
160 } |
|
161 |
|
162 function loadTabView(callback, aWindow) { |
|
163 showTabView(function () { |
|
164 hideTabView(callback, aWindow); |
|
165 }, aWindow); |
|
166 } |