browser/components/tabview/test/browser_tabview_bug610208.js

Wed, 31 Dec 2014 06:09:35 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Wed, 31 Dec 2014 06:09:35 +0100
changeset 0
6474c204b198
permissions
-rw-r--r--

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 requestLongerTimeout(4);
michael@0 6 let cw;
michael@0 7 let win;
michael@0 8 let groupItem;
michael@0 9
michael@0 10 let next = function () {
michael@0 11 let test = tests.shift();
michael@0 12
michael@0 13 if (test) {
michael@0 14 test();
michael@0 15 return;
michael@0 16 }
michael@0 17
michael@0 18 win.close();
michael@0 19 finish();
michael@0 20 }
michael@0 21
michael@0 22 let closeTabItemManually = function (tabItem) {
michael@0 23 EventUtils.synthesizeMouseAtCenter(tabItem.container, {button: 1}, cw);
michael@0 24 }
michael@0 25
michael@0 26 let prepareTest = function (testName) {
michael@0 27 let originalBounds = groupItem.getChild(0).getBounds();
michael@0 28
michael@0 29 let tabItem = groupItem.getChild(1);
michael@0 30 let bounds = tabItem.getBounds();
michael@0 31 closeTabItemManually(tabItem);
michael@0 32
michael@0 33 ok(originalBounds.equals(groupItem.getChild(0).getBounds()), testName + ': tabs did not change their size');
michael@0 34 ok(bounds.equals(groupItem.getChild(1).getBounds()), testName + ': third tab is now on second tab\'s previous position');
michael@0 35
michael@0 36 return originalBounds;
michael@0 37 }
michael@0 38
michael@0 39 let cleanUpTest = function (testName, originalBounds, callback) {
michael@0 40 // Use setTimeout here because the groupItem.arrange() call uses
michael@0 41 // animation to re-arrange the tabItems.
michael@0 42 win.setTimeout(function () {
michael@0 43 ok(!originalBounds.equals(groupItem.getChild(0).getBounds()), testName + ': tabs changed their size');
michael@0 44
michael@0 45 // cleanup
michael@0 46 cw.UI.setActive(groupItem);
michael@0 47 win.gBrowser.loadOneTab('about:blank', {inBackground: true});
michael@0 48 afterAllTabsLoaded(callback, win);
michael@0 49 }, 500);
michael@0 50 }
michael@0 51
michael@0 52 let tests = [];
michael@0 53
michael@0 54 // focus group title's input field to cause item arrange
michael@0 55 let testFocusTitle = function () {
michael@0 56 let originalBounds = prepareTest('testFocusTitle');
michael@0 57
michael@0 58 let target = groupItem.$titleShield[0];
michael@0 59 EventUtils.synthesizeMouseAtCenter(target, {}, cw);
michael@0 60
michael@0 61 cleanUpTest('testFocusTitle', originalBounds, next);
michael@0 62 }
michael@0 63
michael@0 64 // hide tabview to cause item arrange
michael@0 65 let testHideTabView = function () {
michael@0 66 let originalBounds = prepareTest('testHideTabView');
michael@0 67
michael@0 68 hideTabView(function () {
michael@0 69 cleanUpTest('testHideTabView', originalBounds, function () {
michael@0 70 showTabView(next, win);
michael@0 71 });
michael@0 72 }, win);
michael@0 73 }
michael@0 74
michael@0 75 // (undo) close a group to cause item arrange
michael@0 76 let testCloseGroupUndo = function () {
michael@0 77 let originalBounds = prepareTest('testCloseGroupUndo');
michael@0 78
michael@0 79 hideGroupItem(groupItem, function () {
michael@0 80 unhideGroupItem(groupItem, function () {
michael@0 81 cleanUpTest('testCloseGroupUndo', originalBounds, next);
michael@0 82 });
michael@0 83 });
michael@0 84 }
michael@0 85
michael@0 86 // leave the group's container with the mouse to cause item arrange
michael@0 87 let testMouseOut = function () {
michael@0 88 let originalBounds = prepareTest('testMouseOut');
michael@0 89 let doc = cw.document.documentElement;
michael@0 90 let bounds = groupItem.getBounds();
michael@0 91
michael@0 92 EventUtils.synthesizeMouse(doc, bounds.right - 5, bounds.bottom - 5, {type: 'mousemove'}, cw);
michael@0 93 ok(originalBounds.equals(groupItem.getChild(0).getBounds()), 'testMouseOut: tabs did not change their size');
michael@0 94
michael@0 95 EventUtils.synthesizeMouse(doc, bounds.right + 1, bounds.bottom + 1, {type: 'mousemove'}, cw);
michael@0 96 cleanUpTest('testMouseOut', originalBounds, next);
michael@0 97 }
michael@0 98
michael@0 99 // sort item (drag it around) in its group to cause item arrange
michael@0 100 let testSortInGroup = function () {
michael@0 101 let originalBounds = prepareTest('testSortInGroup');
michael@0 102 let target = groupItem.getChild(0).container;
michael@0 103
michael@0 104 // simulate drag/drop sorting
michael@0 105 EventUtils.synthesizeMouse(target, 20, 20, {type: 'mousedown'}, cw);
michael@0 106 EventUtils.synthesizeMouse(target, 40, 20, {type: 'mousemove'}, cw);
michael@0 107 EventUtils.synthesizeMouse(target, 20, 20, {type: 'mouseup'}, cw);
michael@0 108
michael@0 109 cleanUpTest('testSortInGroup', originalBounds, next);
michael@0 110 }
michael@0 111
michael@0 112 // arrange items when the containing group is resized
michael@0 113 let testResizeGroup = function () {
michael@0 114 let originalBounds = prepareTest('testResizeGroup');
michael@0 115 let oldBounds = groupItem.getBounds();
michael@0 116 let resizer = groupItem.$resizer[0];
michael@0 117
michael@0 118 // simulate drag/drop resizing
michael@0 119 EventUtils.synthesizeMouse(resizer, 5, 5, {type: 'mousedown'}, cw);
michael@0 120 EventUtils.synthesizeMouse(resizer, 40, 20, {type: 'mousemove'}, cw);
michael@0 121 EventUtils.synthesizeMouse(resizer, 20, 20, {type: 'mouseup'}, cw);
michael@0 122
michael@0 123 // reset group size
michael@0 124 groupItem.setBounds(oldBounds);
michael@0 125 groupItem.setUserSize();
michael@0 126
michael@0 127 cleanUpTest('testResizeGroup', originalBounds, next);
michael@0 128 }
michael@0 129
michael@0 130 // make sure we don't freeze item size when removing an item from a stack
michael@0 131 let testRemoveWhileStacked = function () {
michael@0 132 let oldBounds = groupItem.getBounds();
michael@0 133 groupItem.setSize(250, 250, true);
michael@0 134 groupItem.setUserSize();
michael@0 135
michael@0 136 ok(!groupItem.isStacked(), 'testRemoveWhileStacked: group is not stacked');
michael@0 137
michael@0 138 let originalBounds;
michael@0 139 let tabItem = groupItem.getChild(0);
michael@0 140
michael@0 141 // add new tabs to let the group stack
michael@0 142 while (!groupItem.isStacked()) {
michael@0 143 originalBounds = tabItem.getBounds();
michael@0 144 win.gBrowser.addTab();
michael@0 145 }
michael@0 146
michael@0 147 afterAllTabsLoaded(function () {
michael@0 148 tabItem.close();
michael@0 149 ok(!groupItem.isStacked(), 'testRemoveWhileStacked: group is not stacked');
michael@0 150
michael@0 151 let bounds = groupItem.getChild(0).getBounds();
michael@0 152 ok(originalBounds.equals(bounds), 'testRemoveWhileStacked: tabs did not change their size');
michael@0 153
michael@0 154 // reset group size
michael@0 155 groupItem.setBounds(oldBounds);
michael@0 156 groupItem.setUserSize();
michael@0 157
michael@0 158 next();
michael@0 159 }, win);
michael@0 160 }
michael@0 161
michael@0 162 // 1) make sure item size is frozen when removing an item in expanded mode
michael@0 163 // 2) make sure item size stays frozen while moving the mouse in the expanded
michael@0 164 // layer
michael@0 165 let testExpandedMode = function () {
michael@0 166 let oldBounds = groupItem.getBounds();
michael@0 167 groupItem.setSize(100, 100, true);
michael@0 168 groupItem.setUserSize();
michael@0 169
michael@0 170 ok(groupItem.isStacked(), 'testExpandedMode: group is stacked');
michael@0 171
michael@0 172 groupItem.addSubscriber('expanded', function onGroupExpanded() {
michael@0 173 groupItem.removeSubscriber('expanded', onGroupExpanded);
michael@0 174 onExpanded();
michael@0 175 });
michael@0 176
michael@0 177 groupItem.addSubscriber('collapsed', function onGroupCollapsed() {
michael@0 178 groupItem.removeSubscriber('collapsed', onGroupCollapsed);
michael@0 179 onCollapsed();
michael@0 180 });
michael@0 181
michael@0 182 let onExpanded = function () {
michael@0 183 let originalBounds = groupItem.getChild(0).getBounds();
michael@0 184 let tabItem = groupItem.getChild(1);
michael@0 185 let bounds = tabItem.getBounds();
michael@0 186
michael@0 187 while (groupItem.getChildren().length > 2)
michael@0 188 closeTabItemManually(groupItem.getChild(1));
michael@0 189
michael@0 190 ok(originalBounds.equals(groupItem.getChild(0).getBounds()), 'testExpandedMode: tabs did not change their size');
michael@0 191
michael@0 192 // move the mouse over the expanded layer
michael@0 193 let trayBounds = groupItem.expanded.bounds;
michael@0 194 let target = groupItem.expanded.$tray[0];
michael@0 195 EventUtils.synthesizeMouse(target, trayBounds.right - 5, trayBounds.bottom -5, {type: 'mousemove'}, cw);
michael@0 196
michael@0 197 ok(originalBounds.equals(groupItem.getChild(0).getBounds()), 'testExpandedMode: tabs did not change their size');
michael@0 198 groupItem.collapse();
michael@0 199 }
michael@0 200
michael@0 201 let onCollapsed = function () {
michael@0 202 // reset group size
michael@0 203 groupItem.setBounds(oldBounds);
michael@0 204 groupItem.setUserSize();
michael@0 205
michael@0 206 next();
michael@0 207 }
michael@0 208
michael@0 209 groupItem.expand();
michael@0 210 }
michael@0 211
michael@0 212 tests.push(testFocusTitle);
michael@0 213 tests.push(testHideTabView);
michael@0 214 tests.push(testCloseGroupUndo);
michael@0 215 tests.push(testMouseOut);
michael@0 216 tests.push(testSortInGroup);
michael@0 217 tests.push(testResizeGroup);
michael@0 218 tests.push(testRemoveWhileStacked);
michael@0 219 tests.push(testExpandedMode);
michael@0 220
michael@0 221 waitForExplicitFinish();
michael@0 222
michael@0 223 newWindowWithTabView(function (tvwin) {
michael@0 224 win = tvwin;
michael@0 225
michael@0 226 registerCleanupFunction(function () {
michael@0 227 if (!win.closed)
michael@0 228 win.close();
michael@0 229 });
michael@0 230
michael@0 231 cw = win.TabView.getContentWindow();
michael@0 232
michael@0 233 groupItem = cw.GroupItems.groupItems[0];
michael@0 234 groupItem.setSize(400, 200, true);
michael@0 235 groupItem.setUserSize();
michael@0 236
michael@0 237 for (let i=0; i<3; i++)
michael@0 238 win.gBrowser.loadOneTab('about:blank', {inBackground: true});
michael@0 239
michael@0 240 afterAllTabsLoaded(next, win);
michael@0 241 });
michael@0 242 }

mercurial