browser/components/tabview/test/browser_tabview_bug633190.js

Wed, 31 Dec 2014 06:09:35 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Wed, 31 Dec 2014 06:09:35 +0100
changeset 0
6474c204b198
permissions
-rw-r--r--

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

mercurial