1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/browser/components/tabview/test/browser_tabview_bug613541.js Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,288 @@ 1.4 +/* Any copyright is dedicated to the Public Domain. 1.5 + http://creativecommons.org/publicdomain/zero/1.0/ */ 1.6 + 1.7 +function test() { 1.8 + let cw; 1.9 + let win; 1.10 + let currentTest; 1.11 + 1.12 + let getGroupItem = function (index) { 1.13 + return cw.GroupItems.groupItems[index]; 1.14 + } 1.15 + 1.16 + let createGroupItem = function (numTabs) { 1.17 + let bounds = new cw.Rect(20, 20, 200, 200); 1.18 + let groupItem = new cw.GroupItem([], {bounds: bounds, immediately: true}); 1.19 + cw.UI.setActive(groupItem); 1.20 + 1.21 + for (let i=0; i<numTabs || 0; i++) 1.22 + win.gBrowser.loadOneTab('about:blank', {inBackground: true}); 1.23 + 1.24 + return groupItem; 1.25 + } 1.26 + 1.27 + let tests = []; 1.28 + 1.29 + let next = function () { 1.30 + let test = tests.shift(); 1.31 + 1.32 + if (test) { 1.33 + // check that the previous test left things as expected 1.34 + if (currentTest) { 1.35 + currentTest += ' (post-check)'; 1.36 + assertTabViewIsHidden(); 1.37 + assertNumberOfGroupItems(1); 1.38 + assertNumberOfTabs(1); 1.39 + } 1.40 + 1.41 + currentTest = test.name; 1.42 + showTabView(test.func, win); 1.43 + } else 1.44 + promiseWindowClosed(win).then(finish); 1.45 + } 1.46 + 1.47 + let assertTabViewIsHidden = function () { 1.48 + ok(!win.TabView.isVisible(), currentTest + ': tabview is hidden'); 1.49 + } 1.50 + 1.51 + let assertNumberOfGroupItems = function (num) { 1.52 + is(cw.GroupItems.groupItems.length, num, currentTest + ': number of groupItems is equal to ' + num); 1.53 + } 1.54 + 1.55 + let assertNumberOfTabs = function (num) { 1.56 + is(win.gBrowser.tabs.length, num, currentTest + ': number of tabs is equal to ' + num); 1.57 + } 1.58 + 1.59 + let assertGroupItemRemoved = function (groupItem) { 1.60 + is(cw.GroupItems.groupItems.indexOf(groupItem), -1, currentTest + ': groupItem was removed'); 1.61 + } 1.62 + 1.63 + let assertGroupItemExists = function (groupItem) { 1.64 + isnot(cw.GroupItems.groupItems.indexOf(groupItem), -1, currentTest + ': groupItem still exists'); 1.65 + } 1.66 + 1.67 + // setup: 1 non-empty group 1.68 + // action: close the group 1.69 + // expected: new group with blank tab is created and zoomed into 1.70 + let testSingleGroup1 = function () { 1.71 + let groupItem = getGroupItem(0); 1.72 + closeGroupItem(groupItem, function () { 1.73 + assertNumberOfGroupItems(1); 1.74 + assertGroupItemRemoved(groupItem); 1.75 + whenTabViewIsHidden(next, win); 1.76 + }); 1.77 + } 1.78 + 1.79 + // setup: 1 non-empty group 1.80 + // action: hide the group, exit panorama 1.81 + // expected: new group with blank tab is created and zoomed into 1.82 + let testSingleGroup2 = function () { 1.83 + let groupItem = getGroupItem(0); 1.84 + hideGroupItem(groupItem, function () { 1.85 + hideTabView(function () { 1.86 + assertNumberOfGroupItems(1); 1.87 + assertGroupItemRemoved(groupItem); 1.88 + next(); 1.89 + }, win); 1.90 + }); 1.91 + } 1.92 + 1.93 + // setup: 2 non-empty groups 1.94 + // action: close one group 1.95 + // expected: nothing should happen 1.96 + let testNonEmptyGroup1 = function () { 1.97 + let groupItem = getGroupItem(0); 1.98 + let newGroupItem = createGroupItem(1); 1.99 + assertNumberOfGroupItems(2); 1.100 + 1.101 + closeGroupItem(groupItem, function () { 1.102 + assertNumberOfGroupItems(1); 1.103 + assertGroupItemExists(newGroupItem); 1.104 + hideTabView(next, win); 1.105 + }); 1.106 + } 1.107 + 1.108 + // setup: 2 non-empty groups 1.109 + // action: hide one group, exit panorama 1.110 + // expected: nothing should happen 1.111 + let testNonEmptyGroup2 = function () { 1.112 + let groupItem = getGroupItem(0); 1.113 + let newGroupItem = createGroupItem(1); 1.114 + assertNumberOfGroupItems(2); 1.115 + 1.116 + hideGroupItem(groupItem, function () { 1.117 + hideTabView(function () { 1.118 + assertNumberOfGroupItems(1); 1.119 + assertGroupItemRemoved(groupItem); 1.120 + assertGroupItemExists(newGroupItem); 1.121 + next(); 1.122 + }, win); 1.123 + }); 1.124 + } 1.125 + 1.126 + // setup: 1 pinned tab, 1 empty group 1.127 + // action: exit panorama 1.128 + // expected: nothing should happen 1.129 + let testPinnedTab1 = function () { 1.130 + win.gBrowser.pinTab(win.gBrowser.selectedTab); 1.131 + 1.132 + let groupItem = getGroupItem(0); 1.133 + hideTabView(function () { 1.134 + assertNumberOfGroupItems(1); 1.135 + assertGroupItemExists(groupItem); 1.136 + win.gBrowser.unpinTab(win.gBrowser.selectedTab); 1.137 + next(); 1.138 + }, win); 1.139 + } 1.140 + 1.141 + // setup: 1 pinned tab 1.142 + // action: exit panorama 1.143 + // expected: new blank group is created 1.144 + let testPinnedTab2 = function () { 1.145 + win.gBrowser.pinTab(win.gBrowser.selectedTab); 1.146 + getGroupItem(0).close(); 1.147 + 1.148 + hideTabView(function () { 1.149 + assertNumberOfTabs(1); 1.150 + assertNumberOfGroupItems(1); 1.151 + win.gBrowser.unpinTab(win.gBrowser.selectedTab); 1.152 + next(); 1.153 + }, win); 1.154 + } 1.155 + 1.156 + // setup: 1 pinned tab, 1 empty group, 1 non-empty group 1.157 + // action: close non-empty group 1.158 + // expected: nothing should happen 1.159 + let testPinnedTab3 = function () { 1.160 + win.gBrowser.pinTab(win.gBrowser.selectedTab); 1.161 + 1.162 + let groupItem = getGroupItem(0); 1.163 + let newGroupItem = createGroupItem(1); 1.164 + assertNumberOfGroupItems(2); 1.165 + 1.166 + closeGroupItem(newGroupItem, function () { 1.167 + assertNumberOfGroupItems(1); 1.168 + assertGroupItemExists(groupItem); 1.169 + 1.170 + win.gBrowser.unpinTab(win.gBrowser.selectedTab); 1.171 + hideTabView(next, win); 1.172 + }); 1.173 + } 1.174 + 1.175 + // setup: 1 pinned tab, 1 empty group, 1 non-empty group 1.176 + // action: hide non-empty group, exit panorama 1.177 + // expected: nothing should happen 1.178 + let testPinnedTab4 = function () { 1.179 + win.gBrowser.pinTab(win.gBrowser.selectedTab); 1.180 + 1.181 + let groupItem = getGroupItem(0); 1.182 + let newGroupItem = createGroupItem(1); 1.183 + assertNumberOfGroupItems(2); 1.184 + 1.185 + hideGroupItem(newGroupItem, function () { 1.186 + hideTabView(function () { 1.187 + assertNumberOfGroupItems(1); 1.188 + assertGroupItemExists(groupItem); 1.189 + assertGroupItemRemoved(newGroupItem); 1.190 + win.gBrowser.unpinTab(win.gBrowser.selectedTab); 1.191 + next(); 1.192 + }, win); 1.193 + }); 1.194 + } 1.195 + 1.196 + // setup: 1 non-empty group, 1 empty group 1.197 + // action: close non-empty group 1.198 + // expected: empty group is re-used, new tab is created and zoomed into 1.199 + let testEmptyGroup1 = function () { 1.200 + let groupItem = getGroupItem(0); 1.201 + let newGroupItem = createGroupItem(0); 1.202 + assertNumberOfGroupItems(2); 1.203 + 1.204 + closeGroupItem(groupItem, function () { 1.205 + assertNumberOfGroupItems(1); 1.206 + assertGroupItemExists(newGroupItem); 1.207 + whenTabViewIsHidden(next, win); 1.208 + }); 1.209 + } 1.210 + 1.211 + // setup: 1 non-empty group, 1 empty group 1.212 + // action: hide non-empty group, exit panorama 1.213 + // expected: empty group is re-used, new tab is created and zoomed into 1.214 + let testEmptyGroup2 = function () { 1.215 + let groupItem = getGroupItem(0); 1.216 + let newGroupItem = createGroupItem(0); 1.217 + assertNumberOfGroupItems(2); 1.218 + 1.219 + hideGroupItem(groupItem, function () { 1.220 + hideTabView(function () { 1.221 + assertNumberOfGroupItems(1); 1.222 + assertGroupItemRemoved(groupItem); 1.223 + assertGroupItemExists(newGroupItem); 1.224 + next(); 1.225 + }, win); 1.226 + }); 1.227 + } 1.228 + 1.229 + // setup: 1 hidden group, 1 non-empty group 1.230 + // action: close non-empty group 1.231 + // expected: nothing should happen 1.232 + let testHiddenGroup1 = function () { 1.233 + let groupItem = getGroupItem(0); 1.234 + let hiddenGroupItem = createGroupItem(1); 1.235 + assertNumberOfGroupItems(2); 1.236 + 1.237 + hideGroupItem(hiddenGroupItem, function () { 1.238 + closeGroupItem(groupItem, function () { 1.239 + assertNumberOfGroupItems(1); 1.240 + assertGroupItemRemoved(groupItem); 1.241 + assertGroupItemExists(hiddenGroupItem); 1.242 + hideTabView(next, win); 1.243 + }); 1.244 + }); 1.245 + } 1.246 + 1.247 + // setup: 1 hidden group, 1 non-empty group 1.248 + // action: hide non-empty group, exit panorama 1.249 + // expected: new group with blank tab is created and zoomed into 1.250 + let testHiddenGroup2 = function () { 1.251 + let groupItem = getGroupItem(0); 1.252 + let hiddenGroupItem = createGroupItem(1); 1.253 + assertNumberOfGroupItems(2); 1.254 + 1.255 + hideGroupItem(hiddenGroupItem, function () { 1.256 + hideGroupItem(groupItem, function () { 1.257 + hideTabView(function () { 1.258 + assertNumberOfGroupItems(1); 1.259 + assertGroupItemRemoved(groupItem); 1.260 + assertGroupItemRemoved(hiddenGroupItem); 1.261 + next(); 1.262 + }, win); 1.263 + }); 1.264 + }); 1.265 + } 1.266 + 1.267 + tests.push({name: 'testSingleGroup1', func: testSingleGroup1}); 1.268 + tests.push({name: 'testSingleGroup2', func: testSingleGroup2}); 1.269 + 1.270 + tests.push({name: 'testNonEmptyGroup1', func: testNonEmptyGroup1}); 1.271 + tests.push({name: 'testNonEmptyGroup2', func: testNonEmptyGroup2}); 1.272 + 1.273 + tests.push({name: 'testPinnedTab1', func: testPinnedTab1}); 1.274 + tests.push({name: 'testPinnedTab2', func: testPinnedTab2}); 1.275 + tests.push({name: 'testPinnedTab3', func: testPinnedTab3}); 1.276 + tests.push({name: 'testPinnedTab4', func: testPinnedTab4}); 1.277 + 1.278 + tests.push({name: 'testEmptyGroup1', func: testEmptyGroup1}); 1.279 + tests.push({name: 'testEmptyGroup2', func: testEmptyGroup2}); 1.280 + 1.281 + tests.push({name: 'testHiddenGroup1', func: testHiddenGroup1}); 1.282 + tests.push({name: 'testHiddenGroup2', func: testHiddenGroup2}), 1.283 + 1.284 + waitForExplicitFinish(); 1.285 + 1.286 + newWindowWithTabView(window => { 1.287 + win = window; 1.288 + cw = win.TabView.getContentWindow(); 1.289 + next(); 1.290 + }); 1.291 +}