tor-browser

The Tor Browser
git clone https://git.dasho.dev/tor-browser.git
Log | Files | Refs | README | LICENSE

test_isAddressAutofillAvailable.js (2612B)


      1 /* Any copyright is dedicated to the Public Domain.
      2 http://creativecommons.org/publicdomain/zero/1.0/ */
      3 
      4 /**
      5 * Test enabling address autofill in specific locales and regions.
      6 */
      7 
      8 "use strict";
      9 
     10 const { FormAutofill } = ChromeUtils.importESModule(
     11  "resource://autofill/FormAutofill.sys.mjs"
     12 );
     13 
     14 add_setup(async () => {
     15  Services.prefs.setBoolPref(
     16    "extensions.formautofill.addresses.experiments.enabled",
     17    false
     18  );
     19  registerCleanupFunction(function cleanupRegion() {
     20    Services.prefs.clearUserPref(
     21      "extensions.formautofill.addresses.experiments.enabled"
     22    );
     23  });
     24 });
     25 
     26 add_task(async function test_defaultTestEnvironment() {
     27  Assert.equal(
     28    Services.prefs.getCharPref("extensions.formautofill.addresses.supported"),
     29    "on"
     30  );
     31 });
     32 
     33 add_task(async function test_default_supported_module_and_autofill_region() {
     34  Services.prefs.setCharPref("browser.search.region", "US");
     35  registerCleanupFunction(function cleanupRegion() {
     36    Services.prefs.clearUserPref("browser.search.region");
     37  });
     38 
     39  let addon = await AddonManager.getAddonByID(EXTENSION_ID);
     40  await addon.reload();
     41 
     42  Assert.equal(FormAutofill.isAutofillAddressesAvailable, true);
     43  Assert.equal(FormAutofill.isAutofillAddressesEnabled, true);
     44 });
     45 
     46 add_task(
     47  async function test_supported_creditCard_region_unsupported_address_region() {
     48    Services.prefs.setCharPref(
     49      "extensions.formautofill.addresses.supported",
     50      "detect"
     51    );
     52    Services.prefs.setCharPref(
     53      "extensions.formautofill.creditCards.supported",
     54      "detect"
     55    );
     56    Services.prefs.setCharPref("browser.search.region", "FR");
     57    Services.prefs.setCharPref(
     58      "extensions.formautofill.addresses.supportedCountries",
     59      "US,CA"
     60    );
     61    Services.prefs.setCharPref(
     62      "extensions.formautofill.creditCards.supportedCountries",
     63      "US,CA,FR"
     64    );
     65    registerCleanupFunction(function cleanupPrefs() {
     66      Services.prefs.clearUserPref("browser.search.region");
     67      Services.prefs.clearUserPref(
     68        "extensions.formautofill.addresses.supportedCountries"
     69      );
     70      Services.prefs.clearUserPref(
     71        "extensions.formautofill.addresses.supported"
     72      );
     73      Services.prefs.clearUserPref(
     74        "extensions.formautofill.creditCards.supported"
     75      );
     76    });
     77 
     78    let addon = await AddonManager.getAddonByID(EXTENSION_ID);
     79    await addon.reload();
     80    Assert.ok(
     81      Services.prefs.getBoolPref("extensions.formautofill.creditCards.enabled")
     82    );
     83    Assert.equal(FormAutofill.isAutofillAddressesAvailable, false);
     84    Assert.equal(FormAutofill.isAutofillAddressesEnabled, false);
     85  }
     86 );