Chromium Code Reviews| Index: components/omnibox/browser/autocomplete_match_unittest.cc |
| diff --git a/components/omnibox/browser/autocomplete_match_unittest.cc b/components/omnibox/browser/autocomplete_match_unittest.cc |
| index 8b2d5a3905ce47657334d47ff0699706be9520d1..6dab9324539dc646ad79f2b5e0cbccc335face74 100644 |
| --- a/components/omnibox/browser/autocomplete_match_unittest.cc |
| +++ b/components/omnibox/browser/autocomplete_match_unittest.cc |
| @@ -8,8 +8,11 @@ |
| #include "base/macros.h" |
| #include "base/strings/utf_string_conversions.h" |
| +#include "base/test/scoped_feature_list.h" |
| +#include "components/omnibox/browser/omnibox_field_trial.h" |
| #include "components/omnibox/browser/test_scheme_classifier.h" |
| #include "testing/gtest/include/gtest/gtest.h" |
| +#include "url/gurl.h" |
| TEST(AutocompleteMatchTest, MoreRelevant) { |
| struct RelevantCases { |
| @@ -108,6 +111,56 @@ TEST(AutocompleteMatchTest, MergeClassifications) { |
| "0,2," "1,0," "5,7," "6,1," "17,0")))); |
| } |
| +TEST(AutocompleteMatchTest, FormatUrlForSuggestionDisplay) { |
| + struct FormatUrlTestData { |
| + const std::string url; |
| + bool trim_scheme; |
| + size_t offset_for_adjustment; |
| + const std::string expected_result; |
| + size_t expected_adjusted_offset; |
| + |
| + void Validate() { |
| + SCOPED_TRACE(testing::Message() |
| + << "url= " << url << "trim_scheme=" << trim_scheme |
| + << "offset_for_adjustment=" << offset_for_adjustment |
| + << "expected_result=" << expected_result |
| + << "expected_adjusted_offset=" << expected_adjusted_offset); |
| + |
| + size_t offset_result = offset_for_adjustment; |
| + base::string16 result = AutocompleteMatch::FormatUrlForSuggestionDisplay( |
| + GURL(url), trim_scheme, &offset_result); |
| + |
| + EXPECT_EQ(expected_result, base::UTF16ToASCII(result)); |
| + EXPECT_EQ(expected_adjusted_offset, offset_result); |
| + }; |
| + }; |
| + |
| + FormatUrlTestData normal_cases[] = { |
| + {"http://google.com", true, 9, "google.com", 2}, |
| + {"https://google.com", true, 9, "https://google.com", 9}, |
| + {"http://google.com", false, 9, "http://google.com", 9}, |
| + {"https://google.com", false, 9, "https://google.com", 9}, |
| + }; |
| + for (size_t i = 0; i < arraysize(normal_cases); ++i) { |
| + normal_cases[i].Validate(); |
| + } |
| + |
| + std::unique_ptr<base::test::ScopedFeatureList> feature_list( |
| + new base::test::ScopedFeatureList); |
| + feature_list->InitAndEnableFeature( |
| + omnibox::kUIExperimentHideSuggestionUrlScheme); |
| + |
| + FormatUrlTestData omit_scheme_cases[] = { |
|
Justin Donnelly
2017/06/20 17:31:01
We could use one or more cases here that result in
tommycli
2017/06/20 22:51:21
Done.
|
| + {"http://google.com", true, 9, "google.com", 2}, |
| + {"https://google.com", true, 9, "google.com", 1}, |
| + {"http://google.com", false, 9, "http://google.com", 9}, |
| + {"https://google.com", false, 9, "https://google.com", 9}, |
| + }; |
| + for (size_t i = 0; i < arraysize(omit_scheme_cases); ++i) { |
| + omit_scheme_cases[i].Validate(); |
| + } |
| +} |
| + |
| TEST(AutocompleteMatchTest, SupportsDeletion) { |
| // A non-deletable match with no duplicates. |
| AutocompleteMatch m(NULL, 0, false, |