Skip to content

Commit

Permalink
Bug 1838974 - Bookmarks engine roundtrips data it doesn't know about …
Browse files Browse the repository at this point in the history
…r=markh,lina,sync-reviewers

Differential Revision: https://phabricator.services.mozilla.com/D181593
  • Loading branch information
skhamis committed Jul 7, 2023
1 parent 2cd140a commit 525249f
Show file tree
Hide file tree
Showing 7 changed files with 476 additions and 24 deletions.
121 changes: 121 additions & 0 deletions services/sync/tests/unit/test_bookmark_engine.js
Original file line number Diff line number Diff line change
Expand Up @@ -1389,3 +1389,124 @@ add_bookmark_test(async function test_livemarks(engine) {
await cleanup(engine, server);
}
});

add_bookmark_test(async function test_unknown_fields(engine) {
let store = engine._store;
let server = await serverForFoo(engine);
await SyncTestingInfrastructure(server);
let collection = server.user("foo").collection("bookmarks");
try {
let folder1 = await PlacesUtils.bookmarks.insert({
parentGuid: PlacesUtils.bookmarks.toolbarGuid,
type: PlacesUtils.bookmarks.TYPE_FOLDER,
title: "Folder 1",
});
let bmk1 = await PlacesUtils.bookmarks.insert({
parentGuid: folder1.guid,
url: "http://getfirefox.com/",
title: "Get Firefox!",
});
let bmk2 = await PlacesUtils.bookmarks.insert({
parentGuid: folder1.guid,
url: "http://getthunderbird.com/",
title: "Get Thunderbird!",
});
let toolbar_record = await store.createRecord("toolbar");
collection.insert("toolbar", encryptPayload(toolbar_record.cleartext));

let folder1_record_without_unknown_fields = await store.createRecord(
folder1.guid
);
collection.insert(
folder1.guid,
encryptPayload(folder1_record_without_unknown_fields.cleartext)
);

// First bookmark record has an unknown string field
let bmk1_record = await store.createRecord(bmk1.guid);
console.log("bmk1_record: ", bmk1_record);
bmk1_record.cleartext.unknownStrField =
"an unknown field from another client";
collection.insert(bmk1.guid, encryptPayload(bmk1_record.cleartext));

// Second bookmark record as an unknown object field
let bmk2_record = await store.createRecord(bmk2.guid);
bmk2_record.cleartext.unknownObjField = {
name: "an unknown object from another client",
};
collection.insert(bmk2.guid, encryptPayload(bmk2_record.cleartext));

// Sync the two bookmarks
await sync_engine_and_validate_telem(engine, true);

// Add a folder could also have an unknown field
let folder1_record = await store.createRecord(folder1.guid);
folder1_record.cleartext.unknownStrField =
"a folder could also have an unknown field!";
collection.insert(folder1.guid, encryptPayload(folder1_record.cleartext));

// sync the new updates
await engine.setLastSync(1);
await sync_engine_and_validate_telem(engine, true);

let payloads = collection.payloads();
// Validate the server has the unknown fields at the top level (and now unknownFields)
let server_bmk1 = payloads.find(payload => payload.id == bmk1.guid);
deepEqual(
server_bmk1.unknownStrField,
"an unknown field from another client",
"unknown fields correctly on the record"
);
Assert.equal(server_bmk1.unknownFields, null);

// Check that the mirror table has unknown fields
let db = await PlacesUtils.promiseDBConnection();
let rows = await db.executeCached(
`
SELECT guid, title, unknownFields from items WHERE guid IN
(:bmk1, :bmk2, :folder1)`,
{ bmk1: bmk1.guid, bmk2: bmk2.guid, folder1: folder1.guid }
);
// We should have 3 rows that came from the server
Assert.equal(rows.length, 3);

// Bookmark 1 - unknown string field
let remote_bmk1 = rows.find(
row => row.getResultByName("guid") == bmk1.guid
);
Assert.equal(remote_bmk1.getResultByName("title"), "Get Firefox!");
deepEqual(JSON.parse(remote_bmk1.getResultByName("unknownFields")), {
unknownStrField: "an unknown field from another client",
});

// Bookmark 2 - unknown object field
let remote_bmk2 = rows.find(
row => row.getResultByName("guid") == bmk2.guid
);
Assert.equal(remote_bmk2.getResultByName("title"), "Get Thunderbird!");
deepEqual(JSON.parse(remote_bmk2.getResultByName("unknownFields")), {
unknownObjField: {
name: "an unknown object from another client",
},
});

// Folder with unknown field

// check the server still has the unknown field
deepEqual(
payloads.find(payload => payload.id == folder1.guid).unknownStrField,
"a folder could also have an unknown field!",
"Server still has the unknown field"
);

let remote_folder = rows.find(
row => row.getResultByName("guid") == folder1.guid
);
Assert.equal(remote_folder.getResultByName("title"), "Folder 1");
deepEqual(JSON.parse(remote_folder.getResultByName("unknownFields")), {
unknownStrField: "a folder could also have an unknown field!",
});
} finally {
await cleanup(engine, server);
}
});
Loading

0 comments on commit 525249f

Please sign in to comment.