Bug 1337993 - Ensure we mark all current bookmarks for reupload when bookmark engine enabled state changes. r=kitcambridge

MozReview-Commit-ID: 4gOmqrzUr77

--HG--
extra : rebase_source : ee645449c2bb08cc13a6b9040a0bbdd506d5c0a3
This commit is contained in:
Thom Chiovoloni 2017-02-13 14:28:06 -05:00
parent df85eed31c
commit c396116b69
3 changed files with 107 additions and 2 deletions

View File

@ -567,8 +567,8 @@ BookmarksEngine.prototype = {
this._noteDeletedId(id);
},
resetClient() {
SyncEngine.prototype.resetClient.call(this);
_resetClient() {
SyncEngine.prototype._resetClient.call(this);
Async.promiseSpinningly(PlacesSyncUtils.bookmarks.reset());
},

View File

@ -0,0 +1,104 @@
/* Any copyright is dedicated to the Public Domain.
http://creativecommons.org/publicdomain/zero/1.0/ */
Cu.import("resource://gre/modules/PlacesUtils.jsm");
Cu.import("resource://gre/modules/PlacesSyncUtils.jsm");
Cu.import("resource://gre/modules/BookmarkJSONUtils.jsm");
Cu.import("resource://gre/modules/Log.jsm");
Cu.import("resource://services-sync/constants.js");
Cu.import("resource://services-sync/engines.js");
Cu.import("resource://services-sync/engines/bookmarks.js");
Cu.import("resource://services-sync/service.js");
Cu.import("resource://services-sync/util.js");
Cu.import("resource://testing-common/services/sync/utils.js");
initTestLogging("Trace");
Service.engineManager.register(BookmarksEngine);
function serverForFoo(engine) {
// The bookmarks engine *always* tracks changes, meaning we might try
// and sync due to the bookmarks we ourselves create! Worse, because we
// do an engine sync only, there's no locking - so we end up with multiple
// syncs running. Neuter that by making the threshold very large.
Service.scheduler.syncThreshold = 10000000;
let clientsEngine = Service.clientsEngine;
return serverForUsers({"foo": "password"}, {
meta: {
global: {
syncID: Service.syncID,
storageVersion: STORAGE_VERSION,
engines: {
clients: {
version: clientsEngine.version,
syncID: clientsEngine.syncID,
},
bookmarks: {
version: engine.version,
syncID: engine.syncID,
},
},
},
},
crypto: {
keys: encryptPayload({
id: "keys",
// Generate a fake default key bundle to avoid resetting the client
// before the first sync.
default: [
Svc.Crypto.generateRandomKey(),
Svc.Crypto.generateRandomKey(),
],
}),
},
bookmarks: {}
});
}
// A stored reference to the collection won't be valid after disabling.
function getBookmarkWBO(server, guid) {
let coll = server.user("foo").collection("bookmarks");
if (!coll) {
return null;
}
return coll.wbo(guid);
}
add_task(async function test_decline_undecline() {
let engine = Service.engineManager.get("bookmarks");
let server = serverForFoo(engine);
await SyncTestingInfrastructure(server);
try {
let bzGuid = "999999999999";
await PlacesSyncUtils.bookmarks.insert({
kind: PlacesSyncUtils.bookmarks.KINDS.BOOKMARK,
syncId: bzGuid,
parentSyncId: "menu",
url: "https://bugzilla.mozilla.org",
});
ok(!getBookmarkWBO(server, bzGuid), "Shouldn't have been uploaded yet");
Service.sync();
ok(getBookmarkWBO(server, bzGuid), "Should be present on server");
engine.enabled = false;
Service.sync();
ok(!getBookmarkWBO(server, bzGuid), "Shouldn't be present on server anymore");
engine.enabled = true;
Service.sync();
ok(getBookmarkWBO(server, bzGuid), "Should be present on server again");
} finally {
await PlacesSyncUtils.bookmarks.reset();
await promiseStopServer(server);
}
});
function run_test() {
initTestLogging("Trace");
generateNewKeys(Service.collectionKeys);
run_next_test();
}

View File

@ -138,6 +138,7 @@ tags = addons
[test_bookmark_record.js]
[test_bookmark_smart_bookmarks.js]
[test_bookmark_store.js]
[test_bookmark_decline_undecline.js]
# Too many intermittent "ASSERTION: thread pool wasn't shutdown: '!mPool'" (bug 804479)
skip-if = debug
[test_bookmark_tracker.js]