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 | let originalGroupItem = null; |
michael@0 | 11 | let originalTab = null; |
michael@0 | 12 | |
michael@0 | 13 | function onTabViewWindowLoaded() { |
michael@0 | 14 | ok(TabView.isVisible(), "Tab View is visible"); |
michael@0 | 15 | |
michael@0 | 16 | let contentWindow = TabView.getContentWindow(); |
michael@0 | 17 | |
michael@0 | 18 | is(contentWindow.GroupItems.groupItems.length, 1, "There is one group item on startup"); |
michael@0 | 19 | originalGroupItem = contentWindow.GroupItems.groupItems[0]; |
michael@0 | 20 | is(originalGroupItem.getChildren().length, 1, "There should be one Tab Item in that group."); |
michael@0 | 21 | contentWindow.UI.setActive(originalGroupItem); |
michael@0 | 22 | |
michael@0 | 23 | [originalTab] = gBrowser.visibleTabs; |
michael@0 | 24 | |
michael@0 | 25 | testEmptyGroupItem(contentWindow); |
michael@0 | 26 | } |
michael@0 | 27 | |
michael@0 | 28 | function testEmptyGroupItem(contentWindow) { |
michael@0 | 29 | let groupItemCount = contentWindow.GroupItems.groupItems.length; |
michael@0 | 30 | |
michael@0 | 31 | // create empty group item |
michael@0 | 32 | let emptyGroupItem = createEmptyGroupItem(contentWindow, 300, 300, 100); |
michael@0 | 33 | ok(emptyGroupItem.isEmpty(), "This group is empty"); |
michael@0 | 34 | |
michael@0 | 35 | is(contentWindow.GroupItems.groupItems.length, ++groupItemCount, |
michael@0 | 36 | "The number of groups is increased by 1"); |
michael@0 | 37 | |
michael@0 | 38 | emptyGroupItem.addSubscriber("close", function onClose() { |
michael@0 | 39 | emptyGroupItem.removeSubscriber("close", onClose); |
michael@0 | 40 | |
michael@0 | 41 | // check the number of groups. |
michael@0 | 42 | is(contentWindow.GroupItems.groupItems.length, --groupItemCount, |
michael@0 | 43 | "The number of groups is decreased by 1"); |
michael@0 | 44 | |
michael@0 | 45 | testGroupItemWithTabItem(contentWindow); |
michael@0 | 46 | }); |
michael@0 | 47 | |
michael@0 | 48 | let closeButton = emptyGroupItem.container.getElementsByClassName("close"); |
michael@0 | 49 | ok(closeButton[0], "Group close button exists"); |
michael@0 | 50 | |
michael@0 | 51 | // click the close button |
michael@0 | 52 | EventUtils.synthesizeMouse(closeButton[0], 1, 1, {}, contentWindow); |
michael@0 | 53 | } |
michael@0 | 54 | |
michael@0 | 55 | function testGroupItemWithTabItem(contentWindow) { |
michael@0 | 56 | let groupItem = createEmptyGroupItem(contentWindow, 300, 300, 200); |
michael@0 | 57 | let tabItemCount = 0; |
michael@0 | 58 | |
michael@0 | 59 | let onTabViewShown = function() { |
michael@0 | 60 | let tabItem = groupItem.getChild(groupItem.getChildren().length - 1); |
michael@0 | 61 | ok(tabItem, "Tab item exists"); |
michael@0 | 62 | |
michael@0 | 63 | let tabItemClosed = false; |
michael@0 | 64 | tabItem.addSubscriber("close", function onClose() { |
michael@0 | 65 | tabItem.removeSubscriber("close", onClose); |
michael@0 | 66 | tabItemClosed = true; |
michael@0 | 67 | }); |
michael@0 | 68 | tabItem.addSubscriber("tabRemoved", function onTabRemoved() { |
michael@0 | 69 | tabItem.removeSubscriber("tabRemoved", onTabRemoved); |
michael@0 | 70 | |
michael@0 | 71 | ok(tabItemClosed, "The tab item is closed"); |
michael@0 | 72 | is(groupItem.getChildren().length, --tabItemCount, |
michael@0 | 73 | "The number of children in new tab group is decreased by 1"); |
michael@0 | 74 | |
michael@0 | 75 | ok(TabView.isVisible(), "Tab View is still shown"); |
michael@0 | 76 | |
michael@0 | 77 | // Now there should only be one tab left, so we need to hide TabView |
michael@0 | 78 | // and go into that tab. |
michael@0 | 79 | is(gBrowser.tabs.length, 1, "There is only one tab left"); |
michael@0 | 80 | |
michael@0 | 81 | // after the last selected tabitem is closed, there would be not active |
michael@0 | 82 | // tabitem on the UI so we set the active tabitem before toggling the |
michael@0 | 83 | // visibility of tabview |
michael@0 | 84 | let tabItems = contentWindow.TabItems.getItems(); |
michael@0 | 85 | ok(tabItems[0], "A tab item exists"); |
michael@0 | 86 | contentWindow.UI.setActive(tabItems[0]); |
michael@0 | 87 | |
michael@0 | 88 | hideTabView(function() { |
michael@0 | 89 | ok(!TabView.isVisible(), "Tab View is hidden"); |
michael@0 | 90 | |
michael@0 | 91 | closeGroupItem(groupItem, finish); |
michael@0 | 92 | }); |
michael@0 | 93 | }); |
michael@0 | 94 | |
michael@0 | 95 | // remove the tab item. The code detects mousedown and mouseup so we stimulate here |
michael@0 | 96 | let closeButton = tabItem.container.getElementsByClassName("close"); |
michael@0 | 97 | ok(closeButton, "Tab item close button exists"); |
michael@0 | 98 | |
michael@0 | 99 | EventUtils.sendMouseEvent({ type: "mousedown" }, closeButton[0], contentWindow); |
michael@0 | 100 | EventUtils.sendMouseEvent({ type: "mouseup" }, closeButton[0], contentWindow); |
michael@0 | 101 | }; |
michael@0 | 102 | |
michael@0 | 103 | whenTabViewIsHidden(function() { |
michael@0 | 104 | is(groupItem.getChildren().length, ++tabItemCount, |
michael@0 | 105 | "The number of children in new tab group is increased by 1"); |
michael@0 | 106 | |
michael@0 | 107 | ok(!TabView.isVisible(), "Tab View is hidden because we just opened a tab"); |
michael@0 | 108 | showTabView(onTabViewShown); |
michael@0 | 109 | }); |
michael@0 | 110 | groupItem.newTab(); |
michael@0 | 111 | } |