summaryrefslogtreecommitdiffstats
path: root/accessible/tests/browser/bounds/browser_zero_area.js
blob: 80954fbd1af7f296506afde63dfd2dda701e97db (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
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
/* 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 testContentBounds(browser, acc, expectedWidth, expectedHeight) {
  let [expectedX, expectedY] = await getContentBoundsForDOMElm(
    browser,
    getAccessibleDOMNodeID(acc)
  );

  let contentDPR = await getContentDPR(browser);
  let [x, y, width, height] = getBounds(acc, contentDPR);
  let prettyAccName = prettyName(acc);
  is(x, expectedX, "Wrong x coordinate of " + prettyAccName);
  is(y, expectedY, "Wrong y coordinate of " + prettyAccName);
  is(width, expectedWidth, "Wrong width of " + prettyAccName);
  is(height, expectedHeight, "Wrong height of " + prettyAccName);
}
/**
 * Test accessible bounds with different combinations of overflow and
 * non-zero frame area.
 */
addAccessibleTask(
  `
  <div id="a1" style="height:100px; width:100px; background:green;"></div>
  <div id="a2" style="height:100px; width:100px; background:green;"><div style="height:300px; max-width: 300px; background:blue;"></div></div>
  <div id="a3" style="height:0; width:0;"><div style="height:200px; width:200px; background:green;"></div></div>
  `,
  async function (browser, accDoc) {
    const a1 = findAccessibleChildByID(accDoc, "a1");
    const a2 = findAccessibleChildByID(accDoc, "a2");
    const a3 = findAccessibleChildByID(accDoc, "a3");
    await testContentBounds(browser, a1, 100, 100);
    await testContentBounds(browser, a2, 100, 100);
    await testContentBounds(browser, a3, 200, 200);
  }
);

/**
 * Ensure frames with zero area have their x, y coordinates correctly reported
 * in bounds()
 */
addAccessibleTask(
  `
<br>
<div id="a" style="height:0; width:0;"></div>
`,
  async function (browser, accDoc) {
    const a = findAccessibleChildByID(accDoc, "a");
    await testContentBounds(browser, a, 0, 0);
  }
);

/**
 * Ensure accessibles have accurately signed dimensions and position when
 * offscreen.
 */
addAccessibleTask(
  `
<input type="radio" id="radio" style="left: -671091em; position: absolute;">
`,
  async function (browser, accDoc) {
    const radio = findAccessibleChildByID(accDoc, "radio");
    const contentDPR = await getContentDPR(browser);
    const [x, y, width, height] = getBounds(radio, contentDPR);
    Assert.less(x, 0, "X coordinate should be negative");
    Assert.greater(y, 0, "Y coordinate should be positive");
    Assert.greater(width, 0, "Width should be positive");
    Assert.greater(height, 0, "Height should be positive");
    // Note: the exact values of x, y, width, and height
    // are inconsistent with the DOM element values of those
    // fields, so we don't check our bounds against them with
    // `testContentBounds` here. DOM reports a negative width,
    // positive height, and a slightly different (+/- 20)
    // x and y.
  }
);

/**
 * Test height: 0 with align-items: flex-end. This causes the content to
 * overflow above the frame's main rect.
 */
addAccessibleTask(
  `
<aside style="height: 0; display: flex; align-items: flex-end;">
  <div id="inner0">testing</div>
</aside>
<aside style="height: 1; display: flex; align-items: flex-end;">
  <div id="inner1">testing</div>
</aside>
  `,
  async function (browser, docAcc) {
    await testBoundsWithContent(docAcc, "inner0", browser);
    await testBoundsWithContent(docAcc, "inner1", browser);
  },
  { chrome: true, topLevel: true, remoteIframe: true }
);

/**
 * Test a div (block) inside a span (inline). This causes the span's primary
 * frame to have an empty rect offset from its visible content.
 */
addAccessibleTask(
  `
<span id="span" tabindex="-1">
  <div id="div">Testing</div>
</span>
  `,
  async function (browser, docAcc) {
    await testBoundsWithContent(docAcc, "span", browser);
    await testBoundsWithContent(docAcc, "div", browser);
  },
  { chrome: true, topLevel: true, remoteIframe: true }
);