Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(314)

Unified Diff: components/sync/device_info/device_info_sync_bridge_unittest.cc

Issue 2568543003: [Sync] Actively guard against provider being cleared in DeviceInfoSyncBridge. (Closed)
Patch Set: Updated comments slightly. Created 4 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « components/sync/device_info/device_info_sync_bridge.cc ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: components/sync/device_info/device_info_sync_bridge_unittest.cc
diff --git a/components/sync/device_info/device_info_sync_bridge_unittest.cc b/components/sync/device_info/device_info_sync_bridge_unittest.cc
index ace221172aef218b8706b4be7de2c5a8d11227ce..3ed624ee0a743facdae85207e2c65b518fb92188 100644
--- a/components/sync/device_info/device_info_sync_bridge_unittest.cc
+++ b/components/sync/device_info/device_info_sync_bridge_unittest.cc
@@ -26,6 +26,7 @@
namespace syncer {
+using base::OneShotTimer;
using base::Time;
using base::TimeDelta;
using sync_pb::DeviceInfoSpecifics;
@@ -287,6 +288,8 @@ class DeviceInfoSyncBridgeTest : public testing::Test,
return processor_;
}
+ const OneShotTimer& pulse_timer() { return bridge()->pulse_timer_; }
+
// Should only be called after the bridge has been initialized. Will first
// recover the bridge's store, so another can be initialized later, and then
// deletes the bridge.
@@ -398,6 +401,16 @@ TEST_F(DeviceInfoSyncBridgeTest, LocalProviderInitRace) {
EXPECT_TRUE(processor()->metadata());
}
+// Simulate shutting down sync during the ModelTypeStore callbacks. The pulse
+// timer should still be initialized, even though reconcile never occurs.
+TEST_F(DeviceInfoSyncBridgeTest, ClearProviderDuringInit) {
+ InitializeBridge();
+ local_device()->Clear();
+ base::RunLoop().RunUntilIdle();
+ EXPECT_EQ(0u, bridge()->GetAllDeviceInfo().size());
+ EXPECT_TRUE(pulse_timer().IsRunning());
+}
+
TEST_F(DeviceInfoSyncBridgeTest, GetClientTagNormal) {
InitializeBridge();
const std::string guid = "abc";
@@ -587,6 +600,25 @@ TEST_F(DeviceInfoSyncBridgeTest, ApplyDeleteNonexistent) {
EXPECT_EQ(1, change_count());
}
+TEST_F(DeviceInfoSyncBridgeTest, ClearProviderAndApply) {
+ // This will initialize the provider a first time.
+ InitializeAndPump();
+ EXPECT_EQ(1u, bridge()->GetAllDeviceInfo().size());
+
+ const DeviceInfoSpecifics specifics = CreateSpecifics(1, Time::Now());
+
+ local_device()->Clear();
+ SyncError error = bridge()->ApplySyncChanges(
+ bridge()->CreateMetadataChangeList(), EntityAddList({specifics}));
+ EXPECT_FALSE(error.IsSet());
+ EXPECT_EQ(1u, bridge()->GetAllDeviceInfo().size());
+
+ local_device()->Initialize(CreateModel(kDefaultLocalSuffix));
+ error = bridge()->ApplySyncChanges(bridge()->CreateMetadataChangeList(),
+ EntityAddList({specifics}));
+ EXPECT_EQ(2u, bridge()->GetAllDeviceInfo().size());
+}
+
TEST_F(DeviceInfoSyncBridgeTest, MergeEmpty) {
InitializeAndPump();
EXPECT_EQ(1, change_count());
@@ -680,6 +712,24 @@ TEST_F(DeviceInfoSyncBridgeTest, MergeLocalGuidBeforeReconcile) {
EXPECT_EQ(0u, bridge()->GetAllDeviceInfo().size());
}
+TEST_F(DeviceInfoSyncBridgeTest, ClearProviderAndMerge) {
+ // This will initialize the provider a first time.
+ InitializeAndPump();
+ EXPECT_EQ(1u, bridge()->GetAllDeviceInfo().size());
+
+ const DeviceInfoSpecifics specifics = CreateSpecifics(1, Time::Now());
+
+ local_device()->Clear();
+ SyncError error = bridge()->MergeSyncData(
+ bridge()->CreateMetadataChangeList(), InlineEntityDataMap({specifics}));
+ EXPECT_FALSE(error.IsSet());
+ EXPECT_EQ(1u, bridge()->GetAllDeviceInfo().size());
+ local_device()->Initialize(CreateModel(kDefaultLocalSuffix));
+ error = bridge()->MergeSyncData(bridge()->CreateMetadataChangeList(),
+ InlineEntityDataMap({specifics}));
+ EXPECT_EQ(2u, bridge()->GetAllDeviceInfo().size());
+}
+
TEST_F(DeviceInfoSyncBridgeTest, CountActiveDevices) {
InitializeAndPump();
EXPECT_EQ(1, bridge()->CountActiveDevices());
« no previous file with comments | « components/sync/device_info/device_info_sync_bridge.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698