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

Side by Side Diff: components/sync/device_info/device_info_sync_bridge_unittest.cc

Issue 2620783002: [sync] Handle local changes in AutocompleteSyncBridge (Closed)
Patch Set: rebase Created 3 years, 11 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 | « components/sync/BUILD.gn ('k') | components/sync/model/recording_model_type_change_processor.h » ('j') | no next file with comments »
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/device_info/device_info_sync_bridge.h" 5 #include "components/sync/device_info/device_info_sync_bridge.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 #include <set> 8 #include <set>
9 #include <utility> 9 #include <utility>
10 10
11 #include "base/bind.h" 11 #include "base/bind.h"
12 #include "base/memory/ptr_util.h" 12 #include "base/memory/ptr_util.h"
13 #include "base/message_loop/message_loop.h" 13 #include "base/message_loop/message_loop.h"
14 #include "base/run_loop.h" 14 #include "base/run_loop.h"
15 #include "base/strings/stringprintf.h" 15 #include "base/strings/stringprintf.h"
16 #include "components/sync/base/time.h" 16 #include "components/sync/base/time.h"
17 #include "components/sync/device_info/local_device_info_provider_mock.h" 17 #include "components/sync/device_info/local_device_info_provider_mock.h"
18 #include "components/sync/model/data_batch.h" 18 #include "components/sync/model/data_batch.h"
19 #include "components/sync/model/data_type_error_handler_mock.h" 19 #include "components/sync/model/data_type_error_handler_mock.h"
20 #include "components/sync/model/entity_data.h" 20 #include "components/sync/model/entity_data.h"
21 #include "components/sync/model/fake_model_type_change_processor.h" 21 #include "components/sync/model/fake_model_type_change_processor.h"
22 #include "components/sync/model/metadata_batch.h" 22 #include "components/sync/model/metadata_batch.h"
23 #include "components/sync/model/model_type_store_test_util.h" 23 #include "components/sync/model/model_type_store_test_util.h"
24 #include "components/sync/model/recording_model_type_change_processor.h"
24 #include "components/sync/protocol/model_type_state.pb.h" 25 #include "components/sync/protocol/model_type_state.pb.h"
25 #include "testing/gtest/include/gtest/gtest.h" 26 #include "testing/gtest/include/gtest/gtest.h"
26 27
27 namespace syncer { 28 namespace syncer {
28 29
29 using base::OneShotTimer; 30 using base::OneShotTimer;
30 using base::Time; 31 using base::Time;
31 using base::TimeDelta; 32 using base::TimeDelta;
32 using sync_pb::DeviceInfoSpecifics; 33 using sync_pb::DeviceInfoSpecifics;
33 using sync_pb::EntitySpecifics; 34 using sync_pb::EntitySpecifics;
(...skipping 129 matching lines...) Expand 10 before | Expand all | Expand 10 after
163 EntityDataMap InlineEntityDataMap( 164 EntityDataMap InlineEntityDataMap(
164 const std::vector<DeviceInfoSpecifics>& specifics_list) { 165 const std::vector<DeviceInfoSpecifics>& specifics_list) {
165 EntityDataMap map; 166 EntityDataMap map;
166 for (const auto& specifics : specifics_list) { 167 for (const auto& specifics : specifics_list) {
167 EXPECT_EQ(map.end(), map.find(specifics.cache_guid())); 168 EXPECT_EQ(map.end(), map.find(specifics.cache_guid()));
168 map[specifics.cache_guid()] = SpecificsToEntity(specifics); 169 map[specifics.cache_guid()] = SpecificsToEntity(specifics);
169 } 170 }
170 return map; 171 return map;
171 } 172 }
172 173
173 // Instead of actually processing anything, simply accumulates all instructions
174 // in members that can then be accessed. TODO(skym): If this ends up being
175 // useful for other model type unittests it should be moved out to a shared
176 // location.
177 class RecordingModelTypeChangeProcessor : public FakeModelTypeChangeProcessor {
178 public:
179 RecordingModelTypeChangeProcessor() {}
180 ~RecordingModelTypeChangeProcessor() override {}
181
182 void Put(const std::string& storage_key,
183 std::unique_ptr<EntityData> entity_data,
184 MetadataChangeList* metadata_changes) override {
185 put_multimap_.insert(std::make_pair(storage_key, std::move(entity_data)));
186 }
187
188 void Delete(const std::string& storage_key,
189 MetadataChangeList* metadata_changes) override {
190 delete_set_.insert(storage_key);
191 }
192
193 void ModelReadyToSync(std::unique_ptr<MetadataBatch> batch) override {
194 std::swap(metadata_, batch);
195 }
196
197 const std::multimap<std::string, std::unique_ptr<EntityData>>& put_multimap()
198 const {
199 return put_multimap_;
200 }
201 const std::set<std::string>& delete_set() const { return delete_set_; }
202 const MetadataBatch* metadata() const { return metadata_.get(); }
203
204 private:
205 std::multimap<std::string, std::unique_ptr<EntityData>> put_multimap_;
206 std::set<std::string> delete_set_;
207 std::unique_ptr<MetadataBatch> metadata_;
208 };
209
210 } // namespace 174 } // namespace
211 175
212 class DeviceInfoSyncBridgeTest : public testing::Test, 176 class DeviceInfoSyncBridgeTest : public testing::Test,
213 public DeviceInfoTracker::Observer { 177 public DeviceInfoTracker::Observer {
214 protected: 178 protected:
215 DeviceInfoSyncBridgeTest() 179 DeviceInfoSyncBridgeTest()
216 : store_(ModelTypeStoreTestUtil::CreateInMemoryStoreForTest()), 180 : store_(ModelTypeStoreTestUtil::CreateInMemoryStoreForTest()),
217 provider_(new LocalDeviceInfoProviderMock()) { 181 provider_(new LocalDeviceInfoProviderMock()) {
218 provider_->Initialize(CreateModel(kDefaultLocalSuffix)); 182 provider_->Initialize(CreateModel(kDefaultLocalSuffix));
219 } 183 }
(...skipping 591 matching lines...) Expand 10 before | Expand all | Expand 10 after
811 775
812 // Reloading from storage shouldn't contain remote data. 776 // Reloading from storage shouldn't contain remote data.
813 RestartBridge(); 777 RestartBridge();
814 EXPECT_EQ(1u, bridge()->GetAllDeviceInfo().size()); 778 EXPECT_EQ(1u, bridge()->GetAllDeviceInfo().size());
815 EXPECT_EQ(4, change_count()); 779 EXPECT_EQ(4, change_count());
816 } 780 }
817 781
818 } // namespace 782 } // namespace
819 783
820 } // namespace syncer 784 } // namespace syncer
OLDNEW
« no previous file with comments | « components/sync/BUILD.gn ('k') | components/sync/model/recording_model_type_change_processor.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698