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

Side by Side Diff: components/sync_driver/device_info_service_unittest.cc

Issue 2077713002: [USS] Store supports hosting multiple datatypes per database (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: can create multiple backend base on path Created 4 years, 6 months 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 unified diff | Download patch
« no previous file with comments | « no previous file | sync/api/model_type_store.h » ('j') | sync/api/model_type_store.h » ('J')
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2015 The Chromium Authors. All rights reserved. 1 // Copyright 2015 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "components/sync_driver/device_info_service.h" 5 #include "components/sync_driver/device_info_service.h"
6 6
7 #include <map> 7 #include <map>
8 #include <memory> 8 #include <memory>
9 #include <set> 9 #include <set>
10 #include <string> 10 #include <string>
(...skipping 151 matching lines...) Expand 10 before | Expand all | Expand 10 after
162 std::unique_ptr<MetadataBatch> metadata_; 162 std::unique_ptr<MetadataBatch> metadata_;
163 }; 163 };
164 164
165 } // namespace 165 } // namespace
166 166
167 class DeviceInfoServiceTest : public testing::Test, 167 class DeviceInfoServiceTest : public testing::Test,
168 public DeviceInfoTracker::Observer { 168 public DeviceInfoTracker::Observer {
169 protected: 169 protected:
170 DeviceInfoServiceTest() 170 DeviceInfoServiceTest()
171 : change_count_(0), 171 : change_count_(0),
172 store_(ModelTypeStoreTestUtil::CreateInMemoryStoreForTest()),
173 local_device_(new LocalDeviceInfoProviderMock()) { 172 local_device_(new LocalDeviceInfoProviderMock()) {
174 local_device_->Initialize(CreateDeviceInfo()); 173 local_device_->Initialize(CreateDeviceInfo());
175 } 174 }
176 175
177 ~DeviceInfoServiceTest() override { 176 ~DeviceInfoServiceTest() override {
178 // Some tests may never initialize the service. 177 // Some tests may never initialize the service.
179 if (service_) 178 if (service_)
180 service_->RemoveObserver(this); 179 service_->RemoveObserver(this);
181 180
182 // Force all remaining (store) tasks to execute so we don't leak memory. 181 // Force all remaining (store) tasks to execute so we don't leak memory.
183 base::RunLoop().RunUntilIdle(); 182 base::RunLoop().RunUntilIdle();
184 } 183 }
185 184
185 void SetUp() override {
maxbogue 2016/06/23 18:22:22 I believe this should just be in the body of the c
Gang Wu 2016/06/27 23:19:39 Done.
186 store_ = ModelTypeStoreTestUtil::CreateInMemoryStoreForTest();
187 base::RunLoop().RunUntilIdle();
188 }
189
190 void TearDown() override {
191 std::swap(store_, service_->store_);
192 store_.reset();
193 base::RunLoop().RunUntilIdle();
194 }
195
186 void OnDeviceInfoChange() override { change_count_++; } 196 void OnDeviceInfoChange() override { change_count_++; }
187 197
188 std::unique_ptr<ModelTypeChangeProcessor> CreateModelTypeChangeProcessor( 198 std::unique_ptr<ModelTypeChangeProcessor> CreateModelTypeChangeProcessor(
189 syncer::ModelType type, 199 syncer::ModelType type,
190 ModelTypeService* service) { 200 ModelTypeService* service) {
191 processor_ = new RecordingModelTypeChangeProcessor(); 201 processor_ = new RecordingModelTypeChangeProcessor();
192 return base::WrapUnique(processor_); 202 return base::WrapUnique(processor_);
193 } 203 }
194 204
195 // Initialized the service based on the current local device and store. Can 205 // Initialized the service based on the current local device and store. Can
(...skipping 531 matching lines...) Expand 10 before | Expand all | Expand 10 after
727 const SyncError error = service()->MergeSyncData( 737 const SyncError error = service()->MergeSyncData(
728 service()->CreateMetadataChangeList(), remote_input); 738 service()->CreateMetadataChangeList(), remote_input);
729 EXPECT_FALSE(error.IsSet()); 739 EXPECT_FALSE(error.IsSet());
730 EXPECT_EQ(0, change_count()); 740 EXPECT_EQ(0, change_count());
731 EXPECT_EQ(1u, service()->GetAllDeviceInfo().size()); 741 EXPECT_EQ(1u, service()->GetAllDeviceInfo().size());
732 EXPECT_TRUE(processor()->delete_set().empty()); 742 EXPECT_TRUE(processor()->delete_set().empty());
733 EXPECT_TRUE(processor()->put_map().empty()); 743 EXPECT_TRUE(processor()->put_map().empty());
734 } 744 }
735 745
736 TEST_F(DeviceInfoServiceTest, GetLastUpdateTime) { 746 TEST_F(DeviceInfoServiceTest, GetLastUpdateTime) {
747 InitializeAndPump();
737 Time time1(Time() + TimeDelta::FromDays(1)); 748 Time time1(Time() + TimeDelta::FromDays(1));
738 749
739 DeviceInfoSpecifics specifics1(GenerateTestSpecifics()); 750 DeviceInfoSpecifics specifics1(GenerateTestSpecifics());
740 DeviceInfoSpecifics specifics2(GenerateTestSpecifics()); 751 DeviceInfoSpecifics specifics2(GenerateTestSpecifics());
741 specifics2.set_last_updated_timestamp(syncer::TimeToProtoTime(time1)); 752 specifics2.set_last_updated_timestamp(syncer::TimeToProtoTime(time1));
742 753
743 EXPECT_EQ(Time(), GetLastUpdateTime(specifics1)); 754 EXPECT_EQ(Time(), GetLastUpdateTime(specifics1));
744 EXPECT_EQ(time1, GetLastUpdateTime(specifics2)); 755 EXPECT_EQ(time1, GetLastUpdateTime(specifics2));
745 } 756 }
746 757
(...skipping 20 matching lines...) Expand all
767 specifics.set_cache_guid("non-local"); 778 specifics.set_cache_guid("non-local");
768 PushBackEntityChangeAdd(specifics, &change_list); 779 PushBackEntityChangeAdd(specifics, &change_list);
769 service()->ApplySyncChanges(service()->CreateMetadataChangeList(), 780 service()->ApplySyncChanges(service()->CreateMetadataChangeList(),
770 change_list); 781 change_list);
771 EXPECT_EQ(1, service()->CountActiveDevices()); 782 EXPECT_EQ(1, service()->CountActiveDevices());
772 } 783 }
773 784
774 } // namespace 785 } // namespace
775 786
776 } // namespace sync_driver_v2 787 } // namespace sync_driver_v2
OLDNEW
« no previous file with comments | « no previous file | sync/api/model_type_store.h » ('j') | sync/api/model_type_store.h » ('J')

Powered by Google App Engine
This is Rietveld 408576698