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

Side by Side Diff: components/ntp_snippets/remote/remote_suggestions_fetcher_unittest.cc

Issue 2685123002: Make OAuth2TokenService and subclasses take delegate by unique_ptr (Closed)
Patch Set: Created 3 years, 10 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 2016 The Chromium Authors. All rights reserved. 1 // Copyright 2016 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 "components/ntp_snippets/remote/remote_suggestions_fetcher.h" 5 #include "components/ntp_snippets/remote/remote_suggestions_fetcher.h"
6 6
7 #include <deque> 7 #include <deque>
8 #include <map> 8 #include <map>
9 #include <set> 9 #include <set>
10 #include <utility> 10 #include <utility>
(...skipping 277 matching lines...) Expand 10 before | Expand all | Expand 10 after
288 user_classifier_ = base::MakeUnique<UserClassifier>(utils_.pref_service()); 288 user_classifier_ = base::MakeUnique<UserClassifier>(utils_.pref_service());
289 // Increase initial time such that ticks are non-zero. 289 // Increase initial time such that ticks are non-zero.
290 mock_task_runner_->FastForwardBy(base::TimeDelta::FromMilliseconds(1234)); 290 mock_task_runner_->FastForwardBy(base::TimeDelta::FromMilliseconds(1234));
291 ResetFetcher(); 291 ResetFetcher();
292 } 292 }
293 293
294 void ResetFetcher() { 294 void ResetFetcher() {
295 scoped_refptr<net::TestURLRequestContextGetter> request_context_getter = 295 scoped_refptr<net::TestURLRequestContextGetter> request_context_getter =
296 new net::TestURLRequestContextGetter(mock_task_runner_.get()); 296 new net::TestURLRequestContextGetter(mock_task_runner_.get());
297 297
298 fake_token_service_delegate_ =
299 new FakeOAuth2TokenServiceDelegate(request_context_getter.get());
300 // Not a memleak because OAuth2TokenService takes ownership of the raw
301 // pointer (crbug.com/688387).
302 fake_token_service_ = base::MakeUnique<FakeProfileOAuth2TokenService>( 298 fake_token_service_ = base::MakeUnique<FakeProfileOAuth2TokenService>(
303 fake_token_service_delegate_); 299 base::MakeUnique<FakeOAuth2TokenServiceDelegate>(
300 request_context_getter.get()));
304 301
305 fetcher_ = base::MakeUnique<RemoteSuggestionsFetcher>( 302 fetcher_ = base::MakeUnique<RemoteSuggestionsFetcher>(
306 utils_.fake_signin_manager(), fake_token_service_.get(), 303 utils_.fake_signin_manager(), fake_token_service_.get(),
307 std::move(request_context_getter), utils_.pref_service(), nullptr, 304 std::move(request_context_getter), utils_.pref_service(), nullptr,
308 base::Bind(&ParseJsonDelayed), kAPIKey, user_classifier_.get()); 305 base::Bind(&ParseJsonDelayed), kAPIKey, user_classifier_.get());
309 306
310 fetcher_->SetTickClockForTesting(mock_task_runner_->GetMockTickClock()); 307 fetcher_->SetTickClockForTesting(mock_task_runner_->GetMockTickClock());
311 } 308 }
312 309
313 void SignIn() { utils_.fake_signin_manager()->SignIn(kTestEmail); } 310 void SignIn() { utils_.fake_signin_manager()->SignIn(kTestEmail); }
314 311
315 void IssueRefreshToken() { 312 void IssueRefreshToken() {
316 fake_token_service_delegate_->UpdateCredentials(kTestEmail, "token"); 313 fake_token_service_->GetDelegate()->UpdateCredentials(kTestEmail, "token");
317 } 314 }
318 315
319 void IssueOAuth2Token() { 316 void IssueOAuth2Token() {
320 fake_token_service_->IssueAllTokensForAccount(kTestEmail, "access_token", 317 fake_token_service_->IssueAllTokensForAccount(kTestEmail, "access_token",
321 base::Time::Max()); 318 base::Time::Max());
322 } 319 }
323 320
324 void CancelOAuth2TokenRequests() { 321 void CancelOAuth2TokenRequests() {
325 fake_token_service_->IssueErrorForAllPendingRequestsForAccount( 322 fake_token_service_->IssueErrorForAllPendingRequestsForAccount(
326 kTestEmail, GoogleServiceAuthError( 323 kTestEmail, GoogleServiceAuthError(
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after
379 std::map<std::string, std::string> default_variation_params_; 376 std::map<std::string, std::string> default_variation_params_;
380 377
381 private: 378 private:
382 test::RemoteSuggestionsTestUtils utils_; 379 test::RemoteSuggestionsTestUtils utils_;
383 variations::testing::VariationParamsManager params_manager_; 380 variations::testing::VariationParamsManager params_manager_;
384 scoped_refptr<base::TestMockTimeTaskRunner> mock_task_runner_; 381 scoped_refptr<base::TestMockTimeTaskRunner> mock_task_runner_;
385 base::ThreadTaskRunnerHandle mock_task_runner_handle_; 382 base::ThreadTaskRunnerHandle mock_task_runner_handle_;
386 FailingFakeURLFetcherFactory failing_url_fetcher_factory_; 383 FailingFakeURLFetcherFactory failing_url_fetcher_factory_;
387 // Initialized lazily in SetFakeResponse(). 384 // Initialized lazily in SetFakeResponse().
388 std::unique_ptr<net::FakeURLFetcherFactory> fake_url_fetcher_factory_; 385 std::unique_ptr<net::FakeURLFetcherFactory> fake_url_fetcher_factory_;
389 FakeOAuth2TokenServiceDelegate* fake_token_service_delegate_;
390 std::unique_ptr<FakeProfileOAuth2TokenService> fake_token_service_; 386 std::unique_ptr<FakeProfileOAuth2TokenService> fake_token_service_;
391 std::unique_ptr<RemoteSuggestionsFetcher> fetcher_; 387 std::unique_ptr<RemoteSuggestionsFetcher> fetcher_;
392 std::unique_ptr<UserClassifier> user_classifier_; 388 std::unique_ptr<UserClassifier> user_classifier_;
393 MockSnippetsAvailableCallback mock_callback_; 389 MockSnippetsAvailableCallback mock_callback_;
394 const GURL test_url_; 390 const GURL test_url_;
395 base::HistogramTester histogram_tester_; 391 base::HistogramTester histogram_tester_;
396 392
397 DISALLOW_COPY_AND_ASSIGN(RemoteSuggestionsFetcherTestBase); 393 DISALLOW_COPY_AND_ASSIGN(RemoteSuggestionsFetcherTestBase);
398 }; 394 };
399 395
(...skipping 620 matching lines...) Expand 10 before | Expand all | Expand 10 after
1020 fetched_categories) { 1016 fetched_categories) {
1021 if (fetched_categories) { 1017 if (fetched_categories) {
1022 // Matchers above aren't any more precise than this, so this is sufficient 1018 // Matchers above aren't any more precise than this, so this is sufficient
1023 // for test-failure diagnostics. 1019 // for test-failure diagnostics.
1024 return os << "list with " << fetched_categories->size() << " elements"; 1020 return os << "list with " << fetched_categories->size() << " elements";
1025 } 1021 }
1026 return os << "null"; 1022 return os << "null";
1027 } 1023 }
1028 1024
1029 } // namespace ntp_snippets 1025 } // namespace ntp_snippets
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698