Commit acb98580 authored by Victor Hugo Vianna Silva's avatar Victor Hugo Vianna Silva Committed by Commit Bot

Remove expectations on merge deltas from syncable services unit tests

A preparation for https://crrev.com/c/2087914. Expectations on the
values of SyncMergeResult::num_items_{added/deleted/...} are removed.
Coverage for the sync merge logic is still present, since the tests
already verified it by mean of other checks.

The CL complements such pre-existing checks with checks on the initial
and final size of the local model. One of the implementations of
GetAllSyncData that was removed in crrev.com/c/2083455 is re-added to
enable this. It is suffixed with ForTesting as with all other cases in
crrev.com/c/2083455.

Change-Id: If83c977b8e5dac6279b3fd7fc7517dc3d2dbc1f5
Bug: 1057577
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2091346
Commit-Queue: Victor Vianna <victorvianna@google.com>
Reviewed-by: default avatarMarc Treib <treib@chromium.org>
Cr-Commit-Position: refs/heads/master@{#758773}
parent 18682c2c
......@@ -204,11 +204,9 @@ TEST_F(SupervisedUserSettingsServiceTest, ProcessSplitSetting) {
TEST_F(SupervisedUserSettingsServiceTest, Merge) {
syncer::SyncMergeResult result = StartSyncing(syncer::SyncDataList());
EXPECT_EQ(0, result.num_items_before_association());
EXPECT_EQ(0, result.num_items_added());
EXPECT_EQ(0, result.num_items_modified());
EXPECT_EQ(0, result.num_items_deleted());
EXPECT_EQ(0, result.num_items_after_association());
EXPECT_TRUE(settings_service_
.GetAllSyncDataForTesting(syncer::SUPERVISED_USER_SETTINGS)
.empty());
ASSERT_TRUE(settings_);
const base::Value* value = nullptr;
......@@ -234,11 +232,10 @@ TEST_F(SupervisedUserSettingsServiceTest, Merge) {
it.value()));
}
result = StartSyncing(sync_data);
EXPECT_EQ(0, result.num_items_before_association());
EXPECT_EQ(3, result.num_items_added());
EXPECT_EQ(0, result.num_items_modified());
EXPECT_EQ(0, result.num_items_deleted());
EXPECT_EQ(3, result.num_items_after_association());
EXPECT_EQ(3u,
settings_service_
.GetAllSyncDataForTesting(syncer::SUPERVISED_USER_SETTINGS)
.size());
settings_service_.StopSyncing(syncer::SUPERVISED_USER_SETTINGS);
}
......@@ -264,11 +261,10 @@ TEST_F(SupervisedUserSettingsServiceTest, Merge) {
it.value()));
}
result = StartSyncing(sync_data);
EXPECT_EQ(6, result.num_items_before_association());
EXPECT_EQ(0, result.num_items_added());
EXPECT_EQ(1, result.num_items_modified());
EXPECT_EQ(2, result.num_items_deleted());
EXPECT_EQ(4, result.num_items_after_association());
EXPECT_EQ(4u,
settings_service_
.GetAllSyncDataForTesting(syncer::SUPERVISED_USER_SETTINGS)
.size());
}
}
......
......@@ -213,6 +213,29 @@ void SupervisedUserWhitelistService::StopSyncing(syncer::ModelType type) {
DCHECK_EQ(syncer::SUPERVISED_USER_WHITELISTS, type);
}
syncer::SyncDataList SupervisedUserWhitelistService::GetAllSyncDataForTesting(
syncer::ModelType type) const {
syncer::SyncDataList sync_data;
const base::DictionaryValue* whitelists =
prefs_->GetDictionary(prefs::kSupervisedUserWhitelists);
for (base::DictionaryValue::Iterator it(*whitelists); !it.IsAtEnd();
it.Advance()) {
const std::string& id = it.key();
const base::DictionaryValue* dict = nullptr;
it.value().GetAsDictionary(&dict);
std::string name;
bool result = dict->GetString(kName, &name);
DCHECK(result);
sync_pb::EntitySpecifics specifics;
sync_pb::ManagedUserWhitelistSpecifics* whitelist =
specifics.mutable_managed_user_whitelist();
whitelist->set_id(id);
whitelist->set_name(name);
sync_data.push_back(syncer::SyncData::CreateLocalData(id, name, specifics));
}
return sync_data;
}
syncer::SyncError SupervisedUserWhitelistService::ProcessSyncChanges(
const base::Location& from_here,
const syncer::SyncChangeList& change_list) {
......
......@@ -89,6 +89,8 @@ class SupervisedUserWhitelistService : public syncer::SyncableService {
const base::Location& from_here,
const syncer::SyncChangeList& change_list) override;
syncer::SyncDataList GetAllSyncDataForTesting(syncer::ModelType type) const;
private:
// The following methods handle whitelist additions, updates and removals,
// usually coming from Sync.
......
......@@ -169,16 +169,17 @@ class SupervisedUserWhitelistServiceTest : public testing::Test {
TEST_F(SupervisedUserWhitelistServiceTest, MergeEmpty) {
service_->Init();
ASSERT_TRUE(
service_->GetAllSyncDataForTesting(syncer::SUPERVISED_USER_WHITELISTS)
.empty());
syncer::SyncMergeResult result = service_->MergeDataAndStartSyncing(
syncer::SUPERVISED_USER_WHITELISTS, syncer::SyncDataList(),
std::unique_ptr<syncer::SyncChangeProcessor>(),
std::unique_ptr<syncer::SyncErrorFactory>());
EXPECT_TRUE(
service_->GetAllSyncDataForTesting(syncer::SUPERVISED_USER_WHITELISTS)
.empty());
EXPECT_FALSE(result.error().IsSet());
EXPECT_EQ(0, result.num_items_added());
EXPECT_EQ(0, result.num_items_modified());
EXPECT_EQ(0, result.num_items_deleted());
EXPECT_EQ(0, result.num_items_before_association());
EXPECT_EQ(0, result.num_items_after_association());
EXPECT_EQ(0u, installer_->registered_whitelists().size());
}
......@@ -214,16 +215,17 @@ TEST_F(SupervisedUserWhitelistServiceTest, MergeExisting) {
initial_data.push_back(
SupervisedUserWhitelistService::CreateWhitelistSyncData(
"cccc", "Whitelist C"));
ASSERT_EQ(
2u, service_->GetAllSyncDataForTesting(syncer::SUPERVISED_USER_WHITELISTS)
.size());
syncer::SyncMergeResult result = service_->MergeDataAndStartSyncing(
syncer::SUPERVISED_USER_WHITELISTS, initial_data,
std::unique_ptr<syncer::SyncChangeProcessor>(),
std::unique_ptr<syncer::SyncErrorFactory>());
EXPECT_EQ(
2u, service_->GetAllSyncDataForTesting(syncer::SUPERVISED_USER_WHITELISTS)
.size());
EXPECT_FALSE(result.error().IsSet());
EXPECT_EQ(1, result.num_items_added());
EXPECT_EQ(1, result.num_items_modified());
EXPECT_EQ(1, result.num_items_deleted());
EXPECT_EQ(2, result.num_items_before_association());
EXPECT_EQ(2, result.num_items_after_association());
// Whitelist A (which was previously ready) should be removed now, and
// whitelist B was never ready.
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment