diff options
Diffstat (limited to 'dom/base/test/browser_outline_refocus.js')
-rw-r--r-- | dom/base/test/browser_outline_refocus.js | 65 |
1 files changed, 65 insertions, 0 deletions
diff --git a/dom/base/test/browser_outline_refocus.js b/dom/base/test/browser_outline_refocus.js new file mode 100644 index 0000000000..066c25de63 --- /dev/null +++ b/dom/base/test/browser_outline_refocus.js @@ -0,0 +1,65 @@ +const URL = `data:text/html,<a target="_blank" href="http://example.com">Click me</a>`; + +async function test_browser_outline_refocus( + aMessage, + aShouldFocusBeVisible, + aOpenTabCallback +) { + await BrowserTestUtils.withNewTab(URL, async function (browser) { + let tab = gBrowser.getTabForBrowser(browser); + let newTabPromise = BrowserTestUtils.waitForNewTab(gBrowser); + + await aOpenTabCallback(browser); + + info("waiting for new tab"); + let newTab = await newTabPromise; + + is(gBrowser.selectedTab, newTab, "Should've switched to the new tab"); + + info("switching back"); + await BrowserTestUtils.switchTab(gBrowser, tab); + + info("checking focus"); + let [wasFocused, wasFocusVisible] = await SpecialPowers.spawn( + browser, + [], + () => { + let link = content.document.querySelector("a"); + return [link.matches(":focus"), link.matches(":focus-visible")]; + } + ); + + ok(wasFocused, "Link should be refocused"); + is(wasFocusVisible, aShouldFocusBeVisible, aMessage); + + info("closing tab"); + await BrowserTestUtils.removeTab(newTab); + }); +} + +add_task(async function browser_outline_refocus_mouse() { + await test_browser_outline_refocus( + "Link shouldn't show outlines since it was originally focused by mouse", + false, + function (aBrowser) { + info("clicking on link"); + return BrowserTestUtils.synthesizeMouseAtCenter("a", {}, aBrowser); + } + ); +}); + +add_task(async function browser_outline_refocus_key() { + await SpecialPowers.pushPrefEnv({ + set: [["accessibility.tabfocus", 7]], + }); + + await test_browser_outline_refocus( + "Link should show outlines since it was originally focused by keyboard", + true, + function (aBrowser) { + info("Navigating via keyboard"); + EventUtils.sendKey("tab"); + EventUtils.sendKey("return"); + } + ); +}); |