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.
michael@0 | 1 | /* Any copyright is dedicated to the Public Domain. |
michael@0 | 2 | http://creativecommons.org/publicdomain/zero/1.0/ */ |
michael@0 | 3 | |
michael@0 | 4 | function test() { |
michael@0 | 5 | let cw; |
michael@0 | 6 | let win; |
michael@0 | 7 | let currentTest; |
michael@0 | 8 | |
michael@0 | 9 | let getGroupItem = function (index) { |
michael@0 | 10 | return cw.GroupItems.groupItems[index]; |
michael@0 | 11 | } |
michael@0 | 12 | |
michael@0 | 13 | let createGroupItem = function (numTabs) { |
michael@0 | 14 | let bounds = new cw.Rect(20, 20, 200, 200); |
michael@0 | 15 | let groupItem = new cw.GroupItem([], {bounds: bounds, immediately: true}); |
michael@0 | 16 | cw.UI.setActive(groupItem); |
michael@0 | 17 | |
michael@0 | 18 | for (let i=0; i<numTabs || 0; i++) |
michael@0 | 19 | win.gBrowser.loadOneTab('about:blank', {inBackground: true}); |
michael@0 | 20 | |
michael@0 | 21 | return groupItem; |
michael@0 | 22 | } |
michael@0 | 23 | |
michael@0 | 24 | let tests = []; |
michael@0 | 25 | |
michael@0 | 26 | let next = function () { |
michael@0 | 27 | let test = tests.shift(); |
michael@0 | 28 | |
michael@0 | 29 | if (test) { |
michael@0 | 30 | // check that the previous test left things as expected |
michael@0 | 31 | if (currentTest) { |
michael@0 | 32 | currentTest += ' (post-check)'; |
michael@0 | 33 | assertTabViewIsHidden(); |
michael@0 | 34 | assertNumberOfGroupItems(1); |
michael@0 | 35 | assertNumberOfTabs(1); |
michael@0 | 36 | } |
michael@0 | 37 | |
michael@0 | 38 | currentTest = test.name; |
michael@0 | 39 | showTabView(test.func, win); |
michael@0 | 40 | } else |
michael@0 | 41 | promiseWindowClosed(win).then(finish); |
michael@0 | 42 | } |
michael@0 | 43 | |
michael@0 | 44 | let assertTabViewIsHidden = function () { |
michael@0 | 45 | ok(!win.TabView.isVisible(), currentTest + ': tabview is hidden'); |
michael@0 | 46 | } |
michael@0 | 47 | |
michael@0 | 48 | let assertNumberOfGroupItems = function (num) { |
michael@0 | 49 | is(cw.GroupItems.groupItems.length, num, currentTest + ': number of groupItems is equal to ' + num); |
michael@0 | 50 | } |
michael@0 | 51 | |
michael@0 | 52 | let assertNumberOfTabs = function (num) { |
michael@0 | 53 | is(win.gBrowser.tabs.length, num, currentTest + ': number of tabs is equal to ' + num); |
michael@0 | 54 | } |
michael@0 | 55 | |
michael@0 | 56 | let assertGroupItemRemoved = function (groupItem) { |
michael@0 | 57 | is(cw.GroupItems.groupItems.indexOf(groupItem), -1, currentTest + ': groupItem was removed'); |
michael@0 | 58 | } |
michael@0 | 59 | |
michael@0 | 60 | let assertGroupItemExists = function (groupItem) { |
michael@0 | 61 | isnot(cw.GroupItems.groupItems.indexOf(groupItem), -1, currentTest + ': groupItem still exists'); |
michael@0 | 62 | } |
michael@0 | 63 | |
michael@0 | 64 | // setup: 1 non-empty group |
michael@0 | 65 | // action: close the group |
michael@0 | 66 | // expected: new group with blank tab is created and zoomed into |
michael@0 | 67 | let testSingleGroup1 = function () { |
michael@0 | 68 | let groupItem = getGroupItem(0); |
michael@0 | 69 | closeGroupItem(groupItem, function () { |
michael@0 | 70 | assertNumberOfGroupItems(1); |
michael@0 | 71 | assertGroupItemRemoved(groupItem); |
michael@0 | 72 | whenTabViewIsHidden(next, win); |
michael@0 | 73 | }); |
michael@0 | 74 | } |
michael@0 | 75 | |
michael@0 | 76 | // setup: 1 non-empty group |
michael@0 | 77 | // action: hide the group, exit panorama |
michael@0 | 78 | // expected: new group with blank tab is created and zoomed into |
michael@0 | 79 | let testSingleGroup2 = function () { |
michael@0 | 80 | let groupItem = getGroupItem(0); |
michael@0 | 81 | hideGroupItem(groupItem, function () { |
michael@0 | 82 | hideTabView(function () { |
michael@0 | 83 | assertNumberOfGroupItems(1); |
michael@0 | 84 | assertGroupItemRemoved(groupItem); |
michael@0 | 85 | next(); |
michael@0 | 86 | }, win); |
michael@0 | 87 | }); |
michael@0 | 88 | } |
michael@0 | 89 | |
michael@0 | 90 | // setup: 2 non-empty groups |
michael@0 | 91 | // action: close one group |
michael@0 | 92 | // expected: nothing should happen |
michael@0 | 93 | let testNonEmptyGroup1 = function () { |
michael@0 | 94 | let groupItem = getGroupItem(0); |
michael@0 | 95 | let newGroupItem = createGroupItem(1); |
michael@0 | 96 | assertNumberOfGroupItems(2); |
michael@0 | 97 | |
michael@0 | 98 | closeGroupItem(groupItem, function () { |
michael@0 | 99 | assertNumberOfGroupItems(1); |
michael@0 | 100 | assertGroupItemExists(newGroupItem); |
michael@0 | 101 | hideTabView(next, win); |
michael@0 | 102 | }); |
michael@0 | 103 | } |
michael@0 | 104 | |
michael@0 | 105 | // setup: 2 non-empty groups |
michael@0 | 106 | // action: hide one group, exit panorama |
michael@0 | 107 | // expected: nothing should happen |
michael@0 | 108 | let testNonEmptyGroup2 = function () { |
michael@0 | 109 | let groupItem = getGroupItem(0); |
michael@0 | 110 | let newGroupItem = createGroupItem(1); |
michael@0 | 111 | assertNumberOfGroupItems(2); |
michael@0 | 112 | |
michael@0 | 113 | hideGroupItem(groupItem, function () { |
michael@0 | 114 | hideTabView(function () { |
michael@0 | 115 | assertNumberOfGroupItems(1); |
michael@0 | 116 | assertGroupItemRemoved(groupItem); |
michael@0 | 117 | assertGroupItemExists(newGroupItem); |
michael@0 | 118 | next(); |
michael@0 | 119 | }, win); |
michael@0 | 120 | }); |
michael@0 | 121 | } |
michael@0 | 122 | |
michael@0 | 123 | // setup: 1 pinned tab, 1 empty group |
michael@0 | 124 | // action: exit panorama |
michael@0 | 125 | // expected: nothing should happen |
michael@0 | 126 | let testPinnedTab1 = function () { |
michael@0 | 127 | win.gBrowser.pinTab(win.gBrowser.selectedTab); |
michael@0 | 128 | |
michael@0 | 129 | let groupItem = getGroupItem(0); |
michael@0 | 130 | hideTabView(function () { |
michael@0 | 131 | assertNumberOfGroupItems(1); |
michael@0 | 132 | assertGroupItemExists(groupItem); |
michael@0 | 133 | win.gBrowser.unpinTab(win.gBrowser.selectedTab); |
michael@0 | 134 | next(); |
michael@0 | 135 | }, win); |
michael@0 | 136 | } |
michael@0 | 137 | |
michael@0 | 138 | // setup: 1 pinned tab |
michael@0 | 139 | // action: exit panorama |
michael@0 | 140 | // expected: new blank group is created |
michael@0 | 141 | let testPinnedTab2 = function () { |
michael@0 | 142 | win.gBrowser.pinTab(win.gBrowser.selectedTab); |
michael@0 | 143 | getGroupItem(0).close(); |
michael@0 | 144 | |
michael@0 | 145 | hideTabView(function () { |
michael@0 | 146 | assertNumberOfTabs(1); |
michael@0 | 147 | assertNumberOfGroupItems(1); |
michael@0 | 148 | win.gBrowser.unpinTab(win.gBrowser.selectedTab); |
michael@0 | 149 | next(); |
michael@0 | 150 | }, win); |
michael@0 | 151 | } |
michael@0 | 152 | |
michael@0 | 153 | // setup: 1 pinned tab, 1 empty group, 1 non-empty group |
michael@0 | 154 | // action: close non-empty group |
michael@0 | 155 | // expected: nothing should happen |
michael@0 | 156 | let testPinnedTab3 = function () { |
michael@0 | 157 | win.gBrowser.pinTab(win.gBrowser.selectedTab); |
michael@0 | 158 | |
michael@0 | 159 | let groupItem = getGroupItem(0); |
michael@0 | 160 | let newGroupItem = createGroupItem(1); |
michael@0 | 161 | assertNumberOfGroupItems(2); |
michael@0 | 162 | |
michael@0 | 163 | closeGroupItem(newGroupItem, function () { |
michael@0 | 164 | assertNumberOfGroupItems(1); |
michael@0 | 165 | assertGroupItemExists(groupItem); |
michael@0 | 166 | |
michael@0 | 167 | win.gBrowser.unpinTab(win.gBrowser.selectedTab); |
michael@0 | 168 | hideTabView(next, win); |
michael@0 | 169 | }); |
michael@0 | 170 | } |
michael@0 | 171 | |
michael@0 | 172 | // setup: 1 pinned tab, 1 empty group, 1 non-empty group |
michael@0 | 173 | // action: hide non-empty group, exit panorama |
michael@0 | 174 | // expected: nothing should happen |
michael@0 | 175 | let testPinnedTab4 = function () { |
michael@0 | 176 | win.gBrowser.pinTab(win.gBrowser.selectedTab); |
michael@0 | 177 | |
michael@0 | 178 | let groupItem = getGroupItem(0); |
michael@0 | 179 | let newGroupItem = createGroupItem(1); |
michael@0 | 180 | assertNumberOfGroupItems(2); |
michael@0 | 181 | |
michael@0 | 182 | hideGroupItem(newGroupItem, function () { |
michael@0 | 183 | hideTabView(function () { |
michael@0 | 184 | assertNumberOfGroupItems(1); |
michael@0 | 185 | assertGroupItemExists(groupItem); |
michael@0 | 186 | assertGroupItemRemoved(newGroupItem); |
michael@0 | 187 | win.gBrowser.unpinTab(win.gBrowser.selectedTab); |
michael@0 | 188 | next(); |
michael@0 | 189 | }, win); |
michael@0 | 190 | }); |
michael@0 | 191 | } |
michael@0 | 192 | |
michael@0 | 193 | // setup: 1 non-empty group, 1 empty group |
michael@0 | 194 | // action: close non-empty group |
michael@0 | 195 | // expected: empty group is re-used, new tab is created and zoomed into |
michael@0 | 196 | let testEmptyGroup1 = function () { |
michael@0 | 197 | let groupItem = getGroupItem(0); |
michael@0 | 198 | let newGroupItem = createGroupItem(0); |
michael@0 | 199 | assertNumberOfGroupItems(2); |
michael@0 | 200 | |
michael@0 | 201 | closeGroupItem(groupItem, function () { |
michael@0 | 202 | assertNumberOfGroupItems(1); |
michael@0 | 203 | assertGroupItemExists(newGroupItem); |
michael@0 | 204 | whenTabViewIsHidden(next, win); |
michael@0 | 205 | }); |
michael@0 | 206 | } |
michael@0 | 207 | |
michael@0 | 208 | // setup: 1 non-empty group, 1 empty group |
michael@0 | 209 | // action: hide non-empty group, exit panorama |
michael@0 | 210 | // expected: empty group is re-used, new tab is created and zoomed into |
michael@0 | 211 | let testEmptyGroup2 = function () { |
michael@0 | 212 | let groupItem = getGroupItem(0); |
michael@0 | 213 | let newGroupItem = createGroupItem(0); |
michael@0 | 214 | assertNumberOfGroupItems(2); |
michael@0 | 215 | |
michael@0 | 216 | hideGroupItem(groupItem, function () { |
michael@0 | 217 | hideTabView(function () { |
michael@0 | 218 | assertNumberOfGroupItems(1); |
michael@0 | 219 | assertGroupItemRemoved(groupItem); |
michael@0 | 220 | assertGroupItemExists(newGroupItem); |
michael@0 | 221 | next(); |
michael@0 | 222 | }, win); |
michael@0 | 223 | }); |
michael@0 | 224 | } |
michael@0 | 225 | |
michael@0 | 226 | // setup: 1 hidden group, 1 non-empty group |
michael@0 | 227 | // action: close non-empty group |
michael@0 | 228 | // expected: nothing should happen |
michael@0 | 229 | let testHiddenGroup1 = function () { |
michael@0 | 230 | let groupItem = getGroupItem(0); |
michael@0 | 231 | let hiddenGroupItem = createGroupItem(1); |
michael@0 | 232 | assertNumberOfGroupItems(2); |
michael@0 | 233 | |
michael@0 | 234 | hideGroupItem(hiddenGroupItem, function () { |
michael@0 | 235 | closeGroupItem(groupItem, function () { |
michael@0 | 236 | assertNumberOfGroupItems(1); |
michael@0 | 237 | assertGroupItemRemoved(groupItem); |
michael@0 | 238 | assertGroupItemExists(hiddenGroupItem); |
michael@0 | 239 | hideTabView(next, win); |
michael@0 | 240 | }); |
michael@0 | 241 | }); |
michael@0 | 242 | } |
michael@0 | 243 | |
michael@0 | 244 | // setup: 1 hidden group, 1 non-empty group |
michael@0 | 245 | // action: hide non-empty group, exit panorama |
michael@0 | 246 | // expected: new group with blank tab is created and zoomed into |
michael@0 | 247 | let testHiddenGroup2 = function () { |
michael@0 | 248 | let groupItem = getGroupItem(0); |
michael@0 | 249 | let hiddenGroupItem = createGroupItem(1); |
michael@0 | 250 | assertNumberOfGroupItems(2); |
michael@0 | 251 | |
michael@0 | 252 | hideGroupItem(hiddenGroupItem, function () { |
michael@0 | 253 | hideGroupItem(groupItem, function () { |
michael@0 | 254 | hideTabView(function () { |
michael@0 | 255 | assertNumberOfGroupItems(1); |
michael@0 | 256 | assertGroupItemRemoved(groupItem); |
michael@0 | 257 | assertGroupItemRemoved(hiddenGroupItem); |
michael@0 | 258 | next(); |
michael@0 | 259 | }, win); |
michael@0 | 260 | }); |
michael@0 | 261 | }); |
michael@0 | 262 | } |
michael@0 | 263 | |
michael@0 | 264 | tests.push({name: 'testSingleGroup1', func: testSingleGroup1}); |
michael@0 | 265 | tests.push({name: 'testSingleGroup2', func: testSingleGroup2}); |
michael@0 | 266 | |
michael@0 | 267 | tests.push({name: 'testNonEmptyGroup1', func: testNonEmptyGroup1}); |
michael@0 | 268 | tests.push({name: 'testNonEmptyGroup2', func: testNonEmptyGroup2}); |
michael@0 | 269 | |
michael@0 | 270 | tests.push({name: 'testPinnedTab1', func: testPinnedTab1}); |
michael@0 | 271 | tests.push({name: 'testPinnedTab2', func: testPinnedTab2}); |
michael@0 | 272 | tests.push({name: 'testPinnedTab3', func: testPinnedTab3}); |
michael@0 | 273 | tests.push({name: 'testPinnedTab4', func: testPinnedTab4}); |
michael@0 | 274 | |
michael@0 | 275 | tests.push({name: 'testEmptyGroup1', func: testEmptyGroup1}); |
michael@0 | 276 | tests.push({name: 'testEmptyGroup2', func: testEmptyGroup2}); |
michael@0 | 277 | |
michael@0 | 278 | tests.push({name: 'testHiddenGroup1', func: testHiddenGroup1}); |
michael@0 | 279 | tests.push({name: 'testHiddenGroup2', func: testHiddenGroup2}), |
michael@0 | 280 | |
michael@0 | 281 | waitForExplicitFinish(); |
michael@0 | 282 | |
michael@0 | 283 | newWindowWithTabView(window => { |
michael@0 | 284 | win = window; |
michael@0 | 285 | cw = win.TabView.getContentWindow(); |
michael@0 | 286 | next(); |
michael@0 | 287 | }); |
michael@0 | 288 | } |