Chromium Code Reviews| 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..7cc2c8bbf8907b856747fef882a4ac17b3453327 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; |
| + pages->GetDictionary(1, &second_page); |
|
Marc Treib
2017/01/18 11:24:01
ASSERT_TRUE?
Also, maybe add a comment? (Set the
vitaliii
2017/01/18 11:48:16
Done.
|
| + 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; |
| + 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, ""); |
|
Marc Treib
2017/01/18 11:24:01
Isn't this the default anyway?
vitaliii
2017/01/18 11:48:16
Yes, it is.
I choose default in fake_physical_web
|
| + } |
| + |
| + physical_web_data_source()->SetMetadata(std::move(pages)); |
| + // The closest page should be reported. |
|
Marc Treib
2017/01/18 11:24:01
Inaccurate comment
vitaliii
2017/01/18 11:48:16
Done.
|
| + 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(); |