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

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

Issue 18119005: Misc. cleanup: (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: Created 7 years, 5 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/strings/utf_string_conversions.h" 6 #include "base/strings/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 116 matching lines...) Expand 10 before | Expand all | Expand 10 after
127 {ASCIIToUTF16("https://z"), 1, {ASCIIToUTF16("z ")}}, 127 {ASCIIToUTF16("https://z"), 1, {ASCIIToUTF16("z ")}},
128 }; 128 };
129 129
130 RunTest<string16>(edit_cases, arraysize(edit_cases), 130 RunTest<string16>(edit_cases, arraysize(edit_cases),
131 &AutocompleteMatch::fill_into_edit); 131 &AutocompleteMatch::fill_into_edit);
132 } 132 }
133 133
134 TEST_F(KeywordProviderTest, URL) { 134 TEST_F(KeywordProviderTest, URL) {
135 test_data<GURL> url_cases[] = { 135 test_data<GURL> url_cases[] = {
136 // No query input -> empty destination URL. 136 // No query input -> empty destination URL.
137 {ASCIIToUTF16("z"), 1, {GURL()}}, 137 {ASCIIToUTF16("z"), 1, {GURL()}},
138 {ASCIIToUTF16("z \t"), 1, {GURL()}}, 138 {ASCIIToUTF16("z \t"), 1, {GURL()}},
139 139
140 // Check that tokenization only collapses whitespace between first tokens 140 // Check that tokenization only collapses whitespace between first tokens
141 // and query input, but not rest of URL, is escaped. 141 // and query input, but not rest of URL, is escaped.
142 {ASCIIToUTF16("w bar +baz"), 2, {GURL(" +%2B?=bar+%2Bbazfoo "), 142 {ASCIIToUTF16("w bar +baz"), 2, {GURL(" +%2B?=bar+%2Bbazfoo "),
143 GURL("bar+%2Bbaz=z")}}, 143 GURL("bar+%2Bbaz=z")}},
144 144
145 // Substitution should work with various locations of the "%s". 145 // Substitution should work with various locations of the "%s".
146 {ASCIIToUTF16("aaa 1a2b"), 2, {GURL("http://aaaa/?aaaa=1&b=1a2b&c"), 146 {ASCIIToUTF16("aaa 1a2b"), 2, {GURL("http://aaaa/?aaaa=1&b=1a2b&c"),
147 GURL("1a2b")}}, 147 GURL("1a2b")}},
148 {ASCIIToUTF16("a 1 2 3"), 3, {GURL("aa.com?foo=1+2+3"), 148 {ASCIIToUTF16("a 1 2 3"), 3, {GURL("aa.com?foo=1+2+3"),
149 GURL("bogus URL 1+2+3"), 149 GURL("bogus URL 1+2+3"),
150 GURL("http://aaaa/?aaaa=1&b=1+2+3&c")}}, 150 GURL("http://aaaa/?aaaa=1&b=1+2+3&c")}},
151 {ASCIIToUTF16("www.w w"), 2, {GURL(" +%2B?=wfoo "), 151 {ASCIIToUTF16("www.w w"), 2, {GURL(" +%2B?=wfoo "),
152 GURL("weaselwweasel")}}, 152 GURL("weaselwweasel")}},
153 }; 153 };
154 154
155 RunTest<GURL>(url_cases, arraysize(url_cases), 155 RunTest<GURL>(url_cases, arraysize(url_cases),
156 &AutocompleteMatch::destination_url); 156 &AutocompleteMatch::destination_url);
157 } 157 }
158 158
159 TEST_F(KeywordProviderTest, Contents) { 159 TEST_F(KeywordProviderTest, Contents) {
160 test_data<string16> contents_cases[] = { 160 test_data<string16> contents_cases[] = {
161 // No query input -> substitute "<enter query>" into contents. 161 // No query input -> substitute "<enter query>" into contents.
162 {ASCIIToUTF16("z"), 1, 162 {ASCIIToUTF16("z"), 1,
(...skipping 22 matching lines...) Expand all
185 {ASCIIToUTF16("a 1 2+ 3"), 3, 185 {ASCIIToUTF16("a 1 2+ 3"), 3,
186 {ASCIIToUTF16("Search aa for 1 2+ 3"), 186 {ASCIIToUTF16("Search aa for 1 2+ 3"),
187 ASCIIToUTF16("Search ab for 1 2+ 3"), 187 ASCIIToUTF16("Search ab for 1 2+ 3"),
188 ASCIIToUTF16("Search aaaa for 1 2+ 3")}}, 188 ASCIIToUTF16("Search aaaa for 1 2+ 3")}},
189 }; 189 };
190 190
191 RunTest<string16>(contents_cases, arraysize(contents_cases), 191 RunTest<string16>(contents_cases, arraysize(contents_cases),
192 &AutocompleteMatch::contents); 192 &AutocompleteMatch::contents);
193 } 193 }
194 194
195 TEST_F(KeywordProviderTest, DISABLED_Description) {
196 test_data<string16> description_cases[] = {
197 // Whole keyword should be returned for both exact and inexact matches.
198 {ASCIIToUTF16("z foo"), 1, {ASCIIToUTF16("(Keyword: z)")}},
199 {ASCIIToUTF16("a foo"), 3, {ASCIIToUTF16("(Keyword: aa)"),
200 ASCIIToUTF16("(Keyword: ab)"),
201 ASCIIToUTF16("(Keyword: aaaa)")}},
202 {ASCIIToUTF16("ftp://www.www w"), 0, {}},
203 {ASCIIToUTF16("http://www.ab w"), 1, {ASCIIToUTF16("(Keyword: ab)")}},
204
205 // Keyword should be returned regardless of query input.
206 {ASCIIToUTF16("z"), 1, {ASCIIToUTF16("(Keyword: z)")}},
207 {ASCIIToUTF16("z \t"), 1, {ASCIIToUTF16("(Keyword: z)")}},
208 {ASCIIToUTF16("z a b c++"), 1, {ASCIIToUTF16("(Keyword: z)")}},
209 };
210
211 RunTest<string16>(description_cases, arraysize(description_cases),
212 &AutocompleteMatch::description);
213 }
214
215 TEST_F(KeywordProviderTest, AddKeyword) { 195 TEST_F(KeywordProviderTest, AddKeyword) {
216 TemplateURLData data; 196 TemplateURLData data;
217 data.short_name = ASCIIToUTF16("Test"); 197 data.short_name = ASCIIToUTF16("Test");
218 string16 keyword(ASCIIToUTF16("foo")); 198 string16 keyword(ASCIIToUTF16("foo"));
219 data.SetKeyword(keyword); 199 data.SetKeyword(keyword);
220 data.SetURL("http://www.google.com/foo?q={searchTerms}"); 200 data.SetURL("http://www.google.com/foo?q={searchTerms}");
221 TemplateURL* template_url = new TemplateURL(NULL, data); 201 TemplateURL* template_url = new TemplateURL(NULL, data);
222 model_->Add(template_url); 202 model_->Add(template_url);
223 ASSERT_TRUE(template_url == model_->GetTemplateURLForKeyword(keyword)); 203 ASSERT_TRUE(template_url == model_->GetTemplateURLForKeyword(keyword));
224 } 204 }
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after
287 KeywordProvider::GetSubstitutingTemplateURLForInput(model_.get(), 267 KeywordProvider::GetSubstitutingTemplateURLForInput(model_.get(),
288 &input); 268 &input);
289 if (cases[i].expected_url.empty()) 269 if (cases[i].expected_url.empty())
290 EXPECT_FALSE(url); 270 EXPECT_FALSE(url);
291 else 271 else
292 EXPECT_EQ(cases[i].expected_url, url->url()); 272 EXPECT_EQ(cases[i].expected_url, url->url());
293 EXPECT_EQ(ASCIIToUTF16(cases[i].updated_text), input.text()); 273 EXPECT_EQ(ASCIIToUTF16(cases[i].updated_text), input.text());
294 EXPECT_EQ(cases[i].updated_cursor_position, input.cursor_position()); 274 EXPECT_EQ(cases[i].updated_cursor_position, input.cursor_position());
295 } 275 }
296 } 276 }
OLDNEW
« no previous file with comments | « chrome/browser/autocomplete/keyword_provider.cc ('k') | chrome/browser/autocomplete/search_provider.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698