tor-browser

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

browser_identityPopup_focus.js (4544B)


      1 /* Tests the focus behavior of the identity popup. */
      2 
      3 // Focusing on the identity box is handled by the ToolbarKeyboardNavigator
      4 // component (see browser/base/content/browser-toolbarKeyNav.js).
      5 async function focusIdentityBox() {
      6  gURLBar.inputField.focus();
      7  is(document.activeElement, gURLBar.inputField, "urlbar should be focused");
      8  const focused = BrowserTestUtils.waitForEvent(
      9    gIdentityHandler._identityIconBox,
     10    "focus"
     11  );
     12  EventUtils.synthesizeKey("VK_TAB", { shiftKey: true });
     13  is(document.activeElement.id, "urlbar-searchmode-switcher");
     14  EventUtils.synthesizeKey("ArrowRight");
     15  is(document.activeElement.id, "tracking-protection-icon-container");
     16  EventUtils.synthesizeKey("ArrowRight");
     17  await focused;
     18 }
     19 
     20 add_setup(async function setup() {
     21  await SpecialPowers.pushPrefEnv({
     22    set: [["browser.urlbar.scotchBonnet.enableOverride", true]],
     23  });
     24 });
     25 
     26 // Access the identity popup via mouseclick. Focus should not be moved inside.
     27 add_task(async function testIdentityPopupFocusClick() {
     28  await SpecialPowers.pushPrefEnv({ set: [["accessibility.tabfocus", 7]] });
     29  await BrowserTestUtils.withNewTab("https://example.com", async function () {
     30    let shown = BrowserTestUtils.waitForEvent(
     31      window,
     32      "popupshown",
     33      true,
     34      event => event.target == gIdentityHandler._identityPopup
     35    );
     36    EventUtils.synthesizeMouseAtCenter(gIdentityHandler._identityIconBox, {});
     37    await shown;
     38    isnot(
     39      Services.focus.focusedElement,
     40      document.getElementById("identity-popup-security-button")
     41    );
     42  });
     43 });
     44 
     45 // Access the identity popup via keyboard. Focus should be moved inside.
     46 add_task(async function testIdentityPopupFocusKeyboard() {
     47  await SpecialPowers.pushPrefEnv({ set: [["accessibility.tabfocus", 7]] });
     48  await BrowserTestUtils.withNewTab("https://example.com", async function () {
     49    await focusIdentityBox();
     50    let shown = BrowserTestUtils.waitForEvent(
     51      window,
     52      "popupshown",
     53      true,
     54      event => event.target == gIdentityHandler._identityPopup
     55    );
     56    EventUtils.sendString(" ");
     57    await shown;
     58    is(
     59      Services.focus.focusedElement,
     60      document.getElementById("identity-popup-security-button")
     61    );
     62  });
     63 });
     64 
     65 // Access the Site Security panel, then move focus with the tab key.
     66 // Tabbing should be able to reach the More Information button.
     67 add_task(async function testSiteSecurityTabOrder() {
     68  await SpecialPowers.pushPrefEnv({ set: [["accessibility.tabfocus", 7]] });
     69  await BrowserTestUtils.withNewTab("https://example.com", async function () {
     70    // 1. Access the identity popup.
     71    await focusIdentityBox();
     72    let shown = BrowserTestUtils.waitForEvent(
     73      window,
     74      "popupshown",
     75      true,
     76      event => event.target == gIdentityHandler._identityPopup
     77    );
     78    EventUtils.sendString(" ");
     79    await shown;
     80    is(
     81      Services.focus.focusedElement,
     82      document.getElementById("identity-popup-security-button")
     83    );
     84 
     85    // 2. Access the Site Security section.
     86    let securityView = document.getElementById("identity-popup-securityView");
     87    shown = BrowserTestUtils.waitForEvent(securityView, "ViewShown");
     88    EventUtils.sendString(" ");
     89    await shown;
     90 
     91    // 3. Custom root learn more info should be focused by default
     92    // This is probably not present in real-world scenarios, but needs to be present in our test infrastructure.
     93    let customRootLearnMore = document.getElementById(
     94      "identity-popup-custom-root-learn-more"
     95    );
     96    is(
     97      Services.focus.focusedElement,
     98      customRootLearnMore,
     99      "learn more option for custom roots is focused"
    100    );
    101 
    102    // 4. First press of tab should move to the More Information button.
    103    let moreInfoButton = document.getElementById("identity-popup-more-info");
    104    let focused = BrowserTestUtils.waitForEvent(
    105      gIdentityHandler._identityPopup,
    106      "focusin"
    107    );
    108    EventUtils.sendKey("tab");
    109    await focused;
    110    is(
    111      Services.focus.focusedElement,
    112      moreInfoButton,
    113      "more info button is focused"
    114    );
    115 
    116    // 5. Second press of tab should focus the Back button.
    117    let backButton = gIdentityHandler._identityPopup.querySelector(
    118      ".subviewbutton-back"
    119    );
    120    // Wait for focus to move somewhere. We use focusin because focus doesn't bubble.
    121    focused = BrowserTestUtils.waitForEvent(
    122      gIdentityHandler._identityPopup,
    123      "focusin"
    124    );
    125    EventUtils.sendKey("tab");
    126    await focused;
    127    is(Services.focus.focusedElement, backButton, "back button is focused");
    128  });
    129 });