Bug 1347186 - (Part 1) Move common utility functions to head.js. r?lchang
MozReview-Commit-ID: 8CfRHUSkKXV
--- a/browser/extensions/formautofill/test/browser/browser.ini
+++ b/browser/extensions/formautofill/test/browser/browser.ini
@@ -1,5 +1,6 @@
[DEFAULT]
+head = head.js
[browser_check_installed.js]
[browser_privacyPreferences.js]
[browser_manageProfilesDialog.js]
--- a/browser/extensions/formautofill/test/browser/browser_manageProfilesDialog.js
+++ b/browser/extensions/formautofill/test/browser/browser_manageProfilesDialog.js
@@ -1,64 +1,29 @@
"use strict";
-const {classes: Cc, interfaces: Ci, utils: Cu, results: Cr} = Components;
-
-const MANAGE_PROFILES_DIALOG_URL = "chrome://formautofill/content/manageProfiles.xhtml";
const TEST_SELECTORS = {
selProfiles: "#profiles",
btnRemove: "#remove",
btnAdd: "#add",
btnEdit: "#edit",
};
-const TEST_PROFILE_1 = {
- organization: "World Wide Web Consortium",
- "street-address": "32 Vassar Street\nMIT Room 32-G524",
- "address-level2": "Cambridge",
- "address-level1": "MA",
- "postal-code": "02139",
- country: "US",
- tel: "+1 617 253 5702",
- email: "timbl@w3.org",
-};
-
-const TEST_PROFILE_2 = {
- "street-address": "Some Address",
- country: "US",
-};
-
-const TEST_PROFILE_3 = {
- "street-address": "Other Address",
- "postal-code": "12345",
-};
-
-function saveProfile(profile) {
- Services.cpmm.sendAsyncMessage("FormAutofill:SaveProfile", {profile});
- return TestUtils.topicObserved("formautofill-storage-changed");
-}
-
-function removeProfiles(guids) {
- Services.cpmm.sendAsyncMessage("FormAutofill:RemoveProfiles", {guids});
- return TestUtils.topicObserved("formautofill-storage-changed");
-}
-
function waitForProfiles() {
return new Promise(resolve => {
Services.cpmm.addMessageListener("FormAutofill:Profiles", function getResult(result) {
Services.cpmm.removeMessageListener("FormAutofill:Profiles", getResult);
// Wait for the next tick for elements to get rendered.
SimpleTest.executeSoon(resolve.bind(null, result.data));
});
});
}
registerCleanupFunction(function* () {
- Services.cpmm.sendAsyncMessage("FormAutofill:GetProfiles", {});
- let profiles = yield waitForProfiles();
+ let profiles = yield getProfiles();
if (profiles.length) {
yield removeProfiles(profiles.map(profile => profile.guid));
}
});
add_task(function* test_manageProfilesInitialState() {
yield BrowserTestUtils.withNewTab({gBrowser, url: MANAGE_PROFILES_DIALOG_URL}, function* (browser) {
yield ContentTask.spawn(browser, TEST_SELECTORS, (args) => {
new file mode 100644
--- /dev/null
+++ b/browser/extensions/formautofill/test/browser/head.js
@@ -0,0 +1,49 @@
+/* exported MANAGE_PROFILES_DIALOG_URL, EDIT_PROFILE_DIALOG_URL,
+ TEST_PROFILE_1, TEST_PROFILE_2, TEST_PROFILE_3,
+ getProfiles, saveProfile, removeProfiles */
+
+"use strict";
+
+const MANAGE_PROFILES_DIALOG_URL = "chrome://formautofill/content/manageProfiles.xhtml";
+const EDIT_PROFILE_DIALOG_URL = "chrome://formautofill/content/editProfile.xhtml";
+
+const TEST_PROFILE_1 = {
+ organization: "World Wide Web Consortium",
+ "street-address": "32 Vassar Street\nMIT Room 32-G524",
+ "address-level2": "Cambridge",
+ "address-level1": "MA",
+ "postal-code": "02139",
+ country: "US",
+ tel: "+1 617 253 5702",
+ email: "timbl@w3.org",
+};
+
+const TEST_PROFILE_2 = {
+ "street-address": "Some Address",
+ country: "US",
+};
+
+const TEST_PROFILE_3 = {
+ "street-address": "Other Address",
+ "postal-code": "12345",
+};
+
+function getProfiles() {
+ return new Promise(resolve => {
+ Services.cpmm.addMessageListener("FormAutofill:Profiles", function getResult(result) {
+ Services.cpmm.removeMessageListener("FormAutofill:Profiles", getResult);
+ resolve(result.data);
+ });
+ Services.cpmm.sendAsyncMessage("FormAutofill:GetProfiles", {});
+ });
+}
+
+function saveProfile(profile) {
+ Services.cpmm.sendAsyncMessage("FormAutofill:SaveProfile", {profile});
+ return TestUtils.topicObserved("formautofill-storage-changed");
+}
+
+function removeProfiles(guids) {
+ Services.cpmm.sendAsyncMessage("FormAutofill:RemoveProfiles", {guids});
+ return TestUtils.topicObserved("formautofill-storage-changed");
+}