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_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 26 matching lines...) Expand all Loading... |
37 void RespondToAccessTokenRequest(GoogleServiceAuthError error); | 37 void RespondToAccessTokenRequest(GoogleServiceAuthError error); |
38 | 38 |
39 int num_invalidate_token() const { return num_invalidate_token_; } | 39 int num_invalidate_token() const { return num_invalidate_token_; } |
40 | 40 |
41 protected: | 41 protected: |
42 virtual void FetchOAuth2Token(RequestImpl* request, | 42 virtual void FetchOAuth2Token(RequestImpl* request, |
43 const std::string& account_id, | 43 const std::string& account_id, |
44 net::URLRequestContextGetter* getter, | 44 net::URLRequestContextGetter* getter, |
45 const std::string& client_id, | 45 const std::string& client_id, |
46 const std::string& client_secret, | 46 const std::string& client_secret, |
47 const ScopeSet& scopes) OVERRIDE; | 47 const ScopeSet& scopes) override; |
48 | 48 |
49 virtual void InvalidateOAuth2Token(const std::string& account_id, | 49 virtual void InvalidateOAuth2Token(const std::string& account_id, |
50 const std::string& client_id, | 50 const std::string& client_id, |
51 const ScopeSet& scopes, | 51 const ScopeSet& scopes, |
52 const std::string& access_token) OVERRIDE; | 52 const std::string& access_token) override; |
53 | 53 |
54 private: | 54 private: |
55 base::WeakPtr<RequestImpl> last_request_; | 55 base::WeakPtr<RequestImpl> last_request_; |
56 int num_invalidate_token_; | 56 int num_invalidate_token_; |
57 }; | 57 }; |
58 | 58 |
59 void MockOAuth2TokenService::RespondToAccessTokenRequest( | 59 void MockOAuth2TokenService::RespondToAccessTokenRequest( |
60 GoogleServiceAuthError error) { | 60 GoogleServiceAuthError error) { |
61 EXPECT_TRUE(last_request_ != NULL); | 61 EXPECT_TRUE(last_request_ != NULL); |
62 std::string access_token; | 62 std::string access_token; |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
95 } | 95 } |
96 | 96 |
97 class TokenServiceProvider | 97 class TokenServiceProvider |
98 : public OAuth2TokenServiceRequest::TokenServiceProvider, | 98 : public OAuth2TokenServiceRequest::TokenServiceProvider, |
99 base::NonThreadSafe { | 99 base::NonThreadSafe { |
100 public: | 100 public: |
101 TokenServiceProvider(OAuth2TokenService* token_service); | 101 TokenServiceProvider(OAuth2TokenService* token_service); |
102 | 102 |
103 // OAuth2TokenService::TokenServiceProvider implementation. | 103 // OAuth2TokenService::TokenServiceProvider implementation. |
104 virtual scoped_refptr<base::SingleThreadTaskRunner> | 104 virtual scoped_refptr<base::SingleThreadTaskRunner> |
105 GetTokenServiceTaskRunner() OVERRIDE; | 105 GetTokenServiceTaskRunner() override; |
106 virtual OAuth2TokenService* GetTokenService() OVERRIDE; | 106 virtual OAuth2TokenService* GetTokenService() override; |
107 | 107 |
108 private: | 108 private: |
109 virtual ~TokenServiceProvider(); | 109 virtual ~TokenServiceProvider(); |
110 | 110 |
111 scoped_refptr<base::SingleThreadTaskRunner> task_runner_; | 111 scoped_refptr<base::SingleThreadTaskRunner> task_runner_; |
112 OAuth2TokenService* token_service_; | 112 OAuth2TokenService* token_service_; |
113 }; | 113 }; |
114 | 114 |
115 TokenServiceProvider::TokenServiceProvider(OAuth2TokenService* token_service) | 115 TokenServiceProvider::TokenServiceProvider(OAuth2TokenService* token_service) |
116 : task_runner_(base::ThreadTaskRunnerHandle::Get()), | 116 : task_runner_(base::ThreadTaskRunnerHandle::Get()), |
(...skipping 16 matching lines...) Expand all Loading... |
133 | 133 |
134 } // namespace | 134 } // namespace |
135 | 135 |
136 class AttachmentDownloaderImplTest : public testing::Test { | 136 class AttachmentDownloaderImplTest : public testing::Test { |
137 protected: | 137 protected: |
138 typedef std::map<AttachmentId, AttachmentDownloader::DownloadResult> | 138 typedef std::map<AttachmentId, AttachmentDownloader::DownloadResult> |
139 ResultsMap; | 139 ResultsMap; |
140 | 140 |
141 AttachmentDownloaderImplTest() : num_completed_downloads_(0) {} | 141 AttachmentDownloaderImplTest() : num_completed_downloads_(0) {} |
142 | 142 |
143 virtual void SetUp() OVERRIDE; | 143 virtual void SetUp() override; |
144 virtual void TearDown() OVERRIDE; | 144 virtual void TearDown() override; |
145 | 145 |
146 AttachmentDownloader* downloader() { return attachment_downloader_.get(); } | 146 AttachmentDownloader* downloader() { return attachment_downloader_.get(); } |
147 | 147 |
148 MockOAuth2TokenService* token_service() { return token_service_.get(); } | 148 MockOAuth2TokenService* token_service() { return token_service_.get(); } |
149 | 149 |
150 int num_completed_downloads() { return num_completed_downloads_; } | 150 int num_completed_downloads() { return num_completed_downloads_; } |
151 | 151 |
152 AttachmentDownloader::DownloadCallback download_callback( | 152 AttachmentDownloader::DownloadCallback download_callback( |
153 const AttachmentId& id) { | 153 const AttachmentId& id) { |
154 return base::Bind(&AttachmentDownloaderImplTest::DownloadDone, | 154 return base::Bind(&AttachmentDownloaderImplTest::DownloadDone, |
(...skipping 194 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
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_TRANSIENT_ERROR); | 355 VerifyDownloadResult(id1, AttachmentDownloader::DOWNLOAD_TRANSIENT_ERROR); |
356 } | 356 } |
357 | 357 |
358 } // namespace syncer | 358 } // namespace syncer |
OLD | NEW |