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