|
1 /* Any copyright is dedicated to the Public Domain. |
|
2 http://creativecommons.org/publicdomain/zero/1.0/ */ |
|
3 |
|
4 let origTab = gBrowser.visibleTabs[0]; |
|
5 let contentWindow; |
|
6 |
|
7 function test() { |
|
8 waitForExplicitFinish(); |
|
9 |
|
10 test1(); |
|
11 } |
|
12 |
|
13 // Open a new tab when the active tab item belongs to a group item. |
|
14 function test1() { |
|
15 registerCleanupFunction(function () TabView.hide()); |
|
16 |
|
17 showTabView(function() { |
|
18 ok(origTab._tabViewTabItem.parent, "The original tab belongs to a group"); |
|
19 |
|
20 contentWindow = TabView.getContentWindow(); |
|
21 contentWindow.UI.setActive(origTab._tabViewTabItem); |
|
22 |
|
23 testCreateTabAndThen(test2); |
|
24 }); |
|
25 } |
|
26 |
|
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 }); |
|
31 |
|
32 testCreateTabAndThen(test3); |
|
33 }); |
|
34 } |
|
35 |
|
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"); |
|
42 |
|
43 let lastTabItem = tabItems[tabItems.length - 1]; |
|
44 groupItem.remove(lastTabItem); |
|
45 |
|
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"); |
|
49 |
|
50 contentWindow.UI.setActive(lastTabItem); |
|
51 |
|
52 testCreateTabAndThen(function() { |
|
53 hideTabView(finish); |
|
54 }); |
|
55 }); |
|
56 } |
|
57 |
|
58 function testCreateTabAndThen(callback) { |
|
59 ok(TabView.isVisible(), "Tab View is visible"); |
|
60 |
|
61 // detect tab open and zoomed in event. |
|
62 let onTabOpen = function(event) { |
|
63 gBrowser.tabContainer.removeEventListener("TabOpen", onTabOpen, false); |
|
64 |
|
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"); |
|
71 |
|
72 registerCleanupFunction(function () gBrowser.removeTab(tab)) |
|
73 |
|
74 tabItem.addSubscriber("zoomedIn", function onZoomedIn() { |
|
75 tabItem.removeSubscriber("zoomedIn", onZoomedIn); |
|
76 |
|
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 } |