| 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 |
| 473 std::unique_ptr<RemoteSuggestionsProviderImpl> |
| 474 MakeSuggestionsProviderWithoutInitializationWithStrictScheduler() { |
| 475 scheduler_ = base::MakeUnique<StrictMock<MockScheduler>>(); |
| 476 return MakeSuggestionsProviderWithoutInitialization(); |
| 477 } |
| 478 |
| 469 void WaitForSuggestionsProviderInitialization( | 479 void WaitForSuggestionsProviderInitialization( |
| 470 RemoteSuggestionsProviderImpl* service, | 480 RemoteSuggestionsProviderImpl* service, |
| 471 bool set_empty_response) { | 481 bool set_empty_response) { |
| 472 EXPECT_EQ(RemoteSuggestionsProviderImpl::State::NOT_INITED, | 482 EXPECT_EQ(RemoteSuggestionsProviderImpl::State::NOT_INITED, |
| 473 service->state_); | 483 service->state_); |
| 474 | 484 |
| 475 // Add an initial fetch response, as the service tries to fetch when there | 485 // Add an initial fetch response, as the service tries to fetch when there |
| 476 // is nothing in the DB. | 486 // is nothing in the DB. |
| 477 if (set_empty_response) { | 487 if (set_empty_response) { |
| 478 SetUpFetchResponse(GetTestJson(std::vector<std::string>())); | 488 SetUpFetchResponse(GetTestJson(std::vector<std::string>())); |
| (...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 521 FakeContentSuggestionsProviderObserver& observer() { return *observer_; } | 531 FakeContentSuggestionsProviderObserver& observer() { return *observer_; } |
| 522 RemoteSuggestionsFetcher* suggestions_fetcher() { | 532 RemoteSuggestionsFetcher* suggestions_fetcher() { |
| 523 return suggestions_fetcher_; | 533 return suggestions_fetcher_; |
| 524 } | 534 } |
| 525 // TODO(tschumann): Make this a strict-mock. We want to avoid unneccesary | 535 // TODO(tschumann): Make this a strict-mock. We want to avoid unneccesary |
| 526 // network requests. | 536 // network requests. |
| 527 NiceMock<MockImageFetcher>* image_fetcher() { return image_fetcher_; } | 537 NiceMock<MockImageFetcher>* image_fetcher() { return image_fetcher_; } |
| 528 FakeImageDecoder* image_decoder() { return &image_decoder_; } | 538 FakeImageDecoder* image_decoder() { return &image_decoder_; } |
| 529 PrefService* pref_service() { return utils_.pref_service(); } | 539 PrefService* pref_service() { return utils_.pref_service(); } |
| 530 RemoteSuggestionsDatabase* database() { return database_; } | 540 RemoteSuggestionsDatabase* database() { return database_; } |
| 541 MockScheduler* scheduler() { return scheduler_.get(); } |
| 531 | 542 |
| 532 // Provide the json to be returned by the fake fetcher. | 543 // Provide the json to be returned by the fake fetcher. |
| 533 void SetUpFetchResponse(const std::string& json) { | 544 void SetUpFetchResponse(const std::string& json) { |
| 534 fake_url_fetcher_factory_.SetFakeResponse(test_url_, json, net::HTTP_OK, | 545 fake_url_fetcher_factory_.SetFakeResponse(test_url_, json, net::HTTP_OK, |
| 535 net::URLRequestStatus::SUCCESS); | 546 net::URLRequestStatus::SUCCESS); |
| 536 } | 547 } |
| 537 | 548 |
| 538 // Have the fake fetcher fail due to a HTTP error like a 404. | 549 // Have the fake fetcher fail due to a HTTP error like a 404. |
| 539 void SetUpHttpError() { | 550 void SetUpHttpError() { |
| 540 fake_url_fetcher_factory_.SetFakeResponse(test_url_, /*json=*/std::string(), | 551 fake_url_fetcher_factory_.SetFakeResponse(test_url_, /*json=*/std::string(), |
| 541 net::HTTP_NOT_FOUND, | 552 net::HTTP_NOT_FOUND, |
| 542 net::URLRequestStatus::SUCCESS); | 553 net::URLRequestStatus::SUCCESS); |
| 543 } | 554 } |
| 544 | 555 |
| 545 void LoadFromJSONString(RemoteSuggestionsProviderImpl* service, | 556 void LoadFromJSONString(RemoteSuggestionsProviderImpl* service, |
| 546 const std::string& json) { | 557 const std::string& json) { |
| 547 SetUpFetchResponse(json); | 558 SetUpFetchResponse(json); |
| 548 service->FetchSuggestions(/*interactive_request=*/true, | 559 service->FetchSuggestions(/*interactive_request=*/true, |
| 549 /*callback=*/nullptr); | 560 /*callback=*/nullptr); |
| 550 base::RunLoop().RunUntilIdle(); | 561 base::RunLoop().RunUntilIdle(); |
| 551 } | 562 } |
| 552 | 563 |
| 553 void LoadMoreFromJSONString(RemoteSuggestionsProviderImpl* service, | 564 void LoadMoreFromJSONString(RemoteSuggestionsProviderImpl* service, |
| 554 const Category& category, | 565 const Category& category, |
| 555 const std::string& json, | 566 const std::string& json, |
| 556 const std::set<std::string>& known_ids, | 567 const std::set<std::string>& known_ids, |
| 557 FetchDoneCallback callback) { | 568 FetchDoneCallback callback) { |
| 558 SetUpFetchResponse(json); | 569 SetUpFetchResponse(json); |
| 570 EXPECT_CALL(*scheduler(), AcquireQuotaForInteractiveFetch()) |
| 571 .WillOnce(Return(true)) |
| 572 .RetiresOnSaturation(); |
| 559 service->Fetch(category, known_ids, callback); | 573 service->Fetch(category, known_ids, callback); |
| 560 base::RunLoop().RunUntilIdle(); | 574 base::RunLoop().RunUntilIdle(); |
| 561 } | 575 } |
| 562 | 576 |
| 563 private: | 577 private: |
| 564 variations::testing::VariationParamsManager params_manager_; | 578 variations::testing::VariationParamsManager params_manager_; |
| 565 test::RemoteSuggestionsTestUtils utils_; | 579 test::RemoteSuggestionsTestUtils utils_; |
| 566 base::MessageLoop message_loop_; | 580 base::MessageLoop message_loop_; |
| 567 FailingFakeURLFetcherFactory failing_url_fetcher_factory_; | 581 FailingFakeURLFetcherFactory failing_url_fetcher_factory_; |
| 568 // Instantiation of factory automatically sets itself as URLFetcher's factory. | 582 // Instantiation of factory automatically sets itself as URLFetcher's factory. |
| 569 net::FakeURLFetcherFactory fake_url_fetcher_factory_; | 583 net::FakeURLFetcherFactory fake_url_fetcher_factory_; |
| 570 const GURL test_url_; | 584 const GURL test_url_; |
| 571 std::unique_ptr<CategoryRanker> category_ranker_; | 585 std::unique_ptr<CategoryRanker> category_ranker_; |
| 572 UserClassifier user_classifier_; | 586 UserClassifier user_classifier_; |
| 573 std::unique_ptr<FakeContentSuggestionsProviderObserver> observer_; | 587 std::unique_ptr<FakeContentSuggestionsProviderObserver> observer_; |
| 574 RemoteSuggestionsFetcher* suggestions_fetcher_; | 588 RemoteSuggestionsFetcher* suggestions_fetcher_; |
| 575 NiceMock<MockImageFetcher>* image_fetcher_; | 589 NiceMock<MockImageFetcher>* image_fetcher_; |
| 576 FakeImageDecoder image_decoder_; | 590 FakeImageDecoder image_decoder_; |
| 591 std::unique_ptr<MockScheduler> scheduler_; |
| 577 | 592 |
| 578 base::ScopedTempDir database_dir_; | 593 base::ScopedTempDir database_dir_; |
| 579 RemoteSuggestionsDatabase* database_; | 594 RemoteSuggestionsDatabase* database_; |
| 580 | 595 |
| 581 DISALLOW_COPY_AND_ASSIGN(RemoteSuggestionsProviderImplTest); | 596 DISALLOW_COPY_AND_ASSIGN(RemoteSuggestionsProviderImplTest); |
| 582 }; | 597 }; |
| 583 | 598 |
| 584 TEST_F(RemoteSuggestionsProviderImplTest, Full) { | 599 TEST_F(RemoteSuggestionsProviderImplTest, Full) { |
| 585 std::string json_str(GetTestJson({GetSuggestion()})); | 600 std::string json_str(GetTestJson({GetSuggestion()})); |
| 586 | 601 |
| (...skipping 1132 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1719 service->RefetchInTheBackground(/*callback=*/nullptr); | 1734 service->RefetchInTheBackground(/*callback=*/nullptr); |
| 1720 base::RunLoop().RunUntilIdle(); | 1735 base::RunLoop().RunUntilIdle(); |
| 1721 // TODO(jkrcal): Move together with the pref storage into the scheduler. | 1736 // TODO(jkrcal): Move together with the pref storage into the scheduler. |
| 1722 EXPECT_EQ( | 1737 EXPECT_EQ( |
| 1723 simple_test_clock_ptr->Now().ToInternalValue(), | 1738 simple_test_clock_ptr->Now().ToInternalValue(), |
| 1724 pref_service()->GetInt64(prefs::kLastSuccessfulBackgroundFetchTime)); | 1739 pref_service()->GetInt64(prefs::kLastSuccessfulBackgroundFetchTime)); |
| 1725 // TODO(markusheintz): Add a test that simulates a browser restart once the | 1740 // TODO(markusheintz): Add a test that simulates a browser restart once the |
| 1726 // scheduler refactoring is done (crbug.com/672434). | 1741 // scheduler refactoring is done (crbug.com/672434). |
| 1727 } | 1742 } |
| 1728 | 1743 |
| 1729 TEST_F(RemoteSuggestionsProviderImplTest, CallsSchedulerIfInited) { | |
| 1730 // Initiate the service so that it is already READY. | |
| 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(); | |
| 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) { | 1744 TEST_F(RemoteSuggestionsProviderImplTest, CallsSchedulerWhenReady) { |
| 1747 auto service = MakeSuggestionsProviderWithoutInitialization(); | 1745 auto service = |
| 1748 StrictMock<MockScheduler> scheduler; | 1746 MakeSuggestionsProviderWithoutInitializationWithStrictScheduler(); |
| 1749 // The provider is not initialized yet, no callback should be called yet. | |
| 1750 service->SetRemoteSuggestionsScheduler(&scheduler); | |
| 1751 | 1747 |
| 1752 // Should be called when becoming ready. | 1748 // Should be called when becoming ready. |
| 1753 EXPECT_CALL(scheduler, OnProviderActivated()); | 1749 EXPECT_CALL(*scheduler(), OnProviderActivated()); |
| 1754 WaitForSuggestionsProviderInitialization(service.get(), | 1750 WaitForSuggestionsProviderInitialization(service.get(), |
| 1755 /*set_empty_response=*/true); | 1751 /*set_empty_response=*/true); |
| 1756 } | 1752 } |
| 1757 | 1753 |
| 1758 TEST_F(RemoteSuggestionsProviderImplTest, CallsSchedulerOnError) { | 1754 TEST_F(RemoteSuggestionsProviderImplTest, CallsSchedulerOnError) { |
| 1759 auto service = MakeSuggestionsProviderWithoutInitialization(); | 1755 auto service = |
| 1760 StrictMock<MockScheduler> scheduler; | 1756 MakeSuggestionsProviderWithoutInitializationWithStrictScheduler(); |
| 1761 // The provider is not initialized yet, no callback should be called yet. | |
| 1762 service->SetRemoteSuggestionsScheduler(&scheduler); | |
| 1763 | 1757 |
| 1764 // Should be called on error. | 1758 // Should be called on error. |
| 1765 EXPECT_CALL(scheduler, OnProviderDeactivated()); | 1759 EXPECT_CALL(*scheduler(), OnProviderDeactivated()); |
| 1766 service->EnterState(RemoteSuggestionsProviderImpl::State::ERROR_OCCURRED); | 1760 service->EnterState(RemoteSuggestionsProviderImpl::State::ERROR_OCCURRED); |
| 1767 } | 1761 } |
| 1768 | 1762 |
| 1769 TEST_F(RemoteSuggestionsProviderImplTest, CallsSchedulerWhenDisabled) { | 1763 TEST_F(RemoteSuggestionsProviderImplTest, CallsSchedulerWhenDisabled) { |
| 1770 auto service = MakeSuggestionsProviderWithoutInitialization(); | 1764 auto service = |
| 1771 StrictMock<MockScheduler> scheduler; | 1765 MakeSuggestionsProviderWithoutInitializationWithStrictScheduler(); |
| 1772 // The provider is not initialized yet, no callback should be called yet. | |
| 1773 service->SetRemoteSuggestionsScheduler(&scheduler); | |
| 1774 | 1766 |
| 1775 // Should be called when becoming disabled. First deactivate and only after | 1767 // Should be called when becoming disabled. First deactivate and only after |
| 1776 // that clear the suggestions so that they are not fetched again. | 1768 // that clear the suggestions so that they are not fetched again. |
| 1777 { | 1769 { |
| 1778 InSequence s; | 1770 InSequence s; |
| 1779 EXPECT_CALL(scheduler, OnProviderDeactivated()); | 1771 EXPECT_CALL(*scheduler(), OnProviderDeactivated()); |
| 1780 ASSERT_THAT(service->ready(), Eq(false)); | 1772 ASSERT_THAT(service->ready(), Eq(false)); |
| 1781 EXPECT_CALL(scheduler, OnSuggestionsCleared()); | 1773 EXPECT_CALL(*scheduler(), OnSuggestionsCleared()); |
| 1782 } | 1774 } |
| 1783 service->EnterState(RemoteSuggestionsProviderImpl::State::DISABLED); | 1775 service->EnterState(RemoteSuggestionsProviderImpl::State::DISABLED); |
| 1784 } | 1776 } |
| 1785 | 1777 |
| 1786 TEST_F(RemoteSuggestionsProviderImplTest, CallsSchedulerWhenHistoryCleared) { | 1778 TEST_F(RemoteSuggestionsProviderImplTest, CallsSchedulerWhenHistoryCleared) { |
| 1779 auto service = |
| 1780 MakeSuggestionsProviderWithoutInitializationWithStrictScheduler(); |
| 1787 // Initiate the service so that it is already READY. | 1781 // Initiate the service so that it is already READY. |
| 1788 auto service = MakeSuggestionsProvider(); | 1782 EXPECT_CALL(*scheduler(), OnProviderActivated()); |
| 1789 StrictMock<MockScheduler> scheduler; | 1783 WaitForSuggestionsProviderInitialization(service.get(), |
| 1790 // The scheduler should be notified of activation of the provider. | 1784 /*set_empty_response=*/true); |
| 1791 EXPECT_CALL(scheduler, OnProviderActivated()); | 1785 |
| 1792 // The scheduler should be notified of clearing the history. | 1786 // The scheduler should be notified of clearing the history. |
| 1793 EXPECT_CALL(scheduler, OnHistoryCleared()); | 1787 EXPECT_CALL(*scheduler(), OnHistoryCleared()); |
| 1794 service->SetRemoteSuggestionsScheduler(&scheduler); | |
| 1795 service->ClearHistory(GetDefaultCreationTime(), GetDefaultExpirationTime(), | 1788 service->ClearHistory(GetDefaultCreationTime(), GetDefaultExpirationTime(), |
| 1796 base::Callback<bool(const GURL& url)>()); | 1789 base::Callback<bool(const GURL& url)>()); |
| 1797 } | 1790 } |
| 1798 | 1791 |
| 1799 TEST_F(RemoteSuggestionsProviderImplTest, CallsSchedulerWhenSignedIn) { | 1792 TEST_F(RemoteSuggestionsProviderImplTest, CallsSchedulerWhenSignedIn) { |
| 1793 auto service = |
| 1794 MakeSuggestionsProviderWithoutInitializationWithStrictScheduler(); |
| 1800 // Initiate the service so that it is already READY. | 1795 // Initiate the service so that it is already READY. |
| 1801 auto service = MakeSuggestionsProvider(); | 1796 EXPECT_CALL(*scheduler(), OnProviderActivated()); |
| 1802 StrictMock<MockScheduler> scheduler; | 1797 WaitForSuggestionsProviderInitialization(service.get(), |
| 1803 // The scheduler should be notified of activation of the provider. | 1798 /*set_empty_response=*/true); |
| 1804 EXPECT_CALL(scheduler, OnProviderActivated()); | 1799 |
| 1805 // The scheduler should be notified of clearing the history. | 1800 // The scheduler should be notified of clearing the history. |
| 1806 EXPECT_CALL(scheduler, OnSuggestionsCleared()); | 1801 EXPECT_CALL(*scheduler(), OnSuggestionsCleared()); |
| 1807 | |
| 1808 service->SetRemoteSuggestionsScheduler(&scheduler); | |
| 1809 service->OnStatusChanged(RemoteSuggestionsStatus::ENABLED_AND_SIGNED_IN, | 1802 service->OnStatusChanged(RemoteSuggestionsStatus::ENABLED_AND_SIGNED_IN, |
| 1810 RemoteSuggestionsStatus::ENABLED_AND_SIGNED_OUT); | 1803 RemoteSuggestionsStatus::ENABLED_AND_SIGNED_OUT); |
| 1811 } | 1804 } |
| 1812 | 1805 |
| 1813 TEST_F(RemoteSuggestionsProviderImplTest, CallsSchedulerWhenSignedOut) { | 1806 TEST_F(RemoteSuggestionsProviderImplTest, CallsSchedulerWhenSignedOut) { |
| 1807 auto service = |
| 1808 MakeSuggestionsProviderWithoutInitializationWithStrictScheduler(); |
| 1814 // Initiate the service so that it is already READY. | 1809 // Initiate the service so that it is already READY. |
| 1815 auto service = MakeSuggestionsProvider(); | 1810 EXPECT_CALL(*scheduler(), OnProviderActivated()); |
| 1816 StrictMock<MockScheduler> scheduler; | 1811 WaitForSuggestionsProviderInitialization(service.get(), |
| 1817 // The scheduler should be notified of activation of the provider. | 1812 /*set_empty_response=*/true); |
| 1818 EXPECT_CALL(scheduler, OnProviderActivated()); | 1813 |
| 1819 // The scheduler should be notified of clearing the history. | 1814 // The scheduler should be notified of clearing the history. |
| 1820 EXPECT_CALL(scheduler, OnSuggestionsCleared()); | 1815 EXPECT_CALL(*scheduler(), OnSuggestionsCleared()); |
| 1821 | |
| 1822 service->SetRemoteSuggestionsScheduler(&scheduler); | |
| 1823 service->OnStatusChanged(RemoteSuggestionsStatus::ENABLED_AND_SIGNED_OUT, | 1816 service->OnStatusChanged(RemoteSuggestionsStatus::ENABLED_AND_SIGNED_OUT, |
| 1824 RemoteSuggestionsStatus::ENABLED_AND_SIGNED_IN); | 1817 RemoteSuggestionsStatus::ENABLED_AND_SIGNED_IN); |
| 1825 } | 1818 } |
| 1826 | 1819 |
| 1827 } // namespace ntp_snippets | 1820 } // namespace ntp_snippets |
| OLD | NEW |