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