1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/browser/components/tabview/test/browser_tabview_bug610208.js Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,242 @@ 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 + requestLongerTimeout(4); 1.9 + let cw; 1.10 + let win; 1.11 + let groupItem; 1.12 + 1.13 + let next = function () { 1.14 + let test = tests.shift(); 1.15 + 1.16 + if (test) { 1.17 + test(); 1.18 + return; 1.19 + } 1.20 + 1.21 + win.close(); 1.22 + finish(); 1.23 + } 1.24 + 1.25 + let closeTabItemManually = function (tabItem) { 1.26 + EventUtils.synthesizeMouseAtCenter(tabItem.container, {button: 1}, cw); 1.27 + } 1.28 + 1.29 + let prepareTest = function (testName) { 1.30 + let originalBounds = groupItem.getChild(0).getBounds(); 1.31 + 1.32 + let tabItem = groupItem.getChild(1); 1.33 + let bounds = tabItem.getBounds(); 1.34 + closeTabItemManually(tabItem); 1.35 + 1.36 + ok(originalBounds.equals(groupItem.getChild(0).getBounds()), testName + ': tabs did not change their size'); 1.37 + ok(bounds.equals(groupItem.getChild(1).getBounds()), testName + ': third tab is now on second tab\'s previous position'); 1.38 + 1.39 + return originalBounds; 1.40 + } 1.41 + 1.42 + let cleanUpTest = function (testName, originalBounds, callback) { 1.43 + // Use setTimeout here because the groupItem.arrange() call uses 1.44 + // animation to re-arrange the tabItems. 1.45 + win.setTimeout(function () { 1.46 + ok(!originalBounds.equals(groupItem.getChild(0).getBounds()), testName + ': tabs changed their size'); 1.47 + 1.48 + // cleanup 1.49 + cw.UI.setActive(groupItem); 1.50 + win.gBrowser.loadOneTab('about:blank', {inBackground: true}); 1.51 + afterAllTabsLoaded(callback, win); 1.52 + }, 500); 1.53 + } 1.54 + 1.55 + let tests = []; 1.56 + 1.57 + // focus group title's input field to cause item arrange 1.58 + let testFocusTitle = function () { 1.59 + let originalBounds = prepareTest('testFocusTitle'); 1.60 + 1.61 + let target = groupItem.$titleShield[0]; 1.62 + EventUtils.synthesizeMouseAtCenter(target, {}, cw); 1.63 + 1.64 + cleanUpTest('testFocusTitle', originalBounds, next); 1.65 + } 1.66 + 1.67 + // hide tabview to cause item arrange 1.68 + let testHideTabView = function () { 1.69 + let originalBounds = prepareTest('testHideTabView'); 1.70 + 1.71 + hideTabView(function () { 1.72 + cleanUpTest('testHideTabView', originalBounds, function () { 1.73 + showTabView(next, win); 1.74 + }); 1.75 + }, win); 1.76 + } 1.77 + 1.78 + // (undo) close a group to cause item arrange 1.79 + let testCloseGroupUndo = function () { 1.80 + let originalBounds = prepareTest('testCloseGroupUndo'); 1.81 + 1.82 + hideGroupItem(groupItem, function () { 1.83 + unhideGroupItem(groupItem, function () { 1.84 + cleanUpTest('testCloseGroupUndo', originalBounds, next); 1.85 + }); 1.86 + }); 1.87 + } 1.88 + 1.89 + // leave the group's container with the mouse to cause item arrange 1.90 + let testMouseOut = function () { 1.91 + let originalBounds = prepareTest('testMouseOut'); 1.92 + let doc = cw.document.documentElement; 1.93 + let bounds = groupItem.getBounds(); 1.94 + 1.95 + EventUtils.synthesizeMouse(doc, bounds.right - 5, bounds.bottom - 5, {type: 'mousemove'}, cw); 1.96 + ok(originalBounds.equals(groupItem.getChild(0).getBounds()), 'testMouseOut: tabs did not change their size'); 1.97 + 1.98 + EventUtils.synthesizeMouse(doc, bounds.right + 1, bounds.bottom + 1, {type: 'mousemove'}, cw); 1.99 + cleanUpTest('testMouseOut', originalBounds, next); 1.100 + } 1.101 + 1.102 + // sort item (drag it around) in its group to cause item arrange 1.103 + let testSortInGroup = function () { 1.104 + let originalBounds = prepareTest('testSortInGroup'); 1.105 + let target = groupItem.getChild(0).container; 1.106 + 1.107 + // simulate drag/drop sorting 1.108 + EventUtils.synthesizeMouse(target, 20, 20, {type: 'mousedown'}, cw); 1.109 + EventUtils.synthesizeMouse(target, 40, 20, {type: 'mousemove'}, cw); 1.110 + EventUtils.synthesizeMouse(target, 20, 20, {type: 'mouseup'}, cw); 1.111 + 1.112 + cleanUpTest('testSortInGroup', originalBounds, next); 1.113 + } 1.114 + 1.115 + // arrange items when the containing group is resized 1.116 + let testResizeGroup = function () { 1.117 + let originalBounds = prepareTest('testResizeGroup'); 1.118 + let oldBounds = groupItem.getBounds(); 1.119 + let resizer = groupItem.$resizer[0]; 1.120 + 1.121 + // simulate drag/drop resizing 1.122 + EventUtils.synthesizeMouse(resizer, 5, 5, {type: 'mousedown'}, cw); 1.123 + EventUtils.synthesizeMouse(resizer, 40, 20, {type: 'mousemove'}, cw); 1.124 + EventUtils.synthesizeMouse(resizer, 20, 20, {type: 'mouseup'}, cw); 1.125 + 1.126 + // reset group size 1.127 + groupItem.setBounds(oldBounds); 1.128 + groupItem.setUserSize(); 1.129 + 1.130 + cleanUpTest('testResizeGroup', originalBounds, next); 1.131 + } 1.132 + 1.133 + // make sure we don't freeze item size when removing an item from a stack 1.134 + let testRemoveWhileStacked = function () { 1.135 + let oldBounds = groupItem.getBounds(); 1.136 + groupItem.setSize(250, 250, true); 1.137 + groupItem.setUserSize(); 1.138 + 1.139 + ok(!groupItem.isStacked(), 'testRemoveWhileStacked: group is not stacked'); 1.140 + 1.141 + let originalBounds; 1.142 + let tabItem = groupItem.getChild(0); 1.143 + 1.144 + // add new tabs to let the group stack 1.145 + while (!groupItem.isStacked()) { 1.146 + originalBounds = tabItem.getBounds(); 1.147 + win.gBrowser.addTab(); 1.148 + } 1.149 + 1.150 + afterAllTabsLoaded(function () { 1.151 + tabItem.close(); 1.152 + ok(!groupItem.isStacked(), 'testRemoveWhileStacked: group is not stacked'); 1.153 + 1.154 + let bounds = groupItem.getChild(0).getBounds(); 1.155 + ok(originalBounds.equals(bounds), 'testRemoveWhileStacked: tabs did not change their size'); 1.156 + 1.157 + // reset group size 1.158 + groupItem.setBounds(oldBounds); 1.159 + groupItem.setUserSize(); 1.160 + 1.161 + next(); 1.162 + }, win); 1.163 + } 1.164 + 1.165 + // 1) make sure item size is frozen when removing an item in expanded mode 1.166 + // 2) make sure item size stays frozen while moving the mouse in the expanded 1.167 + // layer 1.168 + let testExpandedMode = function () { 1.169 + let oldBounds = groupItem.getBounds(); 1.170 + groupItem.setSize(100, 100, true); 1.171 + groupItem.setUserSize(); 1.172 + 1.173 + ok(groupItem.isStacked(), 'testExpandedMode: group is stacked'); 1.174 + 1.175 + groupItem.addSubscriber('expanded', function onGroupExpanded() { 1.176 + groupItem.removeSubscriber('expanded', onGroupExpanded); 1.177 + onExpanded(); 1.178 + }); 1.179 + 1.180 + groupItem.addSubscriber('collapsed', function onGroupCollapsed() { 1.181 + groupItem.removeSubscriber('collapsed', onGroupCollapsed); 1.182 + onCollapsed(); 1.183 + }); 1.184 + 1.185 + let onExpanded = function () { 1.186 + let originalBounds = groupItem.getChild(0).getBounds(); 1.187 + let tabItem = groupItem.getChild(1); 1.188 + let bounds = tabItem.getBounds(); 1.189 + 1.190 + while (groupItem.getChildren().length > 2) 1.191 + closeTabItemManually(groupItem.getChild(1)); 1.192 + 1.193 + ok(originalBounds.equals(groupItem.getChild(0).getBounds()), 'testExpandedMode: tabs did not change their size'); 1.194 + 1.195 + // move the mouse over the expanded layer 1.196 + let trayBounds = groupItem.expanded.bounds; 1.197 + let target = groupItem.expanded.$tray[0]; 1.198 + EventUtils.synthesizeMouse(target, trayBounds.right - 5, trayBounds.bottom -5, {type: 'mousemove'}, cw); 1.199 + 1.200 + ok(originalBounds.equals(groupItem.getChild(0).getBounds()), 'testExpandedMode: tabs did not change their size'); 1.201 + groupItem.collapse(); 1.202 + } 1.203 + 1.204 + let onCollapsed = function () { 1.205 + // reset group size 1.206 + groupItem.setBounds(oldBounds); 1.207 + groupItem.setUserSize(); 1.208 + 1.209 + next(); 1.210 + } 1.211 + 1.212 + groupItem.expand(); 1.213 + } 1.214 + 1.215 + tests.push(testFocusTitle); 1.216 + tests.push(testHideTabView); 1.217 + tests.push(testCloseGroupUndo); 1.218 + tests.push(testMouseOut); 1.219 + tests.push(testSortInGroup); 1.220 + tests.push(testResizeGroup); 1.221 + tests.push(testRemoveWhileStacked); 1.222 + tests.push(testExpandedMode); 1.223 + 1.224 + waitForExplicitFinish(); 1.225 + 1.226 + newWindowWithTabView(function (tvwin) { 1.227 + win = tvwin; 1.228 + 1.229 + registerCleanupFunction(function () { 1.230 + if (!win.closed) 1.231 + win.close(); 1.232 + }); 1.233 + 1.234 + cw = win.TabView.getContentWindow(); 1.235 + 1.236 + groupItem = cw.GroupItems.groupItems[0]; 1.237 + groupItem.setSize(400, 200, true); 1.238 + groupItem.setUserSize(); 1.239 + 1.240 + for (let i=0; i<3; i++) 1.241 + win.gBrowser.loadOneTab('about:blank', {inBackground: true}); 1.242 + 1.243 + afterAllTabsLoaded(next, win); 1.244 + }); 1.245 +}