OLD | NEW |
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/string_util.h" | 5 #include "base/string_util.h" |
6 #include "base/time.h" | 6 #include "base/time.h" |
7 #include "base/utf_string_conversions.h" | 7 #include "base/utf_string_conversions.h" |
8 #include "build/build_config.h" | 8 #include "build/build_config.h" |
9 #include "chrome/browser/autocomplete/autocomplete_match.h" | 9 #include "chrome/browser/autocomplete/autocomplete_match.h" |
10 #include "chrome/browser/autocomplete/search_provider.h" | 10 #include "chrome/browser/autocomplete/search_provider.h" |
(...skipping 155 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
166 #if defined(OS_MACOSX) | 166 #if defined(OS_MACOSX) |
167 message_loop_.Run(); | 167 message_loop_.Run(); |
168 #else | 168 #else |
169 message_loop_.Run(NULL); | 169 message_loop_.Run(NULL); |
170 #endif | 170 #endif |
171 } | 171 } |
172 | 172 |
173 void SearchProviderTest::QueryForInput(const string16& text, | 173 void SearchProviderTest::QueryForInput(const string16& text, |
174 bool prevent_inline_autocomplete) { | 174 bool prevent_inline_autocomplete) { |
175 // Start a query. | 175 // Start a query. |
176 AutocompleteInput input(text, string16(), prevent_inline_autocomplete, | 176 AutocompleteInput input(UTF16ToWide(text), std::wstring(), |
177 false, true, false); | 177 prevent_inline_autocomplete, false, true, false); |
178 provider_->Start(input, false); | 178 provider_->Start(input, false); |
179 | 179 |
180 // RunAllPending so that the task scheduled by SearchProvider to create the | 180 // RunAllPending so that the task scheduled by SearchProvider to create the |
181 // URLFetchers runs. | 181 // URLFetchers runs. |
182 message_loop_.RunAllPending(); | 182 message_loop_.RunAllPending(); |
183 } | 183 } |
184 | 184 |
185 void SearchProviderTest::TearDown() { | 185 void SearchProviderTest::TearDown() { |
186 message_loop_.RunAllPending(); | 186 message_loop_.RunAllPending(); |
187 | 187 |
(...skipping 117 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
305 | 305 |
306 // The SearchProvider is done. Make sure it has a result for the history | 306 // The SearchProvider is done. Make sure it has a result for the history |
307 // term keyword. | 307 // term keyword. |
308 AutocompleteMatch match = FindMatchWithDestination(keyword_url_); | 308 AutocompleteMatch match = FindMatchWithDestination(keyword_url_); |
309 ASSERT_TRUE(!match.destination_url.is_empty()); | 309 ASSERT_TRUE(!match.destination_url.is_empty()); |
310 | 310 |
311 // The match should have a TemplateURL. | 311 // The match should have a TemplateURL. |
312 EXPECT_TRUE(match.template_url); | 312 EXPECT_TRUE(match.template_url); |
313 | 313 |
314 // The fill into edit should contain the keyword. | 314 // The fill into edit should contain the keyword. |
315 EXPECT_EQ(keyword_t_url_->keyword() + char16(' ') + keyword_term_, | 315 EXPECT_EQ(UTF16ToWideHack(keyword_t_url_->keyword()) + |
| 316 L" " + UTF16ToWide(keyword_term_), |
316 match.fill_into_edit); | 317 match.fill_into_edit); |
317 } | 318 } |
318 | 319 |
319 TEST_F(SearchProviderTest, DontSendPrivateDataToSuggest) { | 320 TEST_F(SearchProviderTest, DontSendPrivateDataToSuggest) { |
320 // None of the following input strings should be sent to the suggest server, | 321 // None of the following input strings should be sent to the suggest server, |
321 // because they may contain private data. | 322 // because they may contain private data. |
322 const char* inputs[] = { | 323 const char* inputs[] = { |
323 "username:password", | 324 "username:password", |
324 "http://username:password", | 325 "http://username:password", |
325 "https://username:password", | 326 "https://username:password", |
(...skipping 26 matching lines...) Expand all Loading... |
352 | 353 |
353 // Wait until history and the suggest query complete. | 354 // Wait until history and the suggest query complete. |
354 profile_.BlockUntilHistoryProcessesPendingRequests(); | 355 profile_.BlockUntilHistoryProcessesPendingRequests(); |
355 ASSERT_NO_FATAL_FAILURE(FinishDefaultSuggestQuery()); | 356 ASSERT_NO_FATAL_FAILURE(FinishDefaultSuggestQuery()); |
356 | 357 |
357 // When instant is enabled the provider isn't done until it hears from | 358 // When instant is enabled the provider isn't done until it hears from |
358 // instant. | 359 // instant. |
359 EXPECT_FALSE(provider_->done()); | 360 EXPECT_FALSE(provider_->done()); |
360 | 361 |
361 // Tell the provider instant is done. | 362 // Tell the provider instant is done. |
362 provider_->FinalizeInstantQuery(ASCIIToUTF16("foo"), ASCIIToUTF16("bar")); | 363 provider_->FinalizeInstantQuery(L"foo", L"bar"); |
363 | 364 |
364 // The provider should now be done. | 365 // The provider should now be done. |
365 EXPECT_TRUE(provider_->done()); | 366 EXPECT_TRUE(provider_->done()); |
366 | 367 |
367 // There should be two matches, one for what you typed, the other for | 368 // There should be two matches, one for what you typed, the other for |
368 // 'foobar'. | 369 // 'foobar'. |
369 EXPECT_EQ(2u, provider_->matches().size()); | 370 EXPECT_EQ(2u, provider_->matches().size()); |
370 GURL instant_url = GURL(default_t_url_->url()->ReplaceSearchTerms( | 371 GURL instant_url = GURL(default_t_url_->url()->ReplaceSearchTerms( |
371 *default_t_url_, ASCIIToUTF16("foobar"), 0, string16())); | 372 *default_t_url_, ASCIIToUTF16("foobar"), 0, string16())); |
372 AutocompleteMatch instant_match = FindMatchWithDestination(instant_url); | 373 AutocompleteMatch instant_match = FindMatchWithDestination(instant_url); |
(...skipping 16 matching lines...) Expand all Loading... |
389 | 390 |
390 // Make sure that if FinalizeInstantQuery is invoked before suggest results | 391 // Make sure that if FinalizeInstantQuery is invoked before suggest results |
391 // return, the suggest text from FinalizeInstantQuery is remembered. | 392 // return, the suggest text from FinalizeInstantQuery is remembered. |
392 TEST_F(SearchProviderTest, RememberInstantQuery) { | 393 TEST_F(SearchProviderTest, RememberInstantQuery) { |
393 PrefService* service = profile_.GetPrefs(); | 394 PrefService* service = profile_.GetPrefs(); |
394 service->SetBoolean(prefs::kInstantEnabled, true); | 395 service->SetBoolean(prefs::kInstantEnabled, true); |
395 | 396 |
396 QueryForInput(ASCIIToUTF16("foo"), false); | 397 QueryForInput(ASCIIToUTF16("foo"), false); |
397 | 398 |
398 // Finalize the instant query immediately. | 399 // Finalize the instant query immediately. |
399 provider_->FinalizeInstantQuery(ASCIIToUTF16("foo"), ASCIIToUTF16("bar")); | 400 provider_->FinalizeInstantQuery(L"foo", L"bar"); |
400 | 401 |
401 // There should be two matches, one for what you typed, the other for | 402 // There should be two matches, one for what you typed, the other for |
402 // 'foobar'. | 403 // 'foobar'. |
403 EXPECT_EQ(2u, provider_->matches().size()); | 404 EXPECT_EQ(2u, provider_->matches().size()); |
404 GURL instant_url = GURL(default_t_url_->url()->ReplaceSearchTerms( | 405 GURL instant_url = GURL(default_t_url_->url()->ReplaceSearchTerms( |
405 *default_t_url_, ASCIIToUTF16("foobar"), 0, string16())); | 406 *default_t_url_, ASCIIToUTF16("foobar"), 0, string16())); |
406 AutocompleteMatch instant_match = FindMatchWithDestination(instant_url); | 407 AutocompleteMatch instant_match = FindMatchWithDestination(instant_url); |
407 EXPECT_FALSE(instant_match.destination_url.is_empty()); | 408 EXPECT_FALSE(instant_match.destination_url.is_empty()); |
408 | 409 |
409 // Wait until history and the suggest query complete. | 410 // Wait until history and the suggest query complete. |
410 profile_.BlockUntilHistoryProcessesPendingRequests(); | 411 profile_.BlockUntilHistoryProcessesPendingRequests(); |
411 ASSERT_NO_FATAL_FAILURE(FinishDefaultSuggestQuery()); | 412 ASSERT_NO_FATAL_FAILURE(FinishDefaultSuggestQuery()); |
412 | 413 |
413 // Provider should be done. | 414 // Provider should be done. |
414 EXPECT_TRUE(provider_->done()); | 415 EXPECT_TRUE(provider_->done()); |
415 | 416 |
416 // There should be two matches, one for what you typed, the other for | 417 // There should be two matches, one for what you typed, the other for |
417 // 'foobar'. | 418 // 'foobar'. |
418 EXPECT_EQ(2u, provider_->matches().size()); | 419 EXPECT_EQ(2u, provider_->matches().size()); |
419 instant_match = FindMatchWithDestination(instant_url); | 420 instant_match = FindMatchWithDestination(instant_url); |
420 EXPECT_FALSE(instant_match.destination_url.is_empty()); | 421 EXPECT_FALSE(instant_match.destination_url.is_empty()); |
421 | 422 |
422 // And the 'foobar' match should have a description. | 423 // And the 'foobar' match should have a description. |
423 EXPECT_FALSE(instant_match.description.empty()); | 424 EXPECT_FALSE(instant_match.description.empty()); |
424 } | 425 } |
OLD | NEW |