--- a/services/sync/tests/unit/test_engine_changes_during_sync.js
+++ b/services/sync/tests/unit/test_engine_changes_during_sync.js
@@ -1,10 +1,11 @@
Cu.import("resource://gre/modules/FormHistory.jsm");
Cu.import("resource://gre/modules/Log.jsm");
+Cu.import("resource://gre/modules/PlacesSyncUtils.jsm");
Cu.import("resource://services-sync/service.js");
Cu.import("resource://services-sync/engines/bookmarks.js");
Cu.import("resource://services-sync/engines/history.js");
Cu.import("resource://services-sync/engines/forms.js");
Cu.import("resource://services-sync/engines/passwords.js");
Cu.import("resource://services-sync/engines/prefs.js");
Cu.import("resource://testing-common/services/sync/utils.js");
@@ -38,29 +39,27 @@ add_task(async function test_history_cha
enableValidationPrefs();
let engine = Service.engineManager.get("history");
let server = serverForEnginesWithKeys({"foo": "password"}, [engine]);
await SyncTestingInfrastructure(server);
let collection = server.user("foo").collection("history");
- // Override `applyIncomingBatch` to insert a record while we're applying
+ // Override `uploadOutgoing` to insert a record while we're applying
// changes. The tracker should ignore this change.
- let { applyIncomingBatch } = engine._store;
- engine._store.applyIncomingBatch = async function(records) {
- _("Inserting local history visit");
- engine._store.applyIncomingBatch = applyIncomingBatch;
- let failed;
+ let uploadOutgoing = engine._uploadOutgoing;
+ engine._uploadOutgoing = async function() {
+ engine._uploadOutgoing = uploadOutgoing;
try {
- await addVisit("during_sync");
+ await uploadOutgoing.call(this);
} finally {
- failed = await applyIncomingBatch.call(this, records);
+ _("Inserting local history visit");
+ await addVisit("during_sync");
}
- return failed;
};
Svc.Obs.notify("weave:engine:start-tracking");
try {
let remoteRec = new HistoryRec("history", "UrOOuzE5QM-e");
remoteRec.histUri = "http://getfirefox.com/";
remoteRec.title = "Get Firefox!";
@@ -76,49 +75,45 @@ add_task(async function test_history_cha
equal(collection.count(), 1,
"New local visit should not exist on server after first sync");
await sync_engine_and_validate_telem(engine, true);
strictEqual(Service.scheduler.globalScore, 0,
"Should not bump global score during second history sync");
- // ...But we still won't ever upload the visit to the server, since we
- // cleared the tracker after the first sync.
- equal(collection.count(), 1,
- "New local visit won't exist on server after second sync");
+ equal(collection.count(), 2,
+ "New local visit should exist on server after second sync");
} finally {
- engine._store.applyIncomingBatch = applyIncomingBatch;
+ engine._uploadOutgoing = uploadOutgoing;
await cleanup(engine, server);
}
});
add_task(async function test_passwords_change_during_sync() {
_("Ensure that we don't bump the score when applying passwords.");
enableValidationPrefs();
let engine = Service.engineManager.get("passwords");
let server = serverForEnginesWithKeys({"foo": "password"}, [engine]);
await SyncTestingInfrastructure(server);
let collection = server.user("foo").collection("passwords");
- let { applyIncomingBatch } = engine._store;
- engine._store.applyIncomingBatch = async function(records) {
- _("Inserting local password");
- engine._store.applyIncomingBatch = applyIncomingBatch;
- let failed;
+ let uploadOutgoing = engine._uploadOutgoing;
+ engine._uploadOutgoing = async function() {
+ engine._uploadOutgoing = uploadOutgoing;
try {
+ await uploadOutgoing.call(this);
+ } finally {
+ _("Inserting local password");
let login = new LoginInfo("https://example.com", "", null, "username",
"password", "", "");
Services.logins.addLogin(login);
- } finally {
- failed = await applyIncomingBatch.call(this, records);
}
- return failed;
};
Svc.Obs.notify("weave:engine:start-tracking");
try {
let remoteRec = new LoginRec("passwords", "{765e3d6e-071d-d640-a83d-81a7eb62d3ed}");
remoteRec.formSubmitURL = "";
remoteRec.httpRealm = "";
@@ -135,50 +130,46 @@ add_task(async function test_passwords_c
equal(collection.count(), 1,
"New local password should not exist on server after first sync");
await sync_engine_and_validate_telem(engine, true);
strictEqual(Service.scheduler.globalScore, 0,
"Should not bump global score during second passwords sync");
- // ...But we still won't ever upload the entry to the server, since we
- // cleared the tracker after the first sync.
- equal(collection.count(), 1,
- "New local password won't exist on server after second sync");
+ equal(collection.count(), 2,
+ "New local password should exist on server after second sync");
} finally {
- engine._store.applyIncomingBatch = applyIncomingBatch;
+ engine._uploadOutgoing = uploadOutgoing;
await cleanup(engine, server);
}
});
add_task(async function test_prefs_change_during_sync() {
_("Ensure that we don't bump the score when applying prefs.");
const TEST_PREF = "services.sync.prefs.sync.test.duringSync";
enableValidationPrefs();
let engine = Service.engineManager.get("prefs");
let server = serverForEnginesWithKeys({"foo": "password"}, [engine]);
await SyncTestingInfrastructure(server);
let collection = server.user("foo").collection("prefs");
- let { applyIncomingBatch } = engine._store;
- engine._store.applyIncomingBatch = async function(records) {
- _("Updating local pref value");
- engine._store.applyIncomingBatch = applyIncomingBatch;
- let failed;
+ let uploadOutgoing = engine._uploadOutgoing;
+ engine._uploadOutgoing = async function() {
+ engine._uploadOutgoing = uploadOutgoing;
try {
+ await uploadOutgoing.call(this);
+ } finally {
+ _("Updating local pref value");
// Change the value of a synced pref.
Services.prefs.setCharPref(TEST_PREF, "hello");
- } finally {
- failed = await applyIncomingBatch.call(this, records);
}
- return failed;
};
Svc.Obs.notify("weave:engine:start-tracking");
try {
// All synced prefs are stored in a single record, so we'll only ever
// have one record on the server. This test just checks that we don't
// track or upload prefs changed during the sync.
@@ -199,54 +190,52 @@ add_task(async function test_prefs_chang
"Should not upload pref value changed during first sync");
await sync_engine_and_validate_telem(engine, true);
strictEqual(Service.scheduler.globalScore, 0,
"Should not bump global score during second prefs sync");
payloads = collection.payloads();
equal(payloads.length, 1,
"Should not upload multiple prefs records after second sync");
- equal(payloads[0].value[TEST_PREF], "world",
- "Should not upload changed pref value during second sync");
+ equal(payloads[0].value[TEST_PREF], "hello",
+ "Should upload changed pref value during second sync");
} finally {
- engine._store.applyIncomingBatch = applyIncomingBatch;
+ engine._uploadOutgoing = uploadOutgoing;
await cleanup(engine, server);
Services.prefs.clearUserPref(TEST_PREF);
}
});
add_task(async function test_forms_change_during_sync() {
_("Ensure that we don't bump the score when applying form records.");
enableValidationPrefs();
let engine = Service.engineManager.get("forms");
let server = serverForEnginesWithKeys({"foo": "password"}, [engine]);
await SyncTestingInfrastructure(server);
let collection = server.user("foo").collection("forms");
- let { applyIncomingBatch } = engine._store;
- engine._store.applyIncomingBatch = async function(records) {
- _("Inserting local form history entry");
- engine._store.applyIncomingBatch = applyIncomingBatch;
- let failed;
+ let uploadOutgoing = engine._uploadOutgoing;
+ engine._uploadOutgoing = async function() {
+ engine._uploadOutgoing = uploadOutgoing;
try {
+ await uploadOutgoing.call(this);
+ } finally {
+ _("Inserting local form history entry");
await new Promise(resolve => {
FormHistory.update([{
op: "add",
fieldname: "favoriteDrink",
value: "cocoa",
}], {
handleCompletion: resolve,
});
});
- } finally {
- failed = await applyIncomingBatch.call(this, records);
}
- return failed;
};
Svc.Obs.notify("weave:engine:start-tracking");
try {
// Add an existing remote form history entry. We shouldn't bump the score when
// we apply this record.
let remoteRec = new FormRec("forms", "Tl9dHgmJSR6FkyxS");
@@ -260,22 +249,20 @@ add_task(async function test_forms_chang
equal(collection.count(), 1,
"New local form should not exist on server after first sync");
await sync_engine_and_validate_telem(engine, true);
strictEqual(Service.scheduler.globalScore, 0,
"Should not bump global score during second forms sync");
- // ...But we still won't ever upload the entry to the server, since we
- // cleared the tracker after the first sync.
- equal(collection.count(), 1,
- "New local form won't exist on server after second sync");
+ equal(collection.count(), 2,
+ "New local form should exist on server after second sync");
} finally {
- engine._store.applyIncomingBatch = applyIncomingBatch;
+ engine._uploadOutgoing = uploadOutgoing;
await cleanup(engine, server);
}
});
add_task(async function test_bookmark_change_during_sync() {
_("Ensure that we track bookmark changes made during a sync.");
enableValidationPrefs();
@@ -296,31 +283,29 @@ add_task(async function test_bookmark_ch
let engine = Service.engineManager.get("bookmarks");
let server = serverForEnginesWithKeys({"foo": "password"}, [engine]);
await SyncTestingInfrastructure(server);
let collection = server.user("foo").collection("bookmarks");
let bmk3; // New child of Folder 1, created locally during sync.
- let { applyIncomingBatch } = engine._store;
- engine._store.applyIncomingBatch = async function(records) {
- _("Inserting bookmark into local store");
- engine._store.applyIncomingBatch = applyIncomingBatch;
- let failed;
+ let uploadOutgoing = engine._uploadOutgoing;
+ engine._uploadOutgoing = async function() {
+ engine._uploadOutgoing = uploadOutgoing;
try {
+ await uploadOutgoing.call(this);
+ } finally {
+ _("Inserting bookmark into local store");
bmk3 = await PlacesUtils.bookmarks.insert({
parentGuid: folder1.guid,
url: "https://mozilla.org/",
title: "Mozilla",
});
- } finally {
- failed = await applyIncomingBatch.call(this, records);
}
- return failed;
};
// New bookmarks that should be uploaded during the first sync.
let folder1 = await PlacesUtils.bookmarks.insert({
type: PlacesUtils.bookmarks.TYPE_FOLDER,
parentGuid: PlacesUtils.bookmarks.toolbarGuid,
title: "Folder 1",
});
@@ -343,18 +328,18 @@ add_task(async function test_bookmark_ch
{
// An existing record changed on the server that should not trigger
// another sync when applied.
let remoteBzBmk = new Bookmark("bookmarks", bzBmk.guid);
remoteBzBmk.bmkUri = "https://bugzilla.mozilla.org/";
remoteBzBmk.description = "New description";
remoteBzBmk.title = "Bugzilla";
remoteBzBmk.tags = ["new", "tags"];
- remoteBzBmk.parentName = "Bookmarks Toolbar";
- remoteBzBmk.parentid = "toolbar";
+ remoteBzBmk.parentName = "Bookmarks Menu";
+ remoteBzBmk.parentid = "menu";
collection.insert(bzBmk.guid, encryptPayload(remoteBzBmk.cleartext));
let remoteFolder = new BookmarkFolder("bookmarks", folder2_guid);
remoteFolder.title = "Folder 2";
remoteFolder.children = [bmk4_guid, tagQuery_guid];
remoteFolder.parentName = "Bookmarks Menu";
remoteFolder.parentid = "menu";
collection.insert(folder2_guid, encryptPayload(remoteFolder.cleartext));
@@ -391,17 +376,17 @@ add_task(async function test_bookmark_ch
collection.insert(bmk4_guid, encryptPayload(remoteTaggedBmk.cleartext));
}
await assertChildGuids(folder1.guid, [tbBmk.guid],
"Folder should have 1 child before first sync");
let pingsPromise = wait_for_pings(2);
- let changes = await engine.pullNewChanges();
+ let changes = await PlacesSyncUtils.bookmarks.pullChanges();
deepEqual(Object.keys(changes).sort(), [
folder1.guid,
tbBmk.guid,
"menu",
"mobile",
"toolbar",
"unfiled",
].sort(), "Should track bookmark and folder created before first sync");
@@ -424,33 +409,33 @@ add_task(async function test_bookmark_ch
ok(bmk3, "Should insert bookmark during first sync to simulate change");
ok(collection.wbo(bmk3.guid),
"Changed bookmark should be uploaded after follow-up sync");
let bmk2 = await PlacesUtils.bookmarks.fetch({
guid: bmk2_guid,
});
ok(bmk2, "Remote bookmark should be applied during first sync");
- await assertChildGuids(folder1.guid, [tbBmk.guid, bmk3.guid, bmk2_guid],
+ await assertChildGuids(folder1.guid, [tbBmk.guid, bmk2_guid, bmk3.guid],
"Folder 1 should have 3 children after first sync");
await assertChildGuids(folder2_guid, [bmk4_guid, tagQuery_guid],
"Folder 2 should have 2 children after first sync");
let taggedURIs = PlacesUtils.tagging.getURIsForTag("taggy");
equal(taggedURIs.length, 1, "Should have 1 tagged URI");
equal(taggedURIs[0].spec, "https://example.org/",
"Synced tagged bookmark should appear in tagged URI list");
- changes = await engine.pullNewChanges();
+ changes = await PlacesSyncUtils.bookmarks.pullChanges();
deepEqual(changes, {},
"Should have already uploaded changes in follow-up sync");
// First ping won't include validation data, since we've changed bookmarks
// and `canValidate` will indicate it can't proceed.
let engineData = pings.map(p =>
p.syncs[0].engines.find(e => e.name == "bookmarks")
);
ok(!engineData[0].validation, "Should not validate after first sync");
ok(engineData[1].validation, "Should validate after second sync");
} finally {
- engine._store.applyIncomingBatch = applyIncomingBatch;
+ engine._uploadOutgoing = uploadOutgoing;
await cleanup(engine, server);
}
});