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

Unified Diff: components/ntp_snippets/physical_web_pages/physical_web_page_suggestions_provider_unittest.cc

Issue 2640773002: [NTP::PhysicalWeb] Filter our pages with same group_id. (Closed)
Patch Set: treib@ nits. Created 3 years, 11 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 side-by-side diff with in-line comments
Download patch
Index: components/ntp_snippets/physical_web_pages/physical_web_page_suggestions_provider_unittest.cc
diff --git a/components/ntp_snippets/physical_web_pages/physical_web_page_suggestions_provider_unittest.cc b/components/ntp_snippets/physical_web_pages/physical_web_page_suggestions_provider_unittest.cc
index 763abe01cd5995d3145c8c4a63dee9ba8051fa22..633fd97bfd191ddab522018ccfb2604de41b355b 100644
--- a/components/ntp_snippets/physical_web_pages/physical_web_page_suggestions_provider_unittest.cc
+++ b/components/ntp_snippets/physical_web_pages/physical_web_page_suggestions_provider_unittest.cc
@@ -179,6 +179,70 @@ TEST_F(PhysicalWebPageSuggestionsProviderTest, ShouldSortByDistance) {
}
TEST_F(PhysicalWebPageSuggestionsProviderTest,
+ ShouldConsiderPagesWithoutDistanceEstimateFurthest) {
+ IgnoreOnCategoryStatusChangedToAvailable();
+ IgnoreOnSuggestionInvalidated();
+ // |CreateDummyPhysicalWebPages| builds pages with distances 1, 2 and 3
+ // respectively.
+ std::unique_ptr<base::ListValue> pages =
+ CreateDummyPhysicalWebPages({3, 2, 1});
+ DictionaryValue* second_page;
+ // Set the second page distance estimate to unknown.
+ ASSERT_TRUE(pages->GetDictionary(1, &second_page));
+ second_page->SetDouble(physical_web::kDistanceEstimateKey, -1);
+ physical_web_data_source()->SetMetadata(std::move(pages));
+ EXPECT_CALL(
+ *observer(),
+ OnNewSuggestions(_, provided_category(),
+ ElementsAre(HasUrl("https://resolved_url.com/3"),
+ HasUrl("https://resolved_url.com/1"),
+ HasUrl("https://resolved_url.com/2"))));
+ CreateProvider();
+}
+
+TEST_F(PhysicalWebPageSuggestionsProviderTest,
+ ShouldNotShowSuggestionsWithSameGroupId) {
+ IgnoreOnCategoryStatusChangedToAvailable();
+ IgnoreOnSuggestionInvalidated();
+ // |CreateDummyPhysicalWebPages| builds pages with distances 1, 2
+ // respectively.
+ std::unique_ptr<base::ListValue> pages = CreateDummyPhysicalWebPages({2, 1});
+ for (int i = 0; i < 2; ++i) {
+ DictionaryValue* page;
+ ASSERT_TRUE(pages->GetDictionary(i, &page));
+ page->SetString(physical_web::kGroupIdKey, "some_group_id");
+ }
+
+ physical_web_data_source()->SetMetadata(std::move(pages));
+ // The closest page should be reported.
+ EXPECT_CALL(
+ *observer(),
+ OnNewSuggestions(_, provided_category(),
+ ElementsAre(HasUrl("https://resolved_url.com/2"))));
+ CreateProvider();
+}
+
+TEST_F(PhysicalWebPageSuggestionsProviderTest,
+ ShouldShowSuggestionsWithEmptyGroupId) {
+ IgnoreOnCategoryStatusChangedToAvailable();
+ IgnoreOnSuggestionInvalidated();
+ std::unique_ptr<base::ListValue> pages = CreateDummyPhysicalWebPages({1, 2});
+ for (int i = 0; i < 2; ++i) {
+ DictionaryValue* page;
+ pages->GetDictionary(i, &page);
+ page->SetString(physical_web::kGroupIdKey, "");
+ }
+
+ physical_web_data_source()->SetMetadata(std::move(pages));
+ EXPECT_CALL(*observer(),
+ OnNewSuggestions(
+ _, provided_category(),
+ UnorderedElementsAre(HasUrl("https://resolved_url.com/1"),
+ HasUrl("https://resolved_url.com/2"))));
+ CreateProvider();
+}
+
+TEST_F(PhysicalWebPageSuggestionsProviderTest,
FetchMoreShouldFilterAndReturnSortedSuggestions) {
IgnoreOnCategoryStatusChangedToAvailable();
IgnoreOnSuggestionInvalidated();

Powered by Google App Engine
This is Rietveld 408576698