summaryrefslogtreecommitdiffstats
path: root/accessible/tests/browser/bounds/browser_test_zoom_text.js
blob: 3f40b698bfd7c8cdc4566ff87e3f598168b8e896 (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
77
78
79
80
81
82
83
84
85
86
/* 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";

/* import-globals-from ../../mochitest/layout.js */

async function runTests(browser, accDoc) {
  async function testTextNode(id) {
    let hyperTextNode = findAccessibleChildByID(accDoc, id);
    let textNode = hyperTextNode.firstChild;

    let contentDPR = await getContentDPR(browser);
    let [x, y, width, height] = getBounds(textNode, contentDPR);
    testTextBounds(
      hyperTextNode,
      0,
      -1,
      [x, y, width, height],
      COORDTYPE_SCREEN_RELATIVE
    );
    // A 0 range should return an empty rect.
    testTextBounds(
      hyperTextNode,
      0,
      0,
      [0, 0, 0, 0],
      COORDTYPE_SCREEN_RELATIVE
    );
  }

  async function testEmptyInputNode(id) {
    let inputNode = findAccessibleChildByID(accDoc, id);

    let [x, y, width, height] = getBounds(inputNode);
    testTextBounds(
      inputNode,
      0,
      -1,
      [x, y, width, height],
      COORDTYPE_SCREEN_RELATIVE
    );
    // A 0 range in an empty input should still return
    // rect of input node.
    testTextBounds(
      inputNode,
      0,
      0,
      [x, y, width, height],
      COORDTYPE_SCREEN_RELATIVE
    );
  }

  await testTextNode("p1");
  await testTextNode("p2");
  await testEmptyInputNode("i1");

  await SpecialPowers.spawn(browser, [], () => {
    const { Layout } = ChromeUtils.importESModule(
      "chrome://mochitests/content/browser/accessible/tests/browser/Layout.sys.mjs"
    );
    Layout.zoomDocument(content.document, 2.0);
  });

  await testTextNode("p1");

  await SpecialPowers.spawn(browser, [], () => {
    const { Layout } = ChromeUtils.importESModule(
      "chrome://mochitests/content/browser/accessible/tests/browser/Layout.sys.mjs"
    );
    Layout.zoomDocument(content.document, 1.0);
  });
}

/**
 * Test the text range boundary when page is zoomed
 */
addAccessibleTask(
  `
  <p id='p1' style='font-family: monospace;'>Tilimilitryamdiya</p>
  <p id='p2'>ل</p>
  <form><input id='i1' /></form>`,
  runTests,
  { iframe: true, remoteIframe: true }
);