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

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

Issue 12090006: Omnibox: Create Keyword Verbatim Result in Search Provider (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: more extension cleanup Created 7 years, 10 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 "base/message_loop.h" 5 #include "base/message_loop.h"
6 #include "base/utf_string_conversions.h" 6 #include "base/utf_string_conversions.h"
7 #include "chrome/browser/autocomplete/autocomplete_match.h" 7 #include "chrome/browser/autocomplete/autocomplete_match.h"
8 #include "chrome/browser/autocomplete/keyword_provider.h" 8 #include "chrome/browser/autocomplete/keyword_provider.h"
9 #include "chrome/browser/search_engines/template_url.h" 9 #include "chrome/browser/search_engines/template_url.h"
10 #include "chrome/browser/search_engines/template_url_service.h" 10 #include "chrome/browser/search_engines/template_url_service.h"
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after
81 } 81 }
82 82
83 TEST_F(KeywordProviderTest, Edit) { 83 TEST_F(KeywordProviderTest, Edit) {
84 test_data<string16> edit_cases[] = { 84 test_data<string16> edit_cases[] = {
85 // Searching for a nonexistent prefix should give nothing. 85 // Searching for a nonexistent prefix should give nothing.
86 {ASCIIToUTF16("Not Found"), 0, {}}, 86 {ASCIIToUTF16("Not Found"), 0, {}},
87 {ASCIIToUTF16("aaaaaNot Found"), 0, {}}, 87 {ASCIIToUTF16("aaaaaNot Found"), 0, {}},
88 88
89 // Check that tokenization only collapses whitespace between first tokens, 89 // Check that tokenization only collapses whitespace between first tokens,
90 // no-query-input cases have a space appended, and action is not escaped. 90 // no-query-input cases have a space appended, and action is not escaped.
91 {ASCIIToUTF16("z foo"), 1, {ASCIIToUTF16("z foo")}},
92 {ASCIIToUTF16("z"), 1, {ASCIIToUTF16("z ")}}, 91 {ASCIIToUTF16("z"), 1, {ASCIIToUTF16("z ")}},
93 {ASCIIToUTF16("z \t"), 1, {ASCIIToUTF16("z ")}}, 92 {ASCIIToUTF16("z \t"), 1, {ASCIIToUTF16("z ")}},
94 {ASCIIToUTF16("z a b c++"), 1, {ASCIIToUTF16("z a b c++")}}, 93
94 // Check that exact, substituting keywords with a verbatim search term
95 // don't generate a result. (These are handled by SearchProvider.)
96 {ASCIIToUTF16("z foo"), 0, {}},
97 {ASCIIToUTF16("z a b c++"), 0, {}},
95 98
96 // Matches should be limited to three, and sorted in quality order, not 99 // Matches should be limited to three, and sorted in quality order, not
97 // alphabetical. 100 // alphabetical.
98 {ASCIIToUTF16("aaa"), 2, {ASCIIToUTF16("aaaa "), 101 {ASCIIToUTF16("aaa"), 2, {ASCIIToUTF16("aaaa "),
99 ASCIIToUTF16("aaaaa ")}}, 102 ASCIIToUTF16("aaaaa ")}},
100 {ASCIIToUTF16("a 1 2 3"), 3, {ASCIIToUTF16("aa 1 2 3"), 103 {ASCIIToUTF16("a 1 2 3"), 3, {ASCIIToUTF16("aa 1 2 3"),
101 ASCIIToUTF16("ab 1 2 3"), 104 ASCIIToUTF16("ab 1 2 3"),
102 ASCIIToUTF16("aaaa 1 2 3")}}, 105 ASCIIToUTF16("aaaa 1 2 3")}},
103 {ASCIIToUTF16("www.a"), 3, {ASCIIToUTF16("aa "), 106 {ASCIIToUTF16("www.a"), 3, {ASCIIToUTF16("aa "),
104 ASCIIToUTF16("ab "), 107 ASCIIToUTF16("ab "),
105 ASCIIToUTF16("aaaa ")}}, 108 ASCIIToUTF16("aaaa ")}},
106 // Exact matches should prevent returning inexact matches. 109 // Exact matches should prevent returning inexact matches.
107 {ASCIIToUTF16("aaaa foo"), 1, {ASCIIToUTF16("aaaa foo")}}, 110 {ASCIIToUTF16("aaaa foo"), 0, {}},
108 {ASCIIToUTF16("www.aaaa foo"), 1, {ASCIIToUTF16("aaaa foo")}}, 111 {ASCIIToUTF16("www.aaaa foo"), 0, {}},
109 112
110 // Clean up keyword input properly. "http" and "https" are the only 113 // Clean up keyword input properly. "http" and "https" are the only
111 // allowed schemes. 114 // allowed schemes.
112 {ASCIIToUTF16("www"), 1, {ASCIIToUTF16("www ")}}, 115 {ASCIIToUTF16("www"), 1, {ASCIIToUTF16("www ")}},
113 {ASCIIToUTF16("www."), 0, {}}, 116 {ASCIIToUTF16("www."), 0, {}},
114 {ASCIIToUTF16("www.w w"), 2, {ASCIIToUTF16("www w"), 117 {ASCIIToUTF16("www.w w"), 2, {ASCIIToUTF16("www w"),
115 ASCIIToUTF16("weasel w")}}, 118 ASCIIToUTF16("weasel w")}},
116 {ASCIIToUTF16("http://www"), 1, {ASCIIToUTF16("www ")}}, 119 {ASCIIToUTF16("http://www"), 1, {ASCIIToUTF16("www ")}},
117 {ASCIIToUTF16("http://www."), 0, {}}, 120 {ASCIIToUTF16("http://www."), 0, {}},
118 {ASCIIToUTF16("ftp: blah"), 0, {}}, 121 {ASCIIToUTF16("ftp: blah"), 0, {}},
119 {ASCIIToUTF16("mailto:z"), 0, {}}, 122 {ASCIIToUTF16("mailto:z"), 0, {}},
120 {ASCIIToUTF16("ftp://z"), 0, {}}, 123 {ASCIIToUTF16("ftp://z"), 0, {}},
121 {ASCIIToUTF16("https://z"), 1, {ASCIIToUTF16("z ")}}, 124 {ASCIIToUTF16("https://z"), 1, {ASCIIToUTF16("z ")}},
122 }; 125 };
123 126
124 RunTest<string16>(edit_cases, arraysize(edit_cases), 127 RunTest<string16>(edit_cases, arraysize(edit_cases),
125 &AutocompleteMatch::fill_into_edit); 128 &AutocompleteMatch::fill_into_edit);
126 } 129 }
127 130
128 TEST_F(KeywordProviderTest, URL) { 131 TEST_F(KeywordProviderTest, URL) {
129 test_data<GURL> url_cases[] = { 132 test_data<GURL> url_cases[] = {
130 // No query input -> empty destination URL. 133 // No query input -> empty destination URL.
131 {ASCIIToUTF16("z"), 1, {GURL()}}, 134 {ASCIIToUTF16("z"), 1, {GURL()}},
132 {ASCIIToUTF16("z \t"), 1, {GURL()}}, 135 {ASCIIToUTF16("z \t"), 1, {GURL()}},
133 136
134 // Check that tokenization only collapses whitespace between first tokens 137 // Check that tokenization only collapses whitespace between first tokens
135 // and query input, but not rest of URL, is escaped. 138 // and query input, but not rest of URL, is escaped.
136 {ASCIIToUTF16("z a b c++"), 1, {GURL("a+++b+++c%2B%2B=z")}}, 139 // {ASCIIToUTF16("z a b c++"), 1, {GURL("a+++b+++c%2B%2B=z")}},
137 {ASCIIToUTF16("www.www www"), 1, {GURL(" +%2B?=wwwfoo ")}}, 140 {ASCIIToUTF16("w bar +baz"), 2, {GURL(" +%2B?=bar+%2Bbazfoo "),
141 GURL("bar+%2Bbaz=z")}},
138 142
139 // Substitution should work with various locations of the "%s". 143 // Substitution should work with various locations of the "%s".
140 {ASCIIToUTF16("aaa 1a2b"), 2, {GURL("http://aaaa/?aaaa=1&b=1a2b&c"), 144 {ASCIIToUTF16("aaa 1a2b"), 2, {GURL("http://aaaa/?aaaa=1&b=1a2b&c"),
141 GURL("1a2b")}}, 145 GURL("1a2b")}},
142 {ASCIIToUTF16("a 1 2 3"), 3, {GURL("aa.com?foo=1+2+3"), 146 {ASCIIToUTF16("a 1 2 3"), 3, {GURL("aa.com?foo=1+2+3"),
143 GURL("bogus URL 1+2+3"), 147 GURL("bogus URL 1+2+3"),
144 GURL("http://aaaa/?aaaa=1&b=1+2+3&c")}}, 148 GURL("http://aaaa/?aaaa=1&b=1+2+3&c")}},
145 {ASCIIToUTF16("www.w w"), 2, {GURL(" +%2B?=wfoo "), 149 {ASCIIToUTF16("www.w w"), 2, {GURL(" +%2B?=wfoo "),
146 GURL("weaselwweasel")}}, 150 GURL("weaselwweasel")}},
147 }; 151 };
148 152
149 RunTest<GURL>(url_cases, arraysize(url_cases), 153 RunTest<GURL>(url_cases, arraysize(url_cases),
150 &AutocompleteMatch::destination_url); 154 &AutocompleteMatch::destination_url);
151 } 155 }
152 156
153 TEST_F(KeywordProviderTest, Contents) { 157 TEST_F(KeywordProviderTest, Contents) {
154 test_data<string16> contents_cases[] = { 158 test_data<string16> contents_cases[] = {
155 // No query input -> substitute "<enter query>" into contents. 159 // No query input -> substitute "<enter query>" into contents.
156 {ASCIIToUTF16("z"), 1, 160 {ASCIIToUTF16("z"), 1,
157 {ASCIIToUTF16("Search z for <enter query>")}}, 161 {ASCIIToUTF16("Search z for <enter query>")}},
158 {ASCIIToUTF16("z \t"), 1, 162 {ASCIIToUTF16("z \t"), 1,
159 {ASCIIToUTF16("Search z for <enter query>")}}, 163 {ASCIIToUTF16("Search z for <enter query>")}},
160 164
161 // Check that tokenization only collapses whitespace between first tokens 165 // Exact keyword matches with remaining text should return nothing.
Bart N. 2013/01/29 18:50:42 Can you add a unit test for non empty remaining te
Bart N. 2013/01/29 21:48:35 This may help: http://build.chromium.org/f/chromiu
Mark P 2013/01/30 19:46:21 Acknowledged.
Mark P 2013/01/30 19:46:21 Good question. I re-enabled a test in chrome/brow
162 // and contents are not escaped or unescaped. 166 {ASCIIToUTF16("www.www www"), 0, {}},
163 {ASCIIToUTF16("z a b c++"), 1, 167 {ASCIIToUTF16("z a b c++"), 0, {}},
164 {ASCIIToUTF16("Search z for a b c++")}},
165 {ASCIIToUTF16("www.www www"), 1, {ASCIIToUTF16("Search www for www")}},
166 168
167 // Substitution should work with various locations of the "%s". 169 // Substitution should work with various locations of the "%s".
168 {ASCIIToUTF16("aaa"), 2, 170 {ASCIIToUTF16("aaa"), 2,
169 {ASCIIToUTF16("Search aaaa for <enter query>"), 171 {ASCIIToUTF16("Search aaaa for <enter query>"),
170 ASCIIToUTF16("Search aaaaa for <enter query>")}}, 172 ASCIIToUTF16("Search aaaaa for <enter query>")}},
171 {ASCIIToUTF16("a 1 2 3"), 3, {ASCIIToUTF16("Search aa for 1 2 3"),
172 ASCIIToUTF16("Search ab for 1 2 3"),
173 ASCIIToUTF16("Search aaaa for 1 2 3")}},
174 {ASCIIToUTF16("www.w w"), 2, {ASCIIToUTF16("Search www for w"), 173 {ASCIIToUTF16("www.w w"), 2, {ASCIIToUTF16("Search www for w"),
175 ASCIIToUTF16("Search weasel for w")}}, 174 ASCIIToUTF16("Search weasel for w")}},
175 // Also, check that tokenization only collapses whitespace between first
176 // tokens and contents are not escaped or unescaped.
177 {ASCIIToUTF16("a 1 2+ 3"), 3, {ASCIIToUTF16("Search aa for 1 2+ 3"),
178 ASCIIToUTF16("Search ab for 1 2+ 3"),
179 ASCIIToUTF16("Search aaaa for 1 2+ 3")}},
176 }; 180 };
177 181
178 RunTest<string16>(contents_cases, arraysize(contents_cases), 182 RunTest<string16>(contents_cases, arraysize(contents_cases),
179 &AutocompleteMatch::contents); 183 &AutocompleteMatch::contents);
180 } 184 }
181 185
182 TEST_F(KeywordProviderTest, DISABLED_Description) { 186 TEST_F(KeywordProviderTest, DISABLED_Description) {
183 test_data<string16> description_cases[] = { 187 test_data<string16> description_cases[] = {
184 // Whole keyword should be returned for both exact and inexact matches. 188 // Whole keyword should be returned for both exact and inexact matches.
185 {ASCIIToUTF16("z foo"), 1, {ASCIIToUTF16("(Keyword: z)")}}, 189 {ASCIIToUTF16("z foo"), 1, {ASCIIToUTF16("(Keyword: z)")}},
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
217 } 221 }
218 222
219 TEST_F(KeywordProviderTest, GetKeywordForInput) { 223 TEST_F(KeywordProviderTest, GetKeywordForInput) {
220 EXPECT_EQ(ASCIIToUTF16("aa"), 224 EXPECT_EQ(ASCIIToUTF16("aa"),
221 kw_provider_->GetKeywordForText(ASCIIToUTF16("aa"))); 225 kw_provider_->GetKeywordForText(ASCIIToUTF16("aa")));
222 EXPECT_EQ(string16(), 226 EXPECT_EQ(string16(),
223 kw_provider_->GetKeywordForText(ASCIIToUTF16("aafoo"))); 227 kw_provider_->GetKeywordForText(ASCIIToUTF16("aafoo")));
224 EXPECT_EQ(string16(), 228 EXPECT_EQ(string16(),
225 kw_provider_->GetKeywordForText(ASCIIToUTF16("aa foo"))); 229 kw_provider_->GetKeywordForText(ASCIIToUTF16("aa foo")));
226 } 230 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698