tor-browser

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

browser_bounds.js (3987B)


      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 /**
      8 * Test position, size for onscreen content
      9 */
     10 addAccessibleTask(
     11  `I am some extra content<br>
     12   <div id="hello" style="display:inline;">hello</div><br>
     13   <div id="world" style="display:inline;">hello world<br>I am some text</div>`,
     14  async (browser, accDoc) => {
     15    const hello = getNativeInterface(accDoc, "hello");
     16    const world = getNativeInterface(accDoc, "world");
     17    ok(hello.getAttributeValue("AXFrame"), "Hello's frame attr is not null");
     18    ok(world.getAttributeValue("AXFrame"), "World's frame attr is not null");
     19 
     20    // AXSize and AXPosition are composed of AXFrame components, so we
     21    // test them here instead of calling AXFrame directly.
     22    const [helloWidth, helloHeight] = hello.getAttributeValue("AXSize");
     23    const [worldWidth, worldHeight] = world.getAttributeValue("AXSize");
     24    Assert.greater(helloWidth, 0, "Hello has a positive width");
     25    Assert.greater(helloHeight, 0, "Hello has a positive height");
     26    Assert.greater(worldWidth, 0, "World has a positive width");
     27    Assert.greater(worldHeight, 0, "World has a positive height");
     28    Assert.less(
     29      helloHeight,
     30      worldHeight,
     31      "Hello has a smaller height than world"
     32    );
     33    Assert.less(helloWidth, worldWidth, "Hello has a smaller width than world");
     34 
     35    // Note: these are mac screen coords, so our origin is bottom left
     36    const [helloX, helloY] = hello.getAttributeValue("AXPosition");
     37    const [worldX, worldY] = world.getAttributeValue("AXPosition");
     38    Assert.greater(helloX, 0, "Hello has a positive X");
     39    Assert.greater(helloY, 0, "Hello has a positive Y");
     40    Assert.greater(worldX, 0, "World has a positive X");
     41    Assert.greater(worldY, 0, "World has a positive Y");
     42    Assert.greater(helloY, worldY, "Hello has a larger Y than world");
     43    Assert.equal(helloX, worldX, "Hello and world have the same X");
     44  }
     45 );
     46 
     47 /**
     48 * Test position, size for offscreen content
     49 */
     50 addAccessibleTask(
     51  `I am some extra content<br>
     52   <div id="hello" style="display:inline; position:absolute; left:-2000px;">hello</div><br>
     53   <div id="world" style="display:inline; position:absolute; left:-2000px;">hello world<br>I am some text</div>`,
     54  async (browser, accDoc) => {
     55    const hello = getNativeInterface(accDoc, "hello");
     56    const world = getNativeInterface(accDoc, "world");
     57    ok(hello.getAttributeValue("AXFrame"), "Hello's frame attr is not null");
     58    ok(world.getAttributeValue("AXFrame"), "World's frame attr is not null");
     59 
     60    // AXSize and AXPosition are composed of AXFrame components, so we
     61    // test them here instead of calling AXFrame directly.
     62    const [helloWidth, helloHeight] = hello.getAttributeValue("AXSize");
     63    const [worldWidth, worldHeight] = world.getAttributeValue("AXSize");
     64    Assert.greater(helloWidth, 0, "Hello has a positive width");
     65    Assert.greater(helloHeight, 0, "Hello has a positive height");
     66    Assert.greater(worldWidth, 0, "World has a positive width");
     67    Assert.greater(worldHeight, 0, "World has a positive height");
     68    Assert.less(
     69      helloHeight,
     70      worldHeight,
     71      "Hello has a smaller height than world"
     72    );
     73    Assert.less(helloWidth, worldWidth, "Hello has a smaller width than world");
     74 
     75    // Note: these are mac screen coords, so our origin is bottom left
     76    const [helloX, helloY] = hello.getAttributeValue("AXPosition");
     77    const [worldX, worldY] = world.getAttributeValue("AXPosition");
     78    Assert.less(helloX, 0, "Hello has a negative X");
     79    Assert.greater(helloY, 0, "Hello has a positive Y");
     80    Assert.less(worldX, 0, "World has a negative X");
     81    Assert.greater(worldY, 0, "World has a positive Y");
     82    Assert.greater(helloY, worldY, "Hello has a larger Y than world");
     83    Assert.equal(helloX, worldX, "Hello and world have the same X");
     84  }
     85 );