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

Side by Side Diff: chrome/browser/autocomplete/search_provider_unittest.cc

Issue 10274023: Omnibox SearchProvider Experiment Client Implementation. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Fixes and cleanup. Created 8 years, 6 months 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 | Annotate | Revision Log
OLDNEW
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/search_provider.h" 5 #include "chrome/browser/autocomplete/search_provider.h"
6 6
7 #include "base/string_util.h" 7 #include "base/string_util.h"
8 #include "base/time.h" 8 #include "base/time.h"
9 #include "base/utf_string_conversions.h" 9 #include "base/utf_string_conversions.h"
10 #include "build/build_config.h" 10 #include "build/build_config.h"
(...skipping 698 matching lines...) Expand 10 before | Expand all | Expand 10 after
709 EXPECT_TRUE(FindMatchWithContents(ASCIIToUTF16("a"), &verbatim)); 709 EXPECT_TRUE(FindMatchWithContents(ASCIIToUTF16("a"), &verbatim));
710 EXPECT_TRUE(FindMatchWithContents(ASCIIToUTF16("a1"), &match_a1)); 710 EXPECT_TRUE(FindMatchWithContents(ASCIIToUTF16("a1"), &match_a1));
711 EXPECT_TRUE(FindMatchWithContents(ASCIIToUTF16("a2"), &match_a2)); 711 EXPECT_TRUE(FindMatchWithContents(ASCIIToUTF16("a2"), &match_a2));
712 EXPECT_TRUE(FindMatchWithContents(ASCIIToUTF16("a3"), &match_a3)); 712 EXPECT_TRUE(FindMatchWithContents(ASCIIToUTF16("a3"), &match_a3));
713 EXPECT_FALSE(FindMatchWithContents(ASCIIToUTF16("a4"), &match_a4)); 713 EXPECT_FALSE(FindMatchWithContents(ASCIIToUTF16("a4"), &match_a4));
714 EXPECT_GT(verbatim.relevance, match_a1.relevance); 714 EXPECT_GT(verbatim.relevance, match_a1.relevance);
715 EXPECT_GT(match_a1.relevance, match_a2.relevance); 715 EXPECT_GT(match_a1.relevance, match_a2.relevance);
716 EXPECT_GT(match_a2.relevance, match_a3.relevance); 716 EXPECT_GT(match_a2.relevance, match_a3.relevance);
717 } 717 }
718 718
719 // Verifies that suggest experiment results are added properly.
720 TEST_F(SearchProviderTest, SuggestRelevanceExperiment) {
721 const std::string kNotApplicable("Not Applicable");
722 struct {
723 const std::string input;
724 const std::string json;
725 const std::string matches[4];
726 } cases[] = {
727 // Ensure that suggestrelevance scores reorder matches.
728 { "a", "[\"a\",[\"b\", \"c\"],[],[],{\"google:suggestrelevance\":[1, 2]}]",
729 { "a", "c", "b", kNotApplicable } },
730 { "a", "[\"a\",[\"http://b.com\", \"http://c.com\"],[],[],"
731 "{\"google:suggesttype\":[\"NAVIGATION\", \"NAVIGATION\"],"
732 "\"google:suggestrelevance\":[1, 2]}]",
733 { "a", "c.com", kNotApplicable, kNotApplicable } },
734
735 // Ensure that verbatimrelevance scores reorder or suppress what-you-typed.
736 { "a", "[\"a\",[\"a1\"],[],[],{\"google:verbatimrelevance\":1}]",
737 { "a1", "a", kNotApplicable, kNotApplicable } },
738 { "a", "[\"a\",[\"a1\"],[],[],{\"google:verbatimrelevance\":0}]",
739 { "a1", kNotApplicable, kNotApplicable, kNotApplicable } },
740 { "a", "[\"a\",[\"a1\"],[],[],{\"google:verbatimrelevance\":-1}]",
741 { "a1", kNotApplicable, kNotApplicable, kNotApplicable } },
742 { "a", "[\"a\",[\"http://a.com\"],[],[],"
743 "{\"google:suggesttype\":[\"NAVIGATION\"],"
744 "\"google:verbatimrelevance\":1}]",
745 { "a.com", "a", kNotApplicable, kNotApplicable } },
746 { "a", "[\"a\",[\"http://a.com\"],[],[],"
747 "{\"google:suggesttype\":[\"NAVIGATION\"],"
748 "\"google:verbatimrelevance\":0}]",
749 { "a.com", kNotApplicable, kNotApplicable, kNotApplicable } },
750 { "a", "[\"a\",[\"http://a.com\"],[],[],"
751 "{\"google:suggesttype\":[\"NAVIGATION\"],"
752 "\"google:verbatimrelevance\":-1}]",
753 { "a.com", kNotApplicable, kNotApplicable, kNotApplicable } },
754
755 // Ensure that both types of relevance scores reorder matches together.
756 { "a", "[\"a\",[\"a1\", \"a2\"],[],[],{\"google:suggestrelevance\":[3, 1],"
757 "\"google:verbatimrelevance\":2}]",
758 { "a1", "a", "a2", kNotApplicable } },
759
760 // Ensure that only inlinable matches may be ranked as the highest result.
761 // If the server suggests relevance scores that violate this constraint,
762 // then all other matches are ranked lower than the what-you-typed result.
763 { "a", "[\"a\",[\"b\"],[],[],{\"google:verbatimrelevance\":0}]",
764 { "a", "b", kNotApplicable, kNotApplicable } },
765 { "a", "[\"a\",[\"b\"],[],[],{\"google:suggestrelevance\":[9999]}]",
766 { "a", "b", kNotApplicable, kNotApplicable } },
767 { "a", "[\"a\",[\"b\"],[],[],{\"google:suggestrelevance\":[9999],"
768 "\"google:verbatimrelevance\":0}]",
769 { "a", "b", kNotApplicable, kNotApplicable } },
770 { "a", "[\"a\",[\"http://b.com\"],[],[],"
771 "{\"google:suggesttype\":[\"NAVIGATION\"],"
772 "\"google:verbatimrelevance\":0}]",
773 { "a", "b.com", kNotApplicable, kNotApplicable } },
774 { "a", "[\"a\",[\"http://b.com\"],[],[],"
775 "{\"google:suggesttype\":[\"NAVIGATION\"],"
776 "\"google:suggestrelevance\":[9999]}]",
777 { "a", "b.com", kNotApplicable, kNotApplicable } },
778 { "a", "[\"a\",[\"http://b.com\"],[],[],"
779 "{\"google:suggesttype\":[\"NAVIGATION\"],"
780 "\"google:suggestrelevance\":[9999],"
781 "\"google:verbatimrelevance\":0}]",
782 { "a", "b.com", kNotApplicable, kNotApplicable } },
783
784 // Ensure that all suggestions are considered, regardless of order.
785 { "a", "[\"a\",[\"b\", \"c\", \"d\", \"e\", \"f\", \"g\", \"h\"],[],[],"
786 "{\"google:suggestrelevance\":[1, 2, 3, 4, 5, 6, 7]}]",
787 { "a", "h", "g", "f" } },
788 { "a", "[\"a\",[\"http://b.com\", \"http://c.com\", \"http://d.com\","
789 "\"http://e.com\", \"http://f.com\", \"http://g.com\","
790 "\"http://h.com\"],[],[],"
791 "{\"google:suggesttype\":[\"NAVIGATION\", \"NAVIGATION\","
792 "\"NAVIGATION\", \"NAVIGATION\","
793 "\"NAVIGATION\", \"NAVIGATION\","
794 "\"NAVIGATION\"],"
795 "\"google:suggestrelevance\":[1, 2, 3, 4, 5, 6, 7]}]",
796 { "a", "h.com", kNotApplicable, kNotApplicable } },
797
798 // Ensure that incorrectly sized suggestion relevance lists are ignored.
799 { "a", "[\"a\",[\"a1\", \"a2\"],[],[],{\"google:suggestrelevance\":[1]}]",
800 { "a", "a1", "a2", kNotApplicable } },
801 { "a", "[\"a\",[\"a1\"],[],[],{\"google:suggestrelevance\":[9999, 1]}]",
802 { "a", "a1", kNotApplicable, kNotApplicable } },
803 { "a", "[\"a\",[\"http://a1.com\", \"http://a2.com\"],[],[],"
804 "{\"google:suggesttype\":[\"NAVIGATION\", \"NAVIGATION\"],"
805 "\"google:suggestrelevance\":[1]}]",
806 { "a", "a1.com", kNotApplicable, kNotApplicable } },
807 { "a", "[\"a\",[\"http://a1.com\"],[],[],"
808 "{\"google:suggesttype\":[\"NAVIGATION\"],"
809 "\"google:suggestrelevance\":[9999, 1]}]",
810 { "a", "a1.com", kNotApplicable, kNotApplicable } },
811 };
812
813 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(cases); i++) {
814 QueryForInput(ASCIIToUTF16(cases[i].input), false);
815 TestURLFetcher* fetcher = test_factory_.GetFetcherByID(
816 SearchProvider::kDefaultProviderURLFetcherID);
817 fetcher->set_response_code(200);
818 fetcher->SetResponseString(cases[i].json);
819 fetcher->delegate()->OnURLFetchComplete(fetcher);
820 RunTillProviderDone();
821
822 const ACMatches& matches = provider_->matches();
823 EXPECT_NE(string16::npos, matches[0].inline_autocomplete_offset);
824
825 size_t j = 0;
826 // Ensure that the supplied matches equal the expectations.
827 for (; j < matches.size(); ++j)
828 EXPECT_EQ(ASCIIToUTF16(cases[i].matches[j]), matches[j].contents);
829 // Ensure that no expected matches are missing.
830 for (; j < ARRAYSIZE_UNSAFE(cases[i].matches); ++j)
831 EXPECT_EQ(kNotApplicable, cases[i].matches[j]);
832 }
833 }
834
719 // Verifies inline autocompletion of navigational results. 835 // Verifies inline autocompletion of navigational results.
720 TEST_F(SearchProviderTest, NavigationInline) { 836 TEST_F(SearchProviderTest, NavigationInline) {
721 struct { 837 struct {
722 const std::string input; 838 const std::string input;
723 const std::string url; 839 const std::string url;
724 // Test the expected fill_into_edit, which may drop "http://". 840 // Test the expected fill_into_edit, which may drop "http://".
725 // Some cases will not trim "http://" because "www." is not a valid prefix. 841 // Some cases do not trim "http://" to match from the start of the scheme.
726 const std::string fill_into_edit; 842 const std::string fill_into_edit;
727 size_t inline_offset; 843 size_t inline_offset;
728 } cases[] = { 844 } cases[] = {
729 // Do not inline matches that do not contain the input; trim http as needed. 845 // Do not inline matches that do not contain the input; trim http as needed.
730 { "x", "http://www.abc.com", 846 { "x", "http://www.abc.com",
731 "www.abc.com", string16::npos }, 847 "www.abc.com", string16::npos },
732 { "https:", "http://www.abc.com", 848 { "https:", "http://www.abc.com",
733 "www.abc.com", string16::npos }, 849 "www.abc.com", string16::npos },
734 { "abc.com/", "http://www.abc.com", 850 { "abc.com/", "http://www.abc.com",
735 "www.abc.com", string16::npos }, 851 "www.abc.com", string16::npos },
(...skipping 157 matching lines...) Expand 10 before | Expand all | Expand 10 after
893 EXPECT_EQ(AutocompleteMatch::ACMatchClassification::URL, 1009 EXPECT_EQ(AutocompleteMatch::ACMatchClassification::URL,
894 match.contents_class[0].style); 1010 match.contents_class[0].style);
895 EXPECT_EQ(4U, match.contents_class[1].offset); 1011 EXPECT_EQ(4U, match.contents_class[1].offset);
896 EXPECT_EQ(AutocompleteMatch::ACMatchClassification::URL | 1012 EXPECT_EQ(AutocompleteMatch::ACMatchClassification::URL |
897 AutocompleteMatch::ACMatchClassification::MATCH, 1013 AutocompleteMatch::ACMatchClassification::MATCH,
898 match.contents_class[1].style); 1014 match.contents_class[1].style);
899 EXPECT_EQ(5U, match.contents_class[2].offset); 1015 EXPECT_EQ(5U, match.contents_class[2].offset);
900 EXPECT_EQ(AutocompleteMatch::ACMatchClassification::URL, 1016 EXPECT_EQ(AutocompleteMatch::ACMatchClassification::URL,
901 match.contents_class[2].style); 1017 match.contents_class[2].style);
902 } 1018 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698