Bug 1319995 - Set the substituting handler of the resources of "formautofill" in xpcshell tests; r=MattN
MozReview-Commit-ID: 1w1v9BJRHkw
--- a/browser/extensions/formautofill/test/unit/head.js
+++ b/browser/extensions/formautofill/test/unit/head.js
@@ -1,42 +1,34 @@
/**
- * Provides infrastructure for automated login components tests.
+ * Provides infrastructure for automated formautofill components tests.
*/
- /* exported importAutofillModule, getTempFile */
+/* exported importAutofillModule, getTempFile */
"use strict";
const {classes: Cc, interfaces: Ci, utils: Cu, results: Cr} = Components;
Cu.import("resource://gre/modules/XPCOMUtils.jsm");
Cu.import("resource://gre/modules/Services.jsm");
+Cu.import("resource://gre/modules/NetUtil.jsm");
Cu.import("resource://testing-common/MockDocument.jsm");
-// Redirect the path of the resouce in addon to the exact file path.
-let defineLazyModuleGetter = XPCOMUtils.defineLazyModuleGetter;
-XPCOMUtils.defineLazyModuleGetter = function() {
- let result = /^resource\:\/\/formautofill\/(.+)$/.exec(arguments[2]);
- if (result) {
- arguments[2] = Services.io.newFileURI(do_get_file(result[1])).spec;
- }
- return defineLazyModuleGetter.apply(this, arguments);
-};
-
-// Load the module by Service newFileURI API for running extension's XPCShell test
-function importAutofillModule(module) {
- return Cu.import(Services.io.newFileURI(do_get_file(module)).spec);
-}
-
XPCOMUtils.defineLazyModuleGetter(this, "DownloadPaths",
"resource://gre/modules/DownloadPaths.jsm");
XPCOMUtils.defineLazyModuleGetter(this, "FileUtils",
"resource://gre/modules/FileUtils.jsm");
+// Register the resource path of formautofill
+let resHandler = Services.io.getProtocolHandler("resource")
+ .QueryInterface(Ci.nsISubstitutingProtocolHandler);
+let dataURI = NetUtil.newURI(do_get_file(".", true));
+resHandler.setSubstitution("formautofill", dataURI);
+
// 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);
/**
* Returns a reference to a temporary file, that is guaranteed not to exist, and
new file mode 100644
--- /dev/null
+++ b/browser/extensions/formautofill/test/unit/tail.js
@@ -0,0 +1,10 @@
+/**
+ * Cleans up the testing environment.
+ */
+
+/* global resHandler */
+
+"use strict";
+
+// Unregister the resource path of formautofill.
+resHandler.setSubstitution("formautofill", null);
--- a/browser/extensions/formautofill/test/unit/test_autofillFormFields.js
+++ b/browser/extensions/formautofill/test/unit/test_autofillFormFields.js
@@ -1,15 +1,15 @@
/*
* Test for form auto fill content helper fill all inputs function.
*/
"use strict";
-let {FormAutofillHandler} = importAutofillModule("FormAutofillContent.jsm");
+let {FormAutofillHandler} = Cu.import("resource://formautofill/FormAutofillContent.jsm");
const TESTCASES = [
{
description: "Form without autocomplete property",
document: `<form><input id="given-name"><input id="family-name">
<input id="street-addr"><input id="city"><input id="country">
<input id='email'><input id="tel"></form>`,
fieldDetails: [],
--- a/browser/extensions/formautofill/test/unit/test_collectFormFields.js
+++ b/browser/extensions/formautofill/test/unit/test_collectFormFields.js
@@ -1,15 +1,15 @@
/*
* Test for form auto fill content helper collectFormFields functions.
*/
"use strict";
-let {FormAutofillHandler} = importAutofillModule("FormAutofillContent.jsm");
+let {FormAutofillHandler} = Cu.import("resource://formautofill/FormAutofillContent.jsm");
const TESTCASES = [
{
description: "Form without autocomplete property",
document: `<form><input id="given-name"><input id="family-name">
<input id="street-addr"><input id="city"><input id="country">
<input id='email'><input id="tel"></form>`,
returnedFormat: [],
--- a/browser/extensions/formautofill/test/unit/test_populateFieldValues.js
+++ b/browser/extensions/formautofill/test/unit/test_populateFieldValues.js
@@ -1,17 +1,17 @@
/*
* Test for populating field values in Form Autofill Parent.
*/
/* global FormAutofillParent */
"use strict";
-importAutofillModule("FormAutofillParent.jsm");
+Cu.import("resource://formautofill/FormAutofillParent.jsm");
do_get_profile();
const TEST_FIELDS = [
{"section": "", "addressType": "shipping", "contactType": "", "fieldName": "organization"},
{"section": "", "addressType": "shipping", "contactType": "", "fieldName": "street-address"},
{"section": "", "addressType": "shipping", "contactType": "", "fieldName": "address-level2"},
{"section": "", "addressType": "shipping", "contactType": "", "fieldName": "address-level1"},
--- a/browser/extensions/formautofill/test/unit/test_profileStorage.js
+++ b/browser/extensions/formautofill/test/unit/test_profileStorage.js
@@ -2,17 +2,17 @@
* Tests ProfileStorage object.
*/
/* global ProfileStorage */
"use strict";
Cu.import("resource://gre/modules/Task.jsm");
-Cu.import(Services.io.newFileURI(do_get_file("ProfileStorage.jsm")).spec);
+Cu.import("resource://formautofill/ProfileStorage.jsm");
const TEST_STORE_FILE_NAME = "test-profile.json";
const TEST_PROFILE_1 = {
organization: "World Wide Web Consortium",
streetAddress: "32 Vassar Street\nMIT Room 32-G524",
addressLevel2: "Cambridge",
addressLevel1: "MA",
--- a/browser/extensions/formautofill/test/unit/xpcshell.ini
+++ b/browser/extensions/formautofill/test/unit/xpcshell.ini
@@ -1,11 +1,11 @@
[DEFAULT]
head = head.js
-tail =
+tail = tail.js
support-files =
../../content/FormAutofillContent.jsm
../../content/FormAutofillParent.jsm
../../content/ProfileStorage.jsm
[test_autofillFormFields.js]
[test_collectFormFields.js]
[test_populateFieldValues.js]