Commit b34bc113 authored by Himanshu Jaju's avatar Himanshu Jaju Committed by Commit Bot

Use SyncMode to decide device name

For full sync we use the PII name, but for transport only mode we use
the device's model name as client name.

Bug: 1009454
Change-Id: I4a31e012ad81715af91b1dcaf782a4f0466b6f06
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1852092
Commit-Queue: Himanshu Jaju <himanshujaju@chromium.org>
Reviewed-by: default avatarMikel Astiz <mastiz@chromium.org>
Reviewed-by: default avatarAlex Chau <alexchau@chromium.org>
Cr-Commit-Position: refs/heads/master@{#705955}
parent 4de4e88f
...@@ -202,6 +202,8 @@ void DeviceInfoSyncBridge::OnSyncStarting( ...@@ -202,6 +202,8 @@ void DeviceInfoSyncBridge::OnSyncStarting(
device_info_prefs_->GarbageCollectExpiredCacheGuids(); device_info_prefs_->GarbageCollectExpiredCacheGuids();
// Add the cache guid to the local prefs. // Add the cache guid to the local prefs.
device_info_prefs_->AddLocalCacheGuid(local_cache_guid_); device_info_prefs_->AddLocalCacheGuid(local_cache_guid_);
// SyncMode determines the client name in GetLocalClientName().
sync_mode_ = request.sync_mode;
} }
std::unique_ptr<MetadataChangeList> std::unique_ptr<MetadataChangeList>
...@@ -216,9 +218,8 @@ base::Optional<ModelError> DeviceInfoSyncBridge::MergeSyncData( ...@@ -216,9 +218,8 @@ base::Optional<ModelError> DeviceInfoSyncBridge::MergeSyncData(
DCHECK(all_data_.empty()); DCHECK(all_data_.empty());
DCHECK(!local_cache_guid_.empty()); DCHECK(!local_cache_guid_.empty());
local_device_info_provider_->Initialize(local_cache_guid_, local_device_info_provider_->Initialize(
local_personalizable_device_name_, local_cache_guid_, GetLocalClientName(), local_hardware_info_);
local_hardware_info_);
std::unique_ptr<WriteBatch> batch = store_->CreateWriteBatch(); std::unique_ptr<WriteBatch> batch = store_->CreateWriteBatch();
for (const auto& change : entity_data) { for (const auto& change : entity_data) {
...@@ -397,6 +398,22 @@ bool DeviceInfoSyncBridge::DeleteSpecifics(const std::string& guid, ...@@ -397,6 +398,22 @@ bool DeviceInfoSyncBridge::DeleteSpecifics(const std::string& guid,
} }
} }
std::string DeviceInfoSyncBridge::GetLocalClientName() const {
// |sync_mode_| may not be ready when this function is called.
if (!sync_mode_) {
auto device_it = all_data_.find(local_cache_guid_);
if (device_it != all_data_.end()) {
return device_it->second->client_name();
}
}
if (sync_mode_ == SyncMode::kFull) {
return local_personalizable_device_name_;
}
return local_hardware_info_.model;
}
void DeviceInfoSyncBridge::OnStoreCreated( void DeviceInfoSyncBridge::OnStoreCreated(
const base::Optional<syncer::ModelError>& error, const base::Optional<syncer::ModelError>& error,
std::unique_ptr<ModelTypeStore> store) { std::unique_ptr<ModelTypeStore> store) {
...@@ -498,9 +515,8 @@ void DeviceInfoSyncBridge::OnReadAllMetadata( ...@@ -498,9 +515,8 @@ void DeviceInfoSyncBridge::OnReadAllMetadata(
// If sync already enabled (usual case without data corruption), we can // If sync already enabled (usual case without data corruption), we can
// initialize the provider immediately. // initialize the provider immediately.
local_cache_guid_ = local_cache_guid_in_metadata; local_cache_guid_ = local_cache_guid_in_metadata;
local_device_info_provider_->Initialize(local_cache_guid_, local_device_info_provider_->Initialize(
local_personalizable_device_name_, local_cache_guid_, GetLocalClientName(), local_hardware_info_);
local_hardware_info_);
// This probably isn't strictly needed, but in case the cache_guid has changed // This probably isn't strictly needed, but in case the cache_guid has changed
// we save the new one to prefs. // we save the new one to prefs.
......
...@@ -17,6 +17,7 @@ ...@@ -17,6 +17,7 @@
#include "base/system/sys_info.h" #include "base/system/sys_info.h"
#include "base/time/time.h" #include "base/time/time.h"
#include "base/timer/timer.h" #include "base/timer/timer.h"
#include "components/sync/base/sync_mode.h"
#include "components/sync/model/model_error.h" #include "components/sync/model/model_error.h"
#include "components/sync/model/model_type_store.h" #include "components/sync/model/model_type_store.h"
#include "components/sync/model/model_type_sync_bridge.h" #include "components/sync/model/model_type_sync_bridge.h"
...@@ -96,6 +97,11 @@ class DeviceInfoSyncBridge : public ModelTypeSyncBridge, ...@@ -96,6 +97,11 @@ class DeviceInfoSyncBridge : public ModelTypeSyncBridge,
bool DeleteSpecifics(const std::string& tag, bool DeleteSpecifics(const std::string& tag,
ModelTypeStore::WriteBatch* batch); ModelTypeStore::WriteBatch* batch);
// Returns the device name based on |sync_mode_|. For transport only mode,
// the device model name is returned. For full sync mode,
// |local_personalizable_device_name_| is returned.
std::string GetLocalClientName() const;
// Notify all registered observers. // Notify all registered observers.
void NotifyObservers(); void NotifyObservers();
...@@ -145,6 +151,7 @@ class DeviceInfoSyncBridge : public ModelTypeSyncBridge, ...@@ -145,6 +151,7 @@ class DeviceInfoSyncBridge : public ModelTypeSyncBridge,
std::string local_personalizable_device_name_; std::string local_personalizable_device_name_;
ClientIdToSpecifics all_data_; ClientIdToSpecifics all_data_;
base::SysInfo::HardwareInfo local_hardware_info_; base::SysInfo::HardwareInfo local_hardware_info_;
base::Optional<SyncMode> sync_mode_;
// Registered observers, not owned. // Registered observers, not owned.
base::ObserverList<Observer, true>::Unchecked observers_; base::ObserverList<Observer, true>::Unchecked observers_;
......
...@@ -11,6 +11,7 @@ ...@@ -11,6 +11,7 @@
#include "base/bind.h" #include "base/bind.h"
#include "base/run_loop.h" #include "base/run_loop.h"
#include "base/strings/stringprintf.h" #include "base/strings/stringprintf.h"
#include "base/test/bind_test_util.h"
#include "base/test/simple_test_clock.h" #include "base/test/simple_test_clock.h"
#include "base/test/task_environment.h" #include "base/test/task_environment.h"
#include "components/prefs/testing_pref_service.h" #include "components/prefs/testing_pref_service.h"
...@@ -25,6 +26,7 @@ ...@@ -25,6 +26,7 @@
#include "components/sync/protocol/model_type_state.pb.h" #include "components/sync/protocol/model_type_state.pb.h"
#include "components/sync/test/test_matchers.h" #include "components/sync/test/test_matchers.h"
#include "components/sync_device_info/device_info_prefs.h" #include "components/sync_device_info/device_info_prefs.h"
#include "components/sync_device_info/local_device_info_util.h"
#include "testing/gtest/include/gtest/gtest.h" #include "testing/gtest/include/gtest/gtest.h"
namespace syncer { namespace syncer {
...@@ -140,6 +142,18 @@ std::string SigninScopedDeviceIdForSuffix(int suffix) { ...@@ -140,6 +142,18 @@ std::string SigninScopedDeviceIdForSuffix(int suffix) {
return base::StringPrintf("signin scoped device id %d", suffix); return base::StringPrintf("signin scoped device id %d", suffix);
} }
base::SysInfo::HardwareInfo GetLocalHardwareInfoBlocking() {
base::RunLoop run_loop;
base::SysInfo::HardwareInfo info;
base::SysInfo::GetHardwareInfo(base::BindLambdaForTesting(
[&](base::SysInfo::HardwareInfo hardware_info) {
info = std::move(hardware_info);
run_loop.Quit();
}));
run_loop.Run();
return info;
}
std::string ModelForSuffix(int suffix) { std::string ModelForSuffix(int suffix) {
return base::StringPrintf("model %d", suffix); return base::StringPrintf("model %d", suffix);
} }
...@@ -148,13 +162,6 @@ std::string ManufacturerForSuffix(int suffix) { ...@@ -148,13 +162,6 @@ std::string ManufacturerForSuffix(int suffix) {
return base::StringPrintf("manufacturer %d", suffix); return base::StringPrintf("manufacturer %d", suffix);
} }
base::SysInfo::HardwareInfo HardwareInfoForSuffix(int suffix) {
base::SysInfo::HardwareInfo info;
info.manufacturer = ManufacturerForSuffix(suffix);
info.model = ModelForSuffix(suffix);
return info;
}
std::string SharingFcmTokenForSuffix(int suffix) { std::string SharingFcmTokenForSuffix(int suffix) {
return base::StringPrintf("sharing fcm token %d", suffix); return base::StringPrintf("sharing fcm token %d", suffix);
} }
...@@ -173,9 +180,10 @@ sync_pb::SharingSpecificFields::EnabledFeatures SharingEnabledFeaturesForSuffix( ...@@ -173,9 +180,10 @@ sync_pb::SharingSpecificFields::EnabledFeatures SharingEnabledFeaturesForSuffix(
: sync_pb::SharingSpecificFields::SHARED_CLIPBOARD; : sync_pb::SharingSpecificFields::SHARED_CLIPBOARD;
} }
DataTypeActivationRequest TestDataTypeActivationRequest() { DataTypeActivationRequest TestDataTypeActivationRequest(SyncMode sync_mode) {
DataTypeActivationRequest request; DataTypeActivationRequest request;
request.cache_guid = CacheGuidForSuffix(kLocalSuffix); request.cache_guid = CacheGuidForSuffix(kLocalSuffix);
request.sync_mode = sync_mode;
return request; return request;
} }
...@@ -205,6 +213,41 @@ DeviceInfoSpecifics CreateSpecifics( ...@@ -205,6 +213,41 @@ DeviceInfoSpecifics CreateSpecifics(
return specifics; return specifics;
} }
DeviceInfoSpecifics DeviceInfoToSpecifics(const DeviceInfo& info) {
auto hardware_info = info.hardware_info();
DeviceInfoSpecifics specifics;
specifics.set_cache_guid(info.guid());
specifics.set_client_name(info.client_name());
specifics.set_chrome_version(info.chrome_version());
specifics.set_sync_user_agent(info.sync_user_agent());
specifics.set_device_type(info.device_type());
specifics.set_signin_scoped_device_id(info.signin_scoped_device_id());
specifics.set_model(hardware_info.model);
specifics.set_manufacturer(hardware_info.manufacturer);
specifics.set_last_updated_timestamp(TimeToProtoTime(base::Time::Now()));
sync_pb::FeatureSpecificFields* feature_fields =
specifics.mutable_feature_fields();
feature_fields->set_send_tab_to_self_receiving_enabled(
info.send_tab_to_self_receiving_enabled());
const base::Optional<DeviceInfo::SharingInfo>& sharing_info =
info.sharing_info();
if (sharing_info) {
sync_pb::SharingSpecificFields* sharing_fields =
specifics.mutable_sharing_fields();
sharing_fields->set_fcm_token(sharing_info->fcm_token);
sharing_fields->set_p256dh(sharing_info->p256dh);
sharing_fields->set_auth_secret(sharing_info->auth_secret);
for (sync_pb::SharingSpecificFields::EnabledFeatures feature :
sharing_info->enabled_features) {
sharing_fields->add_enabled_features(feature);
}
}
return specifics;
}
ModelTypeState StateWithEncryption(const std::string& encryption_key_name) { ModelTypeState StateWithEncryption(const std::string& encryption_key_name) {
ModelTypeState state; ModelTypeState state;
state.set_initial_sync_done(true); state.set_initial_sync_done(true);
...@@ -254,9 +297,6 @@ class TestLocalDeviceInfoProvider : public MutableLocalDeviceInfoProvider { ...@@ -254,9 +297,6 @@ class TestLocalDeviceInfoProvider : public MutableLocalDeviceInfoProvider {
~TestLocalDeviceInfoProvider() override = default; ~TestLocalDeviceInfoProvider() override = default;
// MutableLocalDeviceInfoProvider implementation. // MutableLocalDeviceInfoProvider implementation.
// TODO(himanshujaju) - |hardware_info| is ignored right now. We could reuse
// it by calling GetHardwareInfo and storing locally before starting the
// tests.
void Initialize(const std::string& cache_guid, void Initialize(const std::string& cache_guid,
const std::string& session_name, const std::string& session_name,
const base::SysInfo::HardwareInfo& hardware_info) override { const base::SysInfo::HardwareInfo& hardware_info) override {
...@@ -266,8 +306,8 @@ class TestLocalDeviceInfoProvider : public MutableLocalDeviceInfoProvider { ...@@ -266,8 +306,8 @@ class TestLocalDeviceInfoProvider : public MutableLocalDeviceInfoProvider {
cache_guid, session_name, ChromeVersionForSuffix(kLocalSuffix), cache_guid, session_name, ChromeVersionForSuffix(kLocalSuffix),
SyncUserAgentForSuffix(kLocalSuffix), SyncUserAgentForSuffix(kLocalSuffix),
sync_pb::SyncEnums_DeviceType_TYPE_LINUX, sync_pb::SyncEnums_DeviceType_TYPE_LINUX,
SigninScopedDeviceIdForSuffix(kLocalSuffix), SigninScopedDeviceIdForSuffix(kLocalSuffix), hardware_info,
HardwareInfoForSuffix(kLocalSuffix), base::Time(), base::Time(),
/*send_tab_to_self_receiving_enabled=*/true, /*send_tab_to_self_receiving_enabled=*/true,
DeviceInfo::SharingInfo(SharingFcmTokenForSuffix(kLocalSuffix), DeviceInfo::SharingInfo(SharingFcmTokenForSuffix(kLocalSuffix),
SharingP256dhForSuffix(kLocalSuffix), SharingP256dhForSuffix(kLocalSuffix),
...@@ -301,7 +341,8 @@ class DeviceInfoSyncBridgeTest : public testing::Test, ...@@ -301,7 +341,8 @@ class DeviceInfoSyncBridgeTest : public testing::Test,
public DeviceInfoTracker::Observer { public DeviceInfoTracker::Observer {
protected: protected:
DeviceInfoSyncBridgeTest() DeviceInfoSyncBridgeTest()
: store_(ModelTypeStoreTestUtil::CreateInMemoryStoreForTest()) { : store_(ModelTypeStoreTestUtil::CreateInMemoryStoreForTest()),
local_hardware_info_(GetLocalHardwareInfoBlocking()) {
DeviceInfoPrefs::RegisterProfilePrefs(pref_service_.registry()); DeviceInfoPrefs::RegisterProfilePrefs(pref_service_.registry());
ON_CALL(*processor(), IsTrackingMetadata()).WillByDefault(Return(true)); ON_CALL(*processor(), IsTrackingMetadata()).WillByDefault(Return(true));
} }
...@@ -315,6 +356,14 @@ class DeviceInfoSyncBridgeTest : public testing::Test, ...@@ -315,6 +356,14 @@ class DeviceInfoSyncBridgeTest : public testing::Test,
base::RunLoop().RunUntilIdle(); base::RunLoop().RunUntilIdle();
} }
DeviceInfoSpecifics CreateLocalDeviceSpecifics(
const base::Time last_updated = base::Time::Now()) {
DeviceInfoSpecifics specifics = CreateSpecifics(kLocalSuffix, last_updated);
specifics.set_model(local_hardware_info_.model);
specifics.set_manufacturer(local_hardware_info_.manufacturer);
return specifics;
}
void OnDeviceInfoChange() override { change_count_++; } void OnDeviceInfoChange() override { change_count_++; }
// Initialized the bridge based on the current local device and store. // Initialized the bridge based on the current local device and store.
...@@ -336,9 +385,9 @@ class DeviceInfoSyncBridgeTest : public testing::Test, ...@@ -336,9 +385,9 @@ class DeviceInfoSyncBridgeTest : public testing::Test,
// Creates the bridge with no prior data on the store, and mimics sync being // Creates the bridge with no prior data on the store, and mimics sync being
// enabled by the user with no remote data. // enabled by the user with no remote data.
void InitializeAndMergeInitialData() { void InitializeAndMergeInitialData(SyncMode sync_mode) {
InitializeAndPump(); InitializeAndPump();
bridge()->OnSyncStarting(TestDataTypeActivationRequest()); bridge()->OnSyncStarting(TestDataTypeActivationRequest(sync_mode));
std::unique_ptr<MetadataChangeList> metadata_change_list = std::unique_ptr<MetadataChangeList> metadata_change_list =
bridge()->CreateMetadataChangeList(); bridge()->CreateMetadataChangeList();
...@@ -490,6 +539,9 @@ class DeviceInfoSyncBridgeTest : public testing::Test, ...@@ -490,6 +539,9 @@ class DeviceInfoSyncBridgeTest : public testing::Test,
// Holds the store. // Holds the store.
const std::unique_ptr<ModelTypeStore> store_; const std::unique_ptr<ModelTypeStore> store_;
// Stores the local device's hardware information.
const base::SysInfo::HardwareInfo local_hardware_info_;
TestingPrefServiceSimple pref_service_; TestingPrefServiceSimple pref_service_;
// Not initialized immediately (upon test's constructor). This allows each // Not initialized immediately (upon test's constructor). This allows each
// test case to modify the dependencies the bridge will be constructed with. // test case to modify the dependencies the bridge will be constructed with.
...@@ -543,7 +595,7 @@ TEST_F(DeviceInfoSyncBridgeTest, TestWithLocalMetadata) { ...@@ -543,7 +595,7 @@ TEST_F(DeviceInfoSyncBridgeTest, TestWithLocalMetadata) {
} }
TEST_F(DeviceInfoSyncBridgeTest, TestWithLocalDataAndMetadata) { TEST_F(DeviceInfoSyncBridgeTest, TestWithLocalDataAndMetadata) {
const DeviceInfoSpecifics local_specifics = CreateSpecifics(kLocalSuffix); const DeviceInfoSpecifics local_specifics = CreateLocalDeviceSpecifics();
ModelTypeState state = StateWithEncryption("ekn"); ModelTypeState state = StateWithEncryption("ekn");
WriteToStoreWithMetadata({local_specifics}, state); WriteToStoreWithMetadata({local_specifics}, state);
...@@ -559,7 +611,7 @@ TEST_F(DeviceInfoSyncBridgeTest, TestWithLocalDataAndMetadata) { ...@@ -559,7 +611,7 @@ TEST_F(DeviceInfoSyncBridgeTest, TestWithLocalDataAndMetadata) {
} }
TEST_F(DeviceInfoSyncBridgeTest, TestWithMultipleLocalDataAndMetadata) { TEST_F(DeviceInfoSyncBridgeTest, TestWithMultipleLocalDataAndMetadata) {
const DeviceInfoSpecifics local_specifics = CreateSpecifics(kLocalSuffix); const DeviceInfoSpecifics local_specifics = CreateLocalDeviceSpecifics();
const DeviceInfoSpecifics remote_specifics = CreateSpecifics(1); const DeviceInfoSpecifics remote_specifics = CreateSpecifics(1);
ModelTypeState state = StateWithEncryption("ekn"); ModelTypeState state = StateWithEncryption("ekn");
WriteToStoreWithMetadata({local_specifics, remote_specifics}, state); WriteToStoreWithMetadata({local_specifics, remote_specifics}, state);
...@@ -577,7 +629,7 @@ TEST_F(DeviceInfoSyncBridgeTest, TestWithMultipleLocalDataAndMetadata) { ...@@ -577,7 +629,7 @@ TEST_F(DeviceInfoSyncBridgeTest, TestWithMultipleLocalDataAndMetadata) {
} }
TEST_F(DeviceInfoSyncBridgeTest, GetData) { TEST_F(DeviceInfoSyncBridgeTest, GetData) {
const DeviceInfoSpecifics local_specifics = CreateSpecifics(kLocalSuffix); const DeviceInfoSpecifics local_specifics = CreateLocalDeviceSpecifics();
const DeviceInfoSpecifics specifics1 = CreateSpecifics(1); const DeviceInfoSpecifics specifics1 = CreateSpecifics(1);
const DeviceInfoSpecifics specifics2 = CreateSpecifics(2); const DeviceInfoSpecifics specifics2 = CreateSpecifics(2);
const DeviceInfoSpecifics specifics3 = CreateSpecifics(3); const DeviceInfoSpecifics specifics3 = CreateSpecifics(3);
...@@ -609,7 +661,7 @@ TEST_F(DeviceInfoSyncBridgeTest, GetDataMissing) { ...@@ -609,7 +661,7 @@ TEST_F(DeviceInfoSyncBridgeTest, GetDataMissing) {
} }
TEST_F(DeviceInfoSyncBridgeTest, GetAllData) { TEST_F(DeviceInfoSyncBridgeTest, GetAllData) {
const DeviceInfoSpecifics local_specifics = CreateSpecifics(kLocalSuffix); const DeviceInfoSpecifics local_specifics = CreateLocalDeviceSpecifics();
const DeviceInfoSpecifics specifics1 = CreateSpecifics(1); const DeviceInfoSpecifics specifics1 = CreateSpecifics(1);
const DeviceInfoSpecifics specifics2 = CreateSpecifics(2); const DeviceInfoSpecifics specifics2 = CreateSpecifics(2);
WriteToStoreWithMetadata({local_specifics, specifics1, specifics2}, WriteToStoreWithMetadata({local_specifics, specifics1, specifics2},
...@@ -624,7 +676,7 @@ TEST_F(DeviceInfoSyncBridgeTest, GetAllData) { ...@@ -624,7 +676,7 @@ TEST_F(DeviceInfoSyncBridgeTest, GetAllData) {
} }
TEST_F(DeviceInfoSyncBridgeTest, ApplySyncChangesEmpty) { TEST_F(DeviceInfoSyncBridgeTest, ApplySyncChangesEmpty) {
InitializeAndMergeInitialData(); InitializeAndMergeInitialData(SyncMode::kFull);
ASSERT_EQ(1, change_count()); ASSERT_EQ(1, change_count());
auto error = bridge()->ApplySyncChanges(bridge()->CreateMetadataChangeList(), auto error = bridge()->ApplySyncChanges(bridge()->CreateMetadataChangeList(),
...@@ -634,7 +686,7 @@ TEST_F(DeviceInfoSyncBridgeTest, ApplySyncChangesEmpty) { ...@@ -634,7 +686,7 @@ TEST_F(DeviceInfoSyncBridgeTest, ApplySyncChangesEmpty) {
} }
TEST_F(DeviceInfoSyncBridgeTest, ApplySyncChangesInMemory) { TEST_F(DeviceInfoSyncBridgeTest, ApplySyncChangesInMemory) {
InitializeAndMergeInitialData(); InitializeAndMergeInitialData(SyncMode::kFull);
ASSERT_EQ(1, change_count()); ASSERT_EQ(1, change_count());
const DeviceInfoSpecifics specifics = CreateSpecifics(1); const DeviceInfoSpecifics specifics = CreateSpecifics(1);
...@@ -660,7 +712,7 @@ TEST_F(DeviceInfoSyncBridgeTest, ApplySyncChangesInMemory) { ...@@ -660,7 +712,7 @@ TEST_F(DeviceInfoSyncBridgeTest, ApplySyncChangesInMemory) {
} }
TEST_F(DeviceInfoSyncBridgeTest, ApplySyncChangesStore) { TEST_F(DeviceInfoSyncBridgeTest, ApplySyncChangesStore) {
InitializeAndMergeInitialData(); InitializeAndMergeInitialData(SyncMode::kFull);
ASSERT_EQ(1, change_count()); ASSERT_EQ(1, change_count());
const DeviceInfoSpecifics specifics = CreateSpecifics(1); const DeviceInfoSpecifics specifics = CreateSpecifics(1);
...@@ -686,7 +738,7 @@ TEST_F(DeviceInfoSyncBridgeTest, ApplySyncChangesStore) { ...@@ -686,7 +738,7 @@ TEST_F(DeviceInfoSyncBridgeTest, ApplySyncChangesStore) {
} }
TEST_F(DeviceInfoSyncBridgeTest, ApplySyncChangesWithLocalGuid) { TEST_F(DeviceInfoSyncBridgeTest, ApplySyncChangesWithLocalGuid) {
InitializeAndMergeInitialData(); InitializeAndMergeInitialData(SyncMode::kFull);
ASSERT_EQ(1, change_count()); ASSERT_EQ(1, change_count());
ASSERT_TRUE( ASSERT_TRUE(
...@@ -697,7 +749,7 @@ TEST_F(DeviceInfoSyncBridgeTest, ApplySyncChangesWithLocalGuid) { ...@@ -697,7 +749,7 @@ TEST_F(DeviceInfoSyncBridgeTest, ApplySyncChangesWithLocalGuid) {
// guid will match the local device. // guid will match the local device.
EXPECT_CALL(*processor(), Put(_, _, _)).Times(0); EXPECT_CALL(*processor(), Put(_, _, _)).Times(0);
const DeviceInfoSpecifics specifics = CreateSpecifics(kLocalSuffix); const DeviceInfoSpecifics specifics = CreateLocalDeviceSpecifics();
auto error_on_add = bridge()->ApplySyncChanges( auto error_on_add = bridge()->ApplySyncChanges(
bridge()->CreateMetadataChangeList(), EntityAddList({specifics})); bridge()->CreateMetadataChangeList(), EntityAddList({specifics}));
EXPECT_FALSE(error_on_add); EXPECT_FALSE(error_on_add);
...@@ -713,7 +765,7 @@ TEST_F(DeviceInfoSyncBridgeTest, ApplySyncChangesWithLocalGuid) { ...@@ -713,7 +765,7 @@ TEST_F(DeviceInfoSyncBridgeTest, ApplySyncChangesWithLocalGuid) {
} }
TEST_F(DeviceInfoSyncBridgeTest, ApplyDeleteNonexistent) { TEST_F(DeviceInfoSyncBridgeTest, ApplyDeleteNonexistent) {
InitializeAndMergeInitialData(); InitializeAndMergeInitialData(SyncMode::kFull);
ASSERT_EQ(1, change_count()); ASSERT_EQ(1, change_count());
syncer::EntityChangeList entity_change_list; syncer::EntityChangeList entity_change_list;
...@@ -736,7 +788,7 @@ TEST_F(DeviceInfoSyncBridgeTest, MergeEmpty) { ...@@ -736,7 +788,7 @@ TEST_F(DeviceInfoSyncBridgeTest, MergeEmpty) {
EXPECT_CALL(*processor(), Put(kLocalGuid, _, _)); EXPECT_CALL(*processor(), Put(kLocalGuid, _, _));
EXPECT_CALL(*processor(), Delete(_, _)).Times(0); EXPECT_CALL(*processor(), Delete(_, _)).Times(0);
bridge()->OnSyncStarting(TestDataTypeActivationRequest()); bridge()->OnSyncStarting(TestDataTypeActivationRequest(SyncMode::kFull));
auto error = bridge()->MergeSyncData(bridge()->CreateMetadataChangeList(), auto error = bridge()->MergeSyncData(bridge()->CreateMetadataChangeList(),
EntityChangeList()); EntityChangeList());
EXPECT_FALSE(error); EXPECT_FALSE(error);
...@@ -757,10 +809,10 @@ TEST_F(DeviceInfoSyncBridgeTest, MergeLocalGuid) { ...@@ -757,10 +809,10 @@ TEST_F(DeviceInfoSyncBridgeTest, MergeLocalGuid) {
EXPECT_CALL(*processor(), Put(kLocalGuid, _, _)); EXPECT_CALL(*processor(), Put(kLocalGuid, _, _));
EXPECT_CALL(*processor(), Delete(_, _)).Times(0); EXPECT_CALL(*processor(), Delete(_, _)).Times(0);
bridge()->OnSyncStarting(TestDataTypeActivationRequest()); bridge()->OnSyncStarting(TestDataTypeActivationRequest(SyncMode::kFull));
auto error = auto error =
bridge()->MergeSyncData(bridge()->CreateMetadataChangeList(), bridge()->MergeSyncData(bridge()->CreateMetadataChangeList(),
EntityAddList({CreateSpecifics(kLocalSuffix)})); EntityAddList({CreateLocalDeviceSpecifics()}));
EXPECT_FALSE(error); EXPECT_FALSE(error);
EXPECT_EQ(1, change_count()); EXPECT_EQ(1, change_count());
...@@ -770,7 +822,7 @@ TEST_F(DeviceInfoSyncBridgeTest, MergeLocalGuid) { ...@@ -770,7 +822,7 @@ TEST_F(DeviceInfoSyncBridgeTest, MergeLocalGuid) {
} }
TEST_F(DeviceInfoSyncBridgeTest, CountActiveDevices) { TEST_F(DeviceInfoSyncBridgeTest, CountActiveDevices) {
InitializeAndMergeInitialData(); InitializeAndMergeInitialData(SyncMode::kFull);
// Local device. // Local device.
EXPECT_EQ(1, bridge()->CountActiveDevices()); EXPECT_EQ(1, bridge()->CountActiveDevices());
...@@ -782,11 +834,11 @@ TEST_F(DeviceInfoSyncBridgeTest, CountActiveDevices) { ...@@ -782,11 +834,11 @@ TEST_F(DeviceInfoSyncBridgeTest, CountActiveDevices) {
// Regardless of the time, these following two ApplySyncChanges(...) calls // Regardless of the time, these following two ApplySyncChanges(...) calls
// have the same guid as the local device. // have the same guid as the local device.
bridge()->ApplySyncChanges(bridge()->CreateMetadataChangeList(), bridge()->ApplySyncChanges(bridge()->CreateMetadataChangeList(),
EntityAddList({CreateSpecifics(kLocalSuffix)})); EntityAddList({CreateLocalDeviceSpecifics()}));
EXPECT_EQ(1, bridge()->CountActiveDevices()); EXPECT_EQ(1, bridge()->CountActiveDevices());
bridge()->ApplySyncChanges(bridge()->CreateMetadataChangeList(), bridge()->ApplySyncChanges(bridge()->CreateMetadataChangeList(),
EntityAddList({CreateSpecifics(kLocalSuffix)})); EntityAddList({CreateLocalDeviceSpecifics()}));
EXPECT_EQ(1, bridge()->CountActiveDevices()); EXPECT_EQ(1, bridge()->CountActiveDevices());
// A different guid will actually contribute to the count. // A different guid will actually contribute to the count.
...@@ -803,7 +855,7 @@ TEST_F(DeviceInfoSyncBridgeTest, CountActiveDevices) { ...@@ -803,7 +855,7 @@ TEST_F(DeviceInfoSyncBridgeTest, CountActiveDevices) {
} }
TEST_F(DeviceInfoSyncBridgeTest, CountActiveDevicesWithOverlappingTime) { TEST_F(DeviceInfoSyncBridgeTest, CountActiveDevicesWithOverlappingTime) {
InitializeAndMergeInitialData(); InitializeAndMergeInitialData(SyncMode::kFull);
// Local device. // Local device.
ASSERT_EQ(1, bridge()->CountActiveDevices()); ASSERT_EQ(1, bridge()->CountActiveDevices());
...@@ -848,7 +900,7 @@ TEST_F(DeviceInfoSyncBridgeTest, CountActiveDevicesWithOverlappingTime) { ...@@ -848,7 +900,7 @@ TEST_F(DeviceInfoSyncBridgeTest, CountActiveDevicesWithOverlappingTime) {
} }
TEST_F(DeviceInfoSyncBridgeTest, CountActiveDevicesWithNonOverlappingTime) { TEST_F(DeviceInfoSyncBridgeTest, CountActiveDevicesWithNonOverlappingTime) {
InitializeAndMergeInitialData(); InitializeAndMergeInitialData(SyncMode::kFull);
// Local device. // Local device.
ASSERT_EQ(1, bridge()->CountActiveDevices()); ASSERT_EQ(1, bridge()->CountActiveDevices());
...@@ -886,7 +938,7 @@ TEST_F(DeviceInfoSyncBridgeTest, CountActiveDevicesWithNonOverlappingTime) { ...@@ -886,7 +938,7 @@ TEST_F(DeviceInfoSyncBridgeTest, CountActiveDevicesWithNonOverlappingTime) {
TEST_F(DeviceInfoSyncBridgeTest, TEST_F(DeviceInfoSyncBridgeTest,
CountActiveDevicesWithNonOverlappingTimeAndDistictType) { CountActiveDevicesWithNonOverlappingTimeAndDistictType) {
InitializeAndMergeInitialData(); InitializeAndMergeInitialData(SyncMode::kFull);
// Local device. // Local device.
ASSERT_EQ(1, bridge()->CountActiveDevices()); ASSERT_EQ(1, bridge()->CountActiveDevices());
...@@ -928,7 +980,7 @@ TEST_F(DeviceInfoSyncBridgeTest, ...@@ -928,7 +980,7 @@ TEST_F(DeviceInfoSyncBridgeTest,
} }
TEST_F(DeviceInfoSyncBridgeTest, CountActiveDevicesWithMalformedTimestamps) { TEST_F(DeviceInfoSyncBridgeTest, CountActiveDevicesWithMalformedTimestamps) {
InitializeAndMergeInitialData(); InitializeAndMergeInitialData(SyncMode::kFull);
// Local device. // Local device.
ASSERT_EQ(1, bridge()->CountActiveDevices()); ASSERT_EQ(1, bridge()->CountActiveDevices());
...@@ -960,7 +1012,7 @@ TEST_F(DeviceInfoSyncBridgeTest, CountActiveDevicesWithMalformedTimestamps) { ...@@ -960,7 +1012,7 @@ TEST_F(DeviceInfoSyncBridgeTest, CountActiveDevicesWithMalformedTimestamps) {
TEST_F(DeviceInfoSyncBridgeTest, SendLocalData) { TEST_F(DeviceInfoSyncBridgeTest, SendLocalData) {
// Ensure |last_updated| is about now, plus or minus a little bit. // Ensure |last_updated| is about now, plus or minus a little bit.
EXPECT_CALL(*processor(), Put(_, HasSpecifics(HasLastUpdatedAboutNow()), _)); EXPECT_CALL(*processor(), Put(_, HasSpecifics(HasLastUpdatedAboutNow()), _));
InitializeAndMergeInitialData(); InitializeAndMergeInitialData(SyncMode::kFull);
EXPECT_EQ(1, change_count()); EXPECT_EQ(1, change_count());
testing::Mock::VerifyAndClearExpectations(processor()); testing::Mock::VerifyAndClearExpectations(processor());
...@@ -971,7 +1023,7 @@ TEST_F(DeviceInfoSyncBridgeTest, SendLocalData) { ...@@ -971,7 +1023,7 @@ TEST_F(DeviceInfoSyncBridgeTest, SendLocalData) {
} }
TEST_F(DeviceInfoSyncBridgeTest, ApplyStopSyncChangesWithClearData) { TEST_F(DeviceInfoSyncBridgeTest, ApplyStopSyncChangesWithClearData) {
InitializeAndMergeInitialData(); InitializeAndMergeInitialData(SyncMode::kFull);
ASSERT_EQ(1u, bridge()->GetAllDeviceInfo().size()); ASSERT_EQ(1u, bridge()->GetAllDeviceInfo().size());
ASSERT_EQ(1, change_count()); ASSERT_EQ(1, change_count());
ASSERT_FALSE(ReadAllFromStore().empty()); ASSERT_FALSE(ReadAllFromStore().empty());
...@@ -998,7 +1050,7 @@ TEST_F(DeviceInfoSyncBridgeTest, ApplyStopSyncChangesWithClearData) { ...@@ -998,7 +1050,7 @@ TEST_F(DeviceInfoSyncBridgeTest, ApplyStopSyncChangesWithClearData) {
// If sync is re-enabled and the remote data is now empty, we shouldn't // If sync is re-enabled and the remote data is now empty, we shouldn't
// contain remote data. // contain remote data.
bridge()->OnSyncStarting(TestDataTypeActivationRequest()); bridge()->OnSyncStarting(TestDataTypeActivationRequest(SyncMode::kFull));
bridge()->MergeSyncData(bridge()->CreateMetadataChangeList(), bridge()->MergeSyncData(bridge()->CreateMetadataChangeList(),
EntityChangeList()); EntityChangeList());
// Local device. // Local device.
...@@ -1007,7 +1059,7 @@ TEST_F(DeviceInfoSyncBridgeTest, ApplyStopSyncChangesWithClearData) { ...@@ -1007,7 +1059,7 @@ TEST_F(DeviceInfoSyncBridgeTest, ApplyStopSyncChangesWithClearData) {
} }
TEST_F(DeviceInfoSyncBridgeTest, ApplyStopSyncChangesWithKeepData) { TEST_F(DeviceInfoSyncBridgeTest, ApplyStopSyncChangesWithKeepData) {
InitializeAndMergeInitialData(); InitializeAndMergeInitialData(SyncMode::kFull);
ASSERT_EQ(1u, bridge()->GetAllDeviceInfo().size()); ASSERT_EQ(1u, bridge()->GetAllDeviceInfo().size());
ASSERT_EQ(1, change_count()); ASSERT_EQ(1, change_count());
ASSERT_FALSE(ReadAllFromStore().empty()); ASSERT_FALSE(ReadAllFromStore().empty());
...@@ -1035,7 +1087,7 @@ TEST_F(DeviceInfoSyncBridgeTest, ApplyStopSyncChangesWithKeepData) { ...@@ -1035,7 +1087,7 @@ TEST_F(DeviceInfoSyncBridgeTest, ApplyStopSyncChangesWithKeepData) {
} }
TEST_F(DeviceInfoSyncBridgeTest, ExpireOldEntriesUponStartup) { TEST_F(DeviceInfoSyncBridgeTest, ExpireOldEntriesUponStartup) {
InitializeAndMergeInitialData(); InitializeAndMergeInitialData(SyncMode::kFull);
ASSERT_EQ(1u, bridge()->GetAllDeviceInfo().size()); ASSERT_EQ(1u, bridge()->GetAllDeviceInfo().size());
ASSERT_EQ(1, change_count()); ASSERT_EQ(1, change_count());
ASSERT_FALSE(ReadAllFromStore().empty()); ASSERT_FALSE(ReadAllFromStore().empty());
...@@ -1066,7 +1118,7 @@ TEST_F(DeviceInfoSyncBridgeTest, ExpireOldEntriesUponStartup) { ...@@ -1066,7 +1118,7 @@ TEST_F(DeviceInfoSyncBridgeTest, ExpireOldEntriesUponStartup) {
TEST_F(DeviceInfoSyncBridgeTest, RefreshLocalDeviceInfo) { TEST_F(DeviceInfoSyncBridgeTest, RefreshLocalDeviceInfo) {
// Ensure |last_updated| is about now, plus or minus a little bit. // Ensure |last_updated| is about now, plus or minus a little bit.
EXPECT_CALL(*processor(), Put(_, HasSpecifics(HasLastUpdatedAboutNow()), _)); EXPECT_CALL(*processor(), Put(_, HasSpecifics(HasLastUpdatedAboutNow()), _));
InitializeAndMergeInitialData(); InitializeAndMergeInitialData(SyncMode::kFull);
EXPECT_EQ(1, change_count()); EXPECT_EQ(1, change_count());
testing::Mock::VerifyAndClearExpectations(processor()); testing::Mock::VerifyAndClearExpectations(processor());
...@@ -1076,6 +1128,105 @@ TEST_F(DeviceInfoSyncBridgeTest, RefreshLocalDeviceInfo) { ...@@ -1076,6 +1128,105 @@ TEST_F(DeviceInfoSyncBridgeTest, RefreshLocalDeviceInfo) {
EXPECT_EQ(2, change_count()); EXPECT_EQ(2, change_count());
} }
TEST_F(DeviceInfoSyncBridgeTest, DeviceNameForTransportOnlySyncMode) {
InitializeAndMergeInitialData(SyncMode::kTransportOnly);
ASSERT_EQ(1, change_count());
ASSERT_TRUE(local_device()->GetLocalDeviceInfo());
EXPECT_EQ(GetLocalHardwareInfoBlocking().model,
local_device()->GetLocalDeviceInfo()->client_name());
}
TEST_F(DeviceInfoSyncBridgeTest, DeviceNameForFullSyncMode) {
InitializeAndMergeInitialData(SyncMode::kFull);
ASSERT_EQ(1, change_count());
ASSERT_TRUE(local_device()->GetLocalDeviceInfo());
EXPECT_EQ(GetPersonalizableDeviceNameBlocking(),
local_device()->GetLocalDeviceInfo()->client_name());
}
// Tests local client name when device is initially synced with transport only
// sync mode, but the sync mode is not available after restart since it is not
// persisted.
TEST_F(DeviceInfoSyncBridgeTest,
DeviceNameForTransportOnlySyncMode_RestartBridge) {
std::string expected_device_name = GetLocalHardwareInfoBlocking().model;
InitializeAndMergeInitialData(SyncMode::kTransportOnly);
ASSERT_TRUE(local_device()->GetLocalDeviceInfo());
ASSERT_EQ(expected_device_name,
local_device()->GetLocalDeviceInfo()->client_name());
EXPECT_CALL(*processor(),
Put(local_device()->GetLocalDeviceInfo()->guid(), _, _))
.Times(0);
RestartBridge();
ASSERT_TRUE(local_device()->GetLocalDeviceInfo());
EXPECT_EQ(expected_device_name,
local_device()->GetLocalDeviceInfo()->client_name());
}
// Tests local client name when device is initially synced with full sync mode,
// but the sync mode is not available after restart since it is not persisted.
TEST_F(DeviceInfoSyncBridgeTest, DeviceNameForFullSyncMode_RestartBridge) {
std::string expected_device_name = GetPersonalizableDeviceNameBlocking();
InitializeAndMergeInitialData(SyncMode::kFull);
ASSERT_TRUE(local_device()->GetLocalDeviceInfo());
ASSERT_EQ(expected_device_name,
local_device()->GetLocalDeviceInfo()->client_name());
EXPECT_CALL(*processor(),
Put(local_device()->GetLocalDeviceInfo()->guid(), _, _))
.Times(0);
RestartBridge();
ASSERT_TRUE(local_device()->GetLocalDeviceInfo());
EXPECT_EQ(expected_device_name,
local_device()->GetLocalDeviceInfo()->client_name());
}
TEST_F(DeviceInfoSyncBridgeTest, RefreshLocalDeviceNameForSyncModeToggle) {
std::string expected_device_name_full_sync =
GetPersonalizableDeviceNameBlocking();
std::string expected_device_name_transport_only =
GetLocalHardwareInfoBlocking().model;
// Initialize with full sync mode.
InitializeAndMergeInitialData(SyncMode::kFull);
const syncer::DeviceInfo* device = local_device()->GetLocalDeviceInfo();
ASSERT_TRUE(device);
ASSERT_EQ(expected_device_name_full_sync, device->client_name());
// Toggle to transport only sync mode.
syncer::EntityChangeList entity_change_list;
entity_change_list.push_back(EntityChange::CreateUpdate(
device->guid(), SpecificsToEntity(DeviceInfoToSpecifics(*device))));
bridge()->ApplyStopSyncChanges(bridge()->CreateMetadataChangeList());
bridge()->OnSyncStarting(
TestDataTypeActivationRequest(SyncMode::kTransportOnly));
bridge()->MergeSyncData(bridge()->CreateMetadataChangeList(),
std::move(entity_change_list));
device = local_device()->GetLocalDeviceInfo();
ASSERT_TRUE(device);
ASSERT_EQ(expected_device_name_transport_only, device->client_name());
// Toggle to full sync mode.
ASSERT_TRUE(entity_change_list.empty());
entity_change_list.push_back(EntityChange::CreateUpdate(
device->guid(), SpecificsToEntity(DeviceInfoToSpecifics(*device))));
bridge()->ApplyStopSyncChanges(bridge()->CreateMetadataChangeList());
bridge()->OnSyncStarting(TestDataTypeActivationRequest(SyncMode::kFull));
bridge()->MergeSyncData(bridge()->CreateMetadataChangeList(),
std::move(entity_change_list));
device = local_device()->GetLocalDeviceInfo();
ASSERT_TRUE(device);
ASSERT_EQ(expected_device_name_full_sync, device->client_name());
}
} // namespace } // namespace
} // namespace syncer } // namespace syncer
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