summaryrefslogtreecommitdiffstats
path: root/browser/components/preferences/tests/browser_keyboardfocus.js
blob: 89576b926a36faa923752eb2c78e7a9fe460bc1b (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
/* Any copyright is dedicated to the Public Domain.
 * http://creativecommons.org/publicdomain/zero/1.0/ */

async function launchPreferences() {
  let prefs = await openPreferencesViaOpenPreferencesAPI("paneGeneral", {
    leaveOpen: true,
  });
  Assert.equal(prefs.selectedPane, "paneGeneral", "General pane was selected");
}

add_task(async function () {
  await launchPreferences();
  let checkbox = gBrowser.contentDocument.querySelector(
    "#useFullKeyboardNavigation"
  );
  Assert.equal(
    Services.prefs.getIntPref("accessibility.tabfocus"),
    7,
    "default should be full keyboard access"
  );
  Assert.ok(
    checkbox.checked,
    "checkbox should be checked before clicking on checkbox"
  );

  checkbox.click();

  Assert.equal(
    Services.prefs.getIntPref("accessibility.tabfocus"),
    1,
    "Prefstore should reflect checkbox's associated numeric value"
  );
  Assert.ok(
    !checkbox.checked,
    "checkbox should be unchecked after clicking on checkbox"
  );

  checkbox.click();

  Assert.ok(
    checkbox.checked,
    "checkbox should be checked after clicking on checkbox"
  );
  Assert.equal(
    Services.prefs.getIntPref("accessibility.tabfocus"),
    7,
    "Should restore default value"
  );

  BrowserTestUtils.removeTab(gBrowser.selectedTab);
  await SpecialPowers.pushPrefEnv({ set: [["accessibility.tabfocus", 4]] });
  await launchPreferences();
  checkbox = gBrowser.contentDocument.querySelector(
    "#useFullKeyboardNavigation"
  );

  Assert.ok(
    !checkbox.checked,
    "checkbox should stay unchecked after setting non-7 pref value"
  );
  Assert.equal(
    Services.prefs.getIntPref("accessibility.tabfocus"),
    4,
    "pref should have value in store"
  );

  BrowserTestUtils.removeTab(gBrowser.selectedTab);
  await SpecialPowers.pushPrefEnv({ set: [["accessibility.tabfocus", 7]] });
  await launchPreferences();
  checkbox = gBrowser.contentDocument.querySelector(
    "#useFullKeyboardNavigation"
  );

  Assert.equal(
    Services.prefs.getIntPref("accessibility.tabfocus"),
    7,
    "Pref value should update after modification"
  );
  Assert.ok(checkbox.checked, "checkbox should be checked");

  BrowserTestUtils.removeTab(gBrowser.selectedTab);
});