tor-browser

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

browser_navigate.js (10074B)


      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 navigation of same/different type content
      9 */
     10 addAccessibleTask(
     11  `<h1 id="hello">hello</h1>
     12  world<br>
     13  <a href="example.com" id="link">I am a link</a>
     14  <h1 id="goodbye">goodbye</h1>`,
     15  async (browser, accDoc) => {
     16    const searchPred = {
     17      AXSearchKey: "AXSameTypeSearchKey",
     18      AXImmediateDescendantsOnly: 0,
     19      AXResultsLimit: 1,
     20      AXDirection: "AXDirectionNext",
     21    };
     22 
     23    const hello = getNativeInterface(accDoc, "hello");
     24    const goodbye = getNativeInterface(accDoc, "goodbye");
     25    const webArea = accDoc.nativeInterface.QueryInterface(
     26      Ci.nsIAccessibleMacInterface
     27    );
     28 
     29    searchPred.AXStartElement = hello;
     30 
     31    let sameItem = webArea.getParameterizedAttributeValue(
     32      "AXUIElementsForSearchPredicate",
     33      NSDictionary(searchPred)
     34    );
     35 
     36    is(sameItem.length, 1, "Found one item");
     37    is(
     38      "goodbye",
     39      sameItem[0].getAttributeValue("AXTitle"),
     40      "Found correct item of same type"
     41    );
     42 
     43    searchPred.AXDirection = "AXDirectionPrevious";
     44    searchPred.AXStartElement = goodbye;
     45    sameItem = webArea.getParameterizedAttributeValue(
     46      "AXUIElementsForSearchPredicate",
     47      NSDictionary(searchPred)
     48    );
     49 
     50    is(sameItem.length, 1, "Found one item");
     51    is(
     52      "hello",
     53      sameItem[0].getAttributeValue("AXTitle"),
     54      "Found correct item of same type"
     55    );
     56 
     57    searchPred.AXSearchKey = "AXDifferentTypeSearchKey";
     58    let diffItem = webArea.getParameterizedAttributeValue(
     59      "AXUIElementsForSearchPredicate",
     60      NSDictionary(searchPred)
     61    );
     62    is(diffItem.length, 1, "Found one item");
     63    is(
     64      "I am a link",
     65      diffItem[0].getAttributeValue("AXValue"),
     66      "Found correct item of different type"
     67    );
     68  }
     69 );
     70 
     71 /**
     72 * Test navigation of heading levels
     73 */
     74 addAccessibleTask(
     75  `
     76  <h1 id="a">a</h1>
     77  <h2 id="b">b</h2>
     78  <h3 id="c">c</h3>
     79  <h4 id="d">d</h4>
     80  <h5 id="e">e</h5>
     81  <h6 id="f">f</h5>
     82  <h1 id="g">g</h1>
     83  <h2 id="h">h</h2>
     84  <h3 id="i">i</h3>
     85  <h4 id="j">j</h4>
     86  <h5 id="k">k</h5>
     87  <h6 id="l">l</h5>
     88  this is some regular text that should be ignored
     89  `,
     90  async (browser, accDoc) => {
     91    const searchPred = {
     92      AXSearchKey: "AXHeadingLevel1SearchKey",
     93      AXImmediateDescendantsOnly: 0,
     94      AXResultsLimit: -1,
     95      AXDirection: "AXDirectionNext",
     96    };
     97 
     98    const webArea = accDoc.nativeInterface.QueryInterface(
     99      Ci.nsIAccessibleMacInterface
    100    );
    101 
    102    let h1Count = webArea.getParameterizedAttributeValue(
    103      "AXUIElementCountForSearchPredicate",
    104      NSDictionary(searchPred)
    105    );
    106 
    107    is(2, h1Count, "Found two h1 items");
    108 
    109    let h1s = webArea.getParameterizedAttributeValue(
    110      "AXUIElementsForSearchPredicate",
    111      NSDictionary(searchPred)
    112    );
    113 
    114    const a = getNativeInterface(accDoc, "a");
    115    const g = getNativeInterface(accDoc, "g");
    116 
    117    is(
    118      a.getAttributeValue("AXValue"),
    119      h1s[0].getAttributeValue("AXValue"),
    120      "Found correct h1 heading"
    121    );
    122 
    123    is(
    124      g.getAttributeValue("AXValue"),
    125      h1s[1].getAttributeValue("AXValue"),
    126      "Found correct h1 heading"
    127    );
    128 
    129    searchPred.AXSearchKey = "AXHeadingLevel2SearchKey";
    130 
    131    let h2Count = webArea.getParameterizedAttributeValue(
    132      "AXUIElementCountForSearchPredicate",
    133      NSDictionary(searchPred)
    134    );
    135 
    136    is(2, h2Count, "Found two h2 items");
    137 
    138    let h2s = webArea.getParameterizedAttributeValue(
    139      "AXUIElementsForSearchPredicate",
    140      NSDictionary(searchPred)
    141    );
    142 
    143    const b = getNativeInterface(accDoc, "b");
    144    const h = getNativeInterface(accDoc, "h");
    145 
    146    is(
    147      b.getAttributeValue("AXValue"),
    148      h2s[0].getAttributeValue("AXValue"),
    149      "Found correct h2 heading"
    150    );
    151 
    152    is(
    153      h.getAttributeValue("AXValue"),
    154      h2s[1].getAttributeValue("AXValue"),
    155      "Found correct h2 heading"
    156    );
    157 
    158    searchPred.AXSearchKey = "AXHeadingLevel3SearchKey";
    159 
    160    let h3Count = webArea.getParameterizedAttributeValue(
    161      "AXUIElementCountForSearchPredicate",
    162      NSDictionary(searchPred)
    163    );
    164 
    165    is(2, h3Count, "Found two h3 items");
    166 
    167    let h3s = webArea.getParameterizedAttributeValue(
    168      "AXUIElementsForSearchPredicate",
    169      NSDictionary(searchPred)
    170    );
    171 
    172    const c = getNativeInterface(accDoc, "c");
    173    const i = getNativeInterface(accDoc, "i");
    174 
    175    is(
    176      c.getAttributeValue("AXValue"),
    177      h3s[0].getAttributeValue("AXValue"),
    178      "Found correct h3 heading"
    179    );
    180 
    181    is(
    182      i.getAttributeValue("AXValue"),
    183      h3s[1].getAttributeValue("AXValue"),
    184      "Found correct h3 heading"
    185    );
    186 
    187    searchPred.AXSearchKey = "AXHeadingLevel4SearchKey";
    188 
    189    let h4Count = webArea.getParameterizedAttributeValue(
    190      "AXUIElementCountForSearchPredicate",
    191      NSDictionary(searchPred)
    192    );
    193 
    194    is(2, h4Count, "Found two h4 items");
    195 
    196    let h4s = webArea.getParameterizedAttributeValue(
    197      "AXUIElementsForSearchPredicate",
    198      NSDictionary(searchPred)
    199    );
    200 
    201    const d = getNativeInterface(accDoc, "d");
    202    const j = getNativeInterface(accDoc, "j");
    203 
    204    is(
    205      d.getAttributeValue("AXValue"),
    206      h4s[0].getAttributeValue("AXValue"),
    207      "Found correct h4 heading"
    208    );
    209 
    210    is(
    211      j.getAttributeValue("AXValue"),
    212      h4s[1].getAttributeValue("AXValue"),
    213      "Found correct h4 heading"
    214    );
    215 
    216    searchPred.AXSearchKey = "AXHeadingLevel5SearchKey";
    217 
    218    let h5Count = webArea.getParameterizedAttributeValue(
    219      "AXUIElementCountForSearchPredicate",
    220      NSDictionary(searchPred)
    221    );
    222 
    223    is(2, h5Count, "Found two h5 items");
    224 
    225    let h5s = webArea.getParameterizedAttributeValue(
    226      "AXUIElementsForSearchPredicate",
    227      NSDictionary(searchPred)
    228    );
    229 
    230    const e = getNativeInterface(accDoc, "e");
    231    const k = getNativeInterface(accDoc, "k");
    232 
    233    is(
    234      e.getAttributeValue("AXValue"),
    235      h5s[0].getAttributeValue("AXValue"),
    236      "Found correct h5 heading"
    237    );
    238 
    239    is(
    240      k.getAttributeValue("AXValue"),
    241      h5s[1].getAttributeValue("AXValue"),
    242      "Found correct h5 heading"
    243    );
    244 
    245    searchPred.AXSearchKey = "AXHeadingLevel6SearchKey";
    246 
    247    let h6Count = webArea.getParameterizedAttributeValue(
    248      "AXUIElementCountForSearchPredicate",
    249      NSDictionary(searchPred)
    250    );
    251 
    252    is(2, h6Count, "Found two h6 items");
    253 
    254    let h6s = webArea.getParameterizedAttributeValue(
    255      "AXUIElementsForSearchPredicate",
    256      NSDictionary(searchPred)
    257    );
    258 
    259    const f = getNativeInterface(accDoc, "f");
    260    const l = getNativeInterface(accDoc, "l");
    261 
    262    is(
    263      f.getAttributeValue("AXValue"),
    264      h6s[0].getAttributeValue("AXValue"),
    265      "Found correct h6 heading"
    266    );
    267 
    268    is(
    269      l.getAttributeValue("AXValue"),
    270      h6s[1].getAttributeValue("AXValue"),
    271      "Found correct h6 heading"
    272    );
    273  }
    274 );
    275 
    276 /*
    277 * Test rotor with blockquotes
    278 */
    279 addAccessibleTask(
    280  `
    281  <blockquote id="first">hello I am a blockquote</blockquote>
    282  <blockquote id="second">
    283    I am also a blockquote of the same level
    284    <br>
    285    <blockquote id="third">but I have a different level</blockquote>
    286  </blockquote>
    287  `,
    288  (browser, accDoc) => {
    289    let searchPred = {
    290      AXSearchKey: "AXBlockquoteSearchKey",
    291      AXImmediateDescendantsOnly: 0,
    292      AXResultsLimit: -1,
    293      AXDirection: "AXDirectionNext",
    294    };
    295 
    296    const webArea = accDoc.nativeInterface.QueryInterface(
    297      Ci.nsIAccessibleMacInterface
    298    );
    299    is(
    300      webArea.getAttributeValue("AXRole"),
    301      "AXWebArea",
    302      "Got web area accessible"
    303    );
    304 
    305    let bquotes = webArea.getParameterizedAttributeValue(
    306      "AXUIElementsForSearchPredicate",
    307      NSDictionary(searchPred)
    308    );
    309 
    310    is(bquotes.length, 3, "Found three blockquotes");
    311 
    312    const first = getNativeInterface(accDoc, "first");
    313    const second = getNativeInterface(accDoc, "second");
    314    const third = getNativeInterface(accDoc, "third");
    315    console.log("values :");
    316    console.log(first.getAttributeValue("AXValue"));
    317    is(
    318      first.getAttributeValue("AXValue"),
    319      bquotes[0].getAttributeValue("AXValue"),
    320      "Found correct first blockquote"
    321    );
    322 
    323    is(
    324      second.getAttributeValue("AXValue"),
    325      bquotes[1].getAttributeValue("AXValue"),
    326      "Found correct second blockquote"
    327    );
    328 
    329    is(
    330      third.getAttributeValue("AXValue"),
    331      bquotes[2].getAttributeValue("AXValue"),
    332      "Found correct third blockquote"
    333    );
    334  }
    335 );
    336 
    337 /*
    338 * Test rotor with graphics
    339 */
    340 addAccessibleTask(
    341  `
    342  <img id="img1" alt="image one" src="http://example.com/a11y/accessible/tests/mochitest/moz.png"><br>
    343  <a href="http://example.com">
    344    <img id="img2" alt="image two" src="http://example.com/a11y/accessible/tests/mochitest/moz.png">
    345  </a>
    346  <img src="" id="img3">
    347  `,
    348  (browser, accDoc) => {
    349    let searchPred = {
    350      AXSearchKey: "AXGraphicSearchKey",
    351      AXImmediateDescendantsOnly: 0,
    352      AXResultsLimit: -1,
    353      AXDirection: "AXDirectionNext",
    354    };
    355 
    356    const webArea = accDoc.nativeInterface.QueryInterface(
    357      Ci.nsIAccessibleMacInterface
    358    );
    359    is(
    360      webArea.getAttributeValue("AXRole"),
    361      "AXWebArea",
    362      "Got web area accessible"
    363    );
    364 
    365    let images = webArea.getParameterizedAttributeValue(
    366      "AXUIElementsForSearchPredicate",
    367      NSDictionary(searchPred)
    368    );
    369 
    370    is(images.length, 3, "Found three images");
    371 
    372    const img1 = getNativeInterface(accDoc, "img1");
    373    const img2 = getNativeInterface(accDoc, "img2");
    374    const img3 = getNativeInterface(accDoc, "img3");
    375 
    376    is(
    377      img1.getAttributeValue("AXDescription"),
    378      images[0].getAttributeValue("AXDescription"),
    379      "Found correct image"
    380    );
    381 
    382    is(
    383      img2.getAttributeValue("AXDescription"),
    384      images[1].getAttributeValue("AXDescription"),
    385      "Found correct image"
    386    );
    387 
    388    is(
    389      img3.getAttributeValue("AXDescription"),
    390      images[2].getAttributeValue("AXDescription"),
    391      "Found correct image"
    392    );
    393  }
    394 );