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 let origTab = gBrowser.visibleTabs[0];
5 let contentWindow;
7 function test() {
8 waitForExplicitFinish();
10 test1();
11 }
13 // Open a new tab when the active tab item belongs to a group item.
14 function test1() {
15 registerCleanupFunction(function () TabView.hide());
17 showTabView(function() {
18 ok(origTab._tabViewTabItem.parent, "The original tab belongs to a group");
20 contentWindow = TabView.getContentWindow();
21 contentWindow.UI.setActive(origTab._tabViewTabItem);
23 testCreateTabAndThen(test2);
24 });
25 }
27 // Open a new tab when the active tab item is nothing.
28 function test2() {
29 showTabView(function() {
30 contentWindow.UI.setActive(null, { onlyRemoveActiveTab: true });
32 testCreateTabAndThen(test3);
33 });
34 }
36 // Open a new tab when the active tab item is an orphan tab.
37 function test3() {
38 showTabView(function() {
39 let groupItem = origTab._tabViewTabItem.parent;
40 let tabItems = groupItem.getChildren();
41 is(tabItems.length, 3, "There are 3 tab items in the group");
43 let lastTabItem = tabItems[tabItems.length - 1];
44 groupItem.remove(lastTabItem);
46 let orphanedTabs = contentWindow.GroupItems.getOrphanedTabs();
47 is(orphanedTabs.length, 1, "There should be 1 orphan tab");
48 is(orphanedTabs[0], lastTabItem, "The tab item is the same as the orphan tab");
50 contentWindow.UI.setActive(lastTabItem);
52 testCreateTabAndThen(function() {
53 hideTabView(finish);
54 });
55 });
56 }
58 function testCreateTabAndThen(callback) {
59 ok(TabView.isVisible(), "Tab View is visible");
61 // detect tab open and zoomed in event.
62 let onTabOpen = function(event) {
63 gBrowser.tabContainer.removeEventListener("TabOpen", onTabOpen, false);
65 // ensure that the default tabview listener is called before so the
66 // tab._tabViewTabItem exists
67 executeSoon(function() {
68 let tab = event.target;
69 tabItem = tab._tabViewTabItem;
70 ok(tabItem, "Tab item is available after tab open");
72 registerCleanupFunction(function () gBrowser.removeTab(tab))
74 tabItem.addSubscriber("zoomedIn", function onZoomedIn() {
75 tabItem.removeSubscriber("zoomedIn", onZoomedIn);
77 is(gBrowser.selectedTab, tab,
78 "The selected tab is the same as the newly opened tab");
79 executeSoon(callback);
80 });
81 });
82 }
83 gBrowser.tabContainer.addEventListener("TabOpen", onTabOpen, false);
84 // use the menu item (the same as pressing cmd/ctrl + t)
85 document.getElementById("menu_newNavigatorTab").doCommand();
86 }