Backed out changeset 7b2ffe9a4d06 (bug 1869605) for causing bc failures on browser_no...
[gecko.git] / browser / components / firefoxview / tests / browser / browser_firefoxview_accessibility.js
blob9d444511ac54f648d00b36d34b2604a98e5865d5
1 /* Any copyright is dedicated to the Public Domain.
2    http://creativecommons.org/publicdomain/zero/1.0/ */
4 "use strict";
6 /**
7  * Tests that are related to the accessibility of the Firefox View
8  * document. These tasks tend to be privileged content, not browser
9  * chrome.
10  */
12 add_setup(async function setup() {
13   // Make sure the prompt to connect FxA doesn't show
14   // Without resetting the view-count pref it gets surfaced after
15   // the third click on the fx view toolbar button.
16   await SpecialPowers.pushPrefEnv({
17     set: [
18       ["browser.firefox-view.view-count", 0],
19       ["browser.tabs.firefox-view-next", false],
20     ],
21   });
22   registerCleanupFunction(async () => {
23     await SpecialPowers.popPrefEnv();
24   });
25 });
27 add_task(async function test_keyboard_focus_after_tab_pickup_opened() {
28   // Reset various things touched by other tests in this file so that
29   // we have a sufficiently clean environment.
31   TabsSetupFlowManager.resetInternalState();
33   // Ensure that the tab-pickup section doesn't need to be opened.
34   Services.prefs.clearUserPref(
35     "browser.tabs.firefox-view.ui-state.tab-pickup.open"
36   );
38   // Let's be deterministic about the basic UI state!
39   const sandbox = setupMocks({
40     state: UIState.STATUS_NOT_CONFIGURED,
41     syncEnabled: false,
42   });
44   await withFirefoxView({}, async browser => {
45     const { document } = browser.contentWindow;
46     let win = browser.ownerGlobal;
48     is(
49       document.activeElement.localName,
50       "body",
51       "document body element is initially focused"
52     );
54     const tab = () => {
55       info("Tab keypress synthesized");
56       EventUtils.synthesizeKey("KEY_Tab", {}, win);
57     };
59     tab();
61     let tabPickupContainer = document.querySelector(
62       "#tab-pickup-container summary.page-section-header"
63     );
64     is(
65       document.activeElement,
66       tabPickupContainer,
67       "tab pickup container header has focus"
68     );
70     tab();
72     is(
73       document.activeElement.id,
74       "firefoxview-tabpickup-step-signin-primarybutton",
75       "tab pickup primary button has focus"
76     );
77   });
79   // cleanup time
80   await tearDown(sandbox);
81 });
83 add_task(async function test_keyboard_accessibility_tab_pickup() {
84   await withFirefoxView({}, async browser => {
85     const win = browser.ownerGlobal;
86     const { document } = browser.contentWindow;
87     const enter = async () => {
88       info("Enter");
89       EventUtils.synthesizeKey("KEY_Enter", {}, win);
90     };
91     let details = document.getElementById("tab-pickup-container");
92     let summary = details.querySelector("summary");
93     ok(summary, "summary element should exist");
94     ok(details.open, "Tab pickup container should be initially open on load");
95     summary.focus();
96     await enter();
97     ok(!details.open, "Tab pickup container should be closed");
98     await enter();
99     ok(details.open, "Tab pickup container should be opened");
100   });
101   cleanup_tab_pickup();