|
1 /* Any copyright is dedicated to the Public Domain. |
|
2 http://creativecommons.org/publicdomain/zero/1.0/ */ |
|
3 |
|
4 function test() { |
|
5 let createGroupItem = function (aWindow) { |
|
6 let cw = aWindow.TabView.getContentWindow(); |
|
7 let bounds = new cw.Rect(20, 20, 400, 200); |
|
8 let groupItem = new cw.GroupItem([], {bounds: bounds, immediately: true}); |
|
9 cw.UI.setActive(groupItem); |
|
10 |
|
11 let groupItemId = groupItem.id; |
|
12 registerCleanupFunction(function() { |
|
13 let groupItem = cw.GroupItems.groupItem(groupItemId); |
|
14 if (groupItem) |
|
15 groupItem.close(); |
|
16 }); |
|
17 |
|
18 for (let i=0; i<3; i++) |
|
19 aWindow.gBrowser.addTab('about:blank'); |
|
20 } |
|
21 |
|
22 let assertTabViewIsHidden = function (aWindow, prefix) { |
|
23 ok(!aWindow.TabView.isVisible(), prefix + ': tabview is hidden'); |
|
24 } |
|
25 |
|
26 let assertNumberOfTabs = function (aWindow, prefix, num) { |
|
27 is(aWindow.gBrowser.tabs.length, num, prefix + ': there are ' + num + ' tabs'); |
|
28 } |
|
29 |
|
30 let assertNumberOfPinnedTabs = function (aWindow, prefix, num) { |
|
31 is(aWindow.gBrowser._numPinnedTabs, num, prefix + ': there are ' + num + ' pinned tabs'); |
|
32 } |
|
33 |
|
34 let assertNumberOfGroups = function (aCW, prefix, num) { |
|
35 is(aCW.GroupItems.groupItems.length, num, prefix + ': there are ' + num + ' groups'); |
|
36 } |
|
37 |
|
38 let assertOneTabInGroup = function (prefix, groupItem) { |
|
39 is(groupItem.getChildren().length, 1, prefix + ': group contains one tab'); |
|
40 } |
|
41 |
|
42 let assertValidPrerequisites = function (aWindow, prefix) { |
|
43 assertNumberOfTabs(aWindow, prefix, 1); |
|
44 assertNumberOfPinnedTabs(aWindow, prefix, 0); |
|
45 assertTabViewIsHidden(aWindow, prefix); |
|
46 } |
|
47 |
|
48 let assertValidSetup = function (aWindow, prefix) { |
|
49 let cw = aWindow.TabView.getContentWindow(); |
|
50 assertNumberOfGroups(cw, prefix, 2); |
|
51 assertNumberOfTabs(aWindow, prefix, 4); |
|
52 assertNumberOfPinnedTabs(aWindow, prefix, 2); |
|
53 |
|
54 let [group1, group2] = cw.GroupItems.groupItems; |
|
55 assertOneTabInGroup(prefix, group1); |
|
56 assertOneTabInGroup(prefix, group2); |
|
57 } |
|
58 |
|
59 let testStateAfterEnteringPB = function (aWindow, aCallback) { |
|
60 let prefix = 'window is private'; |
|
61 ok(PrivateBrowsingUtils.isWindowPrivate(aWindow), prefix); |
|
62 |
|
63 assertTabViewIsHidden(aWindow, prefix); |
|
64 |
|
65 showTabView(function () { |
|
66 let cw = aWindow.TabView.getContentWindow(); |
|
67 |
|
68 assertNumberOfGroups(cw, prefix, 1); |
|
69 assertNumberOfTabs(aWindow, prefix, 1); |
|
70 assertOneTabInGroup(prefix, cw.GroupItems.groupItems[0]); |
|
71 aCallback(); |
|
72 }, aWindow); |
|
73 } |
|
74 |
|
75 let testStateAfterLeavingPB = function (aWindow) { |
|
76 let prefix = 'window is not private'; |
|
77 ok(!PrivateBrowsingUtils.isWindowPrivate(aWindow), prefix); |
|
78 |
|
79 assertTabViewIsHidden(aWindow, prefix); |
|
80 |
|
81 showTabView(function () { |
|
82 assertValidSetup(aWindow, prefix); |
|
83 finishTest(aWindow); |
|
84 }, aWindow); |
|
85 } |
|
86 |
|
87 let finishTest = function (aWindow) { |
|
88 let cw = aWindow.TabView.getContentWindow(); |
|
89 |
|
90 // Remove pinned tabs |
|
91 aWindow.gBrowser.removeTab(aWindow.gBrowser.tabs[0]); |
|
92 aWindow.gBrowser.removeTab(aWindow.gBrowser.tabs[0]); |
|
93 |
|
94 cw.GroupItems.groupItems[1].closeAll(); |
|
95 |
|
96 hideTabView(function () { |
|
97 assertValidPrerequisites(aWindow, 'exit'); |
|
98 assertNumberOfGroups(cw, 'exit', 1); |
|
99 aWindow.close(); |
|
100 finish(); |
|
101 }, aWindow); |
|
102 } |
|
103 |
|
104 let testOnWindow = function(aIsPrivate, aCallback) { |
|
105 let win = OpenBrowserWindow({private: aIsPrivate}); |
|
106 win.addEventListener("load", function onLoad() { |
|
107 win.removeEventListener("load", onLoad, false); |
|
108 executeSoon(function() { aCallback(win) }); |
|
109 }, false); |
|
110 } |
|
111 |
|
112 waitForExplicitFinish(); |
|
113 testOnWindow(false, function(publicWindow) { |
|
114 registerCleanupFunction(function () publicWindow.TabView.hide()); |
|
115 assertValidPrerequisites(publicWindow, 'start'); |
|
116 |
|
117 showTabView(function () { |
|
118 let cw = publicWindow.TabView.getContentWindow(); |
|
119 assertNumberOfGroups(cw, 'start', 1); |
|
120 createGroupItem(publicWindow); |
|
121 |
|
122 afterAllTabsLoaded(function () { |
|
123 // Setup |
|
124 let groupItems = cw.GroupItems.groupItems; |
|
125 let [tabItem1, tabItem2, ] = groupItems[1].getChildren(); |
|
126 publicWindow.gBrowser.pinTab(tabItem1.tab); |
|
127 publicWindow.gBrowser.pinTab(tabItem2.tab); |
|
128 |
|
129 assertValidSetup(publicWindow, 'setup'); |
|
130 hideTabView(function() { |
|
131 testOnWindow(true, function(privateWindow) { |
|
132 testStateAfterEnteringPB(privateWindow, function() { |
|
133 privateWindow.close(); |
|
134 hideTabView(function() { |
|
135 testStateAfterLeavingPB(publicWindow); |
|
136 }, publicWindow); |
|
137 }); |
|
138 }); |
|
139 }, publicWindow); |
|
140 }); |
|
141 }, publicWindow); |
|
142 }); |
|
143 } |