Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 "base/command_line.h" | 5 #include "base/command_line.h" |
| 6 #include "base/message_loop/message_loop.h" | 6 #include "base/message_loop/message_loop.h" |
| 7 #include "base/metrics/field_trial.h" | |
| 7 #include "base/strings/utf_string_conversions.h" | 8 #include "base/strings/utf_string_conversions.h" |
| 8 #include "components/metrics/proto/omnibox_event.pb.h" | 9 #include "components/metrics/proto/omnibox_event.pb.h" |
| 9 #include "components/omnibox/browser/autocomplete_match.h" | 10 #include "components/omnibox/browser/autocomplete_match.h" |
| 10 #include "components/omnibox/browser/autocomplete_scheme_classifier.h" | 11 #include "components/omnibox/browser/autocomplete_scheme_classifier.h" |
| 11 #include "components/omnibox/browser/keyword_provider.h" | 12 #include "components/omnibox/browser/keyword_provider.h" |
| 12 #include "components/omnibox/browser/mock_autocomplete_provider_client.h" | 13 #include "components/omnibox/browser/mock_autocomplete_provider_client.h" |
| 14 #include "components/omnibox/browser/omnibox_field_trial.h" | |
| 13 #include "components/search_engines/search_engines_switches.h" | 15 #include "components/search_engines/search_engines_switches.h" |
| 14 #include "components/search_engines/template_url.h" | 16 #include "components/search_engines/template_url.h" |
| 15 #include "components/search_engines/template_url_service.h" | 17 #include "components/search_engines/template_url_service.h" |
| 18 #include "components/variations/entropy_provider.h" | |
| 19 #include "components/variations/variations_associated_data.h" | |
| 16 #include "testing/gmock/include/gmock/gmock.h" | 20 #include "testing/gmock/include/gmock/gmock.h" |
| 17 #include "testing/gtest/include/gtest/gtest.h" | 21 #include "testing/gtest/include/gtest/gtest.h" |
| 18 #include "url/gurl.h" | 22 #include "url/gurl.h" |
| 19 | 23 |
| 20 using base::ASCIIToUTF16; | 24 using base::ASCIIToUTF16; |
| 21 | 25 |
| 22 namespace { | 26 namespace { |
| 23 | 27 |
| 24 class TestingSchemeClassifier : public AutocompleteSchemeClassifier { | 28 class TestingSchemeClassifier : public AutocompleteSchemeClassifier { |
| 25 public: | 29 public: |
| (...skipping 15 matching lines...) Expand all Loading... | |
| 41 bool allowed_to_be_default_match; | 45 bool allowed_to_be_default_match; |
| 42 }; | 46 }; |
| 43 | 47 |
| 44 template<class ResultType> | 48 template<class ResultType> |
| 45 struct TestData { | 49 struct TestData { |
| 46 const base::string16 input; | 50 const base::string16 input; |
| 47 const size_t num_results; | 51 const size_t num_results; |
| 48 const MatchType<ResultType> output[3]; | 52 const MatchType<ResultType> output[3]; |
| 49 }; | 53 }; |
| 50 | 54 |
| 51 KeywordProviderTest() : kw_provider_(NULL) { } | 55 KeywordProviderTest() : kw_provider_(NULL) { |
| 56 // Destroy the existing FieldTrialList before creating a new one to avoid | |
| 57 // a DCHECK. | |
| 58 field_trial_list_.reset(); | |
| 59 field_trial_list_.reset(new base::FieldTrialList( | |
| 60 new metrics::SHA1EntropyProvider("foo"))); | |
| 61 variations::testing::ClearAllVariationParams(); | |
| 62 } | |
| 52 ~KeywordProviderTest() override {} | 63 ~KeywordProviderTest() override {} |
| 53 | 64 |
| 54 void SetUp() override; | 65 // Should be called at least once during a test case. This is a separate |
| 66 // function from SetUp() because the client may want to set parameters | |
| 67 // (e.g., field trials) before initializing TemplateURLService and the | |
| 68 // related internal variables here. | |
| 69 void SetUpClientAndKeywordProvider(); | |
| 70 | |
| 55 void TearDown() override; | 71 void TearDown() override; |
| 56 | 72 |
| 57 template<class ResultType> | 73 template<class ResultType> |
| 58 void RunTest(TestData<ResultType>* keyword_cases, | 74 void RunTest(TestData<ResultType>* keyword_cases, |
| 59 int num_cases, | 75 int num_cases, |
| 60 ResultType AutocompleteMatch::* member); | 76 ResultType AutocompleteMatch::* member); |
| 61 | 77 |
| 62 protected: | 78 protected: |
| 63 static const TemplateURLService::Initializer kTestData[]; | 79 static const TemplateURLService::Initializer kTestData[]; |
| 64 | 80 |
| 81 scoped_ptr<base::FieldTrialList> field_trial_list_; | |
| 65 scoped_refptr<KeywordProvider> kw_provider_; | 82 scoped_refptr<KeywordProvider> kw_provider_; |
| 66 scoped_ptr<MockAutocompleteProviderClient> client_; | 83 scoped_ptr<MockAutocompleteProviderClient> client_; |
| 67 }; | 84 }; |
| 68 | 85 |
| 69 // static | 86 // static |
| 70 const TemplateURLService::Initializer KeywordProviderTest::kTestData[] = { | 87 const TemplateURLService::Initializer KeywordProviderTest::kTestData[] = { |
| 71 { "aa", "aa.com?foo={searchTerms}", "aa" }, | 88 { "aa", "aa.com?foo={searchTerms}", "aa" }, |
| 72 { "aaaa", "http://aaaa/?aaaa=1&b={searchTerms}&c", "aaaa" }, | 89 { "aaaa", "http://aaaa/?aaaa=1&b={searchTerms}&c", "aaaa" }, |
| 73 { "aaaaa", "{searchTerms}", "aaaaa" }, | 90 { "aaaaa", "{searchTerms}", "aaaaa" }, |
| 74 { "ab", "bogus URL {searchTerms}", "ab" }, | 91 { "ab", "bogus URL {searchTerms}", "ab" }, |
| 75 { "weasel", "weasel{searchTerms}weasel", "weasel" }, | 92 { "weasel", "weasel{searchTerms}weasel", "weasel" }, |
| 76 { "www", " +%2B?={searchTerms}foo ", "www" }, | 93 { "www", " +%2B?={searchTerms}foo ", "www" }, |
| 77 { "nonsub", "http://nonsubstituting-keyword.com/", "nonsub" }, | 94 { "nonsub", "http://nonsubstituting-keyword.com/", "nonsub" }, |
| 78 { "z", "{searchTerms}=z", "z" }, | 95 { "z", "{searchTerms}=z", "z" }, |
| 96 { "host.site.com", "http://host.site.com/?q={searchTerms}", "host.site.com" }, | |
| 97 { "ignoremelong.domain.com", | |
| 98 "http://ignoremelong.domain.com/?q={searchTerms}", | |
| 99 "ignoremelong.domain.com" }, | |
| 100 { "ignoreme.domain2.com", | |
| 101 "http://ignoreme.domain2.com/?q={searchTerms}", | |
| 102 "ignoreme.domain2.com" }, | |
| 103 { "fooshort.com", "http://fooshort.com/?q={searchTerms}", "fooshort.com" }, | |
| 104 { "foolong.co.uk", "http://foolong.co.uk/?q={searchTerms}", "foolong.co.uk" }, | |
| 79 }; | 105 }; |
| 80 | 106 |
| 81 void KeywordProviderTest::SetUp() { | 107 void KeywordProviderTest::SetUpClientAndKeywordProvider() { |
| 82 scoped_ptr<TemplateURLService> template_url_service( | 108 scoped_ptr<TemplateURLService> template_url_service( |
| 83 new TemplateURLService(kTestData, arraysize(kTestData))); | 109 new TemplateURLService(kTestData, arraysize(kTestData))); |
| 84 client_.reset(new MockAutocompleteProviderClient()); | 110 client_.reset(new MockAutocompleteProviderClient()); |
| 85 client_->set_template_url_service(template_url_service.Pass()); | 111 client_->set_template_url_service(template_url_service.Pass()); |
| 86 kw_provider_ = new KeywordProvider(client_.get(), nullptr); | 112 kw_provider_ = new KeywordProvider(client_.get(), nullptr); |
| 87 } | 113 } |
| 88 | 114 |
| 89 void KeywordProviderTest::TearDown() { | 115 void KeywordProviderTest::TearDown() { |
| 90 client_.reset(); | 116 client_.reset(); |
| 91 kw_provider_ = NULL; | 117 kw_provider_ = NULL; |
| (...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 144 { ASCIIToUTF16("aaaaa "), false }, | 170 { ASCIIToUTF16("aaaaa "), false }, |
| 145 kEmptyMatch } }, | 171 kEmptyMatch } }, |
| 146 { ASCIIToUTF16("a 1 2 3"), 3, | 172 { ASCIIToUTF16("a 1 2 3"), 3, |
| 147 { { ASCIIToUTF16("aa 1 2 3"), false }, | 173 { { ASCIIToUTF16("aa 1 2 3"), false }, |
| 148 { ASCIIToUTF16("ab 1 2 3"), false }, | 174 { ASCIIToUTF16("ab 1 2 3"), false }, |
| 149 { ASCIIToUTF16("aaaa 1 2 3"), false } } }, | 175 { ASCIIToUTF16("aaaa 1 2 3"), false } } }, |
| 150 { ASCIIToUTF16("www.a"), 3, | 176 { ASCIIToUTF16("www.a"), 3, |
| 151 { { ASCIIToUTF16("aa "), false }, | 177 { { ASCIIToUTF16("aa "), false }, |
| 152 { ASCIIToUTF16("ab "), false }, | 178 { ASCIIToUTF16("ab "), false }, |
| 153 { ASCIIToUTF16("aaaa "), false } } }, | 179 { ASCIIToUTF16("aaaa "), false } } }, |
| 180 { ASCIIToUTF16("foo hello"), 2, | |
| 181 { { ASCIIToUTF16("fooshort.com hello"), false }, | |
| 182 { ASCIIToUTF16("foolong.co.uk hello"), false }, | |
| 183 kEmptyMatch } }, | |
| 154 // Exact matches should prevent returning inexact matches. Also, the | 184 // Exact matches should prevent returning inexact matches. Also, the |
| 155 // verbatim query for this keyword match should not be returned. (It's | 185 // verbatim query for this keyword match should not be returned. (It's |
| 156 // returned by SearchProvider.) | 186 // returned by SearchProvider.) |
| 157 { ASCIIToUTF16("aaaa foo"), 0, | 187 { ASCIIToUTF16("aaaa foo"), 0, |
| 158 { kEmptyMatch, kEmptyMatch, kEmptyMatch } }, | 188 { kEmptyMatch, kEmptyMatch, kEmptyMatch } }, |
| 159 { ASCIIToUTF16("www.aaaa foo"), 0, | 189 { ASCIIToUTF16("www.aaaa foo"), 0, |
| 160 { kEmptyMatch, kEmptyMatch, kEmptyMatch } }, | 190 { kEmptyMatch, kEmptyMatch, kEmptyMatch } }, |
| 161 | 191 |
| 192 // Matches should be retrieved by typing the prefix of the keyword, | |
|
Peter Kasting
2015/11/12 22:32:11
Nit: Wrap comment all the way out to 80 columns
Mark P
2015/11/12 23:18:41
Done.
| |
| 193 // not the domain name. | |
| 194 { ASCIIToUTF16("host foo"), 1, | |
| 195 { { ASCIIToUTF16("host.site.com foo"), false }, | |
| 196 kEmptyMatch, kEmptyMatch } }, | |
| 197 { ASCIIToUTF16("host.site foo"), 1, | |
| 198 { { ASCIIToUTF16("host.site.com foo"), false }, | |
| 199 kEmptyMatch, kEmptyMatch } }, | |
| 200 { ASCIIToUTF16("site foo"), 0, | |
| 201 { kEmptyMatch, kEmptyMatch, kEmptyMatch } }, | |
| 202 | |
| 162 // Clean up keyword input properly. "http" and "https" are the only | 203 // Clean up keyword input properly. "http" and "https" are the only |
| 163 // allowed schemes. | 204 // allowed schemes. |
| 164 { ASCIIToUTF16("www"), 1, | 205 { ASCIIToUTF16("www"), 1, |
| 165 { { ASCIIToUTF16("www "), true }, kEmptyMatch, kEmptyMatch }}, | 206 { { ASCIIToUTF16("www "), true }, kEmptyMatch, kEmptyMatch }}, |
| 166 { ASCIIToUTF16("www."), 0, | 207 { ASCIIToUTF16("www."), 0, |
| 167 { kEmptyMatch, kEmptyMatch, kEmptyMatch } }, | 208 { kEmptyMatch, kEmptyMatch, kEmptyMatch } }, |
| 168 { ASCIIToUTF16("www.w w"), 2, | 209 { ASCIIToUTF16("www.w w"), 2, |
| 169 { { ASCIIToUTF16("www w"), false }, | 210 { { ASCIIToUTF16("www w"), false }, |
| 170 { ASCIIToUTF16("weasel w"), false }, | 211 { ASCIIToUTF16("weasel w"), false }, |
| 171 kEmptyMatch } }, | 212 kEmptyMatch } }, |
| (...skipping 11 matching lines...) Expand all Loading... | |
| 183 { { ASCIIToUTF16("z "), true }, kEmptyMatch, kEmptyMatch } }, | 224 { { ASCIIToUTF16("z "), true }, kEmptyMatch, kEmptyMatch } }, |
| 184 | 225 |
| 185 // Non-substituting keywords, whether typed fully or not | 226 // Non-substituting keywords, whether typed fully or not |
| 186 // should not add a space. | 227 // should not add a space. |
| 187 { ASCIIToUTF16("nonsu"), 1, | 228 { ASCIIToUTF16("nonsu"), 1, |
| 188 { { ASCIIToUTF16("nonsub"), false }, kEmptyMatch, kEmptyMatch } }, | 229 { { ASCIIToUTF16("nonsub"), false }, kEmptyMatch, kEmptyMatch } }, |
| 189 { ASCIIToUTF16("nonsub"), 1, | 230 { ASCIIToUTF16("nonsub"), 1, |
| 190 { { ASCIIToUTF16("nonsub"), true }, kEmptyMatch, kEmptyMatch } }, | 231 { { ASCIIToUTF16("nonsub"), true }, kEmptyMatch, kEmptyMatch } }, |
| 191 }; | 232 }; |
| 192 | 233 |
| 234 SetUpClientAndKeywordProvider(); | |
| 193 RunTest<base::string16>(edit_cases, arraysize(edit_cases), | 235 RunTest<base::string16>(edit_cases, arraysize(edit_cases), |
| 194 &AutocompleteMatch::fill_into_edit); | 236 &AutocompleteMatch::fill_into_edit); |
|
Peter Kasting
2015/11/12 22:32:11
Nit: Indenting
Mark P
2015/11/12 23:18:41
Done here and all RunTest calls.
| |
| 195 } | 237 } |
| 238 | |
| 239 TEST_F(KeywordProviderTest, DomainMatches) { | |
| 240 const MatchType<base::string16> kEmptyMatch = { base::string16(), false }; | |
| 241 TestData<base::string16> edit_cases[] = { | |
| 242 // Searching for a nonexistent prefix should give nothing. | |
| 243 { ASCIIToUTF16("Not Found"), 0, | |
| 244 { kEmptyMatch, kEmptyMatch, kEmptyMatch } }, | |
| 245 { ASCIIToUTF16("aaaaaNot Found"), 0, | |
| 246 { kEmptyMatch, kEmptyMatch, kEmptyMatch } }, | |
| 247 | |
| 248 // Matches should be limited to three and sorted in quality order. | |
| 249 // This order depends on whether we're using the pre-domain-name text | |
| 250 // for matching--when matching the domain, we sort by the length of the | |
| 251 // domain, not the length of the whole keyword. | |
| 252 { ASCIIToUTF16("ignore foo"), 2, | |
| 253 { { ASCIIToUTF16("ignoreme.domain2.com foo"), false }, | |
| 254 { ASCIIToUTF16("ignoremelong.domain.com foo"), false }, | |
| 255 kEmptyMatch } }, | |
| 256 { ASCIIToUTF16("dom foo"), 2, | |
| 257 { { ASCIIToUTF16("ignoremelong.domain.com foo"), false }, | |
| 258 { ASCIIToUTF16("ignoreme.domain2.com foo"), false }, | |
| 259 kEmptyMatch } }, | |
| 260 | |
| 261 // Matches should be retrieved by typing the domain name, not only | |
| 262 // a prefix to the keyword. | |
| 263 { ASCIIToUTF16("host foo"), 1, | |
| 264 { { ASCIIToUTF16("host.site.com foo"), false }, | |
| 265 kEmptyMatch, kEmptyMatch } }, | |
| 266 { ASCIIToUTF16("host.site foo"), 1, | |
| 267 { { ASCIIToUTF16("host.site.com foo"), false }, | |
| 268 kEmptyMatch, kEmptyMatch } }, | |
| 269 { ASCIIToUTF16("site foo"), 1, | |
| 270 { { ASCIIToUTF16("host.site.com foo"), false }, | |
| 271 kEmptyMatch, kEmptyMatch } }, | |
| 272 }; | |
| 273 | |
| 274 // Add a rule enabling matching in the domain name of keywords (i.e., | |
| 275 // non-prefix matching). | |
| 276 { | |
| 277 std::map<std::string, std::string> params; | |
| 278 params[std::string(OmniboxFieldTrial::kKeywordRequiresPrefixMatchRule)] = | |
|
Peter Kasting
2015/11/12 22:32:11
Nit: Is the explicit std::string() here necessary?
Mark P
2015/11/12 23:18:41
No, it's not necessary. Removed. This was a left
| |
| 279 "false"; | |
| 280 ASSERT_TRUE(variations::AssociateVariationParams( | |
| 281 OmniboxFieldTrial::kBundledExperimentFieldTrialName, "A", params)); | |
| 282 } | |
| 283 base::FieldTrialList::CreateFieldTrial( | |
| 284 OmniboxFieldTrial::kBundledExperimentFieldTrialName, "A"); | |
| 285 | |
| 286 SetUpClientAndKeywordProvider(); | |
| 287 RunTest<base::string16>(edit_cases, arraysize(edit_cases), | |
| 288 &AutocompleteMatch::fill_into_edit); | |
|
Peter Kasting
2015/11/12 22:32:11
Nit: Indenting
Mark P
2015/11/12 23:18:41
Done.
| |
| 289 } | |
| 290 | |
| 291 TEST_F(KeywordProviderTest, IgnoreRegistryForScoring) { | |
| 292 const MatchType<base::string16> kEmptyMatch = { base::string16(), false }; | |
| 293 TestData<base::string16> edit_cases[] = { | |
| 294 // Matches should be limited to three and sorted in quality order. | |
| 295 // When ignoring the registry length, this order of suggestions should | |
| 296 // result (sorted by keyword length sans registry). The "Edit" test case | |
| 297 // has this exact test for when not ignoring the registry to check that | |
| 298 // the other order (shorter full keyword) results there. | |
| 299 { ASCIIToUTF16("foo hello"), 2, | |
| 300 { { ASCIIToUTF16("foolong.co.uk hello"), false }, | |
| 301 { ASCIIToUTF16("fooshort.com hello"), false }, | |
| 302 kEmptyMatch } }, | |
| 303 | |
| 304 // Keywords that don't have full hostnames should keep the same order | |
| 305 // as normal. | |
| 306 { ASCIIToUTF16("aaa"), 2, | |
| 307 { { ASCIIToUTF16("aaaa "), false }, | |
| 308 { ASCIIToUTF16("aaaaa "), false }, | |
| 309 kEmptyMatch } }, | |
| 310 { ASCIIToUTF16("a 1 2 3"), 3, | |
| 311 { { ASCIIToUTF16("aa 1 2 3"), false }, | |
| 312 { ASCIIToUTF16("ab 1 2 3"), false }, | |
| 313 { ASCIIToUTF16("aaaa 1 2 3"), false } } }, | |
| 314 { ASCIIToUTF16("www.a"), 3, | |
| 315 { { ASCIIToUTF16("aa "), false }, | |
| 316 { ASCIIToUTF16("ab "), false }, | |
| 317 { ASCIIToUTF16("aaaa "), false } } }, | |
| 318 }; | |
| 319 | |
| 320 // Add a rule to make matching in the registry portion of a keyword | |
| 321 // unimportant. | |
| 322 { | |
| 323 std::map<std::string, std::string> params; | |
| 324 params[std::string(OmniboxFieldTrial::kKeywordRequiresRegistryRule)] = | |
| 325 "false"; | |
| 326 ASSERT_TRUE(variations::AssociateVariationParams( | |
| 327 OmniboxFieldTrial::kBundledExperimentFieldTrialName, "A", params)); | |
| 328 } | |
| 329 base::FieldTrialList::CreateFieldTrial( | |
| 330 OmniboxFieldTrial::kBundledExperimentFieldTrialName, "A"); | |
| 331 | |
| 332 SetUpClientAndKeywordProvider(); | |
| 333 RunTest<base::string16>(edit_cases, arraysize(edit_cases), | |
| 334 &AutocompleteMatch::fill_into_edit); | |
|
Peter Kasting
2015/11/12 22:32:11
Nit: While here: indenting
Mark P
2015/11/12 23:18:41
Done.
| |
| 335 } | |
| 196 | 336 |
| 197 TEST_F(KeywordProviderTest, URL) { | 337 TEST_F(KeywordProviderTest, URL) { |
| 198 const MatchType<GURL> kEmptyMatch = { GURL(), false }; | 338 const MatchType<GURL> kEmptyMatch = { GURL(), false }; |
| 199 TestData<GURL> url_cases[] = { | 339 TestData<GURL> url_cases[] = { |
| 200 // No query input -> empty destination URL. | 340 // No query input -> empty destination URL. |
| 201 { ASCIIToUTF16("z"), 1, | 341 { ASCIIToUTF16("z"), 1, |
| 202 { { GURL(), true }, kEmptyMatch, kEmptyMatch } }, | 342 { { GURL(), true }, kEmptyMatch, kEmptyMatch } }, |
| 203 { ASCIIToUTF16("z \t"), 1, | 343 { ASCIIToUTF16("z \t"), 1, |
| 204 { { GURL(), true }, kEmptyMatch, kEmptyMatch } }, | 344 { { GURL(), true }, kEmptyMatch, kEmptyMatch } }, |
| 205 | 345 |
| (...skipping 12 matching lines...) Expand all Loading... | |
| 218 { ASCIIToUTF16("a 1 2 3"), 3, | 358 { ASCIIToUTF16("a 1 2 3"), 3, |
| 219 { { GURL("aa.com?foo=1+2+3"), false }, | 359 { { GURL("aa.com?foo=1+2+3"), false }, |
| 220 { GURL("bogus URL 1+2+3"), false }, | 360 { GURL("bogus URL 1+2+3"), false }, |
| 221 { GURL("http://aaaa/?aaaa=1&b=1+2+3&c"), false } } }, | 361 { GURL("http://aaaa/?aaaa=1&b=1+2+3&c"), false } } }, |
| 222 { ASCIIToUTF16("www.w w"), 2, | 362 { ASCIIToUTF16("www.w w"), 2, |
| 223 { { GURL(" +%2B?=wfoo "), false }, | 363 { { GURL(" +%2B?=wfoo "), false }, |
| 224 { GURL("weaselwweasel"), false }, | 364 { GURL("weaselwweasel"), false }, |
| 225 kEmptyMatch } }, | 365 kEmptyMatch } }, |
| 226 }; | 366 }; |
| 227 | 367 |
| 368 SetUpClientAndKeywordProvider(); | |
| 228 RunTest<GURL>(url_cases, arraysize(url_cases), | 369 RunTest<GURL>(url_cases, arraysize(url_cases), |
| 229 &AutocompleteMatch::destination_url); | 370 &AutocompleteMatch::destination_url); |
| 230 } | 371 } |
| 231 | 372 |
| 232 TEST_F(KeywordProviderTest, Contents) { | 373 TEST_F(KeywordProviderTest, Contents) { |
| 233 const MatchType<base::string16> kEmptyMatch = { base::string16(), false }; | 374 const MatchType<base::string16> kEmptyMatch = { base::string16(), false }; |
| 234 TestData<base::string16> contents_cases[] = { | 375 TestData<base::string16> contents_cases[] = { |
| 235 // No query input -> substitute "<enter query>" into contents. | 376 // No query input -> substitute "<enter query>" into contents. |
| 236 { ASCIIToUTF16("z"), 1, | 377 { ASCIIToUTF16("z"), 1, |
| 237 { { ASCIIToUTF16("Search z for <enter query>"), true }, | 378 { { ASCIIToUTF16("Search z for <enter query>"), true }, |
| (...skipping 23 matching lines...) Expand all Loading... | |
| 261 { ASCIIToUTF16("Search weasel for w"), false }, | 402 { ASCIIToUTF16("Search weasel for w"), false }, |
| 262 kEmptyMatch } }, | 403 kEmptyMatch } }, |
| 263 // Also, check that tokenization only collapses whitespace between first | 404 // Also, check that tokenization only collapses whitespace between first |
| 264 // tokens and contents are not escaped or unescaped. | 405 // tokens and contents are not escaped or unescaped. |
| 265 { ASCIIToUTF16("a 1 2+ 3"), 3, | 406 { ASCIIToUTF16("a 1 2+ 3"), 3, |
| 266 { { ASCIIToUTF16("Search aa for 1 2+ 3"), false }, | 407 { { ASCIIToUTF16("Search aa for 1 2+ 3"), false }, |
| 267 { ASCIIToUTF16("Search ab for 1 2+ 3"), false }, | 408 { ASCIIToUTF16("Search ab for 1 2+ 3"), false }, |
| 268 { ASCIIToUTF16("Search aaaa for 1 2+ 3"), false } } }, | 409 { ASCIIToUTF16("Search aaaa for 1 2+ 3"), false } } }, |
| 269 }; | 410 }; |
| 270 | 411 |
| 412 SetUpClientAndKeywordProvider(); | |
| 271 RunTest<base::string16>(contents_cases, arraysize(contents_cases), | 413 RunTest<base::string16>(contents_cases, arraysize(contents_cases), |
| 272 &AutocompleteMatch::contents); | 414 &AutocompleteMatch::contents); |
|
Peter Kasting
2015/11/12 22:32:11
Nit: While here: indenting
Mark P
2015/11/12 23:18:41
Done.
| |
| 273 } | 415 } |
| 274 | 416 |
| 275 TEST_F(KeywordProviderTest, AddKeyword) { | 417 TEST_F(KeywordProviderTest, AddKeyword) { |
| 418 SetUpClientAndKeywordProvider(); | |
| 276 TemplateURLData data; | 419 TemplateURLData data; |
| 277 data.SetShortName(ASCIIToUTF16("Test")); | 420 data.SetShortName(ASCIIToUTF16("Test")); |
| 278 base::string16 keyword(ASCIIToUTF16("foo")); | 421 base::string16 keyword(ASCIIToUTF16("foo")); |
| 279 data.SetKeyword(keyword); | 422 data.SetKeyword(keyword); |
| 280 data.SetURL("http://www.google.com/foo?q={searchTerms}"); | 423 data.SetURL("http://www.google.com/foo?q={searchTerms}"); |
| 281 TemplateURL* template_url = new TemplateURL(data); | 424 TemplateURL* template_url = new TemplateURL(data); |
| 282 client_->GetTemplateURLService()->Add(template_url); | 425 client_->GetTemplateURLService()->Add(template_url); |
| 283 ASSERT_TRUE( | 426 ASSERT_TRUE( |
| 284 template_url == | 427 template_url == |
| 285 client_->GetTemplateURLService()->GetTemplateURLForKeyword(keyword)); | 428 client_->GetTemplateURLService()->GetTemplateURLForKeyword(keyword)); |
| 286 } | 429 } |
| 287 | 430 |
| 288 TEST_F(KeywordProviderTest, RemoveKeyword) { | 431 TEST_F(KeywordProviderTest, RemoveKeyword) { |
| 432 SetUpClientAndKeywordProvider(); | |
| 289 TemplateURLService* template_url_service = client_->GetTemplateURLService(); | 433 TemplateURLService* template_url_service = client_->GetTemplateURLService(); |
| 290 base::string16 url(ASCIIToUTF16("http://aaaa/?aaaa=1&b={searchTerms}&c")); | 434 base::string16 url(ASCIIToUTF16("http://aaaa/?aaaa=1&b={searchTerms}&c")); |
| 291 template_url_service->Remove( | 435 template_url_service->Remove( |
| 292 template_url_service->GetTemplateURLForKeyword(ASCIIToUTF16("aaaa"))); | 436 template_url_service->GetTemplateURLForKeyword(ASCIIToUTF16("aaaa"))); |
| 293 ASSERT_TRUE(template_url_service->GetTemplateURLForKeyword( | 437 ASSERT_TRUE(template_url_service->GetTemplateURLForKeyword( |
| 294 ASCIIToUTF16("aaaa")) == NULL); | 438 ASCIIToUTF16("aaaa")) == NULL); |
| 295 } | 439 } |
| 296 | 440 |
| 297 TEST_F(KeywordProviderTest, GetKeywordForInput) { | 441 TEST_F(KeywordProviderTest, GetKeywordForInput) { |
| 442 SetUpClientAndKeywordProvider(); | |
| 298 EXPECT_EQ(ASCIIToUTF16("aa"), | 443 EXPECT_EQ(ASCIIToUTF16("aa"), |
| 299 kw_provider_->GetKeywordForText(ASCIIToUTF16("aa"))); | 444 kw_provider_->GetKeywordForText(ASCIIToUTF16("aa"))); |
| 300 EXPECT_EQ(base::string16(), | 445 EXPECT_EQ(base::string16(), |
| 301 kw_provider_->GetKeywordForText(ASCIIToUTF16("aafoo"))); | 446 kw_provider_->GetKeywordForText(ASCIIToUTF16("aafoo"))); |
| 302 EXPECT_EQ(base::string16(), | 447 EXPECT_EQ(base::string16(), |
| 303 kw_provider_->GetKeywordForText(ASCIIToUTF16("aa foo"))); | 448 kw_provider_->GetKeywordForText(ASCIIToUTF16("aa foo"))); |
| 304 } | 449 } |
| 305 | 450 |
| 306 TEST_F(KeywordProviderTest, GetSubstitutingTemplateURLForInput) { | 451 TEST_F(KeywordProviderTest, GetSubstitutingTemplateURLForInput) { |
| 307 struct { | 452 struct { |
| (...skipping 29 matching lines...) Expand all Loading... | |
| 337 { "aa foo ", 3u, true, "aa.com?foo={searchTerms}", "foo ", 0 }, | 482 { "aa foo ", 3u, true, "aa.com?foo={searchTerms}", "foo ", 0 }, |
| 338 // Extra space after keyword, no trailing space, cursor at the end. | 483 // Extra space after keyword, no trailing space, cursor at the end. |
| 339 { "aa foo", 7u, true, "aa.com?foo={searchTerms}", "foo", 3u }, | 484 { "aa foo", 7u, true, "aa.com?foo={searchTerms}", "foo", 3u }, |
| 340 // Extra space after keyword, no trailing space, cursor in the middle. | 485 // Extra space after keyword, no trailing space, cursor in the middle. |
| 341 { "aa foo", 5u, true, "aa.com?foo={searchTerms}", "foo", 1u }, | 486 { "aa foo", 5u, true, "aa.com?foo={searchTerms}", "foo", 1u }, |
| 342 | 487 |
| 343 // Disallow exact keyword match. | 488 // Disallow exact keyword match. |
| 344 { "aa foo", base::string16::npos, false, "", "aa foo", | 489 { "aa foo", base::string16::npos, false, "", "aa foo", |
| 345 base::string16::npos }, | 490 base::string16::npos }, |
| 346 }; | 491 }; |
| 492 SetUpClientAndKeywordProvider(); | |
| 347 for (size_t i = 0; i < arraysize(cases); i++) { | 493 for (size_t i = 0; i < arraysize(cases); i++) { |
| 348 AutocompleteInput input(ASCIIToUTF16(cases[i].text), | 494 AutocompleteInput input(ASCIIToUTF16(cases[i].text), |
| 349 cases[i].cursor_position, std::string(), GURL(), | 495 cases[i].cursor_position, std::string(), GURL(), |
| 350 metrics::OmniboxEventProto::INVALID_SPEC, false, | 496 metrics::OmniboxEventProto::INVALID_SPEC, false, |
| 351 false, cases[i].allow_exact_keyword_match, true, | 497 false, cases[i].allow_exact_keyword_match, true, |
| 352 false, TestingSchemeClassifier()); | 498 false, TestingSchemeClassifier()); |
| 353 const TemplateURL* url = | 499 const TemplateURL* url = |
| 354 KeywordProvider::GetSubstitutingTemplateURLForInput( | 500 KeywordProvider::GetSubstitutingTemplateURLForInput( |
| 355 client_->GetTemplateURLService(), &input); | 501 client_->GetTemplateURLService(), &input); |
| 356 if (cases[i].expected_url.empty()) | 502 if (cases[i].expected_url.empty()) |
| (...skipping 11 matching lines...) Expand all Loading... | |
| 368 base::CommandLine::ForCurrentProcess()->AppendSwitchASCII( | 514 base::CommandLine::ForCurrentProcess()->AppendSwitchASCII( |
| 369 switches::kExtraSearchQueryParams, "a=b"); | 515 switches::kExtraSearchQueryParams, "a=b"); |
| 370 | 516 |
| 371 TestData<GURL> url_cases[] = { | 517 TestData<GURL> url_cases[] = { |
| 372 { ASCIIToUTF16("a 1 2 3"), 3, | 518 { ASCIIToUTF16("a 1 2 3"), 3, |
| 373 { { GURL("aa.com?a=b&foo=1+2+3"), false }, | 519 { { GURL("aa.com?a=b&foo=1+2+3"), false }, |
| 374 { GURL("bogus URL 1+2+3"), false }, | 520 { GURL("bogus URL 1+2+3"), false }, |
| 375 { GURL("http://aaaa/?aaaa=1&b=1+2+3&c"), false } } }, | 521 { GURL("http://aaaa/?aaaa=1&b=1+2+3&c"), false } } }, |
| 376 }; | 522 }; |
| 377 | 523 |
| 524 SetUpClientAndKeywordProvider(); | |
| 378 RunTest<GURL>(url_cases, arraysize(url_cases), | 525 RunTest<GURL>(url_cases, arraysize(url_cases), |
| 379 &AutocompleteMatch::destination_url); | 526 &AutocompleteMatch::destination_url); |
| 380 } | 527 } |
| 381 | 528 |
| 382 TEST_F(KeywordProviderTest, DoesNotProvideMatchesOnFocus) { | 529 TEST_F(KeywordProviderTest, DoesNotProvideMatchesOnFocus) { |
| 530 SetUpClientAndKeywordProvider(); | |
| 383 AutocompleteInput input(ASCIIToUTF16("aaa"), base::string16::npos, | 531 AutocompleteInput input(ASCIIToUTF16("aaa"), base::string16::npos, |
| 384 std::string(), GURL(), | 532 std::string(), GURL(), |
| 385 metrics::OmniboxEventProto::INVALID_SPEC, true, false, | 533 metrics::OmniboxEventProto::INVALID_SPEC, true, false, |
| 386 true, true, true, TestingSchemeClassifier()); | 534 true, true, true, TestingSchemeClassifier()); |
| 387 kw_provider_->Start(input, false); | 535 kw_provider_->Start(input, false); |
| 388 ASSERT_TRUE(kw_provider_->matches().empty()); | 536 ASSERT_TRUE(kw_provider_->matches().empty()); |
| 389 } | 537 } |
| OLD | NEW |