| 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 "sync/internal_api/public/attachments/attachment_service_impl.h" | 5 #include "sync/internal_api/public/attachments/attachment_service_impl.h" |
| 6 | 6 |
| 7 #include "base/bind.h" | 7 #include "base/bind.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 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 72 AttachmentIdList ids = read_ids.back(); | 72 AttachmentIdList ids = read_ids.back(); |
| 73 read_callbacks.pop_back(); | 73 read_callbacks.pop_back(); |
| 74 read_ids.pop_back(); | 74 read_ids.pop_back(); |
| 75 | 75 |
| 76 scoped_ptr<AttachmentMap> attachments(new AttachmentMap()); | 76 scoped_ptr<AttachmentMap> attachments(new AttachmentMap()); |
| 77 scoped_ptr<AttachmentIdList> unavailable_attachments( | 77 scoped_ptr<AttachmentIdList> unavailable_attachments( |
| 78 new AttachmentIdList()); | 78 new AttachmentIdList()); |
| 79 for (AttachmentIdList::const_iterator iter = ids.begin(); iter != ids.end(); | 79 for (AttachmentIdList::const_iterator iter = ids.begin(); iter != ids.end(); |
| 80 ++iter) { | 80 ++iter) { |
| 81 if (local_attachments.find(*iter) != local_attachments.end()) { | 81 if (local_attachments.find(*iter) != local_attachments.end()) { |
| 82 Attachment attachment = Attachment::CreateFromParts(*iter, data); | 82 uint32_t crc32c = ComputeCrc32c(data); |
| 83 Attachment attachment = |
| 84 Attachment::CreateFromParts(*iter, data, crc32c); |
| 83 attachments->insert(std::make_pair(*iter, attachment)); | 85 attachments->insert(std::make_pair(*iter, attachment)); |
| 84 } else { | 86 } else { |
| 85 unavailable_attachments->push_back(*iter); | 87 unavailable_attachments->push_back(*iter); |
| 86 } | 88 } |
| 87 } | 89 } |
| 88 AttachmentStore::Result result = unavailable_attachments->empty() | 90 AttachmentStore::Result result = unavailable_attachments->empty() |
| 89 ? AttachmentStore::SUCCESS | 91 ? AttachmentStore::SUCCESS |
| 90 : AttachmentStore::UNSPECIFIED_ERROR; | 92 : AttachmentStore::UNSPECIFIED_ERROR; |
| 91 | 93 |
| 92 base::MessageLoop::current()->PostTask( | 94 base::MessageLoop::current()->PostTask( |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 128 download_requests.insert(std::make_pair(id, callback)); | 130 download_requests.insert(std::make_pair(id, callback)); |
| 129 } | 131 } |
| 130 | 132 |
| 131 // Multiple requests to download will be active at the same time. | 133 // Multiple requests to download will be active at the same time. |
| 132 // RespondToDownload should respond to only one of them. | 134 // RespondToDownload should respond to only one of them. |
| 133 void RespondToDownload(const AttachmentId& id, const DownloadResult& result) { | 135 void RespondToDownload(const AttachmentId& id, const DownloadResult& result) { |
| 134 ASSERT_TRUE(download_requests.find(id) != download_requests.end()); | 136 ASSERT_TRUE(download_requests.find(id) != download_requests.end()); |
| 135 scoped_ptr<Attachment> attachment; | 137 scoped_ptr<Attachment> attachment; |
| 136 if (result == DOWNLOAD_SUCCESS) { | 138 if (result == DOWNLOAD_SUCCESS) { |
| 137 scoped_refptr<base::RefCountedString> data = new base::RefCountedString(); | 139 scoped_refptr<base::RefCountedString> data = new base::RefCountedString(); |
| 138 attachment.reset(new Attachment(Attachment::CreateFromParts(id, data))); | 140 uint32_t crc32c = ComputeCrc32c(data); |
| 141 attachment.reset( |
| 142 new Attachment(Attachment::CreateFromParts(id, data, crc32c))); |
| 139 } | 143 } |
| 140 base::MessageLoop::current()->PostTask( | 144 base::MessageLoop::current()->PostTask( |
| 141 FROM_HERE, | 145 FROM_HERE, |
| 142 base::Bind(download_requests[id], result, base::Passed(&attachment))); | 146 base::Bind(download_requests[id], result, base::Passed(&attachment))); |
| 143 | 147 |
| 144 download_requests.erase(id); | 148 download_requests.erase(id); |
| 145 } | 149 } |
| 146 | 150 |
| 147 std::map<AttachmentId, DownloadCallback> download_requests; | 151 std::map<AttachmentId, DownloadCallback> download_requests; |
| 148 | 152 |
| (...skipping 161 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 310 RunLoop(); | 314 RunLoop(); |
| 311 store()->RespondToRead(AttachmentIdSet()); | 315 store()->RespondToRead(AttachmentIdSet()); |
| 312 | 316 |
| 313 RunLoop(); | 317 RunLoop(); |
| 314 EXPECT_EQ(1U, download_results().size()); | 318 EXPECT_EQ(1U, download_results().size()); |
| 315 EXPECT_EQ(0U, last_download_attachments().size()); | 319 EXPECT_EQ(0U, last_download_attachments().size()); |
| 316 } | 320 } |
| 317 | 321 |
| 318 TEST_F(AttachmentServiceImplTest, GetOrDownload_Local) { | 322 TEST_F(AttachmentServiceImplTest, GetOrDownload_Local) { |
| 319 AttachmentIdList attachment_ids; | 323 AttachmentIdList attachment_ids; |
| 320 attachment_ids.push_back(AttachmentId::Create(0, 0)); | 324 attachment_ids.push_back(AttachmentId::Create()); |
| 321 attachment_service()->GetOrDownloadAttachments(attachment_ids, | 325 attachment_service()->GetOrDownloadAttachments(attachment_ids, |
| 322 download_callback()); | 326 download_callback()); |
| 323 AttachmentIdSet local_attachments; | 327 AttachmentIdSet local_attachments; |
| 324 local_attachments.insert(attachment_ids[0]); | 328 local_attachments.insert(attachment_ids[0]); |
| 325 RunLoop(); | 329 RunLoop(); |
| 326 store()->RespondToRead(local_attachments); | 330 store()->RespondToRead(local_attachments); |
| 327 | 331 |
| 328 RunLoop(); | 332 RunLoop(); |
| 329 EXPECT_EQ(1U, download_results().size()); | 333 EXPECT_EQ(1U, download_results().size()); |
| 330 EXPECT_EQ(1U, last_download_attachments().size()); | 334 EXPECT_EQ(1U, last_download_attachments().size()); |
| 331 EXPECT_TRUE(last_download_attachments().find(attachment_ids[0]) != | 335 EXPECT_TRUE(last_download_attachments().find(attachment_ids[0]) != |
| 332 last_download_attachments().end()); | 336 last_download_attachments().end()); |
| 333 } | 337 } |
| 334 | 338 |
| 335 TEST_F(AttachmentServiceImplTest, GetOrDownload_LocalRemoteUnavailable) { | 339 TEST_F(AttachmentServiceImplTest, GetOrDownload_LocalRemoteUnavailable) { |
| 336 // Create attachment list with 4 ids. | 340 // Create attachment list with 4 ids. |
| 337 AttachmentIdList attachment_ids; | 341 AttachmentIdList attachment_ids; |
| 338 attachment_ids.push_back(AttachmentId::Create(0, 0)); | 342 attachment_ids.push_back(AttachmentId::Create()); |
| 339 attachment_ids.push_back(AttachmentId::Create(0, 0)); | 343 attachment_ids.push_back(AttachmentId::Create()); |
| 340 attachment_ids.push_back(AttachmentId::Create(0, 0)); | 344 attachment_ids.push_back(AttachmentId::Create()); |
| 341 attachment_ids.push_back(AttachmentId::Create(0, 0)); | 345 attachment_ids.push_back(AttachmentId::Create()); |
| 342 // Call attachment service. | 346 // Call attachment service. |
| 343 attachment_service()->GetOrDownloadAttachments(attachment_ids, | 347 attachment_service()->GetOrDownloadAttachments(attachment_ids, |
| 344 download_callback()); | 348 download_callback()); |
| 345 RunLoop(); | 349 RunLoop(); |
| 346 // Ensure AttachmentStore is called. | 350 // Ensure AttachmentStore is called. |
| 347 EXPECT_FALSE(store()->read_ids.empty()); | 351 EXPECT_FALSE(store()->read_ids.empty()); |
| 348 | 352 |
| 349 // Make AttachmentStore return only attachment 0. | 353 // Make AttachmentStore return only attachment 0. |
| 350 AttachmentIdSet local_attachments; | 354 AttachmentIdSet local_attachments; |
| 351 local_attachments.insert(attachment_ids[0]); | 355 local_attachments.insert(attachment_ids[0]); |
| (...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 398 } | 402 } |
| 399 | 403 |
| 400 TEST_F(AttachmentServiceImplTest, GetOrDownload_NoDownloader) { | 404 TEST_F(AttachmentServiceImplTest, GetOrDownload_NoDownloader) { |
| 401 // No downloader. | 405 // No downloader. |
| 402 InitializeAttachmentService( | 406 InitializeAttachmentService( |
| 403 make_scoped_ptr<MockAttachmentUploader>(new MockAttachmentUploader()), | 407 make_scoped_ptr<MockAttachmentUploader>(new MockAttachmentUploader()), |
| 404 make_scoped_ptr<MockAttachmentDownloader>(NULL), | 408 make_scoped_ptr<MockAttachmentDownloader>(NULL), |
| 405 this); | 409 this); |
| 406 | 410 |
| 407 AttachmentIdList attachment_ids; | 411 AttachmentIdList attachment_ids; |
| 408 attachment_ids.push_back(AttachmentId::Create(0, 0)); | 412 attachment_ids.push_back(AttachmentId::Create()); |
| 409 attachment_service()->GetOrDownloadAttachments(attachment_ids, | 413 attachment_service()->GetOrDownloadAttachments(attachment_ids, |
| 410 download_callback()); | 414 download_callback()); |
| 411 RunLoop(); | 415 RunLoop(); |
| 412 EXPECT_FALSE(store()->read_ids.empty()); | 416 EXPECT_FALSE(store()->read_ids.empty()); |
| 413 | 417 |
| 414 AttachmentIdSet local_attachments; | 418 AttachmentIdSet local_attachments; |
| 415 store()->RespondToRead(local_attachments); | 419 store()->RespondToRead(local_attachments); |
| 416 RunLoop(); | 420 RunLoop(); |
| 417 ASSERT_EQ(1U, download_results().size()); | 421 ASSERT_EQ(1U, download_results().size()); |
| 418 EXPECT_EQ(AttachmentService::GET_UNSPECIFIED_ERROR, download_results()[0]); | 422 EXPECT_EQ(AttachmentService::GET_UNSPECIFIED_ERROR, download_results()[0]); |
| 419 EXPECT_TRUE(last_download_attachments().empty()); | 423 EXPECT_TRUE(last_download_attachments().empty()); |
| 420 } | 424 } |
| 421 | 425 |
| 422 TEST_F(AttachmentServiceImplTest, UploadAttachments_Success) { | 426 TEST_F(AttachmentServiceImplTest, UploadAttachments_Success) { |
| 423 AttachmentIdSet attachment_ids; | 427 AttachmentIdSet attachment_ids; |
| 424 const unsigned num_attachments = 3; | 428 const unsigned num_attachments = 3; |
| 425 for (unsigned i = 0; i < num_attachments; ++i) { | 429 for (unsigned i = 0; i < num_attachments; ++i) { |
| 426 attachment_ids.insert(AttachmentId::Create(0, 0)); | 430 attachment_ids.insert(AttachmentId::Create()); |
| 427 } | 431 } |
| 428 attachment_service()->UploadAttachments(attachment_ids); | 432 attachment_service()->UploadAttachments(attachment_ids); |
| 429 | 433 |
| 430 for (unsigned i = 0; i < num_attachments; ++i) { | 434 for (unsigned i = 0; i < num_attachments; ++i) { |
| 431 RunLoopAndFireTimer(); | 435 RunLoopAndFireTimer(); |
| 432 // See that the service has issued a read for at least one of the | 436 // See that the service has issued a read for at least one of the |
| 433 // attachments. | 437 // attachments. |
| 434 ASSERT_GE(store()->read_ids.size(), 1U); | 438 ASSERT_GE(store()->read_ids.size(), 1U); |
| 435 store()->RespondToRead(attachment_ids); | 439 store()->RespondToRead(attachment_ids); |
| 436 RunLoop(); | 440 RunLoop(); |
| (...skipping 13 matching lines...) Expand all Loading... |
| 450 EXPECT_THAT(on_attachment_uploaded_list(), testing::Contains(*iter)); | 454 EXPECT_THAT(on_attachment_uploaded_list(), testing::Contains(*iter)); |
| 451 } | 455 } |
| 452 } | 456 } |
| 453 | 457 |
| 454 TEST_F(AttachmentServiceImplTest, UploadAttachments_Success_NoDelegate) { | 458 TEST_F(AttachmentServiceImplTest, UploadAttachments_Success_NoDelegate) { |
| 455 InitializeAttachmentService(make_scoped_ptr(new MockAttachmentUploader()), | 459 InitializeAttachmentService(make_scoped_ptr(new MockAttachmentUploader()), |
| 456 make_scoped_ptr(new MockAttachmentDownloader()), | 460 make_scoped_ptr(new MockAttachmentDownloader()), |
| 457 NULL); // No delegate. | 461 NULL); // No delegate. |
| 458 | 462 |
| 459 AttachmentIdSet attachment_ids; | 463 AttachmentIdSet attachment_ids; |
| 460 attachment_ids.insert(AttachmentId::Create(0, 0)); | 464 attachment_ids.insert(AttachmentId::Create()); |
| 461 attachment_service()->UploadAttachments(attachment_ids); | 465 attachment_service()->UploadAttachments(attachment_ids); |
| 462 RunLoopAndFireTimer(); | 466 RunLoopAndFireTimer(); |
| 463 ASSERT_EQ(1U, store()->read_ids.size()); | 467 ASSERT_EQ(1U, store()->read_ids.size()); |
| 464 ASSERT_EQ(0U, uploader()->upload_requests.size()); | 468 ASSERT_EQ(0U, uploader()->upload_requests.size()); |
| 465 store()->RespondToRead(attachment_ids); | 469 store()->RespondToRead(attachment_ids); |
| 466 RunLoop(); | 470 RunLoop(); |
| 467 ASSERT_EQ(0U, store()->read_ids.size()); | 471 ASSERT_EQ(0U, store()->read_ids.size()); |
| 468 ASSERT_EQ(1U, uploader()->upload_requests.size()); | 472 ASSERT_EQ(1U, uploader()->upload_requests.size()); |
| 469 uploader()->RespondToUpload(*attachment_ids.begin(), | 473 uploader()->RespondToUpload(*attachment_ids.begin(), |
| 470 AttachmentUploader::UPLOAD_SUCCESS); | 474 AttachmentUploader::UPLOAD_SUCCESS); |
| 471 RunLoop(); | 475 RunLoop(); |
| 472 ASSERT_TRUE(on_attachment_uploaded_list().empty()); | 476 ASSERT_TRUE(on_attachment_uploaded_list().empty()); |
| 473 } | 477 } |
| 474 | 478 |
| 475 TEST_F(AttachmentServiceImplTest, UploadAttachments_SomeMissingFromStore) { | 479 TEST_F(AttachmentServiceImplTest, UploadAttachments_SomeMissingFromStore) { |
| 476 AttachmentIdSet attachment_ids; | 480 AttachmentIdSet attachment_ids; |
| 477 attachment_ids.insert(AttachmentId::Create(0, 0)); | 481 attachment_ids.insert(AttachmentId::Create()); |
| 478 attachment_ids.insert(AttachmentId::Create(0, 0)); | 482 attachment_ids.insert(AttachmentId::Create()); |
| 479 attachment_service()->UploadAttachments(attachment_ids); | 483 attachment_service()->UploadAttachments(attachment_ids); |
| 480 RunLoopAndFireTimer(); | 484 RunLoopAndFireTimer(); |
| 481 ASSERT_GE(store()->read_ids.size(), 1U); | 485 ASSERT_GE(store()->read_ids.size(), 1U); |
| 482 | 486 |
| 483 ASSERT_EQ(0U, uploader()->upload_requests.size()); | 487 ASSERT_EQ(0U, uploader()->upload_requests.size()); |
| 484 store()->RespondToRead(attachment_ids); | 488 store()->RespondToRead(attachment_ids); |
| 485 RunLoop(); | 489 RunLoop(); |
| 486 ASSERT_EQ(1U, uploader()->upload_requests.size()); | 490 ASSERT_EQ(1U, uploader()->upload_requests.size()); |
| 487 | 491 |
| 488 uploader()->RespondToUpload(uploader()->upload_requests.begin()->first, | 492 uploader()->RespondToUpload(uploader()->upload_requests.begin()->first, |
| 489 AttachmentUploader::UPLOAD_SUCCESS); | 493 AttachmentUploader::UPLOAD_SUCCESS); |
| 490 RunLoopAndFireTimer(); | 494 RunLoopAndFireTimer(); |
| 491 ASSERT_EQ(1U, on_attachment_uploaded_list().size()); | 495 ASSERT_EQ(1U, on_attachment_uploaded_list().size()); |
| 492 ASSERT_GE(store()->read_ids.size(), 1U); | 496 ASSERT_GE(store()->read_ids.size(), 1U); |
| 493 // Not found! | 497 // Not found! |
| 494 store()->RespondToRead(AttachmentIdSet()); | 498 store()->RespondToRead(AttachmentIdSet()); |
| 495 RunLoop(); | 499 RunLoop(); |
| 496 // No upload requests since the read failed. | 500 // No upload requests since the read failed. |
| 497 ASSERT_EQ(0U, uploader()->upload_requests.size()); | 501 ASSERT_EQ(0U, uploader()->upload_requests.size()); |
| 498 } | 502 } |
| 499 | 503 |
| 500 TEST_F(AttachmentServiceImplTest, UploadAttachments_AllMissingFromStore) { | 504 TEST_F(AttachmentServiceImplTest, UploadAttachments_AllMissingFromStore) { |
| 501 AttachmentIdSet attachment_ids; | 505 AttachmentIdSet attachment_ids; |
| 502 const unsigned num_attachments = 2; | 506 const unsigned num_attachments = 2; |
| 503 for (unsigned i = 0; i < num_attachments; ++i) { | 507 for (unsigned i = 0; i < num_attachments; ++i) { |
| 504 attachment_ids.insert(AttachmentId::Create(0, 0)); | 508 attachment_ids.insert(AttachmentId::Create()); |
| 505 } | 509 } |
| 506 attachment_service()->UploadAttachments(attachment_ids); | 510 attachment_service()->UploadAttachments(attachment_ids); |
| 507 | 511 |
| 508 for (unsigned i = 0; i < num_attachments; ++i) { | 512 for (unsigned i = 0; i < num_attachments; ++i) { |
| 509 RunLoopAndFireTimer(); | 513 RunLoopAndFireTimer(); |
| 510 ASSERT_GE(store()->read_ids.size(), 1U); | 514 ASSERT_GE(store()->read_ids.size(), 1U); |
| 511 // None found! | 515 // None found! |
| 512 store()->RespondToRead(AttachmentIdSet()); | 516 store()->RespondToRead(AttachmentIdSet()); |
| 513 } | 517 } |
| 514 RunLoop(); | 518 RunLoop(); |
| 515 | 519 |
| 516 // Nothing uploaded. | 520 // Nothing uploaded. |
| 517 EXPECT_EQ(0U, uploader()->upload_requests.size()); | 521 EXPECT_EQ(0U, uploader()->upload_requests.size()); |
| 518 // See that the delegate was never called. | 522 // See that the delegate was never called. |
| 519 ASSERT_EQ(0U, on_attachment_uploaded_list().size()); | 523 ASSERT_EQ(0U, on_attachment_uploaded_list().size()); |
| 520 } | 524 } |
| 521 | 525 |
| 522 TEST_F(AttachmentServiceImplTest, UploadAttachments_NoUploader) { | 526 TEST_F(AttachmentServiceImplTest, UploadAttachments_NoUploader) { |
| 523 InitializeAttachmentService(make_scoped_ptr<MockAttachmentUploader>(NULL), | 527 InitializeAttachmentService(make_scoped_ptr<MockAttachmentUploader>(NULL), |
| 524 make_scoped_ptr(new MockAttachmentDownloader()), | 528 make_scoped_ptr(new MockAttachmentDownloader()), |
| 525 this); | 529 this); |
| 526 | 530 |
| 527 AttachmentIdSet attachment_ids; | 531 AttachmentIdSet attachment_ids; |
| 528 attachment_ids.insert(AttachmentId::Create(0, 0)); | 532 attachment_ids.insert(AttachmentId::Create()); |
| 529 attachment_service()->UploadAttachments(attachment_ids); | 533 attachment_service()->UploadAttachments(attachment_ids); |
| 530 RunLoop(); | 534 RunLoop(); |
| 531 EXPECT_EQ(0U, store()->read_ids.size()); | 535 EXPECT_EQ(0U, store()->read_ids.size()); |
| 532 ASSERT_EQ(0U, on_attachment_uploaded_list().size()); | 536 ASSERT_EQ(0U, on_attachment_uploaded_list().size()); |
| 533 } | 537 } |
| 534 | 538 |
| 535 // Upload three attachments. For one of them, server responds with error. | 539 // Upload three attachments. For one of them, server responds with error. |
| 536 TEST_F(AttachmentServiceImplTest, UploadAttachments_OneUploadFails) { | 540 TEST_F(AttachmentServiceImplTest, UploadAttachments_OneUploadFails) { |
| 537 AttachmentIdSet attachment_ids; | 541 AttachmentIdSet attachment_ids; |
| 538 const unsigned num_attachments = 3; | 542 const unsigned num_attachments = 3; |
| 539 for (unsigned i = 0; i < num_attachments; ++i) { | 543 for (unsigned i = 0; i < num_attachments; ++i) { |
| 540 attachment_ids.insert(AttachmentId::Create(0, 0)); | 544 attachment_ids.insert(AttachmentId::Create()); |
| 541 } | 545 } |
| 542 attachment_service()->UploadAttachments(attachment_ids); | 546 attachment_service()->UploadAttachments(attachment_ids); |
| 543 | 547 |
| 544 for (unsigned i = 0; i < 3; ++i) { | 548 for (unsigned i = 0; i < 3; ++i) { |
| 545 RunLoopAndFireTimer(); | 549 RunLoopAndFireTimer(); |
| 546 ASSERT_GE(store()->read_ids.size(), 1U); | 550 ASSERT_GE(store()->read_ids.size(), 1U); |
| 547 store()->RespondToRead(attachment_ids); | 551 store()->RespondToRead(attachment_ids); |
| 548 RunLoop(); | 552 RunLoop(); |
| 549 ASSERT_EQ(1U, uploader()->upload_requests.size()); | 553 ASSERT_EQ(1U, uploader()->upload_requests.size()); |
| 550 AttachmentUploader::UploadResult result = | 554 AttachmentUploader::UploadResult result = |
| 551 AttachmentUploader::UPLOAD_SUCCESS; | 555 AttachmentUploader::UPLOAD_SUCCESS; |
| 552 // Fail the 2nd one. | 556 // Fail the 2nd one. |
| 553 if (i == 2U) { | 557 if (i == 2U) { |
| 554 result = AttachmentUploader::UPLOAD_UNSPECIFIED_ERROR; | 558 result = AttachmentUploader::UPLOAD_UNSPECIFIED_ERROR; |
| 555 } else { | 559 } else { |
| 556 result = AttachmentUploader::UPLOAD_SUCCESS; | 560 result = AttachmentUploader::UPLOAD_SUCCESS; |
| 557 } | 561 } |
| 558 uploader()->RespondToUpload(uploader()->upload_requests.begin()->first, | 562 uploader()->RespondToUpload(uploader()->upload_requests.begin()->first, |
| 559 result); | 563 result); |
| 560 RunLoop(); | 564 RunLoop(); |
| 561 } | 565 } |
| 562 ASSERT_EQ(2U, on_attachment_uploaded_list().size()); | 566 ASSERT_EQ(2U, on_attachment_uploaded_list().size()); |
| 563 } | 567 } |
| 564 | 568 |
| 565 // Attempt an upload, respond with transient error to trigger backoff, issue | 569 // Attempt an upload, respond with transient error to trigger backoff, issue |
| 566 // network disconnect/connect events and see that backoff is cleared. | 570 // network disconnect/connect events and see that backoff is cleared. |
| 567 TEST_F(AttachmentServiceImplTest, | 571 TEST_F(AttachmentServiceImplTest, |
| 568 UploadAttachments_ResetBackoffAfterNetworkChange) { | 572 UploadAttachments_ResetBackoffAfterNetworkChange) { |
| 569 AttachmentIdSet attachment_ids; | 573 AttachmentIdSet attachment_ids; |
| 570 attachment_ids.insert(AttachmentId::Create(0, 0)); | 574 attachment_ids.insert(AttachmentId::Create()); |
| 571 attachment_service()->UploadAttachments(attachment_ids); | 575 attachment_service()->UploadAttachments(attachment_ids); |
| 572 | 576 |
| 573 RunLoopAndFireTimer(); | 577 RunLoopAndFireTimer(); |
| 574 ASSERT_EQ(1U, store()->read_ids.size()); | 578 ASSERT_EQ(1U, store()->read_ids.size()); |
| 575 store()->RespondToRead(attachment_ids); | 579 store()->RespondToRead(attachment_ids); |
| 576 RunLoop(); | 580 RunLoop(); |
| 577 ASSERT_EQ(1U, uploader()->upload_requests.size()); | 581 ASSERT_EQ(1U, uploader()->upload_requests.size()); |
| 578 | 582 |
| 579 uploader()->RespondToUpload(uploader()->upload_requests.begin()->first, | 583 uploader()->RespondToUpload(uploader()->upload_requests.begin()->first, |
| 580 AttachmentUploader::UPLOAD_TRANSIENT_ERROR); | 584 AttachmentUploader::UPLOAD_TRANSIENT_ERROR); |
| (...skipping 16 matching lines...) Expand all Loading... |
| 597 net::NetworkChangeNotifier::NotifyObserversOfNetworkChangeForTests( | 601 net::NetworkChangeNotifier::NotifyObserversOfNetworkChangeForTests( |
| 598 net::NetworkChangeNotifier::CONNECTION_WIFI); | 602 net::NetworkChangeNotifier::CONNECTION_WIFI); |
| 599 RunLoop(); | 603 RunLoop(); |
| 600 | 604 |
| 601 // No longer in backoff. | 605 // No longer in backoff. |
| 602 ASSERT_TRUE(mock_timer()->IsRunning()); | 606 ASSERT_TRUE(mock_timer()->IsRunning()); |
| 603 ASSERT_EQ(base::TimeDelta(), mock_timer()->GetCurrentDelay()); | 607 ASSERT_EQ(base::TimeDelta(), mock_timer()->GetCurrentDelay()); |
| 604 } | 608 } |
| 605 | 609 |
| 606 } // namespace syncer | 610 } // namespace syncer |
| OLD | NEW |