| 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" |
| 11 #include "base/thread_task_runner_handle.h" |
| 11 #include "base/timer/mock_timer.h" | 12 #include "base/timer/mock_timer.h" |
| 13 #include "sync/api/attachments/attachment_store_backend.h" |
| 12 #include "sync/internal_api/public/attachments/attachment_util.h" | 14 #include "sync/internal_api/public/attachments/attachment_util.h" |
| 13 #include "sync/internal_api/public/attachments/fake_attachment_downloader.h" | 15 #include "sync/internal_api/public/attachments/fake_attachment_downloader.h" |
| 14 #include "sync/internal_api/public/attachments/fake_attachment_uploader.h" | 16 #include "sync/internal_api/public/attachments/fake_attachment_uploader.h" |
| 15 #include "testing/gmock/include/gmock/gmock-matchers.h" | 17 #include "testing/gmock/include/gmock/gmock-matchers.h" |
| 16 #include "testing/gtest/include/gtest/gtest.h" | 18 #include "testing/gtest/include/gtest/gtest.h" |
| 17 | 19 |
| 18 namespace syncer { | 20 namespace syncer { |
| 19 | 21 |
| 20 namespace { | 22 namespace { |
| 21 | 23 |
| 22 class MockAttachmentStore : public AttachmentStore, | 24 class MockAttachmentStoreBackend |
| 23 public base::SupportsWeakPtr<MockAttachmentStore> { | 25 : public AttachmentStoreBackend, |
| 26 public base::SupportsWeakPtr<MockAttachmentStoreBackend> { |
| 24 public: | 27 public: |
| 25 MockAttachmentStore() {} | 28 MockAttachmentStoreBackend( |
| 29 const scoped_refptr<base::SequencedTaskRunner>& callback_task_runner) |
| 30 : AttachmentStoreBackend(callback_task_runner) {} |
| 26 | 31 |
| 27 void Init(const InitCallback& callback) override { | 32 ~MockAttachmentStoreBackend() override {} |
| 28 } | 33 |
| 34 void Init(const AttachmentStore::InitCallback& callback) override {} |
| 29 | 35 |
| 30 void Read(const AttachmentIdList& ids, | 36 void Read(const AttachmentIdList& ids, |
| 31 const ReadCallback& callback) override { | 37 const AttachmentStore::ReadCallback& callback) override { |
| 32 read_ids.push_back(ids); | 38 read_ids.push_back(ids); |
| 33 read_callbacks.push_back(callback); | 39 read_callbacks.push_back(callback); |
| 34 } | 40 } |
| 35 | 41 |
| 36 void Write(const AttachmentList& attachments, | 42 void Write(AttachmentStore::AttachmentReferrer referrer, |
| 37 const WriteCallback& callback) override { | 43 const AttachmentList& attachments, |
| 44 const AttachmentStore::WriteCallback& callback) override { |
| 38 write_attachments.push_back(attachments); | 45 write_attachments.push_back(attachments); |
| 39 write_callbacks.push_back(callback); | 46 write_callbacks.push_back(callback); |
| 40 } | 47 } |
| 41 | 48 |
| 42 void Drop(const AttachmentIdList& ids, | 49 void Drop(AttachmentStore::AttachmentReferrer referrer, |
| 43 const DropCallback& callback) override { | 50 const AttachmentIdList& ids, |
| 51 const AttachmentStore::DropCallback& callback) override { |
| 44 NOTREACHED(); | 52 NOTREACHED(); |
| 45 } | 53 } |
| 46 | 54 |
| 47 void ReadMetadata(const AttachmentIdList& ids, | 55 void ReadMetadata( |
| 48 const ReadMetadataCallback& callback) override { | 56 const AttachmentIdList& ids, |
| 57 const AttachmentStore::ReadMetadataCallback& callback) override { |
| 49 NOTREACHED(); | 58 NOTREACHED(); |
| 50 } | 59 } |
| 51 | 60 |
| 52 void ReadAllMetadata(const ReadMetadataCallback& callback) override { | 61 void ReadAllMetadata( |
| 62 AttachmentStore::AttachmentReferrer referrer, |
| 63 const AttachmentStore::ReadMetadataCallback& callback) override { |
| 53 NOTREACHED(); | 64 NOTREACHED(); |
| 54 } | 65 } |
| 55 | 66 |
| 56 // Respond to Read request. Attachments found in local_attachments should be | 67 // Respond to Read request. Attachments found in local_attachments should be |
| 57 // returned, everything else should be reported unavailable. | 68 // returned, everything else should be reported unavailable. |
| 58 void RespondToRead(const AttachmentIdSet& local_attachments) { | 69 void RespondToRead(const AttachmentIdSet& local_attachments) { |
| 59 scoped_refptr<base::RefCountedString> data = new base::RefCountedString(); | 70 scoped_refptr<base::RefCountedString> data = new base::RefCountedString(); |
| 60 ReadCallback callback = read_callbacks.back(); | 71 AttachmentStore::ReadCallback callback = read_callbacks.back(); |
| 61 AttachmentIdList ids = read_ids.back(); | 72 AttachmentIdList ids = read_ids.back(); |
| 62 read_callbacks.pop_back(); | 73 read_callbacks.pop_back(); |
| 63 read_ids.pop_back(); | 74 read_ids.pop_back(); |
| 64 | 75 |
| 65 scoped_ptr<AttachmentMap> attachments(new AttachmentMap()); | 76 scoped_ptr<AttachmentMap> attachments(new AttachmentMap()); |
| 66 scoped_ptr<AttachmentIdList> unavailable_attachments( | 77 scoped_ptr<AttachmentIdList> unavailable_attachments( |
| 67 new AttachmentIdList()); | 78 new AttachmentIdList()); |
| 68 for (AttachmentIdList::const_iterator iter = ids.begin(); iter != ids.end(); | 79 for (AttachmentIdList::const_iterator iter = ids.begin(); iter != ids.end(); |
| 69 ++iter) { | 80 ++iter) { |
| 70 if (local_attachments.find(*iter) != local_attachments.end()) { | 81 if (local_attachments.find(*iter) != local_attachments.end()) { |
| 71 uint32_t crc32c = ComputeCrc32c(data); | 82 uint32_t crc32c = ComputeCrc32c(data); |
| 72 Attachment attachment = | 83 Attachment attachment = |
| 73 Attachment::CreateFromParts(*iter, data, crc32c); | 84 Attachment::CreateFromParts(*iter, data, crc32c); |
| 74 attachments->insert(std::make_pair(*iter, attachment)); | 85 attachments->insert(std::make_pair(*iter, attachment)); |
| 75 } else { | 86 } else { |
| 76 unavailable_attachments->push_back(*iter); | 87 unavailable_attachments->push_back(*iter); |
| 77 } | 88 } |
| 78 } | 89 } |
| 79 Result result = | 90 AttachmentStore::Result result = unavailable_attachments->empty() |
| 80 unavailable_attachments->empty() ? SUCCESS : UNSPECIFIED_ERROR; | 91 ? AttachmentStore::SUCCESS |
| 92 : AttachmentStore::UNSPECIFIED_ERROR; |
| 81 | 93 |
| 82 base::MessageLoop::current()->PostTask( | 94 base::MessageLoop::current()->PostTask( |
| 83 FROM_HERE, | 95 FROM_HERE, |
| 84 base::Bind(callback, | 96 base::Bind(callback, |
| 85 result, | 97 result, |
| 86 base::Passed(&attachments), | 98 base::Passed(&attachments), |
| 87 base::Passed(&unavailable_attachments))); | 99 base::Passed(&unavailable_attachments))); |
| 88 } | 100 } |
| 89 | 101 |
| 90 // Respond to Write request with |result|. | 102 // Respond to Write request with |result|. |
| 91 void RespondToWrite(const Result& result) { | 103 void RespondToWrite(const AttachmentStore::Result& result) { |
| 92 WriteCallback callback = write_callbacks.back(); | 104 AttachmentStore::WriteCallback callback = write_callbacks.back(); |
| 93 AttachmentList attachments = write_attachments.back(); | 105 AttachmentList attachments = write_attachments.back(); |
| 94 write_callbacks.pop_back(); | 106 write_callbacks.pop_back(); |
| 95 write_attachments.pop_back(); | 107 write_attachments.pop_back(); |
| 96 base::MessageLoop::current()->PostTask(FROM_HERE, | 108 base::MessageLoop::current()->PostTask(FROM_HERE, |
| 97 base::Bind(callback, result)); | 109 base::Bind(callback, result)); |
| 98 } | 110 } |
| 99 | 111 |
| 100 std::vector<AttachmentIdList> read_ids; | 112 std::vector<AttachmentIdList> read_ids; |
| 101 std::vector<ReadCallback> read_callbacks; | 113 std::vector<AttachmentStore::ReadCallback> read_callbacks; |
| 102 std::vector<AttachmentList> write_attachments; | 114 std::vector<AttachmentList> write_attachments; |
| 103 std::vector<WriteCallback> write_callbacks; | 115 std::vector<AttachmentStore::WriteCallback> write_callbacks; |
| 104 | 116 |
| 105 private: | 117 private: |
| 106 ~MockAttachmentStore() override {} | 118 DISALLOW_COPY_AND_ASSIGN(MockAttachmentStoreBackend); |
| 107 | |
| 108 DISALLOW_COPY_AND_ASSIGN(MockAttachmentStore); | |
| 109 }; | 119 }; |
| 110 | 120 |
| 111 class MockAttachmentDownloader | 121 class MockAttachmentDownloader |
| 112 : public AttachmentDownloader, | 122 : public AttachmentDownloader, |
| 113 public base::SupportsWeakPtr<MockAttachmentDownloader> { | 123 public base::SupportsWeakPtr<MockAttachmentDownloader> { |
| 114 public: | 124 public: |
| 115 MockAttachmentDownloader() {} | 125 MockAttachmentDownloader() {} |
| 116 | 126 |
| 117 void DownloadAttachment(const AttachmentId& id, | 127 void DownloadAttachment(const AttachmentId& id, |
| 118 const DownloadCallback& callback) override { | 128 const DownloadCallback& callback) override { |
| (...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 178 | 188 |
| 179 void SetUp() override { | 189 void SetUp() override { |
| 180 network_change_notifier_.reset(net::NetworkChangeNotifier::CreateMock()); | 190 network_change_notifier_.reset(net::NetworkChangeNotifier::CreateMock()); |
| 181 InitializeAttachmentService(make_scoped_ptr(new MockAttachmentUploader()), | 191 InitializeAttachmentService(make_scoped_ptr(new MockAttachmentUploader()), |
| 182 make_scoped_ptr(new MockAttachmentDownloader()), | 192 make_scoped_ptr(new MockAttachmentDownloader()), |
| 183 this); | 193 this); |
| 184 } | 194 } |
| 185 | 195 |
| 186 void TearDown() override { | 196 void TearDown() override { |
| 187 attachment_service_.reset(); | 197 attachment_service_.reset(); |
| 188 ASSERT_FALSE(attachment_store_); | 198 RunLoop(); |
| 199 ASSERT_FALSE(attachment_store_backend_); |
| 189 ASSERT_FALSE(attachment_uploader_); | 200 ASSERT_FALSE(attachment_uploader_); |
| 190 ASSERT_FALSE(attachment_downloader_); | 201 ASSERT_FALSE(attachment_downloader_); |
| 191 } | 202 } |
| 192 | 203 |
| 193 // AttachmentService::Delegate implementation. | 204 // AttachmentService::Delegate implementation. |
| 194 void OnAttachmentUploaded(const AttachmentId& attachment_id) override { | 205 void OnAttachmentUploaded(const AttachmentId& attachment_id) override { |
| 195 on_attachment_uploaded_list_.push_back(attachment_id); | 206 on_attachment_uploaded_list_.push_back(attachment_id); |
| 196 } | 207 } |
| 197 | 208 |
| 198 void InitializeAttachmentService( | 209 void InitializeAttachmentService( |
| 199 scoped_ptr<MockAttachmentUploader> uploader, | 210 scoped_ptr<MockAttachmentUploader> uploader, |
| 200 scoped_ptr<MockAttachmentDownloader> downloader, | 211 scoped_ptr<MockAttachmentDownloader> downloader, |
| 201 AttachmentService::Delegate* delegate) { | 212 AttachmentService::Delegate* delegate) { |
| 202 scoped_refptr<MockAttachmentStore> attachment_store( | 213 // Initialize mock attachment store |
| 203 new MockAttachmentStore()); | 214 scoped_refptr<base::SingleThreadTaskRunner> runner = |
| 204 attachment_store_ = attachment_store->AsWeakPtr(); | 215 base::ThreadTaskRunnerHandle::Get(); |
| 216 scoped_ptr<MockAttachmentStoreBackend> attachment_store_backend( |
| 217 new MockAttachmentStoreBackend(runner)); |
| 218 attachment_store_backend_ = attachment_store_backend->AsWeakPtr(); |
| 219 scoped_ptr<AttachmentStore> attachment_store = |
| 220 AttachmentStore::CreateMockStoreForTest( |
| 221 attachment_store_backend.Pass()); |
| 205 | 222 |
| 206 if (uploader.get()) { | 223 if (uploader.get()) { |
| 207 attachment_uploader_ = uploader->AsWeakPtr(); | 224 attachment_uploader_ = uploader->AsWeakPtr(); |
| 208 } | 225 } |
| 209 if (downloader.get()) { | 226 if (downloader.get()) { |
| 210 attachment_downloader_ = downloader->AsWeakPtr(); | 227 attachment_downloader_ = downloader->AsWeakPtr(); |
| 211 } | 228 } |
| 212 attachment_service_.reset( | 229 attachment_service_.reset(new AttachmentServiceImpl( |
| 213 new AttachmentServiceImpl(attachment_store, | 230 attachment_store.Pass(), uploader.Pass(), downloader.Pass(), delegate, |
| 214 uploader.Pass(), | 231 base::TimeDelta::FromMinutes(1), base::TimeDelta::FromMinutes(8))); |
| 215 downloader.Pass(), | |
| 216 delegate, | |
| 217 base::TimeDelta::FromMinutes(1), | |
| 218 base::TimeDelta::FromMinutes(8))); | |
| 219 | 232 |
| 220 scoped_ptr<base::MockTimer> timer_to_pass( | 233 scoped_ptr<base::MockTimer> timer_to_pass( |
| 221 new base::MockTimer(false, false)); | 234 new base::MockTimer(false, false)); |
| 222 mock_timer_ = timer_to_pass.get(); | 235 mock_timer_ = timer_to_pass.get(); |
| 223 attachment_service_->SetTimerForTest(timer_to_pass.Pass()); | 236 attachment_service_->SetTimerForTest(timer_to_pass.Pass()); |
| 224 } | 237 } |
| 225 | 238 |
| 226 AttachmentService* attachment_service() { return attachment_service_.get(); } | 239 AttachmentService* attachment_service() { return attachment_service_.get(); } |
| 227 | 240 |
| 228 base::MockTimer* mock_timer() { return mock_timer_; } | 241 base::MockTimer* mock_timer() { return mock_timer_; } |
| (...skipping 11 matching lines...) Expand all Loading... |
| 240 | 253 |
| 241 void RunLoop() { | 254 void RunLoop() { |
| 242 base::RunLoop run_loop; | 255 base::RunLoop run_loop; |
| 243 run_loop.RunUntilIdle(); | 256 run_loop.RunUntilIdle(); |
| 244 } | 257 } |
| 245 | 258 |
| 246 void RunLoopAndFireTimer() { | 259 void RunLoopAndFireTimer() { |
| 247 RunLoop(); | 260 RunLoop(); |
| 248 if (mock_timer()->IsRunning()) { | 261 if (mock_timer()->IsRunning()) { |
| 249 mock_timer()->Fire(); | 262 mock_timer()->Fire(); |
| 263 RunLoop(); |
| 250 } | 264 } |
| 251 RunLoop(); | |
| 252 } | 265 } |
| 253 | 266 |
| 254 const std::vector<AttachmentService::GetOrDownloadResult>& | 267 const std::vector<AttachmentService::GetOrDownloadResult>& |
| 255 download_results() const { | 268 download_results() const { |
| 256 return download_results_; | 269 return download_results_; |
| 257 } | 270 } |
| 258 | 271 |
| 259 const AttachmentMap& last_download_attachments() const { | 272 const AttachmentMap& last_download_attachments() const { |
| 260 return *last_download_attachments_.get(); | 273 return *last_download_attachments_.get(); |
| 261 } | 274 } |
| 262 | 275 |
| 263 net::NetworkChangeNotifier* network_change_notifier() { | 276 net::NetworkChangeNotifier* network_change_notifier() { |
| 264 return network_change_notifier_.get(); | 277 return network_change_notifier_.get(); |
| 265 } | 278 } |
| 266 | 279 |
| 267 MockAttachmentStore* store() { return attachment_store_.get(); } | 280 MockAttachmentStoreBackend* store() { |
| 281 return attachment_store_backend_.get(); |
| 282 } |
| 268 | 283 |
| 269 MockAttachmentDownloader* downloader() { | 284 MockAttachmentDownloader* downloader() { |
| 270 return attachment_downloader_.get(); | 285 return attachment_downloader_.get(); |
| 271 } | 286 } |
| 272 | 287 |
| 273 MockAttachmentUploader* uploader() { | 288 MockAttachmentUploader* uploader() { |
| 274 return attachment_uploader_.get(); | 289 return attachment_uploader_.get(); |
| 275 } | 290 } |
| 276 | 291 |
| 277 const std::vector<AttachmentId>& on_attachment_uploaded_list() const { | 292 const std::vector<AttachmentId>& on_attachment_uploaded_list() const { |
| 278 return on_attachment_uploaded_list_; | 293 return on_attachment_uploaded_list_; |
| 279 } | 294 } |
| 280 | 295 |
| 281 private: | 296 private: |
| 282 base::MessageLoop message_loop_; | 297 base::MessageLoop message_loop_; |
| 283 scoped_ptr<net::NetworkChangeNotifier> network_change_notifier_; | 298 scoped_ptr<net::NetworkChangeNotifier> network_change_notifier_; |
| 284 base::WeakPtr<MockAttachmentStore> attachment_store_; | 299 base::WeakPtr<MockAttachmentStoreBackend> attachment_store_backend_; |
| 285 base::WeakPtr<MockAttachmentDownloader> attachment_downloader_; | 300 base::WeakPtr<MockAttachmentDownloader> attachment_downloader_; |
| 286 base::WeakPtr<MockAttachmentUploader> attachment_uploader_; | 301 base::WeakPtr<MockAttachmentUploader> attachment_uploader_; |
| 287 scoped_ptr<AttachmentServiceImpl> attachment_service_; | 302 scoped_ptr<AttachmentServiceImpl> attachment_service_; |
| 288 base::MockTimer* mock_timer_; // not owned | 303 base::MockTimer* mock_timer_; // not owned |
| 289 | 304 |
| 290 std::vector<AttachmentService::GetOrDownloadResult> download_results_; | 305 std::vector<AttachmentService::GetOrDownloadResult> download_results_; |
| 291 scoped_ptr<AttachmentMap> last_download_attachments_; | 306 scoped_ptr<AttachmentMap> last_download_attachments_; |
| 292 std::vector<AttachmentId> on_attachment_uploaded_list_; | 307 std::vector<AttachmentId> on_attachment_uploaded_list_; |
| 293 }; | 308 }; |
| 294 | 309 |
| 295 TEST_F(AttachmentServiceImplTest, GetStore) { | |
| 296 EXPECT_EQ(store(), attachment_service()->GetStore()); | |
| 297 } | |
| 298 | |
| 299 TEST_F(AttachmentServiceImplTest, GetOrDownload_EmptyAttachmentList) { | 310 TEST_F(AttachmentServiceImplTest, GetOrDownload_EmptyAttachmentList) { |
| 300 AttachmentIdList attachment_ids; | 311 AttachmentIdList attachment_ids; |
| 301 attachment_service()->GetOrDownloadAttachments(attachment_ids, | 312 attachment_service()->GetOrDownloadAttachments(attachment_ids, |
| 302 download_callback()); | 313 download_callback()); |
| 314 RunLoop(); |
| 303 store()->RespondToRead(AttachmentIdSet()); | 315 store()->RespondToRead(AttachmentIdSet()); |
| 304 | 316 |
| 305 RunLoop(); | 317 RunLoop(); |
| 306 EXPECT_EQ(1U, download_results().size()); | 318 EXPECT_EQ(1U, download_results().size()); |
| 307 EXPECT_EQ(0U, last_download_attachments().size()); | 319 EXPECT_EQ(0U, last_download_attachments().size()); |
| 308 } | 320 } |
| 309 | 321 |
| 310 TEST_F(AttachmentServiceImplTest, GetOrDownload_Local) { | 322 TEST_F(AttachmentServiceImplTest, GetOrDownload_Local) { |
| 311 AttachmentIdList attachment_ids; | 323 AttachmentIdList attachment_ids; |
| 312 attachment_ids.push_back(AttachmentId::Create()); | 324 attachment_ids.push_back(AttachmentId::Create()); |
| 313 attachment_service()->GetOrDownloadAttachments(attachment_ids, | 325 attachment_service()->GetOrDownloadAttachments(attachment_ids, |
| 314 download_callback()); | 326 download_callback()); |
| 315 AttachmentIdSet local_attachments; | 327 AttachmentIdSet local_attachments; |
| 316 local_attachments.insert(attachment_ids[0]); | 328 local_attachments.insert(attachment_ids[0]); |
| 329 RunLoop(); |
| 317 store()->RespondToRead(local_attachments); | 330 store()->RespondToRead(local_attachments); |
| 318 | 331 |
| 319 RunLoop(); | 332 RunLoop(); |
| 320 EXPECT_EQ(1U, download_results().size()); | 333 EXPECT_EQ(1U, download_results().size()); |
| 321 EXPECT_EQ(1U, last_download_attachments().size()); | 334 EXPECT_EQ(1U, last_download_attachments().size()); |
| 322 EXPECT_TRUE(last_download_attachments().find(attachment_ids[0]) != | 335 EXPECT_TRUE(last_download_attachments().find(attachment_ids[0]) != |
| 323 last_download_attachments().end()); | 336 last_download_attachments().end()); |
| 324 } | 337 } |
| 325 | 338 |
| 326 TEST_F(AttachmentServiceImplTest, GetOrDownload_LocalRemoteUnavailable) { | 339 TEST_F(AttachmentServiceImplTest, GetOrDownload_LocalRemoteUnavailable) { |
| 327 // Create attachment list with 4 ids. | 340 // Create attachment list with 4 ids. |
| 328 AttachmentIdList attachment_ids; | 341 AttachmentIdList attachment_ids; |
| 329 attachment_ids.push_back(AttachmentId::Create()); | 342 attachment_ids.push_back(AttachmentId::Create()); |
| 330 attachment_ids.push_back(AttachmentId::Create()); | 343 attachment_ids.push_back(AttachmentId::Create()); |
| 331 attachment_ids.push_back(AttachmentId::Create()); | 344 attachment_ids.push_back(AttachmentId::Create()); |
| 332 attachment_ids.push_back(AttachmentId::Create()); | 345 attachment_ids.push_back(AttachmentId::Create()); |
| 333 // Call attachment service. | 346 // Call attachment service. |
| 334 attachment_service()->GetOrDownloadAttachments(attachment_ids, | 347 attachment_service()->GetOrDownloadAttachments(attachment_ids, |
| 335 download_callback()); | 348 download_callback()); |
| 349 RunLoop(); |
| 336 // Ensure AttachmentStore is called. | 350 // Ensure AttachmentStore is called. |
| 337 EXPECT_FALSE(store()->read_ids.empty()); | 351 EXPECT_FALSE(store()->read_ids.empty()); |
| 338 | 352 |
| 339 // Make AttachmentStore return only attachment 0. | 353 // Make AttachmentStore return only attachment 0. |
| 340 AttachmentIdSet local_attachments; | 354 AttachmentIdSet local_attachments; |
| 341 local_attachments.insert(attachment_ids[0]); | 355 local_attachments.insert(attachment_ids[0]); |
| 342 store()->RespondToRead(local_attachments); | 356 store()->RespondToRead(local_attachments); |
| 343 RunLoop(); | 357 RunLoop(); |
| 344 // Ensure Downloader called with right attachment ids | 358 // Ensure Downloader called with right attachment ids |
| 345 EXPECT_EQ(3U, downloader()->download_requests.size()); | 359 EXPECT_EQ(3U, downloader()->download_requests.size()); |
| (...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 391 // No downloader. | 405 // No downloader. |
| 392 InitializeAttachmentService( | 406 InitializeAttachmentService( |
| 393 make_scoped_ptr<MockAttachmentUploader>(new MockAttachmentUploader()), | 407 make_scoped_ptr<MockAttachmentUploader>(new MockAttachmentUploader()), |
| 394 make_scoped_ptr<MockAttachmentDownloader>(NULL), | 408 make_scoped_ptr<MockAttachmentDownloader>(NULL), |
| 395 this); | 409 this); |
| 396 | 410 |
| 397 AttachmentIdList attachment_ids; | 411 AttachmentIdList attachment_ids; |
| 398 attachment_ids.push_back(AttachmentId::Create()); | 412 attachment_ids.push_back(AttachmentId::Create()); |
| 399 attachment_service()->GetOrDownloadAttachments(attachment_ids, | 413 attachment_service()->GetOrDownloadAttachments(attachment_ids, |
| 400 download_callback()); | 414 download_callback()); |
| 415 RunLoop(); |
| 401 EXPECT_FALSE(store()->read_ids.empty()); | 416 EXPECT_FALSE(store()->read_ids.empty()); |
| 402 | 417 |
| 403 AttachmentIdSet local_attachments; | 418 AttachmentIdSet local_attachments; |
| 404 store()->RespondToRead(local_attachments); | 419 store()->RespondToRead(local_attachments); |
| 405 RunLoop(); | 420 RunLoop(); |
| 406 ASSERT_EQ(1U, download_results().size()); | 421 ASSERT_EQ(1U, download_results().size()); |
| 407 EXPECT_EQ(AttachmentService::GET_UNSPECIFIED_ERROR, download_results()[0]); | 422 EXPECT_EQ(AttachmentService::GET_UNSPECIFIED_ERROR, download_results()[0]); |
| 408 EXPECT_TRUE(last_download_attachments().empty()); | 423 EXPECT_TRUE(last_download_attachments().empty()); |
| 409 } | 424 } |
| 410 | 425 |
| (...skipping 175 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 586 net::NetworkChangeNotifier::NotifyObserversOfNetworkChangeForTests( | 601 net::NetworkChangeNotifier::NotifyObserversOfNetworkChangeForTests( |
| 587 net::NetworkChangeNotifier::CONNECTION_WIFI); | 602 net::NetworkChangeNotifier::CONNECTION_WIFI); |
| 588 RunLoop(); | 603 RunLoop(); |
| 589 | 604 |
| 590 // No longer in backoff. | 605 // No longer in backoff. |
| 591 ASSERT_TRUE(mock_timer()->IsRunning()); | 606 ASSERT_TRUE(mock_timer()->IsRunning()); |
| 592 ASSERT_EQ(base::TimeDelta(), mock_timer()->GetCurrentDelay()); | 607 ASSERT_EQ(base::TimeDelta(), mock_timer()->GetCurrentDelay()); |
| 593 } | 608 } |
| 594 | 609 |
| 595 } // namespace syncer | 610 } // namespace syncer |
| OLD | NEW |