browser/components/tabview/test/browser_tabview_bug595965.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 /*
     2  * Any copyright is dedicated to the Public Domain.
     3  * http://creativecommons.org/publicdomain/zero/1.0/
     4  *
     5  * Contributor(s):
     6  *   Mihai Sucan <mihai.sucan@gmail.com>
     7  *   Raymond Lee <raymond@appcoast.com>
     8  *   Ian Gilman <ian@iangilman.com>
     9  */
    11 function test() {
    12   requestLongerTimeout(2);
    13   waitForExplicitFinish();
    15   newWindowWithTabView(onTabViewShown);
    16 }
    18 function onTabViewShown(win) {
    19   let TabView = win.TabView;
    20   let gBrowser = win.gBrowser;
    21   let document = win.document;
    23   ok(TabView.isVisible(), "Tab View is visible");
    25   let contentWindow = document.getElementById("tab-view").contentWindow;
    26   let iQ = contentWindow.iQ;
    28   // establish initial state
    29   is(contentWindow.GroupItems.groupItems.length, 1,
    30       "we start with one group (the default)");
    31   is(gBrowser.tabs.length, 1, "we start with one tab");
    32   let originalTab = gBrowser.tabs[0];
    34   // create a group
    35   let box = new contentWindow.Rect(20, 20, 210, 200);
    36   let groupItem = new contentWindow.GroupItem([],
    37       { bounds: box, title: "test1" });
    38   is(contentWindow.GroupItems.groupItems.length, 2, "we now have two groups");
    39   contentWindow.UI.setActive(groupItem);
    41   // create a tab
    42   let xulTabs = [];
    43   xulTabs.push(gBrowser.loadOneTab("about:blank"));
    44   is(gBrowser.tabs.length, 2, "we now have two tabs");
    45   is(groupItem._children.length, 1, "the new tab was added to the group");
    47   // make sure the group has no app tabs
    48   is(appTabCount(groupItem), 0, "there are no app tab icons");
    50   let tray = groupItem.$appTabTray;
    51   let trayContainer = iQ(tray[0].parentNode);
    53   is(parseInt(trayContainer.css("width")), 0,
    54      "$appTabTray container is not visible");
    56   // pin the tab, make sure the TabItem goes away and the icon comes on
    57   whenAppTabIconAdded(groupItem, function () {
    58     is(groupItem._children.length, 0,
    59        "the app tab's TabItem was removed from the group");
    60     is(appTabCount(groupItem), 1, "there's now one app tab icon");
    62     is(tray.css("-moz-column-count"), 1,
    63        "$appTabTray column count is 1");
    64     isnot(parseInt(trayContainer.css("width")), 0,
    65        "$appTabTray container is visible");
    68     let iconHeight = iQ(iQ(".appTabIcon", tray)[0]).height();
    69     let trayHeight = parseInt(trayContainer.css("height"));
    70     let rows = Math.floor(trayHeight / iconHeight);
    71     let icons = rows * 2;
    73     function pinnedSomeTabs() {
    74       is(appTabCount(groupItem), icons, "number of app tab icons is correct");
    76       is(tray.css("-moz-column-count"), 2,
    77          "$appTabTray column count is 2");
    79       ok(!trayContainer.hasClass("appTabTrayContainerTruncated"),
    80          "$appTabTray container does not have .appTabTrayContainerTruncated");
    82       // add one more tab
    83       xulTabs.push(gBrowser.loadOneTab("about:blank"));
    84       whenAppTabIconAdded(groupItem, function () {
    85         is(tray.css("-moz-column-count"), 3,
    86            "$appTabTray column count is 3");
    88         ok(trayContainer.hasClass("appTabTrayContainerTruncated"),
    89            "$appTabTray container hasClass .appTabTrayContainerTruncated");
    91         // remove all but one app tabs
    92         for (let i = 1; i < xulTabs.length; i++)
    93           gBrowser.removeTab(xulTabs[i]);
    95         is(tray.css("-moz-column-count"), 1,
    96            "$appTabTray column count is 1");
    98         is(appTabCount(groupItem), 1, "there's now one app tab icon");
   100         ok(!trayContainer.hasClass("appTabTrayContainerTruncated"),
   101            "$appTabTray container does not have .appTabTrayContainerTruncated");
   103         // unpin the last remaining tab
   104         gBrowser.unpinTab(xulTabs[0]);
   106         is(parseInt(trayContainer.css("width")), 0,
   107            "$appTabTray container is not visible");
   109         // When the tab was pinned, the last active group with an item got the focus.
   110         // Therefore, switching the focus back to group item one.
   111         contentWindow.UI.setActive(groupItem);
   113         is(appTabCount(groupItem), 0, "there are no app tab icons");
   115         is(groupItem._children.length, 1, "the normal tab shows in the group");
   117         gBrowser.removeTab(xulTabs[0]);
   119         // close the group
   120         groupItem.close();
   122         hideTabView(function() {
   123           ok(!TabView.isVisible(), "Tab View is hidden");
   125           is(contentWindow.GroupItems.groupItems.length, 1,
   126              "we finish with one group");
   127           is(gBrowser.tabs.length, 1, "we finish with one tab");
   129           win.close();
   131           executeSoon(finish);
   132         }, win);
   133       });
   134       win.gBrowser.pinTab(xulTabs[xulTabs.length-1]);
   135     };
   137     // add enough tabs to have two columns
   138     let returnCount = 0;
   139     for (let i = 1; i < icons; i++) {
   140       xulTabs.push(gBrowser.loadOneTab("about:blank"));
   141       whenAppTabIconAdded(groupItem, function () {
   142         if (++returnCount == (icons - 1))
   143           executeSoon(pinnedSomeTabs);
   144       });
   145       win.gBrowser.pinTab(xulTabs[i]);
   146     }
   147   });
   148   win.gBrowser.pinTab(xulTabs[0]);
   149 }
   151 function appTabCount(groupItem) {
   152   return groupItem.container.getElementsByClassName("appTabIcon").length;
   153 }

mercurial