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

Side by Side Diff: sync/internal_api/attachments/attachment_downloader_impl_unittest.cc

Issue 554743004: Update AttachmentServiceImpl to retry attachment uploads. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Merge with master. Created 6 years, 3 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 "sync/internal_api/public/attachments/attachment_downloader.h" 5 #include "sync/internal_api/public/attachments/attachment_downloader.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 301 matching lines...) Expand 10 before | Expand all | Expand 10 after
312 GoogleServiceAuthError::AuthErrorNone()); 312 GoogleServiceAuthError::AuthErrorNone());
313 RunMessageLoop(); 313 RunMessageLoop();
314 // Trigger second RequestAccessToken. 314 // Trigger second RequestAccessToken.
315 downloader()->DownloadAttachment(id2, download_callback(id2)); 315 downloader()->DownloadAttachment(id2, download_callback(id2));
316 RunMessageLoop(); 316 RunMessageLoop();
317 // Fail RequestAccessToken. 317 // Fail RequestAccessToken.
318 token_service()->RespondToAccessTokenRequest( 318 token_service()->RespondToAccessTokenRequest(
319 GoogleServiceAuthError(GoogleServiceAuthError::INVALID_GAIA_CREDENTIALS)); 319 GoogleServiceAuthError(GoogleServiceAuthError::INVALID_GAIA_CREDENTIALS));
320 RunMessageLoop(); 320 RunMessageLoop();
321 // Only id2 should fail. 321 // Only id2 should fail.
322 VerifyDownloadResult(id2, AttachmentDownloader::DOWNLOAD_UNSPECIFIED_ERROR); 322 VerifyDownloadResult(id2, AttachmentDownloader::DOWNLOAD_TRANSIENT_ERROR);
323 // Complete request for id1. 323 // Complete request for id1.
324 CompleteDownload(net::HTTP_OK); 324 CompleteDownload(net::HTTP_OK);
325 VerifyDownloadResult(id1, AttachmentDownloader::DOWNLOAD_SUCCESS); 325 VerifyDownloadResult(id1, AttachmentDownloader::DOWNLOAD_SUCCESS);
326 } 326 }
327 327
328 TEST_F(AttachmentDownloaderImplTest, URLFetcher_BadToken) { 328 TEST_F(AttachmentDownloaderImplTest, URLFetcher_BadToken) {
329 AttachmentId id1 = AttachmentId::Create(); 329 AttachmentId id1 = AttachmentId::Create();
330 downloader()->DownloadAttachment(id1, download_callback(id1)); 330 downloader()->DownloadAttachment(id1, download_callback(id1));
331 RunMessageLoop(); 331 RunMessageLoop();
332 // Return valid access token. 332 // Return valid access token.
333 token_service()->RespondToAccessTokenRequest( 333 token_service()->RespondToAccessTokenRequest(
334 GoogleServiceAuthError::AuthErrorNone()); 334 GoogleServiceAuthError::AuthErrorNone());
335 RunMessageLoop(); 335 RunMessageLoop();
336 // Fail URLFetcher. This should trigger download failure and access token 336 // Fail URLFetcher. This should trigger download failure and access token
337 // invalidation. 337 // invalidation.
338 CompleteDownload(net::HTTP_UNAUTHORIZED); 338 CompleteDownload(net::HTTP_UNAUTHORIZED);
339 EXPECT_EQ(1, token_service()->num_invalidate_token()); 339 EXPECT_EQ(1, token_service()->num_invalidate_token());
340 VerifyDownloadResult(id1, AttachmentDownloader::DOWNLOAD_UNSPECIFIED_ERROR); 340 VerifyDownloadResult(id1, AttachmentDownloader::DOWNLOAD_TRANSIENT_ERROR);
341 } 341 }
342 342
343 TEST_F(AttachmentDownloaderImplTest, URLFetcher_ServiceUnavailable) { 343 TEST_F(AttachmentDownloaderImplTest, URLFetcher_ServiceUnavailable) {
344 AttachmentId id1 = AttachmentId::Create(); 344 AttachmentId id1 = AttachmentId::Create();
345 downloader()->DownloadAttachment(id1, download_callback(id1)); 345 downloader()->DownloadAttachment(id1, download_callback(id1));
346 RunMessageLoop(); 346 RunMessageLoop();
347 // Return valid access token. 347 // Return valid access token.
348 token_service()->RespondToAccessTokenRequest( 348 token_service()->RespondToAccessTokenRequest(
349 GoogleServiceAuthError::AuthErrorNone()); 349 GoogleServiceAuthError::AuthErrorNone());
350 RunMessageLoop(); 350 RunMessageLoop();
351 // Fail URLFetcher. This should trigger download failure. Access token 351 // Fail URLFetcher. This should trigger download failure. Access token
352 // shouldn't be invalidated. 352 // shouldn't be invalidated.
353 CompleteDownload(net::HTTP_SERVICE_UNAVAILABLE); 353 CompleteDownload(net::HTTP_SERVICE_UNAVAILABLE);
354 EXPECT_EQ(0, token_service()->num_invalidate_token()); 354 EXPECT_EQ(0, token_service()->num_invalidate_token());
355 VerifyDownloadResult(id1, AttachmentDownloader::DOWNLOAD_UNSPECIFIED_ERROR); 355 VerifyDownloadResult(id1, AttachmentDownloader::DOWNLOAD_TRANSIENT_ERROR);
356 } 356 }
357 357
358 } // namespace syncer 358 } // namespace syncer
OLDNEW
« no previous file with comments | « sync/internal_api/attachments/attachment_downloader_impl.cc ('k') | sync/internal_api/attachments/attachment_service_impl.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698