--- a/browser/extensions/formautofill/FormAutofillContent.jsm
+++ b/browser/extensions/formautofill/FormAutofillContent.jsm
@@ -101,63 +101,63 @@ AutofillProfileAutoCompleteSearch.protot
onSearchResult: (search, result) => {
listener.onSearchResult(this, result);
ProfileAutocomplete.setProfileAutoCompleteResult(result);
},
});
return;
}
- this._getProfiles({info, searchString}).then((profiles) => {
+ this._getAddresses({info, searchString}).then((addresses) => {
if (this.forceStop) {
return;
}
let allFieldNames = FormAutofillContent.getAllFieldNames(focusedInput);
let result = new ProfileAutoCompleteResult(searchString,
info.fieldName,
allFieldNames,
- profiles,
+ addresses,
{});
listener.onSearchResult(this, result);
ProfileAutocomplete.setProfileAutoCompleteResult(result);
});
},
/**
* Stops an asynchronous search that is in progress
*/
stopSearch() {
ProfileAutocomplete.setProfileAutoCompleteResult(null);
this.forceStop = true;
},
/**
- * Get the profile data from parent process for AutoComplete result.
+ * Get the address data from parent process for AutoComplete result.
*
* @private
* @param {Object} data
* Parameters for querying the corresponding result.
* @param {string} data.searchString
- * The typed string for filtering out the matched profile.
+ * The typed string for filtering out the matched address.
* @param {string} data.info
* The input autocomplete property's information.
* @returns {Promise}
- * Promise that resolves when profiles returned from parent process.
+ * Promise that resolves when addresses returned from parent process.
*/
- _getProfiles(data) {
- this.log.debug("_getProfiles with data:", data);
+ _getAddresses(data) {
+ this.log.debug("_getAddresses with data:", data);
return new Promise((resolve) => {
- Services.cpmm.addMessageListener("FormAutofill:Profiles", function getResult(result) {
- Services.cpmm.removeMessageListener("FormAutofill:Profiles", getResult);
+ Services.cpmm.addMessageListener("FormAutofill:Addresses", function getResult(result) {
+ Services.cpmm.removeMessageListener("FormAutofill:Addresses", getResult);
resolve(result.data);
});
- Services.cpmm.sendAsyncMessage("FormAutofill:GetProfiles", data);
+ Services.cpmm.sendAsyncMessage("FormAutofill:GetAddresses", data);
});
},
};
this.NSGetFactory = XPCOMUtils.generateNSGetFactory([AutofillProfileAutoCompleteSearch]);
let ProfileAutocomplete = {
QueryInterface: XPCOMUtils.generateQI([Ci.nsIObserver]),
--- a/browser/extensions/formautofill/FormAutofillParent.jsm
+++ b/browser/extensions/formautofill/FormAutofillParent.jsm
@@ -71,19 +71,19 @@ FormAutofillParent.prototype = {
*/
init() {
log.debug("init");
let storePath = OS.Path.join(OS.Constants.Path.profileDir, PROFILE_JSON_FILE_NAME);
this._profileStore = new ProfileStorage(storePath);
this._profileStore.initialize();
Services.obs.addObserver(this, "advanced-pane-loaded");
- Services.ppmm.addMessageListener("FormAutofill:GetProfiles", this);
- Services.ppmm.addMessageListener("FormAutofill:SaveProfile", this);
- Services.ppmm.addMessageListener("FormAutofill:RemoveProfiles", this);
+ Services.ppmm.addMessageListener("FormAutofill:GetAddresses", this);
+ Services.ppmm.addMessageListener("FormAutofill:SaveAddress", this);
+ Services.ppmm.addMessageListener("FormAutofill:RemoveAddresses", this);
// Observing the pref and storage changes
Services.prefs.addObserver(ENABLED_PREF, this);
Services.obs.addObserver(this, "formautofill-storage-changed");
// Force to trigger the onStatusChanged function for setting listeners properly
// while initizlization
this._setStatus(this._getStatus());
@@ -177,29 +177,29 @@ FormAutofillParent.prototype = {
* Handles the message coming from FormAutofillContent.
*
* @param {string} message.name The name of the message.
* @param {object} message.data The data of the message.
* @param {nsIFrameMessageManager} message.target Caller's message manager.
*/
receiveMessage({name, data, target}) {
switch (name) {
- case "FormAutofill:GetProfiles": {
- this._getProfiles(data, target);
+ case "FormAutofill:GetAddresses": {
+ this._getAddresses(data, target);
break;
}
- case "FormAutofill:SaveProfile": {
+ case "FormAutofill:SaveAddress": {
if (data.guid) {
- this.getProfileStore().update(data.guid, data.profile);
+ this.getProfileStore().update(data.guid, data.address);
} else {
- this.getProfileStore().add(data.profile);
+ this.getProfileStore().add(data.address);
}
break;
}
- case "FormAutofill:RemoveProfiles": {
+ case "FormAutofill:RemoveAddresses": {
data.guids.forEach(guid => this.getProfileStore().remove(guid));
break;
}
}
},
/**
* Returns the instance of ProfileStorage. To avoid syncing issues, anyone
@@ -218,56 +218,57 @@ FormAutofillParent.prototype = {
* @private
*/
_uninit() {
if (this._profileStore) {
this._profileStore._saveImmediately();
this._profileStore = null;
}
- Services.ppmm.removeMessageListener("FormAutofill:GetProfiles", this);
- Services.ppmm.removeMessageListener("FormAutofill:SaveProfile", this);
- Services.ppmm.removeMessageListener("FormAutofill:RemoveProfiles", this);
+ Services.ppmm.removeMessageListener("FormAutofill:GetAddresses", this);
+ Services.ppmm.removeMessageListener("FormAutofill:SaveAddress", this);
+ Services.ppmm.removeMessageListener("FormAutofill:RemoveAddresses", this);
Services.obs.removeObserver(this, "advanced-pane-loaded");
Services.prefs.removeObserver(ENABLED_PREF, this);
},
/**
- * Get the profile data from profile store and return profiles back to content process.
+ * Get the address data from profile store and return addresses back to content
+ * process.
*
* @private
* @param {string} data.searchString
- * The typed string for filtering out the matched profile.
+ * The typed string for filtering out the matched address.
* @param {string} data.info
* The input autocomplete property's information.
* @param {nsIFrameMessageManager} target
* Content's message manager.
*/
- _getProfiles({searchString, info}, target) {
- let profiles = [];
+ _getAddresses({searchString, info}, target) {
+ let addresses = [];
if (info && info.fieldName) {
- profiles = this._profileStore.getByFilter({searchString, info});
+ addresses = this._profileStore.getByFilter({searchString, info});
} else {
- profiles = this._profileStore.getAll();
+ addresses = this._profileStore.getAll();
}
- target.sendAsyncMessage("FormAutofill:Profiles", profiles);
+ target.sendAsyncMessage("FormAutofill:Addresses", addresses);
},
_updateSavedFieldNames() {
if (!Services.ppmm.initialProcessData.autofillSavedFieldNames) {
Services.ppmm.initialProcessData.autofillSavedFieldNames = new Set();
} else {
Services.ppmm.initialProcessData.autofillSavedFieldNames.clear();
}
- this._profileStore.getAll().forEach((profile) => {
- Object.keys(profile).forEach((fieldName) => {
- if (!profile[fieldName]) {
+ this._profileStore.getAll().forEach((address) => {
+ Object.keys(address).forEach((fieldName) => {
+ if (!address[fieldName]) {
return;
}
Services.ppmm.initialProcessData.autofillSavedFieldNames.add(fieldName);
});
});
// Remove the internal guid and metadata fields.
this._profileStore.INTERNAL_FIELDS.forEach((fieldName) => {
--- a/browser/extensions/formautofill/ProfileStorage.jsm
+++ b/browser/extensions/formautofill/ProfileStorage.jsm
@@ -6,35 +6,36 @@
* Implements an interface of the storage of Form Autofill.
*
* The data is stored in JSON format, without indentation and the computed
* fields, using UTF-8 encoding. With indentation and computed fields applied,
* the schema would look like this:
*
* {
* version: 1,
- * profiles: [
+ * addresses: [
* {
- * guid, // 12 character...
+ * guid, // 12 characters
*
- * // profile
+ * // address fields
* given-name,
* additional-name,
* family-name,
* organization, // Company
* street-address, // (Multiline)
* address-level2, // City/Town
* address-level1, // Province (Standardized code if possible)
* postal-code,
* country, // ISO 3166
* tel,
* email,
*
* // computed fields (These fields are not stored in the file as they are
* // generated at runtime.)
+ * name,
* address-line1,
* address-line2,
* address-line3,
*
* // metadata
* timeCreated, // in ms
* timeLastUsed, // in ms
* timeLastModified, // in ms
@@ -82,36 +83,22 @@ const VALID_FIELDS = [
"address-level2",
"address-level1",
"postal-code",
"country",
"tel",
"email",
];
-// TODO: Remove this once we can add profile from preference.
-const MOCK_MODE = false;
-const MOCK_STORAGE = [{
- guid: "test-guid-1",
- organization: "Sesame Street",
- "street-address": "123 Sesame Street.",
- tel: "1-345-345-3456",
-}, {
- guid: "test-guid-2",
- organization: "Mozilla",
- "street-address": "331 E. Evelyn Avenue",
- tel: "1-650-903-0800",
-}];
-
function ProfileStorage(path) {
this._path = path;
}
ProfileStorage.prototype = {
- // These fields are defined internally for each profile.
+ // These fields are defined internally for each record.
INTERNAL_FIELDS:
["guid", "timeCreated", "timeLastUsed", "timeLastModified", "timesUsed"],
/**
* Loads the profile data from file to memory.
*
* @returns {Promise}
* @resolves When the operation finished successfully.
* @rejects JavaScript exception.
@@ -120,273 +107,273 @@ ProfileStorage.prototype = {
this._store = new JSONFile({
path: this._path,
dataPostProcessor: this._dataPostProcessor.bind(this),
});
return this._store.load();
},
/**
- * Adds a new profile.
+ * Adds a new address.
*
- * @param {Profile} profile
- * The new profile for saving.
+ * @param {Address} address
+ * The new address for saving.
*/
- add(profile) {
- log.debug("add:", profile);
+ add(address) {
+ log.debug("add:", address);
this._store.ensureDataReady();
- let profileToSave = this._clone(profile);
- this._normalizeProfile(profileToSave);
+ let addressToSave = this._clone(address);
+ this._normalizeAddress(addressToSave);
- profileToSave.guid = gUUIDGenerator.generateUUID().toString()
+ addressToSave.guid = gUUIDGenerator.generateUUID().toString()
.replace(/[{}-]/g, "").substring(0, 12);
// Metadata
let now = Date.now();
- profileToSave.timeCreated = now;
- profileToSave.timeLastModified = now;
- profileToSave.timeLastUsed = 0;
- profileToSave.timesUsed = 0;
+ addressToSave.timeCreated = now;
+ addressToSave.timeLastModified = now;
+ addressToSave.timeLastUsed = 0;
+ addressToSave.timesUsed = 0;
- this._store.data.profiles.push(profileToSave);
+ this._store.data.addresses.push(addressToSave);
this._store.saveSoon();
Services.obs.notifyObservers(null, "formautofill-storage-changed", "add");
},
/**
- * Update the specified profile.
+ * Update the specified address.
*
* @param {string} guid
- * Indicates which profile to update.
- * @param {Profile} profile
- * The new profile used to overwrite the old one.
+ * Indicates which address to update.
+ * @param {Address} address
+ * The new address used to overwrite the old one.
*/
- update(guid, profile) {
- log.debug("update:", guid, profile);
+ update(guid, address) {
+ log.debug("update:", guid, address);
this._store.ensureDataReady();
- let profileFound = this._findByGUID(guid);
- if (!profileFound) {
- throw new Error("No matching profile.");
+ let addressFound = this._findByGUID(guid);
+ if (!addressFound) {
+ throw new Error("No matching record.");
}
- let profileToUpdate = this._clone(profile);
- this._normalizeProfile(profileToUpdate);
+ let addressToUpdate = this._clone(address);
+ this._normalizeAddress(addressToUpdate);
for (let field of VALID_FIELDS) {
- if (profileToUpdate[field] !== undefined) {
- profileFound[field] = profileToUpdate[field];
+ if (addressToUpdate[field] !== undefined) {
+ addressFound[field] = addressToUpdate[field];
} else {
- delete profileFound[field];
+ delete addressFound[field];
}
}
- profileFound.timeLastModified = Date.now();
+ addressFound.timeLastModified = Date.now();
this._store.saveSoon();
Services.obs.notifyObservers(null, "formautofill-storage-changed", "update");
},
/**
- * Notifies the stroage of the use of the specified profile, so we can update
+ * Notifies the stroage of the use of the specified address, so we can update
* the metadata accordingly.
*
* @param {string} guid
- * Indicates which profile to be notified.
+ * Indicates which address to be notified.
*/
notifyUsed(guid) {
this._store.ensureDataReady();
- let profileFound = this._findByGUID(guid);
- if (!profileFound) {
- throw new Error("No matching profile.");
+ let addressFound = this._findByGUID(guid);
+ if (!addressFound) {
+ throw new Error("No matching record.");
}
- profileFound.timesUsed++;
- profileFound.timeLastUsed = Date.now();
+ addressFound.timesUsed++;
+ addressFound.timeLastUsed = Date.now();
this._store.saveSoon();
Services.obs.notifyObservers(null, "formautofill-storage-changed", "notifyUsed");
},
/**
- * Removes the specified profile. No error occurs if the profile isn't found.
+ * Removes the specified address. No error occurs if the address isn't found.
*
* @param {string} guid
- * Indicates which profile to remove.
+ * Indicates which address to remove.
*/
remove(guid) {
log.debug("remove:", guid);
this._store.ensureDataReady();
- this._store.data.profiles =
- this._store.data.profiles.filter(profile => profile.guid != guid);
+ this._store.data.addresses =
+ this._store.data.addresses.filter(address => address.guid != guid);
this._store.saveSoon();
Services.obs.notifyObservers(null, "formautofill-storage-changed", "remove");
},
/**
- * Returns the profile with the specified GUID.
+ * Returns the address with the specified GUID.
*
* @param {string} guid
- * Indicates which profile to retrieve.
- * @returns {Profile}
- * A clone of the profile.
+ * Indicates which address to retrieve.
+ * @returns {Address}
+ * A clone of the address.
*/
get(guid) {
log.debug("get:", guid);
this._store.ensureDataReady();
- let profileFound = this._findByGUID(guid);
- if (!profileFound) {
- throw new Error("No matching profile.");
+ let addressFound = this._findByGUID(guid);
+ if (!addressFound) {
+ throw new Error("No matching record.");
}
- // Profile is cloned to avoid accidental modifications from outside.
- let clonedProfile = this._clone(profileFound);
- this._computeFields(clonedProfile);
- return clonedProfile;
+ // The record is cloned to avoid accidental modifications from outside.
+ let clonedAddress = this._clone(addressFound);
+ this._computeFields(clonedAddress);
+ return clonedAddress;
},
/**
- * Returns all profiles.
+ * Returns all addresses.
*
- * @returns {Array.<Profile>}
- * An array containing clones of all profiles.
+ * @returns {Array.<Address>}
+ * An array containing clones of all addresses.
*/
getAll() {
log.debug("getAll");
this._store.ensureDataReady();
- // Profiles are cloned to avoid accidental modifications from outside.
- let clonedProfiles = this._store.data.profiles.map(this._clone);
- clonedProfiles.forEach(this._computeFields);
- return clonedProfiles;
+ // Records are cloned to avoid accidental modifications from outside.
+ let clonedAddresses = this._store.data.addresses.map(this._clone);
+ clonedAddresses.forEach(this._computeFields);
+ return clonedAddresses;
},
/**
- * Returns the filtered profiles based on input's information and searchString.
+ * Returns the filtered addresses based on input's information and searchString.
*
- * @returns {Array.<Profile>}
- * An array containing clones of matched profiles.
+ * @returns {Array.<Address>}
+ * An array containing clones of matched addresses.
*/
getByFilter({info, searchString}) {
log.debug("getByFilter:", info, searchString);
let lcSearchString = searchString.toLowerCase();
- let result = this.getAll().filter(profile => {
+ let result = this.getAll().filter(address => {
// Return true if string is not provided and field exists.
// TODO: We'll need to check if the address is for billing or shipping.
// (Bug 1358941)
- let name = profile[info.fieldName];
+ let name = address[info.fieldName];
if (!searchString) {
return !!name;
}
- return name.toLowerCase().startsWith(lcSearchString);
+ return name && name.toLowerCase().startsWith(lcSearchString);
});
log.debug("getByFilter: Returning", result.length, "result(s)");
return result;
},
- _clone(profile) {
- return Object.assign({}, profile);
+ _clone(record) {
+ return Object.assign({}, record);
},
_findByGUID(guid) {
- return this._store.data.profiles.find(profile => profile.guid == guid);
+ return this._store.data.addresses.find(address => address.guid == guid);
},
- _computeFields(profile) {
+ _computeFields(address) {
// Compute name
- profile.name = FormAutofillNameUtils.joinNameParts({
- given: profile["given-name"],
- middle: profile["additional-name"],
- family: profile["family-name"],
+ address.name = FormAutofillNameUtils.joinNameParts({
+ given: address["given-name"],
+ middle: address["additional-name"],
+ family: address["family-name"],
});
// Compute address
- if (profile["street-address"]) {
- let streetAddress = profile["street-address"].split("\n");
+ if (address["street-address"]) {
+ let streetAddress = address["street-address"].split("\n");
// TODO: we should prevent the dataloss by concatenating the rest of lines
// with a locale-specific character in the future (bug 1360114).
for (let i = 0; i < 3; i++) {
if (streetAddress[i]) {
- profile["address-line" + (i + 1)] = streetAddress[i];
+ address["address-line" + (i + 1)] = streetAddress[i];
}
}
}
},
- _normalizeAddress(profile) {
- if (profile["address-line1"] || profile["address-line2"] ||
- profile["address-line3"]) {
+ _normalizeAddressLines(address) {
+ if (address["address-line1"] || address["address-line2"] ||
+ address["address-line3"]) {
// Treat "street-address" as "address-line1" if it contains only one line
// and "address-line1" is omitted.
- if (!profile["address-line1"] && profile["street-address"] &&
- !profile["street-address"].includes("\n")) {
- profile["address-line1"] = profile["street-address"];
- delete profile["street-address"];
+ if (!address["address-line1"] && address["street-address"] &&
+ !address["street-address"].includes("\n")) {
+ address["address-line1"] = address["street-address"];
+ delete address["street-address"];
}
// Remove "address-line*" but keep the values.
let addressLines = [1, 2, 3].map(i => {
- let value = profile["address-line" + i];
- delete profile["address-line" + i];
+ let value = address["address-line" + i];
+ delete address["address-line" + i];
return value;
});
// Concatenate "address-line*" if "street-address" is omitted.
- if (!profile["street-address"]) {
- profile["street-address"] = addressLines.join("\n");
+ if (!address["street-address"]) {
+ address["street-address"] = addressLines.join("\n");
}
}
},
- _normalizeName(profile) {
- if (!profile.name) {
+ _normalizeName(address) {
+ if (!address.name) {
return;
}
- let nameParts = FormAutofillNameUtils.splitName(profile.name);
- if (!profile["given-name"] && nameParts.given) {
- profile["given-name"] = nameParts.given;
+ let nameParts = FormAutofillNameUtils.splitName(address.name);
+ if (!address["given-name"] && nameParts.given) {
+ address["given-name"] = nameParts.given;
}
- if (!profile["additional-name"] && nameParts.middle) {
- profile["additional-name"] = nameParts.middle;
+ if (!address["additional-name"] && nameParts.middle) {
+ address["additional-name"] = nameParts.middle;
}
- if (!profile["family-name"] && nameParts.family) {
- profile["family-name"] = nameParts.family;
+ if (!address["family-name"] && nameParts.family) {
+ address["family-name"] = nameParts.family;
}
- delete profile.name;
+ delete address.name;
},
- _normalizeProfile(profile) {
- this._normalizeName(profile);
- this._normalizeAddress(profile);
+ _normalizeAddress(address) {
+ this._normalizeName(address);
+ this._normalizeAddressLines(address);
- for (let key in profile) {
+ for (let key in address) {
if (!VALID_FIELDS.includes(key)) {
throw new Error(`"${key}" is not a valid field.`);
}
- if (typeof profile[key] !== "string" &&
- typeof profile[key] !== "number") {
+ if (typeof address[key] !== "string" &&
+ typeof address[key] !== "number") {
throw new Error(`"${key}" contains invalid data type.`);
}
}
},
_dataPostProcessor(data) {
data.version = SCHEMA_VERSION;
- if (!data.profiles) {
- data.profiles = MOCK_MODE ? MOCK_STORAGE : [];
+ if (!data.addresses) {
+ data.addresses = [];
}
return data;
},
// For test only.
_saveImmediately() {
return this._store._save();
},
--- a/browser/extensions/formautofill/content/editProfile.js
+++ b/browser/extensions/formautofill/content/editProfile.js
@@ -4,61 +4,61 @@
"use strict";
const {classes: Cc, interfaces: Ci, utils: Cu, results: Cr} = Components;
Cu.import("resource://gre/modules/Services.jsm");
Cu.import("resource://formautofill/FormAutofillUtils.jsm");
-function EditDialog(profile) {
- this._profile = profile;
+function EditDialog(address) {
+ this._address = address;
window.addEventListener("DOMContentLoaded", this, {once: true});
}
EditDialog.prototype = {
init() {
this.refs = {
controlsContainer: document.getElementById("controls-container"),
cancel: document.getElementById("cancel"),
save: document.getElementById("save"),
};
this.attachEventListeners();
},
/**
- * Asks FormAutofillParent to save or update a profile.
+ * Asks FormAutofillParent to save or update an address.
* @param {object} data
* {
* {string} guid [optional]
- * {object} profile
+ * {object} address
* }
*/
- saveProfile(data) {
- Services.cpmm.sendAsyncMessage("FormAutofill:SaveProfile", data);
+ saveAddress(data) {
+ Services.cpmm.sendAsyncMessage("FormAutofill:SaveAddress", data);
},
/**
- * Fill the form with a profile object.
- * @param {object} profile
+ * Fill the form with an address object.
+ * @param {object} address
*/
- loadInitialValues(profile) {
- for (let field in profile) {
+ loadInitialValues(address) {
+ for (let field in address) {
let input = document.getElementById(field);
if (input) {
- input.value = profile[field];
+ input.value = address[field];
}
}
},
/**
* Get inputs from the form.
* @returns {object}
*/
- buildProfileObject() {
+ buildAddressObject() {
return Array.from(document.forms[0].elements).reduce((obj, input) => {
if (input.value) {
obj[input.id] = input.value;
}
return obj;
}, {});
},
@@ -66,29 +66,29 @@ EditDialog.prototype = {
* Handle events
*
* @param {DOMEvent} event
*/
handleEvent(event) {
switch (event.type) {
case "DOMContentLoaded": {
this.init();
- if (this._profile) {
- this.loadInitialValues(this._profile);
+ if (this._address) {
+ this.loadInitialValues(this._address);
}
break;
}
case "click": {
this.handleClick(event);
break;
}
case "input": {
// Toggle disabled attribute on the save button based on
// whether the form is filled or empty.
- if (Object.keys(this.buildProfileObject()).length == 0) {
+ if (Object.keys(this.buildAddressObject()).length == 0) {
this.refs.save.setAttribute("disabled", true);
} else {
this.refs.save.removeAttribute("disabled");
}
break;
}
}
},
@@ -99,24 +99,24 @@ EditDialog.prototype = {
* @param {DOMEvent} event
*/
handleClick(event) {
if (event.target == this.refs.cancel) {
this.detachEventListeners();
window.close();
}
if (event.target == this.refs.save) {
- if (this._profile) {
- this.saveProfile({
- guid: this._profile.guid,
- profile: this.buildProfileObject(),
+ if (this._address) {
+ this.saveAddress({
+ guid: this._address.guid,
+ address: this.buildAddressObject(),
});
} else {
- this.saveProfile({
- profile: this.buildProfileObject(),
+ this.saveAddress({
+ address: this.buildAddressObject(),
});
}
this.detachEventListeners();
window.close();
}
},
/**
--- a/browser/extensions/formautofill/content/manageProfiles.js
+++ b/browser/extensions/formautofill/content/manageProfiles.js
@@ -20,162 +20,162 @@ function ManageProfileDialog() {
ManageProfileDialog.prototype = {
QueryInterface: XPCOMUtils.generateQI([Ci.nsISupports, Ci.nsIObserver]),
_elements: {},
/**
* Count the number of "formautofill-storage-changed" events epected to
- * receive to prevent repeatedly loading profiles.
+ * receive to prevent repeatedly loading addresses.
* @type {number}
*/
_pendingChangeCount: 0,
/**
- * Get the selected options on the profiles element.
+ * Get the selected options on the addresses element.
*
* @returns {array<DOMElement>}
*/
get _selectedOptions() {
- return Array.from(this._elements.profiles.selectedOptions);
+ return Array.from(this._elements.addresses.selectedOptions);
},
init() {
this._elements = {
- profiles: document.getElementById("profiles"),
+ addresses: document.getElementById("profiles"),
controlsContainer: document.getElementById("controls-container"),
remove: document.getElementById("remove"),
add: document.getElementById("add"),
edit: document.getElementById("edit"),
};
this.attachEventListeners();
},
uninit() {
log.debug("uninit");
this.detachEventListeners();
this._elements = null;
},
/**
- * Load profiles and render them.
+ * Load addresses and render them.
*
* @returns {promise}
*/
- loadProfiles() {
- return this.getProfiles().then(profiles => {
- log.debug("profiles:", profiles);
+ loadAddresses() {
+ return this.getAddresses().then(addresses => {
+ log.debug("addresses:", addresses);
// Sort by last modified time starting with most recent
- profiles.sort((a, b) => b.timeLastModified - a.timeLastModified);
- this.renderProfileElements(profiles);
+ addresses.sort((a, b) => b.timeLastModified - a.timeLastModified);
+ this.renderAddressElements(addresses);
this.updateButtonsStates(this._selectedOptions.length);
});
},
/**
- * Get profiles from storage.
+ * Get addresses from storage.
*
* @returns {promise}
*/
- getProfiles() {
+ getAddresses() {
return new Promise(resolve => {
- Services.cpmm.addMessageListener("FormAutofill:Profiles", function getResult(result) {
- Services.cpmm.removeMessageListener("FormAutofill:Profiles", getResult);
+ Services.cpmm.addMessageListener("FormAutofill:Addresses", function getResult(result) {
+ Services.cpmm.removeMessageListener("FormAutofill:Addresses", getResult);
resolve(result.data);
});
- Services.cpmm.sendAsyncMessage("FormAutofill:GetProfiles", {});
+ Services.cpmm.sendAsyncMessage("FormAutofill:GetAddresses", {});
});
},
/**
- * Render the profiles onto the page while maintaining selected options if
+ * Render the addresses onto the page while maintaining selected options if
* they still exist.
*
- * @param {array<object>} profiles
+ * @param {array<object>} addresses
*/
- renderProfileElements(profiles) {
+ renderAddressElements(addresses) {
let selectedGuids = this._selectedOptions.map(option => option.value);
- this.clearProfileElements();
- for (let profile of profiles) {
- let option = new Option(this.getProfileLabel(profile),
- profile.guid,
+ this.clearAddressElements();
+ for (let address of addresses) {
+ let option = new Option(this.getAddressLabel(address),
+ address.guid,
false,
- selectedGuids.includes(profile.guid));
- option.profile = profile;
- this._elements.profiles.appendChild(option);
+ selectedGuids.includes(address.guid));
+ option.address = address;
+ this._elements.addresses.appendChild(option);
}
},
/**
- * Remove all existing profile elements.
+ * Remove all existing address elements.
*/
- clearProfileElements() {
- let parent = this._elements.profiles;
+ clearAddressElements() {
+ let parent = this._elements.addresses;
while (parent.lastChild) {
parent.removeChild(parent.lastChild);
}
},
/**
- * Remove profiles by guids.
+ * Remove addresses by guids.
* Keep track of the number of "formautofill-storage-changed" events to
- * ignore before loading profiles.
+ * ignore before loading addresses.
*
* @param {array<string>} guids
*/
- removeProfiles(guids) {
+ removeAddresses(guids) {
this._pendingChangeCount += guids.length - 1;
- Services.cpmm.sendAsyncMessage("FormAutofill:RemoveProfiles", {guids});
+ Services.cpmm.sendAsyncMessage("FormAutofill:RemoveAddresses", {guids});
},
/**
- * Get profile display label. It should display up to two pieces of
+ * Get address display label. It should display up to two pieces of
* information, separated by a comma.
*
- * @param {object} profile
+ * @param {object} address
* @returns {string}
*/
- getProfileLabel(profile) {
+ getAddressLabel(address) {
// TODO: Implement a smarter way for deciding what to display
// as option text. Possibly improve the algorithm in
// ProfileAutoCompleteResult.jsm and reuse it here.
const fieldOrder = [
"street-address", // Street address
"address-level2", // City/Town
"organization", // Company or organization name
"address-level1", // Province/State (Standardized code if possible)
"country", // Country
"postal-code", // Postal code
"tel", // Phone number
"email", // Email address
];
let parts = [];
for (const fieldName of fieldOrder) {
- let string = profile[fieldName];
+ let string = address[fieldName];
if (string) {
parts.push(string);
}
if (parts.length == 2) {
break;
}
}
return parts.join(", ");
},
/**
- * Open the edit profile dialog to create/edit a profile.
+ * Open the edit address dialog to create/edit an address.
*
- * @param {object} profile [optional]
+ * @param {object} address [optional]
*/
- openEditDialog(profile) {
+ openEditDialog(address) {
window.openDialog(EDIT_PROFILE_URL, null,
"chrome,centerscreen,modal,width=600,height=370",
- profile);
+ address);
},
/**
* Enable/disable the Edit and Remove buttons based on number of selected
* options.
*
* @param {number} selectedCount
*/
@@ -197,17 +197,17 @@ ManageProfileDialog.prototype = {
* Handle events
*
* @param {DOMEvent} event
*/
handleEvent(event) {
switch (event.type) {
case "DOMContentLoaded": {
this.init();
- this.loadProfiles();
+ this.loadAddresses();
break;
}
case "click": {
this.handleClick(event);
break;
}
case "change": {
this.updateButtonsStates(this._selectedOptions.length);
@@ -222,49 +222,49 @@ ManageProfileDialog.prototype = {
/**
* Handle click events
*
* @param {DOMEvent} event
*/
handleClick(event) {
if (event.target == this._elements.remove) {
- this.removeProfiles(this._selectedOptions.map(option => option.value));
+ this.removeAddresses(this._selectedOptions.map(option => option.value));
} else if (event.target == this._elements.add) {
this.openEditDialog();
} else if (event.target == this._elements.edit) {
- this.openEditDialog(this._selectedOptions[0].profile);
+ this.openEditDialog(this._selectedOptions[0].address);
}
},
observe(subject, topic, data) {
switch (topic) {
case "formautofill-storage-changed": {
if (this._pendingChangeCount) {
this._pendingChangeCount -= 1;
return;
}
- this.loadProfiles();
+ this.loadAddresses();
}
}
},
/**
* Attach event listener
*/
attachEventListeners() {
window.addEventListener("unload", this, {once: true});
- this._elements.profiles.addEventListener("change", this);
+ this._elements.addresses.addEventListener("change", this);
this._elements.controlsContainer.addEventListener("click", this);
Services.obs.addObserver(this, "formautofill-storage-changed");
},
/**
* Remove event listener
*/
detachEventListeners() {
- this._elements.profiles.removeEventListener("change", this);
+ this._elements.addresses.removeEventListener("change", this);
this._elements.controlsContainer.removeEventListener("click", this);
Services.obs.removeObserver(this, "formautofill-storage-changed");
},
};
new ManageProfileDialog();
--- a/browser/extensions/formautofill/test/browser/browser_editProfileDialog.js
+++ b/browser/extensions/formautofill/test/browser/browser_editProfileDialog.js
@@ -1,87 +1,87 @@
"use strict";
registerCleanupFunction(function* () {
- let profiles = yield getProfiles();
- if (profiles.length) {
- yield removeProfiles(profiles.map(profile => profile.guid));
+ let addresses = yield getAddresses();
+ if (addresses.length) {
+ yield removeAddresses(addresses.map(address => address.guid));
}
});
add_task(function* test_cancelEditProfileDialog() {
yield new Promise(resolve => {
let win = window.openDialog(EDIT_PROFILE_DIALOG_URL, null, null, null);
win.addEventListener("load", () => {
win.addEventListener("unload", () => {
ok(true, "Edit profile dialog is closed");
resolve();
}, {once: true});
win.document.querySelector("#cancel").click();
}, {once: true});
});
});
-add_task(function* test_saveProfile() {
+add_task(function* test_saveAddress() {
yield new Promise(resolve => {
let win = window.openDialog(EDIT_PROFILE_DIALOG_URL, null, null, null);
win.addEventListener("load", () => {
win.addEventListener("unload", () => {
ok(true, "Edit profile dialog is closed");
resolve();
}, {once: true});
EventUtils.synthesizeKey("VK_TAB", {}, win);
- EventUtils.synthesizeKey(TEST_PROFILE_1.organization, {}, win);
+ EventUtils.synthesizeKey(TEST_ADDRESS_1.organization, {}, win);
EventUtils.synthesizeKey("VK_TAB", {}, win);
- EventUtils.synthesizeKey(TEST_PROFILE_1["street-address"], {}, win);
+ EventUtils.synthesizeKey(TEST_ADDRESS_1["street-address"], {}, win);
EventUtils.synthesizeKey("VK_TAB", {}, win);
- EventUtils.synthesizeKey(TEST_PROFILE_1["address-level2"], {}, win);
+ EventUtils.synthesizeKey(TEST_ADDRESS_1["address-level2"], {}, win);
EventUtils.synthesizeKey("VK_TAB", {}, win);
- EventUtils.synthesizeKey(TEST_PROFILE_1["address-level1"], {}, win);
+ EventUtils.synthesizeKey(TEST_ADDRESS_1["address-level1"], {}, win);
EventUtils.synthesizeKey("VK_TAB", {}, win);
- EventUtils.synthesizeKey(TEST_PROFILE_1["postal-code"], {}, win);
+ EventUtils.synthesizeKey(TEST_ADDRESS_1["postal-code"], {}, win);
EventUtils.synthesizeKey("VK_TAB", {}, win);
- EventUtils.synthesizeKey(TEST_PROFILE_1.country, {}, win);
+ EventUtils.synthesizeKey(TEST_ADDRESS_1.country, {}, win);
EventUtils.synthesizeKey("VK_TAB", {}, win);
- EventUtils.synthesizeKey(TEST_PROFILE_1.email, {}, win);
+ EventUtils.synthesizeKey(TEST_ADDRESS_1.email, {}, win);
EventUtils.synthesizeKey("VK_TAB", {}, win);
- EventUtils.synthesizeKey(TEST_PROFILE_1.tel, {}, win);
+ EventUtils.synthesizeKey(TEST_ADDRESS_1.tel, {}, win);
EventUtils.synthesizeKey("VK_TAB", {}, win);
EventUtils.synthesizeKey("VK_TAB", {}, win);
EventUtils.synthesizeKey("VK_RETURN", {}, win);
}, {once: true});
});
- let profiles = yield getProfiles();
+ let addresses = yield getAddresses();
- is(profiles.length, 1, "only one profile is in storage");
- is(profiles[0].organization, TEST_PROFILE_1.organization, "match organization");
- is(profiles[0]["street-address"], TEST_PROFILE_1["street-address"], "match street-address");
- is(profiles[0]["address-level2"], TEST_PROFILE_1["address-level2"], "match address-level2");
- is(profiles[0]["address-level1"], TEST_PROFILE_1["address-level1"], "match address-level1");
- is(profiles[0]["postal-code"], TEST_PROFILE_1["postal-code"], "match postal-code");
- is(profiles[0].country, TEST_PROFILE_1.country, "match country");
- is(profiles[0].email, TEST_PROFILE_1.email, "match email");
- is(profiles[0].tel, TEST_PROFILE_1.tel, "match tel");
+ is(addresses.length, 1, "only one address is in storage");
+ is(addresses[0].organization, TEST_ADDRESS_1.organization, "match organization");
+ is(addresses[0]["street-address"], TEST_ADDRESS_1["street-address"], "match street-address");
+ is(addresses[0]["address-level2"], TEST_ADDRESS_1["address-level2"], "match address-level2");
+ is(addresses[0]["address-level1"], TEST_ADDRESS_1["address-level1"], "match address-level1");
+ is(addresses[0]["postal-code"], TEST_ADDRESS_1["postal-code"], "match postal-code");
+ is(addresses[0].country, TEST_ADDRESS_1.country, "match country");
+ is(addresses[0].email, TEST_ADDRESS_1.email, "match email");
+ is(addresses[0].tel, TEST_ADDRESS_1.tel, "match tel");
});
add_task(function* test_editProfile() {
- let profiles = yield getProfiles();
+ let addresses = yield getAddresses();
yield new Promise(resolve => {
let win = window.openDialog(EDIT_PROFILE_DIALOG_URL, null, null, profiles[0]);
win.addEventListener("load", () => {
win.addEventListener("unload", () => {
ok(true, "Edit profile dialog is closed");
resolve();
}, {once: true});
EventUtils.synthesizeKey("VK_TAB", {}, win);
EventUtils.synthesizeKey("test", {}, win);
win.document.querySelector("#save").click();
}, {once: true});
});
- profiles = yield getProfiles();
+ addresses = yield getAddresses();
- is(profiles.length, 1, "only one profile is in storage");
- is(profiles[0].organization, TEST_PROFILE_1.organization + "test", "organization changed");
- yield removeProfiles([profiles[0].guid]);
+ is(addresses.length, 1, "only one address is in storage");
+ is(addresses[0].organization, TEST_ADDRESS_1.organization + "test", "organization changed");
+ yield removeAddresses([addresses[0].guid]);
- profiles = yield getProfiles();
- is(profiles.length, 0, "Profile storage is empty");
+ addresses = yield getAddresses();
+ is(addresses.length, 0, "Address storage is empty");
});
--- a/browser/extensions/formautofill/test/browser/browser_manageProfilesDialog.js
+++ b/browser/extensions/formautofill/test/browser/browser_manageProfilesDialog.js
@@ -1,90 +1,90 @@
"use strict";
const TEST_SELECTORS = {
- selProfiles: "#profiles",
+ selAddresses: "#profiles",
btnRemove: "#remove",
btnAdd: "#add",
btnEdit: "#edit",
};
-function waitForProfiles() {
+function waitForAddresses() {
return new Promise(resolve => {
- Services.cpmm.addMessageListener("FormAutofill:Profiles", function getResult(result) {
- Services.cpmm.removeMessageListener("FormAutofill:Profiles", getResult);
+ Services.cpmm.addMessageListener("FormAutofill:Addresses", function getResult(result) {
+ Services.cpmm.removeMessageListener("FormAutofill:Addresses", getResult);
// Wait for the next tick for elements to get rendered.
SimpleTest.executeSoon(resolve.bind(null, result.data));
});
});
}
registerCleanupFunction(function* () {
- let profiles = yield getProfiles();
- if (profiles.length) {
- yield removeProfiles(profiles.map(profile => profile.guid));
+ let addresses = yield getAddresses();
+ if (addresses.length) {
+ yield removeAddresses(addresses.map(address => address.guid));
}
});
add_task(function* test_manageProfilesInitialState() {
yield BrowserTestUtils.withNewTab({gBrowser, url: MANAGE_PROFILES_DIALOG_URL}, function* (browser) {
yield ContentTask.spawn(browser, TEST_SELECTORS, (args) => {
- let selProfiles = content.document.querySelector(args.selProfiles);
+ let selAddresses = content.document.querySelector(args.selAddresses);
let btnRemove = content.document.querySelector(args.btnRemove);
let btnEdit = content.document.querySelector(args.btnEdit);
let btnAdd = content.document.querySelector(args.btnAdd);
- is(selProfiles.length, 0, "No profile");
+ is(selAddresses.length, 0, "No address");
is(btnAdd.disabled, false, "Add button enabled");
is(btnRemove.disabled, true, "Remove button disabled");
is(btnEdit.disabled, true, "Edit button disabled");
});
});
});
add_task(function* test_removingSingleAndMultipleProfiles() {
- yield saveProfile(TEST_PROFILE_1);
- yield saveProfile(TEST_PROFILE_2);
- yield saveProfile(TEST_PROFILE_3);
+ yield saveAddress(TEST_ADDRESS_1);
+ yield saveAddress(TEST_ADDRESS_2);
+ yield saveAddress(TEST_ADDRESS_3);
let win = window.openDialog(MANAGE_PROFILES_DIALOG_URL);
- yield waitForProfiles();
+ yield waitForAddresses();
- let selProfiles = win.document.querySelector(TEST_SELECTORS.selProfiles);
+ let selAddresses = win.document.querySelector(TEST_SELECTORS.selAddresses);
let btnRemove = win.document.querySelector(TEST_SELECTORS.btnRemove);
let btnEdit = win.document.querySelector(TEST_SELECTORS.btnEdit);
- is(selProfiles.length, 3, "Three profiles");
+ is(selAddresses.length, 3, "Three addresses");
EventUtils.synthesizeMouseAtCenter(selProfiles.children[0], {}, win);
is(btnRemove.disabled, false, "Remove button enabled");
is(btnEdit.disabled, false, "Edit button enabled");
EventUtils.synthesizeMouseAtCenter(btnRemove, {}, win);
- yield waitForProfiles();
- is(selProfiles.length, 2, "Two profiles left");
+ yield waitForAddresses();
+ is(selAddresses.length, 2, "Two addresses left");
- EventUtils.synthesizeMouseAtCenter(selProfiles.children[0], {}, win);
- EventUtils.synthesizeMouseAtCenter(selProfiles.children[1],
+ EventUtils.synthesizeMouseAtCenter(selAddresses.children[0], {}, win);
+ EventUtils.synthesizeMouseAtCenter(selAddresses.children[1],
{shiftKey: true}, win);
is(btnEdit.disabled, true, "Edit button disabled when multi-select");
EventUtils.synthesizeMouseAtCenter(btnRemove, {}, win);
- yield waitForProfiles();
- is(selProfiles.length, 0, "All profiles are removed");
+ yield waitForAddresses();
+ is(selAddresses.length, 0, "All addresses are removed");
win.close();
});
add_task(function* test_profilesDialogWatchesStorageChanges() {
let win = window.openDialog(MANAGE_PROFILES_DIALOG_URL);
- yield waitForProfiles();
+ yield waitForAddresses();
- let selProfiles = win.document.querySelector(TEST_SELECTORS.selProfiles);
+ let selAddresses = win.document.querySelector(TEST_SELECTORS.selAddresses);
- yield saveProfile(TEST_PROFILE_1);
- let profiles = yield waitForProfiles();
- is(selProfiles.length, 1, "One profile is shown");
+ yield saveAddress(TEST_ADDRESS_1);
+ let addresses = yield waitForAddresses();
+ is(selAddresses.length, 1, "One address is shown");
- yield removeProfiles([profiles[0].guid]);
- yield waitForProfiles();
- is(selProfiles.length, 0, "Profile is removed");
+ yield removeAddresses([addresses[0].guid]);
+ yield waitForAddresses();
+ is(selAddresses.length, 0, "Address is removed");
win.close();
});
--- a/browser/extensions/formautofill/test/browser/head.js
+++ b/browser/extensions/formautofill/test/browser/head.js
@@ -1,49 +1,49 @@
/* exported MANAGE_PROFILES_DIALOG_URL, EDIT_PROFILE_DIALOG_URL,
- TEST_PROFILE_1, TEST_PROFILE_2, TEST_PROFILE_3,
- getProfiles, saveProfile, removeProfiles */
+ TEST_ADDRESS_1, TEST_ADDRESS_2, TEST_ADDRESS_3,
+ getAddresses, saveAddress, removeAddresses */
"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 = {
+const TEST_ADDRESS_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 = {
+const TEST_ADDRESS_2 = {
"street-address": "Some Address",
country: "US",
};
-const TEST_PROFILE_3 = {
+const TEST_ADDRESS_3 = {
"street-address": "Other Address",
"postal-code": "12345",
};
-function getProfiles() {
+function getAddresses() {
return new Promise(resolve => {
- Services.cpmm.addMessageListener("FormAutofill:Profiles", function getResult(result) {
- Services.cpmm.removeMessageListener("FormAutofill:Profiles", getResult);
+ Services.cpmm.addMessageListener("FormAutofill:Addresses", function getResult(result) {
+ Services.cpmm.removeMessageListener("FormAutofill:Addresses", getResult);
resolve(result.data);
});
- Services.cpmm.sendAsyncMessage("FormAutofill:GetProfiles", {});
+ Services.cpmm.sendAsyncMessage("FormAutofill:GetAddresses", {});
});
}
-function saveProfile(profile) {
- Services.cpmm.sendAsyncMessage("FormAutofill:SaveProfile", {profile});
+function saveAddress(address) {
+ Services.cpmm.sendAsyncMessage("FormAutofill:SaveAddress", {address});
return TestUtils.topicObserved("formautofill-storage-changed");
}
-function removeProfiles(guids) {
- Services.cpmm.sendAsyncMessage("FormAutofill:RemoveProfiles", {guids});
+function removeAddresses(guids) {
+ Services.cpmm.sendAsyncMessage("FormAutofill:RemoveAddresses", {guids});
return TestUtils.topicObserved("formautofill-storage-changed");
}
--- a/browser/extensions/formautofill/test/unit/test_profileStorage.js
+++ b/browser/extensions/formautofill/test/unit/test_profileStorage.js
@@ -4,267 +4,267 @@
"use strict";
Cu.import("resource://gre/modules/Task.jsm");
Cu.import("resource://formautofill/ProfileStorage.jsm");
const TEST_STORE_FILE_NAME = "test-profile.json";
-const TEST_PROFILE_1 = {
+const TEST_ADDRESS_1 = {
"given-name": "Timothy",
"additional-name": "John",
"family-name": "Berners-Lee",
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 = {
+const TEST_ADDRESS_2 = {
"street-address": "Some Address",
country: "US",
};
-const TEST_PROFILE_3 = {
+const TEST_ADDRESS_3 = {
"street-address": "Other Address",
"postal-code": "12345",
};
-const TEST_PROFILE_WITH_INVALID_FIELD = {
+const TEST_ADDRESS_WITH_INVALID_FIELD = {
"street-address": "Another Address",
invalidField: "INVALID",
};
-let prepareTestProfiles = Task.async(function* (path) {
+let prepareTestRecords = Task.async(function* (path) {
let profileStorage = new ProfileStorage(path);
yield profileStorage.initialize();
let onChanged = TestUtils.topicObserved("formautofill-storage-changed",
(subject, data) => data == "add");
- profileStorage.add(TEST_PROFILE_1);
+ profileStorage.add(TEST_ADDRESS_1);
yield onChanged;
- profileStorage.add(TEST_PROFILE_2);
+ profileStorage.add(TEST_ADDRESS_2);
yield profileStorage._saveImmediately();
});
-let do_check_profile_matches = (profileWithMeta, profile) => {
- for (let key in profile) {
- do_check_eq(profileWithMeta[key], profile[key]);
+let do_check_record_matches = (recordWithMeta, record) => {
+ for (let key in record) {
+ do_check_eq(recordWithMeta[key], record[key]);
}
};
add_task(function* test_initialize() {
let path = getTempFile(TEST_STORE_FILE_NAME).path;
let profileStorage = new ProfileStorage(path);
yield profileStorage.initialize();
do_check_eq(profileStorage._store.data.version, 1);
- do_check_eq(profileStorage._store.data.profiles.length, 0);
+ do_check_eq(profileStorage._store.data.addresses.length, 0);
let data = profileStorage._store.data;
yield profileStorage._saveImmediately();
profileStorage = new ProfileStorage(path);
yield profileStorage.initialize();
Assert.deepEqual(profileStorage._store.data, data);
});
add_task(function* test_getAll() {
let path = getTempFile(TEST_STORE_FILE_NAME).path;
- yield prepareTestProfiles(path);
+ yield prepareTestRecords(path);
let profileStorage = new ProfileStorage(path);
yield profileStorage.initialize();
- let profiles = profileStorage.getAll();
+ let addresses = profileStorage.getAll();
- do_check_eq(profiles.length, 2);
- do_check_profile_matches(profiles[0], TEST_PROFILE_1);
- do_check_profile_matches(profiles[1], TEST_PROFILE_2);
+ do_check_eq(addresses.length, 2);
+ do_check_record_matches(addresses[0], TEST_ADDRESS_1);
+ do_check_record_matches(addresses[1], TEST_ADDRESS_2);
// Modifying output shouldn't affect the storage.
- profiles[0].organization = "test";
- do_check_profile_matches(profileStorage.getAll()[0], TEST_PROFILE_1);
+ addresses[0].organization = "test";
+ do_check_record_matches(profileStorage.getAll()[0], TEST_ADDRESS_1);
});
add_task(function* test_get() {
let path = getTempFile(TEST_STORE_FILE_NAME).path;
- yield prepareTestProfiles(path);
+ yield prepareTestRecords(path);
let profileStorage = new ProfileStorage(path);
yield profileStorage.initialize();
- let profiles = profileStorage.getAll();
- let guid = profiles[0].guid;
+ let addresses = profileStorage.getAll();
+ let guid = addresses[0].guid;
- let profile = profileStorage.get(guid);
- do_check_profile_matches(profile, TEST_PROFILE_1);
+ let address = profileStorage.get(guid);
+ do_check_record_matches(address, TEST_ADDRESS_1);
// Modifying output shouldn't affect the storage.
- profile.organization = "test";
- do_check_profile_matches(profileStorage.get(guid), TEST_PROFILE_1);
+ address.organization = "test";
+ do_check_record_matches(profileStorage.get(guid), TEST_ADDRESS_1);
Assert.throws(() => profileStorage.get("INVALID_GUID"),
- /No matching profile\./);
+ /No matching record\./);
});
add_task(function* test_getByFilter() {
let path = getTempFile(TEST_STORE_FILE_NAME).path;
- yield prepareTestProfiles(path);
+ yield prepareTestRecords(path);
let profileStorage = new ProfileStorage(path);
yield profileStorage.initialize();
let filter = {info: {fieldName: "street-address"}, searchString: "Some"};
- let profiles = profileStorage.getByFilter(filter);
- do_check_eq(profiles.length, 1);
- do_check_profile_matches(profiles[0], TEST_PROFILE_2);
+ let addresses = profileStorage.getByFilter(filter);
+ do_check_eq(addresses.length, 1);
+ do_check_record_matches(addresses[0], TEST_ADDRESS_2);
filter = {info: {fieldName: "country"}, searchString: "u"};
- profiles = profileStorage.getByFilter(filter);
- do_check_eq(profiles.length, 2);
- do_check_profile_matches(profiles[0], TEST_PROFILE_1);
- do_check_profile_matches(profiles[1], TEST_PROFILE_2);
+ addresses = profileStorage.getByFilter(filter);
+ do_check_eq(addresses.length, 2);
+ do_check_record_matches(addresses[0], TEST_ADDRESS_1);
+ do_check_record_matches(addresses[1], TEST_ADDRESS_2);
filter = {info: {fieldName: "street-address"}, searchString: "test"};
- profiles = profileStorage.getByFilter(filter);
- do_check_eq(profiles.length, 0);
+ addresses = profileStorage.getByFilter(filter);
+ do_check_eq(addresses.length, 0);
filter = {info: {fieldName: "street-address"}, searchString: ""};
- profiles = profileStorage.getByFilter(filter);
- do_check_eq(profiles.length, 2);
+ addresses = profileStorage.getByFilter(filter);
+ do_check_eq(addresses.length, 2);
// Check if the filtering logic is free from searching special chars.
filter = {info: {fieldName: "street-address"}, searchString: ".*"};
- profiles = profileStorage.getByFilter(filter);
- do_check_eq(profiles.length, 0);
+ addresses = profileStorage.getByFilter(filter);
+ do_check_eq(addresses.length, 0);
});
add_task(function* test_add() {
let path = getTempFile(TEST_STORE_FILE_NAME).path;
- yield prepareTestProfiles(path);
+ yield prepareTestRecords(path);
let profileStorage = new ProfileStorage(path);
yield profileStorage.initialize();
- let profiles = profileStorage.getAll();
+ let addresses = profileStorage.getAll();
- do_check_eq(profiles.length, 2);
+ do_check_eq(addresses.length, 2);
- do_check_profile_matches(profiles[0], TEST_PROFILE_1);
- do_check_profile_matches(profiles[1], TEST_PROFILE_2);
+ do_check_record_matches(addresses[0], TEST_ADDRESS_1);
+ do_check_record_matches(addresses[1], TEST_ADDRESS_2);
- do_check_neq(profiles[0].guid, undefined);
- do_check_neq(profiles[0].timeCreated, undefined);
- do_check_eq(profiles[0].timeLastModified, profiles[0].timeCreated);
- do_check_eq(profiles[0].timeLastUsed, 0);
- do_check_eq(profiles[0].timesUsed, 0);
+ do_check_neq(addresses[0].guid, undefined);
+ do_check_neq(addresses[0].timeCreated, undefined);
+ do_check_eq(addresses[0].timeLastModified, addresses[0].timeCreated);
+ do_check_eq(addresses[0].timeLastUsed, 0);
+ do_check_eq(addresses[0].timesUsed, 0);
- Assert.throws(() => profileStorage.add(TEST_PROFILE_WITH_INVALID_FIELD),
+ Assert.throws(() => profileStorage.add(TEST_ADDRESS_WITH_INVALID_FIELD),
/"invalidField" is not a valid field\./);
});
add_task(function* test_update() {
let path = getTempFile(TEST_STORE_FILE_NAME).path;
- yield prepareTestProfiles(path);
+ yield prepareTestRecords(path);
let profileStorage = new ProfileStorage(path);
yield profileStorage.initialize();
- let profiles = profileStorage.getAll();
- let guid = profiles[1].guid;
- let timeLastModified = profiles[1].timeLastModified;
+ let addresses = profileStorage.getAll();
+ let guid = addresses[1].guid;
+ let timeLastModified = addresses[1].timeLastModified;
let onChanged = TestUtils.topicObserved("formautofill-storage-changed",
(subject, data) => data == "update");
- do_check_neq(profiles[1].country, undefined);
+ do_check_neq(addresses[1].country, undefined);
- profileStorage.update(guid, TEST_PROFILE_3);
+ profileStorage.update(guid, TEST_ADDRESS_3);
yield onChanged;
yield profileStorage._saveImmediately();
profileStorage = new ProfileStorage(path);
yield profileStorage.initialize();
- let profile = profileStorage.get(guid);
+ let address = profileStorage.get(guid);
- do_check_eq(profile.country, undefined);
- do_check_neq(profile.timeLastModified, timeLastModified);
- do_check_profile_matches(profile, TEST_PROFILE_3);
+ do_check_eq(address.country, undefined);
+ do_check_neq(address.timeLastModified, timeLastModified);
+ do_check_record_matches(address, TEST_ADDRESS_3);
Assert.throws(
- () => profileStorage.update("INVALID_GUID", TEST_PROFILE_3),
- /No matching profile\./
+ () => profileStorage.update("INVALID_GUID", TEST_ADDRESS_3),
+ /No matching record\./
);
Assert.throws(
- () => profileStorage.update(guid, TEST_PROFILE_WITH_INVALID_FIELD),
+ () => profileStorage.update(guid, TEST_ADDRESS_WITH_INVALID_FIELD),
/"invalidField" is not a valid field\./
);
});
add_task(function* test_notifyUsed() {
let path = getTempFile(TEST_STORE_FILE_NAME).path;
- yield prepareTestProfiles(path);
+ yield prepareTestRecords(path);
let profileStorage = new ProfileStorage(path);
yield profileStorage.initialize();
- let profiles = profileStorage.getAll();
- let guid = profiles[1].guid;
- let timeLastUsed = profiles[1].timeLastUsed;
- let timesUsed = profiles[1].timesUsed;
+ let addresses = profileStorage.getAll();
+ let guid = addresses[1].guid;
+ let timeLastUsed = addresses[1].timeLastUsed;
+ let timesUsed = addresses[1].timesUsed;
let onChanged = TestUtils.topicObserved("formautofill-storage-changed",
(subject, data) => data == "notifyUsed");
profileStorage.notifyUsed(guid);
yield onChanged;
yield profileStorage._saveImmediately();
profileStorage = new ProfileStorage(path);
yield profileStorage.initialize();
- let profile = profileStorage.get(guid);
+ let address = profileStorage.get(guid);
- do_check_eq(profile.timesUsed, timesUsed + 1);
- do_check_neq(profile.timeLastUsed, timeLastUsed);
+ do_check_eq(address.timesUsed, timesUsed + 1);
+ do_check_neq(address.timeLastUsed, timeLastUsed);
Assert.throws(() => profileStorage.notifyUsed("INVALID_GUID"),
- /No matching profile\./);
+ /No matching record\./);
});
add_task(function* test_remove() {
let path = getTempFile(TEST_STORE_FILE_NAME).path;
- yield prepareTestProfiles(path);
+ yield prepareTestRecords(path);
let profileStorage = new ProfileStorage(path);
yield profileStorage.initialize();
- let profiles = profileStorage.getAll();
- let guid = profiles[1].guid;
+ let addresses = profileStorage.getAll();
+ let guid = addresses[1].guid;
let onChanged = TestUtils.topicObserved("formautofill-storage-changed",
(subject, data) => data == "remove");
- do_check_eq(profiles.length, 2);
+ do_check_eq(addresses.length, 2);
profileStorage.remove(guid);
yield onChanged;
yield profileStorage._saveImmediately();
profileStorage = new ProfileStorage(path);
yield profileStorage.initialize();
- profiles = profileStorage.getAll();
+ addresses = profileStorage.getAll();
- do_check_eq(profiles.length, 1);
+ do_check_eq(addresses.length, 1);
- Assert.throws(() => profileStorage.get(guid), /No matching profile\./);
+ Assert.throws(() => profileStorage.get(guid), /No matching record\./);
});
--- a/browser/extensions/formautofill/test/unit/test_transformFields.js
+++ b/browser/extensions/formautofill/test/unit/test_transformFields.js
@@ -7,222 +7,222 @@
Cu.import("resource://gre/modules/Task.jsm");
Cu.import("resource://formautofill/ProfileStorage.jsm");
const TEST_STORE_FILE_NAME = "test-profile.json";
const COMPUTE_TESTCASES = [
// Empty
{
- description: "Empty profile",
- profile: {
+ description: "Empty address",
+ address: {
},
expectedResult: {
},
},
// Name
{
description: "Has split names",
- profile: {
+ address: {
"given-name": "Timothy",
"additional-name": "John",
"family-name": "Berners-Lee",
},
expectedResult: {
"given-name": "Timothy",
"additional-name": "John",
"family-name": "Berners-Lee",
"name": "Timothy John Berners-Lee",
},
},
// Address
{
description: "\"street-address\" with single line",
- profile: {
+ address: {
"street-address": "single line",
},
expectedResult: {
"street-address": "single line",
"address-line1": "single line",
},
},
{
description: "\"street-address\" with multiple lines",
- profile: {
+ address: {
"street-address": "line1\nline2\nline3",
},
expectedResult: {
"street-address": "line1\nline2\nline3",
"address-line1": "line1",
"address-line2": "line2",
"address-line3": "line3",
},
},
{
description: "\"street-address\" with multiple lines but line2 is omitted",
- profile: {
+ address: {
"street-address": "line1\n\nline3",
},
expectedResult: {
"street-address": "line1\n\nline3",
"address-line1": "line1",
"address-line2": "",
"address-line3": "line3",
},
},
{
description: "\"street-address\" with 4 lines",
- profile: {
+ address: {
"street-address": "line1\nline2\nline3\nline4",
},
expectedResult: {
"street-address": "line1\nline2\nline3\nline4",
"address-line1": "line1",
"address-line2": "line2",
"address-line3": "line3",
},
},
];
const NORMALIZE_TESTCASES = [
// Empty
{
- description: "Empty profile",
- profile: {
+ description: "Empty address",
+ address: {
},
expectedResult: {
},
},
// Name
{
description: "Has \"name\", and the split names are omitted",
- profile: {
+ address: {
"name": "Timothy John Berners-Lee",
},
expectedResult: {
"given-name": "Timothy",
"additional-name": "John",
"family-name": "Berners-Lee",
},
},
{
description: "Has both \"name\" and split names",
- profile: {
+ address: {
"name": "John Doe",
"given-name": "Timothy",
"additional-name": "John",
"family-name": "Berners-Lee",
},
expectedResult: {
"given-name": "Timothy",
"additional-name": "John",
"family-name": "Berners-Lee",
},
},
{
description: "Has \"name\", and some of split names are omitted",
- profile: {
+ address: {
"name": "John Doe",
"given-name": "Timothy",
},
expectedResult: {
"given-name": "Timothy",
"family-name": "Doe",
},
},
// Address
{
description: "Has \"address-line1~3\" and \"street-address\" is omitted",
- profile: {
+ address: {
"address-line1": "line1",
"address-line2": "line2",
"address-line3": "line3",
},
expectedResult: {
"street-address": "line1\nline2\nline3",
},
},
{
description: "Has both \"address-line1~3\" and \"street-address\"",
- profile: {
+ address: {
"street-address": "street address",
"address-line1": "line1",
"address-line2": "line2",
"address-line3": "line3",
},
expectedResult: {
"street-address": "street address",
},
},
{
description: "Has \"address-line2~3\" and single-line \"street-address\"",
- profile: {
+ address: {
"street-address": "street address",
"address-line2": "line2",
"address-line3": "line3",
},
expectedResult: {
"street-address": "street address\nline2\nline3",
},
},
{
description: "Has \"address-line2~3\" and multiple-line \"street-address\"",
- profile: {
+ address: {
"street-address": "street address\nstreet address line 2",
"address-line2": "line2",
"address-line3": "line3",
},
expectedResult: {
"street-address": "street address\nstreet address line 2",
},
},
];
-let do_check_profile_matches = (expectedProfile, profile) => {
- for (let key in expectedProfile) {
- do_check_eq(expectedProfile[key], profile[key] || "");
+let do_check_record_matches = (expectedRecord, record) => {
+ for (let key in expectedRecord) {
+ do_check_eq(expectedRecord[key], record[key] || "");
}
};
add_task(function* test_computeFields() {
let path = getTempFile(TEST_STORE_FILE_NAME).path;
let profileStorage = new ProfileStorage(path);
yield profileStorage.initialize();
- COMPUTE_TESTCASES.forEach(testcase => profileStorage.add(testcase.profile));
+ COMPUTE_TESTCASES.forEach(testcase => profileStorage.add(testcase.address));
yield profileStorage._saveImmediately();
profileStorage = new ProfileStorage(path);
yield profileStorage.initialize();
- let profiles = profileStorage.getAll();
+ let addresses = profileStorage.getAll();
- for (let i in profiles) {
+ for (let i in addresses) {
do_print("Verify testcase: " + COMPUTE_TESTCASES[i].description);
- do_check_profile_matches(COMPUTE_TESTCASES[i].expectedResult, profiles[i]);
+ do_check_record_matches(COMPUTE_TESTCASES[i].expectedResult, addresses[i]);
}
});
-add_task(function* test_normalizeProfile() {
+add_task(function* test_normalizeFields() {
let path = getTempFile(TEST_STORE_FILE_NAME).path;
let profileStorage = new ProfileStorage(path);
yield profileStorage.initialize();
- NORMALIZE_TESTCASES.forEach(testcase => profileStorage.add(testcase.profile));
+ NORMALIZE_TESTCASES.forEach(testcase => profileStorage.add(testcase.address));
yield profileStorage._saveImmediately();
profileStorage = new ProfileStorage(path);
yield profileStorage.initialize();
- let profiles = profileStorage.getAll();
+ let addresses = profileStorage.getAll();
- for (let i in profiles) {
+ for (let i in addresses) {
do_print("Verify testcase: " + NORMALIZE_TESTCASES[i].description);
- do_check_profile_matches(NORMALIZE_TESTCASES[i].expectedResult, profiles[i]);
+ do_check_record_matches(NORMALIZE_TESTCASES[i].expectedResult, addresses[i]);
}
});