--- 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());
@@ -149,17 +149,17 @@ FormAutofillParent.prototype = {
*
* @returns {boolean} status of form autofill feature
*/
_getStatus() {
if (!Services.prefs.getBoolPref(ENABLED_PREF)) {
return false;
}
- return this._profileStore.profiles.getAll().length > 0;
+ return this._profileStore.addresses.getAll().length > 0;
},
/**
* Set status and trigger _onStatusChanged.
*
* @param {boolean} newStatus The latest status we want to set for _enabled
*/
_setStatus(newStatus) {
@@ -171,30 +171,30 @@ 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._profileStore.addresses.update(data.guid, data.address);
} else {
- this.getProfileStore().add(data.profile);
+ this._profileStore.addresses.add(data.address);
}
break;
}
- case "FormAutofill:RemoveProfiles": {
- data.guids.forEach(guid => this.getProfileStore().remove(guid));
+ case "FormAutofill:RemoveAddresses": {
+ data.guids.forEach(guid => this._profileStore.addresses.remove(guid));
break;
}
}
},
/**
* Returns the instance of ProfileStorage. To avoid syncing issues, anyone
* who needs to access the profile should request the instance by this instead
@@ -212,56 +212,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 profileStore 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.profiles.getByFilter({searchString, info});
+ addresses = this._profileStore.addresses.getByFilter({searchString, info});
} else {
- profiles = this._profileStore.profiles.getAll();
+ addresses = this._profileStore.addresses.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.profiles.getAll().forEach((profile) => {
- Object.keys(profile).forEach((fieldName) => {
- if (!profile[fieldName]) {
+ this._profileStore.addresses.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,21 +6,21 @@
* 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 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,
@@ -331,19 +331,19 @@ class AutofillRecords {
// An interface to be inherited.
_recordReadProcessor(record, noComputedFields) {}
// An interface to be inherited.
_recordWriteProcessor(record) {}
}
-class Profiles extends AutofillRecords {
+class Addresses extends AutofillRecords {
constructor(store) {
- super(store, "profiles", VALID_PROFILE_FIELDS);
+ super(store, "addresses", VALID_PROFILE_FIELDS);
}
_recordReadProcessor(profile, noComputedFields) {
if (noComputedFields) {
return;
}
// Compute name
@@ -477,22 +477,22 @@ class CreditCards extends AutofillRecord
}
class ProfileStorage {
constructor(path) {
this._path = path;
this.INTERNAL_FIELDS = INTERNAL_FIELDS;
}
- get profiles() {
- if (!this._profiles) {
+ get addresses() {
+ if (!this._addresses) {
this._store.ensureDataReady();
- this._profiles = new Profiles(this._store);
+ this._addresses = new Addresses(this._store);
}
- return this._profiles;
+ return this._addresses;
}
get creditCards() {
if (!this._creditCards) {
this._store.ensureDataReady();
this._creditCards = new CreditCards(this._store);
}
return this._creditCards;
@@ -510,18 +510,18 @@ class ProfileStorage {
path: this._path,
dataPostProcessor: this._dataPostProcessor.bind(this),
});
return this._store.load();
}
_dataPostProcessor(data) {
data.version = SCHEMA_VERSION;
- if (!data.profiles) {
- data.profiles = [];
+ if (!data.addresses) {
+ data.addresses = [];
}
if (!data.creditCards) {
data.creditCards = [];
}
return data;
}
// For test only.
--- a/browser/extensions/formautofill/content/editProfile.js
+++ b/browser/extensions/formautofill/content/editProfile.js
@@ -20,25 +20,25 @@ EditDialog.prototype = {
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
* }
*/
- 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
*/
loadInitialValues(profile) {
for (let field in profile) {
@@ -100,23 +100,23 @@ EditDialog.prototype = {
*/
handleClick(event) {
if (event.target == this.refs.cancel) {
this.detachEventListeners();
window.close();
}
if (event.target == this.refs.save) {
if (this._profile) {
- this.saveProfile({
+ this.saveAddress({
guid: this._profile.guid,
- profile: this.buildProfileObject(),
+ address: this.buildProfileObject(),
});
} else {
- this.saveProfile({
- profile: this.buildProfileObject(),
+ this.saveAddress({
+ address: this.buildProfileObject(),
});
}
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 profile 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_manageProfilesDialog.js
+++ b/browser/extensions/formautofill/test/browser/browser_manageProfilesDialog.js
@@ -27,37 +27,37 @@ const TEST_PROFILE_2 = {
};
const TEST_PROFILE_3 = {
"street-address": "Other Address",
"postal-code": "12345",
};
function saveProfile(profile) {
- Services.cpmm.sendAsyncMessage("FormAutofill:SaveProfile", {profile});
+ Services.cpmm.sendAsyncMessage("FormAutofill:SaveAddress", {profile});
return TestUtils.topicObserved("formautofill-storage-changed");
}
function removeProfiles(guids) {
- Services.cpmm.sendAsyncMessage("FormAutofill:RemoveProfiles", {guids});
+ Services.cpmm.sendAsyncMessage("FormAutofill:RemoveAddresses", {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);
+ 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* () {
- Services.cpmm.sendAsyncMessage("FormAutofill:GetProfiles", {});
+ Services.cpmm.sendAsyncMessage("FormAutofill:GetAddresses", {});
let profiles = yield waitForProfiles();
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) {
--- a/browser/extensions/formautofill/test/unit/test_enabledStatus.js
+++ b/browser/extensions/formautofill/test/unit/test_enabledStatus.js
@@ -60,17 +60,17 @@ add_task(function* test_enabledStatus_ob
add_task(function* test_enabledStatus_getStatus() {
let formAutofillParent = new FormAutofillParent();
do_register_cleanup(function cleanup() {
Services.prefs.clearUserPref("browser.formautofill.enabled");
});
let fakeStorage = [];
formAutofillParent._profileStore = {
- profiles: {
+ addresses: {
getAll: () => fakeStorage,
},
};
// pref is enabled and profile is empty.
Services.prefs.setBoolPref("browser.formautofill.enabled", true);
do_check_eq(formAutofillParent._getStatus(), false);
--- a/browser/extensions/formautofill/test/unit/test_profileStorage.js
+++ b/browser/extensions/formautofill/test/unit/test_profileStorage.js
@@ -1,270 +1,270 @@
/**
- * Tests ProfileStorage object profiles records.
+ * Tests ProfileStorage object with addresses records.
*/
"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 prepareTestAddresses = Task.async(function* (path) {
let profileStorage = new ProfileStorage(path);
yield profileStorage.initialize();
let onChanged = TestUtils.topicObserved("formautofill-storage-changed",
(subject, data) => data == "add");
- profileStorage.profiles.add(TEST_PROFILE_1);
+ profileStorage.addresses.add(TEST_ADDRESS_1);
yield onChanged;
- profileStorage.profiles.add(TEST_PROFILE_2);
+ profileStorage.addresses.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_address_matches = (addressWithMeta, address) => {
+ for (let key in address) {
+ do_check_eq(addressWithMeta[key], address[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;
- Assert.deepEqual(data.profiles, []);
+ Assert.deepEqual(data.addresses, []);
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 prepareTestAddresses(path);
let profileStorage = new ProfileStorage(path);
yield profileStorage.initialize();
- let profiles = profileStorage.profiles.getAll();
+ let addresses = profileStorage.addresses.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_address_matches(addresses[0], TEST_ADDRESS_1);
+ do_check_address_matches(addresses[1], TEST_ADDRESS_2);
// Modifying output shouldn't affect the storage.
- profiles[0].organization = "test";
- do_check_profile_matches(profileStorage.profiles.getAll()[0], TEST_PROFILE_1);
+ addresses[0].organization = "test";
+ do_check_address_matches(profileStorage.addresses.getAll()[0], TEST_ADDRESS_1);
});
add_task(function* test_get() {
let path = getTempFile(TEST_STORE_FILE_NAME).path;
- yield prepareTestProfiles(path);
+ yield prepareTestAddresses(path);
let profileStorage = new ProfileStorage(path);
yield profileStorage.initialize();
- let profiles = profileStorage.profiles.getAll();
- let guid = profiles[0].guid;
+ let addresses = profileStorage.addresses.getAll();
+ let guid = addresses[0].guid;
- let profile = profileStorage.profiles.get(guid);
- do_check_profile_matches(profile, TEST_PROFILE_1);
+ let address = profileStorage.addresses.get(guid);
+ do_check_address_matches(address, TEST_ADDRESS_1);
// Modifying output shouldn't affect the storage.
- profile.organization = "test";
- do_check_profile_matches(profileStorage.profiles.get(guid), TEST_PROFILE_1);
+ address.organization = "test";
+ do_check_address_matches(profileStorage.addresses.get(guid), TEST_ADDRESS_1);
- Assert.throws(() => profileStorage.profiles.get("INVALID_GUID"),
+ Assert.throws(() => profileStorage.addresses.get("INVALID_GUID"),
/No matching record\./);
});
add_task(function* test_getByFilter() {
let path = getTempFile(TEST_STORE_FILE_NAME).path;
- yield prepareTestProfiles(path);
+ yield prepareTestAddresses(path);
let profileStorage = new ProfileStorage(path);
yield profileStorage.initialize();
let filter = {info: {fieldName: "street-address"}, searchString: "Some"};
- let profiles = profileStorage.profiles.getByFilter(filter);
- do_check_eq(profiles.length, 1);
- do_check_profile_matches(profiles[0], TEST_PROFILE_2);
+ let addresses = profileStorage.addresses.getByFilter(filter);
+ do_check_eq(addresses.length, 1);
+ do_check_address_matches(addresses[0], TEST_ADDRESS_2);
filter = {info: {fieldName: "country"}, searchString: "u"};
- profiles = profileStorage.profiles.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.addresses.getByFilter(filter);
+ do_check_eq(addresses.length, 2);
+ do_check_address_matches(addresses[0], TEST_ADDRESS_1);
+ do_check_address_matches(addresses[1], TEST_ADDRESS_2);
filter = {info: {fieldName: "street-address"}, searchString: "test"};
- profiles = profileStorage.profiles.getByFilter(filter);
- do_check_eq(profiles.length, 0);
+ addresses = profileStorage.addresses.getByFilter(filter);
+ do_check_eq(addresses.length, 0);
filter = {info: {fieldName: "street-address"}, searchString: ""};
- profiles = profileStorage.profiles.getByFilter(filter);
- do_check_eq(profiles.length, 2);
+ addresses = profileStorage.addresses.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.profiles.getByFilter(filter);
- do_check_eq(profiles.length, 0);
+ addresses = profileStorage.addresses.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 prepareTestAddresses(path);
let profileStorage = new ProfileStorage(path);
yield profileStorage.initialize();
- let profiles = profileStorage.profiles.getAll();
+ let addresses = profileStorage.addresses.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_address_matches(addresses[0], TEST_ADDRESS_1);
+ do_check_address_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.profiles.add(TEST_PROFILE_WITH_INVALID_FIELD),
+ Assert.throws(() => profileStorage.addresses.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 prepareTestAddresses(path);
let profileStorage = new ProfileStorage(path);
yield profileStorage.initialize();
- let profiles = profileStorage.profiles.getAll();
- let guid = profiles[1].guid;
- let timeLastModified = profiles[1].timeLastModified;
+ let addresses = profileStorage.addresses.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.profiles.update(guid, TEST_PROFILE_3);
+ profileStorage.addresses.update(guid, TEST_ADDRESS_3);
yield onChanged;
yield profileStorage._saveImmediately();
profileStorage = new ProfileStorage(path);
yield profileStorage.initialize();
- let profile = profileStorage.profiles.get(guid);
+ let address = profileStorage.addresses.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_address_matches(address, TEST_ADDRESS_3);
Assert.throws(
- () => profileStorage.profiles.update("INVALID_GUID", TEST_PROFILE_3),
+ () => profileStorage.addresses.update("INVALID_GUID", TEST_ADDRESS_3),
/No matching record\./
);
Assert.throws(
- () => profileStorage.profiles.update(guid, TEST_PROFILE_WITH_INVALID_FIELD),
+ () => profileStorage.addresses.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 prepareTestAddresses(path);
let profileStorage = new ProfileStorage(path);
yield profileStorage.initialize();
- let profiles = profileStorage.profiles.getAll();
- let guid = profiles[1].guid;
- let timeLastUsed = profiles[1].timeLastUsed;
- let timesUsed = profiles[1].timesUsed;
+ let addresses = profileStorage.addresses.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.profiles.notifyUsed(guid);
+ profileStorage.addresses.notifyUsed(guid);
yield onChanged;
yield profileStorage._saveImmediately();
profileStorage = new ProfileStorage(path);
yield profileStorage.initialize();
- let profile = profileStorage.profiles.get(guid);
+ let address = profileStorage.addresses.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.profiles.notifyUsed("INVALID_GUID"),
+ Assert.throws(() => profileStorage.addresses.notifyUsed("INVALID_GUID"),
/No matching record\./);
});
add_task(function* test_remove() {
let path = getTempFile(TEST_STORE_FILE_NAME).path;
- yield prepareTestProfiles(path);
+ yield prepareTestAddresses(path);
let profileStorage = new ProfileStorage(path);
yield profileStorage.initialize();
- let profiles = profileStorage.profiles.getAll();
- let guid = profiles[1].guid;
+ let addresses = profileStorage.addresses.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.profiles.remove(guid);
+ profileStorage.addresses.remove(guid);
yield onChanged;
yield profileStorage._saveImmediately();
profileStorage = new ProfileStorage(path);
yield profileStorage.initialize();
- profiles = profileStorage.profiles.getAll();
- do_check_eq(profiles.length, 1);
+ addresses = profileStorage.addresses.getAll();
+ do_check_eq(addresses.length, 1);
- Assert.throws(() => profileStorage.profiles.get(guid), /No matching record\./);
+ Assert.throws(() => profileStorage.addresses.get(guid), /No matching record\./);
});
--- a/browser/extensions/formautofill/test/unit/test_savedFieldNames.js
+++ b/browser/extensions/formautofill/test/unit/test_savedFieldNames.js
@@ -38,18 +38,18 @@ add_task(function* test_profileSavedFiel
add_task(function* test_profileSavedFieldNames_update() {
let formAutofillParent = new FormAutofillParent();
formAutofillParent.init();
do_register_cleanup(function cleanup() {
Services.prefs.clearUserPref("browser.formautofill.enabled");
});
- sinon.stub(formAutofillParent._profileStore.profiles, "getAll");
- formAutofillParent._profileStore.profiles.getAll.returns([]);
+ sinon.stub(formAutofillParent._profileStore.addresses, "getAll");
+ formAutofillParent._profileStore.addresses.getAll.returns([]);
// The set is empty if there's no profile in the store.
formAutofillParent._updateSavedFieldNames();
do_check_eq(Services.ppmm.initialProcessData.autofillSavedFieldNames.size, 0);
// 2 profiles with 4 valid fields.
let fakeStorage = [{
guid: "test-guid-1",
@@ -67,17 +67,17 @@ add_task(function* test_profileSavedFiel
"street-address": "331 E. Evelyn Avenue",
tel: "1-650-903-0800",
country: "US",
timeCreated: 0,
timeLastUsed: 0,
timeLastModified: 0,
timesUsed: 0,
}];
- formAutofillParent._profileStore.profiles.getAll.returns(fakeStorage);
+ formAutofillParent._profileStore.addresses.getAll.returns(fakeStorage);
formAutofillParent._updateSavedFieldNames();
let autofillSavedFieldNames = Services.ppmm.initialProcessData.autofillSavedFieldNames;
do_check_eq(autofillSavedFieldNames.size, 4);
do_check_eq(autofillSavedFieldNames.has("organization"), true);
do_check_eq(autofillSavedFieldNames.has("street-address"), true);
do_check_eq(autofillSavedFieldNames.has("tel"), true);
do_check_eq(autofillSavedFieldNames.has("email"), false);
--- a/browser/extensions/formautofill/test/unit/test_transformFields.js
+++ b/browser/extensions/formautofill/test/unit/test_transformFields.js
@@ -4,178 +4,178 @@
"use strict";
Cu.import("resource://gre/modules/Task.jsm");
Cu.import("resource://formautofill/ProfileStorage.jsm");
const TEST_STORE_FILE_NAME = "test-profile.json";
-const PROFILE_COMPUTE_TESTCASES = [
+const ADDRESS_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 PROFILE_NORMALIZE_TESTCASES = [
+const ADDRESS_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",
},
},
@@ -235,59 +235,59 @@ const CREDIT_CARD_NORMALIZE_TESTCASES =
"cc-family-name": "Doe",
},
expectedResult: {
"cc-name": "John Doe",
},
},
];
-let do_check_record_matches = (expectedProfile, profile) => {
- for (let key in expectedProfile) {
- do_check_eq(expectedProfile[key], profile[key] || "");
+let do_check_record_matches = (expectedAddress, address) => {
+ for (let key in expectedAddress) {
+ do_check_eq(expectedAddress[key], address[key] || "");
}
};
-add_task(function* test_computeProfileFields() {
+add_task(function* test_computeAddressFields() {
let path = getTempFile(TEST_STORE_FILE_NAME).path;
let profileStorage = new ProfileStorage(path);
yield profileStorage.initialize();
- PROFILE_COMPUTE_TESTCASES.forEach(testcase => profileStorage.profiles.add(testcase.profile));
+ ADDRESS_COMPUTE_TESTCASES.forEach(testcase => profileStorage.addresses.add(testcase.address));
yield profileStorage._saveImmediately();
profileStorage = new ProfileStorage(path);
yield profileStorage.initialize();
- let profiles = profileStorage.profiles.getAll();
+ let addresses = profileStorage.addresses.getAll();
- for (let i in profiles) {
- do_print("Verify testcase: " + PROFILE_COMPUTE_TESTCASES[i].description);
- do_check_record_matches(PROFILE_COMPUTE_TESTCASES[i].expectedResult, profiles[i]);
+ for (let i in addresses) {
+ do_print("Verify testcase: " + ADDRESS_COMPUTE_TESTCASES[i].description);
+ do_check_record_matches(ADDRESS_COMPUTE_TESTCASES[i].expectedResult, addresses[i]);
}
});
-add_task(function* test_normalizeProfileFields() {
+add_task(function* test_normalizeAddressFields() {
let path = getTempFile(TEST_STORE_FILE_NAME).path;
let profileStorage = new ProfileStorage(path);
yield profileStorage.initialize();
- PROFILE_NORMALIZE_TESTCASES.forEach(testcase => profileStorage.profiles.add(testcase.profile));
+ ADDRESS_NORMALIZE_TESTCASES.forEach(testcase => profileStorage.addresses.add(testcase.address));
yield profileStorage._saveImmediately();
profileStorage = new ProfileStorage(path);
yield profileStorage.initialize();
- let profiles = profileStorage.profiles.getAll();
+ let addresses = profileStorage.addresses.getAll();
- for (let i in profiles) {
- do_print("Verify testcase: " + PROFILE_NORMALIZE_TESTCASES[i].description);
- do_check_record_matches(PROFILE_NORMALIZE_TESTCASES[i].expectedResult, profiles[i]);
+ for (let i in addresses) {
+ do_print("Verify testcase: " + ADDRESS_NORMALIZE_TESTCASES[i].description);
+ do_check_record_matches(ADDRESS_NORMALIZE_TESTCASES[i].expectedResult, addresses[i]);
}
});
add_task(function* test_computeCreditCardFields() {
let path = getTempFile(TEST_STORE_FILE_NAME).path;
let profileStorage = new ProfileStorage(path);
yield profileStorage.initialize();