browser/components/tabview/test/browser_tabview_apptabs.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_apptabs.js	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,96 @@
     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 +  waitForExplicitFinish();
     1.9 +
    1.10 +  showTabView(onTabViewWindowLoaded);
    1.11 +}
    1.12 +
    1.13 +function onTabViewWindowLoaded() {
    1.14 +  ok(TabView.isVisible(), "Tab View is visible");
    1.15 +
    1.16 +  let contentWindow = TabView.getContentWindow();
    1.17 +
    1.18 +  // establish initial state
    1.19 +  is(contentWindow.GroupItems.groupItems.length, 1,
    1.20 +      "we start with one group (the default)");
    1.21 +  is(gBrowser.tabs.length, 1, "we start with one tab");
    1.22 +  let originalTab = gBrowser.tabs[0];
    1.23 +
    1.24 +  // create a group
    1.25 +  let box = new contentWindow.Rect(20, 20, 180, 180);
    1.26 +  let groupItemOne = new contentWindow.GroupItem([],
    1.27 +      { bounds: box, title: "test1" });
    1.28 +  is(contentWindow.GroupItems.groupItems.length, 2, "we now have two groups");
    1.29 +  contentWindow.UI.setActive(groupItemOne);
    1.30 +
    1.31 +  // create a tab
    1.32 +  let xulTab = gBrowser.loadOneTab("about:blank");
    1.33 +  is(gBrowser.tabs.length, 2, "we now have two tabs");
    1.34 +  is(groupItemOne._children.length, 1, "the new tab was added to the group");
    1.35 +
    1.36 +  // make sure the group has no app tabs
    1.37 +  is(appTabCount(groupItemOne), 0, "there are no app tab icons");
    1.38 +
    1.39 +  // pin the tab, make sure the TabItem goes away and the icon comes on
    1.40 +  whenAppTabIconAdded(groupItemOne, function () {
    1.41 +    is(groupItemOne._children.length, 0,
    1.42 +       "the app tab's TabItem was removed from the group");
    1.43 +    is(appTabCount(groupItemOne), 1, "there's now one app tab icon");
    1.44 +
    1.45 +    // create a second group and make sure it gets the icon too
    1.46 +    box.offset(box.width + 20, 0);
    1.47 +    let groupItemTwo = new contentWindow.GroupItem([],
    1.48 +        { bounds: box, title: "test2" });
    1.49 +    whenAppTabIconAdded(groupItemTwo, function() {
    1.50 +      is(contentWindow.GroupItems.groupItems.length, 3, "we now have three groups");
    1.51 +      is(appTabCount(groupItemTwo), 1,
    1.52 +         "there's an app tab icon in the second group");
    1.53 +
    1.54 +      // When the tab was pinned, the last active group with an item got the focus.
    1.55 +      // Therefore, switching the focus back to group item one.
    1.56 +      contentWindow.UI.setActive(groupItemOne);
    1.57 +
    1.58 +      // unpin the tab, make sure the icon goes away and the TabItem comes on
    1.59 +      gBrowser.unpinTab(xulTab);
    1.60 +      is(groupItemOne._children.length, 1, "the app tab's TabItem is back");
    1.61 +      is(appTabCount(groupItemOne), 0, "the icon is gone from group one");
    1.62 +      is(appTabCount(groupItemTwo), 0, "the icon is gone from group two");
    1.63 +
    1.64 +      whenAppTabIconAdded(groupItemOne, function() {
    1.65 +        // close the second group
    1.66 +        groupItemTwo.close();
    1.67 +
    1.68 +        // find app tab in group and hit it
    1.69 +        whenTabViewIsHidden(function() {
    1.70 +          ok(!TabView.isVisible(),
    1.71 +             "Tab View is hidden because we clicked on the app tab");
    1.72 +
    1.73 +          // delete the app tab and make sure its icon goes away
    1.74 +          gBrowser.removeTab(xulTab);
    1.75 +          is(appTabCount(groupItemOne), 0, "closing app tab removes its icon");
    1.76 +
    1.77 +          // clean up
    1.78 +          groupItemOne.close();
    1.79 +
    1.80 +          is(contentWindow.GroupItems.groupItems.length, 1,
    1.81 +             "we finish with one group");
    1.82 +          is(gBrowser.tabs.length, 1, "we finish with one tab");
    1.83 +          ok(!TabView.isVisible(), "we finish with Tab View not visible");
    1.84 +
    1.85 +          finish();
    1.86 +        });
    1.87 +
    1.88 +        let appTabIcons = groupItemOne.container.getElementsByClassName("appTabIcon");
    1.89 +        EventUtils.sendMouseEvent({ type: "click" }, appTabIcons[0], contentWindow);
    1.90 +      });
    1.91 +      gBrowser.pinTab(xulTab);
    1.92 +    });
    1.93 +  });
    1.94 +  gBrowser.pinTab(xulTab);
    1.95 +}
    1.96 +
    1.97 +function appTabCount(groupItem) {
    1.98 +  return groupItem.container.getElementsByClassName("appTabIcon").length;
    1.99 +}

mercurial