Bug 1429976 - Include collectionName in formautofill-storage-changed notify payload. r=lchang

MozReview-Commit-ID: 55m97PwMXsx

--HG--
extra : rebase_source : d2a8534bcc5e27241f7521cdb806bea8db0c4785
This commit is contained in:
Ray Lin 2018-01-16 12:18:48 +08:00
Родитель 5ee733c0c6
Коммит 92c96346cb
5 изменённых файлов: 61 добавлений и 18 удалений

Просмотреть файл

@ -376,7 +376,10 @@ class AutofillRecords {
this._store.saveSoon();
Services.obs.notifyObservers({wrappedJSObject: {sourceSync}}, "formautofill-storage-changed", "add");
Services.obs.notifyObservers({wrappedJSObject: {
sourceSync,
collectionName: this._collectionName,
}}, "formautofill-storage-changed", "add");
return recordToSave.guid;
}
@ -449,9 +452,10 @@ class AutofillRecords {
this._store.saveSoon();
let str = Cc["@mozilla.org/supports-string;1"].createInstance(Ci.nsISupportsString);
str.data = guid;
Services.obs.notifyObservers(str, "formautofill-storage-changed", "update");
Services.obs.notifyObservers({wrappedJSObject: {
guid,
collectionName: this._collectionName,
}}, "formautofill-storage-changed", "update");
}
/**
@ -519,7 +523,10 @@ class AutofillRecords {
}
this._store.saveSoon();
Services.obs.notifyObservers({wrappedJSObject: {sourceSync}}, "formautofill-storage-changed", "remove");
Services.obs.notifyObservers({wrappedJSObject: {
sourceSync,
collectionName: this._collectionName,
}}, "formautofill-storage-changed", "remove");
}
/**
@ -838,6 +845,7 @@ class AutofillRecords {
this._store.saveSoon();
Services.obs.notifyObservers({wrappedJSObject: {
sourceSync: true,
collectionName: this._collectionName,
}}, "formautofill-storage-changed", "reconcile");
return {forkedGUID};

Просмотреть файл

@ -68,8 +68,12 @@ async function initProfileStorage(fileName, records, collectionName = "addresses
return profileStorage;
}
let onChanged = TestUtils.topicObserved("formautofill-storage-changed",
(subject, data) => data == "add");
let onChanged = TestUtils.topicObserved(
"formautofill-storage-changed",
(subject, data) =>
data == "add" &&
subject.wrappedJSObject.collectionName == collectionName
);
for (let record of records) {
Assert.ok(profileStorage[collectionName].add(record));
await onChanged;

Просмотреть файл

@ -5,6 +5,7 @@
"use strict";
const TEST_STORE_FILE_NAME = "test-profile.json";
const COLLECTION_NAME = "addresses";
const TEST_ADDRESS_1 = {
"given-name": "Timothy",
@ -378,7 +379,9 @@ add_task(async function test_update() {
let onChanged = TestUtils.topicObserved(
"formautofill-storage-changed",
(subject, data) =>
data == "update" && subject.QueryInterface(Ci.nsISupportsString).data == guid
data == "update" &&
subject.wrappedJSObject.guid == guid &&
subject.wrappedJSObject.collectionName == COLLECTION_NAME
);
Assert.notEqual(addresses[1].country, undefined);
@ -491,8 +494,12 @@ add_task(async function test_remove() {
let addresses = profileStorage.addresses.getAll();
let guid = addresses[1].guid;
let onChanged = TestUtils.topicObserved("formautofill-storage-changed",
(subject, data) => data == "remove");
let onChanged = TestUtils.topicObserved(
"formautofill-storage-changed",
(subject, data) =>
data == "remove" &&
subject.wrappedJSObject.collectionName == COLLECTION_NAME
);
Assert.equal(addresses.length, 2);
@ -519,7 +526,9 @@ MERGE_TESTCASES.forEach((testcase) => {
let onMerged = TestUtils.topicObserved(
"formautofill-storage-changed",
(subject, data) =>
data == "update" && subject.QueryInterface(Ci.nsISupportsString).data == guid
data == "update" &&
subject.wrappedJSObject.guid == guid &&
subject.wrappedJSObject.collectionName == COLLECTION_NAME
);
// Force to create sync metadata.

Просмотреть файл

@ -7,6 +7,7 @@
const {ProfileStorage} = Cu.import("resource://formautofill/ProfileStorage.jsm", {});
const TEST_STORE_FILE_NAME = "test-credit-card.json";
const COLLECTION_NAME = "creditCards";
const TEST_CREDIT_CARD_1 = {
"cc-name": "John Doe",
@ -148,8 +149,12 @@ let prepareTestCreditCards = async function(path) {
let profileStorage = new ProfileStorage(path);
await profileStorage.initialize();
let onChanged = TestUtils.topicObserved("formautofill-storage-changed",
(subject, data) => data == "add");
let onChanged = TestUtils.topicObserved(
"formautofill-storage-changed",
(subject, data) =>
data == "add" &&
subject.wrappedJSObject.collectionName == COLLECTION_NAME
);
Assert.ok(profileStorage.creditCards.add(TEST_CREDIT_CARD_1));
await onChanged;
Assert.ok(profileStorage.creditCards.add(TEST_CREDIT_CARD_2));
@ -295,8 +300,12 @@ add_task(async function test_update() {
let guid = creditCards[1].guid;
let timeLastModified = creditCards[1].timeLastModified;
let onChanged = TestUtils.topicObserved("formautofill-storage-changed",
(subject, data) => data == "update");
let onChanged = TestUtils.topicObserved(
"formautofill-storage-changed",
(subject, data) =>
data == "update" &&
subject.wrappedJSObject.collectionName == COLLECTION_NAME
);
Assert.notEqual(creditCards[1]["cc-name"], undefined);
profileStorage.creditCards.update(guid, TEST_CREDIT_CARD_3);
@ -421,8 +430,12 @@ add_task(async function test_remove() {
let creditCards = profileStorage.creditCards.getAll();
let guid = creditCards[1].guid;
let onChanged = TestUtils.topicObserved("formautofill-storage-changed",
(subject, data) => data == "remove");
let onChanged = TestUtils.topicObserved(
"formautofill-storage-changed",
(subject, data) =>
data == "remove" &&
subject.wrappedJSObject.collectionName == COLLECTION_NAME
);
Assert.equal(creditCards.length, 2);
@ -453,7 +466,9 @@ MERGE_TESTCASES.forEach((testcase) => {
let onMerged = TestUtils.topicObserved(
"formautofill-storage-changed",
(subject, data) =>
data == "update" && subject.QueryInterface(Ci.nsISupportsString).data == guid
data == "update" &&
subject.wrappedJSObject.guid == guid &&
subject.wrappedJSObject.collectionName == COLLECTION_NAME
);
// Force to create sync metadata.
profileStorage.creditCards.pullSyncChanges();

Просмотреть файл

@ -1011,7 +1011,14 @@ add_task(async function test_reconcile_three_way_merge() {
rawData: true,
});
let onReconciled = TestUtils.topicObserved(
"formautofill-storage-changed",
(subject, data) =>
data == "reconcile" &&
subject.wrappedJSObject.collectionName == collectionName
);
let {forkedGUID} = profileStorage[collectionName].reconcile(test.remote);
await onReconciled;
let reconciledRecord = profileStorage[collectionName].get(test.parent.guid, {
rawData: true,
});