tor-browser

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

browser_tree.js (2852B)


      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 async function testIsControl(pyVar, isControl) {
      8  const result = await runPython(`bool(${pyVar}.CurrentIsControlElement)`);
      9  if (isControl) {
     10    ok(result, `${pyVar} is a control element`);
     11  } else {
     12    ok(!result, `${pyVar} isn't a control element`);
     13  }
     14 }
     15 
     16 addUiaTask(
     17  `
     18 <p id="p">paragraph</p>
     19 <div id="div">div</div>
     20 <!-- The spans are because the UIA -> IA2 proxy seems to remove a single text
     21   leaf child from even the raw tree.
     22  -->
     23 <a id="link" href="#">link<span> </span>></a>
     24 <h1 id="h1">h1<span> </span></h1>
     25 <h1 id="h1WithDiv"><div>h1 with div<span> </span></div></h1>
     26 <input id="range" type="range">
     27 <div onclick=";" id="clickable">clickable</div>
     28 <div id="editable" contenteditable>editable</div>
     29 <table id="table"><tr><th>th</th></tr></table>
     30  `,
     31  async function () {
     32    await definePyVar("doc", `getDocUia()`);
     33    await assignPyVarToUiaWithId("p");
     34    await testIsControl("p", false);
     35    await definePyVar(
     36      "pTextLeaf",
     37      `uiaClient.RawViewWalker.GetFirstChildElement(p)`
     38    );
     39    await testIsControl("pTextLeaf", true);
     40    await assignPyVarToUiaWithId("div");
     41    await testIsControl("div", false);
     42    await definePyVar(
     43      "divTextLeaf",
     44      `uiaClient.RawViewWalker.GetFirstChildElement(div)`
     45    );
     46    await testIsControl("divTextLeaf", true);
     47    await assignPyVarToUiaWithId("link");
     48    await testIsControl("link", true);
     49    await assignPyVarToUiaWithId("range");
     50    await testIsControl("range", true);
     51    await assignPyVarToUiaWithId("editable");
     52    await testIsControl("editable", true);
     53    await assignPyVarToUiaWithId("table");
     54    await testIsControl("table", true);
     55    if (!gIsUiaEnabled) {
     56      // The remaining tests are broken with the UIA -> IA2 proxy.
     57      return;
     58    }
     59    await definePyVar(
     60      "linkTextLeaf",
     61      `uiaClient.RawViewWalker.GetFirstChildElement(link)`
     62    );
     63    await testIsControl("linkTextLeaf", false);
     64    await assignPyVarToUiaWithId("h1");
     65    await testIsControl("h1", true);
     66    await definePyVar(
     67      "h1TextLeaf",
     68      `uiaClient.RawViewWalker.GetFirstChildElement(h1)`
     69    );
     70    await testIsControl("h1TextLeaf", false);
     71    await assignPyVarToUiaWithId("h1WithDiv");
     72    await testIsControl("h1WithDiv", true);
     73    // h1WithDiv's text leaf is its grandchild.
     74    await definePyVar(
     75      "h1WithDivTextLeaf",
     76      `uiaClient.RawViewWalker.GetFirstChildElement(
     77        uiaClient.RawViewWalker.GetFirstChildElement(
     78          h1WithDiv
     79        )
     80      )`
     81    );
     82    await testIsControl("h1WithDivTextLeaf", false);
     83    await assignPyVarToUiaWithId("clickable");
     84    await testIsControl("clickable", true);
     85  }
     86 );