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

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

Issue 2191343002: 📰 Remove SnippetService's dependency on Sync (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: update some doc, show NO_SNIPPETS instead of SIGNIN when during INITIALIZING state Created 4 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
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/ntp_snippets_service.h" 5 #include "components/ntp_snippets/ntp_snippets_service.h"
6 6
7 #include <memory> 7 #include <memory>
8 #include <vector> 8 #include <vector>
9 9
10 #include "base/command_line.h" 10 #include "base/command_line.h"
(...skipping 311 matching lines...) Expand 10 before | Expand all | Expand 10 after
322 322
323 // Add an initial fetch response, as the service tries to fetch when there 323 // Add an initial fetch response, as the service tries to fetch when there
324 // is nothing in the DB. 324 // is nothing in the DB.
325 SetUpFetchResponse(GetTestJson({GetSnippet()})); 325 SetUpFetchResponse(GetTestJson({GetSnippet()}));
326 326
327 service_.reset(new NTPSnippetsService( 327 service_.reset(new NTPSnippetsService(
328 enabled, pref_service(), nullptr, "fr", &scheduler_, 328 enabled, pref_service(), nullptr, "fr", &scheduler_,
329 std::move(snippets_fetcher), /*image_fetcher=*/nullptr, 329 std::move(snippets_fetcher), /*image_fetcher=*/nullptr,
330 /*image_fetcher=*/nullptr, base::MakeUnique<NTPSnippetsDatabase>( 330 /*image_fetcher=*/nullptr, base::MakeUnique<NTPSnippetsDatabase>(
331 database_dir_.path(), task_runner), 331 database_dir_.path(), task_runner),
332 base::MakeUnique<NTPSnippetsStatusService>( 332 base::MakeUnique<NTPSnippetsStatusService>(fake_signin_manager(),
333 fake_signin_manager(), mock_sync_service(), pref_service()))); 333 pref_service())));
334 334
335 if (enabled) 335 if (enabled)
336 WaitForDBLoad(service_.get()); 336 WaitForDBLoad(service_.get());
337 } 337 }
338 338
339 std::string MakeUniqueID(const std::string& within_category_id) { 339 std::string MakeUniqueID(const std::string& within_category_id) {
340 return NTPSnippetsService::MakeUniqueID( 340 return NTPSnippetsService::MakeUniqueID(
341 ContentSuggestionsCategory::ARTICLES, within_category_id); 341 ContentSuggestionsCategory::ARTICLES, within_category_id);
342 } 342 }
343 343
(...skipping 516 matching lines...) Expand 10 before | Expand all | Expand 10 after
860 // Dismiss the snippet via the mashable source corpus ID. 860 // Dismiss the snippet via the mashable source corpus ID.
861 service()->DismissSuggestion(MakeUniqueID(source_urls[0])); 861 service()->DismissSuggestion(MakeUniqueID(source_urls[0]));
862 EXPECT_THAT(service()->snippets(), IsEmpty()); 862 EXPECT_THAT(service()->snippets(), IsEmpty());
863 863
864 // The same article from the AOL domain should now be detected as dismissed. 864 // The same article from the AOL domain should now be detected as dismissed.
865 LoadFromJSONString(GetTestJson({GetSnippetWithUrlAndTimesAndSources( 865 LoadFromJSONString(GetTestJson({GetSnippetWithUrlAndTimesAndSources(
866 source_urls[1], creation, expiry, source_urls, publishers, amp_urls)})); 866 source_urls[1], creation, expiry, source_urls, publishers, amp_urls)}));
867 ASSERT_THAT(service()->snippets(), IsEmpty()); 867 ASSERT_THAT(service()->snippets(), IsEmpty());
868 } 868 }
869 869
870 TEST_F(NTPSnippetsServiceTest, HistorySyncStateChanges) { 870 TEST_F(NTPSnippetsServiceTest, StatusChanges) {
871 MockServiceObserver mock_observer; 871 MockServiceObserver mock_observer;
872 service()->AddObserver(&mock_observer); 872 service()->AddObserver(&mock_observer);
873 873
874 // Simulate user signed out 874 // Simulate user signed out
875 SetUpFetchResponse(GetTestJson({GetSnippet()})); 875 SetUpFetchResponse(GetTestJson({GetSnippet()}));
876 EXPECT_CALL(mock_observer, NTPSnippetsServiceDisabledReasonChanged( 876 EXPECT_CALL(mock_observer, NTPSnippetsServiceDisabledReasonChanged(
877 DisabledReason::SIGNED_OUT)); 877 DisabledReason::SIGNED_OUT));
878 service()->OnDisabledReasonChanged(DisabledReason::SIGNED_OUT); 878 service()->OnDisabledReasonChanged(DisabledReason::SIGNED_OUT);
879 base::RunLoop().RunUntilIdle(); 879 base::RunLoop().RunUntilIdle();
880 EXPECT_EQ(NTPSnippetsService::State::DISABLED, service()->state_); 880 EXPECT_EQ(NTPSnippetsService::State::DISABLED, service()->state_);
881 EXPECT_THAT(service()->snippets(), IsEmpty()); // No fetch should be made. 881 EXPECT_THAT(service()->snippets(), IsEmpty()); // No fetch should be made.
882 882
883 // Simulate user sign in. The service should be ready again and load snippets. 883 // Simulate user sign in. The service should be ready again and load snippets.
884 SetUpFetchResponse(GetTestJson({GetSnippet()})); 884 SetUpFetchResponse(GetTestJson({GetSnippet()}));
885 EXPECT_CALL(mock_observer, 885 EXPECT_CALL(mock_observer,
886 NTPSnippetsServiceDisabledReasonChanged(DisabledReason::NONE)); 886 NTPSnippetsServiceDisabledReasonChanged(DisabledReason::NONE));
887 EXPECT_CALL(mock_scheduler(), Schedule(_, _, _, _)).Times(1); 887 EXPECT_CALL(mock_scheduler(), Schedule(_, _, _, _)).Times(1);
888 service()->OnDisabledReasonChanged(DisabledReason::NONE); 888 service()->OnDisabledReasonChanged(DisabledReason::NONE);
889 base::RunLoop().RunUntilIdle(); 889 base::RunLoop().RunUntilIdle();
890 EXPECT_EQ(NTPSnippetsService::State::READY, service()->state_); 890 EXPECT_EQ(NTPSnippetsService::State::READY, service()->state_);
891 EXPECT_FALSE(service()->snippets().empty()); 891 EXPECT_FALSE(service()->snippets().empty());
892 892
893 service()->RemoveObserver(&mock_observer); 893 service()->RemoveObserver(&mock_observer);
894 } 894 }
895 895
896 } // namespace ntp_snippets 896 } // namespace ntp_snippets
OLDNEW
« no previous file with comments | « components/ntp_snippets/ntp_snippets_service.cc ('k') | components/ntp_snippets/ntp_snippets_status_service.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698