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/prefs/pref_service.h" | 10 #include "base/prefs/pref_service.h" |
(...skipping 395 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
406 }; | 406 }; |
407 RunTest(ASCIIToUTF16("foo.com"), std::string(), true, short_2, | 407 RunTest(ASCIIToUTF16("foo.com"), std::string(), true, short_2, |
408 arraysize(short_2)); | 408 arraysize(short_2)); |
409 RunTest(ASCIIToUTF16("foo.com/"), std::string(), true, short_2, | 409 RunTest(ASCIIToUTF16("foo.com/"), std::string(), true, short_2, |
410 arraysize(short_2)); | 410 arraysize(short_2)); |
411 | 411 |
412 // The filename is the second best of the foo.com* entries, but there is a | 412 // The filename is the second best of the foo.com* entries, but there is a |
413 // shorter URL that's "good enough". The host doesn't match the user input | 413 // shorter URL that's "good enough". The host doesn't match the user input |
414 // and so should not appear. | 414 // and so should not appear. |
415 const UrlAndLegalDefault short_3[] = { | 415 const UrlAndLegalDefault short_3[] = { |
| 416 { "http://foo.com/dir/another/", false }, |
416 { "http://foo.com/d", true }, | 417 { "http://foo.com/d", true }, |
417 { "http://foo.com/dir/another/", false }, | |
418 { "http://foo.com/dir/another/again/myfile.html", false }, | 418 { "http://foo.com/dir/another/again/myfile.html", false }, |
419 { "http://foo.com/dir/", false } | 419 { "http://foo.com/dir/", false } |
420 }; | 420 }; |
421 RunTest(ASCIIToUTF16("foo.com/d"), std::string(), true, short_3, | 421 RunTest(ASCIIToUTF16("foo.com/d"), std::string(), true, short_3, |
422 arraysize(short_3)); | 422 arraysize(short_3)); |
| 423 // If prevent_inline_autocomplete is false, we won't bother creating the |
| 424 // URL-what-you-typed match because we have promoted inline autocompletions. |
| 425 const UrlAndLegalDefault short_3_allow_inline[] = { |
| 426 { "http://foo.com/dir/another/", true }, |
| 427 { "http://foo.com/dir/another/again/myfile.html", true }, |
| 428 { "http://foo.com/dir/", true } |
| 429 }; |
| 430 RunTest(ASCIIToUTF16("foo.com/d"), std::string(), false, short_3_allow_inline, |
| 431 arraysize(short_3_allow_inline)); |
423 | 432 |
424 // We shouldn't promote shorter URLs than the best if they're not good | 433 // We shouldn't promote shorter URLs than the best if they're not good |
425 // enough. | 434 // enough. |
426 const UrlAndLegalDefault short_4[] = { | 435 const UrlAndLegalDefault short_4[] = { |
| 436 { "http://foo.com/dir/another/again/myfile.html", false }, |
427 { "http://foo.com/dir/another/a", true }, | 437 { "http://foo.com/dir/another/a", true }, |
428 { "http://foo.com/dir/another/again/myfile.html", false }, | |
429 { "http://foo.com/dir/another/again/", false } | 438 { "http://foo.com/dir/another/again/", false } |
430 }; | 439 }; |
431 RunTest(ASCIIToUTF16("foo.com/dir/another/a"), std::string(), true, short_4, | 440 RunTest(ASCIIToUTF16("foo.com/dir/another/a"), std::string(), true, short_4, |
432 arraysize(short_4)); | 441 arraysize(short_4)); |
| 442 // If prevent_inline_autocomplete is false, we won't bother creating the |
| 443 // URL-what-you-typed match because we have promoted inline autocompletions. |
| 444 const UrlAndLegalDefault short_4_allow_inline[] = { |
| 445 { "http://foo.com/dir/another/again/myfile.html", true }, |
| 446 { "http://foo.com/dir/another/again/", true } |
| 447 }; |
| 448 RunTest(ASCIIToUTF16("foo.com/dir/another/a"), std::string(), false, |
| 449 short_4_allow_inline, arraysize(short_4_allow_inline)); |
433 | 450 |
434 // Exact matches should always be best no matter how much more another match | 451 // Exact matches should always be best no matter how much more another match |
435 // has been typed. | 452 // has been typed. |
436 const UrlAndLegalDefault short_5a[] = { | 453 const UrlAndLegalDefault short_5a[] = { |
437 { "http://gooey/", true }, | 454 { "http://gooey/", true }, |
438 { "http://www.google.com/", true }, | 455 { "http://www.google.com/", true }, |
439 { "http://go/", true } | 456 { "http://go/", true } |
440 }; | 457 }; |
441 const UrlAndLegalDefault short_5b[] = { | 458 const UrlAndLegalDefault short_5b[] = { |
442 { "http://go/", true }, | 459 { "http://go/", true }, |
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
478 redirects_to_a.push_back(GURL(test_cases[0].url)); | 495 redirects_to_a.push_back(GURL(test_cases[0].url)); |
479 history_service_->AddPage(GURL(test_cases[0].url), base::Time::Now(), | 496 history_service_->AddPage(GURL(test_cases[0].url), base::Time::Now(), |
480 NULL, 0, GURL(), redirects_to_a, ui::PAGE_TRANSITION_TYPED, | 497 NULL, 0, GURL(), redirects_to_a, ui::PAGE_TRANSITION_TYPED, |
481 history::SOURCE_BROWSED, true); | 498 history::SOURCE_BROWSED, true); |
482 | 499 |
483 // Because all the results are part of a redirect chain with other results, | 500 // Because all the results are part of a redirect chain with other results, |
484 // all but the first one (A) should be culled. We should get the default | 501 // all but the first one (A) should be culled. We should get the default |
485 // "what you typed" result, plus this one. | 502 // "what you typed" result, plus this one. |
486 const base::string16 typing(ASCIIToUTF16("http://redirects/")); | 503 const base::string16 typing(ASCIIToUTF16("http://redirects/")); |
487 const UrlAndLegalDefault expected_results[] = { | 504 const UrlAndLegalDefault expected_results[] = { |
488 { base::UTF16ToUTF8(typing), true }, | 505 { test_cases[0].url, false }, |
489 { test_cases[0].url, false } | 506 { base::UTF16ToUTF8(typing), true } |
490 }; | 507 }; |
491 RunTest(typing, std::string(), true, expected_results, | 508 RunTest(typing, std::string(), true, expected_results, |
492 arraysize(expected_results)); | 509 arraysize(expected_results)); |
| 510 |
| 511 // If prevent_inline_autocomplete is false, we won't bother creating the |
| 512 // URL-what-you-typed match because we have promoted inline autocompletions. |
| 513 // The result set should instead consist of a single URL representing the |
| 514 // whole set of redirects. |
| 515 const UrlAndLegalDefault expected_results_allow_inlining[] = { |
| 516 { test_cases[0].url, true } |
| 517 }; |
| 518 RunTest(typing, std::string(), false, expected_results_allow_inlining, |
| 519 arraysize(expected_results_allow_inlining)); |
493 } | 520 } |
494 | 521 |
495 TEST_F(HistoryURLProviderTestNoSearchProvider, WhatYouTypedNoSearchProvider) { | 522 TEST_F(HistoryURLProviderTestNoSearchProvider, WhatYouTypedNoSearchProvider) { |
496 // When no search provider is available, make sure we provide WYT matches | 523 // When no search provider is available, make sure we provide WYT matches |
497 // for text that could be a URL. | 524 // for text that could be a URL. |
498 | 525 |
499 const UrlAndLegalDefault results_1[] = { | 526 const UrlAndLegalDefault results_1[] = { |
500 { "http://wytmatch/", true } | 527 { "http://wytmatch/", true } |
501 }; | 528 }; |
502 RunTest(ASCIIToUTF16("wytmatch"), std::string(), false, results_1, | 529 RunTest(ASCIIToUTF16("wytmatch"), std::string(), false, results_1, |
(...skipping 528 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1031 // Test the experiment (scoring enabled). | 1058 // Test the experiment (scoring enabled). |
1032 autocomplete_->scoring_params_.experimental_scoring_enabled = true; | 1059 autocomplete_->scoring_params_.experimental_scoring_enabled = true; |
1033 ASSERT_NO_FATAL_FAILURE(RunTest(ASCIIToUTF16(test_cases[i].input), | 1060 ASSERT_NO_FATAL_FAILURE(RunTest(ASCIIToUTF16(test_cases[i].input), |
1034 std::string(), false, output, max_matches)); | 1061 std::string(), false, output, max_matches)); |
1035 for (int j = 0; j < max_matches; ++j) { | 1062 for (int j = 0; j < max_matches; ++j) { |
1036 EXPECT_EQ(test_cases[i].matches[j].experiment_relevance, | 1063 EXPECT_EQ(test_cases[i].matches[j].experiment_relevance, |
1037 matches_[j].relevance); | 1064 matches_[j].relevance); |
1038 } | 1065 } |
1039 } | 1066 } |
1040 } | 1067 } |
OLD | NEW |