tor-browser

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

browser_action.js (2530B)


      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 basic press action.
      9 */
     10 addAccessibleTask(
     11  `
     12 <button id="btn" onclick="this.textContent = 'Clicked'">Click me</button>
     13  `,
     14  async function testBasicPress() {
     15    const actions = await runPython(`
     16      global doc
     17      doc = getDoc()
     18      global btn
     19      btn = findByDomId(doc, "btn").queryAction()
     20      return str([[btn.getName(i), btn.getLocalizedName(i), btn.getDescription(i)] for i in range(btn.get_nActions())])
     21    `);
     22    is(actions, "[['press', 'Press', 'Press']]", "btn has correct actions");
     23 
     24    const nameChanged = waitForEvent(EVENT_NAME_CHANGE, "btn");
     25    await runPython(`
     26      btn.doAction(0)
     27    `);
     28    await nameChanged;
     29  }
     30 );
     31 
     32 /**
     33 * Test aria-actions.
     34 */
     35 addAccessibleTask(
     36  `
     37  <div id="container">
     38    <dialog aria-actions="btn1" id="dlg1" open>
     39      Hello
     40      <form method="dialog">
     41        <button id="btn1">Close</button>
     42      </form>
     43    </dialog>
     44    <dialog aria-actions="btn2" id="dlg2" onclick="" open>
     45      Dialog with its own click listener
     46      <form method="dialog">
     47        <button id="btn2">Close</button>
     48      </form>
     49    </dialog>
     50  </div>`,
     51  async function testAriaActions() {
     52    let actions = await runPython(`
     53      global doc
     54      doc = getDoc()
     55      global dlg1
     56      dlg1 = findByDomId(doc, "dlg1").queryAction()
     57      return str([[dlg1.getName(i), dlg1.getLocalizedName(i), dlg1.getDescription(i)] for i in range(dlg1.get_nActions())])
     58    `);
     59    is(
     60      actions,
     61      "[['custom_btn1', 'Close', 'Close']]",
     62      "dlg1 has correct actions"
     63    );
     64 
     65    let reorder = waitForEvent(EVENT_REORDER, "container");
     66    await runPython(`
     67      dlg1.doAction(0)
     68    `);
     69    await reorder;
     70 
     71    // Test dialog with its own click listener, and therefore has the aria-actions
     72    // target actions appended to its own actions.
     73    actions = await runPython(`
     74      global dlg2
     75      dlg2 = findByDomId(doc, "dlg2").queryAction()
     76      return str([[dlg2.getName(i), dlg2.getLocalizedName(i), dlg2.getDescription(i)] for i in range(dlg2.get_nActions())])
     77    `);
     78    is(
     79      actions,
     80      "[['click', 'Click', 'Click'], ['custom_btn2', 'Close', 'Close']]",
     81      "dlg2 has correct actions"
     82    );
     83 
     84    reorder = waitForEvent(EVENT_REORDER, "container");
     85    await runPython(`
     86      dlg2.doAction(1)
     87    `);
     88    await reorder;
     89  }
     90 );