browser/base/content/test/general/browser_visibleTabs_bookmarkAllTabs.js

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/browser/base/content/test/general/browser_visibleTabs_bookmarkAllTabs.js	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,66 @@
     1.4 +/* This Source Code Form is subject to the terms of the Mozilla Public
     1.5 + * License, v. 2.0. If a copy of the MPL was not distributed with this
     1.6 + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
     1.7 +
     1.8 +function test() {
     1.9 +  waitForExplicitFinish();
    1.10 +
    1.11 +  // There should be one tab when we start the test
    1.12 +  let [origTab] = gBrowser.visibleTabs;
    1.13 +  is(gBrowser.visibleTabs.length, 1, "1 tab should be open");  
    1.14 +  is(Disabled(), true, "Bookmark All Tabs should be disabled");
    1.15 +
    1.16 +  // Add a tab
    1.17 +  let testTab1 = gBrowser.addTab();
    1.18 +  is(gBrowser.visibleTabs.length, 2, "2 tabs should be open");
    1.19 +  is(Disabled(), true, "Bookmark All Tabs should be disabled since there are two tabs with the same address");
    1.20 +
    1.21 +  let testTab2 = gBrowser.addTab("about:mozilla");
    1.22 +  is(gBrowser.visibleTabs.length, 3, "3 tabs should be open");
    1.23 +  // Wait for tab load, the code checks for currentURI.
    1.24 +  testTab2.linkedBrowser.addEventListener("load", function () {
    1.25 +    testTab2.linkedBrowser.removeEventListener("load", arguments.callee, true);
    1.26 +    is(Disabled(), false, "Bookmark All Tabs should be enabled since there are two tabs with different addresses");
    1.27 +
    1.28 +    // Hide the original tab
    1.29 +    gBrowser.selectedTab = testTab2;
    1.30 +    gBrowser.showOnlyTheseTabs([testTab2]);
    1.31 +    is(gBrowser.visibleTabs.length, 1, "1 tab should be visible");  
    1.32 +    is(Disabled(), true, "Bookmark All Tabs should be disabled as there is only one visible tab");
    1.33 +
    1.34 +    // Add a tab that will get pinned
    1.35 +    let pinned = gBrowser.addTab();
    1.36 +    is(gBrowser.visibleTabs.length, 2, "2 tabs should be visible now");
    1.37 +    is(Disabled(), false, "Bookmark All Tabs should be available as there are two visible tabs");
    1.38 +    gBrowser.pinTab(pinned);
    1.39 +    is(Hidden(), false, "Bookmark All Tabs should be visible on a normal tab");
    1.40 +    is(Disabled(), true, "Bookmark All Tabs should not be available since one tab is pinned");
    1.41 +    gBrowser.selectedTab = pinned;
    1.42 +    is(Hidden(), true, "Bookmark All Tabs should be hidden on a pinned tab");
    1.43 +
    1.44 +    // Show all tabs
    1.45 +    let allTabs = [tab for each (tab in gBrowser.tabs)];
    1.46 +    gBrowser.showOnlyTheseTabs(allTabs);
    1.47 +
    1.48 +    // reset the environment  
    1.49 +    gBrowser.removeTab(testTab2);
    1.50 +    gBrowser.removeTab(testTab1);
    1.51 +    gBrowser.removeTab(pinned);
    1.52 +    is(gBrowser.visibleTabs.length, 1, "only orig is left and visible");
    1.53 +    is(gBrowser.tabs.length, 1, "sanity check that it matches");
    1.54 +    is(Disabled(), true, "Bookmark All Tabs should be hidden");
    1.55 +    is(gBrowser.selectedTab, origTab, "got the orig tab");
    1.56 +    is(origTab.hidden, false, "and it's not hidden -- visible!");
    1.57 +    finish();
    1.58 +  }, true);
    1.59 +}
    1.60 +
    1.61 +function Disabled() {
    1.62 +  updateTabContextMenu();
    1.63 +  return document.getElementById("Browser:BookmarkAllTabs").getAttribute("disabled") == "true";
    1.64 +}
    1.65 +
    1.66 +function Hidden() {
    1.67 +  updateTabContextMenu();
    1.68 +  return document.getElementById("context_bookmarkAllTabs").hidden;
    1.69 +}

mercurial