tor-browser

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

browser_test_text.js (2841B)


      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 addAccessibleTask(
      8  `
      9 a
     10 <div id="noChars" style="width: 5px; height: 5px;"><p></p></div>
     11 <p id="twoText"><span>a</span><span>b</span></p>
     12 <div id="iframeAtEnd" style="width: 20px; height: 20px;">
     13  a
     14  <iframe width="1" height="1"></iframe>
     15 </div>
     16 <button id="pointBeforeText">
     17  <div style="display: flex;">
     18    <div style="width: 100px; background-color: red;" role="none"></div>
     19    test
     20    <div style="width: 100px; background-color: blue;" role="none"></div>
     21  </div>
     22 </button>
     23  `,
     24  async function (browser, docAcc) {
     25    const dpr = await getContentDPR(browser);
     26    // Test getOffsetAtPoint on a container containing no characters. The inner
     27    // container does not include the requested point, but the outer one does.
     28    const noChars = findAccessibleChildByID(docAcc, "noChars", [
     29      Ci.nsIAccessibleText,
     30    ]);
     31    let [x, y] = Layout.getBounds(noChars, dpr);
     32    await testOffsetAtPoint(noChars, x, y, COORDTYPE_SCREEN_RELATIVE, -1);
     33 
     34    // Test that the correct offset is returned for a point in a second text
     35    // leaf.
     36    const twoText = findAccessibleChildByID(docAcc, "twoText", [
     37      Ci.nsIAccessibleText,
     38    ]);
     39    const text2 = twoText.getChildAt(1);
     40    [x, y] = Layout.getBounds(text2, dpr);
     41    await testOffsetAtPoint(twoText, x, y, COORDTYPE_SCREEN_RELATIVE, 1);
     42 
     43    // Test offsetAtPoint when there is an iframe at the end of the container.
     44    const iframeAtEnd = findAccessibleChildByID(docAcc, "iframeAtEnd", [
     45      Ci.nsIAccessibleText,
     46    ]);
     47    let width;
     48    let height;
     49    [x, y, width, height] = Layout.getBounds(iframeAtEnd, dpr);
     50    x += width - 1;
     51    y += height - 1;
     52    await testOffsetAtPoint(iframeAtEnd, x, y, COORDTYPE_SCREEN_RELATIVE, -1);
     53 
     54    // Test that 0 is returned if the point is within the container but before
     55    // the rectangle at offset 0. This is buggy behavior that some users have
     56    // unfortunately come to rely on (bug 1816601).
     57    const pointBeforeText = findAccessibleChildByID(docAcc, "pointBeforeText", [
     58      Ci.nsIAccessibleText,
     59    ]);
     60    [x, y, width, height] = Layout.getBounds(pointBeforeText, dpr);
     61    await testOffsetAtPoint(
     62      pointBeforeText,
     63      x + 1,
     64      y + 1,
     65      COORDTYPE_SCREEN_RELATIVE,
     66      0
     67    );
     68    // But this buggy behavior only applies for a point before offset 0, not
     69    // a point after the last offset. So it's asymmetrically buggy. :(
     70    await testOffsetAtPoint(
     71      pointBeforeText,
     72      x + width - 1,
     73      y + height - 1,
     74      COORDTYPE_SCREEN_RELATIVE,
     75      -1
     76    );
     77  },
     78  {
     79    topLevel: true,
     80    iframe: true,
     81    remoteIframe: true,
     82    chrome: true,
     83  }
     84 );