Fixed for Bug 585855 - Test that the bookmark all tabs command is disabled when we have one visible and one hidden tab
☠☠ backed out by 3ed9e49adf6e ☠ ☠
authorRaymond Lee <raymond@raysquare.com>
Wed, 11 Aug 2010 14:16:02 +0800
changeset 50321 ed2484b982b9f0165227626deab7e72559548047
parent 50320 d55ac170d93ab2889ec532fb59a680c802ff2bc5
child 50322 4e6f59ce5d1d4d107a41f57d9f1ea90be2b19304
child 50339 3ed9e49adf6ec8b8ebc2ac47ae81dcc02d6c6337
push id1
push userroot
push dateTue, 26 Apr 2011 22:38:44 +0000
treeherdermozilla-beta@bfdb6e623a36 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
bugs585855
milestone2.0b4pre
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Fixed for Bug 585855 - Test that the bookmark all tabs command is disabled when we have one visible and one hidden tab
browser/base/content/browser.js
browser/base/content/tabbrowser.xml
browser/base/content/test/Makefile.in
browser/base/content/test/browser_visibleTabs_bookmarkAllTabs.js
--- a/browser/base/content/browser.js
+++ b/browser/base/content/browser.js
@@ -1573,16 +1573,18 @@ function BrowserShutdown()
   PlacesStarButton.uninit();
 
   try {
     gPrefService.removeObserver(gHomeButton.prefDomain, gHomeButton);
   } catch (ex) {
     Components.utils.reportError(ex);
   }
 
+  gBookmarkAllTabsHandler.uninit();
+
   BrowserOffline.uninit();
   OfflineApps.uninit();
   DownloadMonitorPanel.uninit();
   gPrivateBrowsingUI.uninit();
 
   var enumerator = Services.wm.getEnumerator(null);
   enumerator.getNext();
   if (!enumerator.hasMoreElements()) {
@@ -4284,17 +4286,17 @@ var XULBrowserWindow = {
         // Close the Find toolbar if we're in old-style TAF mode
         gFindBar.close();
       }
 
       // XXXmano new-findbar, do something useful once it lands.
       // Of course, this is especially wrong with bfcache on...
 
       // fix bug 253793 - turn off highlight when page changes
-      gFindBar.getElement("highlight").checked = false;      
+      gFindBar.getElement("highlight").checked = false;
     }
 
     // See bug 358202, when tabs are switched during a drag operation,
     // timers don't fire on windows (bug 203573)
     if (aRequest)
       setTimeout(function () { XULBrowserWindow.asyncUpdateUI(); }, 0);
     else
       this.asyncUpdateUI();
