OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "components/omnibox/autocomplete_result.h" | 5 #include "components/omnibox/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 628 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
639 AutocompleteResult result; | 639 AutocompleteResult result; |
640 result.AppendMatches(input, matches); | 640 result.AppendMatches(input, matches); |
641 result.SortAndCull(input, template_url_service_.get()); | 641 result.SortAndCull(input, template_url_service_.get()); |
642 ASSERT_EQ(4U, result.size()); | 642 ASSERT_EQ(4U, result.size()); |
643 EXPECT_EQ("http://c/", result.match_at(0)->destination_url.spec()); | 643 EXPECT_EQ("http://c/", result.match_at(0)->destination_url.spec()); |
644 EXPECT_EQ("http://a/", result.match_at(1)->destination_url.spec()); | 644 EXPECT_EQ("http://a/", result.match_at(1)->destination_url.spec()); |
645 EXPECT_EQ("http://b/", result.match_at(2)->destination_url.spec()); | 645 EXPECT_EQ("http://b/", result.match_at(2)->destination_url.spec()); |
646 EXPECT_EQ("http://d/", result.match_at(3)->destination_url.spec()); | 646 EXPECT_EQ("http://d/", result.match_at(3)->destination_url.spec()); |
647 } | 647 } |
648 } | 648 } |
649 | |
650 TEST_F(AutocompleteResultTest, ShouldHideTopMatch) { | |
651 base::FieldTrialList::CreateFieldTrial("InstantExtended", | |
652 "Group1 hide_verbatim:1"); | |
653 ACMatches matches; | |
654 | |
655 // Case 1: Top match is a verbatim match. | |
656 PopulateAutocompleteMatchesFromTestData(kVerbatimMatches, 1, &matches); | |
657 AutocompleteResult result; | |
658 result.AppendMatches(AutocompleteInput(), matches); | |
659 EXPECT_TRUE(result.ShouldHideTopMatch()); | |
660 matches.clear(); | |
661 result.Reset(); | |
662 | |
663 // Case 2: If the verbatim first match is followed by another verbatim match, | |
664 // don't hide the top verbatim match. | |
665 PopulateAutocompleteMatchesFromTestData(kVerbatimMatches, | |
666 arraysize(kVerbatimMatches), | |
667 &matches); | |
668 result.AppendMatches(AutocompleteInput(), matches); | |
669 EXPECT_FALSE(result.ShouldHideTopMatch()); | |
670 matches.clear(); | |
671 result.Reset(); | |
672 | |
673 // Case 3: Top match is not a verbatim match. Do not hide the top match. | |
674 PopulateAutocompleteMatchesFromTestData(kNonVerbatimMatches, 1, &matches); | |
675 PopulateAutocompleteMatchesFromTestData(kVerbatimMatches, | |
676 arraysize(kVerbatimMatches), | |
677 &matches); | |
678 result.AppendMatches(AutocompleteInput(), matches); | |
679 EXPECT_FALSE(result.ShouldHideTopMatch()); | |
680 } | |
681 | |
682 TEST_F(AutocompleteResultTest, ShouldHideTopMatchAfterCopy) { | |
683 base::FieldTrialList::CreateFieldTrial("InstantExtended", | |
684 "Group1 hide_verbatim:1"); | |
685 ACMatches matches; | |
686 | |
687 // Case 1: Top match is a verbatim match followed by only copied matches. | |
688 PopulateAutocompleteMatchesFromTestData(kVerbatimMatches, | |
689 arraysize(kVerbatimMatches), | |
690 &matches); | |
691 for (size_t i = 1; i < arraysize(kVerbatimMatches); ++i) | |
692 matches[i].from_previous = true; | |
693 AutocompleteResult result; | |
694 result.AppendMatches(AutocompleteInput(), matches); | |
695 EXPECT_TRUE(result.ShouldHideTopMatch()); | |
696 result.Reset(); | |
697 | |
698 // Case 2: The copied matches are then followed by a non-verbatim match. | |
699 PopulateAutocompleteMatchesFromTestData(kNonVerbatimMatches, 1, &matches); | |
700 result.AppendMatches(AutocompleteInput(), matches); | |
701 EXPECT_TRUE(result.ShouldHideTopMatch()); | |
702 result.Reset(); | |
703 | |
704 // Case 3: The copied matches are instead followed by a verbatim match. | |
705 matches.back().from_previous = true; | |
706 PopulateAutocompleteMatchesFromTestData(kVerbatimMatches, 1, &matches); | |
707 result.AppendMatches(AutocompleteInput(), matches); | |
708 EXPECT_FALSE(result.ShouldHideTopMatch()); | |
709 } | |
710 | |
711 TEST_F(AutocompleteResultTest, DoNotHideTopMatch_FieldTrialFlagDisabled) { | |
712 // This test config is identical to ShouldHideTopMatch test ("Case 1") except | |
713 // that the "hide_verbatim" flag is disabled in the field trials. | |
714 base::FieldTrialList::CreateFieldTrial("InstantExtended", | |
715 "Group1 hide_verbatim:0"); | |
716 ACMatches matches; | |
717 PopulateAutocompleteMatchesFromTestData(kVerbatimMatches, 1, &matches); | |
718 AutocompleteResult result; | |
719 result.AppendMatches(AutocompleteInput(), matches); | |
720 // Field trial flag "hide_verbatim" is disabled. Do not hide top match. | |
721 EXPECT_FALSE(result.ShouldHideTopMatch()); | |
722 } | |
723 | |
724 TEST_F(AutocompleteResultTest, TopMatchIsStandaloneVerbatimMatch) { | |
725 ACMatches matches; | |
726 AutocompleteResult result; | |
727 result.AppendMatches(AutocompleteInput(), matches); | |
728 | |
729 // Case 1: Result set is empty. | |
730 EXPECT_FALSE(result.TopMatchIsStandaloneVerbatimMatch()); | |
731 | |
732 // Case 2: Top match is not a verbatim match. | |
733 PopulateAutocompleteMatchesFromTestData(kNonVerbatimMatches, 1, &matches); | |
734 result.AppendMatches(AutocompleteInput(), matches); | |
735 EXPECT_FALSE(result.TopMatchIsStandaloneVerbatimMatch()); | |
736 result.Reset(); | |
737 matches.clear(); | |
738 | |
739 // Case 3: Top match is a verbatim match. | |
740 PopulateAutocompleteMatchesFromTestData(kVerbatimMatches, 1, &matches); | |
741 result.AppendMatches(AutocompleteInput(), matches); | |
742 EXPECT_TRUE(result.TopMatchIsStandaloneVerbatimMatch()); | |
743 result.Reset(); | |
744 matches.clear(); | |
745 | |
746 // Case 4: Standalone verbatim match found in AutocompleteResult. | |
747 PopulateAutocompleteMatchesFromTestData(kVerbatimMatches, 1, &matches); | |
748 PopulateAutocompleteMatchesFromTestData(kNonVerbatimMatches, 1, &matches); | |
749 result.AppendMatches(AutocompleteInput(), matches); | |
750 EXPECT_TRUE(result.TopMatchIsStandaloneVerbatimMatch()); | |
751 result.Reset(); | |
752 matches.clear(); | |
753 | |
754 // Case 5: Multiple verbatim matches found in AutocompleteResult. | |
755 PopulateAutocompleteMatchesFromTestData(kVerbatimMatches, | |
756 arraysize(kVerbatimMatches), | |
757 &matches); | |
758 result.AppendMatches(AutocompleteInput(), matches); | |
759 EXPECT_FALSE(result.ShouldHideTopMatch()); | |
760 } | |
OLD | NEW |