browser/components/tabview/test/browser_tabview_bug626791.js

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/browser/components/tabview/test/browser_tabview_bug626791.js	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,178 @@
     1.4 +/* Any copyright is dedicated to the Public Domain.
     1.5 +   http://creativecommons.org/publicdomain/zero/1.0/ */
     1.6 +
     1.7 +Cu.import("resource:///modules/CustomizableUI.jsm");
     1.8 +
     1.9 +
    1.10 +function test() {
    1.11 +  let cw;
    1.12 +  let win;
    1.13 +  let prefix;
    1.14 +
    1.15 +  let getToolbar = function () {
    1.16 +    return win.document.getElementById("TabsToolbar");
    1.17 +  }
    1.18 +
    1.19 +  let assertToolbarButtonExists = function () {
    1.20 +    isnot(getToolbar().currentSet.indexOf("tabview-button"), -1,
    1.21 +          prefix + ": panorama button should be in the toolbar");
    1.22 +  }
    1.23 +
    1.24 +  let assertToolbarButtonNotExists = function () {
    1.25 +    is(getToolbar().currentSet.indexOf("tabview-button"), -1,
    1.26 +       prefix + ": panorama button should not be in the toolbar");
    1.27 +  }
    1.28 +
    1.29 +  let assertNumberOfTabs = function (num) {
    1.30 +    is(win.gBrowser.tabs.length, num, prefix + ': there are ' + num + ' tabs');
    1.31 +  }
    1.32 +
    1.33 +  let removeToolbarButton = function () {
    1.34 +    let toolbar = getToolbar();
    1.35 +    let currentSet = toolbar.currentSet.split(",");
    1.36 +    let buttonId = "tabview-button";
    1.37 +    let pos = currentSet.indexOf(buttonId);
    1.38 +
    1.39 +    if (-1 < pos) {
    1.40 +      CustomizableUI.removeWidgetFromArea("tabview-button");
    1.41 +    }
    1.42 +  }
    1.43 +
    1.44 +  let testNameGroup = function () {
    1.45 +    prefix = 'name-group';
    1.46 +    assertToolbarButtonNotExists();
    1.47 +    let groupItem = cw.GroupItems.groupItems[0];
    1.48 +
    1.49 +    groupItem.setTitle('title');
    1.50 +    assertToolbarButtonNotExists();
    1.51 +    groupItem.setTitle('');
    1.52 +
    1.53 +    EventUtils.synthesizeMouseAtCenter(groupItem.$titleShield[0], {}, cw);
    1.54 +    EventUtils.synthesizeKey('t', {}, cw);
    1.55 +    groupItem.$title[0].blur();
    1.56 +
    1.57 +    assertToolbarButtonExists();
    1.58 +    next();
    1.59 +  }
    1.60 +
    1.61 +  let testDragToCreateGroup = function () {
    1.62 +    prefix = 'drag-to-create-group';
    1.63 +    assertToolbarButtonNotExists();
    1.64 +    let width = cw.innerWidth;
    1.65 +    let height = cw.innerHeight;
    1.66 +
    1.67 +    let body = cw.document.body;
    1.68 +    EventUtils.synthesizeMouse(body, width - 10, height - 10, {type: 'mousedown'}, cw);
    1.69 +    EventUtils.synthesizeMouse(body, width - 200, height - 200, {type: 'mousemove'}, cw);
    1.70 +    EventUtils.synthesizeMouse(body, width - 200, height - 200, {type: 'mouseup'}, cw);
    1.71 +
    1.72 +    assertToolbarButtonExists();
    1.73 +    next();
    1.74 +  }
    1.75 +
    1.76 +  let testCreateOrphan = function (tab) {
    1.77 +    prefix = 'create-orphan';
    1.78 +    assertNumberOfTabs(1);
    1.79 +    assertToolbarButtonNotExists();
    1.80 +
    1.81 +    let width = cw.innerWidth;
    1.82 +    let height = cw.innerHeight;
    1.83 +
    1.84 +    let body = cw.document.body;
    1.85 +    EventUtils.synthesizeMouse(body, width - 10, height - 10, { clickCount: 2 }, cw);
    1.86 +
    1.87 +    whenTabViewIsHidden(function () {
    1.88 +      assertNumberOfTabs(2);
    1.89 +      assertToolbarButtonExists();
    1.90 +
    1.91 +      next();
    1.92 +    }, win);
    1.93 +  }
    1.94 +
    1.95 +  let testDragToCreateOrphan = function (tab) {
    1.96 +    if (!tab) {
    1.97 +      let tab = win.gBrowser.loadOneTab('about:blank', {inBackground: true});
    1.98 +      afterAllTabsLoaded(function () testDragToCreateOrphan(tab), win);
    1.99 +      return;
   1.100 +    }
   1.101 +
   1.102 +    prefix = 'drag-to-create-orphan';
   1.103 +    assertNumberOfTabs(2);
   1.104 +    assertToolbarButtonNotExists();
   1.105 +
   1.106 +    let width = cw.innerWidth;
   1.107 +    let height = cw.innerHeight;
   1.108 +
   1.109 +    let target = tab._tabViewTabItem.container;
   1.110 +    let rect = target.getBoundingClientRect();
   1.111 +    EventUtils.synthesizeMouseAtCenter(target, {type: 'mousedown'}, cw);
   1.112 +    EventUtils.synthesizeMouse(target, rect.width - 10, rect.height - 10, {type: 'mousemove'}, cw);
   1.113 +    EventUtils.synthesizeMouse(target, width - 300, height - 300, {type: 'mousemove'}, cw);
   1.114 +    EventUtils.synthesizeMouse(target, width - 200, height - 200, {type: 'mousemove'}, cw);
   1.115 +    EventUtils.synthesizeMouseAtCenter(target, {type: 'mouseup'}, cw);
   1.116 +
   1.117 +    assertToolbarButtonExists();
   1.118 +    next();
   1.119 +  }
   1.120 +
   1.121 +  let testReAddingAfterRemoval = function () {
   1.122 +    prefix = 're-adding-after-removal';
   1.123 +    assertToolbarButtonNotExists();
   1.124 +
   1.125 +    win.TabView.firstUseExperienced = true;
   1.126 +    assertToolbarButtonExists();
   1.127 +    removeToolbarButton();
   1.128 +    assertToolbarButtonNotExists();
   1.129 +
   1.130 +    win.close();
   1.131 +
   1.132 +    newWindowWithTabView(function (newWin) {
   1.133 +      win = newWin;
   1.134 +      win.TabView.firstUseExperienced = true;
   1.135 +      assertToolbarButtonNotExists();
   1.136 +      next();
   1.137 +    });
   1.138 +  }
   1.139 +
   1.140 +  let tests = [testNameGroup, testDragToCreateGroup, testCreateOrphan,
   1.141 +               testDragToCreateOrphan, testReAddingAfterRemoval];
   1.142 +
   1.143 +  let next = function () {
   1.144 +    if (win)
   1.145 +      win.close();
   1.146 +
   1.147 +    let test = tests.shift();
   1.148 +
   1.149 +    if (!test) {
   1.150 +      finish();
   1.151 +      return;
   1.152 +    }
   1.153 +
   1.154 +    TabView.firstUseExperienced = false;
   1.155 +
   1.156 +    let onLoad = function (newWin) {
   1.157 +      win = newWin;
   1.158 +      removeToolbarButton();
   1.159 +    };
   1.160 +
   1.161 +    let onShow = function () {
   1.162 +      cw = win.TabView.getContentWindow();
   1.163 +
   1.164 +      let groupItem = cw.GroupItems.groupItems[0];
   1.165 +      groupItem.setSize(200, 200, true);
   1.166 +      groupItem.setUserSize();
   1.167 +
   1.168 +      SimpleTest.waitForFocus(function () {
   1.169 +        assertToolbarButtonNotExists();
   1.170 +        test();
   1.171 +      }, cw);
   1.172 +    };
   1.173 +
   1.174 +    newWindowWithTabView(onShow, onLoad);
   1.175 +  }
   1.176 +
   1.177 +  waitForExplicitFinish();
   1.178 +  requestLongerTimeout(2);
   1.179 +
   1.180 +  next();
   1.181 +}

mercurial