michael@0: /* Any copyright is dedicated to the Public Domain. michael@0: http://creativecommons.org/publicdomain/zero/1.0/ */ michael@0: michael@0: function test() { michael@0: waitForExplicitFinish(); michael@0: michael@0: showTabView(onTabViewWindowLoaded); michael@0: } michael@0: michael@0: function onTabViewWindowLoaded() { michael@0: ok(TabView.isVisible(), "Tab View is visible"); michael@0: michael@0: let contentWindow = TabView.getContentWindow(); 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, 180, 180); michael@0: let groupItemOne = 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(groupItemOne); michael@0: michael@0: // create a tab michael@0: let xulTab = gBrowser.loadOneTab("about:blank"); michael@0: is(gBrowser.tabs.length, 2, "we now have two tabs"); michael@0: is(groupItemOne._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(groupItemOne), 0, "there are no app tab icons"); michael@0: michael@0: // pin the tab, make sure the TabItem goes away and the icon comes on michael@0: whenAppTabIconAdded(groupItemOne, function () { michael@0: is(groupItemOne._children.length, 0, michael@0: "the app tab's TabItem was removed from the group"); michael@0: is(appTabCount(groupItemOne), 1, "there's now one app tab icon"); michael@0: michael@0: // create a second group and make sure it gets the icon too michael@0: box.offset(box.width + 20, 0); michael@0: let groupItemTwo = new contentWindow.GroupItem([], michael@0: { bounds: box, title: "test2" }); michael@0: whenAppTabIconAdded(groupItemTwo, function() { michael@0: is(contentWindow.GroupItems.groupItems.length, 3, "we now have three groups"); michael@0: is(appTabCount(groupItemTwo), 1, michael@0: "there's an app tab icon in the second group"); 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(groupItemOne); michael@0: michael@0: // unpin the tab, make sure the icon goes away and the TabItem comes on michael@0: gBrowser.unpinTab(xulTab); michael@0: is(groupItemOne._children.length, 1, "the app tab's TabItem is back"); michael@0: is(appTabCount(groupItemOne), 0, "the icon is gone from group one"); michael@0: is(appTabCount(groupItemTwo), 0, "the icon is gone from group two"); michael@0: michael@0: whenAppTabIconAdded(groupItemOne, function() { michael@0: // close the second group michael@0: groupItemTwo.close(); michael@0: michael@0: // find app tab in group and hit it michael@0: whenTabViewIsHidden(function() { michael@0: ok(!TabView.isVisible(), michael@0: "Tab View is hidden because we clicked on the app tab"); michael@0: michael@0: // delete the app tab and make sure its icon goes away michael@0: gBrowser.removeTab(xulTab); michael@0: is(appTabCount(groupItemOne), 0, "closing app tab removes its icon"); michael@0: michael@0: // clean up michael@0: groupItemOne.close(); 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: ok(!TabView.isVisible(), "we finish with Tab View not visible"); michael@0: michael@0: finish(); michael@0: }); michael@0: michael@0: let appTabIcons = groupItemOne.container.getElementsByClassName("appTabIcon"); michael@0: EventUtils.sendMouseEvent({ type: "click" }, appTabIcons[0], contentWindow); michael@0: }); michael@0: gBrowser.pinTab(xulTab); michael@0: }); michael@0: }); michael@0: gBrowser.pinTab(xulTab); michael@0: } michael@0: michael@0: function appTabCount(groupItem) { michael@0: return groupItem.container.getElementsByClassName("appTabIcon").length; michael@0: }