browser/components/tabview/test/browser_tabview_apptabs.js

Thu, 22 Jan 2015 13:21:57 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Thu, 22 Jan 2015 13:21:57 +0100
branch
TOR_BUG_9701
changeset 15
b8a032363ba2
permissions
-rw-r--r--

Incorporate requested changes from Mozilla in review:
https://bugzilla.mozilla.org/show_bug.cgi?id=1123480#c6

     1 /* Any copyright is dedicated to the Public Domain.
     2    http://creativecommons.org/publicdomain/zero/1.0/ */
     4 function test() {
     5   waitForExplicitFinish();
     7   showTabView(onTabViewWindowLoaded);
     8 }
    10 function onTabViewWindowLoaded() {
    11   ok(TabView.isVisible(), "Tab View is visible");
    13   let contentWindow = TabView.getContentWindow();
    15   // establish initial state
    16   is(contentWindow.GroupItems.groupItems.length, 1,
    17       "we start with one group (the default)");
    18   is(gBrowser.tabs.length, 1, "we start with one tab");
    19   let originalTab = gBrowser.tabs[0];
    21   // create a group
    22   let box = new contentWindow.Rect(20, 20, 180, 180);
    23   let groupItemOne = new contentWindow.GroupItem([],
    24       { bounds: box, title: "test1" });
    25   is(contentWindow.GroupItems.groupItems.length, 2, "we now have two groups");
    26   contentWindow.UI.setActive(groupItemOne);
    28   // create a tab
    29   let xulTab = gBrowser.loadOneTab("about:blank");
    30   is(gBrowser.tabs.length, 2, "we now have two tabs");
    31   is(groupItemOne._children.length, 1, "the new tab was added to the group");
    33   // make sure the group has no app tabs
    34   is(appTabCount(groupItemOne), 0, "there are no app tab icons");
    36   // pin the tab, make sure the TabItem goes away and the icon comes on
    37   whenAppTabIconAdded(groupItemOne, function () {
    38     is(groupItemOne._children.length, 0,
    39        "the app tab's TabItem was removed from the group");
    40     is(appTabCount(groupItemOne), 1, "there's now one app tab icon");
    42     // create a second group and make sure it gets the icon too
    43     box.offset(box.width + 20, 0);
    44     let groupItemTwo = new contentWindow.GroupItem([],
    45         { bounds: box, title: "test2" });
    46     whenAppTabIconAdded(groupItemTwo, function() {
    47       is(contentWindow.GroupItems.groupItems.length, 3, "we now have three groups");
    48       is(appTabCount(groupItemTwo), 1,
    49          "there's an app tab icon in the second group");
    51       // When the tab was pinned, the last active group with an item got the focus.
    52       // Therefore, switching the focus back to group item one.
    53       contentWindow.UI.setActive(groupItemOne);
    55       // unpin the tab, make sure the icon goes away and the TabItem comes on
    56       gBrowser.unpinTab(xulTab);
    57       is(groupItemOne._children.length, 1, "the app tab's TabItem is back");
    58       is(appTabCount(groupItemOne), 0, "the icon is gone from group one");
    59       is(appTabCount(groupItemTwo), 0, "the icon is gone from group two");
    61       whenAppTabIconAdded(groupItemOne, function() {
    62         // close the second group
    63         groupItemTwo.close();
    65         // find app tab in group and hit it
    66         whenTabViewIsHidden(function() {
    67           ok(!TabView.isVisible(),
    68              "Tab View is hidden because we clicked on the app tab");
    70           // delete the app tab and make sure its icon goes away
    71           gBrowser.removeTab(xulTab);
    72           is(appTabCount(groupItemOne), 0, "closing app tab removes its icon");
    74           // clean up
    75           groupItemOne.close();
    77           is(contentWindow.GroupItems.groupItems.length, 1,
    78              "we finish with one group");
    79           is(gBrowser.tabs.length, 1, "we finish with one tab");
    80           ok(!TabView.isVisible(), "we finish with Tab View not visible");
    82           finish();
    83         });
    85         let appTabIcons = groupItemOne.container.getElementsByClassName("appTabIcon");
    86         EventUtils.sendMouseEvent({ type: "click" }, appTabIcons[0], contentWindow);
    87       });
    88       gBrowser.pinTab(xulTab);
    89     });
    90   });
    91   gBrowser.pinTab(xulTab);
    92 }
    94 function appTabCount(groupItem) {
    95   return groupItem.container.getElementsByClassName("appTabIcon").length;
    96 }

mercurial