summaryrefslogtreecommitdiffstats
path: root/toolkit/modules/tests/browser/browser_FinderHighlighter2.js
blob: 1fa026b33323a2f723e640021a883a0c1fa6bac8 (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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
"use strict";

const kPrefHighlightAll = "findbar.highlightAll";
const kPrefModalHighlight = "findbar.modalHighlight";

add_setup(async function () {
  await SpecialPowers.pushPrefEnv({
    set: [
      [kPrefHighlightAll, true],
      [kPrefModalHighlight, true],
    ],
  });
});

add_task(async function testIframeOffset() {
  let url = kFixtureBaseURL + "file_FinderIframeTest.html";

  await BrowserTestUtils.withNewTab(url, async function (browser) {
    let findbar = gBrowser.getFindBar();
    await promiseOpenFindbar(findbar);

    let word = "frame";
    let expectedResult = {
      rectCount: 12,
      insertCalls: [2, 4],
      removeCalls: [0, 2],
    };
    let promise = promiseTestHighlighterOutput(
      browser,
      word,
      expectedResult,
      (maskNode, outlineNode, rects) => {
        Assert.equal(
          rects.length,
          expectedResult.rectCount,
          "Rect counts should match"
        );
        // Checks to guard against regressing this functionality:
        let expectedOffsets = [
          { x: 16, y: 60 },
          { x: 68, y: 104 },
          { x: 21, y: 215 },
          { x: 78, y: 264 },
          { x: 21, y: 375 },
          { x: 78, y: 424 },
          { x: 20, y: 534 },
          { x: 93, y: 534 },
          { x: 71, y: 577 },
          { x: 145, y: 577 },
        ];
        for (let i = 1, l = rects.length - 1; i < l; ++i) {
          let rect = rects[i];
          let expected = expectedOffsets[i - 1];
          Assert.equal(
            Math.floor(rect.x),
            expected.x,
            "Horizontal offset should match for rect " + i
          );
          Assert.equal(
            Math.floor(rect.y),
            expected.y,
            "Vertical offset should match for rect " + i
          );
        }
      }
    );
    await promiseEnterStringIntoFindField(findbar, word);
    await promise;
  });
});