@@ -6776,24 +6778,28 @@ function formatURL(aFormat, aIsPref) {
 }
 
 /**
  * This also takes care of updating the command enabled-state when tabs are
  * created or removed.
  */
 var gBookmarkAllTabsHandler = {
   init: function () {
+    Services.obs.addObserver(this, "tab-visibility-change", false);
+
     this._command = document.getElementById("Browser:BookmarkAllTabs");
     gBrowser.tabContainer.addEventListener("TabOpen", this, true);
     gBrowser.tabContainer.addEventListener("TabClose", this, true);
-    gBrowser.tabContainer.addEventListener("TabSelect", this, true);
-    gBrowser.tabContainer.addEventListener("TabMove", this, true);
     this._updateCommandState();
   },
 
+  uninit: function () {
+    Services.obs.removeObserver(this, "tab-visibility-change");
+  },
+
   _updateCommandState: function BATH__updateCommandState(aTabClose) {
     let numTabs = gBrowser.visibleTabs.length;
 
     // The TabClose event is fired before the tab is removed from the DOM
     if (aTabClose)
       numTabs--;
 
     if (numTabs > 1)
@@ -6804,17 +6810,22 @@ var gBookmarkAllTabsHandler = {
 
   doCommand: function BATH_doCommand() {
     PlacesCommandHook.bookmarkCurrentPages();
   },
 
   // nsIDOMEventListener
   handleEvent: function(aEvent) {
     this._updateCommandState(aEvent.type == "TabClose");
-  }
+  },
+
+  observe: function(subject, topic, data) {
+    if (topic == "tab-visibility-change" && subject == window)
+      this._updateCommandState();
+  },
 };
 
 /**
  * Utility object to handle manipulations of the identity indicators in the UI
  */
 var gIdentityHandler = {
   // Mode strings used to control CSS display
   IDENTITY_MODE_IDENTIFIED       : "verifiedIdentity", // High-quality identity information
@@ -7848,9 +7859,8 @@ XPCOMUtils.defineLazyGetter(this, "HUDCo
   Cu.import("resource://gre/modules/HUDService.jsm");
   try {
     return HUDService.consoleUI;
   }
   catch (ex) {
     Components.utils.reportError(ex);
   }
 });
-
--- a/browser/base/content/tabbrowser.xml
+++ b/browser/base/content/tabbrowser.xml
@@ -550,17 +550,17 @@
                   aIID.equals(Components.interfaces.nsISupportsWeakReference) ||
                   aIID.equals(Components.interfaces.nsISupports))
                 return this;
               throw Components.results.NS_NOINTERFACE;
             },
 
             _startStalledTimer: function () {
               this._cancelStalledTimer();
-              this._stalledTimer = setTimeout(function (self) { 
+              this._stalledTimer = setTimeout(function (self) {
                 self.mTab.setAttribute("stalled", "true");
               }, 700, this);
             },
 
             _cancelStalledTimer: function () {
               if (this._stalledTimer) {
                 clearTimeout(this._stalledTimer);
                 this._stalledTimer = 0;
@@ -629,17 +629,17 @@
         </body>
       </method>
 
       <method name="useDefaultIcon">
         <parameter name="aTab"/>
         <body>
           <![CDATA[
             var browser = this.getBrowserForTab(aTab);
-            var docURIObject = browser.contentDocument.documentURIObject; 
+            var docURIObject = browser.contentDocument.documentURIObject;
             if (browser.contentDocument instanceof ImageDocument) {
               if (Services.prefs.getBoolPref("browser.chrome.site_icons")) {
                 try {
                   let sz = Services.prefs.getIntPref("browser.chrome.image_icons.max_size");
                   if (!sz)
                     return;
 
                   var req = browser.contentDocument.imageRequest;
@@ -1767,16 +1767,17 @@
 
       <method name="showOnlyTheseTabs">
         <parameter name="aTabs"/>
         <body>
         <![CDATA[
           Array.forEach(this.tabs, function(tab) {
             tab.hidden = aTabs.indexOf(tab) == -1 && !tab.pinned && !tab.selected;
           });
+          Services.obs.notifyObservers(window, "tab-visibility-change", null);
         ]]>
         </body>
       </method>
 
       <method name="selectTabAtIndex">
         <parameter name="aIndex"/>
         <parameter name="aEvent"/>
         <body>
@@ -2720,17 +2721,17 @@
 
       <method name="_getDropIndex">
         <parameter name="event"/>
         <body><![CDATA[
           var tabs = this.childNodes;
           var tab = this._getDragTargetTab(event);
           if (window.getComputedStyle(this, null).direction == "ltr") {
             for (let i = tab ? tab._tPos : 0; i < tabs.length; i++)
-              if (event.screenX < tabs[i].boxObject.screenX + tabs[i].boxObject.width / 2) 
+              if (event.screenX < tabs[i].boxObject.screenX + tabs[i].boxObject.width / 2)
                 return i;
           } else {
             for (let i = tab ? tab._tPos : 0; i < tabs.length; i++)
               if (event.screenX > tabs[i].boxObject.screenX + tabs[i].boxObject.width / 2)
                 return i;
           }
           return tabs.length;
         ]]></body>
@@ -2955,17 +2956,17 @@
             return;
           }
         }
 
         var newIndex = this._getDropIndex(event);
         var scrollRect = tabStrip.scrollClientRect;
         var rect = this.getBoundingClientRect();
         var minMargin = scrollRect.left - rect.left;
-        var maxMargin = Math.min(minMargin + scrollRect.width, 
+        var maxMargin = Math.min(minMargin + scrollRect.width,
                                  scrollRect.right);
         if (!ltr)
           [minMargin, maxMargin] = [this.clientWidth - maxMargin,
                                     this.clientWidth - minMargin];
         var newMargin;
         if (pixelsToScroll) {
           // if we are scrolling, put the drop indicator at the edge
           // so that it doesn't jump while scrolling
@@ -3336,28 +3337,28 @@
           if (tabContainer.getAttribute("overflow") != "true")
             return;
 
           var tabstripBO = tabContainer.mTabstrip.scrollBoxObject;
           for (var i = 0; i < this.childNodes.length; i++) {
             var curTabBO = this.childNodes[i].tab.boxObject;
             if (curTabBO.screenX >= tabstripBO.screenX &&
                 curTabBO.screenX + curTabBO.width <= tabstripBO.screenX + tabstripBO.width)
-              this.childNodes[i].setAttribute("tabIsVisible", "true"); 
+              this.childNodes[i].setAttribute("tabIsVisible", "true");
             else
               this.childNodes[i].removeAttribute("tabIsVisible");
           }
         ]]></body>
       </method>
 
       <method name="_createTabMenuItem">
         <parameter name="aTab"/>
         <body><![CDATA[
           var menuItem = document.createElementNS(
-            "http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul", 
+            "http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul",
             "menuitem");
 
           menuItem.setAttribute("class", "menuitem-iconic alltabs-item menuitem-with-favicon");
 
           this._setMenuitemAttributes(menuItem, aTab);
 
           // Keep some attributes of the menuitem in sync with its
           // corresponding tab (e.g. the tab label)
--- a/browser/base/content/test/Makefile.in
+++ b/browser/base/content/test/Makefile.in
@@ -167,16 +167,17 @@ endif
                  browser_sanitizeDialog.js \
                  browser_scope.js \
                  browser_selectTabAtIndex.js \
                  browser_tabfocus.js \
                  browser_tabs_owner.js \
                  browser_visibleTabs.js \
                  browser_visibleTabs_contextMenu.js \
                  browser_visibleTabs_bookmarkAllPages.js \
+                 browser_visibleTabs_bookmarkAllTabs.js \
                  discovery.html \
                  moz.png \
                  test_bug435035.html \
                  test_bug462673.html \
                  page_style_sample.html \
                  feed_tab.html \
                  plugin_unknown.html \
                  plugin_test.html \
--- a/browser/base/content/test/browser_visibleTabs_bookmarkAllTabs.js
+++ b/browser/base/content/test/browser_visibleTabs_bookmarkAllTabs.js
@@ -31,48 +31,59 @@
  * decision by deleting the provisions above and replace them with the notice
  * and other provisions required by the GPL or the LGPL. If you do not delete
  * the provisions above, a recipient may use your version of this file under
  * the terms of any one of the MPL, the GPL or the LGPL.
  *
  * ***** END LICENSE BLOCK ***** */
 
 function test() {
+  waitForExplicitFinish();
+
   // There should be one tab when we start the test
   let [origTab] = gBrowser.visibleTabs;
-  is(gBrowser.visibleTabs.length, 1, "1 tab should be open");  
+  is(gBrowser.visibleTabs.length, 1, "1 tab should be open");
   is(Disabled(), true, "Bookmark All Tabs should be hidden");
 
   // Add a tab
   let testTab = gBrowser.addTab();
   is(gBrowser.visibleTabs.length, 2, "2 tabs should be open");
   is(Disabled(), false, "Bookmark All Tabs should be available");
 
+  let observe = function(subject, topic, data) {
+    Services.obs.removeObserver(observe, "tab-visibility-change");
+    setTimeout(function() {
+      is(Disabled(), true, "Bookmark All Tabs should be hidden as there is only one visible tab");
+
+      // Add a tab that will get pinned
+      let pinned = gBrowser.addTab();
+      gBrowser.pinTab(pinned);
+      is(gBrowser.visibleTabs.length, 2, "2 tabs should be visible now");
+      is(Disabled(), false, "Bookmark All Tabs should be available as there are two visible tabs");
+
+      // Show all tabs
+      let allTabs = [tab for each (tab in gBrowser.tabs)];
+      gBrowser.showOnlyTheseTabs(allTabs);
+
+      // reset the environment
+      gBrowser.removeTab(testTab);
+      gBrowser.removeTab(pinned);
+      is(gBrowser.visibleTabs.length, 1, "only orig is left and visible");
+      is(gBrowser.tabs.length, 1, "sanity check that it matches");
+      is(Disabled(), true, "Bookmark All Tabs should be hidden");
+      is(gBrowser.selectedTab, origTab, "got the orig tab");
+      is(origTab.hidden, false, "and it's not hidden -- visible!");
+
+      finish();
+    }, 0);
+  }
+  Services.obs.addObserver(observe, "tab-visibility-change", false);
+
   // Hide the original tab
   gBrowser.selectedTab = testTab;
   gBrowser.showOnlyTheseTabs([testTab]);
-  is(gBrowser.visibleTabs.length, 1, "1 tab should be visible");  
-  is(Disabled(), true, "Bookmark All Tabs should be hidden as there is only one visible tab");
-  
-  // Add a tab that will get pinned
-  let pinned = gBrowser.addTab();
-  gBrowser.pinTab(pinned);
-  is(gBrowser.visibleTabs.length, 2, "2 tabs should be visible now");
-  is(Disabled(), false, "Bookmark All Tabs should be available as there are two visible tabs");
-
-  // Show all tabs
-  let allTabs = [tab for each (tab in gBrowser.tabs)];
-  gBrowser.showOnlyTheseTabs(allTabs);
-
-  // reset the environment  
-  gBrowser.removeTab(testTab);
-  gBrowser.removeTab(pinned);
-  is(gBrowser.visibleTabs.length, 1, "only orig is left and visible");
-  is(gBrowser.tabs.length, 1, "sanity check that it matches");
-  is(Disabled(), true, "Bookmark All Tabs should be hidden");
-  is(gBrowser.selectedTab, origTab, "got the orig tab");
-  is(origTab.hidden, false, "and it's not hidden -- visible!");
+  is(gBrowser.visibleTabs.length, 1, "1 tab should be visible");
 }
 
 function Disabled() {
   let command = document.getElementById("Browser:BookmarkAllTabs");
   return command.hasAttribute("disabled") && command.getAttribute("disabled") === "true";
 }
\ No newline at end of file