tor-browser

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

browser_outline_refocus.js (1988B)


      1 const URL = `data:text/html,<a target="_blank" href="http://example.com">Click me</a>`;
      2 
      3 async function test_browser_outline_refocus(
      4  aMessage,
      5  aShouldFocusBeVisible,
      6  aOpenTabCallback
      7 ) {
      8  await BrowserTestUtils.withNewTab(URL, async function (browser) {
      9    let tab = gBrowser.getTabForBrowser(browser);
     10    let newTabPromise = BrowserTestUtils.waitForNewTab(gBrowser);
     11 
     12    await aOpenTabCallback(browser);
     13 
     14    info("waiting for new tab");
     15    let newTab = await newTabPromise;
     16 
     17    is(gBrowser.selectedTab, newTab, "Should've switched to the new tab");
     18 
     19    info("switching back");
     20    await BrowserTestUtils.switchTab(gBrowser, tab);
     21 
     22    info("checking focus");
     23    let [wasFocused, wasFocusVisible] = await SpecialPowers.spawn(
     24      browser,
     25      [],
     26      () => {
     27        let link = content.document.querySelector("a");
     28        return [link.matches(":focus"), link.matches(":focus-visible")];
     29      }
     30    );
     31 
     32    ok(wasFocused, "Link should be refocused");
     33    is(wasFocusVisible, aShouldFocusBeVisible, aMessage);
     34 
     35    info("closing tab");
     36    await BrowserTestUtils.removeTab(newTab);
     37  });
     38 }
     39 
     40 add_setup(async function () {
     41  await SpecialPowers.pushPrefEnv({
     42    set: [["test.wait300msAfterTabSwitch", true]],
     43  });
     44 });
     45 
     46 add_task(async function browser_outline_refocus_mouse() {
     47  await test_browser_outline_refocus(
     48    "Link shouldn't show outlines since it was originally focused by mouse",
     49    false,
     50    function (aBrowser) {
     51      info("clicking on link");
     52      return BrowserTestUtils.synthesizeMouseAtCenter("a", {}, aBrowser);
     53    }
     54  );
     55 });
     56 
     57 add_task(async function browser_outline_refocus_key() {
     58  await SpecialPowers.pushPrefEnv({
     59    set: [["accessibility.tabfocus", 7]],
     60  });
     61 
     62  await test_browser_outline_refocus(
     63    "Link should show outlines since it was originally focused by keyboard",
     64    true,
     65    function (aBrowser) {
     66      info("Navigating via keyboard");
     67      EventUtils.sendKey("tab");
     68      EventUtils.sendKey("return");
     69    }
     70  );
     71 });