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/autocomplete_unittest.cc

Issue 6256010: Revert 72380 - Remove wstring from autocomplete.... (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: Created 9 years, 11 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) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 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/scoped_ptr.h" 6 #include "base/scoped_ptr.h"
7 #include "base/string_number_conversions.h" 7 #include "base/string_number_conversions.h"
8 #include "base/string_util.h" 8 #include "base/string_util.h"
9 #include "base/utf_string_conversions.h" 9 #include "base/utf_string_conversions.h"
10 #include "chrome/browser/autocomplete/autocomplete.h" 10 #include "chrome/browser/autocomplete/autocomplete.h"
11 #include "chrome/browser/autocomplete/autocomplete_match.h" 11 #include "chrome/browser/autocomplete/autocomplete_match.h"
12 #include "chrome/browser/autocomplete/keyword_provider.h" 12 #include "chrome/browser/autocomplete/keyword_provider.h"
13 #include "chrome/browser/autocomplete/search_provider.h" 13 #include "chrome/browser/autocomplete/search_provider.h"
14 #include "chrome/browser/search_engines/template_url.h" 14 #include "chrome/browser/search_engines/template_url.h"
15 #include "chrome/browser/search_engines/template_url_model.h" 15 #include "chrome/browser/search_engines/template_url_model.h"
16 #include "chrome/common/notification_observer.h" 16 #include "chrome/common/notification_observer.h"
17 #include "chrome/common/notification_registrar.h" 17 #include "chrome/common/notification_registrar.h"
18 #include "chrome/common/notification_service.h" 18 #include "chrome/common/notification_service.h"
19 #include "chrome/test/testing_profile.h" 19 #include "chrome/test/testing_profile.h"
20 #include "testing/gtest/include/gtest/gtest.h" 20 #include "testing/gtest/include/gtest/gtest.h"
21 21
22 // identifiers for known autocomplete providers
23 #define HISTORY_IDENTIFIER L"Chrome:History"
24 #define SEARCH_IDENTIFIER L"google.com/websearch/en"
25
22 static std::ostream& operator<<(std::ostream& os, 26 static std::ostream& operator<<(std::ostream& os,
23 const AutocompleteResult::const_iterator& it) { 27 const AutocompleteResult::const_iterator& it) {
24 return os << static_cast<const AutocompleteMatch*>(&(*it)); 28 return os << static_cast<const AutocompleteMatch*>(&(*it));
25 } 29 }
26 30
27 namespace { 31 namespace {
28 32
29 const size_t num_results_per_provider = 3; 33 const size_t num_results_per_provider = 3;
30 34
31 // Autocomplete provider that provides known results. Note that this is 35 // Autocomplete provider that provides known results. Note that this is
32 // refcounted so that it can also be a task on the message loop. 36 // refcounted so that it can also be a task on the message loop.
33 class TestProvider : public AutocompleteProvider { 37 class TestProvider : public AutocompleteProvider {
34 public: 38 public:
35 TestProvider(int relevance, const string16& prefix) 39 TestProvider(int relevance, const std::wstring& prefix)
36 : AutocompleteProvider(NULL, NULL, ""), 40 : AutocompleteProvider(NULL, NULL, ""),
37 relevance_(relevance), 41 relevance_(relevance),
38 prefix_(prefix) { 42 prefix_(prefix) {
39 } 43 }
40 44
41 virtual void Start(const AutocompleteInput& input, 45 virtual void Start(const AutocompleteInput& input,
42 bool minimal_changes); 46 bool minimal_changes);
43 47
44 void set_listener(ACProviderListener* listener) { 48 void set_listener(ACProviderListener* listener) {
45 listener_ = listener; 49 listener_ = listener;
46 } 50 }
47 51
48 private: 52 private:
49 ~TestProvider() {} 53 ~TestProvider() {}
50 54
51 void Run(); 55 void Run();
52 56
53 void AddResults(int start_at, int num); 57 void AddResults(int start_at, int num);
54 58
55 int relevance_; 59 int relevance_;
56 const string16 prefix_; 60 const std::wstring prefix_;
57 }; 61 };
58 62
59 void TestProvider::Start(const AutocompleteInput& input, 63 void TestProvider::Start(const AutocompleteInput& input,
60 bool minimal_changes) { 64 bool minimal_changes) {
61 if (minimal_changes) 65 if (minimal_changes)
62 return; 66 return;
63 67
64 matches_.clear(); 68 matches_.clear();
65 69
66 // Generate one result synchronously, the rest later. 70 // Generate one result synchronously, the rest later.
(...skipping 12 matching lines...) Expand all
79 done_ = true; 83 done_ = true;
80 DCHECK(listener_); 84 DCHECK(listener_);
81 listener_->OnProviderUpdate(true); 85 listener_->OnProviderUpdate(true);
82 } 86 }
83 87
84 void TestProvider::AddResults(int start_at, int num) { 88 void TestProvider::AddResults(int start_at, int num) {
85 for (int i = start_at; i < num; i++) { 89 for (int i = start_at; i < num; i++) {
86 AutocompleteMatch match(this, relevance_ - i, false, 90 AutocompleteMatch match(this, relevance_ - i, false,
87 AutocompleteMatch::URL_WHAT_YOU_TYPED); 91 AutocompleteMatch::URL_WHAT_YOU_TYPED);
88 92
89 match.fill_into_edit = prefix_ + UTF8ToUTF16(base::IntToString(i)); 93 match.fill_into_edit = prefix_ + UTF8ToWide(base::IntToString(i));
90 match.destination_url = GURL(UTF16ToUTF8(match.fill_into_edit)); 94 match.destination_url = GURL(WideToUTF8(match.fill_into_edit));
91 95
92 match.contents = match.fill_into_edit; 96 match.contents = match.fill_into_edit;
93 match.contents_class.push_back( 97 match.contents_class.push_back(
94 ACMatchClassification(0, ACMatchClassification::NONE)); 98 ACMatchClassification(0, ACMatchClassification::NONE));
95 match.description = match.fill_into_edit; 99 match.description = match.fill_into_edit;
96 match.description_class.push_back( 100 match.description_class.push_back(
97 ACMatchClassification(0, ACMatchClassification::NONE)); 101 ACMatchClassification(0, ACMatchClassification::NONE));
98 102
99 matches_.push_back(match); 103 matches_.push_back(match);
100 } 104 }
(...skipping 29 matching lines...) Expand all
130 }; 134 };
131 135
132 void AutocompleteProviderTest::ResetControllerWithTestProviders( 136 void AutocompleteProviderTest::ResetControllerWithTestProviders(
133 bool same_destinations) { 137 bool same_destinations) {
134 // Forget about any existing providers. The controller owns them and will 138 // Forget about any existing providers. The controller owns them and will
135 // Release() them below, when we delete it during the call to reset(). 139 // Release() them below, when we delete it during the call to reset().
136 providers_.clear(); 140 providers_.clear();
137 141
138 // Construct two new providers, with either the same or different prefixes. 142 // Construct two new providers, with either the same or different prefixes.
139 TestProvider* providerA = new TestProvider(num_results_per_provider, 143 TestProvider* providerA = new TestProvider(num_results_per_provider,
140 ASCIIToUTF16("http://a")); 144 L"http://a");
141 providerA->AddRef(); 145 providerA->AddRef();
142 providers_.push_back(providerA); 146 providers_.push_back(providerA);
143 147
144 TestProvider* providerB = new TestProvider(num_results_per_provider * 2, 148 TestProvider* providerB = new TestProvider(num_results_per_provider * 2,
145 same_destinations ? ASCIIToUTF16("http://a") : ASCIIToUTF16("http://b")); 149 same_destinations ? L"http://a" : L"http://b");
146 providerB->AddRef(); 150 providerB->AddRef();
147 providers_.push_back(providerB); 151 providers_.push_back(providerB);
148 152
149 // Reset the controller to contain our new providers. 153 // Reset the controller to contain our new providers.
150 AutocompleteController* controller = new AutocompleteController(providers_); 154 AutocompleteController* controller = new AutocompleteController(providers_);
151 controller_.reset(controller); 155 controller_.reset(controller);
152 providerA->set_listener(controller); 156 providerA->set_listener(controller);
153 providerB->set_listener(controller); 157 providerB->set_listener(controller);
154 158
155 // The providers don't complete synchronously, so listen for "result updated" 159 // The providers don't complete synchronously, so listen for "result updated"
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
192 AutocompleteProvider* search_provider = new SearchProvider(NULL, &profile_); 196 AutocompleteProvider* search_provider = new SearchProvider(NULL, &profile_);
193 search_provider->AddRef(); 197 search_provider->AddRef();
194 providers_.push_back(search_provider); 198 providers_.push_back(search_provider);
195 199
196 AutocompleteController* controller = new AutocompleteController(providers_); 200 AutocompleteController* controller = new AutocompleteController(providers_);
197 controller_.reset(controller); 201 controller_.reset(controller);
198 } 202 }
199 203
200 void AutocompleteProviderTest::RunTest() { 204 void AutocompleteProviderTest::RunTest() {
201 result_.Reset(); 205 result_.Reset();
202 controller_->Start(ASCIIToUTF16("a"), string16(), true, false, true, false); 206 controller_->Start(L"a", std::wstring(), true, false, true, false);
203 207
204 // The message loop will terminate when all autocomplete input has been 208 // The message loop will terminate when all autocomplete input has been
205 // collected. 209 // collected.
206 MessageLoop::current()->Run(); 210 MessageLoop::current()->Run();
207 } 211 }
208 212
209 void AutocompleteProviderTest::RunExactKeymatchTest( 213 void AutocompleteProviderTest::RunExactKeymatchTest(
210 bool allow_exact_keyword_match) { 214 bool allow_exact_keyword_match) {
211 // Send the controller input which exactly matches the keyword provider we 215 // Send the controller input which exactly matches the keyword provider we
212 // created in ResetControllerWithKeywordAndSearchProviders(). The default 216 // created in ResetControllerWithKeywordAndSearchProviders(). The default
213 // match should thus be a keyword match iff |allow_exact_keyword_match| is 217 // match should thus be a keyword match iff |allow_exact_keyword_match| is
214 // true. 218 // true.
215 controller_->Start(ASCIIToUTF16("k test"), string16(), true, false, 219 controller_->Start(L"k test", std::wstring(), true, false,
216 allow_exact_keyword_match, true); 220 allow_exact_keyword_match, true);
217 EXPECT_TRUE(controller_->done()); 221 EXPECT_TRUE(controller_->done());
218 // ResetControllerWithKeywordAndSearchProviders() adds the keyword provider 222 // ResetControllerWithKeywordAndSearchProviders() adds the keyword provider
219 // first, then the search provider. So if the default match is a keyword 223 // first, then the search provider. So if the default match is a keyword
220 // match, it will come from provider 0, otherwise from provider 1. 224 // match, it will come from provider 0, otherwise from provider 1.
221 EXPECT_EQ(providers_[allow_exact_keyword_match ? 0 : 1], 225 EXPECT_EQ(providers_[allow_exact_keyword_match ? 0 : 1],
222 controller_->result().default_match()->provider); 226 controller_->result().default_match()->provider);
223 } 227 }
224 228
225 void AutocompleteProviderTest::Observe(NotificationType type, 229 void AutocompleteProviderTest::Observe(NotificationType type,
(...skipping 30 matching lines...) Expand all
256 } 260 }
257 261
258 TEST_F(AutocompleteProviderTest, AllowExactKeywordMatch) { 262 TEST_F(AutocompleteProviderTest, AllowExactKeywordMatch) {
259 ResetControllerWithTestProvidersWithKeywordAndSearchProviders(); 263 ResetControllerWithTestProvidersWithKeywordAndSearchProviders();
260 RunExactKeymatchTest(true); 264 RunExactKeymatchTest(true);
261 RunExactKeymatchTest(false); 265 RunExactKeymatchTest(false);
262 } 266 }
263 267
264 TEST(AutocompleteTest, InputType) { 268 TEST(AutocompleteTest, InputType) {
265 struct test_data { 269 struct test_data {
266 const string16 input; 270 const wchar_t* input;
267 const AutocompleteInput::Type type; 271 const AutocompleteInput::Type type;
268 } input_cases[] = { 272 } input_cases[] = {
269 { ASCIIToUTF16(""), AutocompleteInput::INVALID }, 273 { L"", AutocompleteInput::INVALID },
270 { ASCIIToUTF16("?"), AutocompleteInput::FORCED_QUERY }, 274 { L"?", AutocompleteInput::FORCED_QUERY },
271 { ASCIIToUTF16("?foo"), AutocompleteInput::FORCED_QUERY }, 275 { L"?foo", AutocompleteInput::FORCED_QUERY },
272 { ASCIIToUTF16("?foo bar"), AutocompleteInput::FORCED_QUERY }, 276 { L"?foo bar", AutocompleteInput::FORCED_QUERY },
273 { ASCIIToUTF16("?http://foo.com/bar"), AutocompleteInput::FORCED_QUERY }, 277 { L"?http://foo.com/bar", AutocompleteInput::FORCED_QUERY },
274 { ASCIIToUTF16("foo"), AutocompleteInput::UNKNOWN }, 278 { L"foo", AutocompleteInput::UNKNOWN },
275 { ASCIIToUTF16("foo.c"), AutocompleteInput::UNKNOWN }, 279 { L"foo.c", AutocompleteInput::UNKNOWN },
276 { ASCIIToUTF16("foo.com"), AutocompleteInput::URL }, 280 { L"foo.com", AutocompleteInput::URL },
277 { ASCIIToUTF16("-.com"), AutocompleteInput::UNKNOWN }, 281 { L"-.com", AutocompleteInput::UNKNOWN },
278 { ASCIIToUTF16("foo/bar"), AutocompleteInput::URL }, 282 { L"foo/bar", AutocompleteInput::URL },
279 { ASCIIToUTF16("foo;bar"), AutocompleteInput::QUERY }, 283 { L"foo;bar", AutocompleteInput::QUERY },
280 { ASCIIToUTF16("foo/bar baz"), AutocompleteInput::UNKNOWN }, 284 { L"foo/bar baz", AutocompleteInput::UNKNOWN },
281 { ASCIIToUTF16("foo bar.com"), AutocompleteInput::QUERY }, 285 { L"foo bar.com", AutocompleteInput::QUERY },
282 { ASCIIToUTF16("foo bar"), AutocompleteInput::QUERY }, 286 { L"foo bar", AutocompleteInput::QUERY },
283 { ASCIIToUTF16("foo+bar"), AutocompleteInput::QUERY }, 287 { L"foo+bar", AutocompleteInput::QUERY },
284 { ASCIIToUTF16("foo+bar.com"), AutocompleteInput::UNKNOWN }, 288 { L"foo+bar.com", AutocompleteInput::UNKNOWN },
285 { ASCIIToUTF16("\"foo:bar\""), AutocompleteInput::QUERY }, 289 { L"\"foo:bar\"", AutocompleteInput::QUERY },
286 { ASCIIToUTF16("link:foo.com"), AutocompleteInput::UNKNOWN }, 290 { L"link:foo.com", AutocompleteInput::UNKNOWN },
287 { ASCIIToUTF16("foo:81"), AutocompleteInput::URL }, 291 { L"foo:81", AutocompleteInput::URL },
288 { ASCIIToUTF16("www.foo.com:81"), AutocompleteInput::URL }, 292 { L"www.foo.com:81", AutocompleteInput::URL },
289 { ASCIIToUTF16("localhost:8080"), AutocompleteInput::URL }, 293 { L"localhost:8080", AutocompleteInput::URL },
290 { ASCIIToUTF16("foo.com:123456"), AutocompleteInput::QUERY }, 294 { L"foo.com:123456", AutocompleteInput::QUERY },
291 { ASCIIToUTF16("foo.com:abc"), AutocompleteInput::QUERY }, 295 { L"foo.com:abc", AutocompleteInput::QUERY },
292 { ASCIIToUTF16("1.2.3.4:abc"), AutocompleteInput::QUERY }, 296 { L"1.2.3.4:abc", AutocompleteInput::QUERY },
293 { ASCIIToUTF16("user@foo.com"), AutocompleteInput::UNKNOWN }, 297 { L"user@foo.com", AutocompleteInput::UNKNOWN },
294 { ASCIIToUTF16("user:pass@"), AutocompleteInput::UNKNOWN }, 298 { L"user:pass@", AutocompleteInput::UNKNOWN },
295 { ASCIIToUTF16("user:pass@!foo.com"), AutocompleteInput::UNKNOWN }, 299 { L"user:pass@!foo.com", AutocompleteInput::UNKNOWN },
296 { ASCIIToUTF16("user:pass@foo"), AutocompleteInput::URL }, 300 { L"user:pass@foo", AutocompleteInput::URL },
297 { ASCIIToUTF16("user:pass@foo.c"), AutocompleteInput::URL }, 301 { L"user:pass@foo.c", AutocompleteInput::URL },
298 { ASCIIToUTF16("user:pass@foo.com"), AutocompleteInput::URL }, 302 { L"user:pass@foo.com", AutocompleteInput::URL },
299 { ASCIIToUTF16("user:pass@foo.com:81"), AutocompleteInput::URL }, 303 { L"user:pass@foo.com:81", AutocompleteInput::URL },
300 { ASCIIToUTF16("user:pass@foo:81"), AutocompleteInput::URL }, 304 { L"user:pass@foo:81", AutocompleteInput::URL },
301 { ASCIIToUTF16("1.2"), AutocompleteInput::UNKNOWN }, 305 { L"1.2", AutocompleteInput::UNKNOWN },
302 { ASCIIToUTF16("1.2/45"), AutocompleteInput::UNKNOWN }, 306 { L"1.2/45", AutocompleteInput::UNKNOWN },
303 { ASCIIToUTF16("1.2:45"), AutocompleteInput::UNKNOWN }, 307 { L"1.2:45", AutocompleteInput::UNKNOWN },
304 { ASCIIToUTF16("user@1.2:45"), AutocompleteInput::UNKNOWN }, 308 { L"user@1.2:45", AutocompleteInput::UNKNOWN },
305 { ASCIIToUTF16("user:pass@1.2:45"), AutocompleteInput::URL }, 309 { L"user:pass@1.2:45", AutocompleteInput::URL },
306 { ASCIIToUTF16("ps/2 games"), AutocompleteInput::UNKNOWN }, 310 { L"ps/2 games", AutocompleteInput::UNKNOWN },
307 { ASCIIToUTF16("en.wikipedia.org/wiki/James Bond"), 311 { L"en.wikipedia.org/wiki/James Bond", AutocompleteInput::URL },
308 AutocompleteInput::URL },
309 // In Chrome itself, mailto: will get handled by ShellExecute, but in 312 // In Chrome itself, mailto: will get handled by ShellExecute, but in
310 // unittest mode, we don't have the data loaded in the external protocol 313 // unittest mode, we don't have the data loaded in the external protocol
311 // handler to know this. 314 // handler to know this.
312 // { ASCIIToUTF16("mailto:abuse@foo.com"), AutocompleteInput::URL }, 315 // { L"mailto:abuse@foo.com", AutocompleteInput::URL },
313 { ASCIIToUTF16("view-source:http://www.foo.com/"), AutocompleteInput::URL }, 316 { L"view-source:http://www.foo.com/", AutocompleteInput::URL },
314 { ASCIIToUTF16("javascript:alert(\"Hey there!\");"), 317 { L"javascript:alert(\"Hey there!\");", AutocompleteInput::URL },
315 AutocompleteInput::URL },
316 #if defined(OS_WIN) 318 #if defined(OS_WIN)
317 { ASCIIToUTF16("C:\\Program Files"), AutocompleteInput::URL }, 319 { L"C:\\Program Files", AutocompleteInput::URL },
318 { ASCIIToUTF16("\\\\Server\\Folder\\File"), AutocompleteInput::URL }, 320 { L"\\\\Server\\Folder\\File", AutocompleteInput::URL },
319 #endif // defined(OS_WIN) 321 #endif // defined(OS_WIN)
320 { ASCIIToUTF16("http:foo"), AutocompleteInput::URL }, 322 { L"http:foo", AutocompleteInput::URL },
321 { ASCIIToUTF16("http://foo"), AutocompleteInput::URL }, 323 { L"http://foo", AutocompleteInput::URL },
322 { ASCIIToUTF16("http://foo.c"), AutocompleteInput::URL }, 324 { L"http://foo.c", AutocompleteInput::URL },
323 { ASCIIToUTF16("http://foo.com"), AutocompleteInput::URL }, 325 { L"http://foo.com", AutocompleteInput::URL },
324 { ASCIIToUTF16("http://foo_bar.com"), AutocompleteInput::URL }, 326 { L"http://foo_bar.com", AutocompleteInput::URL },
325 { ASCIIToUTF16("http://foo/bar baz"), AutocompleteInput::URL }, 327 { L"http://foo/bar baz", AutocompleteInput::URL },
326 { ASCIIToUTF16("http://-.com"), AutocompleteInput::UNKNOWN }, 328 { L"http://-.com", AutocompleteInput::UNKNOWN },
327 { ASCIIToUTF16("http://_foo_.com"), AutocompleteInput::UNKNOWN }, 329 { L"http://_foo_.com", AutocompleteInput::UNKNOWN },
328 { ASCIIToUTF16("http://foo.com:abc"), AutocompleteInput::QUERY }, 330 { L"http://foo.com:abc", AutocompleteInput::QUERY },
329 { ASCIIToUTF16("http://foo.com:123456"), AutocompleteInput::QUERY }, 331 { L"http://foo.com:123456", AutocompleteInput::QUERY },
330 { ASCIIToUTF16("http://1.2.3.4:abc"), AutocompleteInput::QUERY }, 332 { L"http://1.2.3.4:abc", AutocompleteInput::QUERY },
331 { ASCIIToUTF16("http:user@foo.com"), AutocompleteInput::URL }, 333 { L"http:user@foo.com", AutocompleteInput::URL },
332 { ASCIIToUTF16("http://user@foo.com"), AutocompleteInput::URL }, 334 { L"http://user@foo.com", AutocompleteInput::URL },
333 { ASCIIToUTF16("http:user:pass@foo.com"), AutocompleteInput::URL }, 335 { L"http:user:pass@foo.com", AutocompleteInput::URL },
334 { ASCIIToUTF16("http://user:pass@foo.com"), AutocompleteInput::URL }, 336 { L"http://user:pass@foo.com", AutocompleteInput::URL },
335 { ASCIIToUTF16("http://1.2"), AutocompleteInput::URL }, 337 { L"http://1.2", AutocompleteInput::URL },
336 { ASCIIToUTF16("http://1.2/45"), AutocompleteInput::URL }, 338 { L"http://1.2/45", AutocompleteInput::URL },
337 { ASCIIToUTF16("http:ps/2 games"), AutocompleteInput::URL }, 339 { L"http:ps/2 games", AutocompleteInput::URL },
338 { ASCIIToUTF16("http://ps/2 games"), AutocompleteInput::URL }, 340 { L"http://ps/2 games", AutocompleteInput::URL },
339 { ASCIIToUTF16("https://foo.com"), AutocompleteInput::URL }, 341 { L"https://foo.com", AutocompleteInput::URL },
340 { ASCIIToUTF16("127.0.0.1"), AutocompleteInput::URL }, 342 { L"127.0.0.1", AutocompleteInput::URL },
341 { ASCIIToUTF16("127.0.1"), AutocompleteInput::UNKNOWN }, 343 { L"127.0.1", AutocompleteInput::UNKNOWN },
342 { ASCIIToUTF16("127.0.1/"), AutocompleteInput::UNKNOWN }, 344 { L"127.0.1/", AutocompleteInput::UNKNOWN },
343 { ASCIIToUTF16("browser.tabs.closeButtons"), AutocompleteInput::UNKNOWN }, 345 { L"browser.tabs.closeButtons", AutocompleteInput::UNKNOWN },
344 { WideToUTF16(L"\u6d4b\u8bd5"), AutocompleteInput::UNKNOWN }, 346 { L"\u6d4b\u8bd5", AutocompleteInput::UNKNOWN },
345 { ASCIIToUTF16("[2001:]"), AutocompleteInput::QUERY }, // Not a valid IP 347 { L"[2001:]", AutocompleteInput::QUERY }, // Not a valid IP
346 { ASCIIToUTF16("[2001:dB8::1]"), AutocompleteInput::URL }, 348 { L"[2001:dB8::1]", AutocompleteInput::URL },
347 { ASCIIToUTF16("192.168.0.256"), 349 { L"192.168.0.256", AutocompleteInput::QUERY }, // Invalid IPv4 literal.
348 AutocompleteInput::QUERY }, // Invalid IPv4 literal. 350 { L"[foo.com]", AutocompleteInput::QUERY }, // Invalid IPv6 literal.
349 { ASCIIToUTF16("[foo.com]"),
350 AutocompleteInput::QUERY }, // Invalid IPv6 literal.
351 }; 351 };
352 352
353 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(input_cases); ++i) { 353 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(input_cases); ++i) {
354 SCOPED_TRACE(input_cases[i].input); 354 SCOPED_TRACE(input_cases[i].input);
355 AutocompleteInput input(input_cases[i].input, string16(), true, false, 355 AutocompleteInput input(input_cases[i].input, std::wstring(), true, false,
356 true, false); 356 true, false);
357 EXPECT_EQ(input_cases[i].type, input.type()); 357 EXPECT_EQ(input_cases[i].type, input.type());
358 } 358 }
359 } 359 }
360 360
361 TEST(AutocompleteTest, InputTypeWithDesiredTLD) { 361 TEST(AutocompleteTest, InputTypeWithDesiredTLD) {
362 struct test_data { 362 struct test_data {
363 const string16 input; 363 const wchar_t* input;
364 const AutocompleteInput::Type type; 364 const AutocompleteInput::Type type;
365 } input_cases[] = { 365 } input_cases[] = {
366 { ASCIIToUTF16("401k"), AutocompleteInput::REQUESTED_URL }, 366 { L"401k", AutocompleteInput::REQUESTED_URL },
367 { ASCIIToUTF16("999999999999999"), AutocompleteInput::REQUESTED_URL }, 367 { L"999999999999999", AutocompleteInput::REQUESTED_URL },
368 }; 368 };
369 369
370 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(input_cases); ++i) { 370 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(input_cases); ++i) {
371 AutocompleteInput input(input_cases[i].input, ASCIIToUTF16("com"), true, 371 AutocompleteInput input(input_cases[i].input, L"com", true, false, true,
372 false, true, false); 372 false);
373 EXPECT_EQ(input_cases[i].type, input.type()) << "Input: " << 373 EXPECT_EQ(input_cases[i].type, input.type()) << "Input: " <<
374 input_cases[i].input; 374 input_cases[i].input;
375 } 375 }
376 } 376 }
377 377
378 // This tests for a regression where certain input in the omnibox caused us to 378 // This tests for a regression where certain input in the omnibox caused us to
379 // crash. As long as the test completes without crashing, we're fine. 379 // crash. As long as the test completes without crashing, we're fine.
380 TEST(AutocompleteTest, InputCrash) { 380 TEST(AutocompleteTest, InputCrash) {
381 AutocompleteInput input(WideToUTF16(L"\uff65@s"), string16(), true, false, 381 AutocompleteInput input(L"\uff65@s", std::wstring(), true, false, true,
382 true, false); 382 false);
383 } 383 }
384 384
385 // Test comparing matches relevance. 385 // Test comparing matches relevance.
386 TEST(AutocompleteMatch, MoreRelevant) { 386 TEST(AutocompleteMatch, MoreRelevant) {
387 struct RelevantCases { 387 struct RelevantCases {
388 int r1; 388 int r1;
389 int r2; 389 int r2;
390 bool expected_result; 390 bool expected_result;
391 } cases[] = { 391 } cases[] = {
392 { 10, 0, true }, 392 { 10, 0, true },
(...skipping 12 matching lines...) Expand all
405 m2.relevance = cases[i].r2; 405 m2.relevance = cases[i].r2;
406 EXPECT_EQ(cases[i].expected_result, 406 EXPECT_EQ(cases[i].expected_result,
407 AutocompleteMatch::MoreRelevant(m1, m2)); 407 AutocompleteMatch::MoreRelevant(m1, m2));
408 } 408 }
409 } 409 }
410 410
411 TEST(AutocompleteInput, ParseForEmphasizeComponent) { 411 TEST(AutocompleteInput, ParseForEmphasizeComponent) {
412 using url_parse::Component; 412 using url_parse::Component;
413 Component kInvalidComponent(0, -1); 413 Component kInvalidComponent(0, -1);
414 struct test_data { 414 struct test_data {
415 const string16 input; 415 const wchar_t* input;
416 const Component scheme; 416 const Component scheme;
417 const Component host; 417 const Component host;
418 } input_cases[] = { 418 } input_cases[] = {
419 { ASCIIToUTF16(""), kInvalidComponent, kInvalidComponent }, 419 { L"", kInvalidComponent, kInvalidComponent },
420 { ASCIIToUTF16("?"), kInvalidComponent, kInvalidComponent }, 420 { L"?", kInvalidComponent, kInvalidComponent },
421 { ASCIIToUTF16("?http://foo.com/bar"), kInvalidComponent, 421 { L"?http://foo.com/bar", kInvalidComponent, kInvalidComponent },
422 kInvalidComponent }, 422 { L"foo/bar baz", kInvalidComponent, Component(0, 3) },
423 { ASCIIToUTF16("foo/bar baz"), kInvalidComponent, Component(0, 3) }, 423 { L"http://foo/bar baz", Component(0, 4), Component(7, 3) },
424 { ASCIIToUTF16("http://foo/bar baz"), Component(0, 4), Component(7, 3) }, 424 { L"link:foo.com", Component(0, 4), kInvalidComponent },
425 { ASCIIToUTF16("link:foo.com"), Component(0, 4), kInvalidComponent }, 425 { L"www.foo.com:81", kInvalidComponent, Component(0, 11) },
426 { ASCIIToUTF16("www.foo.com:81"), kInvalidComponent, Component(0, 11) }, 426 { L"\u6d4b\u8bd5", kInvalidComponent, Component(0, 2) },
427 { WideToUTF16(L"\u6d4b\u8bd5"), kInvalidComponent, Component(0, 2) }, 427 { L"view-source:http://www.foo.com/", Component(12, 4), Component(19, 11) },
428 { ASCIIToUTF16("view-source:http://www.foo.com/"), Component(12, 4), 428 { L"view-source:https://example.com/",
429 Component(19, 11) },
430 { ASCIIToUTF16("view-source:https://example.com/"),
431 Component(12, 5), Component(20, 11) }, 429 Component(12, 5), Component(20, 11) },
432 { ASCIIToUTF16("view-source:www.foo.com"), kInvalidComponent, 430 { L"view-source:www.foo.com", kInvalidComponent, Component(12, 11) },
433 Component(12, 11) }, 431 { L"view-source:", Component(0, 11), kInvalidComponent },
434 { ASCIIToUTF16("view-source:"), Component(0, 11), kInvalidComponent }, 432 { L"view-source:garbage", kInvalidComponent, Component(12, 7) },
435 { ASCIIToUTF16("view-source:garbage"), kInvalidComponent, 433 { L"view-source:http://http://foo", Component(12, 4), Component(19, 4) },
436 Component(12, 7) }, 434 { L"view-source:view-source:http://example.com/",
437 { ASCIIToUTF16("view-source:http://http://foo"), Component(12, 4), 435 Component(12, 11), kInvalidComponent }
438 Component(19, 4) },
439 { ASCIIToUTF16("view-source:view-source:http://example.com/"),
440 Component(12, 11), kInvalidComponent }
441 }; 436 };
442 437
443 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(input_cases); ++i) { 438 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(input_cases); ++i) {
444 Component scheme, host; 439 Component scheme, host;
445 AutocompleteInput::ParseForEmphasizeComponents(input_cases[i].input, 440 AutocompleteInput::ParseForEmphasizeComponents(input_cases[i].input,
446 string16(), 441 std::wstring(),
447 &scheme, 442 &scheme,
448 &host); 443 &host);
449 AutocompleteInput input(input_cases[i].input, string16(), true, false, 444 AutocompleteInput input(input_cases[i].input, std::wstring(), true, false,
450 true, false); 445 true, false);
451 EXPECT_EQ(input_cases[i].scheme.begin, scheme.begin) << "Input: " << 446 EXPECT_EQ(input_cases[i].scheme.begin, scheme.begin) << "Input: " <<
452 input_cases[i].input; 447 input_cases[i].input;
453 EXPECT_EQ(input_cases[i].scheme.len, scheme.len) << "Input: " << 448 EXPECT_EQ(input_cases[i].scheme.len, scheme.len) << "Input: " <<
454 input_cases[i].input; 449 input_cases[i].input;
455 EXPECT_EQ(input_cases[i].host.begin, host.begin) << "Input: " << 450 EXPECT_EQ(input_cases[i].host.begin, host.begin) << "Input: " <<
456 input_cases[i].input; 451 input_cases[i].input;
457 EXPECT_EQ(input_cases[i].host.len, host.len) << "Input: " << 452 EXPECT_EQ(input_cases[i].host.len, host.len) << "Input: " <<
458 input_cases[i].input; 453 input_cases[i].input;
459 } 454 }
460 } 455 }
461 456
462 } // namespace 457 } // namespace
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698