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

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

Issue 458753006: Fix use after free bug by calling GetTokenService in Core's ctor. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Update TSP comment (CANDIDATE). Created 6 years, 4 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 | Annotate | Revision Log
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 81 matching lines...) Expand 10 before | Expand all | Expand 10 after
92 const ScopeSet& scopes, 92 const ScopeSet& scopes,
93 const std::string& access_token) { 93 const std::string& access_token) {
94 ++num_invalidate_token_; 94 ++num_invalidate_token_;
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 virtual ~TokenServiceProvider();
103 102
104 // OAuth2TokenService::TokenServiceProvider implementation. 103 // OAuth2TokenService::TokenServiceProvider implementation.
105 virtual scoped_refptr<base::SingleThreadTaskRunner> 104 virtual scoped_refptr<base::SingleThreadTaskRunner>
106 GetTokenServiceTaskRunner() OVERRIDE; 105 GetTokenServiceTaskRunner() OVERRIDE;
107 virtual OAuth2TokenService* GetTokenService() OVERRIDE; 106 virtual OAuth2TokenService* GetTokenService() OVERRIDE;
108 107
109 private: 108 private:
109 virtual ~TokenServiceProvider();
110
110 scoped_refptr<base::SingleThreadTaskRunner> task_runner_; 111 scoped_refptr<base::SingleThreadTaskRunner> task_runner_;
111 OAuth2TokenService* token_service_; 112 OAuth2TokenService* token_service_;
112 }; 113 };
113 114
114 TokenServiceProvider::TokenServiceProvider(OAuth2TokenService* token_service) 115 TokenServiceProvider::TokenServiceProvider(OAuth2TokenService* token_service)
115 : task_runner_(base::ThreadTaskRunnerHandle::Get()), 116 : task_runner_(base::ThreadTaskRunnerHandle::Get()),
116 token_service_(token_service) { 117 token_service_(token_service) {
117 DCHECK(token_service_); 118 DCHECK(token_service_);
118 } 119 }
119 120
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after
175 ResultsMap download_results_; 176 ResultsMap download_results_;
176 int num_completed_downloads_; 177 int num_completed_downloads_;
177 }; 178 };
178 179
179 void AttachmentDownloaderImplTest::SetUp() { 180 void AttachmentDownloaderImplTest::SetUp() {
180 url_request_context_getter_ = 181 url_request_context_getter_ =
181 new net::TestURLRequestContextGetter(message_loop_.message_loop_proxy()); 182 new net::TestURLRequestContextGetter(message_loop_.message_loop_proxy());
182 url_fetcher_factory_.set_remove_fetcher_on_delete(true); 183 url_fetcher_factory_.set_remove_fetcher_on_delete(true);
183 token_service_.reset(new MockOAuth2TokenService()); 184 token_service_.reset(new MockOAuth2TokenService());
184 token_service_->AddAccount(kAccountId); 185 token_service_->AddAccount(kAccountId);
185 scoped_ptr<OAuth2TokenServiceRequest::TokenServiceProvider> 186 scoped_refptr<OAuth2TokenServiceRequest::TokenServiceProvider>
186 token_service_provider(new TokenServiceProvider(token_service_.get())); 187 token_service_provider(new TokenServiceProvider(token_service_.get()));
187 188
188 OAuth2TokenService::ScopeSet scopes; 189 OAuth2TokenService::ScopeSet scopes;
189 scopes.insert(GaiaConstants::kChromeSyncOAuth2Scope); 190 scopes.insert(GaiaConstants::kChromeSyncOAuth2Scope);
190 attachment_downloader_ = 191 attachment_downloader_ =
191 AttachmentDownloader::Create(GURL(kAttachmentServerUrl), 192 AttachmentDownloader::Create(GURL(kAttachmentServerUrl),
192 url_request_context_getter_, 193 url_request_context_getter_,
193 kAccountId, 194 kAccountId,
194 scopes, 195 scopes,
195 token_service_provider.Pass()); 196 token_service_provider);
196 } 197 }
197 198
198 void AttachmentDownloaderImplTest::TearDown() { 199 void AttachmentDownloaderImplTest::TearDown() {
199 RunMessageLoop(); 200 RunMessageLoop();
200 } 201 }
201 202
202 void AttachmentDownloaderImplTest::CompleteDownload(int response_code) { 203 void AttachmentDownloaderImplTest::CompleteDownload(int response_code) {
203 // TestURLFetcherFactory remembers last active URLFetcher. 204 // TestURLFetcherFactory remembers last active URLFetcher.
204 net::TestURLFetcher* fetcher = url_fetcher_factory_.GetFetcherByID(0); 205 net::TestURLFetcher* fetcher = url_fetcher_factory_.GetFetcherByID(0);
205 // There should be outstanding url fetch request. 206 // There should be outstanding url fetch request.
(...skipping 142 matching lines...) Expand 10 before | Expand all | Expand 10 after
348 GoogleServiceAuthError::AuthErrorNone()); 349 GoogleServiceAuthError::AuthErrorNone());
349 RunMessageLoop(); 350 RunMessageLoop();
350 // Fail URLFetcher. This should trigger download failure. Access token 351 // Fail URLFetcher. This should trigger download failure. Access token
351 // shouldn't be invalidated. 352 // shouldn't be invalidated.
352 CompleteDownload(net::HTTP_SERVICE_UNAVAILABLE); 353 CompleteDownload(net::HTTP_SERVICE_UNAVAILABLE);
353 EXPECT_EQ(0, token_service()->num_invalidate_token()); 354 EXPECT_EQ(0, token_service()->num_invalidate_token());
354 VerifyDownloadResult(id1, AttachmentDownloader::DOWNLOAD_UNSPECIFIED_ERROR); 355 VerifyDownloadResult(id1, AttachmentDownloader::DOWNLOAD_UNSPECIFIED_ERROR);
355 } 356 }
356 357
357 } // namespace syncer 358 } // namespace syncer
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698