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

Side by Side Diff: components/omnibox/browser/keyword_provider_unittest.cc

Issue 1411543011: Omnibox: Make Keyword Provide More Generous with Matching (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: finish converting AddToMap() calls Created 5 years, 1 month 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 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
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
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, not the
193 // 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
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);
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[OmniboxFieldTrial::kKeywordRequiresPrefixMatchRule] = "false";
279 ASSERT_TRUE(variations::AssociateVariationParams(
280 OmniboxFieldTrial::kBundledExperimentFieldTrialName, "A", params));
281 }
282 base::FieldTrialList::CreateFieldTrial(
283 OmniboxFieldTrial::kBundledExperimentFieldTrialName, "A");
284
285 SetUpClientAndKeywordProvider();
286 RunTest<base::string16>(edit_cases, arraysize(edit_cases),
287 &AutocompleteMatch::fill_into_edit);
288 }
289
290 TEST_F(KeywordProviderTest, IgnoreRegistryForScoring) {
291 const MatchType<base::string16> kEmptyMatch = { base::string16(), false };
292 TestData<base::string16> edit_cases[] = {
293 // Matches should be limited to three and sorted in quality order.
294 // When ignoring the registry length, this order of suggestions should
295 // result (sorted by keyword length sans registry). The "Edit" test case
296 // has this exact test for when not ignoring the registry to check that
297 // the other order (shorter full keyword) results there.
298 { ASCIIToUTF16("foo hello"), 2,
299 { { ASCIIToUTF16("foolong.co.uk hello"), false },
300 { ASCIIToUTF16("fooshort.com hello"), false },
301 kEmptyMatch } },
302
303 // Keywords that don't have full hostnames should keep the same order
304 // as normal.
305 { ASCIIToUTF16("aaa"), 2,
306 { { ASCIIToUTF16("aaaa "), false },
307 { ASCIIToUTF16("aaaaa "), false },
308 kEmptyMatch } },
309 { ASCIIToUTF16("a 1 2 3"), 3,
310 { { ASCIIToUTF16("aa 1 2 3"), false },
311 { ASCIIToUTF16("ab 1 2 3"), false },
312 { ASCIIToUTF16("aaaa 1 2 3"), false } } },
313 { ASCIIToUTF16("www.a"), 3,
314 { { ASCIIToUTF16("aa "), false },
315 { ASCIIToUTF16("ab "), false },
316 { ASCIIToUTF16("aaaa "), false } } },
317 };
318
319 // Add a rule to make matching in the registry portion of a keyword
320 // unimportant.
321 {
322 std::map<std::string, std::string> params;
323 params[OmniboxFieldTrial::kKeywordRequiresRegistryRule] = "false";
324 ASSERT_TRUE(variations::AssociateVariationParams(
325 OmniboxFieldTrial::kBundledExperimentFieldTrialName, "A", params));
326 }
327 base::FieldTrialList::CreateFieldTrial(
328 OmniboxFieldTrial::kBundledExperimentFieldTrialName, "A");
329
330 SetUpClientAndKeywordProvider();
331 RunTest<base::string16>(edit_cases, arraysize(edit_cases),
332 &AutocompleteMatch::fill_into_edit);
195 } 333 }
196 334
197 TEST_F(KeywordProviderTest, URL) { 335 TEST_F(KeywordProviderTest, URL) {
198 const MatchType<GURL> kEmptyMatch = { GURL(), false }; 336 const MatchType<GURL> kEmptyMatch = { GURL(), false };
199 TestData<GURL> url_cases[] = { 337 TestData<GURL> url_cases[] = {
200 // No query input -> empty destination URL. 338 // No query input -> empty destination URL.
201 { ASCIIToUTF16("z"), 1, 339 { ASCIIToUTF16("z"), 1,
202 { { GURL(), true }, kEmptyMatch, kEmptyMatch } }, 340 { { GURL(), true }, kEmptyMatch, kEmptyMatch } },
203 { ASCIIToUTF16("z \t"), 1, 341 { ASCIIToUTF16("z \t"), 1,
204 { { GURL(), true }, kEmptyMatch, kEmptyMatch } }, 342 { { GURL(), true }, kEmptyMatch, kEmptyMatch } },
(...skipping 13 matching lines...) Expand all
218 { ASCIIToUTF16("a 1 2 3"), 3, 356 { ASCIIToUTF16("a 1 2 3"), 3,
219 { { GURL("aa.com?foo=1+2+3"), false }, 357 { { GURL("aa.com?foo=1+2+3"), false },
220 { GURL("bogus URL 1+2+3"), false }, 358 { GURL("bogus URL 1+2+3"), false },
221 { GURL("http://aaaa/?aaaa=1&b=1+2+3&c"), false } } }, 359 { GURL("http://aaaa/?aaaa=1&b=1+2+3&c"), false } } },
222 { ASCIIToUTF16("www.w w"), 2, 360 { ASCIIToUTF16("www.w w"), 2,
223 { { GURL(" +%2B?=wfoo "), false }, 361 { { GURL(" +%2B?=wfoo "), false },
224 { GURL("weaselwweasel"), false }, 362 { GURL("weaselwweasel"), false },
225 kEmptyMatch } }, 363 kEmptyMatch } },
226 }; 364 };
227 365
366 SetUpClientAndKeywordProvider();
228 RunTest<GURL>(url_cases, arraysize(url_cases), 367 RunTest<GURL>(url_cases, arraysize(url_cases),
229 &AutocompleteMatch::destination_url); 368 &AutocompleteMatch::destination_url);
230 } 369 }
231 370
232 TEST_F(KeywordProviderTest, Contents) { 371 TEST_F(KeywordProviderTest, Contents) {
233 const MatchType<base::string16> kEmptyMatch = { base::string16(), false }; 372 const MatchType<base::string16> kEmptyMatch = { base::string16(), false };
234 TestData<base::string16> contents_cases[] = { 373 TestData<base::string16> contents_cases[] = {
235 // No query input -> substitute "<enter query>" into contents. 374 // No query input -> substitute "<enter query>" into contents.
236 { ASCIIToUTF16("z"), 1, 375 { ASCIIToUTF16("z"), 1,
237 { { ASCIIToUTF16("Search z for <enter query>"), true }, 376 { { ASCIIToUTF16("Search z for <enter query>"), true },
(...skipping 23 matching lines...) Expand all
261 { ASCIIToUTF16("Search weasel for w"), false }, 400 { ASCIIToUTF16("Search weasel for w"), false },
262 kEmptyMatch } }, 401 kEmptyMatch } },
263 // Also, check that tokenization only collapses whitespace between first 402 // Also, check that tokenization only collapses whitespace between first
264 // tokens and contents are not escaped or unescaped. 403 // tokens and contents are not escaped or unescaped.
265 { ASCIIToUTF16("a 1 2+ 3"), 3, 404 { ASCIIToUTF16("a 1 2+ 3"), 3,
266 { { ASCIIToUTF16("Search aa for 1 2+ 3"), false }, 405 { { ASCIIToUTF16("Search aa for 1 2+ 3"), false },
267 { ASCIIToUTF16("Search ab for 1 2+ 3"), false }, 406 { ASCIIToUTF16("Search ab for 1 2+ 3"), false },
268 { ASCIIToUTF16("Search aaaa for 1 2+ 3"), false } } }, 407 { ASCIIToUTF16("Search aaaa for 1 2+ 3"), false } } },
269 }; 408 };
270 409
410 SetUpClientAndKeywordProvider();
271 RunTest<base::string16>(contents_cases, arraysize(contents_cases), 411 RunTest<base::string16>(contents_cases, arraysize(contents_cases),
272 &AutocompleteMatch::contents); 412 &AutocompleteMatch::contents);
273 } 413 }
274 414
275 TEST_F(KeywordProviderTest, AddKeyword) { 415 TEST_F(KeywordProviderTest, AddKeyword) {
416 SetUpClientAndKeywordProvider();
276 TemplateURLData data; 417 TemplateURLData data;
277 data.SetShortName(ASCIIToUTF16("Test")); 418 data.SetShortName(ASCIIToUTF16("Test"));
278 base::string16 keyword(ASCIIToUTF16("foo")); 419 base::string16 keyword(ASCIIToUTF16("foo"));
279 data.SetKeyword(keyword); 420 data.SetKeyword(keyword);
280 data.SetURL("http://www.google.com/foo?q={searchTerms}"); 421 data.SetURL("http://www.google.com/foo?q={searchTerms}");
281 TemplateURL* template_url = new TemplateURL(data); 422 TemplateURL* template_url = new TemplateURL(data);
282 client_->GetTemplateURLService()->Add(template_url); 423 client_->GetTemplateURLService()->Add(template_url);
283 ASSERT_TRUE( 424 ASSERT_TRUE(
284 template_url == 425 template_url ==
285 client_->GetTemplateURLService()->GetTemplateURLForKeyword(keyword)); 426 client_->GetTemplateURLService()->GetTemplateURLForKeyword(keyword));
286 } 427 }
287 428
288 TEST_F(KeywordProviderTest, RemoveKeyword) { 429 TEST_F(KeywordProviderTest, RemoveKeyword) {
430 SetUpClientAndKeywordProvider();
289 TemplateURLService* template_url_service = client_->GetTemplateURLService(); 431 TemplateURLService* template_url_service = client_->GetTemplateURLService();
290 base::string16 url(ASCIIToUTF16("http://aaaa/?aaaa=1&b={searchTerms}&c")); 432 base::string16 url(ASCIIToUTF16("http://aaaa/?aaaa=1&b={searchTerms}&c"));
291 template_url_service->Remove( 433 template_url_service->Remove(
292 template_url_service->GetTemplateURLForKeyword(ASCIIToUTF16("aaaa"))); 434 template_url_service->GetTemplateURLForKeyword(ASCIIToUTF16("aaaa")));
293 ASSERT_TRUE(template_url_service->GetTemplateURLForKeyword( 435 ASSERT_TRUE(template_url_service->GetTemplateURLForKeyword(
294 ASCIIToUTF16("aaaa")) == NULL); 436 ASCIIToUTF16("aaaa")) == NULL);
295 } 437 }
296 438
297 TEST_F(KeywordProviderTest, GetKeywordForInput) { 439 TEST_F(KeywordProviderTest, GetKeywordForInput) {
440 SetUpClientAndKeywordProvider();
298 EXPECT_EQ(ASCIIToUTF16("aa"), 441 EXPECT_EQ(ASCIIToUTF16("aa"),
299 kw_provider_->GetKeywordForText(ASCIIToUTF16("aa"))); 442 kw_provider_->GetKeywordForText(ASCIIToUTF16("aa")));
300 EXPECT_EQ(base::string16(), 443 EXPECT_EQ(base::string16(),
301 kw_provider_->GetKeywordForText(ASCIIToUTF16("aafoo"))); 444 kw_provider_->GetKeywordForText(ASCIIToUTF16("aafoo")));
302 EXPECT_EQ(base::string16(), 445 EXPECT_EQ(base::string16(),
303 kw_provider_->GetKeywordForText(ASCIIToUTF16("aa foo"))); 446 kw_provider_->GetKeywordForText(ASCIIToUTF16("aa foo")));
304 } 447 }
305 448
306 TEST_F(KeywordProviderTest, GetSubstitutingTemplateURLForInput) { 449 TEST_F(KeywordProviderTest, GetSubstitutingTemplateURLForInput) {
307 struct { 450 struct {
(...skipping 29 matching lines...) Expand all
337 { "aa foo ", 3u, true, "aa.com?foo={searchTerms}", "foo ", 0 }, 480 { "aa foo ", 3u, true, "aa.com?foo={searchTerms}", "foo ", 0 },
338 // Extra space after keyword, no trailing space, cursor at the end. 481 // Extra space after keyword, no trailing space, cursor at the end.
339 { "aa foo", 7u, true, "aa.com?foo={searchTerms}", "foo", 3u }, 482 { "aa foo", 7u, true, "aa.com?foo={searchTerms}", "foo", 3u },
340 // Extra space after keyword, no trailing space, cursor in the middle. 483 // Extra space after keyword, no trailing space, cursor in the middle.
341 { "aa foo", 5u, true, "aa.com?foo={searchTerms}", "foo", 1u }, 484 { "aa foo", 5u, true, "aa.com?foo={searchTerms}", "foo", 1u },
342 485
343 // Disallow exact keyword match. 486 // Disallow exact keyword match.
344 { "aa foo", base::string16::npos, false, "", "aa foo", 487 { "aa foo", base::string16::npos, false, "", "aa foo",
345 base::string16::npos }, 488 base::string16::npos },
346 }; 489 };
490 SetUpClientAndKeywordProvider();
347 for (size_t i = 0; i < arraysize(cases); i++) { 491 for (size_t i = 0; i < arraysize(cases); i++) {
348 AutocompleteInput input(ASCIIToUTF16(cases[i].text), 492 AutocompleteInput input(ASCIIToUTF16(cases[i].text),
349 cases[i].cursor_position, std::string(), GURL(), 493 cases[i].cursor_position, std::string(), GURL(),
350 metrics::OmniboxEventProto::INVALID_SPEC, false, 494 metrics::OmniboxEventProto::INVALID_SPEC, false,
351 false, cases[i].allow_exact_keyword_match, true, 495 false, cases[i].allow_exact_keyword_match, true,
352 false, TestingSchemeClassifier()); 496 false, TestingSchemeClassifier());
353 const TemplateURL* url = 497 const TemplateURL* url =
354 KeywordProvider::GetSubstitutingTemplateURLForInput( 498 KeywordProvider::GetSubstitutingTemplateURLForInput(
355 client_->GetTemplateURLService(), &input); 499 client_->GetTemplateURLService(), &input);
356 if (cases[i].expected_url.empty()) 500 if (cases[i].expected_url.empty())
(...skipping 11 matching lines...) Expand all
368 base::CommandLine::ForCurrentProcess()->AppendSwitchASCII( 512 base::CommandLine::ForCurrentProcess()->AppendSwitchASCII(
369 switches::kExtraSearchQueryParams, "a=b"); 513 switches::kExtraSearchQueryParams, "a=b");
370 514
371 TestData<GURL> url_cases[] = { 515 TestData<GURL> url_cases[] = {
372 { ASCIIToUTF16("a 1 2 3"), 3, 516 { ASCIIToUTF16("a 1 2 3"), 3,
373 { { GURL("aa.com?a=b&foo=1+2+3"), false }, 517 { { GURL("aa.com?a=b&foo=1+2+3"), false },
374 { GURL("bogus URL 1+2+3"), false }, 518 { GURL("bogus URL 1+2+3"), false },
375 { GURL("http://aaaa/?aaaa=1&b=1+2+3&c"), false } } }, 519 { GURL("http://aaaa/?aaaa=1&b=1+2+3&c"), false } } },
376 }; 520 };
377 521
522 SetUpClientAndKeywordProvider();
378 RunTest<GURL>(url_cases, arraysize(url_cases), 523 RunTest<GURL>(url_cases, arraysize(url_cases),
379 &AutocompleteMatch::destination_url); 524 &AutocompleteMatch::destination_url);
380 } 525 }
381 526
382 TEST_F(KeywordProviderTest, DoesNotProvideMatchesOnFocus) { 527 TEST_F(KeywordProviderTest, DoesNotProvideMatchesOnFocus) {
528 SetUpClientAndKeywordProvider();
383 AutocompleteInput input(ASCIIToUTF16("aaa"), base::string16::npos, 529 AutocompleteInput input(ASCIIToUTF16("aaa"), base::string16::npos,
384 std::string(), GURL(), 530 std::string(), GURL(),
385 metrics::OmniboxEventProto::INVALID_SPEC, true, false, 531 metrics::OmniboxEventProto::INVALID_SPEC, true, false,
386 true, true, true, TestingSchemeClassifier()); 532 true, true, true, TestingSchemeClassifier());
387 kw_provider_->Start(input, false); 533 kw_provider_->Start(input, false);
388 ASSERT_TRUE(kw_provider_->matches().empty()); 534 ASSERT_TRUE(kw_provider_->matches().empty());
389 } 535 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698