Bug 1390433 - (From 1385196)[Form Autofill] Test: Enable the feature based on locale and geoip. draft
authorMatthew Noorenberghe <mozilla@noorenberghe.ca>
Thu, 10 Aug 2017 21:38:48 -0700
changeset 649803 4a150df7166bdd24540ac5cc7733d8a94912bbd2
parent 649802 8644497531c8ebcf299abc86f3d5c85eb7b635f4
child 649804 fc8117e92b415e49913fc8bcba8f2cf0b87fcedb
push id75162
push userschung@mozilla.com
push dateMon, 21 Aug 2017 10:29:17 +0000
bugs1390433, 1385196
milestone56.0
Bug 1390433 - (From 1385196)[Form Autofill] Test: Enable the feature based on locale and geoip. MozReview-Commit-ID: 3eCRKB9eiDK
browser/extensions/formautofill/test/unit/head.js
browser/extensions/formautofill/test/unit/test_isAvailable.js
browser/extensions/formautofill/test/unit/xpcshell.ini
--- a/browser/extensions/formautofill/test/unit/head.js
+++ b/browser/extensions/formautofill/test/unit/head.js
@@ -1,14 +1,14 @@
 /**
  * Provides infrastructure for automated formautofill components tests.
  */
 
 /* exported getTempFile, loadFormAutofillContent, runHeuristicsTest, sinon,
- *          initProfileStorage, getSyncChangeCounter, objectMatches
+ *          initProfileStorage, getSyncChangeCounter, objectMatches, bootstrapURI
  */
 
 "use strict";
 
 var {classes: Cc, interfaces: Ci, utils: Cu, results: Cr} = Components;
 
 Cu.import("resource://gre/modules/XPCOMUtils.jsm");
 Cu.import("resource://gre/modules/Services.jsm");
@@ -46,20 +46,25 @@ var sinon = require("sinon-2.3.2");
 // ================================================
 
 // Load our bootstrap extension manifest so we can access our chrome/resource URIs.
 const EXTENSION_ID = "formautofill@mozilla.org";
 let extensionDir = Services.dirsvc.get("GreD", Ci.nsIFile);
 extensionDir.append("browser");
 extensionDir.append("features");
 extensionDir.append(EXTENSION_ID);
+let bootstrapFile = extensionDir.clone();
+bootstrapFile.append("bootstrap.js");
+let bootstrapURI = Services.io.newFileURI(bootstrapFile).spec;
 // If the unpacked extension doesn't exist, use the packed version.
 if (!extensionDir.exists()) {
   extensionDir = extensionDir.parent;
   extensionDir.append(EXTENSION_ID + ".xpi");
+  let jarURI = Services.io.newFileURI(extensionDir);
+  bootstrapURI = "jar:" + jarURI.spec + "!/bootstrap.js";
 }
 Components.manager.addBootstrappedManifestLocation(extensionDir);
 
 // While the previous test file should have deleted all the temporary files it
 // used, on Windows these might still be pending deletion on the physical file
 // system.  Thus, start from a new base number every time, to make a collision
 // with a file that is still pending deletion highly unlikely.
 let gFileCounter = Math.floor(Math.random() * 1000000);
new file mode 100644
--- /dev/null
+++ b/browser/extensions/formautofill/test/unit/test_isAvailable.js
@@ -0,0 +1,32 @@
+/**
+ * Test enabling the feature in specific locales and regions.
+ */
+
+"use strict";
+
+// Load bootstrap.js into a sandbox to be able to test `isAvailable`
+let sandbox = {};
+Services.scriptloader.loadSubScript(bootstrapURI, sandbox, "utf-8");
+do_print("bootstrapURI: " + bootstrapURI);
+
+add_task(async function test_defaultTestEnvironment() {
+  do_check_true(sandbox.isAvailable());
+});
+
+add_task(async function test_unsupportedRegion() {
+  Services.prefs.setCharPref("extensions.formautofill.available", "detect");
+  Services.prefs.setCharPref("browser.search.region", "ZZ");
+  do_register_cleanup(function cleanupRegion() {
+    Services.prefs.clearUserPref("browser.search.region");
+  });
+  do_check_false(sandbox.isAvailable());
+});
+
+add_task(async function test_supportedRegion() {
+  Services.prefs.setCharPref("extensions.formautofill.available", "detect");
+  Services.prefs.setCharPref("browser.search.region", "US");
+  do_register_cleanup(function cleanupRegion() {
+    Services.prefs.clearUserPref("browser.search.region");
+  });
+  do_check_true(sandbox.isAvailable());
+});
--- a/browser/extensions/formautofill/test/unit/xpcshell.ini
+++ b/browser/extensions/formautofill/test/unit/xpcshell.ini
@@ -23,16 +23,17 @@ support-files =
 [test_creditCardRecords.js]
 [test_extractLabelStrings.js]
 [test_findLabelElements.js]
 [test_getAdaptedProfiles.js]
 [test_getCategoriesFromFieldNames.js]
 [test_getFormInputDetails.js]
 [test_getInfo.js]
 [test_getRecords.js]
+[test_isAvailable.js]
 [test_isCJKName.js]
 [test_isFieldEligibleForAutofill.js]
 [test_markAsAutofillField.js]
 [test_migrateRecords.js]
 [test_nameUtils.js]
 [test_onFormSubmitted.js]
 [test_profileAutocompleteResult.js]
 [test_phoneNumber.js]