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

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

Issue 2395753003: [NTP Snippets] Hook up background fetching scheduler to UserClassifier (Closed)
Patch Set: Created 4 years, 2 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 2015 The Chromium Authors. All rights reserved. 1 // Copyright 2015 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/ntp_snippets_service.h" 5 #include "components/ntp_snippets/remote/ntp_snippets_service.h"
6 6
7 #include <memory> 7 #include <memory>
8 #include <utility> 8 #include <utility>
9 #include <vector> 9 #include <vector>
10 10
(...skipping 15 matching lines...) Expand all
26 #include "components/image_fetcher/image_fetcher.h" 26 #include "components/image_fetcher/image_fetcher.h"
27 #include "components/image_fetcher/image_fetcher_delegate.h" 27 #include "components/image_fetcher/image_fetcher_delegate.h"
28 #include "components/ntp_snippets/category_factory.h" 28 #include "components/ntp_snippets/category_factory.h"
29 #include "components/ntp_snippets/ntp_snippets_constants.h" 29 #include "components/ntp_snippets/ntp_snippets_constants.h"
30 #include "components/ntp_snippets/remote/ntp_snippet.h" 30 #include "components/ntp_snippets/remote/ntp_snippet.h"
31 #include "components/ntp_snippets/remote/ntp_snippets_database.h" 31 #include "components/ntp_snippets/remote/ntp_snippets_database.h"
32 #include "components/ntp_snippets/remote/ntp_snippets_fetcher.h" 32 #include "components/ntp_snippets/remote/ntp_snippets_fetcher.h"
33 #include "components/ntp_snippets/remote/ntp_snippets_scheduler.h" 33 #include "components/ntp_snippets/remote/ntp_snippets_scheduler.h"
34 #include "components/ntp_snippets/remote/ntp_snippets_test_utils.h" 34 #include "components/ntp_snippets/remote/ntp_snippets_test_utils.h"
35 #include "components/ntp_snippets/switches.h" 35 #include "components/ntp_snippets/switches.h"
36 #include "components/ntp_snippets/user_classifier.h"
36 #include "components/prefs/testing_pref_service.h" 37 #include "components/prefs/testing_pref_service.h"
37 #include "components/signin/core/browser/fake_profile_oauth2_token_service.h" 38 #include "components/signin/core/browser/fake_profile_oauth2_token_service.h"
38 #include "components/signin/core/browser/fake_signin_manager.h" 39 #include "components/signin/core/browser/fake_signin_manager.h"
39 #include "components/variations/variations_associated_data.h" 40 #include "components/variations/variations_associated_data.h"
40 #include "net/url_request/test_url_fetcher_factory.h" 41 #include "net/url_request/test_url_fetcher_factory.h"
41 #include "net/url_request/url_request_test_util.h" 42 #include "net/url_request/url_request_test_util.h"
42 #include "testing/gmock/include/gmock/gmock.h" 43 #include "testing/gmock/include/gmock/gmock.h"
43 #include "testing/gtest/include/gtest/gtest.h" 44 #include "testing/gtest/include/gtest/gtest.h"
44 #include "ui/gfx/image/image.h" 45 #include "ui/gfx/image/image.h"
45 #include "ui/gfx/image/image_unittest_util.h" 46 #include "ui/gfx/image/image_unittest_util.h"
(...skipping 296 matching lines...) Expand 10 before | Expand all | Expand 10 after
342 343
343 class NTPSnippetsServiceTest : public ::testing::Test { 344 class NTPSnippetsServiceTest : public ::testing::Test {
344 public: 345 public:
345 NTPSnippetsServiceTest() 346 NTPSnippetsServiceTest()
346 : params_manager_(ntp_snippets::kStudyName, 347 : params_manager_(ntp_snippets::kStudyName,
347 {{"content_suggestions_backend", 348 {{"content_suggestions_backend",
348 kTestContentSuggestionsServerEndpoint}}), 349 kTestContentSuggestionsServerEndpoint}}),
349 fake_url_fetcher_factory_( 350 fake_url_fetcher_factory_(
350 /*default_factory=*/&failing_url_fetcher_factory_), 351 /*default_factory=*/&failing_url_fetcher_factory_),
351 test_url_(kTestContentSuggestionsServerWithAPIKey), 352 test_url_(kTestContentSuggestionsServerWithAPIKey),
353 user_classifier_(/*pref_service=*/nullptr),
352 image_fetcher_(nullptr) { 354 image_fetcher_(nullptr) {
353 NTPSnippetsService::RegisterProfilePrefs(utils_.pref_service()->registry()); 355 NTPSnippetsService::RegisterProfilePrefs(utils_.pref_service()->registry());
354 RequestThrottler::RegisterProfilePrefs(utils_.pref_service()->registry()); 356 RequestThrottler::RegisterProfilePrefs(utils_.pref_service()->registry());
355 357
356 // Since no SuggestionsService is injected in tests, we need to force the 358 // Since no SuggestionsService is injected in tests, we need to force the
357 // service to fetch from all hosts. 359 // service to fetch from all hosts.
358 base::CommandLine::ForCurrentProcess()->AppendSwitch( 360 base::CommandLine::ForCurrentProcess()->AppendSwitch(
359 switches::kDontRestrict); 361 switches::kDontRestrict);
360 EXPECT_TRUE(database_dir_.CreateUniqueTempDir()); 362 EXPECT_TRUE(database_dir_.CreateUniqueTempDir());
361 } 363 }
(...skipping 29 matching lines...) Expand all
391 utils_.fake_signin_manager()->SignIn("foo@bar.com"); 393 utils_.fake_signin_manager()->SignIn("foo@bar.com");
392 snippets_fetcher->SetPersonalizationForTesting( 394 snippets_fetcher->SetPersonalizationForTesting(
393 NTPSnippetsFetcher::Personalization::kNonPersonal); 395 NTPSnippetsFetcher::Personalization::kNonPersonal);
394 396
395 auto image_fetcher = base::MakeUnique<NiceMock<MockImageFetcher>>(); 397 auto image_fetcher = base::MakeUnique<NiceMock<MockImageFetcher>>();
396 image_fetcher_ = image_fetcher.get(); 398 image_fetcher_ = image_fetcher.get();
397 EXPECT_FALSE(observer_); 399 EXPECT_FALSE(observer_);
398 observer_ = base::MakeUnique<FakeContentSuggestionsProviderObserver>(); 400 observer_ = base::MakeUnique<FakeContentSuggestionsProviderObserver>();
399 return base::MakeUnique<NTPSnippetsService>( 401 return base::MakeUnique<NTPSnippetsService>(
400 observer_.get(), &category_factory_, utils_.pref_service(), nullptr, 402 observer_.get(), &category_factory_, utils_.pref_service(), nullptr,
401 "fr", &scheduler_, std::move(snippets_fetcher), 403 "fr", &user_classifier_, &scheduler_, std::move(snippets_fetcher),
402 std::move(image_fetcher), /*image_decoder=*/nullptr, 404 std::move(image_fetcher), /*image_decoder=*/nullptr,
403 base::MakeUnique<NTPSnippetsDatabase>(database_dir_.GetPath(), 405 base::MakeUnique<NTPSnippetsDatabase>(database_dir_.GetPath(),
404 task_runner), 406 task_runner),
405 base::MakeUnique<NTPSnippetsStatusService>(utils_.fake_signin_manager(), 407 base::MakeUnique<NTPSnippetsStatusService>(utils_.fake_signin_manager(),
406 utils_.pref_service())); 408 utils_.pref_service()));
407 } 409 }
408 410
409 void WaitForSnippetsServiceInitialization(bool set_empty_response = true) { 411 void WaitForSnippetsServiceInitialization(bool set_empty_response = true) {
410 EXPECT_TRUE(observer_); 412 EXPECT_TRUE(observer_);
411 EXPECT_FALSE(observer_->Loaded()); 413 EXPECT_FALSE(observer_->Loaded());
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after
460 462
461 private: 463 private:
462 variations::testing::VariationParamsManager params_manager_; 464 variations::testing::VariationParamsManager params_manager_;
463 test::NTPSnippetsTestUtils utils_; 465 test::NTPSnippetsTestUtils utils_;
464 base::MessageLoop message_loop_; 466 base::MessageLoop message_loop_;
465 FailingFakeURLFetcherFactory failing_url_fetcher_factory_; 467 FailingFakeURLFetcherFactory failing_url_fetcher_factory_;
466 // Instantiation of factory automatically sets itself as URLFetcher's factory. 468 // Instantiation of factory automatically sets itself as URLFetcher's factory.
467 net::FakeURLFetcherFactory fake_url_fetcher_factory_; 469 net::FakeURLFetcherFactory fake_url_fetcher_factory_;
468 const GURL test_url_; 470 const GURL test_url_;
469 std::unique_ptr<OAuth2TokenService> fake_token_service_; 471 std::unique_ptr<OAuth2TokenService> fake_token_service_;
472 UserClassifier user_classifier_;
470 NiceMock<MockScheduler> scheduler_; 473 NiceMock<MockScheduler> scheduler_;
471 std::unique_ptr<FakeContentSuggestionsProviderObserver> observer_; 474 std::unique_ptr<FakeContentSuggestionsProviderObserver> observer_;
472 CategoryFactory category_factory_; 475 CategoryFactory category_factory_;
473 NiceMock<MockImageFetcher>* image_fetcher_; 476 NiceMock<MockImageFetcher>* image_fetcher_;
474 477
475 base::ScopedTempDir database_dir_; 478 base::ScopedTempDir database_dir_;
476 479
477 DISALLOW_COPY_AND_ASSIGN(NTPSnippetsServiceTest); 480 DISALLOW_COPY_AND_ASSIGN(NTPSnippetsServiceTest);
478 }; 481 };
479 482
(...skipping 589 matching lines...) Expand 10 before | Expand all | Expand 10 after
1069 end = base::Time::FromTimeT(456); 1072 end = base::Time::FromTimeT(456);
1070 base::Callback<bool(const GURL& url)> filter; 1073 base::Callback<bool(const GURL& url)> filter;
1071 service->ClearHistory(begin, end, filter); 1074 service->ClearHistory(begin, end, filter);
1072 1075
1073 EXPECT_THAT(service->GetSnippetsForTesting(articles_category()), IsEmpty()); 1076 EXPECT_THAT(service->GetSnippetsForTesting(articles_category()), IsEmpty());
1074 EXPECT_THAT(service->GetDismissedSnippetsForTesting(articles_category()), 1077 EXPECT_THAT(service->GetDismissedSnippetsForTesting(articles_category()),
1075 IsEmpty()); 1078 IsEmpty());
1076 } 1079 }
1077 1080
1078 } // namespace ntp_snippets 1081 } // namespace ntp_snippets
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698