1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/browser/components/tabview/test/browser_tabview_bug633190.js Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,86 @@ 1.4 +/* Any copyright is dedicated to the Public Domain. 1.5 + http://creativecommons.org/publicdomain/zero/1.0/ */ 1.6 + 1.7 +let origTab = gBrowser.visibleTabs[0]; 1.8 +let contentWindow; 1.9 + 1.10 +function test() { 1.11 + waitForExplicitFinish(); 1.12 + 1.13 + test1(); 1.14 +} 1.15 + 1.16 +// Open a new tab when the active tab item belongs to a group item. 1.17 +function test1() { 1.18 + registerCleanupFunction(function () TabView.hide()); 1.19 + 1.20 + showTabView(function() { 1.21 + ok(origTab._tabViewTabItem.parent, "The original tab belongs to a group"); 1.22 + 1.23 + contentWindow = TabView.getContentWindow(); 1.24 + contentWindow.UI.setActive(origTab._tabViewTabItem); 1.25 + 1.26 + testCreateTabAndThen(test2); 1.27 + }); 1.28 +} 1.29 + 1.30 +// Open a new tab when the active tab item is nothing. 1.31 +function test2() { 1.32 + showTabView(function() { 1.33 + contentWindow.UI.setActive(null, { onlyRemoveActiveTab: true }); 1.34 + 1.35 + testCreateTabAndThen(test3); 1.36 + }); 1.37 +} 1.38 + 1.39 +// Open a new tab when the active tab item is an orphan tab. 1.40 +function test3() { 1.41 + showTabView(function() { 1.42 + let groupItem = origTab._tabViewTabItem.parent; 1.43 + let tabItems = groupItem.getChildren(); 1.44 + is(tabItems.length, 3, "There are 3 tab items in the group"); 1.45 + 1.46 + let lastTabItem = tabItems[tabItems.length - 1]; 1.47 + groupItem.remove(lastTabItem); 1.48 + 1.49 + let orphanedTabs = contentWindow.GroupItems.getOrphanedTabs(); 1.50 + is(orphanedTabs.length, 1, "There should be 1 orphan tab"); 1.51 + is(orphanedTabs[0], lastTabItem, "The tab item is the same as the orphan tab"); 1.52 + 1.53 + contentWindow.UI.setActive(lastTabItem); 1.54 + 1.55 + testCreateTabAndThen(function() { 1.56 + hideTabView(finish); 1.57 + }); 1.58 + }); 1.59 +} 1.60 + 1.61 +function testCreateTabAndThen(callback) { 1.62 + ok(TabView.isVisible(), "Tab View is visible"); 1.63 + 1.64 + // detect tab open and zoomed in event. 1.65 + let onTabOpen = function(event) { 1.66 + gBrowser.tabContainer.removeEventListener("TabOpen", onTabOpen, false); 1.67 + 1.68 + // ensure that the default tabview listener is called before so the 1.69 + // tab._tabViewTabItem exists 1.70 + executeSoon(function() { 1.71 + let tab = event.target; 1.72 + tabItem = tab._tabViewTabItem; 1.73 + ok(tabItem, "Tab item is available after tab open"); 1.74 + 1.75 + registerCleanupFunction(function () gBrowser.removeTab(tab)) 1.76 + 1.77 + tabItem.addSubscriber("zoomedIn", function onZoomedIn() { 1.78 + tabItem.removeSubscriber("zoomedIn", onZoomedIn); 1.79 + 1.80 + is(gBrowser.selectedTab, tab, 1.81 + "The selected tab is the same as the newly opened tab"); 1.82 + executeSoon(callback); 1.83 + }); 1.84 + }); 1.85 + } 1.86 + gBrowser.tabContainer.addEventListener("TabOpen", onTabOpen, false); 1.87 + // use the menu item (the same as pressing cmd/ctrl + t) 1.88 + document.getElementById("menu_newNavigatorTab").doCommand(); 1.89 +}