OLD | NEW |
---|---|
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 "chrome/browser/autocomplete/history_url_provider.h" | 5 #include "chrome/browser/autocomplete/history_url_provider.h" |
6 | 6 |
7 #include <algorithm> | 7 #include <algorithm> |
8 | 8 |
9 #include "base/message_loop/message_loop.h" | 9 #include "base/message_loop/message_loop.h" |
10 #include "base/path_service.h" | 10 #include "base/path_service.h" |
(...skipping 114 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
125 {"http://typedhost/untypedpath", "Intranet untyped", 1, 0}, | 125 {"http://typedhost/untypedpath", "Intranet untyped", 1, 0}, |
126 | 126 |
127 {"http://x.com/one", "Internet", 2, 2}, | 127 {"http://x.com/one", "Internet", 2, 2}, |
128 {"http://x.com/two", "Internet two", 1, 1}, | 128 {"http://x.com/two", "Internet two", 1, 1}, |
129 {"http://x.com/three", "Internet three", 2, 2}, | 129 {"http://x.com/three", "Internet three", 2, 2}, |
130 }; | 130 }; |
131 | 131 |
132 class HistoryURLProviderTest : public testing::Test, | 132 class HistoryURLProviderTest : public testing::Test, |
133 public AutocompleteProviderListener { | 133 public AutocompleteProviderListener { |
134 public: | 134 public: |
135 // A pair of with the URL and whether that URL is allowed to be | |
Peter Kasting
2013/08/06 22:56:16
Nit: Grammar
Mark P
2013/08/07 00:44:31
Done.
| |
136 // the default match. | |
137 typedef std::pair<std::string, bool> ExpectedUrlAndLegalDefaultMatch; | |
Peter Kasting
2013/08/06 22:56:16
Tiny nit: Chrome code does both, but personally I
Mark P
2013/08/07 00:44:31
In this context, I think URL looks better. I pref
Peter Kasting
2013/08/09 21:59:34
Did you reverse URL and Url in your reply, or just
Mark P
2013/08/09 22:24:11
I reversed it in my reply. I find strings with mu
| |
138 | |
135 HistoryURLProviderTest() | 139 HistoryURLProviderTest() |
136 : sort_matches_(false) { | 140 : sort_matches_(false) { |
137 HistoryQuickProvider::set_disabled(true); | 141 HistoryQuickProvider::set_disabled(true); |
138 } | 142 } |
139 | 143 |
140 virtual ~HistoryURLProviderTest() { | 144 virtual ~HistoryURLProviderTest() { |
141 HistoryQuickProvider::set_disabled(false); | 145 HistoryQuickProvider::set_disabled(false); |
142 } | 146 } |
143 | 147 |
144 // AutocompleteProviderListener: | 148 // AutocompleteProviderListener: |
(...skipping 16 matching lines...) Expand all Loading... | |
161 | 165 |
162 // Fills test data into the history system. | 166 // Fills test data into the history system. |
163 void FillData(); | 167 void FillData(); |
164 | 168 |
165 // Runs an autocomplete query on |text| and checks to see that the returned | 169 // Runs an autocomplete query on |text| and checks to see that the returned |
166 // results' destination URLs match those provided. Also allows checking | 170 // results' destination URLs match those provided. Also allows checking |
167 // that the input type was identified correctly. | 171 // that the input type was identified correctly. |
168 void RunTest(const string16 text, | 172 void RunTest(const string16 text, |
169 const string16& desired_tld, | 173 const string16& desired_tld, |
170 bool prevent_inline_autocomplete, | 174 bool prevent_inline_autocomplete, |
171 const std::string* expected_urls, | 175 const ExpectedUrlAndLegalDefaultMatch* expected_urls, |
172 size_t num_results, | 176 size_t num_results, |
173 AutocompleteInput::Type* identified_input_type); | 177 AutocompleteInput::Type* identified_input_type); |
174 | 178 |
175 // A version of the above without the final |type| output parameter. | 179 // A version of the above without the final |type| output parameter. |
176 void RunTest(const string16 text, | 180 void RunTest(const string16 text, |
177 const string16& desired_tld, | 181 const string16& desired_tld, |
178 bool prevent_inline_autocomplete, | 182 bool prevent_inline_autocomplete, |
179 const std::string* expected_urls, | 183 const ExpectedUrlAndLegalDefaultMatch* expected_urls, |
180 size_t num_results) { | 184 size_t num_results) { |
181 AutocompleteInput::Type type; | 185 AutocompleteInput::Type type; |
182 return RunTest(text, desired_tld, prevent_inline_autocomplete, | 186 return RunTest(text, desired_tld, prevent_inline_autocomplete, |
183 expected_urls, num_results, &type); | 187 expected_urls, num_results, &type); |
184 } | 188 } |
185 | 189 |
186 content::TestBrowserThreadBundle thread_bundle_; | 190 content::TestBrowserThreadBundle thread_bundle_; |
187 ACMatches matches_; | 191 ACMatches matches_; |
188 scoped_ptr<TestingProfile> profile_; | 192 scoped_ptr<TestingProfile> profile_; |
189 HistoryService* history_service_; | 193 HistoryService* history_service_; |
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
250 GURL("http://p/"), UTF8ToUTF16("p"), 0, 0, | 254 GURL("http://p/"), UTF8ToUTF16("p"), 0, 0, |
251 Time::Now() - | 255 Time::Now() - |
252 TimeDelta::FromDays(history::kLowQualityMatchAgeLimitInDays - 1), | 256 TimeDelta::FromDays(history::kLowQualityMatchAgeLimitInDays - 1), |
253 false, history::SOURCE_BROWSED); | 257 false, history::SOURCE_BROWSED); |
254 } | 258 } |
255 | 259 |
256 void HistoryURLProviderTest::RunTest( | 260 void HistoryURLProviderTest::RunTest( |
257 const string16 text, | 261 const string16 text, |
258 const string16& desired_tld, | 262 const string16& desired_tld, |
259 bool prevent_inline_autocomplete, | 263 bool prevent_inline_autocomplete, |
260 const std::string* expected_urls, | 264 const ExpectedUrlAndLegalDefaultMatch* expected_urls, |
261 size_t num_results, | 265 size_t num_results, |
262 AutocompleteInput::Type* identified_input_type) { | 266 AutocompleteInput::Type* identified_input_type) { |
263 AutocompleteInput input(text, string16::npos, desired_tld, GURL(), | 267 AutocompleteInput input(text, string16::npos, desired_tld, GURL(), |
264 AutocompleteInput::INVALID_SPEC, | 268 AutocompleteInput::INVALID_SPEC, |
265 prevent_inline_autocomplete, false, true, | 269 prevent_inline_autocomplete, false, true, |
266 AutocompleteInput::ALL_MATCHES); | 270 AutocompleteInput::ALL_MATCHES); |
267 *identified_input_type = input.type(); | 271 *identified_input_type = input.type(); |
268 autocomplete_->Start(input, false); | 272 autocomplete_->Start(input, false); |
269 if (!autocomplete_->done()) | 273 if (!autocomplete_->done()) |
270 base::MessageLoop::current()->Run(); | 274 base::MessageLoop::current()->Run(); |
271 | 275 |
272 matches_ = autocomplete_->matches(); | 276 matches_ = autocomplete_->matches(); |
273 if (sort_matches_) { | 277 if (sort_matches_) { |
274 for (ACMatches::iterator i = matches_.begin(); i != matches_.end(); ++i) | 278 for (ACMatches::iterator i = matches_.begin(); i != matches_.end(); ++i) |
275 i->ComputeStrippedDestinationURL(profile_.get()); | 279 i->ComputeStrippedDestinationURL(profile_.get()); |
276 std::sort(matches_.begin(), matches_.end(), | 280 std::sort(matches_.begin(), matches_.end(), |
277 &AutocompleteMatch::DestinationSortFunc); | 281 &AutocompleteMatch::DestinationSortFunc); |
278 matches_.erase(std::unique(matches_.begin(), matches_.end(), | 282 matches_.erase(std::unique(matches_.begin(), matches_.end(), |
279 &AutocompleteMatch::DestinationsEqual), | 283 &AutocompleteMatch::DestinationsEqual), |
280 matches_.end()); | 284 matches_.end()); |
281 std::sort(matches_.begin(), matches_.end(), | 285 std::sort(matches_.begin(), matches_.end(), |
282 &AutocompleteMatch::MoreRelevant); | 286 &AutocompleteMatch::MoreRelevant); |
283 } | 287 } |
284 ASSERT_EQ(num_results, matches_.size()) << "Input text: " << text | 288 ASSERT_EQ(num_results, matches_.size()) << "Input text: " << text |
285 << "\nTLD: \"" << desired_tld << "\""; | 289 << "\nTLD: \"" << desired_tld << "\""; |
286 for (size_t i = 0; i < num_results; ++i) | 290 for (size_t i = 0; i < num_results; ++i) { |
287 EXPECT_EQ(expected_urls[i], matches_[i].destination_url.spec()); | 291 EXPECT_EQ(expected_urls[i].first, matches_[i].destination_url.spec()); |
292 EXPECT_EQ(expected_urls[i].second, matches_[i].allowed_to_be_default_match); | |
293 } | |
288 } | 294 } |
289 | 295 |
290 TEST_F(HistoryURLProviderTest, PromoteShorterURLs) { | 296 TEST_F(HistoryURLProviderTest, PromoteShorterURLs) { |
291 // Test that hosts get synthesized below popular pages. | 297 // Test that hosts get synthesized below popular pages. |
292 const std::string expected_nonsynth[] = { | 298 const ExpectedUrlAndLegalDefaultMatch expected_nonsynth[] = { |
293 "http://slashdot.org/favorite_page.html", | 299 ExpectedUrlAndLegalDefaultMatch( |
294 "http://slashdot.org/", | 300 "http://slashdot.org/favorite_page.html", false), |
301 ExpectedUrlAndLegalDefaultMatch("http://slashdot.org/", false) | |
295 }; | 302 }; |
296 RunTest(ASCIIToUTF16("slash"), string16(), true, expected_nonsynth, | 303 RunTest(ASCIIToUTF16("slash"), string16(), true, expected_nonsynth, |
297 arraysize(expected_nonsynth)); | 304 arraysize(expected_nonsynth)); |
298 | 305 |
299 // Test that hosts get synthesized above less popular pages. | 306 // Test that hosts get synthesized above less popular pages. |
300 const std::string expected_synth[] = { | 307 const ExpectedUrlAndLegalDefaultMatch expected_synth[] = { |
301 "http://kerneltrap.org/", | 308 ExpectedUrlAndLegalDefaultMatch("http://kerneltrap.org/", false), |
302 "http://kerneltrap.org/not_very_popular.html", | 309 ExpectedUrlAndLegalDefaultMatch( |
310 "http://kerneltrap.org/not_very_popular.html", false) | |
303 }; | 311 }; |
304 RunTest(ASCIIToUTF16("kernel"), string16(), true, expected_synth, | 312 RunTest(ASCIIToUTF16("kernel"), string16(), true, expected_synth, |
305 arraysize(expected_synth)); | 313 arraysize(expected_synth)); |
306 | 314 |
307 // Test that unpopular pages are ignored completely. | 315 // Test that unpopular pages are ignored completely. |
308 RunTest(ASCIIToUTF16("fresh"), string16(), true, NULL, 0); | 316 RunTest(ASCIIToUTF16("fresh"), string16(), true, NULL, 0); |
309 | 317 |
310 // Test that if we create or promote shorter suggestions that would not | 318 // Test that if we create or promote shorter suggestions that would not |
311 // normally be inline autocompletable, we make them inline autocompletable if | 319 // normally be inline autocompletable, we make them inline autocompletable if |
312 // the original suggestion (that we replaced as "top") was inline | 320 // the original suggestion (that we replaced as "top") was inline |
313 // autocompletable. | 321 // autocompletable. |
314 const std::string expected_synthesisa[] = { | 322 const ExpectedUrlAndLegalDefaultMatch expected_synthesisa[] = { |
315 "http://synthesisatest.com/", | 323 ExpectedUrlAndLegalDefaultMatch("http://synthesisatest.com/", true), |
316 "http://synthesisatest.com/foo/", | 324 ExpectedUrlAndLegalDefaultMatch("http://synthesisatest.com/foo/", true) |
317 }; | 325 }; |
318 RunTest(ASCIIToUTF16("synthesisa"), string16(), false, expected_synthesisa, | 326 RunTest(ASCIIToUTF16("synthesisa"), string16(), false, expected_synthesisa, |
319 arraysize(expected_synthesisa)); | 327 arraysize(expected_synthesisa)); |
320 EXPECT_LT(matches_.front().relevance, 1200); | 328 EXPECT_LT(matches_.front().relevance, 1200); |
321 const std::string expected_synthesisb[] = { | 329 const ExpectedUrlAndLegalDefaultMatch expected_synthesisb[] = { |
322 "http://synthesisbtest.com/foo/", | 330 ExpectedUrlAndLegalDefaultMatch("http://synthesisbtest.com/foo/", true), |
323 "http://synthesisbtest.com/foo/bar.html", | 331 ExpectedUrlAndLegalDefaultMatch( |
332 "http://synthesisbtest.com/foo/bar.html", true) | |
324 }; | 333 }; |
325 RunTest(ASCIIToUTF16("synthesisb"), string16(), false, expected_synthesisb, | 334 RunTest(ASCIIToUTF16("synthesisb"), string16(), false, expected_synthesisb, |
326 arraysize(expected_synthesisb)); | 335 arraysize(expected_synthesisb)); |
327 EXPECT_GE(matches_.front().relevance, 1410); | 336 EXPECT_GE(matches_.front().relevance, 1410); |
328 | 337 |
329 // Test that if we have a synthesized host that matches a suggestion, they | 338 // Test that if we have a synthesized host that matches a suggestion, they |
330 // get combined into one. | 339 // get combined into one. |
331 const std::string expected_combine[] = { | 340 const ExpectedUrlAndLegalDefaultMatch expected_combine[] = { |
332 "http://news.google.com/", | 341 ExpectedUrlAndLegalDefaultMatch("http://news.google.com/", false), |
333 "http://news.google.com/?ned=us&topic=n", | 342 ExpectedUrlAndLegalDefaultMatch( |
343 "http://news.google.com/?ned=us&topic=n", false), | |
334 }; | 344 }; |
335 ASSERT_NO_FATAL_FAILURE(RunTest(ASCIIToUTF16("news"), string16(), true, | 345 ASSERT_NO_FATAL_FAILURE(RunTest(ASCIIToUTF16("news"), string16(), true, |
336 expected_combine, arraysize(expected_combine))); | 346 expected_combine, arraysize(expected_combine))); |
337 // The title should also have gotten set properly on the host for the | 347 // The title should also have gotten set properly on the host for the |
338 // synthesized one, since it was also in the results. | 348 // synthesized one, since it was also in the results. |
339 EXPECT_EQ(ASCIIToUTF16("Google News"), matches_.front().description); | 349 EXPECT_EQ(ASCIIToUTF16("Google News"), matches_.front().description); |
340 | 350 |
341 // Test that short URL matching works correctly as the user types more | 351 // Test that short URL matching works correctly as the user types more |
342 // (several tests): | 352 // (several tests): |
343 // The entry for foo.com is the best of all five foo.com* entries. | 353 // The entry for foo.com is the best of all five foo.com* entries. |
344 const std::string short_1[] = { | 354 const ExpectedUrlAndLegalDefaultMatch short_1[] = { |
345 "http://foo.com/", | 355 ExpectedUrlAndLegalDefaultMatch("http://foo.com/", false), |
346 "http://foo.com/dir/another/again/myfile.html", | 356 ExpectedUrlAndLegalDefaultMatch( |
347 "http://foo.com/dir/", | 357 "http://foo.com/dir/another/again/myfile.html", false), |
358 ExpectedUrlAndLegalDefaultMatch("http://foo.com/dir/", false) | |
348 }; | 359 }; |
349 RunTest(ASCIIToUTF16("foo"), string16(), true, short_1, arraysize(short_1)); | 360 RunTest(ASCIIToUTF16("foo"), string16(), true, short_1, arraysize(short_1)); |
350 | 361 |
351 // When the user types the whole host, make sure we don't get two results for | 362 // When the user types the whole host, make sure we don't get two results for |
352 // it. | 363 // it. |
353 const std::string short_2[] = { | 364 const ExpectedUrlAndLegalDefaultMatch short_2[] = { |
354 "http://foo.com/", | 365 ExpectedUrlAndLegalDefaultMatch("http://foo.com/", true), |
355 "http://foo.com/dir/another/again/myfile.html", | 366 ExpectedUrlAndLegalDefaultMatch( |
356 "http://foo.com/dir/", | 367 "http://foo.com/dir/another/again/myfile.html", false), |
357 "http://foo.com/dir/another/", | 368 ExpectedUrlAndLegalDefaultMatch("http://foo.com/dir/", false), |
369 ExpectedUrlAndLegalDefaultMatch("http://foo.com/dir/another/", false) | |
358 }; | 370 }; |
359 RunTest(ASCIIToUTF16("foo.com"), string16(), true, short_2, | 371 RunTest(ASCIIToUTF16("foo.com"), string16(), true, short_2, |
360 arraysize(short_2)); | 372 arraysize(short_2)); |
361 RunTest(ASCIIToUTF16("foo.com/"), string16(), true, short_2, | 373 RunTest(ASCIIToUTF16("foo.com/"), string16(), true, short_2, |
362 arraysize(short_2)); | 374 arraysize(short_2)); |
363 | 375 |
364 // The filename is the second best of the foo.com* entries, but there is a | 376 // The filename is the second best of the foo.com* entries, but there is a |
365 // shorter URL that's "good enough". The host doesn't match the user input | 377 // shorter URL that's "good enough". The host doesn't match the user input |
366 // and so should not appear. | 378 // and so should not appear. |
367 const std::string short_3[] = { | 379 const ExpectedUrlAndLegalDefaultMatch short_3[] = { |
368 "http://foo.com/d", | 380 ExpectedUrlAndLegalDefaultMatch("http://foo.com/d", true), |
369 "http://foo.com/dir/another/", | 381 ExpectedUrlAndLegalDefaultMatch("http://foo.com/dir/another/", false), |
370 "http://foo.com/dir/another/again/myfile.html", | 382 ExpectedUrlAndLegalDefaultMatch( |
371 "http://foo.com/dir/", | 383 "http://foo.com/dir/another/again/myfile.html", false), |
384 ExpectedUrlAndLegalDefaultMatch("http://foo.com/dir/", false) | |
372 }; | 385 }; |
373 RunTest(ASCIIToUTF16("foo.com/d"), string16(), true, short_3, | 386 RunTest(ASCIIToUTF16("foo.com/d"), string16(), true, short_3, |
374 arraysize(short_3)); | 387 arraysize(short_3)); |
375 | 388 |
376 // We shouldn't promote shorter URLs than the best if they're not good | 389 // We shouldn't promote shorter URLs than the best if they're not good |
377 // enough. | 390 // enough. |
378 const std::string short_4[] = { | 391 const ExpectedUrlAndLegalDefaultMatch short_4[] = { |
379 "http://foo.com/dir/another/a", | 392 ExpectedUrlAndLegalDefaultMatch("http://foo.com/dir/another/a", true), |
380 "http://foo.com/dir/another/again/myfile.html", | 393 ExpectedUrlAndLegalDefaultMatch( |
381 "http://foo.com/dir/another/again/", | 394 "http://foo.com/dir/another/again/myfile.html", false), |
395 ExpectedUrlAndLegalDefaultMatch("http://foo.com/dir/another/again/", false) | |
382 }; | 396 }; |
383 RunTest(ASCIIToUTF16("foo.com/dir/another/a"), string16(), true, short_4, | 397 RunTest(ASCIIToUTF16("foo.com/dir/another/a"), string16(), true, short_4, |
384 arraysize(short_4)); | 398 arraysize(short_4)); |
385 | 399 |
386 // Exact matches should always be best no matter how much more another match | 400 // Exact matches should always be best no matter how much more another match |
387 // has been typed. | 401 // has been typed. |
388 const std::string short_5a[] = { | 402 const ExpectedUrlAndLegalDefaultMatch short_5a[] = { |
389 "http://gooey/", | 403 ExpectedUrlAndLegalDefaultMatch("http://gooey/", true), |
390 "http://www.google.com/", | 404 ExpectedUrlAndLegalDefaultMatch("http://www.google.com/", true), |
391 "http://go/", | 405 ExpectedUrlAndLegalDefaultMatch("http://go/", true) |
392 }; | 406 }; |
393 const std::string short_5b[] = { | 407 const ExpectedUrlAndLegalDefaultMatch short_5b[] = { |
394 "http://go/", | 408 ExpectedUrlAndLegalDefaultMatch("http://go/", true), |
395 "http://gooey/", | 409 ExpectedUrlAndLegalDefaultMatch("http://gooey/", true), |
396 "http://www.google.com/", | 410 ExpectedUrlAndLegalDefaultMatch("http://www.google.com/", true) |
397 }; | 411 }; |
398 RunTest(ASCIIToUTF16("g"), string16(), false, short_5a, arraysize(short_5a)); | 412 RunTest(ASCIIToUTF16("g"), string16(), false, short_5a, arraysize(short_5a)); |
399 RunTest(ASCIIToUTF16("go"), string16(), false, short_5b, arraysize(short_5b)); | 413 RunTest(ASCIIToUTF16("go"), string16(), false, short_5b, arraysize(short_5b)); |
400 } | 414 } |
401 | 415 |
402 TEST_F(HistoryURLProviderTest, CullRedirects) { | 416 TEST_F(HistoryURLProviderTest, CullRedirects) { |
403 // URLs we will be using, plus the visit counts they will initially get | 417 // URLs we will be using, plus the visit counts they will initially get |
404 // (the redirect set below will also increment the visit counts). We want | 418 // (the redirect set below will also increment the visit counts). We want |
405 // the results to be in A,B,C order. Note also that our visit counts are | 419 // the results to be in A,B,C order. Note also that our visit counts are |
406 // all high enough so that domain synthesizing won't get triggered. | 420 // all high enough so that domain synthesizing won't get triggered. |
(...skipping 20 matching lines...) Expand all Loading... | |
427 redirects_to_a.push_back(GURL(test_cases[2].url)); | 441 redirects_to_a.push_back(GURL(test_cases[2].url)); |
428 redirects_to_a.push_back(GURL(test_cases[0].url)); | 442 redirects_to_a.push_back(GURL(test_cases[0].url)); |
429 history_service_->AddPage(GURL(test_cases[0].url), base::Time::Now(), | 443 history_service_->AddPage(GURL(test_cases[0].url), base::Time::Now(), |
430 NULL, 0, GURL(), redirects_to_a, content::PAGE_TRANSITION_TYPED, | 444 NULL, 0, GURL(), redirects_to_a, content::PAGE_TRANSITION_TYPED, |
431 history::SOURCE_BROWSED, true); | 445 history::SOURCE_BROWSED, true); |
432 | 446 |
433 // Because all the results are part of a redirect chain with other results, | 447 // Because all the results are part of a redirect chain with other results, |
434 // all but the first one (A) should be culled. We should get the default | 448 // all but the first one (A) should be culled. We should get the default |
435 // "what you typed" result, plus this one. | 449 // "what you typed" result, plus this one. |
436 const string16 typing(ASCIIToUTF16("http://redirects/")); | 450 const string16 typing(ASCIIToUTF16("http://redirects/")); |
437 const std::string expected_results[] = { | 451 const ExpectedUrlAndLegalDefaultMatch expected_results[] = { |
438 UTF16ToUTF8(typing), | 452 ExpectedUrlAndLegalDefaultMatch(UTF16ToUTF8(typing), true), |
439 test_cases[0].url, | 453 ExpectedUrlAndLegalDefaultMatch(test_cases[0].url, false) |
440 }; | 454 }; |
441 RunTest(typing, string16(), true, expected_results, | 455 RunTest(typing, string16(), true, expected_results, |
442 arraysize(expected_results)); | 456 arraysize(expected_results)); |
443 } | 457 } |
444 | 458 |
445 TEST_F(HistoryURLProviderTest, WhatYouTyped) { | 459 TEST_F(HistoryURLProviderTest, WhatYouTyped) { |
446 // Make sure we suggest a What You Typed match at the right times. | 460 // Make sure we suggest a What You Typed match at the right times. |
447 RunTest(ASCIIToUTF16("wytmatch"), string16(), false, NULL, 0); | 461 RunTest(ASCIIToUTF16("wytmatch"), string16(), false, NULL, 0); |
448 RunTest(ASCIIToUTF16("wytmatch foo bar"), string16(), false, NULL, 0); | 462 RunTest(ASCIIToUTF16("wytmatch foo bar"), string16(), false, NULL, 0); |
449 RunTest(ASCIIToUTF16("wytmatch+foo+bar"), string16(), false, NULL, 0); | 463 RunTest(ASCIIToUTF16("wytmatch+foo+bar"), string16(), false, NULL, 0); |
450 RunTest(ASCIIToUTF16("wytmatch+foo+bar.com"), string16(), false, NULL, 0); | 464 RunTest(ASCIIToUTF16("wytmatch+foo+bar.com"), string16(), false, NULL, 0); |
451 | 465 |
452 const std::string results_1[] = {"http://www.wytmatch.com/"}; | 466 const ExpectedUrlAndLegalDefaultMatch results_1[] = { |
467 ExpectedUrlAndLegalDefaultMatch("http://www.wytmatch.com/", true) | |
468 }; | |
453 RunTest(ASCIIToUTF16("wytmatch"), ASCIIToUTF16("com"), false, results_1, | 469 RunTest(ASCIIToUTF16("wytmatch"), ASCIIToUTF16("com"), false, results_1, |
454 arraysize(results_1)); | 470 arraysize(results_1)); |
455 | 471 |
456 const std::string results_2[] = {"http://wytmatch%20foo%20bar/"}; | 472 const ExpectedUrlAndLegalDefaultMatch results_2[] = { |
473 ExpectedUrlAndLegalDefaultMatch("http://wytmatch%20foo%20bar/", true) | |
474 }; | |
457 RunTest(ASCIIToUTF16("http://wytmatch foo bar"), string16(), false, results_2, | 475 RunTest(ASCIIToUTF16("http://wytmatch foo bar"), string16(), false, results_2, |
458 arraysize(results_2)); | 476 arraysize(results_2)); |
459 | 477 |
460 const std::string results_3[] = {"https://wytmatch%20foo%20bar/"}; | 478 const ExpectedUrlAndLegalDefaultMatch results_3[] = { |
479 ExpectedUrlAndLegalDefaultMatch("https://wytmatch%20foo%20bar/", true) | |
480 }; | |
461 RunTest(ASCIIToUTF16("https://wytmatch foo bar"), string16(), false, | 481 RunTest(ASCIIToUTF16("https://wytmatch foo bar"), string16(), false, |
462 results_3, arraysize(results_3)); | 482 results_3, arraysize(results_3)); |
463 } | 483 } |
464 | 484 |
465 TEST_F(HistoryURLProviderTest, Fixup) { | 485 TEST_F(HistoryURLProviderTest, Fixup) { |
466 // Test for various past crashes we've had. | 486 // Test for various past crashes we've had. |
467 RunTest(ASCIIToUTF16("\\"), string16(), false, NULL, 0); | 487 RunTest(ASCIIToUTF16("\\"), string16(), false, NULL, 0); |
468 RunTest(ASCIIToUTF16("#"), string16(), false, NULL, 0); | 488 RunTest(ASCIIToUTF16("#"), string16(), false, NULL, 0); |
469 RunTest(ASCIIToUTF16("%20"), string16(), false, NULL, 0); | 489 RunTest(ASCIIToUTF16("%20"), string16(), false, NULL, 0); |
470 const std::string fixup_crash[] = {"http://%EF%BD%A5@s/"}; | 490 const ExpectedUrlAndLegalDefaultMatch fixup_crash[] = { |
491 ExpectedUrlAndLegalDefaultMatch("http://%EF%BD%A5@s/", true) | |
492 }; | |
471 RunTest(WideToUTF16(L"\uff65@s"), string16(), false, fixup_crash, | 493 RunTest(WideToUTF16(L"\uff65@s"), string16(), false, fixup_crash, |
472 arraysize(fixup_crash)); | 494 arraysize(fixup_crash)); |
473 RunTest(WideToUTF16(L"\u2015\u2015@ \uff7c"), string16(), false, NULL, 0); | 495 RunTest(WideToUTF16(L"\u2015\u2015@ \uff7c"), string16(), false, NULL, 0); |
474 | 496 |
475 // Fixing up "file:" should result in an inline autocomplete offset of just | 497 // Fixing up "file:" should result in an inline autocomplete offset of just |
476 // after "file:", not just after "file://". | 498 // after "file:", not just after "file://". |
477 const string16 input_1(ASCIIToUTF16("file:")); | 499 const string16 input_1(ASCIIToUTF16("file:")); |
478 const std::string fixup_1[] = {"file:///C:/foo.txt"}; | 500 const ExpectedUrlAndLegalDefaultMatch fixup_1[] = { |
501 ExpectedUrlAndLegalDefaultMatch("file:///C:/foo.txt", true) | |
502 }; | |
479 ASSERT_NO_FATAL_FAILURE(RunTest(input_1, string16(), false, fixup_1, | 503 ASSERT_NO_FATAL_FAILURE(RunTest(input_1, string16(), false, fixup_1, |
480 arraysize(fixup_1))); | 504 arraysize(fixup_1))); |
481 EXPECT_EQ(ASCIIToUTF16("///C:/foo.txt"), | 505 EXPECT_EQ(ASCIIToUTF16("///C:/foo.txt"), |
482 matches_.front().inline_autocompletion); | 506 matches_.front().inline_autocompletion); |
483 | 507 |
484 // Fixing up "http:/" should result in an inline autocomplete offset of just | 508 // Fixing up "http:/" should result in an inline autocomplete offset of just |
485 // after "http:/", not just after "http:". | 509 // after "http:/", not just after "http:". |
486 const string16 input_2(ASCIIToUTF16("http:/")); | 510 const string16 input_2(ASCIIToUTF16("http:/")); |
487 const std::string fixup_2[] = { | 511 const ExpectedUrlAndLegalDefaultMatch fixup_2[] = { |
488 "http://bogussite.com/a", | 512 ExpectedUrlAndLegalDefaultMatch("http://bogussite.com/a", true), |
489 "http://bogussite.com/b", | 513 ExpectedUrlAndLegalDefaultMatch("http://bogussite.com/b", true), |
490 "http://bogussite.com/c", | 514 ExpectedUrlAndLegalDefaultMatch("http://bogussite.com/c", true) |
491 }; | 515 }; |
492 ASSERT_NO_FATAL_FAILURE(RunTest(input_2, string16(), false, fixup_2, | 516 ASSERT_NO_FATAL_FAILURE(RunTest(input_2, string16(), false, fixup_2, |
493 arraysize(fixup_2))); | 517 arraysize(fixup_2))); |
494 EXPECT_EQ(ASCIIToUTF16("/bogussite.com/a"), | 518 EXPECT_EQ(ASCIIToUTF16("/bogussite.com/a"), |
495 matches_.front().inline_autocompletion); | 519 matches_.front().inline_autocompletion); |
496 | 520 |
497 // Adding a TLD to a small number like "56" should result in "www.56.com" | 521 // Adding a TLD to a small number like "56" should result in "www.56.com" |
498 // rather than "0.0.0.56.com". | 522 // rather than "0.0.0.56.com". |
499 const std::string fixup_3[] = {"http://www.56.com/"}; | 523 const ExpectedUrlAndLegalDefaultMatch fixup_3[] = { |
524 ExpectedUrlAndLegalDefaultMatch("http://www.56.com/", true) | |
525 }; | |
500 RunTest(ASCIIToUTF16("56"), ASCIIToUTF16("com"), true, fixup_3, | 526 RunTest(ASCIIToUTF16("56"), ASCIIToUTF16("com"), true, fixup_3, |
501 arraysize(fixup_3)); | 527 arraysize(fixup_3)); |
502 | 528 |
503 // An input looks like a IP address like "127.0.0.1" should result in | 529 // An input looks like a IP address like "127.0.0.1" should result in |
504 // "http://127.0.0.1/". | 530 // "http://127.0.0.1/". |
505 const std::string fixup_4[] = {"http://127.0.0.1/"}; | 531 const ExpectedUrlAndLegalDefaultMatch fixup_4[] = { |
532 ExpectedUrlAndLegalDefaultMatch("http://127.0.0.1/", true) | |
533 }; | |
506 RunTest(ASCIIToUTF16("127.0.0.1"), string16(), false, fixup_4, | 534 RunTest(ASCIIToUTF16("127.0.0.1"), string16(), false, fixup_4, |
507 arraysize(fixup_4)); | 535 arraysize(fixup_4)); |
508 | 536 |
509 // An number "17173" should result in "http://www.17173.com/" in db. | 537 // An number "17173" should result in "http://www.17173.com/" in db. |
510 const std::string fixup_5[] = {"http://www.17173.com/"}; | 538 const ExpectedUrlAndLegalDefaultMatch fixup_5[] = { |
539 ExpectedUrlAndLegalDefaultMatch("http://www.17173.com/", true) | |
540 }; | |
511 RunTest(ASCIIToUTF16("17173"), string16(), false, fixup_5, | 541 RunTest(ASCIIToUTF16("17173"), string16(), false, fixup_5, |
512 arraysize(fixup_5)); | 542 arraysize(fixup_5)); |
513 } | 543 } |
514 | 544 |
515 // Make sure the results for the input 'p' don't change between the first and | 545 // Make sure the results for the input 'p' don't change between the first and |
516 // second passes. | 546 // second passes. |
517 TEST_F(HistoryURLProviderTest, EmptyVisits) { | 547 TEST_F(HistoryURLProviderTest, EmptyVisits) { |
518 // Wait for history to create the in memory DB. | 548 // Wait for history to create the in memory DB. |
519 profile_->BlockUntilHistoryProcessesPendingRequests(); | 549 profile_->BlockUntilHistoryProcessesPendingRequests(); |
520 | 550 |
(...skipping 15 matching lines...) Expand all Loading... | |
536 EXPECT_TRUE(autocomplete_->done()); | 566 EXPECT_TRUE(autocomplete_->done()); |
537 matches_ = autocomplete_->matches(); | 567 matches_ = autocomplete_->matches(); |
538 ASSERT_GT(matches_.size(), 0u); | 568 ASSERT_GT(matches_.size(), 0u); |
539 EXPECT_EQ(GURL("http://pandora.com/"), matches_[0].destination_url); | 569 EXPECT_EQ(GURL("http://pandora.com/"), matches_[0].destination_url); |
540 EXPECT_EQ(pandora_relevance, matches_[0].relevance); | 570 EXPECT_EQ(pandora_relevance, matches_[0].relevance); |
541 } | 571 } |
542 | 572 |
543 TEST_F(HistoryURLProviderTestNoDB, NavigateWithoutDB) { | 573 TEST_F(HistoryURLProviderTestNoDB, NavigateWithoutDB) { |
544 // Ensure that we will still produce matches for navigation when there is no | 574 // Ensure that we will still produce matches for navigation when there is no |
545 // database. | 575 // database. |
546 std::string navigation_1[] = {"http://test.com/"}; | 576 ExpectedUrlAndLegalDefaultMatch navigation_1[] = { |
577 ExpectedUrlAndLegalDefaultMatch("http://test.com/", true) | |
578 }; | |
547 RunTest(ASCIIToUTF16("test.com"), string16(), false, navigation_1, | 579 RunTest(ASCIIToUTF16("test.com"), string16(), false, navigation_1, |
548 arraysize(navigation_1)); | 580 arraysize(navigation_1)); |
549 | 581 |
550 std::string navigation_2[] = {"http://slash/"}; | 582 ExpectedUrlAndLegalDefaultMatch navigation_2[] = { |
583 ExpectedUrlAndLegalDefaultMatch("http://slash/", true) | |
584 }; | |
551 RunTest(ASCIIToUTF16("slash"), string16(), false, navigation_2, | 585 RunTest(ASCIIToUTF16("slash"), string16(), false, navigation_2, |
552 arraysize(navigation_2)); | 586 arraysize(navigation_2)); |
553 | 587 |
554 RunTest(ASCIIToUTF16("this is a query"), string16(), false, NULL, 0); | 588 RunTest(ASCIIToUTF16("this is a query"), string16(), false, NULL, 0); |
555 } | 589 } |
556 | 590 |
557 TEST_F(HistoryURLProviderTest, DontAutocompleteOnTrailingWhitespace) { | 591 TEST_F(HistoryURLProviderTest, DontAutocompleteOnTrailingWhitespace) { |
558 AutocompleteInput input(ASCIIToUTF16("slash "), string16::npos, string16(), | 592 AutocompleteInput input(ASCIIToUTF16("slash "), string16::npos, string16(), |
559 GURL(), AutocompleteInput::INVALID_SPEC, false, false, | 593 GURL(), AutocompleteInput::INVALID_SPEC, false, false, |
560 true, AutocompleteInput::ALL_MATCHES); | 594 true, AutocompleteInput::ALL_MATCHES); |
561 autocomplete_->Start(input, false); | 595 autocomplete_->Start(input, false); |
562 if (!autocomplete_->done()) | 596 if (!autocomplete_->done()) |
563 base::MessageLoop::current()->Run(); | 597 base::MessageLoop::current()->Run(); |
564 | 598 |
565 // None of the matches should attempt to autocomplete. | 599 // None of the matches should attempt to autocomplete. |
566 matches_ = autocomplete_->matches(); | 600 matches_ = autocomplete_->matches(); |
567 for (size_t i = 0; i < matches_.size(); ++i) | 601 for (size_t i = 0; i < matches_.size(); ++i) { |
568 EXPECT_TRUE(matches_[i].inline_autocompletion.empty()); | 602 EXPECT_TRUE(matches_[i].inline_autocompletion.empty()); |
603 EXPECT_FALSE(matches_[i].allowed_to_be_default_match); | |
604 } | |
569 } | 605 } |
570 | 606 |
571 TEST_F(HistoryURLProviderTest, TreatEmailsAsSearches) { | 607 TEST_F(HistoryURLProviderTest, TreatEmailsAsSearches) { |
572 // Visiting foo.com should not make this string be treated as a navigation. | 608 // Visiting foo.com should not make this string be treated as a navigation. |
573 // That means the result should be scored around 1200 ("what you typed") | 609 // That means the result should be scored around 1200 ("what you typed") |
574 // and not 1400+. | 610 // and not 1400+. |
575 const std::string expected[] = {"http://user@foo.com/"}; | 611 const ExpectedUrlAndLegalDefaultMatch expected[] = { |
612 ExpectedUrlAndLegalDefaultMatch("http://user@foo.com/", true) | |
613 }; | |
576 ASSERT_NO_FATAL_FAILURE(RunTest(ASCIIToUTF16("user@foo.com"), string16(), | 614 ASSERT_NO_FATAL_FAILURE(RunTest(ASCIIToUTF16("user@foo.com"), string16(), |
577 false, expected, arraysize(expected))); | 615 false, expected, arraysize(expected))); |
578 EXPECT_LE(1200, matches_[0].relevance); | 616 EXPECT_LE(1200, matches_[0].relevance); |
579 EXPECT_LT(matches_[0].relevance, 1210); | 617 EXPECT_LT(matches_[0].relevance, 1210); |
580 } | 618 } |
581 | 619 |
582 TEST_F(HistoryURLProviderTest, IntranetURLsWithPaths) { | 620 TEST_F(HistoryURLProviderTest, IntranetURLsWithPaths) { |
583 struct TestCase { | 621 struct TestCase { |
584 const char* input; | 622 const char* input; |
585 int relevance; | 623 int relevance; |
586 } test_cases[] = { | 624 } test_cases[] = { |
587 { "fooey", 0 }, | 625 { "fooey", 0 }, |
588 { "fooey/", 1200 }, // 1200 for URL would still navigate by default. | 626 { "fooey/", 1200 }, // 1200 for URL would still navigate by default. |
589 { "fooey/a", 1200 }, // 1200 for UNKNOWN would not. | 627 { "fooey/a", 1200 }, // 1200 for UNKNOWN would not. |
590 { "fooey/a b", 1200 }, // Also UNKNOWN. | 628 { "fooey/a b", 1200 }, // Also UNKNOWN. |
591 { "gooey", 1410 }, | 629 { "gooey", 1410 }, |
592 { "gooey/", 1410 }, | 630 { "gooey/", 1410 }, |
593 { "gooey/a", 1400 }, | 631 { "gooey/a", 1400 }, |
594 { "gooey/a b", 1400 }, | 632 { "gooey/a b", 1400 }, |
595 }; | 633 }; |
596 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(test_cases); ++i) { | 634 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(test_cases); ++i) { |
597 SCOPED_TRACE(test_cases[i].input); | 635 SCOPED_TRACE(test_cases[i].input); |
598 if (test_cases[i].relevance == 0) { | 636 if (test_cases[i].relevance == 0) { |
599 RunTest(ASCIIToUTF16(test_cases[i].input), string16(), false, NULL, 0); | 637 RunTest(ASCIIToUTF16(test_cases[i].input), string16(), false, NULL, 0); |
600 } else { | 638 } else { |
601 const std::string output[] = { | 639 const ExpectedUrlAndLegalDefaultMatch output[] = { |
602 URLFixerUpper::FixupURL(test_cases[i].input, std::string()).spec() | 640 ExpectedUrlAndLegalDefaultMatch( |
641 URLFixerUpper::FixupURL(test_cases[i].input, std::string()).spec(), | |
642 true) | |
603 }; | 643 }; |
604 ASSERT_NO_FATAL_FAILURE(RunTest(ASCIIToUTF16(test_cases[i].input), | 644 ASSERT_NO_FATAL_FAILURE(RunTest(ASCIIToUTF16(test_cases[i].input), |
605 string16(), false, output, arraysize(output))); | 645 string16(), false, output, arraysize(output))); |
606 // Actual relevance should be at least what test_cases expects and | 646 // Actual relevance should be at least what test_cases expects and |
607 // and no more than 10 more. | 647 // and no more than 10 more. |
608 EXPECT_LE(test_cases[i].relevance, matches_[0].relevance); | 648 EXPECT_LE(test_cases[i].relevance, matches_[0].relevance); |
609 EXPECT_LT(matches_[0].relevance, test_cases[i].relevance + 10); | 649 EXPECT_LT(matches_[0].relevance, test_cases[i].relevance + 10); |
610 } | 650 } |
611 } | 651 } |
612 } | 652 } |
613 | 653 |
614 TEST_F(HistoryURLProviderTest, IntranetURLsWithRefs) { | 654 TEST_F(HistoryURLProviderTest, IntranetURLsWithRefs) { |
615 struct TestCase { | 655 struct TestCase { |
616 const char* input; | 656 const char* input; |
617 int relevance; | 657 int relevance; |
618 AutocompleteInput::Type type; | 658 AutocompleteInput::Type type; |
619 } test_cases[] = { | 659 } test_cases[] = { |
620 { "gooey", 1410, AutocompleteInput::UNKNOWN }, | 660 { "gooey", 1410, AutocompleteInput::UNKNOWN }, |
621 { "gooey/", 1410, AutocompleteInput::URL }, | 661 { "gooey/", 1410, AutocompleteInput::URL }, |
622 { "gooey#", 1200, AutocompleteInput::UNKNOWN }, | 662 { "gooey#", 1200, AutocompleteInput::UNKNOWN }, |
623 { "gooey/#", 1200, AutocompleteInput::URL }, | 663 { "gooey/#", 1200, AutocompleteInput::URL }, |
624 { "gooey#foo", 1200, AutocompleteInput::UNKNOWN }, | 664 { "gooey#foo", 1200, AutocompleteInput::UNKNOWN }, |
625 { "gooey/#foo", 1200, AutocompleteInput::URL }, | 665 { "gooey/#foo", 1200, AutocompleteInput::URL }, |
626 { "gooey# foo", 1200, AutocompleteInput::UNKNOWN }, | 666 { "gooey# foo", 1200, AutocompleteInput::UNKNOWN }, |
627 { "gooey/# foo", 1200, AutocompleteInput::URL }, | 667 { "gooey/# foo", 1200, AutocompleteInput::URL }, |
628 }; | 668 }; |
629 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(test_cases); ++i) { | 669 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(test_cases); ++i) { |
630 SCOPED_TRACE(test_cases[i].input); | 670 SCOPED_TRACE(test_cases[i].input); |
631 const std::string output[] = { | 671 const ExpectedUrlAndLegalDefaultMatch output[] = { |
632 URLFixerUpper::FixupURL(test_cases[i].input, std::string()).spec() | 672 ExpectedUrlAndLegalDefaultMatch( |
673 URLFixerUpper::FixupURL(test_cases[i].input, std::string()).spec(), | |
674 true) | |
633 }; | 675 }; |
634 AutocompleteInput::Type type; | 676 AutocompleteInput::Type type; |
635 ASSERT_NO_FATAL_FAILURE( | 677 ASSERT_NO_FATAL_FAILURE( |
636 RunTest(ASCIIToUTF16(test_cases[i].input), | 678 RunTest(ASCIIToUTF16(test_cases[i].input), |
637 string16(), false, output, arraysize(output), &type)); | 679 string16(), false, output, arraysize(output), &type)); |
638 // Actual relevance should be at least what test_cases expects and | 680 // Actual relevance should be at least what test_cases expects and |
639 // and no more than 10 more. | 681 // and no more than 10 more. |
640 EXPECT_LE(test_cases[i].relevance, matches_[0].relevance); | 682 EXPECT_LE(test_cases[i].relevance, matches_[0].relevance); |
641 EXPECT_LT(matches_[0].relevance, test_cases[i].relevance + 10); | 683 EXPECT_LT(matches_[0].relevance, test_cases[i].relevance + 10); |
642 // Input type should be what we expect. This is important because | 684 // Input type should be what we expect. This is important because |
643 // this provider counts on SearchProvider to give queries a relevance | 685 // this provider counts on SearchProvider to give queries a relevance |
644 // score >1200 for UNKNOWN inputs and <1200 for URL inputs. (That's | 686 // score >1200 for UNKNOWN inputs and <1200 for URL inputs. (That's |
645 // already tested in search_provider_unittest.cc.) For this test | 687 // already tested in search_provider_unittest.cc.) For this test |
646 // here to test that the user sees the correct behavior, it needs | 688 // here to test that the user sees the correct behavior, it needs |
647 // to check that the input type was identified correctly. | 689 // to check that the input type was identified correctly. |
648 EXPECT_EQ(test_cases[i].type, type); | 690 EXPECT_EQ(test_cases[i].type, type); |
649 } | 691 } |
650 } | 692 } |
651 | 693 |
652 // Makes sure autocompletion happens for intranet sites that have been | 694 // Makes sure autocompletion happens for intranet sites that have been |
653 // previoulsy visited. | 695 // previoulsy visited. |
654 TEST_F(HistoryURLProviderTest, IntranetURLCompletion) { | 696 TEST_F(HistoryURLProviderTest, IntranetURLCompletion) { |
655 sort_matches_ = true; | 697 sort_matches_ = true; |
656 | 698 |
657 const std::string expected1[] = { | 699 const ExpectedUrlAndLegalDefaultMatch expected1[] = { |
658 "http://intra/three", | 700 ExpectedUrlAndLegalDefaultMatch("http://intra/three", true), |
659 "http://intra/two", | 701 ExpectedUrlAndLegalDefaultMatch("http://intra/two", true) |
660 }; | 702 }; |
661 ASSERT_NO_FATAL_FAILURE(RunTest(ASCIIToUTF16("intra/t"), string16(), false, | 703 ASSERT_NO_FATAL_FAILURE(RunTest(ASCIIToUTF16("intra/t"), string16(), false, |
662 expected1, arraysize(expected1))); | 704 expected1, arraysize(expected1))); |
663 EXPECT_LE(1410, matches_[0].relevance); | 705 EXPECT_LE(1410, matches_[0].relevance); |
664 EXPECT_LT(matches_[0].relevance, 1420); | 706 EXPECT_LT(matches_[0].relevance, 1420); |
665 EXPECT_EQ(matches_[0].relevance - 1, matches_[1].relevance); | 707 EXPECT_EQ(matches_[0].relevance - 1, matches_[1].relevance); |
666 | 708 |
667 const std::string expected2[] = { | 709 const ExpectedUrlAndLegalDefaultMatch expected2[] = { |
668 "http://moo/b", | 710 ExpectedUrlAndLegalDefaultMatch("http://moo/b", true), |
669 "http://moo/bar", | 711 ExpectedUrlAndLegalDefaultMatch("http://moo/bar", true) |
670 }; | 712 }; |
671 ASSERT_NO_FATAL_FAILURE(RunTest(ASCIIToUTF16("moo/b"), string16(), false, | 713 ASSERT_NO_FATAL_FAILURE(RunTest(ASCIIToUTF16("moo/b"), string16(), false, |
672 expected2, arraysize(expected2))); | 714 expected2, arraysize(expected2))); |
673 // The url what you typed match should be around 1400, otherwise the | 715 // The url what you typed match should be around 1400, otherwise the |
674 // search what you typed match is going to be first. | 716 // search what you typed match is going to be first. |
675 EXPECT_LE(1400, matches_[0].relevance); | 717 EXPECT_LE(1400, matches_[0].relevance); |
676 EXPECT_LT(matches_[0].relevance, 1410); | 718 EXPECT_LT(matches_[0].relevance, 1410); |
677 | 719 |
678 const std::string expected3[] = { | 720 const ExpectedUrlAndLegalDefaultMatch expected3[] = { |
679 "http://intra/one", | 721 ExpectedUrlAndLegalDefaultMatch("http://intra/one", true), |
680 "http://intra/three", | 722 ExpectedUrlAndLegalDefaultMatch("http://intra/three", true), |
681 "http://intra/two", | 723 ExpectedUrlAndLegalDefaultMatch("http://intra/two", true) |
682 }; | 724 }; |
683 RunTest(ASCIIToUTF16("intra"), string16(), false, expected3, | 725 RunTest(ASCIIToUTF16("intra"), string16(), false, expected3, |
684 arraysize(expected3)); | 726 arraysize(expected3)); |
685 | 727 |
686 const std::string expected4[] = { | 728 const ExpectedUrlAndLegalDefaultMatch expected4[] = { |
687 "http://intra/one", | 729 ExpectedUrlAndLegalDefaultMatch("http://intra/one", true), |
688 "http://intra/three", | 730 ExpectedUrlAndLegalDefaultMatch("http://intra/three", true), |
689 "http://intra/two", | 731 ExpectedUrlAndLegalDefaultMatch("http://intra/two", true) |
690 }; | 732 }; |
691 RunTest(ASCIIToUTF16("intra/"), string16(), false, expected4, | 733 RunTest(ASCIIToUTF16("intra/"), string16(), false, expected4, |
692 arraysize(expected4)); | 734 arraysize(expected4)); |
693 | 735 |
694 const std::string expected5[] = { | 736 const ExpectedUrlAndLegalDefaultMatch expected5[] = { |
695 "http://intra/one", | 737 ExpectedUrlAndLegalDefaultMatch("http://intra/one", true) |
696 }; | 738 }; |
697 ASSERT_NO_FATAL_FAILURE(RunTest(ASCIIToUTF16("intra/o"), string16(), false, | 739 ASSERT_NO_FATAL_FAILURE(RunTest(ASCIIToUTF16("intra/o"), string16(), false, |
698 expected5, arraysize(expected5))); | 740 expected5, arraysize(expected5))); |
699 EXPECT_LE(1410, matches_[0].relevance); | 741 EXPECT_LE(1410, matches_[0].relevance); |
700 EXPECT_LT(matches_[0].relevance, 1420); | 742 EXPECT_LT(matches_[0].relevance, 1420); |
701 | 743 |
702 const std::string expected6[] = { | 744 const ExpectedUrlAndLegalDefaultMatch expected6[] = { |
703 "http://intra/x", | 745 ExpectedUrlAndLegalDefaultMatch("http://intra/x", true) |
704 }; | 746 }; |
705 ASSERT_NO_FATAL_FAILURE(RunTest(ASCIIToUTF16("intra/x"), string16(), false, | 747 ASSERT_NO_FATAL_FAILURE(RunTest(ASCIIToUTF16("intra/x"), string16(), false, |
706 expected6, arraysize(expected6))); | 748 expected6, arraysize(expected6))); |
707 EXPECT_LE(1400, matches_[0].relevance); | 749 EXPECT_LE(1400, matches_[0].relevance); |
708 EXPECT_LT(matches_[0].relevance, 1410); | 750 EXPECT_LT(matches_[0].relevance, 1410); |
709 | 751 |
710 const std::string expected7[] = { | 752 const ExpectedUrlAndLegalDefaultMatch expected7[] = { |
711 "http://typedhost/untypedpath", | 753 ExpectedUrlAndLegalDefaultMatch("http://typedhost/untypedpath", true) |
712 }; | 754 }; |
713 ASSERT_NO_FATAL_FAILURE(RunTest(ASCIIToUTF16("typedhost/untypedpath"), | 755 ASSERT_NO_FATAL_FAILURE(RunTest(ASCIIToUTF16("typedhost/untypedpath"), |
714 string16(), false, expected7, arraysize(expected7))); | 756 string16(), false, expected7, arraysize(expected7))); |
715 EXPECT_LE(1400, matches_[0].relevance); | 757 EXPECT_LE(1400, matches_[0].relevance); |
716 EXPECT_LT(matches_[0].relevance, 1410); | 758 EXPECT_LT(matches_[0].relevance, 1410); |
717 } | 759 } |
718 | 760 |
719 TEST_F(HistoryURLProviderTest, CrashDueToFixup) { | 761 TEST_F(HistoryURLProviderTest, CrashDueToFixup) { |
720 // This test passes if we don't crash. The results don't matter. | 762 // This test passes if we don't crash. The results don't matter. |
721 const char* const test_cases[] = { | 763 const char* const test_cases[] = { |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
756 {"https://testsearch.com/?q=foobar", 20}, | 798 {"https://testsearch.com/?q=foobar", 20}, |
757 {"http://foobar.com/", 10} | 799 {"http://foobar.com/", 10} |
758 }; | 800 }; |
759 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(test_cases); ++i) { | 801 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(test_cases); ++i) { |
760 history_service_->AddPageWithDetails(GURL(test_cases[i].url), | 802 history_service_->AddPageWithDetails(GURL(test_cases[i].url), |
761 UTF8ToUTF16("Title"), test_cases[i].count, test_cases[i].count, | 803 UTF8ToUTF16("Title"), test_cases[i].count, test_cases[i].count, |
762 Time::Now(), false, history::SOURCE_BROWSED); | 804 Time::Now(), false, history::SOURCE_BROWSED); |
763 } | 805 } |
764 | 806 |
765 // We should not see search URLs when typing a previously used query. | 807 // We should not see search URLs when typing a previously used query. |
766 const std::string expected_when_searching_query[] = { | 808 const ExpectedUrlAndLegalDefaultMatch expected_when_searching_query[] = { |
767 test_cases[2].url | 809 ExpectedUrlAndLegalDefaultMatch(test_cases[2].url, false) |
768 }; | 810 }; |
769 RunTest(ASCIIToUTF16("foobar"), string16(), true, | 811 RunTest(ASCIIToUTF16("foobar"), string16(), true, |
770 expected_when_searching_query, arraysize(expected_when_searching_query)); | 812 expected_when_searching_query, arraysize(expected_when_searching_query)); |
771 | 813 |
772 // We should not see search URLs when typing the search engine name. | 814 // We should not see search URLs when typing the search engine name. |
773 const std::string expected_when_searching_site[] = { | 815 const ExpectedUrlAndLegalDefaultMatch expected_when_searching_site[] = { |
774 test_cases[0].url | 816 ExpectedUrlAndLegalDefaultMatch(test_cases[0].url, false) |
775 }; | 817 }; |
776 RunTest(ASCIIToUTF16("testsearch"), string16(), true, | 818 RunTest(ASCIIToUTF16("testsearch"), string16(), true, |
777 expected_when_searching_site, arraysize(expected_when_searching_site)); | 819 expected_when_searching_site, arraysize(expected_when_searching_site)); |
778 } | 820 } |
779 | 821 |
780 TEST_F(HistoryURLProviderTest, SuggestExactInput) { | 822 TEST_F(HistoryURLProviderTest, SuggestExactInput) { |
781 const size_t npos = std::string::npos; | 823 const size_t npos = std::string::npos; |
782 struct TestCase { | 824 struct TestCase { |
783 // Inputs: | 825 // Inputs: |
784 const char* input; | 826 const char* input; |
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
849 EXPECT_EQ(test_cases[i].offsets[match_index], | 891 EXPECT_EQ(test_cases[i].offsets[match_index], |
850 match.contents_class[match_index].offset); | 892 match.contents_class[match_index].offset); |
851 EXPECT_EQ(ACMatchClassification::URL | | 893 EXPECT_EQ(ACMatchClassification::URL | |
852 (match_index == test_cases[i].match_classification_index ? | 894 (match_index == test_cases[i].match_classification_index ? |
853 ACMatchClassification::MATCH : 0), | 895 ACMatchClassification::MATCH : 0), |
854 match.contents_class[match_index].style); | 896 match.contents_class[match_index].style); |
855 } | 897 } |
856 EXPECT_EQ(npos, test_cases[i].offsets[match.contents_class.size()]); | 898 EXPECT_EQ(npos, test_cases[i].offsets[match.contents_class.size()]); |
857 } | 899 } |
858 } | 900 } |
OLD | NEW |