OLD | NEW |
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 <set> | 8 #include <set> |
9 #include <string> | 9 #include <string> |
10 #include <utility> | 10 #include <utility> |
11 | 11 |
12 #include "base/bind.h" | 12 #include "base/bind.h" |
13 #include "base/memory/scoped_ptr.h" | 13 #include "base/memory/scoped_ptr.h" |
14 #include "base/message_loop/message_loop.h" | 14 #include "base/message_loop/message_loop.h" |
15 #include "base/run_loop.h" | 15 #include "base/run_loop.h" |
16 #include "base/strings/stringprintf.h" | 16 #include "base/strings/stringprintf.h" |
17 #include "components/sync_driver/local_device_info_provider_mock.h" | 17 #include "components/sync_driver/local_device_info_provider_mock.h" |
18 #include "sync/api/data_batch.h" | 18 #include "sync/api/data_batch.h" |
19 #include "sync/api/entity_data.h" | 19 #include "sync/api/entity_data.h" |
20 #include "sync/api/metadata_batch.h" | 20 #include "sync/api/metadata_batch.h" |
21 #include "sync/api/model_type_store.h" | 21 #include "sync/api/model_type_store.h" |
| 22 #include "sync/internal_api/public/shared_model_type_processor.h" |
22 #include "sync/internal_api/public/test/model_type_store_test_util.h" | 23 #include "sync/internal_api/public/test/model_type_store_test_util.h" |
23 #include "sync/protocol/data_type_state.pb.h" | 24 #include "sync/protocol/data_type_state.pb.h" |
24 #include "testing/gtest/include/gtest/gtest.h" | 25 #include "testing/gtest/include/gtest/gtest.h" |
25 | 26 |
26 namespace sync_driver_v2 { | 27 namespace sync_driver_v2 { |
27 | 28 |
28 using syncer::SyncError; | 29 using syncer::SyncError; |
29 using syncer_v2::DataBatch; | 30 using syncer_v2::DataBatch; |
30 using syncer_v2::EntityChange; | 31 using syncer_v2::EntityChange; |
31 using syncer_v2::EntityChangeList; | 32 using syncer_v2::EntityChangeList; |
(...skipping 124 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
156 // Some tests may never initialize the service. | 157 // Some tests may never initialize the service. |
157 if (service_) | 158 if (service_) |
158 service_->RemoveObserver(this); | 159 service_->RemoveObserver(this); |
159 | 160 |
160 // Force all remaining (store) tasks to execute so we don't leak memory. | 161 // Force all remaining (store) tasks to execute so we don't leak memory. |
161 base::RunLoop().RunUntilIdle(); | 162 base::RunLoop().RunUntilIdle(); |
162 } | 163 } |
163 | 164 |
164 void OnDeviceInfoChange() override { change_count_++; } | 165 void OnDeviceInfoChange() override { change_count_++; } |
165 | 166 |
166 protected: | 167 scoped_ptr<ModelTypeChangeProcessor> CreateModelTypeChangeProcessor( |
| 168 ModelTypeService* service) { |
| 169 processor_ = new FakeModelTypeChangeProcessor(); |
| 170 return make_scoped_ptr(processor_); |
| 171 } |
| 172 |
167 DeviceInfoServiceTest() | 173 DeviceInfoServiceTest() |
168 : change_count_(0), | 174 : change_count_(0), |
169 store_(ModelTypeStoreTestUtil::CreateInMemoryStoreForTest()), | 175 store_(ModelTypeStoreTestUtil::CreateInMemoryStoreForTest()), |
170 local_device_(new LocalDeviceInfoProviderMock( | 176 local_device_(new LocalDeviceInfoProviderMock( |
171 "guid_1", | 177 "guid_1", |
172 "client_1", | 178 "client_1", |
173 "Chromium 10k", | 179 "Chromium 10k", |
174 "Chrome 10k", | 180 "Chrome 10k", |
175 sync_pb::SyncEnums_DeviceType_TYPE_LINUX, | 181 sync_pb::SyncEnums_DeviceType_TYPE_LINUX, |
176 "device_id")) {} | 182 "device_id")) {} |
(...skipping 13 matching lines...) Expand all Loading... |
190 // cause all initialization callbacks between the sevice and store to fire. | 196 // cause all initialization callbacks between the sevice and store to fire. |
191 void InitializeAndPump() { | 197 void InitializeAndPump() { |
192 InitializeService(); | 198 InitializeService(); |
193 base::RunLoop().RunUntilIdle(); | 199 base::RunLoop().RunUntilIdle(); |
194 } | 200 } |
195 | 201 |
196 // Creates a new processor and sets it on the service. We typically need to | 202 // Creates a new processor and sets it on the service. We typically need to |
197 // pump in this scenario because metadata is going to need to be loading from | 203 // pump in this scenario because metadata is going to need to be loading from |
198 // the store and given to the processor, which is async. | 204 // the store and given to the processor, which is async. |
199 void SetProcessorAndPump() { | 205 void SetProcessorAndPump() { |
200 processor_ = new FakeModelTypeChangeProcessor(); | 206 service()->InitializeProcessor( |
201 service()->set_change_processor(make_scoped_ptr(processor_)); | 207 base::Bind(&DeviceInfoServiceTest::CreateModelTypeChangeProcessor, |
| 208 base::Unretained(this))); |
202 base::RunLoop().RunUntilIdle(); | 209 base::RunLoop().RunUntilIdle(); |
203 } | 210 } |
204 | 211 |
205 // Generates a specifics object with slightly differing values. Will generate | 212 // Generates a specifics object with slightly differing values. Will generate |
206 // the same values on each run of a test because a simple counter is used to | 213 // the same values on each run of a test because a simple counter is used to |
207 // vary field values. | 214 // vary field values. |
208 DeviceInfoSpecifics GenerateTestSpecifics() { | 215 DeviceInfoSpecifics GenerateTestSpecifics() { |
209 int label = ++generated_count_; | 216 int label = ++generated_count_; |
210 DeviceInfoSpecifics specifics; | 217 DeviceInfoSpecifics specifics; |
211 specifics.set_cache_guid(base::StringPrintf("cache guid %d", label)); | 218 specifics.set_cache_guid(base::StringPrintf("cache guid %d", label)); |
(...skipping 447 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
659 EXPECT_FALSE(error.IsSet()); | 666 EXPECT_FALSE(error.IsSet()); |
660 EXPECT_EQ(0, change_count()); | 667 EXPECT_EQ(0, change_count()); |
661 EXPECT_TRUE(service()->GetAllDeviceInfo().empty()); | 668 EXPECT_TRUE(service()->GetAllDeviceInfo().empty()); |
662 EXPECT_TRUE(processor()->delete_set().empty()); | 669 EXPECT_TRUE(processor()->delete_set().empty()); |
663 EXPECT_TRUE(processor()->put_map().empty()); | 670 EXPECT_TRUE(processor()->put_map().empty()); |
664 } | 671 } |
665 | 672 |
666 } // namespace | 673 } // namespace |
667 | 674 |
668 } // namespace sync_driver_v2 | 675 } // namespace sync_driver_v2 |
OLD | NEW |