Bug 1316515 - Clear the find selection when the findbar input box is cleared. r=Gijs, a=gchang
☠☠ backed out by a99c9599b458 ☠ ☠
authorMike de Boer <mdeboer@mozilla.com>
Mon, 14 Nov 2016 13:29:12 +0100
changeset 352503 9dbda637a860cdc3f9809209f50e47f110977ecf
parent 352502 aca4526abbb954903cfdbf8ef794e291bc8ec0f9
child 352504 adf273962957d0063068a8e17295770a045ba80b
push id6795
push userjlund@mozilla.com
push dateMon, 23 Jan 2017 14:19:46 +0000
treeherdermozilla-esr52@76101b503191 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersGijs, gchang
bugs1316515
milestone52.0a2
Bug 1316515 - Clear the find selection when the findbar input box is cleared. r=Gijs, a=gchang MozReview-Commit-ID: AfmubgbCevw
toolkit/content/tests/chrome/findbar_window.xul
toolkit/modules/FinderHighlighter.jsm
--- a/toolkit/content/tests/chrome/findbar_window.xul
+++ b/toolkit/content/tests/chrome/findbar_window.xul
@@ -260,16 +260,28 @@
           }
         };
         gFindBar.browser.finder.addResultListener(listener);
         // Make sure we resolve _at least_ after five times the find iterator timeout.
         setTimeout(resolve, (ITERATOR_TIMEOUT * 5) + 20);
       });
     }
 
+    function promiseHighlightFinished() {
+      return new Promise(resolve => {
+        let listener = {
+          onHighlightFinished() {
+            gFindBar.browser.finder.removeResultListener(listener);
+            resolve();
+          }
+        };
+        gFindBar.browser.finder.addResultListener(listener);
+      });
+    }
+
     var enterStringIntoFindField = Task.async(function* (str, waitForResult = true) {
       for (let promise, i = 0; i < str.length; i++) {
         if (waitForResult) {
           promise = promiseFindResult();
         }
         let event = document.createEvent("KeyboardEvent");
         event.initKeyEvent("keypress", true, true, null, false, false,
                            false, false, 0, str.charCodeAt(i));
@@ -431,17 +443,16 @@
         Assert.equal(content.getSelection().toString(), args.searchStr,
           "testQuickFindLink: failed to find sample link");
       });
       testClipboardSearchString(searchStr);
     }
 
     // See bug 963925 for more details on this test.
     function* testFindWithHighlight() {
-      //yield clearFocus();
       gFindBar._findField.value = "";
 
       // For this test, we want to closely control the selection. The easiest
       // way to do so is to replace the implementation of
       // Finder.getInitialSelection with a no-op and call the findbar's callback
       // (onCurrentSelection(..., true)) ourselves with our hand-picked
       // selection.
       let oldGetInitialSelection = gFindBar.browser.finder.getInitialSelection;
@@ -485,16 +496,53 @@
       gFindBar.onFindAgainCommand();
       a = gFindBar._findField.value;
       b = gFindBar._browser.finder._fastFind.searchString;
       c = gFindBar._browser.finder.searchString;
       ok(a == b && b == c, "testFindWithHighlight 5: " + a + ", " + b + ", " + c + ".");
 
       highlightButton.click();
       ok(!highlightButton.checked, "testFindWithHighlight: Highlight All should be unchecked.");
+
+      // Regression test for bug 1316515.
+      searchStr = "e";
+      gFindBar.clear();
+      yield enterStringIntoFindField(searchStr);
+
+      yield ContentTask.spawn(gBrowser, {}, function* () {
+        let controller = docShell.QueryInterface(Ci.nsIInterfaceRequestor)
+                                 .getInterface(Ci.nsISelectionDisplay)
+                                 .QueryInterface(Ci.nsISelectionController);
+        let sel = controller.getSelection(Ci.nsISelectionController.SELECTION_FIND);
+        Assert.equal(sel.rangeCount, 0, "testFindWithHighlight - 1316515: no highlights, please [1]");
+      });
+
+      highlightButton.click();
+      ok(highlightButton.checked, "testFindWithHighlight: Highlight All should be checked.");
+
+      yield promiseHighlightFinished();
+
+      yield ContentTask.spawn(gBrowser, {}, function* () {
+        let controller = docShell.QueryInterface(Ci.nsIInterfaceRequestor)
+                                 .getInterface(Ci.nsISelectionDisplay)
+                                 .QueryInterface(Ci.nsISelectionController);
+        let sel = controller.getSelection(Ci.nsISelectionController.SELECTION_FIND);
+        // The other 4 ranges are in a different controller.
+        Assert.equal(sel.rangeCount, 3, "testFindWithHighlight - 1316515: more highlights, please");
+      });
+
+      synthesizeKey("VK_BACK_SPACE", {});
+
+      yield ContentTask.spawn(gBrowser, null, function* () {
+        let controller = docShell.QueryInterface(Ci.nsIInterfaceRequestor)
+                                 .getInterface(Ci.nsISelectionDisplay)
+                                 .QueryInterface(Ci.nsISelectionController);
+        let sel = controller.getSelection(Ci.nsISelectionController.SELECTION_FIND);
+        Assert.equal(sel.rangeCount, 0, "testFindWithHighlight - 1316515: no highlights, please [2]");
+      });
     }
 
     function* testQuickFindText() {
       yield clearFocus();
 
       yield ContentTask.spawn(gBrowser, null, function* () {
         let document = content.document;
         let event = document.createEvent("KeyboardEvent");
--- a/toolkit/modules/FinderHighlighter.jsm
+++ b/toolkit/modules/FinderHighlighter.jsm
@@ -406,33 +406,34 @@ FinderHighlighter.prototype = {
    *   {String}  searchString  The string the search was performed with.
    *   {Boolean} storeResult   Indicator if the search string should be stored
    *                           by the consumer of the Finder.
    */
   update(data) {
     let window = this.finder._getWindow();
     let dict = this.getForWindow(window);
     let foundRange = this.finder._fastFind.getFoundRange();
+
+    if (data.result == Ci.nsITypeAheadFind.FIND_NOTFOUND || !data.searchString || !foundRange) {
+      this.hide();
+      return;
+    }
+
     if (!this._modal) {
       if (this._highlightAll) {
         dict.currentFoundRange = foundRange;
         let params = this.iterator.params;
         if (this.iterator._areParamsEqual(params, dict.lastIteratorParams))
           return;
         if (params)
           this.highlight(true, params.word, params.linksOnly);
       }
       return;
     }
 
-    if (data.result == Ci.nsITypeAheadFind.FIND_NOTFOUND || !data.searchString || !foundRange) {
-      this.hide();
-      return;
-    }
-
     if (foundRange !== dict.currentFoundRange || data.findAgain) {
       dict.currentFoundRange = foundRange;
 
       let textContent = this._getRangeContentArray(foundRange);
       if (!textContent.length) {
         this.hide(window);
         return;
       }