Bug 1302178 - fix a regression that made the modal highlight not disappear between page navigations. r?jaws draft
authorMike de Boer <mdeboer@mozilla.com>
Tue, 13 Sep 2016 16:42:12 +0200
changeset 413086 a5a0296021a29b4c9536a76cb3d24ad73aa83b75
parent 413068 44a738ae4045683e9f5b6a0ddb1ee2604b970e11
child 531126 370e38c268647da96a0bd3fb967edf9572252cf7
push id29324
push usermdeboer@mozilla.com
push dateTue, 13 Sep 2016 14:42:46 +0000
reviewersjaws
bugs1302178
milestone51.0a1
Bug 1302178 - fix a regression that made the modal highlight not disappear between page navigations. r?jaws MozReview-Commit-ID: KIrOvR8Pdps
toolkit/modules/FinderHighlighter.jsm
toolkit/modules/tests/browser/browser_FinderHighlighter.js
--- a/toolkit/modules/FinderHighlighter.jsm
+++ b/toolkit/modules/FinderHighlighter.jsm
@@ -472,16 +472,17 @@ FinderHighlighter.prototype = {
   /**
    * When the current page is refreshed or navigated away from, the CanvasFrame
    * contents is not valid anymore, i.e. all anonymous content is destroyed.
    * We need to clear the references we keep, which'll make sure we redraw
    * everything when the user starts to find in page again.
    */
   onLocationChange() {
     let window = this.finder._getWindow();
+    this.hide(window);
     let dict = this.getForWindow(window);
     this.clear(window);
     dict.currentFoundRange = null;
 
     if (!dict.modalHighlightOutline)
       return;
 
     if (kDebug) {
--- a/toolkit/modules/tests/browser/browser_FinderHighlighter.js
+++ b/toolkit/modules/tests/browser/browser_FinderHighlighter.js
@@ -55,37 +55,39 @@ function promiseEnterStringIntoFindField
     findbar._findField.inputField.dispatchEvent(event);
   }
   return promise;
 }
 
 function promiseTestHighlighterOutput(browser, word, expectedResult, extraTest = () => {}) {
   return ContentTask.spawn(browser, { word, expectedResult, extraTest: extraTest.toSource() },
     function* ({ word, expectedResult, extraTest }) {
-    let document = content.document;
+    Cu.import("resource://gre/modules/Timer.jsm", this);
 
     return new Promise((resolve, reject) => {
       let stubbed = {};
       let callCounts = {
         insertCalls: [],
         removeCalls: []
       };
 
       // Amount of milliseconds to wait after the last time one of our stubs
       // was called.
       const kTimeoutMs = 1000;
       // The initial timeout may wait for a while for results to come in.
-      let timeout = content.setTimeout(() => finish(false, "Timeout"), kTimeoutMs * 5);
+      let timeout = setTimeout(() => finish(false, "Timeout"), kTimeoutMs * 5);
 
       function finish(ok = true, message = "finished with error") {
         // Restore the functions we stubbed out.
-        document.insertAnonymousContent = stubbed.insert;
-        document.removeAnonymousContent = stubbed.remove;
+        try {
+          content.document.insertAnonymousContent = stubbed.insert;
+          content.document.removeAnonymousContent = stubbed.remove;
+        } catch(ex) {}
         stubbed = {};
-        content.clearTimeout(timeout);
+        clearTimeout(timeout);
 
         if (expectedResult.rectCount !== 0)
           Assert.ok(ok, message);
 
         Assert.greaterOrEqual(callCounts.insertCalls.length, expectedResult.insertCalls[0],
           `Min. insert calls should match for '${word}'.`);
         Assert.lessOrEqual(callCounts.insertCalls.length, expectedResult.insertCalls[1],
           `Max. insert calls should match for '${word}'.`);
@@ -111,27 +113,29 @@ function promiseTestHighlighterOutput(br
         extraTest(lastMaskNode);
 
         resolve();
       }
 
       // Create a function that will stub the original version and collects
       // the arguments so we can check the results later.
       function stub(which) {
-        stubbed[which] = document[which + "AnonymousContent"];
+        stubbed[which] = content.document[which + "AnonymousContent"];
         let prop = which + "Calls";
         return function(node) {
           callCounts[prop].push(node);
-          content.clearTimeout(timeout);
-          timeout = content.setTimeout(finish, kTimeoutMs);
-          return stubbed[which].call(document, node);
+          clearTimeout(timeout);
+          timeout = setTimeout(() => {
+            finish();
+          }, kTimeoutMs);
+          return stubbed[which].call(content.document, node);
         };
       }
-      document.insertAnonymousContent = stub("insert");
-      document.removeAnonymousContent = stub("remove");
+      content.document.insertAnonymousContent = stub("insert");
+      content.document.removeAnonymousContent = stub("remove");
     });
   });
 }
 
 add_task(function* setup() {
   yield SpecialPowers.pushPrefEnv({ set: [
     [kHighlightAllPref, true],
     [kPrefModalHighlight, true]
@@ -335,8 +339,38 @@ add_task(function* testXMLDocument() {
     };
     let promise = promiseTestHighlighterOutput(browser, word, expectedResult);
     yield promiseEnterStringIntoFindField(findbar, word);
     yield promise;
 
     findbar.close(true);
   });
 });
+
+add_task(function* testHideOnLocationChange() {
+  let url = kFixtureBaseURL + "file_FinderSample.html";
+  let tab = yield BrowserTestUtils.openNewForegroundTab(gBrowser, url);
+  let browser = tab.linkedBrowser;
+  let findbar = gBrowser.getFindBar();
+
+  yield promiseOpenFindbar(findbar);
+
+  let word = "Roland";
+  let expectedResult = {
+    rectCount: 1,
+    insertCalls: [2, 4],
+    removeCalls: [1, 2]
+  };
+  let promise = promiseTestHighlighterOutput(browser, word, expectedResult);
+  yield promiseEnterStringIntoFindField(findbar, word);
+  yield promise;
+
+  // Now we try to navigate away! (Using the same page)
+  promise = promiseTestHighlighterOutput(browser, word, {
+    rectCount: 0,
+    insertCalls: [0, 0],
+    removeCalls: [1, 2]
+  });
+  yield BrowserTestUtils.loadURI(browser, url);
+  yield promise;
+
+  yield BrowserTestUtils.removeTab(tab);
+});