michael@0: /* michael@0: * Any copyright is dedicated to the Public Domain. michael@0: * http://creativecommons.org/publicdomain/zero/1.0/ michael@0: * michael@0: * Contributor(s): michael@0: * Mihai Sucan michael@0: * Raymond Lee michael@0: * Ian Gilman michael@0: */ michael@0: michael@0: function test() { michael@0: requestLongerTimeout(2); michael@0: waitForExplicitFinish(); michael@0: michael@0: newWindowWithTabView(onTabViewShown); michael@0: } michael@0: michael@0: function onTabViewShown(win) { michael@0: let TabView = win.TabView; michael@0: let gBrowser = win.gBrowser; michael@0: let document = win.document; michael@0: michael@0: ok(TabView.isVisible(), "Tab View is visible"); michael@0: michael@0: let contentWindow = document.getElementById("tab-view").contentWindow; michael@0: let iQ = contentWindow.iQ; michael@0: michael@0: // establish initial state michael@0: is(contentWindow.GroupItems.groupItems.length, 1, michael@0: "we start with one group (the default)"); michael@0: is(gBrowser.tabs.length, 1, "we start with one tab"); michael@0: let originalTab = gBrowser.tabs[0]; michael@0: michael@0: // create a group michael@0: let box = new contentWindow.Rect(20, 20, 210, 200); michael@0: let groupItem = new contentWindow.GroupItem([], michael@0: { bounds: box, title: "test1" }); michael@0: is(contentWindow.GroupItems.groupItems.length, 2, "we now have two groups"); michael@0: contentWindow.UI.setActive(groupItem); michael@0: michael@0: // create a tab michael@0: let xulTabs = []; michael@0: xulTabs.push(gBrowser.loadOneTab("about:blank")); michael@0: is(gBrowser.tabs.length, 2, "we now have two tabs"); michael@0: is(groupItem._children.length, 1, "the new tab was added to the group"); michael@0: michael@0: // make sure the group has no app tabs michael@0: is(appTabCount(groupItem), 0, "there are no app tab icons"); michael@0: michael@0: let tray = groupItem.$appTabTray; michael@0: let trayContainer = iQ(tray[0].parentNode); michael@0: michael@0: is(parseInt(trayContainer.css("width")), 0, michael@0: "$appTabTray container is not visible"); michael@0: michael@0: // pin the tab, make sure the TabItem goes away and the icon comes on michael@0: whenAppTabIconAdded(groupItem, function () { michael@0: is(groupItem._children.length, 0, michael@0: "the app tab's TabItem was removed from the group"); michael@0: is(appTabCount(groupItem), 1, "there's now one app tab icon"); michael@0: michael@0: is(tray.css("-moz-column-count"), 1, michael@0: "$appTabTray column count is 1"); michael@0: isnot(parseInt(trayContainer.css("width")), 0, michael@0: "$appTabTray container is visible"); michael@0: michael@0: michael@0: let iconHeight = iQ(iQ(".appTabIcon", tray)[0]).height(); michael@0: let trayHeight = parseInt(trayContainer.css("height")); michael@0: let rows = Math.floor(trayHeight / iconHeight); michael@0: let icons = rows * 2; michael@0: michael@0: function pinnedSomeTabs() { michael@0: is(appTabCount(groupItem), icons, "number of app tab icons is correct"); michael@0: michael@0: is(tray.css("-moz-column-count"), 2, michael@0: "$appTabTray column count is 2"); michael@0: michael@0: ok(!trayContainer.hasClass("appTabTrayContainerTruncated"), michael@0: "$appTabTray container does not have .appTabTrayContainerTruncated"); michael@0: michael@0: // add one more tab michael@0: xulTabs.push(gBrowser.loadOneTab("about:blank")); michael@0: whenAppTabIconAdded(groupItem, function () { michael@0: is(tray.css("-moz-column-count"), 3, michael@0: "$appTabTray column count is 3"); michael@0: michael@0: ok(trayContainer.hasClass("appTabTrayContainerTruncated"), michael@0: "$appTabTray container hasClass .appTabTrayContainerTruncated"); michael@0: michael@0: // remove all but one app tabs michael@0: for (let i = 1; i < xulTabs.length; i++) michael@0: gBrowser.removeTab(xulTabs[i]); michael@0: michael@0: is(tray.css("-moz-column-count"), 1, michael@0: "$appTabTray column count is 1"); michael@0: michael@0: is(appTabCount(groupItem), 1, "there's now one app tab icon"); michael@0: michael@0: ok(!trayContainer.hasClass("appTabTrayContainerTruncated"), michael@0: "$appTabTray container does not have .appTabTrayContainerTruncated"); michael@0: michael@0: // unpin the last remaining tab michael@0: gBrowser.unpinTab(xulTabs[0]); michael@0: michael@0: is(parseInt(trayContainer.css("width")), 0, michael@0: "$appTabTray container is not visible"); michael@0: michael@0: // When the tab was pinned, the last active group with an item got the focus. michael@0: // Therefore, switching the focus back to group item one. michael@0: contentWindow.UI.setActive(groupItem); michael@0: michael@0: is(appTabCount(groupItem), 0, "there are no app tab icons"); michael@0: michael@0: is(groupItem._children.length, 1, "the normal tab shows in the group"); michael@0: michael@0: gBrowser.removeTab(xulTabs[0]); michael@0: michael@0: // close the group michael@0: groupItem.close(); michael@0: michael@0: hideTabView(function() { michael@0: ok(!TabView.isVisible(), "Tab View is hidden"); michael@0: michael@0: is(contentWindow.GroupItems.groupItems.length, 1, michael@0: "we finish with one group"); michael@0: is(gBrowser.tabs.length, 1, "we finish with one tab"); michael@0: michael@0: win.close(); michael@0: michael@0: executeSoon(finish); michael@0: }, win); michael@0: }); michael@0: win.gBrowser.pinTab(xulTabs[xulTabs.length-1]); michael@0: }; michael@0: michael@0: // add enough tabs to have two columns michael@0: let returnCount = 0; michael@0: for (let i = 1; i < icons; i++) { michael@0: xulTabs.push(gBrowser.loadOneTab("about:blank")); michael@0: whenAppTabIconAdded(groupItem, function () { michael@0: if (++returnCount == (icons - 1)) michael@0: executeSoon(pinnedSomeTabs); michael@0: }); michael@0: win.gBrowser.pinTab(xulTabs[i]); michael@0: } michael@0: }); michael@0: win.gBrowser.pinTab(xulTabs[0]); michael@0: } michael@0: michael@0: function appTabCount(groupItem) { michael@0: return groupItem.container.getElementsByClassName("appTabIcon").length; michael@0: } michael@0: