browser/components/tabview/test/browser_tabview_bug595965.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_bug595965.js	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,154 @@
     1.4 +/*
     1.5 + * Any copyright is dedicated to the Public Domain.
     1.6 + * http://creativecommons.org/publicdomain/zero/1.0/
     1.7 + *
     1.8 + * Contributor(s):
     1.9 + *   Mihai Sucan <mihai.sucan@gmail.com>
    1.10 + *   Raymond Lee <raymond@appcoast.com>
    1.11 + *   Ian Gilman <ian@iangilman.com>
    1.12 + */
    1.13 +
    1.14 +function test() {
    1.15 +  requestLongerTimeout(2);
    1.16 +  waitForExplicitFinish();
    1.17 +
    1.18 +  newWindowWithTabView(onTabViewShown);
    1.19 +}
    1.20 +
    1.21 +function onTabViewShown(win) {
    1.22 +  let TabView = win.TabView;
    1.23 +  let gBrowser = win.gBrowser;
    1.24 +  let document = win.document;
    1.25 +
    1.26 +  ok(TabView.isVisible(), "Tab View is visible");
    1.27 +
    1.28 +  let contentWindow = document.getElementById("tab-view").contentWindow;
    1.29 +  let iQ = contentWindow.iQ;
    1.30 +
    1.31 +  // establish initial state
    1.32 +  is(contentWindow.GroupItems.groupItems.length, 1,
    1.33 +      "we start with one group (the default)");
    1.34 +  is(gBrowser.tabs.length, 1, "we start with one tab");
    1.35 +  let originalTab = gBrowser.tabs[0];
    1.36 +
    1.37 +  // create a group
    1.38 +  let box = new contentWindow.Rect(20, 20, 210, 200);
    1.39 +  let groupItem = new contentWindow.GroupItem([],
    1.40 +      { bounds: box, title: "test1" });
    1.41 +  is(contentWindow.GroupItems.groupItems.length, 2, "we now have two groups");
    1.42 +  contentWindow.UI.setActive(groupItem);
    1.43 +
    1.44 +  // create a tab
    1.45 +  let xulTabs = [];
    1.46 +  xulTabs.push(gBrowser.loadOneTab("about:blank"));
    1.47 +  is(gBrowser.tabs.length, 2, "we now have two tabs");
    1.48 +  is(groupItem._children.length, 1, "the new tab was added to the group");
    1.49 +
    1.50 +  // make sure the group has no app tabs
    1.51 +  is(appTabCount(groupItem), 0, "there are no app tab icons");
    1.52 +
    1.53 +  let tray = groupItem.$appTabTray;
    1.54 +  let trayContainer = iQ(tray[0].parentNode);
    1.55 +
    1.56 +  is(parseInt(trayContainer.css("width")), 0,
    1.57 +     "$appTabTray container is not visible");
    1.58 +
    1.59 +  // pin the tab, make sure the TabItem goes away and the icon comes on
    1.60 +  whenAppTabIconAdded(groupItem, function () {
    1.61 +    is(groupItem._children.length, 0,
    1.62 +       "the app tab's TabItem was removed from the group");
    1.63 +    is(appTabCount(groupItem), 1, "there's now one app tab icon");
    1.64 +
    1.65 +    is(tray.css("-moz-column-count"), 1,
    1.66 +       "$appTabTray column count is 1");
    1.67 +    isnot(parseInt(trayContainer.css("width")), 0,
    1.68 +       "$appTabTray container is visible");
    1.69 +
    1.70 +
    1.71 +    let iconHeight = iQ(iQ(".appTabIcon", tray)[0]).height();
    1.72 +    let trayHeight = parseInt(trayContainer.css("height"));
    1.73 +    let rows = Math.floor(trayHeight / iconHeight);
    1.74 +    let icons = rows * 2;
    1.75 +
    1.76 +    function pinnedSomeTabs() {
    1.77 +      is(appTabCount(groupItem), icons, "number of app tab icons is correct");
    1.78 +
    1.79 +      is(tray.css("-moz-column-count"), 2,
    1.80 +         "$appTabTray column count is 2");
    1.81 +
    1.82 +      ok(!trayContainer.hasClass("appTabTrayContainerTruncated"),
    1.83 +         "$appTabTray container does not have .appTabTrayContainerTruncated");
    1.84 +
    1.85 +      // add one more tab
    1.86 +      xulTabs.push(gBrowser.loadOneTab("about:blank"));
    1.87 +      whenAppTabIconAdded(groupItem, function () {
    1.88 +        is(tray.css("-moz-column-count"), 3,
    1.89 +           "$appTabTray column count is 3");
    1.90 +
    1.91 +        ok(trayContainer.hasClass("appTabTrayContainerTruncated"),
    1.92 +           "$appTabTray container hasClass .appTabTrayContainerTruncated");
    1.93 +
    1.94 +        // remove all but one app tabs
    1.95 +        for (let i = 1; i < xulTabs.length; i++)
    1.96 +          gBrowser.removeTab(xulTabs[i]);
    1.97 +
    1.98 +        is(tray.css("-moz-column-count"), 1,
    1.99 +           "$appTabTray column count is 1");
   1.100 +
   1.101 +        is(appTabCount(groupItem), 1, "there's now one app tab icon");
   1.102 +
   1.103 +        ok(!trayContainer.hasClass("appTabTrayContainerTruncated"),
   1.104 +           "$appTabTray container does not have .appTabTrayContainerTruncated");
   1.105 +
   1.106 +        // unpin the last remaining tab
   1.107 +        gBrowser.unpinTab(xulTabs[0]);
   1.108 +
   1.109 +        is(parseInt(trayContainer.css("width")), 0,
   1.110 +           "$appTabTray container is not visible");
   1.111 +
   1.112 +        // When the tab was pinned, the last active group with an item got the focus.
   1.113 +        // Therefore, switching the focus back to group item one.
   1.114 +        contentWindow.UI.setActive(groupItem);
   1.115 +
   1.116 +        is(appTabCount(groupItem), 0, "there are no app tab icons");
   1.117 +
   1.118 +        is(groupItem._children.length, 1, "the normal tab shows in the group");
   1.119 +
   1.120 +        gBrowser.removeTab(xulTabs[0]);
   1.121 +
   1.122 +        // close the group
   1.123 +        groupItem.close();
   1.124 +
   1.125 +        hideTabView(function() {
   1.126 +          ok(!TabView.isVisible(), "Tab View is hidden");
   1.127 +
   1.128 +          is(contentWindow.GroupItems.groupItems.length, 1,
   1.129 +             "we finish with one group");
   1.130 +          is(gBrowser.tabs.length, 1, "we finish with one tab");
   1.131 +
   1.132 +          win.close();
   1.133 +
   1.134 +          executeSoon(finish);
   1.135 +        }, win);
   1.136 +      });
   1.137 +      win.gBrowser.pinTab(xulTabs[xulTabs.length-1]);
   1.138 +    };
   1.139 +
   1.140 +    // add enough tabs to have two columns
   1.141 +    let returnCount = 0;
   1.142 +    for (let i = 1; i < icons; i++) {
   1.143 +      xulTabs.push(gBrowser.loadOneTab("about:blank"));
   1.144 +      whenAppTabIconAdded(groupItem, function () {
   1.145 +        if (++returnCount == (icons - 1))
   1.146 +          executeSoon(pinnedSomeTabs);
   1.147 +      });
   1.148 +      win.gBrowser.pinTab(xulTabs[i]);
   1.149 +    }
   1.150 +  });
   1.151 +  win.gBrowser.pinTab(xulTabs[0]);
   1.152 +}
   1.153 +
   1.154 +function appTabCount(groupItem) {
   1.155 +  return groupItem.container.getElementsByClassName("appTabIcon").length;
   1.156 +}
   1.157 +

mercurial