browser/components/tabview/test/browser_tabview_bug626791.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 Cu.import("resource:///modules/CustomizableUI.jsm");
     7 function test() {
     8   let cw;
     9   let win;
    10   let prefix;
    12   let getToolbar = function () {
    13     return win.document.getElementById("TabsToolbar");
    14   }
    16   let assertToolbarButtonExists = function () {
    17     isnot(getToolbar().currentSet.indexOf("tabview-button"), -1,
    18           prefix + ": panorama button should be in the toolbar");
    19   }
    21   let assertToolbarButtonNotExists = function () {
    22     is(getToolbar().currentSet.indexOf("tabview-button"), -1,
    23        prefix + ": panorama button should not be in the toolbar");
    24   }
    26   let assertNumberOfTabs = function (num) {
    27     is(win.gBrowser.tabs.length, num, prefix + ': there are ' + num + ' tabs');
    28   }
    30   let removeToolbarButton = function () {
    31     let toolbar = getToolbar();
    32     let currentSet = toolbar.currentSet.split(",");
    33     let buttonId = "tabview-button";
    34     let pos = currentSet.indexOf(buttonId);
    36     if (-1 < pos) {
    37       CustomizableUI.removeWidgetFromArea("tabview-button");
    38     }
    39   }
    41   let testNameGroup = function () {
    42     prefix = 'name-group';
    43     assertToolbarButtonNotExists();
    44     let groupItem = cw.GroupItems.groupItems[0];
    46     groupItem.setTitle('title');
    47     assertToolbarButtonNotExists();
    48     groupItem.setTitle('');
    50     EventUtils.synthesizeMouseAtCenter(groupItem.$titleShield[0], {}, cw);
    51     EventUtils.synthesizeKey('t', {}, cw);
    52     groupItem.$title[0].blur();
    54     assertToolbarButtonExists();
    55     next();
    56   }
    58   let testDragToCreateGroup = function () {
    59     prefix = 'drag-to-create-group';
    60     assertToolbarButtonNotExists();
    61     let width = cw.innerWidth;
    62     let height = cw.innerHeight;
    64     let body = cw.document.body;
    65     EventUtils.synthesizeMouse(body, width - 10, height - 10, {type: 'mousedown'}, cw);
    66     EventUtils.synthesizeMouse(body, width - 200, height - 200, {type: 'mousemove'}, cw);
    67     EventUtils.synthesizeMouse(body, width - 200, height - 200, {type: 'mouseup'}, cw);
    69     assertToolbarButtonExists();
    70     next();
    71   }
    73   let testCreateOrphan = function (tab) {
    74     prefix = 'create-orphan';
    75     assertNumberOfTabs(1);
    76     assertToolbarButtonNotExists();
    78     let width = cw.innerWidth;
    79     let height = cw.innerHeight;
    81     let body = cw.document.body;
    82     EventUtils.synthesizeMouse(body, width - 10, height - 10, { clickCount: 2 }, cw);
    84     whenTabViewIsHidden(function () {
    85       assertNumberOfTabs(2);
    86       assertToolbarButtonExists();
    88       next();
    89     }, win);
    90   }
    92   let testDragToCreateOrphan = function (tab) {
    93     if (!tab) {
    94       let tab = win.gBrowser.loadOneTab('about:blank', {inBackground: true});
    95       afterAllTabsLoaded(function () testDragToCreateOrphan(tab), win);
    96       return;
    97     }
    99     prefix = 'drag-to-create-orphan';
   100     assertNumberOfTabs(2);
   101     assertToolbarButtonNotExists();
   103     let width = cw.innerWidth;
   104     let height = cw.innerHeight;
   106     let target = tab._tabViewTabItem.container;
   107     let rect = target.getBoundingClientRect();
   108     EventUtils.synthesizeMouseAtCenter(target, {type: 'mousedown'}, cw);
   109     EventUtils.synthesizeMouse(target, rect.width - 10, rect.height - 10, {type: 'mousemove'}, cw);
   110     EventUtils.synthesizeMouse(target, width - 300, height - 300, {type: 'mousemove'}, cw);
   111     EventUtils.synthesizeMouse(target, width - 200, height - 200, {type: 'mousemove'}, cw);
   112     EventUtils.synthesizeMouseAtCenter(target, {type: 'mouseup'}, cw);
   114     assertToolbarButtonExists();
   115     next();
   116   }
   118   let testReAddingAfterRemoval = function () {
   119     prefix = 're-adding-after-removal';
   120     assertToolbarButtonNotExists();
   122     win.TabView.firstUseExperienced = true;
   123     assertToolbarButtonExists();
   124     removeToolbarButton();
   125     assertToolbarButtonNotExists();
   127     win.close();
   129     newWindowWithTabView(function (newWin) {
   130       win = newWin;
   131       win.TabView.firstUseExperienced = true;
   132       assertToolbarButtonNotExists();
   133       next();
   134     });
   135   }
   137   let tests = [testNameGroup, testDragToCreateGroup, testCreateOrphan,
   138                testDragToCreateOrphan, testReAddingAfterRemoval];
   140   let next = function () {
   141     if (win)
   142       win.close();
   144     let test = tests.shift();
   146     if (!test) {
   147       finish();
   148       return;
   149     }
   151     TabView.firstUseExperienced = false;
   153     let onLoad = function (newWin) {
   154       win = newWin;
   155       removeToolbarButton();
   156     };
   158     let onShow = function () {
   159       cw = win.TabView.getContentWindow();
   161       let groupItem = cw.GroupItems.groupItems[0];
   162       groupItem.setSize(200, 200, true);
   163       groupItem.setUserSize();
   165       SimpleTest.waitForFocus(function () {
   166         assertToolbarButtonNotExists();
   167         test();
   168       }, cw);
   169     };
   171     newWindowWithTabView(onShow, onLoad);
   172   }
   174   waitForExplicitFinish();
   175   requestLongerTimeout(2);
   177   next();
   178 }

mercurial