michael@0: /* This Source Code Form is subject to the terms of the Mozilla Public michael@0: * License, v. 2.0. If a copy of the MPL was not distributed with this michael@0: * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ michael@0: michael@0: function test() { michael@0: waitForExplicitFinish(); michael@0: michael@0: // There should be one tab when we start the test michael@0: let [origTab] = gBrowser.visibleTabs; michael@0: is(gBrowser.visibleTabs.length, 1, "1 tab should be open"); michael@0: is(Disabled(), true, "Bookmark All Tabs should be disabled"); michael@0: michael@0: // Add a tab michael@0: let testTab1 = gBrowser.addTab(); michael@0: is(gBrowser.visibleTabs.length, 2, "2 tabs should be open"); michael@0: is(Disabled(), true, "Bookmark All Tabs should be disabled since there are two tabs with the same address"); michael@0: michael@0: let testTab2 = gBrowser.addTab("about:mozilla"); michael@0: is(gBrowser.visibleTabs.length, 3, "3 tabs should be open"); michael@0: // Wait for tab load, the code checks for currentURI. michael@0: testTab2.linkedBrowser.addEventListener("load", function () { michael@0: testTab2.linkedBrowser.removeEventListener("load", arguments.callee, true); michael@0: is(Disabled(), false, "Bookmark All Tabs should be enabled since there are two tabs with different addresses"); michael@0: michael@0: // Hide the original tab michael@0: gBrowser.selectedTab = testTab2; michael@0: gBrowser.showOnlyTheseTabs([testTab2]); michael@0: is(gBrowser.visibleTabs.length, 1, "1 tab should be visible"); michael@0: is(Disabled(), true, "Bookmark All Tabs should be disabled as there is only one visible tab"); michael@0: michael@0: // Add a tab that will get pinned michael@0: let pinned = gBrowser.addTab(); michael@0: is(gBrowser.visibleTabs.length, 2, "2 tabs should be visible now"); michael@0: is(Disabled(), false, "Bookmark All Tabs should be available as there are two visible tabs"); michael@0: gBrowser.pinTab(pinned); michael@0: is(Hidden(), false, "Bookmark All Tabs should be visible on a normal tab"); michael@0: is(Disabled(), true, "Bookmark All Tabs should not be available since one tab is pinned"); michael@0: gBrowser.selectedTab = pinned; michael@0: is(Hidden(), true, "Bookmark All Tabs should be hidden on a pinned tab"); michael@0: michael@0: // Show all tabs michael@0: let allTabs = [tab for each (tab in gBrowser.tabs)]; michael@0: gBrowser.showOnlyTheseTabs(allTabs); michael@0: michael@0: // reset the environment michael@0: gBrowser.removeTab(testTab2); michael@0: gBrowser.removeTab(testTab1); michael@0: gBrowser.removeTab(pinned); michael@0: is(gBrowser.visibleTabs.length, 1, "only orig is left and visible"); michael@0: is(gBrowser.tabs.length, 1, "sanity check that it matches"); michael@0: is(Disabled(), true, "Bookmark All Tabs should be hidden"); michael@0: is(gBrowser.selectedTab, origTab, "got the orig tab"); michael@0: is(origTab.hidden, false, "and it's not hidden -- visible!"); michael@0: finish(); michael@0: }, true); michael@0: } michael@0: michael@0: function Disabled() { michael@0: updateTabContextMenu(); michael@0: return document.getElementById("Browser:BookmarkAllTabs").getAttribute("disabled") == "true"; michael@0: } michael@0: michael@0: function Hidden() { michael@0: updateTabContextMenu(); michael@0: return document.getElementById("context_bookmarkAllTabs").hidden; michael@0: }