tor-browser

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

browser_text_leaf.js (3037B)


      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/role.js */
      8 loadScripts({ name: "role.js", dir: MOCHITESTS_DIR });
      9 
     10 add_setup(async function () {
     11  await SpecialPowers.pushPrefEnv({
     12    set: [["test.wait300msAfterTabSwitch", true]],
     13  });
     14 });
     15 
     16 /**
     17 * Test accessibles aren't created for linebreaks.
     18 */
     19 addAccessibleTask(
     20  `hello<br>world`,
     21  async (browser, accDoc) => {
     22    let doc = accDoc.nativeInterface.QueryInterface(
     23      Ci.nsIAccessibleMacInterface
     24    );
     25    let children = doc.getAttributeValue("AXChildren");
     26    is(children.length, 2, "The document contains 2 children");
     27 
     28    // verify first child is correct
     29    is(
     30      children[0].getAttributeValue("AXRole"),
     31      "AXStaticText",
     32      "First child is a text node"
     33    );
     34    is(
     35      children[0].getAttributeValue("AXValue"),
     36      "hello",
     37      "First child is hello text"
     38    );
     39 
     40    // verify second child is correct
     41    is(
     42      children[1].getAttributeValue("AXRole"),
     43      "AXStaticText",
     44      "Second child is a text node"
     45    );
     46 
     47    is(
     48      children[1].getAttributeValue("AXValue"),
     49      gIsIframe && !gIsRemoteIframe ? "world" : "world ",
     50      "Second child is world text"
     51    );
     52    // we have a trailing space in here due to bug 1577028
     53    // but this appears fixed in non-remote iframes
     54  },
     55  { chrome: true, iframe: true, remoteIframe: true }
     56 );
     57 
     58 addAccessibleTask(
     59  `<p id="p">hello, this is a test</p>`,
     60  async (browser, accDoc) => {
     61    let p = getNativeInterface(accDoc, "p");
     62    let textLeaf = p.getAttributeValue("AXChildren")[0];
     63    ok(textLeaf, "paragraph has a text leaf");
     64 
     65    let str = textLeaf.getParameterizedAttributeValue(
     66      "AXStringForRange",
     67      NSRange(3, 6)
     68    );
     69 
     70    is(str, "lo, th", "AXStringForRange matches.");
     71 
     72    let smallBounds = textLeaf.getParameterizedAttributeValue(
     73      "AXBoundsForRange",
     74      NSRange(3, 6)
     75    );
     76 
     77    let largeBounds = textLeaf.getParameterizedAttributeValue(
     78      "AXBoundsForRange",
     79      NSRange(3, 8)
     80    );
     81 
     82    Assert.less(
     83      smallBounds.size[0],
     84      largeBounds.size[0],
     85      "longer range is wider"
     86    );
     87  },
     88  { chrome: true, iframe: true, remoteIframe: true }
     89 );
     90 
     91 // Text leaf inherits container's AXLanguage, and container's default AXLanguage is the doc one.
     92 addAccessibleTask(
     93  `<p id="ar">العربية</p>
     94   <p id="es" lang="es">Español</p>`,
     95  async (browser, accDoc) => {
     96    const es = getNativeInterface(accDoc, "es");
     97    const ar = getNativeInterface(accDoc, "ar");
     98    const firstChild = a => a.getAttributeValue("AXChildren")[0];
     99 
    100    is(es.getAttributeValue("AXLanguage"), "es");
    101    is(firstChild(es).getAttributeValue("AXLanguage"), "es");
    102 
    103    is(ar.getAttributeValue("AXLanguage"), "ar");
    104    is(firstChild(ar).getAttributeValue("AXLanguage"), "ar");
    105  },
    106  { chrome: true, contentDocBodyAttrs: { lang: "ar" } }
    107 );