Bug 567306 - Find command(ctrl+F) does not start looking for it with a selected text on the actual page (r=gavin, a=blocking)
authormano@mozilla.com
Thu, 14 Oct 2010 19:32:34 +0700
changeset 55769 9fd4170ac5919cba3a2b7b828faee78436d2455d
parent 55768 bebe4e0ed795cabd6988f47af3a6e94dea1ad5d9
child 55770 4169f7ac4cf28f96dae6a43d84c2aca7681c86f4
push id16275
push userdietrich@mozilla.com
push dateThu, 14 Oct 2010 12:40:20 +0000
treeherdermozilla-central@9fd4170ac591 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersgavin, blocking
bugs567306
milestone2.0b8pre
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
Bug 567306 - Find command(ctrl+F) does not start looking for it with a selected text on the actual page (r=gavin, a=blocking)
browser/base/content/browser.js
browser/base/content/test/Makefile.in
browser/base/content/test/browser_bug567306.js
browser/base/content/test/browser_typeAheadFind.js
toolkit/content/widgets/findbar.xml
--- a/browser/base/content/browser.js
+++ b/browser/base/content/browser.js
@@ -110,24 +110,24 @@ var gEditUIVisible = true;
 });
 
 // Smart getter for the findbar.  If you don't wish to force the creation of
 // the findbar, check gFindBarInitialized first.
 var gFindBarInitialized = false;
 XPCOMUtils.defineLazyGetter(window, "gFindBar", function() {
   let XULNS = "http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul";
   let findbar = document.createElementNS(XULNS, "findbar");
-  findbar.setAttribute("browserid", "content");
   findbar.id = "FindToolbar";
 
   let browserBottomBox = document.getElementById("browser-bottombox");
   browserBottomBox.insertBefore(findbar, browserBottomBox.firstChild);
 
   // Force a style flush to ensure that our binding is attached.
   findbar.clientTop;
+  findbar.browser = gBrowser;
   window.gFindBarInitialized = true;
   return findbar;
 });
 
 __defineGetter__("gPrefService", function() {
   delete this.gPrefService;
   return this.gPrefService = Services.prefs;
 });
--- a/browser/base/content/test/Makefile.in
+++ b/browser/base/content/test/Makefile.in
@@ -89,16 +89,17 @@ endif
 # browser_sanitizeDialog_treeView.js is disabled until the tree view is added
 # back to the clear recent history dialog (santize.xul), if it ever is (bug
 # 480169)
 
 # browser_drag.js is disabled, as it needs to be updated for the new behavior from bug 320638.
 
 _BROWSER_FILES = \
                  browser_typeAheadFind.js \
+                 browser_bug567306.js \
                  browser_keywordSearch.js \
                  browser_NetworkPrioritizer.js \
                  browser_allTabsPanel.js \
                  browser_alltabslistener.js \
                  browser_bug304198.js \
                  browser_bug321000.js \
                  title_test.svg \
                  browser_bug329212.js \
