test_isCreditCardAutofillAvailable.js (2393B)
1 /** 2 * Test enabling the feature in specific locales and regions. 3 */ 4 5 "use strict"; 6 7 const { FormAutofill } = ChromeUtils.importESModule( 8 "resource://autofill/FormAutofill.sys.mjs" 9 ); 10 11 add_task(async function test_defaultTestEnvironment() { 12 Assert.ok(Services.prefs.getBoolPref("dom.forms.autocomplete.formautofill")); 13 }); 14 15 add_task(async function test_detect_unsupportedRegion() { 16 Services.prefs.setCharPref( 17 "extensions.formautofill.creditCards.supported", 18 "detect" 19 ); 20 Services.prefs.setCharPref( 21 "extensions.formautofill.creditCards.supportedCountries", 22 "US,CA" 23 ); 24 Services.prefs.setCharPref("browser.search.region", "ZZ"); 25 registerCleanupFunction(function cleanupRegion() { 26 Services.prefs.clearUserPref("browser.search.region"); 27 Services.prefs.clearUserPref( 28 "extensions.formautofill.creditCards.supported" 29 ); 30 Services.prefs.clearUserPref("extensions.formautofill.addresses.supported"); 31 Services.prefs.clearUserPref( 32 "extensions.formautofill.creditCards.supportedCountries" 33 ); 34 }); 35 36 let addon = await AddonManager.getAddonByID(EXTENSION_ID); 37 await addon.reload(); 38 39 Assert.equal( 40 FormAutofill.isAutofillCreditCardsAvailable, 41 false, 42 "Credit card autofill should not be available" 43 ); 44 Assert.equal( 45 FormAutofill.isAutofillCreditCardsEnabled, 46 false, 47 "Credit card autofill should not be enabled" 48 ); 49 }); 50 51 add_task(async function test_detect_supportedRegion() { 52 Services.prefs.setCharPref( 53 "extensions.formautofill.creditCards.supported", 54 "detect" 55 ); 56 Services.prefs.setCharPref( 57 "extensions.formautofill.creditCards.supportedCountries", 58 "US,CA" 59 ); 60 Services.prefs.setCharPref("browser.search.region", "US"); 61 registerCleanupFunction(function cleanupRegion() { 62 Services.prefs.clearUserPref("browser.search.region"); 63 Services.prefs.clearUserPref( 64 "extensions.formautofill.creditCards.supported" 65 ); 66 Services.prefs.clearUserPref( 67 "extensions.formautofill.creditCards.supportedCountries" 68 ); 69 }); 70 71 let addon = await AddonManager.getAddonByID(EXTENSION_ID); 72 await addon.reload(); 73 74 Assert.equal( 75 FormAutofill.isAutofillCreditCardsAvailable, 76 true, 77 "Credit card autofill should be available" 78 ); 79 Assert.equal( 80 FormAutofill.isAutofillCreditCardsEnabled, 81 true, 82 "Credit card autofill should be enabled" 83 ); 84 });