in components/places/src/bookmark_sync/engine.rs [4257:4426]
fn test_reconcile_sync_metadata() -> anyhow::Result<()> {
let api = new_mem_api();
let writer = api.open_connection(ConnectionType::ReadWrite)?;
let local_modified = Timestamp::from(Timestamp::now().as_millis() - 5000);
let remote_modified = local_modified.as_millis() as f64 / 1000f64;
insert_local_json_tree(
&writer,
json!({
"guid": &BookmarkRootGuid::Menu.as_guid(),
"children": [{
// this folder is going to reconcile exactly
"guid": "folderAAAAAA",
"type": BookmarkType::Folder as u8,
"title": "A",
"date_added": local_modified,
"last_modified": local_modified,
"children": [{
"guid": "bookmarkBBBB",
"title": "B",
"url": "http://example.com/b",
"date_added": local_modified,
"last_modified": local_modified,
}]
}, {
// this folder's existing child isn't on the server (so will be
// outgoing) and also will take a new child from the server.
"guid": "folderCCCCCC",
"type": BookmarkType::Folder as u8,
"title": "C",
"date_added": local_modified,
"last_modified": local_modified,
"children": [{
"guid": "bookmarkEEEE",
"title": "E",
"url": "http://example.com/e",
"date_added": local_modified,
"last_modified": local_modified,
}]
}, {
// This bookmark is going to take the remote title.
"guid": "bookmarkFFFF",
"title": "f",
"url": "http://example.com/f",
"date_added": local_modified,
"last_modified": local_modified,
}],
}),
);
let outgoing = apply_incoming(
&api,
ServerTimestamp::from_float_seconds(remote_modified),
json!([{
"id": "menu",
"type": "folder",
"parentid": "places",
"parentName": "",
"title": "menu",
"children": ["folderAAAAAA", "folderCCCCCC", "bookmarkFFFF"],
"dateAdded": local_modified.as_millis(),
"modified": remote_modified,
}, {
"id": "folderAAAAAA",
"type": "folder",
"parentid": "menu",
"parentName": "menu",
"title": "A",
"children": ["bookmarkBBBB"],
"dateAdded": local_modified.as_millis(),
"modified": remote_modified,
}, {
"id": "bookmarkBBBB",
"type": "bookmark",
"parentid": "folderAAAAAA",
"parentName": "A",
"title": "B",
"bmkUri": "http://example.com/b",
"dateAdded": local_modified.as_millis(),
"modified": remote_modified,
}, {
"id": "folderCCCCCC",
"type": "folder",
"parentid": "menu",
"parentName": "menu",
"title": "C",
"children": ["bookmarkDDDD"],
"dateAdded": local_modified.as_millis(),
"modified": remote_modified,
}, {
"id": "bookmarkDDDD",
"type": "bookmark",
"parentid": "folderCCCCCC",
"parentName": "C",
"title": "D",
"bmkUri": "http://example.com/d",
"dateAdded": local_modified.as_millis(),
"modified": remote_modified,
}, {
"id": "bookmarkFFFF",
"type": "bookmark",
"parentid": "menu",
"parentName": "menu",
"title": "F",
"bmkUri": "http://example.com/f",
"dateAdded": local_modified.as_millis(),
"modified": remote_modified + 5f64,
},]),
);
// Assert the tree is correct even though that's not really the point
// of this test.
assert_local_json_tree(
&writer,
&BookmarkRootGuid::Menu.as_guid(),
json!({
"guid": &BookmarkRootGuid::Menu.as_guid(),
"children": [{
// this folder is going to reconcile exactly
"guid": "folderAAAAAA",
"type": BookmarkType::Folder as u8,
"title": "A",
"children": [{
"guid": "bookmarkBBBB",
"title": "B",
"url": "http://example.com/b",
}]
}, {
"guid": "folderCCCCCC",
"type": BookmarkType::Folder as u8,
"title": "C",
"children": [{
"guid": "bookmarkDDDD",
"title": "D",
"url": "http://example.com/d",
},{
"guid": "bookmarkEEEE",
"title": "E",
"url": "http://example.com/e",
}]
}, {
"guid": "bookmarkFFFF",
"title": "F",
"url": "http://example.com/f",
}],
}),
);
// After application everything should have SyncStatus::Normal and
// a change counter of zero.
for guid in &[
"folderAAAAAA",
"bookmarkBBBB",
"folderCCCCCC",
"bookmarkDDDD",
"bookmarkFFFF",
] {
let bm = get_raw_bookmark(&writer, &guid.into())
.expect("must work")
.expect("must exist");
assert_eq!(bm._sync_status, SyncStatus::Normal, "{}", guid);
assert_eq!(bm._sync_change_counter, 0, "{}", guid);
}
// And bookmarkEEEE wasn't on the server, so should be outgoing, and
// it's parent too.
assert!(outgoing.contains(&"bookmarkEEEE".into()));
assert!(outgoing.contains(&"folderCCCCCC".into()));
Ok(())
}