OLD | NEW |
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 "base/memory/scoped_ptr.h" | 7 #include "base/memory/scoped_ptr.h" |
8 #include "base/memory/weak_ptr.h" | 8 #include "base/memory/weak_ptr.h" |
9 #include "base/message_loop/message_loop.h" | 9 #include "base/message_loop/message_loop.h" |
10 #include "base/run_loop.h" | 10 #include "base/run_loop.h" |
(...skipping 352 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
363 // AttachmentService. | 363 // AttachmentService. |
364 TEST_F(SyncGenericChangeProcessorTest, | 364 TEST_F(SyncGenericChangeProcessorTest, |
365 ProcessSyncChanges_AddUpdateWithAttachment) { | 365 ProcessSyncChanges_AddUpdateWithAttachment) { |
366 std::string tag = "client_tag"; | 366 std::string tag = "client_tag"; |
367 std::string title = "client_title"; | 367 std::string title = "client_title"; |
368 sync_pb::EntitySpecifics specifics; | 368 sync_pb::EntitySpecifics specifics; |
369 sync_pb::PreferenceSpecifics* pref_specifics = specifics.mutable_preference(); | 369 sync_pb::PreferenceSpecifics* pref_specifics = specifics.mutable_preference(); |
370 pref_specifics->set_name("test"); | 370 pref_specifics->set_name("test"); |
371 | 371 |
372 syncer::AttachmentIdList attachment_ids; | 372 syncer::AttachmentIdList attachment_ids; |
373 attachment_ids.push_back(syncer::AttachmentId::Create()); | 373 attachment_ids.push_back(syncer::AttachmentId::Create(0, 0)); |
374 attachment_ids.push_back(syncer::AttachmentId::Create()); | 374 attachment_ids.push_back(syncer::AttachmentId::Create(0, 0)); |
375 | 375 |
376 // Add a SyncData with two attachments. | 376 // Add a SyncData with two attachments. |
377 syncer::SyncChangeList change_list; | 377 syncer::SyncChangeList change_list; |
378 change_list.push_back( | 378 change_list.push_back( |
379 syncer::SyncChange(FROM_HERE, | 379 syncer::SyncChange(FROM_HERE, |
380 syncer::SyncChange::ACTION_ADD, | 380 syncer::SyncChange::ACTION_ADD, |
381 syncer::SyncData::CreateLocalDataWithAttachments( | 381 syncer::SyncData::CreateLocalDataWithAttachments( |
382 tag, title, specifics, attachment_ids))); | 382 tag, title, specifics, attachment_ids))); |
383 ASSERT_FALSE( | 383 ASSERT_FALSE( |
384 change_processor()->ProcessSyncChanges(FROM_HERE, change_list).IsSet()); | 384 change_processor()->ProcessSyncChanges(FROM_HERE, change_list).IsSet()); |
385 RunLoop(); | 385 RunLoop(); |
386 | 386 |
387 // Check that the AttachmentService received the new attachments. | 387 // Check that the AttachmentService received the new attachments. |
388 ASSERT_EQ(mock_attachment_service()->attachment_id_sets()->size(), 1U); | 388 ASSERT_EQ(mock_attachment_service()->attachment_id_sets()->size(), 1U); |
389 const syncer::AttachmentIdSet& attachments_added = | 389 const syncer::AttachmentIdSet& attachments_added = |
390 mock_attachment_service()->attachment_id_sets()->front(); | 390 mock_attachment_service()->attachment_id_sets()->front(); |
391 ASSERT_THAT( | 391 ASSERT_THAT( |
392 attachments_added, | 392 attachments_added, |
393 testing::UnorderedElementsAre(attachment_ids[0], attachment_ids[1])); | 393 testing::UnorderedElementsAre(attachment_ids[0], attachment_ids[1])); |
394 | 394 |
395 // Update the SyncData, replacing its two attachments with one new attachment. | 395 // Update the SyncData, replacing its two attachments with one new attachment. |
396 syncer::AttachmentIdList new_attachment_ids; | 396 syncer::AttachmentIdList new_attachment_ids; |
397 new_attachment_ids.push_back(syncer::AttachmentId::Create()); | 397 new_attachment_ids.push_back(syncer::AttachmentId::Create(0, 0)); |
398 mock_attachment_service()->attachment_id_sets()->clear(); | 398 mock_attachment_service()->attachment_id_sets()->clear(); |
399 change_list.clear(); | 399 change_list.clear(); |
400 change_list.push_back( | 400 change_list.push_back( |
401 syncer::SyncChange(FROM_HERE, | 401 syncer::SyncChange(FROM_HERE, |
402 syncer::SyncChange::ACTION_UPDATE, | 402 syncer::SyncChange::ACTION_UPDATE, |
403 syncer::SyncData::CreateLocalDataWithAttachments( | 403 syncer::SyncData::CreateLocalDataWithAttachments( |
404 tag, title, specifics, new_attachment_ids))); | 404 tag, title, specifics, new_attachment_ids))); |
405 ASSERT_FALSE( | 405 ASSERT_FALSE( |
406 change_processor()->ProcessSyncChanges(FROM_HERE, change_list).IsSet()); | 406 change_processor()->ProcessSyncChanges(FROM_HERE, change_list).IsSet()); |
407 RunLoop(); | 407 RunLoop(); |
408 | 408 |
409 // Check that the AttachmentService received it. | 409 // Check that the AttachmentService received it. |
410 ASSERT_EQ(mock_attachment_service()->attachment_id_sets()->size(), 1U); | 410 ASSERT_EQ(mock_attachment_service()->attachment_id_sets()->size(), 1U); |
411 const syncer::AttachmentIdSet& new_attachments_added = | 411 const syncer::AttachmentIdSet& new_attachments_added = |
412 mock_attachment_service()->attachment_id_sets()->front(); | 412 mock_attachment_service()->attachment_id_sets()->front(); |
413 ASSERT_THAT(new_attachments_added, | 413 ASSERT_THAT(new_attachments_added, |
414 testing::UnorderedElementsAre(new_attachment_ids[0])); | 414 testing::UnorderedElementsAre(new_attachment_ids[0])); |
415 } | 415 } |
416 | 416 |
417 // Verify that after attachment is uploaded GenericChangeProcessor updates | 417 // Verify that after attachment is uploaded GenericChangeProcessor updates |
418 // corresponding entries | 418 // corresponding entries |
419 TEST_F(SyncGenericChangeProcessorTest, AttachmentUploaded) { | 419 TEST_F(SyncGenericChangeProcessorTest, AttachmentUploaded) { |
420 std::string tag = "client_tag"; | 420 std::string tag = "client_tag"; |
421 std::string title = "client_title"; | 421 std::string title = "client_title"; |
422 sync_pb::EntitySpecifics specifics; | 422 sync_pb::EntitySpecifics specifics; |
423 sync_pb::PreferenceSpecifics* pref_specifics = specifics.mutable_preference(); | 423 sync_pb::PreferenceSpecifics* pref_specifics = specifics.mutable_preference(); |
424 pref_specifics->set_name("test"); | 424 pref_specifics->set_name("test"); |
425 | 425 |
426 syncer::AttachmentIdList attachment_ids; | 426 syncer::AttachmentIdList attachment_ids; |
427 attachment_ids.push_back(syncer::AttachmentId::Create()); | 427 attachment_ids.push_back(syncer::AttachmentId::Create(0, 0)); |
428 | 428 |
429 // Add a SyncData with two attachments. | 429 // Add a SyncData with two attachments. |
430 syncer::SyncChangeList change_list; | 430 syncer::SyncChangeList change_list; |
431 change_list.push_back( | 431 change_list.push_back( |
432 syncer::SyncChange(FROM_HERE, | 432 syncer::SyncChange(FROM_HERE, |
433 syncer::SyncChange::ACTION_ADD, | 433 syncer::SyncChange::ACTION_ADD, |
434 syncer::SyncData::CreateLocalDataWithAttachments( | 434 syncer::SyncData::CreateLocalDataWithAttachments( |
435 tag, title, specifics, attachment_ids))); | 435 tag, title, specifics, attachment_ids))); |
436 ASSERT_FALSE( | 436 ASSERT_FALSE( |
437 change_processor()->ProcessSyncChanges(FROM_HERE, change_list).IsSet()); | 437 change_processor()->ProcessSyncChanges(FROM_HERE, change_list).IsSet()); |
438 | 438 |
439 sync_pb::AttachmentIdProto attachment_id_proto = attachment_ids[0].GetProto(); | 439 sync_pb::AttachmentIdProto attachment_id_proto = attachment_ids[0].GetProto(); |
440 syncer::AttachmentId attachment_id = | 440 syncer::AttachmentId attachment_id = |
441 syncer::AttachmentId::CreateFromProto(attachment_id_proto); | 441 syncer::AttachmentId::CreateFromProto(attachment_id_proto); |
442 | 442 |
443 change_processor()->OnAttachmentUploaded(attachment_id); | 443 change_processor()->OnAttachmentUploaded(attachment_id); |
444 syncer::ReadTransaction read_transaction(FROM_HERE, user_share()); | 444 syncer::ReadTransaction read_transaction(FROM_HERE, user_share()); |
445 syncer::ReadNode node(&read_transaction); | 445 syncer::ReadNode node(&read_transaction); |
446 ASSERT_EQ(node.InitByClientTagLookup(kType, tag), syncer::BaseNode::INIT_OK); | 446 ASSERT_EQ(node.InitByClientTagLookup(kType, tag), syncer::BaseNode::INIT_OK); |
447 attachment_ids = node.GetAttachmentIds(); | 447 attachment_ids = node.GetAttachmentIds(); |
448 EXPECT_EQ(1U, attachment_ids.size()); | 448 EXPECT_EQ(1U, attachment_ids.size()); |
449 } | 449 } |
450 | 450 |
451 // Verify that upon construction, all attachments not yet on the server are | 451 // Verify that upon construction, all attachments not yet on the server are |
452 // scheduled for upload. | 452 // scheduled for upload. |
453 TEST_F(SyncGenericChangeProcessorTest, UploadAllAttachmentsNotOnServer) { | 453 TEST_F(SyncGenericChangeProcessorTest, UploadAllAttachmentsNotOnServer) { |
454 // Create two attachment ids. id2 will be marked as "on server". | 454 // Create two attachment ids. id2 will be marked as "on server". |
455 syncer::AttachmentId id1 = syncer::AttachmentId::Create(); | 455 syncer::AttachmentId id1 = syncer::AttachmentId::Create(0, 0); |
456 syncer::AttachmentId id2 = syncer::AttachmentId::Create(); | 456 syncer::AttachmentId id2 = syncer::AttachmentId::Create(0, 0); |
457 { | 457 { |
458 // Write an entry containing these two attachment ids. | 458 // Write an entry containing these two attachment ids. |
459 syncer::WriteTransaction trans(FROM_HERE, user_share()); | 459 syncer::WriteTransaction trans(FROM_HERE, user_share()); |
460 syncer::ReadNode root(&trans); | 460 syncer::ReadNode root(&trans); |
461 ASSERT_EQ(syncer::BaseNode::INIT_OK, root.InitTypeRoot(kType)); | 461 ASSERT_EQ(syncer::BaseNode::INIT_OK, root.InitTypeRoot(kType)); |
462 syncer::WriteNode node(&trans); | 462 syncer::WriteNode node(&trans); |
463 node.InitUniqueByCreation(kType, root, "some node"); | 463 node.InitUniqueByCreation(kType, root, "some node"); |
464 sync_pb::AttachmentMetadata metadata; | 464 sync_pb::AttachmentMetadata metadata; |
465 sync_pb::AttachmentMetadataRecord* record1 = metadata.add_record(); | 465 sync_pb::AttachmentMetadataRecord* record1 = metadata.add_record(); |
466 *record1->mutable_id() = id1.GetProto(); | 466 *record1->mutable_id() = id1.GetProto(); |
467 sync_pb::AttachmentMetadataRecord* record2 = metadata.add_record(); | 467 sync_pb::AttachmentMetadataRecord* record2 = metadata.add_record(); |
468 *record2->mutable_id() = id2.GetProto(); | 468 *record2->mutable_id() = id2.GetProto(); |
469 record2->set_is_on_server(true); | 469 record2->set_is_on_server(true); |
470 node.SetAttachmentMetadata(metadata); | 470 node.SetAttachmentMetadata(metadata); |
471 } | 471 } |
472 | 472 |
473 // Construct the GenericChangeProcessor and see that it asks the | 473 // Construct the GenericChangeProcessor and see that it asks the |
474 // AttachmentService to upload id1 only. | 474 // AttachmentService to upload id1 only. |
475 ConstructGenericChangeProcessor(kType); | 475 ConstructGenericChangeProcessor(kType); |
476 ASSERT_EQ(1U, mock_attachment_service()->attachment_id_sets()->size()); | 476 ASSERT_EQ(1U, mock_attachment_service()->attachment_id_sets()->size()); |
477 ASSERT_THAT(mock_attachment_service()->attachment_id_sets()->front(), | 477 ASSERT_THAT(mock_attachment_service()->attachment_id_sets()->front(), |
478 testing::UnorderedElementsAre(id1)); | 478 testing::UnorderedElementsAre(id1)); |
479 } | 479 } |
480 | 480 |
481 } // namespace | 481 } // namespace |
482 | 482 |
483 } // namespace sync_driver | 483 } // namespace sync_driver |
OLD | NEW |