Chromium Code Reviews| OLD | NEW |
|---|---|
| 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/remote_suggestions_provider_impl.h" | 5 #include "components/ntp_snippets/remote/remote_suggestions_provider_impl.h" |
| 6 | 6 |
| 7 #include <memory> | 7 #include <memory> |
| 8 #include <utility> | 8 #include <utility> |
| 9 #include <vector> | 9 #include <vector> |
| 10 | 10 |
| (...skipping 362 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 373 } | 373 } |
| 374 | 374 |
| 375 void SetDecodedImage(const gfx::Image& image) { decoded_image_ = image; } | 375 void SetDecodedImage(const gfx::Image& image) { decoded_image_ = image; } |
| 376 | 376 |
| 377 private: | 377 private: |
| 378 gfx::Image decoded_image_; | 378 gfx::Image decoded_image_; |
| 379 }; | 379 }; |
| 380 | 380 |
| 381 class MockScheduler : public RemoteSuggestionsScheduler { | 381 class MockScheduler : public RemoteSuggestionsScheduler { |
| 382 public: | 382 public: |
| 383 MOCK_METHOD1(SetProvider, void(RemoteSuggestionsProvider* provider)); | |
| 383 MOCK_METHOD0(OnProviderActivated, void()); | 384 MOCK_METHOD0(OnProviderActivated, void()); |
| 384 MOCK_METHOD0(OnProviderDeactivated, void()); | 385 MOCK_METHOD0(OnProviderDeactivated, void()); |
| 385 MOCK_METHOD0(OnSuggestionsCleared, void()); | 386 MOCK_METHOD0(OnSuggestionsCleared, void()); |
| 386 MOCK_METHOD0(OnHistoryCleared, void()); | 387 MOCK_METHOD0(OnHistoryCleared, void()); |
| 388 MOCK_METHOD0(AcquireQuotaForInteractiveFetch, bool()); | |
| 389 MOCK_METHOD1(OnInteractiveFetchFinished, void(Status fetch_status)); | |
| 387 MOCK_METHOD0(OnBrowserForegrounded, void()); | 390 MOCK_METHOD0(OnBrowserForegrounded, void()); |
| 388 MOCK_METHOD0(OnBrowserColdStart, void()); | 391 MOCK_METHOD0(OnBrowserColdStart, void()); |
| 389 MOCK_METHOD0(OnNTPOpened, void()); | 392 MOCK_METHOD0(OnNTPOpened, void()); |
| 390 MOCK_METHOD0(OnPersistentSchedulerWakeUp, void()); | 393 MOCK_METHOD0(OnPersistentSchedulerWakeUp, void()); |
| 391 MOCK_METHOD0(RescheduleFetching, void()); | 394 MOCK_METHOD0(RescheduleFetching, void()); |
| 392 }; | 395 }; |
| 393 | 396 |
| 394 } // namespace | 397 } // namespace |
| 395 | 398 |
| 396 class RemoteSuggestionsProviderImplTest : public ::testing::Test { | 399 class RemoteSuggestionsProviderImplTest : public ::testing::Test { |
| 397 public: | 400 public: |
| 398 RemoteSuggestionsProviderImplTest() | 401 RemoteSuggestionsProviderImplTest() |
| 399 : params_manager_(ntp_snippets::kStudyName, | 402 : params_manager_(ntp_snippets::kStudyName, |
| 400 {{"content_suggestions_backend", | 403 {{"content_suggestions_backend", |
| 401 kTestContentSuggestionsServerEndpoint}}, | 404 kTestContentSuggestionsServerEndpoint}}, |
| 402 {ntp_snippets::kArticleSuggestionsFeature.name}), | 405 {ntp_snippets::kArticleSuggestionsFeature.name}), |
| 403 fake_url_fetcher_factory_( | 406 fake_url_fetcher_factory_( |
| 404 /*default_factory=*/&failing_url_fetcher_factory_), | 407 /*default_factory=*/&failing_url_fetcher_factory_), |
| 405 test_url_(kTestContentSuggestionsServerWithAPIKey), | 408 test_url_(kTestContentSuggestionsServerWithAPIKey), |
| 406 category_ranker_(base::MakeUnique<ConstantCategoryRanker>()), | 409 category_ranker_(base::MakeUnique<ConstantCategoryRanker>()), |
| 407 user_classifier_(/*pref_service=*/nullptr, | 410 user_classifier_(/*pref_service=*/nullptr, |
| 408 base::MakeUnique<base::DefaultClock>()), | 411 base::MakeUnique<base::DefaultClock>()), |
| 409 suggestions_fetcher_(nullptr), | 412 suggestions_fetcher_(nullptr), |
| 410 image_fetcher_(nullptr), | 413 image_fetcher_(nullptr), |
| 414 scheduler_(base::MakeUnique<NiceMock<MockScheduler>>()), | |
| 411 database_(nullptr) { | 415 database_(nullptr) { |
| 412 RemoteSuggestionsProviderImpl::RegisterProfilePrefs( | 416 RemoteSuggestionsProviderImpl::RegisterProfilePrefs( |
| 413 utils_.pref_service()->registry()); | 417 utils_.pref_service()->registry()); |
| 414 RequestThrottler::RegisterProfilePrefs(utils_.pref_service()->registry()); | 418 RequestThrottler::RegisterProfilePrefs(utils_.pref_service()->registry()); |
| 415 | 419 |
| 416 EXPECT_TRUE(database_dir_.CreateUniqueTempDir()); | 420 EXPECT_TRUE(database_dir_.CreateUniqueTempDir()); |
| 417 } | 421 } |
| 418 | 422 |
| 419 ~RemoteSuggestionsProviderImplTest() override { | 423 ~RemoteSuggestionsProviderImplTest() override { |
| 420 // We need to run the message loop after deleting the database, because | 424 // We need to run the message loop after deleting the database, because |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 453 EXPECT_CALL(*image_fetcher, SetImageFetcherDelegate(_)); | 457 EXPECT_CALL(*image_fetcher, SetImageFetcherDelegate(_)); |
| 454 ON_CALL(*image_fetcher, GetImageDecoder()) | 458 ON_CALL(*image_fetcher, GetImageDecoder()) |
| 455 .WillByDefault(Return(&image_decoder_)); | 459 .WillByDefault(Return(&image_decoder_)); |
| 456 EXPECT_FALSE(observer_); | 460 EXPECT_FALSE(observer_); |
| 457 observer_ = base::MakeUnique<FakeContentSuggestionsProviderObserver>(); | 461 observer_ = base::MakeUnique<FakeContentSuggestionsProviderObserver>(); |
| 458 auto database = base::MakeUnique<RemoteSuggestionsDatabase>( | 462 auto database = base::MakeUnique<RemoteSuggestionsDatabase>( |
| 459 database_dir_.GetPath(), task_runner); | 463 database_dir_.GetPath(), task_runner); |
| 460 database_ = database.get(); | 464 database_ = database.get(); |
| 461 return base::MakeUnique<RemoteSuggestionsProviderImpl>( | 465 return base::MakeUnique<RemoteSuggestionsProviderImpl>( |
| 462 observer_.get(), utils_.pref_service(), "fr", category_ranker_.get(), | 466 observer_.get(), utils_.pref_service(), "fr", category_ranker_.get(), |
| 463 std::move(suggestions_fetcher), std::move(image_fetcher), | 467 scheduler_.get(), std::move(suggestions_fetcher), |
| 464 std::move(database), | 468 std::move(image_fetcher), std::move(database), |
| 465 base::MakeUnique<RemoteSuggestionsStatusService>( | 469 base::MakeUnique<RemoteSuggestionsStatusService>( |
| 466 utils_.fake_signin_manager(), utils_.pref_service())); | 470 utils_.fake_signin_manager(), utils_.pref_service())); |
| 467 } | 471 } |
| 468 | 472 |
| 469 void WaitForSuggestionsProviderInitialization( | 473 void WaitForSuggestionsProviderInitialization( |
| 470 RemoteSuggestionsProviderImpl* service, | 474 RemoteSuggestionsProviderImpl* service, |
| 471 bool set_empty_response) { | 475 bool set_empty_response) { |
| 472 EXPECT_EQ(RemoteSuggestionsProviderImpl::State::NOT_INITED, | 476 EXPECT_EQ(RemoteSuggestionsProviderImpl::State::NOT_INITED, |
| 473 service->state_); | 477 service->state_); |
| 474 | 478 |
| (...skipping 10 matching lines...) Expand all Loading... | |
| 485 } | 489 } |
| 486 | 490 |
| 487 void ResetSuggestionsProvider( | 491 void ResetSuggestionsProvider( |
| 488 std::unique_ptr<RemoteSuggestionsProviderImpl>* service, | 492 std::unique_ptr<RemoteSuggestionsProviderImpl>* service, |
| 489 bool set_empty_response) { | 493 bool set_empty_response) { |
| 490 service->reset(); | 494 service->reset(); |
| 491 observer_.reset(); | 495 observer_.reset(); |
| 492 *service = MakeSuggestionsProvider(set_empty_response); | 496 *service = MakeSuggestionsProvider(set_empty_response); |
| 493 } | 497 } |
| 494 | 498 |
| 499 void SetStrictScheduler() { | |
|
Marc Treib
2017/03/29 11:11:57
Hm, by itself this doesn't really make sense, as t
| |
| 500 scheduler_ = base::MakeUnique<StrictMock<MockScheduler>>(); | |
| 501 } | |
| 502 | |
| 495 void SetCategoryRanker(std::unique_ptr<CategoryRanker> category_ranker) { | 503 void SetCategoryRanker(std::unique_ptr<CategoryRanker> category_ranker) { |
| 496 category_ranker_ = std::move(category_ranker); | 504 category_ranker_ = std::move(category_ranker); |
| 497 } | 505 } |
| 498 | 506 |
| 499 ContentSuggestion::ID MakeArticleID(const std::string& id_within_category) { | 507 ContentSuggestion::ID MakeArticleID(const std::string& id_within_category) { |
| 500 return ContentSuggestion::ID(articles_category(), id_within_category); | 508 return ContentSuggestion::ID(articles_category(), id_within_category); |
| 501 } | 509 } |
| 502 | 510 |
| 503 Category articles_category() { | 511 Category articles_category() { |
| 504 return Category::FromKnownCategory(KnownCategories::ARTICLES); | 512 return Category::FromKnownCategory(KnownCategories::ARTICLES); |
| (...skipping 16 matching lines...) Expand all Loading... | |
| 521 FakeContentSuggestionsProviderObserver& observer() { return *observer_; } | 529 FakeContentSuggestionsProviderObserver& observer() { return *observer_; } |
| 522 RemoteSuggestionsFetcher* suggestions_fetcher() { | 530 RemoteSuggestionsFetcher* suggestions_fetcher() { |
| 523 return suggestions_fetcher_; | 531 return suggestions_fetcher_; |
| 524 } | 532 } |
| 525 // TODO(tschumann): Make this a strict-mock. We want to avoid unneccesary | 533 // TODO(tschumann): Make this a strict-mock. We want to avoid unneccesary |
| 526 // network requests. | 534 // network requests. |
| 527 NiceMock<MockImageFetcher>* image_fetcher() { return image_fetcher_; } | 535 NiceMock<MockImageFetcher>* image_fetcher() { return image_fetcher_; } |
| 528 FakeImageDecoder* image_decoder() { return &image_decoder_; } | 536 FakeImageDecoder* image_decoder() { return &image_decoder_; } |
| 529 PrefService* pref_service() { return utils_.pref_service(); } | 537 PrefService* pref_service() { return utils_.pref_service(); } |
| 530 RemoteSuggestionsDatabase* database() { return database_; } | 538 RemoteSuggestionsDatabase* database() { return database_; } |
| 539 MockScheduler* scheduler() { return scheduler_.get(); } | |
| 531 | 540 |
| 532 // Provide the json to be returned by the fake fetcher. | 541 // Provide the json to be returned by the fake fetcher. |
| 533 void SetUpFetchResponse(const std::string& json) { | 542 void SetUpFetchResponse(const std::string& json) { |
| 534 fake_url_fetcher_factory_.SetFakeResponse(test_url_, json, net::HTTP_OK, | 543 fake_url_fetcher_factory_.SetFakeResponse(test_url_, json, net::HTTP_OK, |
| 535 net::URLRequestStatus::SUCCESS); | 544 net::URLRequestStatus::SUCCESS); |
| 536 } | 545 } |
| 537 | 546 |
| 538 // Have the fake fetcher fail due to a HTTP error like a 404. | 547 // Have the fake fetcher fail due to a HTTP error like a 404. |
| 539 void SetUpHttpError() { | 548 void SetUpHttpError() { |
| 540 fake_url_fetcher_factory_.SetFakeResponse(test_url_, /*json=*/std::string(), | 549 fake_url_fetcher_factory_.SetFakeResponse(test_url_, /*json=*/std::string(), |
| 541 net::HTTP_NOT_FOUND, | 550 net::HTTP_NOT_FOUND, |
| 542 net::URLRequestStatus::SUCCESS); | 551 net::URLRequestStatus::SUCCESS); |
| 543 } | 552 } |
| 544 | 553 |
| 545 void LoadFromJSONString(RemoteSuggestionsProviderImpl* service, | 554 void LoadFromJSONString(RemoteSuggestionsProviderImpl* service, |
| 546 const std::string& json) { | 555 const std::string& json) { |
| 547 SetUpFetchResponse(json); | 556 SetUpFetchResponse(json); |
| 548 service->FetchSuggestions(/*interactive_request=*/true, | 557 service->FetchSuggestions(/*interactive_request=*/true, |
| 549 /*callback=*/nullptr); | 558 /*callback=*/nullptr); |
| 550 base::RunLoop().RunUntilIdle(); | 559 base::RunLoop().RunUntilIdle(); |
| 551 } | 560 } |
| 552 | 561 |
| 553 void LoadMoreFromJSONString(RemoteSuggestionsProviderImpl* service, | 562 void LoadMoreFromJSONString(RemoteSuggestionsProviderImpl* service, |
| 554 const Category& category, | 563 const Category& category, |
| 555 const std::string& json, | 564 const std::string& json, |
| 556 const std::set<std::string>& known_ids, | 565 const std::set<std::string>& known_ids, |
| 557 FetchDoneCallback callback) { | 566 FetchDoneCallback callback) { |
| 558 SetUpFetchResponse(json); | 567 SetUpFetchResponse(json); |
| 568 EXPECT_CALL(*scheduler(), AcquireQuotaForInteractiveFetch()) | |
| 569 .WillOnce(Return(true)) | |
| 570 .RetiresOnSaturation(); | |
| 559 service->Fetch(category, known_ids, callback); | 571 service->Fetch(category, known_ids, callback); |
| 560 base::RunLoop().RunUntilIdle(); | 572 base::RunLoop().RunUntilIdle(); |
| 561 } | 573 } |
| 562 | 574 |
| 563 private: | 575 private: |
| 564 variations::testing::VariationParamsManager params_manager_; | 576 variations::testing::VariationParamsManager params_manager_; |
| 565 test::RemoteSuggestionsTestUtils utils_; | 577 test::RemoteSuggestionsTestUtils utils_; |
| 566 base::MessageLoop message_loop_; | 578 base::MessageLoop message_loop_; |
| 567 FailingFakeURLFetcherFactory failing_url_fetcher_factory_; | 579 FailingFakeURLFetcherFactory failing_url_fetcher_factory_; |
| 568 // Instantiation of factory automatically sets itself as URLFetcher's factory. | 580 // Instantiation of factory automatically sets itself as URLFetcher's factory. |
| 569 net::FakeURLFetcherFactory fake_url_fetcher_factory_; | 581 net::FakeURLFetcherFactory fake_url_fetcher_factory_; |
| 570 const GURL test_url_; | 582 const GURL test_url_; |
| 571 std::unique_ptr<CategoryRanker> category_ranker_; | 583 std::unique_ptr<CategoryRanker> category_ranker_; |
| 572 UserClassifier user_classifier_; | 584 UserClassifier user_classifier_; |
| 573 std::unique_ptr<FakeContentSuggestionsProviderObserver> observer_; | 585 std::unique_ptr<FakeContentSuggestionsProviderObserver> observer_; |
| 574 RemoteSuggestionsFetcher* suggestions_fetcher_; | 586 RemoteSuggestionsFetcher* suggestions_fetcher_; |
| 575 NiceMock<MockImageFetcher>* image_fetcher_; | 587 NiceMock<MockImageFetcher>* image_fetcher_; |
| 576 FakeImageDecoder image_decoder_; | 588 FakeImageDecoder image_decoder_; |
| 589 std::unique_ptr<MockScheduler> scheduler_; | |
| 577 | 590 |
| 578 base::ScopedTempDir database_dir_; | 591 base::ScopedTempDir database_dir_; |
| 579 RemoteSuggestionsDatabase* database_; | 592 RemoteSuggestionsDatabase* database_; |
| 580 | 593 |
| 581 DISALLOW_COPY_AND_ASSIGN(RemoteSuggestionsProviderImplTest); | 594 DISALLOW_COPY_AND_ASSIGN(RemoteSuggestionsProviderImplTest); |
| 582 }; | 595 }; |
| 583 | 596 |
| 584 TEST_F(RemoteSuggestionsProviderImplTest, Full) { | 597 TEST_F(RemoteSuggestionsProviderImplTest, Full) { |
| 585 std::string json_str(GetTestJson({GetSuggestion()})); | 598 std::string json_str(GetTestJson({GetSuggestion()})); |
| 586 | 599 |
| (...skipping 1132 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1719 service->RefetchInTheBackground(/*callback=*/nullptr); | 1732 service->RefetchInTheBackground(/*callback=*/nullptr); |
| 1720 base::RunLoop().RunUntilIdle(); | 1733 base::RunLoop().RunUntilIdle(); |
| 1721 // TODO(jkrcal): Move together with the pref storage into the scheduler. | 1734 // TODO(jkrcal): Move together with the pref storage into the scheduler. |
| 1722 EXPECT_EQ( | 1735 EXPECT_EQ( |
| 1723 simple_test_clock_ptr->Now().ToInternalValue(), | 1736 simple_test_clock_ptr->Now().ToInternalValue(), |
| 1724 pref_service()->GetInt64(prefs::kLastSuccessfulBackgroundFetchTime)); | 1737 pref_service()->GetInt64(prefs::kLastSuccessfulBackgroundFetchTime)); |
| 1725 // TODO(markusheintz): Add a test that simulates a browser restart once the | 1738 // TODO(markusheintz): Add a test that simulates a browser restart once the |
| 1726 // scheduler refactoring is done (crbug.com/672434). | 1739 // scheduler refactoring is done (crbug.com/672434). |
| 1727 } | 1740 } |
| 1728 | 1741 |
| 1729 TEST_F(RemoteSuggestionsProviderImplTest, CallsSchedulerIfInited) { | 1742 TEST_F(RemoteSuggestionsProviderImplTest, CallsSchedulerWhenReady) { |
| 1730 // Initiate the service so that it is already READY. | 1743 SetStrictScheduler(); |
| 1731 auto service = MakeSuggestionsProvider(); | |
| 1732 StrictMock<MockScheduler> scheduler; | |
| 1733 // The scheduler should be notified of activation of the provider. | |
| 1734 EXPECT_CALL(scheduler, OnProviderActivated()); | |
| 1735 service->SetRemoteSuggestionsScheduler(&scheduler); | |
| 1736 } | |
| 1737 | |
| 1738 TEST_F(RemoteSuggestionsProviderImplTest, DoesNotCallSchedulerIfNotInited) { | |
| 1739 auto service = MakeSuggestionsProviderWithoutInitialization(); | 1744 auto service = MakeSuggestionsProviderWithoutInitialization(); |
| 1740 StrictMock<MockScheduler> scheduler; | |
| 1741 // The provider is not initialized yet, no callback should be called on | |
| 1742 // registering. | |
| 1743 service->SetRemoteSuggestionsScheduler(&scheduler); | |
| 1744 } | |
| 1745 | |
| 1746 TEST_F(RemoteSuggestionsProviderImplTest, CallsSchedulerWhenReady) { | |
| 1747 auto service = MakeSuggestionsProviderWithoutInitialization(); | |
| 1748 StrictMock<MockScheduler> scheduler; | |
| 1749 // The provider is not initialized yet, no callback should be called yet. | |
| 1750 service->SetRemoteSuggestionsScheduler(&scheduler); | |
| 1751 | 1745 |
| 1752 // Should be called when becoming ready. | 1746 // Should be called when becoming ready. |
| 1753 EXPECT_CALL(scheduler, OnProviderActivated()); | 1747 EXPECT_CALL(*scheduler(), OnProviderActivated()); |
| 1754 WaitForSuggestionsProviderInitialization(service.get(), | 1748 WaitForSuggestionsProviderInitialization(service.get(), |
| 1755 /*set_empty_response=*/true); | 1749 /*set_empty_response=*/true); |
| 1756 } | 1750 } |
| 1757 | 1751 |
| 1758 TEST_F(RemoteSuggestionsProviderImplTest, CallsSchedulerOnError) { | 1752 TEST_F(RemoteSuggestionsProviderImplTest, CallsSchedulerOnError) { |
| 1753 SetStrictScheduler(); | |
| 1759 auto service = MakeSuggestionsProviderWithoutInitialization(); | 1754 auto service = MakeSuggestionsProviderWithoutInitialization(); |
| 1760 StrictMock<MockScheduler> scheduler; | |
| 1761 // The provider is not initialized yet, no callback should be called yet. | |
| 1762 service->SetRemoteSuggestionsScheduler(&scheduler); | |
| 1763 | 1755 |
| 1764 // Should be called on error. | 1756 // Should be called on error. |
| 1765 EXPECT_CALL(scheduler, OnProviderDeactivated()); | 1757 EXPECT_CALL(*scheduler(), OnProviderDeactivated()); |
| 1766 service->EnterState(RemoteSuggestionsProviderImpl::State::ERROR_OCCURRED); | 1758 service->EnterState(RemoteSuggestionsProviderImpl::State::ERROR_OCCURRED); |
| 1767 } | 1759 } |
| 1768 | 1760 |
| 1769 TEST_F(RemoteSuggestionsProviderImplTest, CallsSchedulerWhenDisabled) { | 1761 TEST_F(RemoteSuggestionsProviderImplTest, CallsSchedulerWhenDisabled) { |
| 1762 SetStrictScheduler(); | |
| 1770 auto service = MakeSuggestionsProviderWithoutInitialization(); | 1763 auto service = MakeSuggestionsProviderWithoutInitialization(); |
| 1771 StrictMock<MockScheduler> scheduler; | |
| 1772 // The provider is not initialized yet, no callback should be called yet. | |
| 1773 service->SetRemoteSuggestionsScheduler(&scheduler); | |
| 1774 | 1764 |
| 1775 // Should be called when becoming disabled. First deactivate and only after | 1765 // Should be called when becoming disabled. First deactivate and only after |
| 1776 // that clear the suggestions so that they are not fetched again. | 1766 // that clear the suggestions so that they are not fetched again. |
| 1777 { | 1767 { |
| 1778 InSequence s; | 1768 InSequence s; |
| 1779 EXPECT_CALL(scheduler, OnProviderDeactivated()); | 1769 EXPECT_CALL(*scheduler(), OnProviderDeactivated()); |
| 1780 ASSERT_THAT(service->ready(), Eq(false)); | 1770 ASSERT_THAT(service->ready(), Eq(false)); |
| 1781 EXPECT_CALL(scheduler, OnSuggestionsCleared()); | 1771 EXPECT_CALL(*scheduler(), OnSuggestionsCleared()); |
| 1782 } | 1772 } |
| 1783 service->EnterState(RemoteSuggestionsProviderImpl::State::DISABLED); | 1773 service->EnterState(RemoteSuggestionsProviderImpl::State::DISABLED); |
| 1784 } | 1774 } |
| 1785 | 1775 |
| 1786 TEST_F(RemoteSuggestionsProviderImplTest, CallsSchedulerWhenHistoryCleared) { | 1776 TEST_F(RemoteSuggestionsProviderImplTest, CallsSchedulerWhenHistoryCleared) { |
| 1777 SetStrictScheduler(); | |
| 1787 // Initiate the service so that it is already READY. | 1778 // Initiate the service so that it is already READY. |
| 1779 EXPECT_CALL(*scheduler(), OnProviderActivated()); | |
| 1788 auto service = MakeSuggestionsProvider(); | 1780 auto service = MakeSuggestionsProvider(); |
| 1789 StrictMock<MockScheduler> scheduler; | 1781 |
| 1790 // The scheduler should be notified of activation of the provider. | |
| 1791 EXPECT_CALL(scheduler, OnProviderActivated()); | |
| 1792 // The scheduler should be notified of clearing the history. | 1782 // The scheduler should be notified of clearing the history. |
| 1793 EXPECT_CALL(scheduler, OnHistoryCleared()); | 1783 EXPECT_CALL(*scheduler(), OnHistoryCleared()); |
| 1794 service->SetRemoteSuggestionsScheduler(&scheduler); | |
| 1795 service->ClearHistory(GetDefaultCreationTime(), GetDefaultExpirationTime(), | 1784 service->ClearHistory(GetDefaultCreationTime(), GetDefaultExpirationTime(), |
| 1796 base::Callback<bool(const GURL& url)>()); | 1785 base::Callback<bool(const GURL& url)>()); |
| 1797 } | 1786 } |
| 1798 | 1787 |
| 1799 TEST_F(RemoteSuggestionsProviderImplTest, CallsSchedulerWhenSignedIn) { | 1788 TEST_F(RemoteSuggestionsProviderImplTest, CallsSchedulerWhenSignedIn) { |
| 1789 SetStrictScheduler(); | |
| 1800 // Initiate the service so that it is already READY. | 1790 // Initiate the service so that it is already READY. |
| 1791 EXPECT_CALL(*scheduler(), OnProviderActivated()); | |
| 1801 auto service = MakeSuggestionsProvider(); | 1792 auto service = MakeSuggestionsProvider(); |
| 1802 StrictMock<MockScheduler> scheduler; | 1793 |
| 1803 // The scheduler should be notified of activation of the provider. | |
| 1804 EXPECT_CALL(scheduler, OnProviderActivated()); | |
| 1805 // The scheduler should be notified of clearing the history. | 1794 // The scheduler should be notified of clearing the history. |
| 1806 EXPECT_CALL(scheduler, OnSuggestionsCleared()); | 1795 EXPECT_CALL(*scheduler(), OnSuggestionsCleared()); |
| 1807 | |
| 1808 service->SetRemoteSuggestionsScheduler(&scheduler); | |
| 1809 service->OnStatusChanged(RemoteSuggestionsStatus::ENABLED_AND_SIGNED_IN, | 1796 service->OnStatusChanged(RemoteSuggestionsStatus::ENABLED_AND_SIGNED_IN, |
| 1810 RemoteSuggestionsStatus::ENABLED_AND_SIGNED_OUT); | 1797 RemoteSuggestionsStatus::ENABLED_AND_SIGNED_OUT); |
| 1811 } | 1798 } |
| 1812 | 1799 |
| 1813 TEST_F(RemoteSuggestionsProviderImplTest, CallsSchedulerWhenSignedOut) { | 1800 TEST_F(RemoteSuggestionsProviderImplTest, CallsSchedulerWhenSignedOut) { |
| 1801 SetStrictScheduler(); | |
| 1814 // Initiate the service so that it is already READY. | 1802 // Initiate the service so that it is already READY. |
| 1803 EXPECT_CALL(*scheduler(), OnProviderActivated()); | |
| 1815 auto service = MakeSuggestionsProvider(); | 1804 auto service = MakeSuggestionsProvider(); |
| 1816 StrictMock<MockScheduler> scheduler; | 1805 |
| 1817 // The scheduler should be notified of activation of the provider. | |
| 1818 EXPECT_CALL(scheduler, OnProviderActivated()); | |
| 1819 // The scheduler should be notified of clearing the history. | 1806 // The scheduler should be notified of clearing the history. |
| 1820 EXPECT_CALL(scheduler, OnSuggestionsCleared()); | 1807 EXPECT_CALL(*scheduler(), OnSuggestionsCleared()); |
| 1821 | |
| 1822 service->SetRemoteSuggestionsScheduler(&scheduler); | |
| 1823 service->OnStatusChanged(RemoteSuggestionsStatus::ENABLED_AND_SIGNED_OUT, | 1808 service->OnStatusChanged(RemoteSuggestionsStatus::ENABLED_AND_SIGNED_OUT, |
| 1824 RemoteSuggestionsStatus::ENABLED_AND_SIGNED_IN); | 1809 RemoteSuggestionsStatus::ENABLED_AND_SIGNED_IN); |
| 1825 } | 1810 } |
| 1826 | 1811 |
| 1827 } // namespace ntp_snippets | 1812 } // namespace ntp_snippets |
| OLD | NEW |