browser/components/tabview/test/browser_tabview_bug631752.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_bug631752.js	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,85 @@
     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 +  let cw;
     1.9 +  let groupItem;
    1.10 +
    1.11 +  let getTabItemAspect = function (tabItem) {
    1.12 +    let bounds = cw.iQ('.thumb', tabItem.container).bounds();
    1.13 +    let padding = cw.TabItems.tabItemPadding;
    1.14 +    return (bounds.height + padding.y) / (bounds.width + padding.x);
    1.15 +  }
    1.16 +
    1.17 +  let getAspectRange = function () {
    1.18 +    let aspect = cw.TabItems.tabAspect;
    1.19 +    let variance = aspect / 100 * 1.5;
    1.20 +    return new cw.Range(aspect - variance, aspect + variance);
    1.21 +  }
    1.22 +
    1.23 +  let dragTabItem = function (tabItem) {
    1.24 +    let doc = cw.document.documentElement;
    1.25 +    let tabItem = groupItem.getChild(0);
    1.26 +    let container = tabItem.container;
    1.27 +    let aspectRange = getAspectRange();
    1.28 +
    1.29 +    EventUtils.synthesizeMouseAtCenter(container, {type: "mousedown"}, cw);
    1.30 +    for (let x = 200; x <= 400; x += 100)
    1.31 +      EventUtils.synthesizeMouse(doc, x, 100, {type: "mousemove"}, cw);
    1.32 +    ok(aspectRange.contains(getTabItemAspect(tabItem)), "tabItem's aspect is correct");
    1.33 +
    1.34 +    ok(!groupItem.getBounds().intersects(tabItem.getBounds()), "tabItem was moved out of group bounds");
    1.35 +    ok(!tabItem.parent, "tabItem is orphaned");
    1.36 +
    1.37 +    EventUtils.synthesizeMouseAtCenter(container, {type: "mouseup"}, cw);
    1.38 +    ok(aspectRange.contains(getTabItemAspect(tabItem)), "tabItem's aspect is correct");
    1.39 +  }
    1.40 +
    1.41 +  let testDragOutOfStackedGroup = function () {
    1.42 +    dragTabItem();
    1.43 +
    1.44 +    let secondGroup = cw.GroupItems.groupItems[1];
    1.45 +    closeGroupItem(secondGroup, testDragOutOfExpandedStackedGroup);
    1.46 +  }
    1.47 +
    1.48 +  let testDragOutOfExpandedStackedGroup = function () {
    1.49 +    groupItem.addSubscriber("expanded", function onExpanded() {
    1.50 +      groupItem.removeSubscriber("expanded", onExpanded);
    1.51 +      dragTabItem();
    1.52 +    });
    1.53 +
    1.54 +    groupItem.addSubscriber("collapsed", function onCollapsed() {
    1.55 +      groupItem.removeSubscriber("collapsed", onCollapsed);
    1.56 +
    1.57 +      let secondGroup = cw.GroupItems.groupItems[1];
    1.58 +      closeGroupItem(secondGroup, function () hideTabView(finishTest));
    1.59 +    });
    1.60 +
    1.61 +    groupItem.expand();
    1.62 +  }
    1.63 +
    1.64 +  let finishTest = function () {
    1.65 +    is(cw.GroupItems.groupItems.length, 1, "there is one groupItem");
    1.66 +    is(gBrowser.tabs.length, 1, "there is one tab");
    1.67 +    ok(!TabView.isVisible(), "tabview is hidden");
    1.68 +
    1.69 +    finish();
    1.70 +  }
    1.71 +
    1.72 +  waitForExplicitFinish();
    1.73 +
    1.74 +  newWindowWithTabView(function (win) {
    1.75 +    registerCleanupFunction(function () win.close());
    1.76 +
    1.77 +    cw = win.TabView.getContentWindow();
    1.78 +
    1.79 +    groupItem = cw.GroupItems.groupItems[0];
    1.80 +    groupItem.setSize(200, 200, true);
    1.81 +
    1.82 +    for (let i = 0; i < 9; i++)
    1.83 +      win.gBrowser.addTab();
    1.84 +
    1.85 +    ok(groupItem.isStacked(), "groupItem is stacked");
    1.86 +    testDragOutOfStackedGroup();
    1.87 +  });
    1.88 +}

mercurial