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_impl.h" | 5 #include "sync/internal_api/public/attachments/attachment_downloader_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 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
47 int num_invalidate_token() const { return num_invalidate_token_; } | 47 int num_invalidate_token() const { return num_invalidate_token_; } |
48 | 48 |
49 protected: | 49 protected: |
50 void FetchOAuth2Token(RequestImpl* request, | 50 void FetchOAuth2Token(RequestImpl* request, |
51 const std::string& account_id, | 51 const std::string& account_id, |
52 net::URLRequestContextGetter* getter, | 52 net::URLRequestContextGetter* getter, |
53 const std::string& client_id, | 53 const std::string& client_id, |
54 const std::string& client_secret, | 54 const std::string& client_secret, |
55 const ScopeSet& scopes) override; | 55 const ScopeSet& scopes) override; |
56 | 56 |
57 void InvalidateOAuth2Token(const std::string& account_id, | 57 void InvalidateAccessTokenImpl(const std::string& account_id, |
58 const std::string& client_id, | 58 const std::string& client_id, |
59 const ScopeSet& scopes, | 59 const ScopeSet& scopes, |
60 const std::string& access_token) override; | 60 const std::string& access_token) override; |
61 | 61 |
62 private: | 62 private: |
63 base::WeakPtr<RequestImpl> last_request_; | 63 base::WeakPtr<RequestImpl> last_request_; |
64 int num_invalidate_token_; | 64 int num_invalidate_token_; |
65 }; | 65 }; |
66 | 66 |
67 void MockOAuth2TokenService::RespondToAccessTokenRequest( | 67 void MockOAuth2TokenService::RespondToAccessTokenRequest( |
68 GoogleServiceAuthError error) { | 68 GoogleServiceAuthError error) { |
69 EXPECT_TRUE(last_request_ != NULL); | 69 EXPECT_TRUE(last_request_ != NULL); |
70 std::string access_token; | 70 std::string access_token; |
(...skipping 16 matching lines...) Expand all Loading... |
87 const std::string& account_id, | 87 const std::string& account_id, |
88 net::URLRequestContextGetter* getter, | 88 net::URLRequestContextGetter* getter, |
89 const std::string& client_id, | 89 const std::string& client_id, |
90 const std::string& client_secret, | 90 const std::string& client_secret, |
91 const ScopeSet& scopes) { | 91 const ScopeSet& scopes) { |
92 // Only one request at a time is allowed. | 92 // Only one request at a time is allowed. |
93 EXPECT_TRUE(last_request_ == NULL); | 93 EXPECT_TRUE(last_request_ == NULL); |
94 last_request_ = request->AsWeakPtr(); | 94 last_request_ = request->AsWeakPtr(); |
95 } | 95 } |
96 | 96 |
97 void MockOAuth2TokenService::InvalidateOAuth2Token( | 97 void MockOAuth2TokenService::InvalidateAccessTokenImpl( |
98 const std::string& account_id, | 98 const std::string& account_id, |
99 const std::string& client_id, | 99 const std::string& client_id, |
100 const ScopeSet& scopes, | 100 const ScopeSet& scopes, |
101 const std::string& access_token) { | 101 const std::string& access_token) { |
102 ++num_invalidate_token_; | 102 ++num_invalidate_token_; |
103 } | 103 } |
104 | 104 |
105 class TokenServiceProvider | 105 class TokenServiceProvider |
106 : public OAuth2TokenServiceRequest::TokenServiceProvider, | 106 : public OAuth2TokenServiceRequest::TokenServiceProvider, |
107 base::NonThreadSafe { | 107 base::NonThreadSafe { |
(...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
201 ResultsMap download_results_; | 201 ResultsMap download_results_; |
202 int num_completed_downloads_; | 202 int num_completed_downloads_; |
203 const AttachmentId attachment_id_; | 203 const AttachmentId attachment_id_; |
204 }; | 204 }; |
205 | 205 |
206 void AttachmentDownloaderImplTest::SetUp() { | 206 void AttachmentDownloaderImplTest::SetUp() { |
207 url_request_context_getter_ = | 207 url_request_context_getter_ = |
208 new net::TestURLRequestContextGetter(message_loop_.message_loop_proxy()); | 208 new net::TestURLRequestContextGetter(message_loop_.message_loop_proxy()); |
209 url_fetcher_factory_.set_remove_fetcher_on_delete(true); | 209 url_fetcher_factory_.set_remove_fetcher_on_delete(true); |
210 token_service_.reset(new MockOAuth2TokenService()); | 210 token_service_.reset(new MockOAuth2TokenService()); |
211 token_service_->AddAccount(kAccountId); | 211 token_service_->GetDelegate()->UpdateCredentials(kAccountId, "refresh_token"); |
212 scoped_refptr<OAuth2TokenServiceRequest::TokenServiceProvider> | 212 scoped_refptr<OAuth2TokenServiceRequest::TokenServiceProvider> |
213 token_service_provider(new TokenServiceProvider(token_service_.get())); | 213 token_service_provider(new TokenServiceProvider(token_service_.get())); |
214 | 214 |
215 OAuth2TokenService::ScopeSet scopes; | 215 OAuth2TokenService::ScopeSet scopes; |
216 scopes.insert(GaiaConstants::kChromeSyncOAuth2Scope); | 216 scopes.insert(GaiaConstants::kChromeSyncOAuth2Scope); |
217 attachment_downloader_ = AttachmentDownloader::Create( | 217 attachment_downloader_ = AttachmentDownloader::Create( |
218 GURL(kAttachmentServerUrl), url_request_context_getter_, kAccountId, | 218 GURL(kAttachmentServerUrl), url_request_context_getter_, kAccountId, |
219 scopes, token_service_provider, std::string(kStoreBirthday), kModelType); | 219 scopes, token_service_provider, std::string(kStoreBirthday), kModelType); |
220 } | 220 } |
221 | 221 |
(...skipping 306 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
528 raw += "\n"; | 528 raw += "\n"; |
529 std::replace(raw.begin(), raw.end(), '\n', '\0'); | 529 std::replace(raw.begin(), raw.end(), '\n', '\0'); |
530 scoped_refptr<net::HttpResponseHeaders> headers( | 530 scoped_refptr<net::HttpResponseHeaders> headers( |
531 new net::HttpResponseHeaders(raw)); | 531 new net::HttpResponseHeaders(raw)); |
532 uint32_t extracted; | 532 uint32_t extracted; |
533 ASSERT_FALSE( | 533 ASSERT_FALSE( |
534 AttachmentDownloaderImpl::ExtractCrc32c(headers.get(), &extracted)); | 534 AttachmentDownloaderImpl::ExtractCrc32c(headers.get(), &extracted)); |
535 } | 535 } |
536 | 536 |
537 } // namespace syncer | 537 } // namespace syncer |
OLD | NEW |