Skip to content

Commit

Permalink
Add tests for Virtual "Other Bookmarks" mapping
Browse files Browse the repository at this point in the history
  • Loading branch information
darkdh committed Feb 8, 2020
1 parent 1d9024a commit dbc8ae5
Show file tree
Hide file tree
Showing 7 changed files with 392 additions and 22 deletions.
11 changes: 7 additions & 4 deletions components/brave_sync/brave_profile_sync_service_impl.cc
Original file line number Diff line number Diff line change
Expand Up @@ -804,12 +804,15 @@ void BraveProfileSyncServiceImpl::LoadSyncEntityInfo(

bool BraveProfileSyncServiceImpl::IsOtherBookmarksFolder(
const jslib::SyncRecord* record) const {
auto bookmark = record->GetBookmark();
if (!bookmark.isFolder)
return false;

std::string other_node_object_id;
if (model_->other_node()->GetMetaInfo("object_id", &other_node_object_id) &&
record->objectId == other_node_object_id)
return true;

auto bookmark = record->GetBookmark();
if (bookmark.order == tools::kOtherNodeOrder &&
bookmark.site.title == tools::GetOtherNodeName() &&
bookmark.site.customTitle == tools::GetOtherNodeName()) {
Expand All @@ -823,14 +826,14 @@ void BraveProfileSyncServiceImpl::ProcessOtherBookmarksFolder(
const jslib::SyncRecord* record,
bool* pass_to_syncer) {
std::string other_node_object_id;
// Save object_id for late joined desktop to catch up with currecnt id
// Save object_id for late joined desktop to catch up with current id
// iteration
if (!model_->other_node()->GetMetaInfo("object_id", &other_node_object_id) &&
record->action == jslib::SyncRecord::Action::A_CREATE) {
tools::AsMutable(model_->other_node())->SetMetaInfo("object_id",
record->objectId);
} else {
// If late joined desktop has bookmarks in other_node before joing sync
// If late joined desktop has bookmarks in other_node before joining sync
// chain
if (other_node_object_id != record->objectId &&
other_node_object_id ==
Expand Down Expand Up @@ -874,7 +877,7 @@ void BraveProfileSyncServiceImpl::ProcessOtherBookmarksFolder(

auto record_to_send = SyncRecord::Clone(*sync_record);

// Append chnages to remote records
// Append changes to remote records
if (!pending_received_records_)
pending_received_records_ = std::make_unique<RecordsList>();
pending_received_records_->push_back(std::move(sync_record));
Expand Down
15 changes: 15 additions & 0 deletions components/brave_sync/brave_profile_sync_service_impl.h
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,11 @@ FORWARD_DECLARE_TEST(BraveSyncServiceTest, SetThisDeviceCreatedTime);
FORWARD_DECLARE_TEST(BraveSyncServiceTest, InitialFetchesStartWithZero);
FORWARD_DECLARE_TEST(BraveSyncServiceTest, DeviceIdV2Migration);
FORWARD_DECLARE_TEST(BraveSyncServiceTest, DeviceIdV2MigrationDupDeviceId);
FORWARD_DECLARE_TEST(BraveSyncServiceTest, IsOtherBookmarksFolder);
FORWARD_DECLARE_TEST(BraveSyncServiceTest, ProcessOtherBookmarksFolder);
FORWARD_DECLARE_TEST(BraveSyncServiceTest, ProcessOtherBookmarksChildren);
FORWARD_DECLARE_TEST(BraveSyncServiceTest, CheckOtherBookmarkRecord);
FORWARD_DECLARE_TEST(BraveSyncServiceTest, CheckOtherBookmarkChildRecord);

class BraveSyncServiceTest;

Expand Down Expand Up @@ -168,6 +173,16 @@ class BraveProfileSyncServiceImpl
FRIEND_TEST_ALL_PREFIXES(::BraveSyncServiceTest, DeviceIdV2Migration);
FRIEND_TEST_ALL_PREFIXES(::BraveSyncServiceTest,
DeviceIdV2MigrationDupDeviceId);
FRIEND_TEST_ALL_PREFIXES(::BraveSyncServiceTest,
IsOtherBookmarksFolder);
FRIEND_TEST_ALL_PREFIXES(::BraveSyncServiceTest,
ProcessOtherBookmarksFolder);
FRIEND_TEST_ALL_PREFIXES(::BraveSyncServiceTest,
ProcessOtherBookmarksChildren);
FRIEND_TEST_ALL_PREFIXES(::BraveSyncServiceTest,
CheckOtherBookmarkRecord);
FRIEND_TEST_ALL_PREFIXES(::BraveSyncServiceTest,
CheckOtherBookmarkChildRecord);

friend class ::BraveSyncServiceTest;

Expand Down
Loading

0 comments on commit dbc8ae5

Please sign in to comment.