tor-browser

The Tor Browser
git clone https://git.dasho.dev/tor-browser.git
Log | Files | Refs | README | LICENSE

browser_zero_area.js (4038B)


      1 /* This Source Code Form is subject to the terms of the Mozilla Public
      2 * License, v. 2.0. If a copy of the MPL was not distributed with this
      3 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
      4 
      5 "use strict";
      6 
      7 /* import-globals-from ../../mochitest/layout.js */
      8 
      9 async function testContentBounds(browser, acc, expectedWidth, expectedHeight) {
     10  let [expectedX, expectedY] = await getContentBoundsForDOMElm(
     11    browser,
     12    getAccessibleDOMNodeID(acc)
     13  );
     14 
     15  let contentDPR = await getContentDPR(browser);
     16  let [x, y, width, height] = getBounds(acc, contentDPR);
     17  let prettyAccName = prettyName(acc);
     18  is(x, expectedX, "Wrong x coordinate of " + prettyAccName);
     19  is(y, expectedY, "Wrong y coordinate of " + prettyAccName);
     20  is(width, expectedWidth, "Wrong width of " + prettyAccName);
     21  is(height, expectedHeight, "Wrong height of " + prettyAccName);
     22 }
     23 /**
     24 * Test accessible bounds with different combinations of overflow and
     25 * non-zero frame area.
     26 */
     27 addAccessibleTask(
     28  `
     29  <div id="a1" style="height:100px; width:100px; background:green;"></div>
     30  <div id="a2" style="height:100px; width:100px; background:green;"><div style="height:300px; max-width: 300px; background:blue;"></div></div>
     31  <div id="a3" style="height:0; width:0;"><div style="height:200px; width:200px; background:green;"></div></div>
     32  `,
     33  async function (browser, accDoc) {
     34    const a1 = findAccessibleChildByID(accDoc, "a1");
     35    const a2 = findAccessibleChildByID(accDoc, "a2");
     36    const a3 = findAccessibleChildByID(accDoc, "a3");
     37    await testContentBounds(browser, a1, 100, 100);
     38    await testContentBounds(browser, a2, 100, 100);
     39    await testContentBounds(browser, a3, 200, 200);
     40  }
     41 );
     42 
     43 /**
     44 * Ensure frames with zero area have their x, y coordinates correctly reported
     45 * in bounds()
     46 */
     47 addAccessibleTask(
     48  `
     49 <br>
     50 <div id="a" style="height:0; width:0;"></div>
     51 `,
     52  async function (browser, accDoc) {
     53    const a = findAccessibleChildByID(accDoc, "a");
     54    await testContentBounds(browser, a, 0, 0);
     55  }
     56 );
     57 
     58 /**
     59 * Ensure accessibles have accurately signed dimensions and position when
     60 * offscreen.
     61 */
     62 addAccessibleTask(
     63  `
     64 <input type="radio" id="radio" style="left: -671091em; position: absolute;">
     65 `,
     66  async function (browser, accDoc) {
     67    const radio = findAccessibleChildByID(accDoc, "radio");
     68    const contentDPR = await getContentDPR(browser);
     69    const [x, y, width, height] = getBounds(radio, contentDPR);
     70    Assert.less(x, 0, "X coordinate should be negative");
     71    Assert.greater(y, 0, "Y coordinate should be positive");
     72    Assert.greater(width, 0, "Width should be positive");
     73    Assert.greater(height, 0, "Height should be positive");
     74    // Note: the exact values of x, y, width, and height
     75    // are inconsistent with the DOM element values of those
     76    // fields, so we don't check our bounds against them with
     77    // `testContentBounds` here. DOM reports a negative width,
     78    // positive height, and a slightly different (+/- 20)
     79    // x and y.
     80  }
     81 );
     82 
     83 /**
     84 * Test height: 0 with align-items: flex-end. This causes the content to
     85 * overflow above the frame's main rect.
     86 */
     87 addAccessibleTask(
     88  `
     89 <aside style="height: 0; display: flex; align-items: flex-end;">
     90  <div id="inner0">testing</div>
     91 </aside>
     92 <aside style="height: 1; display: flex; align-items: flex-end;">
     93  <div id="inner1">testing</div>
     94 </aside>
     95  `,
     96  async function (browser, docAcc) {
     97    await testBoundsWithContent(docAcc, "inner0", browser);
     98    await testBoundsWithContent(docAcc, "inner1", browser);
     99  },
    100  { chrome: true, topLevel: true, remoteIframe: true }
    101 );
    102 
    103 /**
    104 * Test a div (block) inside a span (inline). This causes the span's primary
    105 * frame to have an empty rect offset from its visible content.
    106 */
    107 addAccessibleTask(
    108  `
    109 <span id="span" tabindex="-1">
    110  <div id="div">Testing</div>
    111 </span>
    112  `,
    113  async function (browser, docAcc) {
    114    await testBoundsWithContent(docAcc, "span", browser);
    115    await testBoundsWithContent(docAcc, "div", browser);
    116  },
    117  { chrome: true, topLevel: true, remoteIframe: true }
    118 );