summaryrefslogtreecommitdiffstats
path: root/browser/extensions/formautofill/test/unit/test_isCreditCardAutofillAvailable.js
blob: 5be5101ee684d307de9e2bfddee02e90ca6c1b69 (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
/**
 * Test enabling the feature in specific locales and regions.
 */

"use strict";

const { FormAutofill } = ChromeUtils.importESModule(
  "resource://autofill/FormAutofill.sys.mjs"
);

add_task(async function test_defaultTestEnvironment() {
  Assert.ok(Services.prefs.getBoolPref("dom.forms.autocomplete.formautofill"));
});

add_task(async function test_detect_unsupportedRegion() {
  Services.prefs.setCharPref(
    "extensions.formautofill.creditCards.supported",
    "detect"
  );
  Services.prefs.setCharPref(
    "extensions.formautofill.creditCards.supportedCountries",
    "US,CA"
  );
  Services.prefs.setCharPref("browser.search.region", "ZZ");
  registerCleanupFunction(function cleanupRegion() {
    Services.prefs.clearUserPref("browser.search.region");
    Services.prefs.clearUserPref(
      "extensions.formautofill.creditCards.supported"
    );
    Services.prefs.clearUserPref("extensions.formautofill.addresses.supported");
    Services.prefs.clearUserPref(
      "extensions.formautofill.creditCards.supportedCountries"
    );
  });

  let addon = await AddonManager.getAddonByID(EXTENSION_ID);
  await addon.reload();

  Assert.equal(
    FormAutofill.isAutofillCreditCardsAvailable,
    false,
    "Credit card autofill should not be available"
  );
  Assert.equal(
    FormAutofill.isAutofillCreditCardsEnabled,
    false,
    "Credit card autofill should not be enabled"
  );
});

add_task(async function test_detect_supportedRegion() {
  Services.prefs.setCharPref(
    "extensions.formautofill.creditCards.supported",
    "detect"
  );
  Services.prefs.setCharPref(
    "extensions.formautofill.creditCards.supportedCountries",
    "US,CA"
  );
  Services.prefs.setCharPref("browser.search.region", "US");
  registerCleanupFunction(function cleanupRegion() {
    Services.prefs.clearUserPref("browser.search.region");
    Services.prefs.clearUserPref(
      "extensions.formautofill.creditCards.supported"
    );
    Services.prefs.clearUserPref(
      "extensions.formautofill.creditCards.supportedCountries"
    );
  });

  let addon = await AddonManager.getAddonByID(EXTENSION_ID);
  await addon.reload();

  Assert.equal(
    FormAutofill.isAutofillCreditCardsAvailable,
    true,
    "Credit card autofill should be available"
  );
  Assert.equal(
    FormAutofill.isAutofillCreditCardsEnabled,
    true,
    "Credit card autofill should be enabled"
  );
});