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

Side by Side Diff: components/sync/driver/generic_change_processor_unittest.cc

Issue 2203673002: [Sync] Move //components/sync_driver to //components/sync/driver. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@sd-a
Patch Set: Full change rebased on static lib. Created 4 years, 4 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
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 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/generic_change_processor.h" 5 #include "components/sync/driver/generic_change_processor.h"
6 6
7 #include <stddef.h> 7 #include <stddef.h>
8 8
9 #include <memory> 9 #include <memory>
10 #include <string> 10 #include <string>
11 #include <utility> 11 #include <utility>
12 12
13 #include "base/memory/weak_ptr.h" 13 #include "base/memory/weak_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/api/attachments/attachment_id.h" 17 #include "components/sync/api/attachments/attachment_id.h"
18 #include "components/sync/api/attachments/attachment_store.h" 18 #include "components/sync/api/attachments/attachment_store.h"
19 #include "components/sync/api/fake_syncable_service.h" 19 #include "components/sync/api/fake_syncable_service.h"
20 #include "components/sync/api/sync_change.h" 20 #include "components/sync/api/sync_change.h"
21 #include "components/sync/api/sync_merge_result.h" 21 #include "components/sync/api/sync_merge_result.h"
22 #include "components/sync/base/model_type.h" 22 #include "components/sync/base/model_type.h"
23 #include "components/sync/core/attachments/attachment_service_impl.h" 23 #include "components/sync/core/attachments/attachment_service_impl.h"
24 #include "components/sync/core/attachments/fake_attachment_downloader.h" 24 #include "components/sync/core/attachments/fake_attachment_downloader.h"
25 #include "components/sync/core/attachments/fake_attachment_uploader.h" 25 #include "components/sync/core/attachments/fake_attachment_uploader.h"
26 #include "components/sync/core/read_node.h" 26 #include "components/sync/core/read_node.h"
27 #include "components/sync/core/read_transaction.h" 27 #include "components/sync/core/read_transaction.h"
28 #include "components/sync/core/sync_encryption_handler.h" 28 #include "components/sync/core/sync_encryption_handler.h"
29 #include "components/sync/core/test/data_type_error_handler_mock.h" 29 #include "components/sync/core/test/data_type_error_handler_mock.h"
30 #include "components/sync/core/test/test_user_share.h" 30 #include "components/sync/core/test/test_user_share.h"
31 #include "components/sync/core/user_share.h" 31 #include "components/sync/core/user_share.h"
32 #include "components/sync/core/write_node.h" 32 #include "components/sync/core/write_node.h"
33 #include "components/sync/core/write_transaction.h" 33 #include "components/sync/core/write_transaction.h"
34 #include "components/sync_driver/fake_sync_client.h" 34 #include "components/sync/driver/fake_sync_client.h"
35 #include "components/sync_driver/local_device_info_provider.h" 35 #include "components/sync/driver/local_device_info_provider.h"
36 #include "components/sync_driver/sync_api_component_factory.h" 36 #include "components/sync/driver/sync_api_component_factory.h"
37 #include "testing/gmock/include/gmock/gmock.h" 37 #include "testing/gmock/include/gmock/gmock.h"
38 #include "testing/gtest/include/gtest/gtest.h" 38 #include "testing/gtest/include/gtest/gtest.h"
39 39
40 namespace sync_driver { 40 namespace sync_driver {
41 41
42 namespace { 42 namespace {
43 43
44 // A mock that keeps track of attachments passed to UploadAttachments. 44 // A mock that keeps track of attachments passed to UploadAttachments.
45 class MockAttachmentService : public syncer::AttachmentServiceImpl { 45 class MockAttachmentService : public syncer::AttachmentServiceImpl {
46 public: 46 public:
(...skipping 12 matching lines...) Expand all
59 std::unique_ptr<syncer::AttachmentStoreForSync> attachment_store) 59 std::unique_ptr<syncer::AttachmentStoreForSync> attachment_store)
60 : AttachmentServiceImpl(std::move(attachment_store), 60 : AttachmentServiceImpl(std::move(attachment_store),
61 std::unique_ptr<syncer::AttachmentUploader>( 61 std::unique_ptr<syncer::AttachmentUploader>(
62 new syncer::FakeAttachmentUploader), 62 new syncer::FakeAttachmentUploader),
63 std::unique_ptr<syncer::AttachmentDownloader>( 63 std::unique_ptr<syncer::AttachmentDownloader>(
64 new syncer::FakeAttachmentDownloader), 64 new syncer::FakeAttachmentDownloader),
65 NULL, 65 NULL,
66 base::TimeDelta(), 66 base::TimeDelta(),
67 base::TimeDelta()) {} 67 base::TimeDelta()) {}
68 68
69 MockAttachmentService::~MockAttachmentService() { 69 MockAttachmentService::~MockAttachmentService() {}
70 }
71 70
72 void MockAttachmentService::UploadAttachments( 71 void MockAttachmentService::UploadAttachments(
73 const syncer::AttachmentIdList& attachment_ids) { 72 const syncer::AttachmentIdList& attachment_ids) {
74 attachment_id_lists_.push_back(attachment_ids); 73 attachment_id_lists_.push_back(attachment_ids);
75 AttachmentServiceImpl::UploadAttachments(attachment_ids); 74 AttachmentServiceImpl::UploadAttachments(attachment_ids);
76 } 75 }
77 76
78 std::vector<syncer::AttachmentIdList>* 77 std::vector<syncer::AttachmentIdList>*
79 MockAttachmentService::attachment_id_lists() { 78 MockAttachmentService::attachment_id_lists() {
80 return &attachment_id_lists_; 79 return &attachment_id_lists_;
81 } 80 }
82 81
83 // MockSyncApiComponentFactory needed to initialize GenericChangeProcessor and 82 // MockSyncApiComponentFactory needed to initialize GenericChangeProcessor and
84 // pass MockAttachmentService to it. 83 // pass MockAttachmentService to it.
85 class MockSyncApiComponentFactory : public SyncApiComponentFactory { 84 class MockSyncApiComponentFactory : public SyncApiComponentFactory {
86 public: 85 public:
87 MockSyncApiComponentFactory() {} 86 MockSyncApiComponentFactory() {}
88 87
89 // SyncApiComponentFactory implementation. 88 // SyncApiComponentFactory implementation.
90 void RegisterDataTypes( 89 void RegisterDataTypes(
91 sync_driver::SyncService* sync_service, 90 sync_driver::SyncService* sync_service,
92 const RegisterDataTypesMethod& register_platform_types_method) override {} 91 const RegisterDataTypesMethod& register_platform_types_method) override {}
93 sync_driver::DataTypeManager* CreateDataTypeManager( 92 sync_driver::DataTypeManager* CreateDataTypeManager(
94 const syncer::WeakHandle<syncer::DataTypeDebugInfoListener>& 93 const syncer::WeakHandle<syncer::DataTypeDebugInfoListener>&
95 debug_info_listener, 94 debug_info_listener,
96 const sync_driver::DataTypeController::TypeMap* controllers, 95 const sync_driver::DataTypeController::TypeMap* controllers,
97 const sync_driver::DataTypeEncryptionHandler* encryption_handler, 96 const sync_driver::DataTypeEncryptionHandler* encryption_handler,
98 browser_sync::SyncBackendHost* backend, 97 browser_sync::SyncBackendHost* backend,
99 sync_driver::DataTypeManagerObserver* observer) override{ 98 sync_driver::DataTypeManagerObserver* observer) override {
100 return nullptr; 99 return nullptr;
101 }; 100 };
102 browser_sync::SyncBackendHost* CreateSyncBackendHost( 101 browser_sync::SyncBackendHost* CreateSyncBackendHost(
103 const std::string& name, 102 const std::string& name,
104 invalidation::InvalidationService* invalidator, 103 invalidation::InvalidationService* invalidator,
105 const base::WeakPtr<sync_driver::SyncPrefs>& sync_prefs, 104 const base::WeakPtr<sync_driver::SyncPrefs>& sync_prefs,
106 const base::FilePath& sync_folder) override { 105 const base::FilePath& sync_folder) override {
107 return nullptr; 106 return nullptr;
108 } 107 }
109 std::unique_ptr<sync_driver::LocalDeviceInfoProvider> 108 std::unique_ptr<sync_driver::LocalDeviceInfoProvider>
(...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after
198 } 197 }
199 198
200 void BuildChildNodes(syncer::ModelType type, int n) { 199 void BuildChildNodes(syncer::ModelType type, int n) {
201 syncer::WriteTransaction trans(FROM_HERE, user_share()); 200 syncer::WriteTransaction trans(FROM_HERE, user_share());
202 for (int i = 0; i < n; ++i) { 201 for (int i = 0; i < n; ++i) {
203 syncer::WriteNode node(&trans); 202 syncer::WriteNode node(&trans);
204 node.InitUniqueByCreation(type, base::StringPrintf("node%05d", i)); 203 node.InitUniqueByCreation(type, base::StringPrintf("node%05d", i));
205 } 204 }
206 } 205 }
207 206
208 GenericChangeProcessor* change_processor() { 207 GenericChangeProcessor* change_processor() { return change_processor_.get(); }
209 return change_processor_.get();
210 }
211 208
212 syncer::UserShare* user_share() { 209 syncer::UserShare* user_share() { return test_user_share_->user_share(); }
213 return test_user_share_->user_share();
214 }
215 210
216 MockAttachmentService* mock_attachment_service() { 211 MockAttachmentService* mock_attachment_service() {
217 return mock_attachment_service_; 212 return mock_attachment_service_;
218 } 213 }
219 214
220 void RunLoop() { 215 void RunLoop() {
221 base::RunLoop run_loop; 216 base::RunLoop run_loop;
222 run_loop.RunUntilIdle(); 217 run_loop.RunUntilIdle();
223 } 218 }
224 219
(...skipping 19 matching lines...) Expand all
244 239
245 // Similar to above, but focused on the method that implements sync/api 240 // Similar to above, but focused on the method that implements sync/api
246 // interfaces and is hence exposed to datatypes directly. 241 // interfaces and is hence exposed to datatypes directly.
247 TEST_F(SyncGenericChangeProcessorTest, StressGetAllSyncData) { 242 TEST_F(SyncGenericChangeProcessorTest, StressGetAllSyncData) {
248 const int kNumChildNodes = 1000; 243 const int kNumChildNodes = 1000;
249 const int kRepeatCount = 1; 244 const int kRepeatCount = 1;
250 245
251 ASSERT_NO_FATAL_FAILURE(BuildChildNodes(kType, kNumChildNodes)); 246 ASSERT_NO_FATAL_FAILURE(BuildChildNodes(kType, kNumChildNodes));
252 247
253 for (int i = 0; i < kRepeatCount; ++i) { 248 for (int i = 0; i < kRepeatCount; ++i) {
254 syncer::SyncDataList sync_data = 249 syncer::SyncDataList sync_data = change_processor()->GetAllSyncData(kType);
255 change_processor()->GetAllSyncData(kType);
256 250
257 // Start with a simple test. We can add more in-depth testing later. 251 // Start with a simple test. We can add more in-depth testing later.
258 EXPECT_EQ(static_cast<size_t>(kNumChildNodes), sync_data.size()); 252 EXPECT_EQ(static_cast<size_t>(kNumChildNodes), sync_data.size());
259 } 253 }
260 } 254 }
261 255
262 TEST_F(SyncGenericChangeProcessorTest, SetGetPasswords) { 256 TEST_F(SyncGenericChangeProcessorTest, SetGetPasswords) {
263 InitializeForType(syncer::PASSWORDS); 257 InitializeForType(syncer::PASSWORDS);
264 const int kNumPasswords = 10; 258 const int kNumPasswords = 10;
265 sync_pb::PasswordSpecificsData password_data; 259 sync_pb::PasswordSpecificsData password_data;
266 password_data.set_username_value("user"); 260 password_data.set_username_value("user");
267 261
268 sync_pb::EntitySpecifics password_holder; 262 sync_pb::EntitySpecifics password_holder;
269 263
270 syncer::SyncChangeList change_list; 264 syncer::SyncChangeList change_list;
271 for (int i = 0; i < kNumPasswords; ++i) { 265 for (int i = 0; i < kNumPasswords; ++i) {
272 password_data.set_password_value( 266 password_data.set_password_value(base::StringPrintf("password%i", i));
273 base::StringPrintf("password%i", i)); 267 password_holder.mutable_password()
274 password_holder.mutable_password()->mutable_client_only_encrypted_data()-> 268 ->mutable_client_only_encrypted_data()
275 CopyFrom(password_data); 269 ->CopyFrom(password_data);
276 change_list.push_back( 270 change_list.push_back(syncer::SyncChange(
277 syncer::SyncChange(FROM_HERE, 271 FROM_HERE, syncer::SyncChange::ACTION_ADD,
278 syncer::SyncChange::ACTION_ADD, 272 syncer::SyncData::CreateLocalData(base::StringPrintf("tag%i", i),
279 syncer::SyncData::CreateLocalData( 273 base::StringPrintf("title%i", i),
280 base::StringPrintf("tag%i", i), 274 password_holder)));
281 base::StringPrintf("title%i", i),
282 password_holder)));
283 } 275 }
284 276
285 ASSERT_FALSE( 277 ASSERT_FALSE(
286 change_processor()->ProcessSyncChanges(FROM_HERE, change_list).IsSet()); 278 change_processor()->ProcessSyncChanges(FROM_HERE, change_list).IsSet());
287 279
288 syncer::SyncDataList password_list( 280 syncer::SyncDataList password_list(
289 change_processor()->GetAllSyncData(syncer::PASSWORDS)); 281 change_processor()->GetAllSyncData(syncer::PASSWORDS));
290 282
291 ASSERT_EQ(password_list.size(), change_list.size()); 283 ASSERT_EQ(password_list.size(), change_list.size());
292 for (int i = 0; i < kNumPasswords; ++i) { 284 for (int i = 0; i < kNumPasswords; ++i) {
293 // Verify the password is returned properly. 285 // Verify the password is returned properly.
294 ASSERT_TRUE(password_list[i].GetSpecifics().has_password()); 286 ASSERT_TRUE(password_list[i].GetSpecifics().has_password());
295 ASSERT_TRUE(password_list[i].GetSpecifics().password(). 287 ASSERT_TRUE(password_list[i]
296 has_client_only_encrypted_data()); 288 .GetSpecifics()
289 .password()
290 .has_client_only_encrypted_data());
297 ASSERT_FALSE(password_list[i].GetSpecifics().password().has_encrypted()); 291 ASSERT_FALSE(password_list[i].GetSpecifics().password().has_encrypted());
298 const sync_pb::PasswordSpecificsData& sync_password = 292 const sync_pb::PasswordSpecificsData& sync_password =
299 password_list[i].GetSpecifics().password().client_only_encrypted_data(); 293 password_list[i].GetSpecifics().password().client_only_encrypted_data();
300 const sync_pb::PasswordSpecificsData& change_password = 294 const sync_pb::PasswordSpecificsData& change_password =
301 change_list[i].sync_data().GetSpecifics().password(). 295 change_list[i]
302 client_only_encrypted_data(); 296 .sync_data()
297 .GetSpecifics()
298 .password()
299 .client_only_encrypted_data();
303 ASSERT_EQ(sync_password.password_value(), change_password.password_value()); 300 ASSERT_EQ(sync_password.password_value(), change_password.password_value());
304 ASSERT_EQ(sync_password.username_value(), change_password.username_value()); 301 ASSERT_EQ(sync_password.username_value(), change_password.username_value());
305 302
306 // Verify the raw sync data was stored securely. 303 // Verify the raw sync data was stored securely.
307 syncer::ReadTransaction read_transaction(FROM_HERE, user_share()); 304 syncer::ReadTransaction read_transaction(FROM_HERE, user_share());
308 syncer::ReadNode node(&read_transaction); 305 syncer::ReadNode node(&read_transaction);
309 ASSERT_EQ(node.InitByClientTagLookup(syncer::PASSWORDS, 306 ASSERT_EQ(node.InitByClientTagLookup(syncer::PASSWORDS,
310 base::StringPrintf("tag%i", i)), 307 base::StringPrintf("tag%i", i)),
311 syncer::BaseNode::INIT_OK); 308 syncer::BaseNode::INIT_OK);
312 ASSERT_EQ(node.GetTitle(), "encrypted"); 309 ASSERT_EQ(node.GetTitle(), "encrypted");
313 const sync_pb::EntitySpecifics& raw_specifics = node.GetEntitySpecifics(); 310 const sync_pb::EntitySpecifics& raw_specifics = node.GetEntitySpecifics();
314 ASSERT_TRUE(raw_specifics.has_password()); 311 ASSERT_TRUE(raw_specifics.has_password());
315 ASSERT_TRUE(raw_specifics.password().has_encrypted()); 312 ASSERT_TRUE(raw_specifics.password().has_encrypted());
316 ASSERT_FALSE(raw_specifics.password().has_client_only_encrypted_data()); 313 ASSERT_FALSE(raw_specifics.password().has_client_only_encrypted_data());
317 } 314 }
318 } 315 }
319 316
320 TEST_F(SyncGenericChangeProcessorTest, UpdatePasswords) { 317 TEST_F(SyncGenericChangeProcessorTest, UpdatePasswords) {
321 InitializeForType(syncer::PASSWORDS); 318 InitializeForType(syncer::PASSWORDS);
322 const int kNumPasswords = 10; 319 const int kNumPasswords = 10;
323 sync_pb::PasswordSpecificsData password_data; 320 sync_pb::PasswordSpecificsData password_data;
324 password_data.set_username_value("user"); 321 password_data.set_username_value("user");
325 322
326 sync_pb::EntitySpecifics password_holder; 323 sync_pb::EntitySpecifics password_holder;
327 324
328 syncer::SyncChangeList change_list; 325 syncer::SyncChangeList change_list;
329 syncer::SyncChangeList change_list2; 326 syncer::SyncChangeList change_list2;
330 for (int i = 0; i < kNumPasswords; ++i) { 327 for (int i = 0; i < kNumPasswords; ++i) {
331 password_data.set_password_value( 328 password_data.set_password_value(base::StringPrintf("password%i", i));
332 base::StringPrintf("password%i", i)); 329 password_holder.mutable_password()
333 password_holder.mutable_password()->mutable_client_only_encrypted_data()-> 330 ->mutable_client_only_encrypted_data()
334 CopyFrom(password_data); 331 ->CopyFrom(password_data);
335 change_list.push_back( 332 change_list.push_back(syncer::SyncChange(
336 syncer::SyncChange(FROM_HERE, 333 FROM_HERE, syncer::SyncChange::ACTION_ADD,
337 syncer::SyncChange::ACTION_ADD, 334 syncer::SyncData::CreateLocalData(base::StringPrintf("tag%i", i),
338 syncer::SyncData::CreateLocalData( 335 base::StringPrintf("title%i", i),
339 base::StringPrintf("tag%i", i), 336 password_holder)));
340 base::StringPrintf("title%i", i), 337 password_data.set_password_value(base::StringPrintf("password_m%i", i));
341 password_holder))); 338 password_holder.mutable_password()
342 password_data.set_password_value( 339 ->mutable_client_only_encrypted_data()
343 base::StringPrintf("password_m%i", i)); 340 ->CopyFrom(password_data);
344 password_holder.mutable_password()->mutable_client_only_encrypted_data()-> 341 change_list2.push_back(syncer::SyncChange(
345 CopyFrom(password_data); 342 FROM_HERE, syncer::SyncChange::ACTION_UPDATE,
346 change_list2.push_back( 343 syncer::SyncData::CreateLocalData(base::StringPrintf("tag%i", i),
347 syncer::SyncChange(FROM_HERE, 344 base::StringPrintf("title_m%i", i),
348 syncer::SyncChange::ACTION_UPDATE, 345 password_holder)));
349 syncer::SyncData::CreateLocalData(
350 base::StringPrintf("tag%i", i),
351 base::StringPrintf("title_m%i", i),
352 password_holder)));
353 } 346 }
354 347
355 ASSERT_FALSE( 348 ASSERT_FALSE(
356 change_processor()->ProcessSyncChanges(FROM_HERE, change_list).IsSet()); 349 change_processor()->ProcessSyncChanges(FROM_HERE, change_list).IsSet());
357 ASSERT_FALSE( 350 ASSERT_FALSE(
358 change_processor()->ProcessSyncChanges(FROM_HERE, change_list2).IsSet()); 351 change_processor()->ProcessSyncChanges(FROM_HERE, change_list2).IsSet());
359 352
360 syncer::SyncDataList password_list( 353 syncer::SyncDataList password_list(
361 change_processor()->GetAllSyncData(syncer::PASSWORDS)); 354 change_processor()->GetAllSyncData(syncer::PASSWORDS));
362 355
363 ASSERT_EQ(password_list.size(), change_list2.size()); 356 ASSERT_EQ(password_list.size(), change_list2.size());
364 for (int i = 0; i < kNumPasswords; ++i) { 357 for (int i = 0; i < kNumPasswords; ++i) {
365 // Verify the password is returned properly. 358 // Verify the password is returned properly.
366 ASSERT_TRUE(password_list[i].GetSpecifics().has_password()); 359 ASSERT_TRUE(password_list[i].GetSpecifics().has_password());
367 ASSERT_TRUE(password_list[i].GetSpecifics().password(). 360 ASSERT_TRUE(password_list[i]
368 has_client_only_encrypted_data()); 361 .GetSpecifics()
362 .password()
363 .has_client_only_encrypted_data());
369 ASSERT_FALSE(password_list[i].GetSpecifics().password().has_encrypted()); 364 ASSERT_FALSE(password_list[i].GetSpecifics().password().has_encrypted());
370 const sync_pb::PasswordSpecificsData& sync_password = 365 const sync_pb::PasswordSpecificsData& sync_password =
371 password_list[i].GetSpecifics().password().client_only_encrypted_data(); 366 password_list[i].GetSpecifics().password().client_only_encrypted_data();
372 const sync_pb::PasswordSpecificsData& change_password = 367 const sync_pb::PasswordSpecificsData& change_password =
373 change_list2[i].sync_data().GetSpecifics().password(). 368 change_list2[i]
374 client_only_encrypted_data(); 369 .sync_data()
370 .GetSpecifics()
371 .password()
372 .client_only_encrypted_data();
375 ASSERT_EQ(sync_password.password_value(), change_password.password_value()); 373 ASSERT_EQ(sync_password.password_value(), change_password.password_value());
376 ASSERT_EQ(sync_password.username_value(), change_password.username_value()); 374 ASSERT_EQ(sync_password.username_value(), change_password.username_value());
377 375
378 // Verify the raw sync data was stored securely. 376 // Verify the raw sync data was stored securely.
379 syncer::ReadTransaction read_transaction(FROM_HERE, user_share()); 377 syncer::ReadTransaction read_transaction(FROM_HERE, user_share());
380 syncer::ReadNode node(&read_transaction); 378 syncer::ReadNode node(&read_transaction);
381 ASSERT_EQ(node.InitByClientTagLookup(syncer::PASSWORDS, 379 ASSERT_EQ(node.InitByClientTagLookup(syncer::PASSWORDS,
382 base::StringPrintf("tag%i", i)), 380 base::StringPrintf("tag%i", i)),
383 syncer::BaseNode::INIT_OK); 381 syncer::BaseNode::INIT_OK);
384 ASSERT_EQ(node.GetTitle(), "encrypted"); 382 ASSERT_EQ(node.GetTitle(), "encrypted");
(...skipping 14 matching lines...) Expand all
399 sync_pb::PreferenceSpecifics* pref_specifics = specifics.mutable_preference(); 397 sync_pb::PreferenceSpecifics* pref_specifics = specifics.mutable_preference();
400 pref_specifics->set_name("test"); 398 pref_specifics->set_name("test");
401 399
402 syncer::AttachmentIdList attachment_ids; 400 syncer::AttachmentIdList attachment_ids;
403 attachment_ids.push_back(syncer::AttachmentId::Create(0, 0)); 401 attachment_ids.push_back(syncer::AttachmentId::Create(0, 0));
404 attachment_ids.push_back(syncer::AttachmentId::Create(0, 0)); 402 attachment_ids.push_back(syncer::AttachmentId::Create(0, 0));
405 403
406 // Add a SyncData with two attachments. 404 // Add a SyncData with two attachments.
407 syncer::SyncChangeList change_list; 405 syncer::SyncChangeList change_list;
408 change_list.push_back( 406 change_list.push_back(
409 syncer::SyncChange(FROM_HERE, 407 syncer::SyncChange(FROM_HERE, syncer::SyncChange::ACTION_ADD,
410 syncer::SyncChange::ACTION_ADD,
411 syncer::SyncData::CreateLocalDataWithAttachments( 408 syncer::SyncData::CreateLocalDataWithAttachments(
412 tag, title, specifics, attachment_ids))); 409 tag, title, specifics, attachment_ids)));
413 ASSERT_FALSE( 410 ASSERT_FALSE(
414 change_processor()->ProcessSyncChanges(FROM_HERE, change_list).IsSet()); 411 change_processor()->ProcessSyncChanges(FROM_HERE, change_list).IsSet());
415 RunLoop(); 412 RunLoop();
416 413
417 // Check that the AttachmentService received the new attachments. 414 // Check that the AttachmentService received the new attachments.
418 ASSERT_EQ(mock_attachment_service()->attachment_id_lists()->size(), 1U); 415 ASSERT_EQ(mock_attachment_service()->attachment_id_lists()->size(), 1U);
419 const syncer::AttachmentIdList& attachments_added = 416 const syncer::AttachmentIdList& attachments_added =
420 mock_attachment_service()->attachment_id_lists()->front(); 417 mock_attachment_service()->attachment_id_lists()->front();
421 ASSERT_THAT( 418 ASSERT_THAT(attachments_added, testing::UnorderedElementsAre(
422 attachments_added, 419 attachment_ids[0], attachment_ids[1]));
423 testing::UnorderedElementsAre(attachment_ids[0], attachment_ids[1]));
424 420
425 // Update the SyncData, replacing its two attachments with one new attachment. 421 // Update the SyncData, replacing its two attachments with one new attachment.
426 syncer::AttachmentIdList new_attachment_ids; 422 syncer::AttachmentIdList new_attachment_ids;
427 new_attachment_ids.push_back(syncer::AttachmentId::Create(0, 0)); 423 new_attachment_ids.push_back(syncer::AttachmentId::Create(0, 0));
428 mock_attachment_service()->attachment_id_lists()->clear(); 424 mock_attachment_service()->attachment_id_lists()->clear();
429 change_list.clear(); 425 change_list.clear();
430 change_list.push_back( 426 change_list.push_back(
431 syncer::SyncChange(FROM_HERE, 427 syncer::SyncChange(FROM_HERE, syncer::SyncChange::ACTION_UPDATE,
432 syncer::SyncChange::ACTION_UPDATE,
433 syncer::SyncData::CreateLocalDataWithAttachments( 428 syncer::SyncData::CreateLocalDataWithAttachments(
434 tag, title, specifics, new_attachment_ids))); 429 tag, title, specifics, new_attachment_ids)));
435 ASSERT_FALSE( 430 ASSERT_FALSE(
436 change_processor()->ProcessSyncChanges(FROM_HERE, change_list).IsSet()); 431 change_processor()->ProcessSyncChanges(FROM_HERE, change_list).IsSet());
437 RunLoop(); 432 RunLoop();
438 433
439 // Check that the AttachmentService received it. 434 // Check that the AttachmentService received it.
440 ASSERT_EQ(mock_attachment_service()->attachment_id_lists()->size(), 1U); 435 ASSERT_EQ(mock_attachment_service()->attachment_id_lists()->size(), 1U);
441 const syncer::AttachmentIdList& new_attachments_added = 436 const syncer::AttachmentIdList& new_attachments_added =
442 mock_attachment_service()->attachment_id_lists()->front(); 437 mock_attachment_service()->attachment_id_lists()->front();
443 ASSERT_THAT(new_attachments_added, 438 ASSERT_THAT(new_attachments_added,
444 testing::UnorderedElementsAre(new_attachment_ids[0])); 439 testing::UnorderedElementsAre(new_attachment_ids[0]));
445 } 440 }
446 441
447 // Verify that after attachment is uploaded GenericChangeProcessor updates 442 // Verify that after attachment is uploaded GenericChangeProcessor updates
448 // corresponding entries 443 // corresponding entries
449 TEST_F(SyncGenericChangeProcessorTest, AttachmentUploaded) { 444 TEST_F(SyncGenericChangeProcessorTest, AttachmentUploaded) {
450 std::string tag = "client_tag"; 445 std::string tag = "client_tag";
451 std::string title = "client_title"; 446 std::string title = "client_title";
452 sync_pb::EntitySpecifics specifics; 447 sync_pb::EntitySpecifics specifics;
453 sync_pb::PreferenceSpecifics* pref_specifics = specifics.mutable_preference(); 448 sync_pb::PreferenceSpecifics* pref_specifics = specifics.mutable_preference();
454 pref_specifics->set_name("test"); 449 pref_specifics->set_name("test");
455 450
456 syncer::AttachmentIdList attachment_ids; 451 syncer::AttachmentIdList attachment_ids;
457 attachment_ids.push_back(syncer::AttachmentId::Create(0, 0)); 452 attachment_ids.push_back(syncer::AttachmentId::Create(0, 0));
458 453
459 // Add a SyncData with two attachments. 454 // Add a SyncData with two attachments.
460 syncer::SyncChangeList change_list; 455 syncer::SyncChangeList change_list;
461 change_list.push_back( 456 change_list.push_back(
462 syncer::SyncChange(FROM_HERE, 457 syncer::SyncChange(FROM_HERE, syncer::SyncChange::ACTION_ADD,
463 syncer::SyncChange::ACTION_ADD,
464 syncer::SyncData::CreateLocalDataWithAttachments( 458 syncer::SyncData::CreateLocalDataWithAttachments(
465 tag, title, specifics, attachment_ids))); 459 tag, title, specifics, attachment_ids)));
466 ASSERT_FALSE( 460 ASSERT_FALSE(
467 change_processor()->ProcessSyncChanges(FROM_HERE, change_list).IsSet()); 461 change_processor()->ProcessSyncChanges(FROM_HERE, change_list).IsSet());
468 462
469 sync_pb::AttachmentIdProto attachment_id_proto = attachment_ids[0].GetProto(); 463 sync_pb::AttachmentIdProto attachment_id_proto = attachment_ids[0].GetProto();
470 syncer::AttachmentId attachment_id = 464 syncer::AttachmentId attachment_id =
471 syncer::AttachmentId::CreateFromProto(attachment_id_proto); 465 syncer::AttachmentId::CreateFromProto(attachment_id_proto);
472 466
473 change_processor()->OnAttachmentUploaded(attachment_id); 467 change_processor()->OnAttachmentUploaded(attachment_id);
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after
540 change_processor()->GetAllSyncData(syncer::SESSIONS); 534 change_processor()->GetAllSyncData(syncer::SESSIONS);
541 ASSERT_EQ(sync_data.size(), 1U); 535 ASSERT_EQ(sync_data.size(), 1U);
542 ASSERT_EQ("session tag 2", 536 ASSERT_EQ("session tag 2",
543 sync_data[0].GetSpecifics().session().session_tag()); 537 sync_data[0].GetSpecifics().session().session_tag());
544 EXPECT_FALSE(syncer::SyncDataRemote(sync_data[0]).GetClientTagHash().empty()); 538 EXPECT_FALSE(syncer::SyncDataRemote(sync_data[0]).GetClientTagHash().empty());
545 } 539 }
546 540
547 } // namespace 541 } // namespace
548 542
549 } // namespace sync_driver 543 } // namespace sync_driver
OLDNEW
« no previous file with comments | « components/sync/driver/generic_change_processor_factory.cc ('k') | components/sync/driver/glue/browser_thread_model_worker.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698