summaryrefslogtreecommitdiffstats
path: root/browser/components/firefoxview/tests/browser/browser_firefoxview_accessibility.js
blob: e4b2e866a0ba88706953141832f730a6fefa7661 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
/* Any copyright is dedicated to the Public Domain.
   http://creativecommons.org/publicdomain/zero/1.0/ */

"use strict";

/**
 * Tests that are related to the accessibility of the Firefox View
 * document. These tasks tend to be privileged content, not browser
 * chrome.
 */

add_setup(async function setup() {
  // Make sure the prompt to connect FxA doesn't show
  // Without resetting the view-count pref it gets surfaced after
  // the third click on the fx view toolbar button.
  await SpecialPowers.pushPrefEnv({
    set: [["browser.firefox-view.view-count", 0]],
  });
});

add_task(async function test_keyboard_focus_after_tab_pickup_opened() {
  // Reset various things touched by other tests in this file so that
  // we have a sufficiently clean environment.

  TabsSetupFlowManager.resetInternalState();

  // Ensure that the tab-pickup section doesn't need to be opened.
  Services.prefs.clearUserPref(
    "browser.tabs.firefox-view.ui-state.tab-pickup.open"
  );

  // make sure the feature tour doesn't get in the way
  await SpecialPowers.pushPrefEnv({
    set: [
      [
        "browser.firefox-view.feature-tour",
        JSON.stringify({
          screen: `FEATURE_CALLOUT_1`,
          complete: true,
        }),
      ],
    ],
  });

  // Let's be deterministic about the basic UI state!
  const sandbox = setupMocks({
    state: UIState.STATUS_NOT_CONFIGURED,
    syncEnabled: false,
  });

  await withFirefoxView({}, async browser => {
    const { document } = browser.contentWindow;
    let win = browser.ownerGlobal;

    is(
      document.activeElement.localName,
      "body",
      "document body element is initially focused"
    );

    const tab = () => {
      info("Tab keypress synthesized");
      EventUtils.synthesizeKey("KEY_Tab", {}, win);
    };

    tab();

    let tabPickupContainer = document.querySelector(
      "#tab-pickup-container summary.page-section-header"
    );
    is(
      document.activeElement,
      tabPickupContainer,
      "tab pickup container header has focus"
    );

    tab();

    is(
      document.activeElement.id,
      "firefoxview-tabpickup-step-signin-primarybutton",
      "tab pickup primary button has focus"
    );
  });

  // cleanup time
  await tearDown(sandbox);
  await SpecialPowers.popPrefEnv();
});

add_task(async function test_keyboard_accessibility_tab_pickup() {
  await withFirefoxView({}, async browser => {
    const win = browser.ownerGlobal;
    const { document } = browser.contentWindow;
    const enter = async () => {
      info("Enter");
      EventUtils.synthesizeKey("KEY_Enter", {}, win);
    };
    let details = document.getElementById("tab-pickup-container");
    let summary = details.querySelector("summary");
    ok(summary, "summary element should exist");
    ok(details.open, "Tab pickup container should be initially open on load");
    summary.focus();
    await enter();
    ok(!details.open, "Tab pickup container should be closed");
    await enter();
    ok(details.open, "Tab pickup container should be opened");
  });
  cleanup_tab_pickup();
});