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.

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

mercurial