summaryrefslogtreecommitdiffstats
path: root/accessible/tests/browser/hittest/browser_test_zoom_text.js
blob: 0d7eb336ca9f3dfb9e19b8ccd6448bda2fc36d35 (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
71
72
73
74
75
76
/* This Source Code Form is subject to the terms of the Mozilla Public
 * License, v. 2.0. If a copy of the MPL was not distributed with this
 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */

"use strict";

/**
 * Test if getOffsetAtPoint returns the given text offset at given coordinates.
 */
function testOffsetAtPoint(hyperText, x, y, coordType, expectedOffset) {
  is(
    hyperText.getOffsetAtPoint(x, y, coordType),
    expectedOffset,
    `Wrong offset at given point (${x}, ${y}) for ${prettyName(hyperText)}`
  );
}

async function runTests(browser, accDoc) {
  const expectedLength = await invokeContentTask(browser, [], () => {
    const { CommonUtils } = ChromeUtils.import(
      "chrome://mochitests/content/browser/accessible/tests/browser/Common.jsm"
    );
    const hyperText = CommonUtils.getNode("paragraph", content.document);

    return hyperText.textContent.length / 2;
  });
  const hyperText = findAccessibleChildByID(accDoc, "paragraph", [
    Ci.nsIAccessibleText,
  ]);
  const textNode = hyperText.firstChild;

  let [x, y, width, height] = Layout.getBounds(
    textNode,
    await getContentDPR(browser)
  );

  testOffsetAtPoint(
    hyperText,
    x + width / 2,
    y + height / 2,
    COORDTYPE_SCREEN_RELATIVE,
    expectedLength
  );

  await invokeContentTask(browser, [], () => {
    const { Layout } = ChromeUtils.import(
      "chrome://mochitests/content/browser/accessible/tests/browser/Layout.jsm"
    );

    Layout.zoomDocument(content.document, 2.0);
    content.document.body.offsetTop; // getBounds doesn't flush layout on its own.
  });

  [x, y, width, height] = Layout.getBounds(
    textNode,
    await getContentDPR(browser)
  );

  testOffsetAtPoint(
    hyperText,
    x + width / 2,
    y + height / 2,
    COORDTYPE_SCREEN_RELATIVE,
    expectedLength
  );
}

addAccessibleTask(
  `<p id="paragraph" style="font-family: monospace;">Болтали две сороки</p>`,
  runTests,
  {
    iframe: true,
    remoteIframe: true,
    iframeAttrs: { style: "width: 600px; height: 600px;" },
  }
);