summaryrefslogtreecommitdiffstats
path: root/browser/base/content/test/general/browser_visibleFindSelection.js
blob: 63049064486f41cc7306e698f56b92b62ea6bf37 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
add_task(function*() {
  const childContent = "<div style='position: absolute; left: 2200px; background: green; width: 200px; height: 200px;'>" +
                       "div</div><div  style='position: absolute; left: 0px; background: red; width: 200px; height: 200px;'>" +
                       "<span id='s'>div</span></div>";

  let tab = gBrowser.selectedTab = gBrowser.addTab();

  yield promiseTabLoadEvent(tab, "data:text/html," + escape(childContent));
  yield SimpleTest.promiseFocus(gBrowser.selectedBrowser.contentWindowAsCPOW);

  let findBarOpenPromise = promiseWaitForEvent(gBrowser, "findbaropen");
  EventUtils.synthesizeKey("f", { accelKey: true });
  yield findBarOpenPromise;

  ok(gFindBarInitialized, "find bar is now initialized");

  // Finds the div in the green box.
  let scrollPromise = promiseWaitForEvent(gBrowser, "scroll");
  EventUtils.synthesizeKey("d", {});
  EventUtils.synthesizeKey("i", {});
  EventUtils.synthesizeKey("v", {});
  yield scrollPromise;

  // Wait for one paint to ensure we've processed the previous key events and scrolling.
  yield ContentTask.spawn(gBrowser.selectedBrowser, null, function* () {
    return new Promise(
      resolve => {
        content.requestAnimationFrame(() => {
          setTimeout(resolve, 0);
        });
      }
    );
  });

  // Finds the div in the red box.
  scrollPromise = promiseWaitForEvent(gBrowser, "scroll");
  EventUtils.synthesizeKey("g", { accelKey: true });
  yield scrollPromise;

  yield ContentTask.spawn(gBrowser.selectedBrowser, null, function* () {
    Assert.ok(content.document.getElementById("s").getBoundingClientRect().left >= 0,
      "scroll should include find result");
  });

  // clear the find bar
  EventUtils.synthesizeKey("a", { accelKey: true });
  EventUtils.synthesizeKey("VK_DELETE", { });

  gFindBar.close();
  gBrowser.removeCurrentTab();
});