Bug 1407987 Part 2: Add a test of finding offscreen text. r=mikedeboer
authorBrad Werth <bwerth@mozilla.com>
Thu, 12 Oct 2017 17:38:46 -0700
changeset 386798 bca102a85314692e03c31da42c257ab9356263ee
parent 386797 bec74ea195454b8117ff4f09b09b008bfdd66b16
child 386799 5e7b8f9471a4f266a21204cefc29a424b2c92a69
push id96311
push userarchaeopteryx@coole-files.de
push dateWed, 18 Oct 2017 09:52:02 +0000
treeherdermozilla-inbound@a8a1e8cc1980 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersmikedeboer
bugs1407987
milestone58.0a1
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 1407987 Part 2: Add a test of finding offscreen text. r=mikedeboer MozReview-Commit-ID: ATQRdHB0Q9j
toolkit/modules/tests/browser/browser.ini
toolkit/modules/tests/browser/browser_Finder_offscreen_text.js
--- a/toolkit/modules/tests/browser/browser.ini
+++ b/toolkit/modules/tests/browser/browser.ini
@@ -22,16 +22,17 @@ support-files =
   WebRequest_dynamic.sjs
   WebRequest_redirection.sjs
 
 [browser_AsyncPrefs.js]
 [browser_Battery.js]
 [browser_Deprecated.js]
 [browser_Finder.js]
 [browser_Finder_hidden_textarea.js]
+[browser_Finder_offscreen_text.js]
 [browser_FinderHighlighter.js]
 skip-if = debug || os = "linux"
 support-files = file_FinderSample.html
 [browser_Geometry.js]
 [browser_InlineSpellChecker.js]
 [browser_WebNavigation.js]
 skip-if = true # Superseded by WebExtension tests
 [browser_WebRequest.js]
new file mode 100644
--- /dev/null
+++ b/toolkit/modules/tests/browser/browser_Finder_offscreen_text.js
@@ -0,0 +1,60 @@
+/* Any copyright is dedicated to the Public Domain.
+ * http://creativecommons.org/publicdomain/zero/1.0/ */
+
+add_task(async function test_offscreen_text() {
+
+  // Generate URI of a big DOM that contains the target text at several
+  // line positions (to force some targets to be offscreen).
+  const linesToGenerate = 155;
+  const linesToInsertTargetText = [5, 50, 150];
+  let targetCount = linesToInsertTargetText.length;
+  let t = 0;
+  const TARGET_TEXT = "findthis";
+
+  let URI = "<body>";
+  for (let i = 0; i < linesToGenerate; i++) {
+    URI += i + "<br>";
+    if (t < targetCount && linesToInsertTargetText[t] == i) {
+      URI += TARGET_TEXT;
+      t++;
+    }
+  }
+  URI += "</body>";
+
+  await BrowserTestUtils.withNewTab({ gBrowser, url: "data:text/html;charset=utf-8," + encodeURIComponent(URI) },
+    async function(browser) {
+      let finder = browser.finder;
+      let listener = {
+        onFindResult() {
+          ok(false, "callback wasn't replaced");
+        }
+      };
+      finder.addResultListener(listener);
+
+      function waitForFind() {
+        return new Promise(resolve => {
+          listener.onFindResult = resolve;
+        })
+      }
+
+      // Find each of the targets.
+      for (let t = 0; t < targetCount; ++t) {
+        let promiseFind = waitForFind();
+        if (t == 0) {
+          finder.fastFind(TARGET_TEXT, false, false);
+        } else {
+          finder.findAgain(false, false, false);
+        }
+        let findResult = await promiseFind;
+        is(findResult.result, Ci.nsITypeAheadFind.FIND_FOUND, "Found target " + t);
+      }
+
+      // Find one more time and make sure we wrap.
+      let promiseFind = waitForFind();
+      finder.findAgain(false, false, false);
+      let findResult = await promiseFind;
+      is(findResult.result, Ci.nsITypeAheadFind.FIND_WRAPPED, "Wrapped to first target");
+
+      finder.removeResultListener(listener);
+    });
+});