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(UTF16ToWide(text), std::wstring(), | 176 AutocompleteInput input(text, string16(), prevent_inline_autocomplete, |
177 prevent_inline_autocomplete, false, true, false); | 177 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(UTF16ToWideHack(keyword_t_url_->keyword()) + | 315 EXPECT_EQ(keyword_t_url_->keyword() + char16(' ') + keyword_term_, |
316 L" " + UTF16ToWide(keyword_term_), | |
317 match.fill_into_edit); | 316 match.fill_into_edit); |
318 } | 317 } |
319 | 318 |
320 TEST_F(SearchProviderTest, DontSendPrivateDataToSuggest) { | 319 TEST_F(SearchProviderTest, DontSendPrivateDataToSuggest) { |
321 // None of the following input strings should be sent to the suggest server, | 320 // None of the following input strings should be sent to the suggest server, |
322 // because they may contain private data. | 321 // because they may contain private data. |
323 const char* inputs[] = { | 322 const char* inputs[] = { |
324 "username:password", | 323 "username:password", |
325 "http://username:password", | 324 "http://username:password", |
326 "https://username:password", | 325 "https://username:password", |
(...skipping 26 matching lines...) Expand all Loading... |
353 | 352 |
354 // Wait until history and the suggest query complete. | 353 // Wait until history and the suggest query complete. |
355 profile_.BlockUntilHistoryProcessesPendingRequests(); | 354 profile_.BlockUntilHistoryProcessesPendingRequests(); |
356 ASSERT_NO_FATAL_FAILURE(FinishDefaultSuggestQuery()); | 355 ASSERT_NO_FATAL_FAILURE(FinishDefaultSuggestQuery()); |
357 | 356 |
358 // When instant is enabled the provider isn't done until it hears from | 357 // When instant is enabled the provider isn't done until it hears from |
359 // instant. | 358 // instant. |
360 EXPECT_FALSE(provider_->done()); | 359 EXPECT_FALSE(provider_->done()); |
361 | 360 |
362 // Tell the provider instant is done. | 361 // Tell the provider instant is done. |
363 provider_->FinalizeInstantQuery(L"foo", L"bar"); | 362 provider_->FinalizeInstantQuery(ASCIIToUTF16("foo"), ASCIIToUTF16("bar")); |
364 | 363 |
365 // The provider should now be done. | 364 // The provider should now be done. |
366 EXPECT_TRUE(provider_->done()); | 365 EXPECT_TRUE(provider_->done()); |
367 | 366 |
368 // There should be two matches, one for what you typed, the other for | 367 // There should be two matches, one for what you typed, the other for |
369 // 'foobar'. | 368 // 'foobar'. |
370 EXPECT_EQ(2u, provider_->matches().size()); | 369 EXPECT_EQ(2u, provider_->matches().size()); |
371 GURL instant_url = GURL(default_t_url_->url()->ReplaceSearchTerms( | 370 GURL instant_url = GURL(default_t_url_->url()->ReplaceSearchTerms( |
372 *default_t_url_, ASCIIToUTF16("foobar"), 0, string16())); | 371 *default_t_url_, ASCIIToUTF16("foobar"), 0, string16())); |
373 AutocompleteMatch instant_match = FindMatchWithDestination(instant_url); | 372 AutocompleteMatch instant_match = FindMatchWithDestination(instant_url); |
(...skipping 16 matching lines...) Expand all Loading... |
390 | 389 |
391 // Make sure that if FinalizeInstantQuery is invoked before suggest results | 390 // Make sure that if FinalizeInstantQuery is invoked before suggest results |
392 // return, the suggest text from FinalizeInstantQuery is remembered. | 391 // return, the suggest text from FinalizeInstantQuery is remembered. |
393 TEST_F(SearchProviderTest, RememberInstantQuery) { | 392 TEST_F(SearchProviderTest, RememberInstantQuery) { |
394 PrefService* service = profile_.GetPrefs(); | 393 PrefService* service = profile_.GetPrefs(); |
395 service->SetBoolean(prefs::kInstantEnabled, true); | 394 service->SetBoolean(prefs::kInstantEnabled, true); |
396 | 395 |
397 QueryForInput(ASCIIToUTF16("foo"), false); | 396 QueryForInput(ASCIIToUTF16("foo"), false); |
398 | 397 |
399 // Finalize the instant query immediately. | 398 // Finalize the instant query immediately. |
400 provider_->FinalizeInstantQuery(L"foo", L"bar"); | 399 provider_->FinalizeInstantQuery(ASCIIToUTF16("foo"), ASCIIToUTF16("bar")); |
401 | 400 |
402 // There should be two matches, one for what you typed, the other for | 401 // There should be two matches, one for what you typed, the other for |
403 // 'foobar'. | 402 // 'foobar'. |
404 EXPECT_EQ(2u, provider_->matches().size()); | 403 EXPECT_EQ(2u, provider_->matches().size()); |
405 GURL instant_url = GURL(default_t_url_->url()->ReplaceSearchTerms( | 404 GURL instant_url = GURL(default_t_url_->url()->ReplaceSearchTerms( |
406 *default_t_url_, ASCIIToUTF16("foobar"), 0, string16())); | 405 *default_t_url_, ASCIIToUTF16("foobar"), 0, string16())); |
407 AutocompleteMatch instant_match = FindMatchWithDestination(instant_url); | 406 AutocompleteMatch instant_match = FindMatchWithDestination(instant_url); |
408 EXPECT_FALSE(instant_match.destination_url.is_empty()); | 407 EXPECT_FALSE(instant_match.destination_url.is_empty()); |
409 | 408 |
410 // Wait until history and the suggest query complete. | 409 // Wait until history and the suggest query complete. |
411 profile_.BlockUntilHistoryProcessesPendingRequests(); | 410 profile_.BlockUntilHistoryProcessesPendingRequests(); |
412 ASSERT_NO_FATAL_FAILURE(FinishDefaultSuggestQuery()); | 411 ASSERT_NO_FATAL_FAILURE(FinishDefaultSuggestQuery()); |
413 | 412 |
414 // Provider should be done. | 413 // Provider should be done. |
415 EXPECT_TRUE(provider_->done()); | 414 EXPECT_TRUE(provider_->done()); |
416 | 415 |
417 // There should be two matches, one for what you typed, the other for | 416 // There should be two matches, one for what you typed, the other for |
418 // 'foobar'. | 417 // 'foobar'. |
419 EXPECT_EQ(2u, provider_->matches().size()); | 418 EXPECT_EQ(2u, provider_->matches().size()); |
420 instant_match = FindMatchWithDestination(instant_url); | 419 instant_match = FindMatchWithDestination(instant_url); |
421 EXPECT_FALSE(instant_match.destination_url.is_empty()); | 420 EXPECT_FALSE(instant_match.destination_url.is_empty()); |
422 | 421 |
423 // And the 'foobar' match should have a description. | 422 // And the 'foobar' match should have a description. |
424 EXPECT_FALSE(instant_match.description.empty()); | 423 EXPECT_FALSE(instant_match.description.empty()); |
425 } | 424 } |
OLD | NEW |