Bug 569342 - Find bar should not be enabled in about:addons [r=dtownsend,gavin a=blocking]
authorMargaret Leibovic <mleibovic@mozilla.com>
Fri, 21 Jan 2011 09:18:21 -0800
changeset 61087 ffb56732bdbeba4566897e7656a99b257749cc17
parent 61086 2a14b48cc2877c945798f99b4c13719e7c944f91
child 61088 f9e25d57bb252f1099ed8d3de25520ed0d39e32c
push idunknown
push userunknown
push dateunknown
reviewersdtownsend, gavin, blocking
bugs569342
milestone2.0b10pre
Bug 569342 - Find bar should not be enabled in about:addons [r=dtownsend,gavin a=blocking]
browser/base/content/browser.js
browser/base/content/test/browser_zbug569342.js
--- a/browser/base/content/browser.js
+++ b/browser/base/content/browser.js
@@ -4314,16 +4314,31 @@ var XULBrowserWindow = {
       var disableChrome = this.inContentWhitelist.some(function(aSpec) {
         return aSpec == location;
       });
 
       if (disableChrome)
         document.documentElement.setAttribute("disablechrome", "true");
       else
         document.documentElement.removeAttribute("disablechrome");
+
+      // Disable find commands in documents that ask for them to be disabled.
+      let docElt = content.document.documentElement;
+      let disableFind = aLocationURI &&
+        (docElt && docElt.getAttribute("disablefastfind") == "true") &&
+        (aLocationURI.schemeIs("about") || aLocationURI.schemeIs("chrome"));
+      let findCommands = [document.getElementById("cmd_find"),
+                          document.getElementById("cmd_findAgain"),
+                          document.getElementById("cmd_findPrevious")];
+      findCommands.forEach(function (elt) {
+        if (disableFind)
+          elt.setAttribute("disabled", "true");
+        else
+          elt.removeAttribute("disabled");
+      });
     }
     UpdateBackForwardCommands(gBrowser.webNavigation);
 
     if (gFindBarInitialized) {
       if (gFindBar.findMode != gFindBar.FIND_NORMAL) {
         // Close the Find toolbar if we're in old-style TAF mode
         gFindBar.close();
       }
--- a/browser/base/content/test/browser_zbug569342.js
+++ b/browser/base/content/test/browser_zbug569342.js
@@ -1,48 +1,63 @@
 /* Any copyright is dedicated to the Public Domain.
  * http://creativecommons.org/publicdomain/zero/1.0/
  */
 
 var gTab = null;
 
-function cleanUp() {
-  gBrowser.removeTab(gTab);
-  finish();
-}
-
-// function borrowed from browser_bug386835.js
-function load(tab, url, cb) {
-  tab.linkedBrowser.addEventListener("load", function (event) {
-    event.currentTarget.removeEventListener("load", arguments.callee, true);
+function load(url, cb) {
+  gTab = gBrowser.addTab(url);
+  gBrowser.addEventListener("load", function (event) {
+    gBrowser.removeEventListener("load", arguments.callee, true);
+    // Trigger onLocationChange by switching tabs.
+    gBrowser.selectedTab = gTab;
     cb();
   }, true);
-  tab.linkedBrowser.loadURI(url);
 }
 
 function test() {
   waitForExplicitFinish();
 
-  gTab = gBrowser.selectedTab = gBrowser.addTab();
   ok(gFindBar.hidden, "Find bar should not be visible");
 
   run_test_1();
 }
 
 function run_test_1() {
-  load(gTab, "about:config", function() {
+  load("about:config", function() {
     ok(gFindBar.hidden, "Find bar should not be visible");
     EventUtils.synthesizeKey("/", {}, gTab.linkedBrowser.contentWindow);
     ok(gFindBar.hidden, "Find bar should not be visible");
+    EventUtils.synthesizeKey("f", { accelKey: true });
+    ok(gFindBar.hidden, "Find bar should not be visible");
+    ok(document.getElementById("cmd_find").getAttribute("disabled"),
+       "Find command should be disabled");
 
+    gBrowser.removeTab(gTab);
     run_test_2();
   });
 }
 
 function run_test_2() {
-  load(gTab, "about:addons", function() {
+  load("about:addons", function() {
     ok(gFindBar.hidden, "Find bar should not be visible");
     EventUtils.synthesizeKey("/", {}, gTab.linkedBrowser.contentWindow);
     ok(gFindBar.hidden, "Find bar should not be visible");
+    EventUtils.synthesizeKey("f", { accelKey: true });
+    ok(gFindBar.hidden, "Find bar should not be visible");
+    ok(document.getElementById("cmd_find").getAttribute("disabled"),
+       "Find command should be disabled");
 
-    cleanUp();
+    gBrowser.removeTab(gTab);
+    run_test_3();
   });
 }
+
+function run_test_3() {
+  load("about:blank", function() {
+    ok(!document.getElementById("cmd_find").getAttribute("disabled"),
+       "Find command should not be disabled");
+
+    gBrowser.removeTab(gTab);
+    finish();
+  });
+}
\ No newline at end of file