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.

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

mercurial