Wed, 31 Dec 2014 06:09:35 +0100
Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.
michael@0 | 1 | /* Any copyright is dedicated to the Public Domain. |
michael@0 | 2 | http://creativecommons.org/publicdomain/zero/1.0/ */ |
michael@0 | 3 | |
michael@0 | 4 | function test() { |
michael@0 | 5 | waitForExplicitFinish(); |
michael@0 | 6 | |
michael@0 | 7 | showTabView(onTabViewWindowLoaded); |
michael@0 | 8 | } |
michael@0 | 9 | |
michael@0 | 10 | function onTabViewWindowLoaded() { |
michael@0 | 11 | ok(TabView.isVisible(), "Tab View is visible"); |
michael@0 | 12 | |
michael@0 | 13 | let contentWindow = TabView.getContentWindow(); |
michael@0 | 14 | |
michael@0 | 15 | // establish initial state |
michael@0 | 16 | is(contentWindow.GroupItems.groupItems.length, 1, |
michael@0 | 17 | "we start with one group (the default)"); |
michael@0 | 18 | is(gBrowser.tabs.length, 1, "we start with one tab"); |
michael@0 | 19 | let originalTab = gBrowser.tabs[0]; |
michael@0 | 20 | |
michael@0 | 21 | // create a group |
michael@0 | 22 | let box = new contentWindow.Rect(20, 20, 180, 180); |
michael@0 | 23 | let groupItemOne = new contentWindow.GroupItem([], |
michael@0 | 24 | { bounds: box, title: "test1" }); |
michael@0 | 25 | is(contentWindow.GroupItems.groupItems.length, 2, "we now have two groups"); |
michael@0 | 26 | contentWindow.UI.setActive(groupItemOne); |
michael@0 | 27 | |
michael@0 | 28 | // create a tab |
michael@0 | 29 | let xulTab = gBrowser.loadOneTab("about:blank"); |
michael@0 | 30 | is(gBrowser.tabs.length, 2, "we now have two tabs"); |
michael@0 | 31 | is(groupItemOne._children.length, 1, "the new tab was added to the group"); |
michael@0 | 32 | |
michael@0 | 33 | // make sure the group has no app tabs |
michael@0 | 34 | is(appTabCount(groupItemOne), 0, "there are no app tab icons"); |
michael@0 | 35 | |
michael@0 | 36 | // pin the tab, make sure the TabItem goes away and the icon comes on |
michael@0 | 37 | whenAppTabIconAdded(groupItemOne, function () { |
michael@0 | 38 | is(groupItemOne._children.length, 0, |
michael@0 | 39 | "the app tab's TabItem was removed from the group"); |
michael@0 | 40 | is(appTabCount(groupItemOne), 1, "there's now one app tab icon"); |
michael@0 | 41 | |
michael@0 | 42 | // create a second group and make sure it gets the icon too |
michael@0 | 43 | box.offset(box.width + 20, 0); |
michael@0 | 44 | let groupItemTwo = new contentWindow.GroupItem([], |
michael@0 | 45 | { bounds: box, title: "test2" }); |
michael@0 | 46 | whenAppTabIconAdded(groupItemTwo, function() { |
michael@0 | 47 | is(contentWindow.GroupItems.groupItems.length, 3, "we now have three groups"); |
michael@0 | 48 | is(appTabCount(groupItemTwo), 1, |
michael@0 | 49 | "there's an app tab icon in the second group"); |
michael@0 | 50 | |
michael@0 | 51 | // When the tab was pinned, the last active group with an item got the focus. |
michael@0 | 52 | // Therefore, switching the focus back to group item one. |
michael@0 | 53 | contentWindow.UI.setActive(groupItemOne); |
michael@0 | 54 | |
michael@0 | 55 | // unpin the tab, make sure the icon goes away and the TabItem comes on |
michael@0 | 56 | gBrowser.unpinTab(xulTab); |
michael@0 | 57 | is(groupItemOne._children.length, 1, "the app tab's TabItem is back"); |
michael@0 | 58 | is(appTabCount(groupItemOne), 0, "the icon is gone from group one"); |
michael@0 | 59 | is(appTabCount(groupItemTwo), 0, "the icon is gone from group two"); |
michael@0 | 60 | |
michael@0 | 61 | whenAppTabIconAdded(groupItemOne, function() { |
michael@0 | 62 | // close the second group |
michael@0 | 63 | groupItemTwo.close(); |
michael@0 | 64 | |
michael@0 | 65 | // find app tab in group and hit it |
michael@0 | 66 | whenTabViewIsHidden(function() { |
michael@0 | 67 | ok(!TabView.isVisible(), |
michael@0 | 68 | "Tab View is hidden because we clicked on the app tab"); |
michael@0 | 69 | |
michael@0 | 70 | // delete the app tab and make sure its icon goes away |
michael@0 | 71 | gBrowser.removeTab(xulTab); |
michael@0 | 72 | is(appTabCount(groupItemOne), 0, "closing app tab removes its icon"); |
michael@0 | 73 | |
michael@0 | 74 | // clean up |
michael@0 | 75 | groupItemOne.close(); |
michael@0 | 76 | |
michael@0 | 77 | is(contentWindow.GroupItems.groupItems.length, 1, |
michael@0 | 78 | "we finish with one group"); |
michael@0 | 79 | is(gBrowser.tabs.length, 1, "we finish with one tab"); |
michael@0 | 80 | ok(!TabView.isVisible(), "we finish with Tab View not visible"); |
michael@0 | 81 | |
michael@0 | 82 | finish(); |
michael@0 | 83 | }); |
michael@0 | 84 | |
michael@0 | 85 | let appTabIcons = groupItemOne.container.getElementsByClassName("appTabIcon"); |
michael@0 | 86 | EventUtils.sendMouseEvent({ type: "click" }, appTabIcons[0], contentWindow); |
michael@0 | 87 | }); |
michael@0 | 88 | gBrowser.pinTab(xulTab); |
michael@0 | 89 | }); |
michael@0 | 90 | }); |
michael@0 | 91 | gBrowser.pinTab(xulTab); |
michael@0 | 92 | } |
michael@0 | 93 | |
michael@0 | 94 | function appTabCount(groupItem) { |
michael@0 | 95 | return groupItem.container.getElementsByClassName("appTabIcon").length; |
michael@0 | 96 | } |