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/autocomplete_result.h" | 5 #include "chrome/browser/autocomplete/autocomplete_result.h" |
6 | 6 |
7 #include <vector> | 7 #include <vector> |
8 | 8 |
9 #include "base/memory/scoped_ptr.h" | 9 #include "base/memory/scoped_ptr.h" |
10 #include "base/metrics/field_trial.h" | 10 #include "base/metrics/field_trial.h" |
(...skipping 539 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
550 true); | 550 true); |
551 result.SortAndCull(input, test_util_.profile()); | 551 result.SortAndCull(input, test_util_.profile()); |
552 ASSERT_EQ(4U, result.size()); | 552 ASSERT_EQ(4U, result.size()); |
553 EXPECT_EQ("http://c/", result.match_at(0)->destination_url.spec()); | 553 EXPECT_EQ("http://c/", result.match_at(0)->destination_url.spec()); |
554 EXPECT_EQ("http://a/", result.match_at(1)->destination_url.spec()); | 554 EXPECT_EQ("http://a/", result.match_at(1)->destination_url.spec()); |
555 EXPECT_EQ("http://b/", result.match_at(2)->destination_url.spec()); | 555 EXPECT_EQ("http://b/", result.match_at(2)->destination_url.spec()); |
556 EXPECT_EQ("http://d/", result.match_at(3)->destination_url.spec()); | 556 EXPECT_EQ("http://d/", result.match_at(3)->destination_url.spec()); |
557 } | 557 } |
558 } | 558 } |
559 | 559 |
| 560 |
| 561 |
| 562 TEST_F(AutocompleteResultTest, SortAndCullWithDisableInlining) { |
| 563 TestData data[] = { |
| 564 { 0, 0, 1300 }, |
| 565 { 1, 0, 1200 }, |
| 566 { 2, 0, 1100 }, |
| 567 { 3, 0, 1000 } |
| 568 }; |
| 569 |
| 570 { |
| 571 // Check that with the field trial disabled, we keep keep the first match |
| 572 // first even if it has an inline autocompletion. |
| 573 ACMatches matches; |
| 574 PopulateAutocompleteMatches(data, arraysize(data), &matches); |
| 575 matches[0].inline_autocompletion = base::ASCIIToUTF16("completion"); |
| 576 AutocompleteResult result; |
| 577 result.AppendMatches(matches); |
| 578 AutocompleteInput input(base::string16(), base::string16::npos, |
| 579 base::string16(), GURL(), |
| 580 AutocompleteInput::HOME_PAGE, false, false, false, |
| 581 true); |
| 582 result.SortAndCull(input, test_util_.profile()); |
| 583 AssertResultMatches(result, data, 4); |
| 584 } |
| 585 |
| 586 // Enable the field trial to disable inlining. |
| 587 { |
| 588 std::map<std::string, std::string> params; |
| 589 params[OmniboxFieldTrial::kDisableInliningRule] = "true"; |
| 590 ASSERT_TRUE(chrome_variations::AssociateVariationParams( |
| 591 OmniboxFieldTrial::kBundledExperimentFieldTrialName, "D", params)); |
| 592 } |
| 593 base::FieldTrialList::CreateFieldTrial( |
| 594 OmniboxFieldTrial::kBundledExperimentFieldTrialName, "D"); |
| 595 |
| 596 { |
| 597 // Now the first match should be demoted past the second. |
| 598 ACMatches matches; |
| 599 PopulateAutocompleteMatches(data, arraysize(data), &matches); |
| 600 matches[0].inline_autocompletion = base::ASCIIToUTF16("completion"); |
| 601 AutocompleteResult result; |
| 602 result.AppendMatches(matches); |
| 603 AutocompleteInput input(base::string16(), base::string16::npos, |
| 604 base::string16(), GURL(), |
| 605 AutocompleteInput::HOME_PAGE, false, false, false, |
| 606 true); |
| 607 result.SortAndCull(input, test_util_.profile()); |
| 608 ASSERT_EQ(4U, result.size()); |
| 609 EXPECT_EQ("http://b/", result.match_at(0)->destination_url.spec()); |
| 610 EXPECT_EQ("http://a/", result.match_at(1)->destination_url.spec()); |
| 611 EXPECT_EQ("http://c/", result.match_at(2)->destination_url.spec()); |
| 612 EXPECT_EQ("http://d/", result.match_at(3)->destination_url.spec()); |
| 613 } |
| 614 |
| 615 { |
| 616 // But if there was no inline autocompletion on the first match, then |
| 617 // the order should stay the same. This is true even if there are |
| 618 // inline autocompletions elsewhere. |
| 619 ACMatches matches; |
| 620 PopulateAutocompleteMatches(data, arraysize(data), &matches); |
| 621 matches[2].inline_autocompletion = base::ASCIIToUTF16("completion"); |
| 622 AutocompleteResult result; |
| 623 result.AppendMatches(matches); |
| 624 AutocompleteInput input(base::string16(), base::string16::npos, |
| 625 base::string16(), GURL(), |
| 626 AutocompleteInput::HOME_PAGE, false, false, false, |
| 627 true); |
| 628 result.SortAndCull(input, test_util_.profile()); |
| 629 AssertResultMatches(result, data, 4); |
| 630 } |
| 631 |
| 632 { |
| 633 // Try a more complicated situation. |
| 634 ACMatches matches; |
| 635 PopulateAutocompleteMatches(data, arraysize(data), &matches); |
| 636 matches[0].allowed_to_be_default_match = false; |
| 637 matches[1].inline_autocompletion = base::ASCIIToUTF16("completion"); |
| 638 AutocompleteResult result; |
| 639 result.AppendMatches(matches); |
| 640 AutocompleteInput input(base::string16(), base::string16::npos, |
| 641 base::string16(), GURL(), |
| 642 AutocompleteInput::HOME_PAGE, false, false, false, |
| 643 true); |
| 644 result.SortAndCull(input, test_util_.profile()); |
| 645 ASSERT_EQ(4U, result.size()); |
| 646 EXPECT_EQ("http://c/", result.match_at(0)->destination_url.spec()); |
| 647 EXPECT_EQ("http://a/", result.match_at(1)->destination_url.spec()); |
| 648 EXPECT_EQ("http://b/", result.match_at(2)->destination_url.spec()); |
| 649 EXPECT_EQ("http://d/", result.match_at(3)->destination_url.spec()); |
| 650 } |
| 651 |
| 652 { |
| 653 // Try another complicated situation. |
| 654 ACMatches matches; |
| 655 PopulateAutocompleteMatches(data, arraysize(data), &matches); |
| 656 matches[0].inline_autocompletion = base::ASCIIToUTF16("completion"); |
| 657 matches[1].allowed_to_be_default_match = false; |
| 658 AutocompleteResult result; |
| 659 result.AppendMatches(matches); |
| 660 AutocompleteInput input(base::string16(), base::string16::npos, |
| 661 base::string16(), GURL(), |
| 662 AutocompleteInput::HOME_PAGE, false, false, false, |
| 663 true); |
| 664 result.SortAndCull(input, test_util_.profile()); |
| 665 ASSERT_EQ(4U, result.size()); |
| 666 EXPECT_EQ("http://c/", result.match_at(0)->destination_url.spec()); |
| 667 EXPECT_EQ("http://a/", result.match_at(1)->destination_url.spec()); |
| 668 EXPECT_EQ("http://b/", result.match_at(2)->destination_url.spec()); |
| 669 EXPECT_EQ("http://d/", result.match_at(3)->destination_url.spec()); |
| 670 } |
| 671 |
| 672 { |
| 673 // Check that disaster doesn't strike if we can't demote the top inline |
| 674 // autocompletion because every match either has a completion or isn't |
| 675 // allowed to be the default match. In this case, we should leave |
| 676 // everything untouched. |
| 677 ACMatches matches; |
| 678 PopulateAutocompleteMatches(data, arraysize(data), &matches); |
| 679 matches[0].inline_autocompletion = base::ASCIIToUTF16("completion"); |
| 680 matches[1].allowed_to_be_default_match = false; |
| 681 matches[2].allowed_to_be_default_match = false; |
| 682 matches[3].inline_autocompletion = base::ASCIIToUTF16("completion"); |
| 683 AutocompleteResult result; |
| 684 result.AppendMatches(matches); |
| 685 AutocompleteInput input(base::string16(), base::string16::npos, |
| 686 base::string16(), GURL(), |
| 687 AutocompleteInput::HOME_PAGE, false, false, false, |
| 688 true); |
| 689 result.SortAndCull(input, test_util_.profile()); |
| 690 AssertResultMatches(result, data, 4); |
| 691 } |
| 692 |
| 693 { |
| 694 // Check a similar situation, except in this case the top match is not |
| 695 // allowed to the default match, so it still needs to be demoted so we |
| 696 // get a legal default match first. That match will have an inline |
| 697 // autocompletion because we don't have any better options. |
| 698 ACMatches matches; |
| 699 PopulateAutocompleteMatches(data, arraysize(data), &matches); |
| 700 matches[0].allowed_to_be_default_match = false; |
| 701 matches[1].inline_autocompletion = base::ASCIIToUTF16("completion"); |
| 702 matches[2].allowed_to_be_default_match = false; |
| 703 matches[3].inline_autocompletion = base::ASCIIToUTF16("completion"); |
| 704 AutocompleteResult result; |
| 705 result.AppendMatches(matches); |
| 706 AutocompleteInput input(base::string16(), base::string16::npos, |
| 707 base::string16(), GURL(), |
| 708 AutocompleteInput::HOME_PAGE, false, false, false, |
| 709 true); |
| 710 result.SortAndCull(input, test_util_.profile()); |
| 711 ASSERT_EQ(4U, result.size()); |
| 712 EXPECT_EQ("http://b/", result.match_at(0)->destination_url.spec()); |
| 713 EXPECT_EQ("http://a/", result.match_at(1)->destination_url.spec()); |
| 714 EXPECT_EQ("http://c/", result.match_at(2)->destination_url.spec()); |
| 715 EXPECT_EQ("http://d/", result.match_at(3)->destination_url.spec()); |
| 716 } |
| 717 } |
| 718 |
560 TEST_F(AutocompleteResultTest, ShouldHideTopMatch) { | 719 TEST_F(AutocompleteResultTest, ShouldHideTopMatch) { |
561 base::FieldTrialList::CreateFieldTrial("InstantExtended", | 720 base::FieldTrialList::CreateFieldTrial("InstantExtended", |
562 "Group1 hide_verbatim:1"); | 721 "Group1 hide_verbatim:1"); |
563 ACMatches matches; | 722 ACMatches matches; |
564 | 723 |
565 // Case 1: Top match is a verbatim match. | 724 // Case 1: Top match is a verbatim match. |
566 PopulateAutocompleteMatchesFromTestData(kVerbatimMatches, 1, &matches); | 725 PopulateAutocompleteMatchesFromTestData(kVerbatimMatches, 1, &matches); |
567 AutocompleteResult result; | 726 AutocompleteResult result; |
568 result.AppendMatches(matches); | 727 result.AppendMatches(matches); |
569 EXPECT_TRUE(result.ShouldHideTopMatch()); | 728 EXPECT_TRUE(result.ShouldHideTopMatch()); |
(...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
661 result.Reset(); | 820 result.Reset(); |
662 matches.clear(); | 821 matches.clear(); |
663 | 822 |
664 // Case 5: Multiple verbatim matches found in AutocompleteResult. | 823 // Case 5: Multiple verbatim matches found in AutocompleteResult. |
665 PopulateAutocompleteMatchesFromTestData(kVerbatimMatches, | 824 PopulateAutocompleteMatchesFromTestData(kVerbatimMatches, |
666 arraysize(kVerbatimMatches), | 825 arraysize(kVerbatimMatches), |
667 &matches); | 826 &matches); |
668 result.AppendMatches(matches); | 827 result.AppendMatches(matches); |
669 EXPECT_FALSE(result.ShouldHideTopMatch()); | 828 EXPECT_FALSE(result.ShouldHideTopMatch()); |
670 } | 829 } |
OLD | NEW |