new file mode 100644
--- /dev/null
+++ b/browser/base/content/test/browser_bug567306.js
@@ -0,0 +1,42 @@
+/* Any copyright is dedicated to the Public Domain.
+ * http://creativecommons.org/publicdomain/zero/1.0/
+ */
+
+let testWindow = null;
+function test() {
+  waitForExplicitFinish();
+  testWindow = OpenBrowserWindow();
+  testWindow.addEventListener("load", function() {
+    testWindow.removeEventListener("load", arguments.callee, true);
+    executeSoon(function() {
+      ok(true, "Load listener called");
+      testWindow.gBrowser.selectedBrowser.addEventListener("pageshow", function () {
+        ok(true, "Pageshow listener called");
+        testWindow.gBrowser.selectedBrowser.removeEventListener("pageshow", arguments.callee, false);
+        waitForFocus(onFocus, testWindow.content);
+      }, true);
+      testWindow.content.location = "data:text/html,<h1 id='h1'>Select Me</h1>";
+    });
+  }, false);
+}
+
+function selectText() {
+  let elt = testWindow.content.document.getElementById("h1");
+  let selection = testWindow.content.getSelection();
+  let range = testWindow.content.document.createRange();
+  range.setStart(elt, 0);
+  range.setEnd(elt, 1);
+  selection.removeAllRanges();
+  selection.addRange(range);
+}
+
+
+function onFocus() {
+  ok(!testWindow.gFindBarInitialized, "find bar is not yet initialized");
+  selectText();
+  testWindow.gFindBar.onFindCommand();
+  ok(testWindow.gFindBar._findField.value == "Select Me", "Findbar is initialized with selection");
+  testWindow.gFindBar.close();
+  testWindow.close();
+  finish();
+}
--- a/browser/base/content/test/browser_typeAheadFind.js
+++ b/browser/base/content/test/browser_typeAheadFind.js
@@ -1,60 +1,30 @@
-/* ***** BEGIN LICENSE BLOCK *****
- * Version: MPL 1.1/GPL 2.0/LGPL 2.1
- *
- * The contents of this file are subject to the Mozilla Public License Version
- * 1.1 (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- * http://www.mozilla.org/MPL/
- *
- * Software distributed under the License is distributed on an "AS IS" basis,
- * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
- * for the specific language governing rights and limitations under the
- * License.
- *
- * The Original Code is typeaheadfind test code.
- *
- * The Initial Developer of the Original Code is
- * the Mozilla Foundation.
- * Portions created by the Initial Developer are Copyright (C) 2010
- * the Initial Developer. All Rights Reserved.
- *
- * Contributor(s):
- *  Gavin Sharp <gavin@gavinsharp.com> (Original Author)
- *
- * Alternatively, the contents of this file may be used under the terms of
- * either the GNU General Public License Version 2 or later (the "GPL"), or
- * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
- * in which case the provisions of the GPL or the LGPL are applicable instead
- * of those above. If you wish to allow use of your version of this file only
- * under the terms of either the GPL or the LGPL, and not to allow others to
- * use your version of this file under the terms of the MPL, indicate your
- * 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 ***** */
+/* Any copyright is dedicated to the Public Domain.
+ * http://creativecommons.org/publicdomain/zero/1.0/
+ */
 
+let testWindow = null;
 function test() {
   waitForExplicitFinish();
-  ok(!gFindBarInitialized, "find bar is not yet initialized");
-
-  let tab = gBrowser.addTab();
-  gBrowser.selectedTab = tab;
-  tab.linkedBrowser.addEventListener("load", function(aEvent) {
-    tab.linkedBrowser.removeEventListener("load", arguments.callee, true);
-
+  testWindow = OpenBrowserWindow();
+  testWindow.addEventListener("load", function() {
+    testWindow.removeEventListener("load", arguments.callee, true);
     ok(true, "Load listener called");
-    waitForFocus(onFocus, content);
-  }, true);
-
-  content.location = "data:text/html,<h1>A Page</h1>";
+    executeSoon(function() {
+      ok(!testWindow.gFindBarInitialized, "find bar is not yet initialized");
+      testWindow.gBrowser.selectedBrowser.addEventListener("pageshow", function () {
+        ok(true, "Pageshow listener called");
+        testWindow.gBrowser.selectedBrowser.removeEventListener("pageshow", arguments.callee, false);
+        waitForFocus(onFocus, testWindow.content);
+      }, true);
+      testWindow.content.location = "data:text/html,<h1>A Page</h1>";
+    });
+  }, false);
 }
 
 function onFocus() {
   EventUtils.synthesizeKey("/", {});
-  ok(gFindBarInitialized, "find bar is now initialized");
-  gFindBar.close();
-  gBrowser.removeCurrentTab();
+  ok(testWindow.gFindBarInitialized, "find bar is now initialized");
+  testWindow.gFindBar.close();
+  testWindow.close();
   finish();
 }
--- a/toolkit/content/widgets/findbar.xml
+++ b/toolkit/content/widgets/findbar.xml
@@ -399,17 +399,18 @@
         this.nsITypeAheadFind = Components.interfaces.nsITypeAheadFind;
         this.nsISelectionController = Components.interfaces.nsISelectionController;
         this._findSelection = this.nsISelectionController.SELECTION_FIND;
 
         this._findResetTimeout = -1;
 
         // Make sure the FAYT keypress listener is attached by initializing the
         // browser property
-        setTimeout(function(aSelf) { aSelf.browser = aSelf.browser; }, 0, this);
+        if (this.getAttribute("browserid"))
+          setTimeout(function(aSelf) { aSelf.browser = aSelf.browser; }, 0, this);
       ]]></constructor>
 
       <destructor><![CDATA[
         this.destroy();
       ]]></destructor>
 
       <!-- This is necessary because the destructor isn't called when
            we are removed from a document that is not destroyed. This