| OLD | NEW |
| 1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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 <vector> | 5 #include <vector> |
| 6 | 6 |
| 7 #include "app/l10n_util.h" |
| 7 #include "base/ref_counted.h" | 8 #include "base/ref_counted.h" |
| 8 #include "base/scoped_ptr.h" | 9 #include "base/scoped_ptr.h" |
| 9 #include "base/scoped_vector.h" | 10 #include "base/scoped_vector.h" |
| 10 #include "base/string16.h" | 11 #include "base/string16.h" |
| 11 #include "base/tuple.h" | 12 #include "base/tuple.h" |
| 12 #include "base/utf_string_conversions.h" | 13 #include "base/utf_string_conversions.h" |
| 13 #include "chrome/browser/autofill/autofill_common_test.h" | 14 #include "chrome/browser/autofill/autofill_common_test.h" |
| 14 #include "chrome/browser/autofill/autofill_manager.h" | 15 #include "chrome/browser/autofill/autofill_manager.h" |
| 15 #include "chrome/browser/autofill/autofill_profile.h" | 16 #include "chrome/browser/autofill/autofill_profile.h" |
| 16 #include "chrome/browser/autofill/credit_card.h" | 17 #include "chrome/browser/autofill/credit_card.h" |
| 17 #include "chrome/browser/autofill/personal_data_manager.h" | 18 #include "chrome/browser/autofill/personal_data_manager.h" |
| 18 #include "chrome/browser/prefs/pref_service.h" | 19 #include "chrome/browser/prefs/pref_service.h" |
| 19 #include "chrome/browser/profile.h" | 20 #include "chrome/browser/profile.h" |
| 20 #include "chrome/browser/renderer_host/test/test_render_view_host.h" | 21 #include "chrome/browser/renderer_host/test/test_render_view_host.h" |
| 21 #include "chrome/browser/tab_contents/test_tab_contents.h" | 22 #include "chrome/browser/tab_contents/test_tab_contents.h" |
| 22 #include "chrome/common/ipc_test_sink.h" | 23 #include "chrome/common/ipc_test_sink.h" |
| 23 #include "chrome/common/pref_names.h" | 24 #include "chrome/common/pref_names.h" |
| 24 #include "chrome/common/render_messages.h" | 25 #include "chrome/common/render_messages.h" |
| 25 #include "googleurl/src/gurl.h" | 26 #include "googleurl/src/gurl.h" |
| 27 #include "grit/generated_resources.h" |
| 26 #include "testing/gtest/include/gtest/gtest.h" | 28 #include "testing/gtest/include/gtest/gtest.h" |
| 27 #include "webkit/glue/form_data.h" | 29 #include "webkit/glue/form_data.h" |
| 28 #include "webkit/glue/form_field.h" | 30 #include "webkit/glue/form_field.h" |
| 29 | 31 |
| 30 using webkit_glue::FormData; | 32 using webkit_glue::FormData; |
| 31 | 33 |
| 32 typedef Tuple5<int, | 34 typedef Tuple5<int, |
| 33 std::vector<string16>, | 35 std::vector<string16>, |
| 34 std::vector<string16>, | 36 std::vector<string16>, |
| 35 std::vector<string16>, | 37 std::vector<string16>, |
| (...skipping 16 matching lines...) Expand all Loading... |
| 52 if (!(*it)->Label().compare(ASCIIToUTF16(label))) | 54 if (!(*it)->Label().compare(ASCIIToUTF16(label))) |
| 53 return *it; | 55 return *it; |
| 54 } | 56 } |
| 55 return NULL; | 57 return NULL; |
| 56 } | 58 } |
| 57 | 59 |
| 58 void AddProfile(AutoFillProfile* profile) { | 60 void AddProfile(AutoFillProfile* profile) { |
| 59 web_profiles_->push_back(profile); | 61 web_profiles_->push_back(profile); |
| 60 } | 62 } |
| 61 | 63 |
| 64 void ClearAutoFillProfiles() { |
| 65 web_profiles_.reset(); |
| 66 } |
| 67 |
| 68 void ClearCreditCards() { |
| 69 credit_cards_.reset(); |
| 70 } |
| 71 |
| 62 private: | 72 private: |
| 63 void CreateTestAutoFillProfiles(ScopedVector<AutoFillProfile>* profiles) { | 73 void CreateTestAutoFillProfiles(ScopedVector<AutoFillProfile>* profiles) { |
| 64 AutoFillProfile* profile = new AutoFillProfile; | 74 AutoFillProfile* profile = new AutoFillProfile; |
| 65 autofill_test::SetProfileInfo(profile, "Home", "Elvis", "Aaron", | 75 autofill_test::SetProfileInfo(profile, "Home", "Elvis", "Aaron", |
| 66 "Presley", "theking@gmail.com", "RCA", | 76 "Presley", "theking@gmail.com", "RCA", |
| 67 "3734 Elvis Presley Blvd.", "Apt. 10", | 77 "3734 Elvis Presley Blvd.", "Apt. 10", |
| 68 "Memphis", "Tennessee", "38116", "USA", | 78 "Memphis", "Tennessee", "38116", "USA", |
| 69 "12345678901", ""); | 79 "12345678901", ""); |
| 70 profile->set_guid("00000000-0000-0000-0000-000000000001"); | 80 profile->set_guid("00000000-0000-0000-0000-000000000001"); |
| 71 profiles->push_back(profile); | 81 profiles->push_back(profile); |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 103 credit_cards->push_back(credit_card); | 113 credit_cards->push_back(credit_card); |
| 104 } | 114 } |
| 105 | 115 |
| 106 DISALLOW_COPY_AND_ASSIGN(TestPersonalDataManager); | 116 DISALLOW_COPY_AND_ASSIGN(TestPersonalDataManager); |
| 107 }; | 117 }; |
| 108 | 118 |
| 109 class TestAutoFillManager : public AutoFillManager { | 119 class TestAutoFillManager : public AutoFillManager { |
| 110 public: | 120 public: |
| 111 TestAutoFillManager(TabContents* tab_contents, | 121 TestAutoFillManager(TabContents* tab_contents, |
| 112 TestPersonalDataManager* personal_manager) | 122 TestPersonalDataManager* personal_manager) |
| 113 : AutoFillManager(tab_contents, NULL) { | 123 : AutoFillManager(tab_contents, NULL), |
| 124 autofill_enabled_(true) { |
| 114 test_personal_data_ = personal_manager; | 125 test_personal_data_ = personal_manager; |
| 115 set_personal_data_manager(personal_manager); | 126 set_personal_data_manager(personal_manager); |
| 116 // Download manager requests are disabled for purposes of this unit-test. | 127 // Download manager requests are disabled for purposes of this unit-test. |
| 117 // These request are tested in autofill_download_unittest.cc. | 128 // These request are tested in autofill_download_unittest.cc. |
| 118 set_disable_download_manager_requests(true); | 129 set_disable_download_manager_requests(true); |
| 119 } | 130 } |
| 120 | 131 |
| 121 virtual bool IsAutoFillEnabled() const { return true; } | 132 virtual bool IsAutoFillEnabled() const { return autofill_enabled_; } |
| 133 |
| 134 void set_autofill_enabled(bool autofill_enabled) { |
| 135 autofill_enabled_ = autofill_enabled; |
| 136 } |
| 122 | 137 |
| 123 AutoFillProfile* GetLabeledProfile(const char* label) { | 138 AutoFillProfile* GetLabeledProfile(const char* label) { |
| 124 return test_personal_data_->GetLabeledProfile(label); | 139 return test_personal_data_->GetLabeledProfile(label); |
| 125 } | 140 } |
| 126 | 141 |
| 127 void AddProfile(AutoFillProfile* profile) { | 142 void AddProfile(AutoFillProfile* profile) { |
| 128 test_personal_data_->AddProfile(profile); | 143 test_personal_data_->AddProfile(profile); |
| 129 } | 144 } |
| 130 | 145 |
| 131 private: | 146 private: |
| 132 TestPersonalDataManager* test_personal_data_; | 147 TestPersonalDataManager* test_personal_data_; |
| 148 bool autofill_enabled_; |
| 133 | 149 |
| 134 DISALLOW_COPY_AND_ASSIGN(TestAutoFillManager); | 150 DISALLOW_COPY_AND_ASSIGN(TestAutoFillManager); |
| 135 }; | 151 }; |
| 136 | 152 |
| 137 // Populates |form| with data corresponding to a simple address form. | 153 // Populates |form| with data corresponding to a simple address form. |
| 138 // Note that this actually appends fields to the form data, which can be useful | 154 // Note that this actually appends fields to the form data, which can be useful |
| 139 // for building up more complex test forms. | 155 // for building up more complex test forms. |
| 140 void CreateTestAddressFormData(FormData* form) { | 156 void CreateTestAddressFormData(FormData* form) { |
| 141 form->name = ASCIIToUTF16("MyForm"); | 157 form->name = ASCIIToUTF16("MyForm"); |
| 142 form->method = ASCIIToUTF16("POST"); | 158 form->method = ASCIIToUTF16("POST"); |
| (...skipping 143 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 286 forms.push_back(form); | 302 forms.push_back(form); |
| 287 autofill_manager_->FormsSeen(forms); | 303 autofill_manager_->FormsSeen(forms); |
| 288 | 304 |
| 289 // The page ID sent to the AutoFillManager from the RenderView, used to send | 305 // The page ID sent to the AutoFillManager from the RenderView, used to send |
| 290 // an IPC message back to the renderer. | 306 // an IPC message back to the renderer. |
| 291 const int kPageID = 1; | 307 const int kPageID = 1; |
| 292 | 308 |
| 293 webkit_glue::FormField field; | 309 webkit_glue::FormField field; |
| 294 autofill_test::CreateTestFormField( | 310 autofill_test::CreateTestFormField( |
| 295 "First Name", "firstname", "", "text", &field); | 311 "First Name", "firstname", "", "text", &field); |
| 296 EXPECT_TRUE(autofill_manager_->GetAutoFillSuggestions(kPageID, false, field)); | 312 rvh()->ResetAutoFillState(kPageID); |
| 313 EXPECT_TRUE(autofill_manager_->GetAutoFillSuggestions(false, field)); |
| 297 | 314 |
| 298 // No suggestions provided, so send an empty vector as the results. | 315 // No suggestions provided, so send an empty vector as the results. |
| 299 // This triggers the combined message send. | 316 // This triggers the combined message send. |
| 300 rvh()->AutocompleteSuggestionsReturned(kPageID, std::vector<string16>()); | 317 rvh()->AutocompleteSuggestionsReturned(std::vector<string16>()); |
| 301 | 318 |
| 302 // Test that we sent the right message to the renderer. | 319 // Test that we sent the right message to the renderer. |
| 303 int page_id = 0; | 320 int page_id = 0; |
| 304 std::vector<string16> values; | 321 std::vector<string16> values; |
| 305 std::vector<string16> labels; | 322 std::vector<string16> labels; |
| 306 std::vector<string16> icons; | 323 std::vector<string16> icons; |
| 307 EXPECT_TRUE(GetAutoFillSuggestionsMessage(&page_id, &values, &labels, | 324 EXPECT_TRUE(GetAutoFillSuggestionsMessage(&page_id, &values, &labels, |
| 308 &icons)); | 325 &icons)); |
| 309 EXPECT_EQ(kPageID, page_id); | 326 EXPECT_EQ(kPageID, page_id); |
| 310 ASSERT_EQ(2U, values.size()); | 327 ASSERT_EQ(2U, values.size()); |
| (...skipping 20 matching lines...) Expand all Loading... |
| 331 forms.push_back(form); | 348 forms.push_back(form); |
| 332 autofill_manager_->FormsSeen(forms); | 349 autofill_manager_->FormsSeen(forms); |
| 333 | 350 |
| 334 // The page ID sent to the AutoFillManager from the RenderView, used to send | 351 // The page ID sent to the AutoFillManager from the RenderView, used to send |
| 335 // an IPC message back to the renderer. | 352 // an IPC message back to the renderer. |
| 336 const int kPageID = 1; | 353 const int kPageID = 1; |
| 337 | 354 |
| 338 webkit_glue::FormField field; | 355 webkit_glue::FormField field; |
| 339 autofill_test::CreateTestFormField( | 356 autofill_test::CreateTestFormField( |
| 340 "First Name", "firstname", "E", "text", &field); | 357 "First Name", "firstname", "E", "text", &field); |
| 341 EXPECT_TRUE(autofill_manager_->GetAutoFillSuggestions(kPageID, false, field)); | 358 rvh()->ResetAutoFillState(kPageID); |
| 359 EXPECT_TRUE(autofill_manager_->GetAutoFillSuggestions(false, field)); |
| 342 | 360 |
| 343 // No suggestions provided, so send an empty vector as the results. | 361 // No suggestions provided, so send an empty vector as the results. |
| 344 // This triggers the combined message send. | 362 // This triggers the combined message send. |
| 345 rvh()->AutocompleteSuggestionsReturned(kPageID, std::vector<string16>()); | 363 rvh()->AutocompleteSuggestionsReturned(std::vector<string16>()); |
| 346 | 364 |
| 347 // Test that we sent the right message to the renderer. | 365 // Test that we sent the right message to the renderer. |
| 348 int page_id = 0; | 366 int page_id = 0; |
| 349 std::vector<string16> values; | 367 std::vector<string16> values; |
| 350 std::vector<string16> labels; | 368 std::vector<string16> labels; |
| 351 std::vector<string16> icons; | 369 std::vector<string16> icons; |
| 352 EXPECT_TRUE(GetAutoFillSuggestionsMessage(&page_id, &values, &labels, | 370 EXPECT_TRUE(GetAutoFillSuggestionsMessage(&page_id, &values, &labels, |
| 353 &icons)); | 371 &icons)); |
| 354 EXPECT_EQ(kPageID, page_id); | 372 EXPECT_EQ(kPageID, page_id); |
| 355 ASSERT_EQ(1U, values.size()); | 373 ASSERT_EQ(1U, values.size()); |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 387 std::vector<FormData> forms; | 405 std::vector<FormData> forms; |
| 388 forms.push_back(form); | 406 forms.push_back(form); |
| 389 autofill_manager_->FormsSeen(forms); | 407 autofill_manager_->FormsSeen(forms); |
| 390 | 408 |
| 391 // The page ID sent to the AutoFillManager from the RenderView, used to send | 409 // The page ID sent to the AutoFillManager from the RenderView, used to send |
| 392 // an IPC message back to the renderer. | 410 // an IPC message back to the renderer. |
| 393 const int kPageID = 1; | 411 const int kPageID = 1; |
| 394 | 412 |
| 395 autofill_test::CreateTestFormField( | 413 autofill_test::CreateTestFormField( |
| 396 "Username", "username", "", "text", &field); | 414 "Username", "username", "", "text", &field); |
| 415 rvh()->ResetAutoFillState(kPageID); |
| 397 EXPECT_FALSE( | 416 EXPECT_FALSE( |
| 398 autofill_manager_->GetAutoFillSuggestions(kPageID, false, field)); | 417 autofill_manager_->GetAutoFillSuggestions(false, field)); |
| 418 } |
| 419 |
| 420 // Test that we return no suggestions when autofill is disabled. |
| 421 TEST_F(AutoFillManagerTest, GetProfileSuggestionsAutofillDisabledByUser) { |
| 422 FormData form; |
| 423 CreateTestAddressFormData(&form); |
| 424 |
| 425 // Set up our FormStructures. |
| 426 std::vector<FormData> forms; |
| 427 forms.push_back(form); |
| 428 autofill_manager_->FormsSeen(forms); |
| 429 |
| 430 // Disable AutoFill. |
| 431 autofill_manager_->set_autofill_enabled(false); |
| 432 |
| 433 // The page ID sent to the AutoFillManager from the RenderView, used to send |
| 434 // an IPC message back to the renderer. |
| 435 const int kPageID = 1; |
| 436 |
| 437 webkit_glue::FormField field; |
| 438 autofill_test::CreateTestFormField( |
| 439 "First Name", "firstname", "", "text", &field); |
| 440 rvh()->ResetAutoFillState(kPageID); |
| 441 EXPECT_FALSE(autofill_manager_->GetAutoFillSuggestions(false, field)); |
| 442 } |
| 443 |
| 444 // Test that we return a warning explaining that autofill suggestions are |
| 445 // unavailable when the form method is GET rather than POST. |
| 446 TEST_F(AutoFillManagerTest, GetProfileSuggestionsMethodGet) { |
| 447 FormData form; |
| 448 CreateTestAddressFormData(&form); |
| 449 form.method = ASCIIToUTF16("GET"); |
| 450 |
| 451 // Set up our FormStructures. |
| 452 std::vector<FormData> forms; |
| 453 forms.push_back(form); |
| 454 autofill_manager_->FormsSeen(forms); |
| 455 |
| 456 // The page ID sent to the AutoFillManager from the RenderView, used to send |
| 457 // an IPC message back to the renderer. |
| 458 const int kPageID = 1; |
| 459 |
| 460 webkit_glue::FormField field; |
| 461 autofill_test::CreateTestFormField( |
| 462 "First Name", "firstname", "", "text", &field); |
| 463 rvh()->ResetAutoFillState(kPageID); |
| 464 EXPECT_TRUE(autofill_manager_->GetAutoFillSuggestions(false, field)); |
| 465 |
| 466 // No suggestions provided, so send an empty vector as the results. |
| 467 // This triggers the combined message send. |
| 468 rvh()->AutocompleteSuggestionsReturned(std::vector<string16>()); |
| 469 |
| 470 // Test that we sent the right message to the renderer. |
| 471 int page_id = 0; |
| 472 std::vector<string16> values; |
| 473 std::vector<string16> labels; |
| 474 std::vector<string16> icons; |
| 475 EXPECT_TRUE(GetAutoFillSuggestionsMessage(&page_id, &values, &labels, |
| 476 &icons)); |
| 477 EXPECT_EQ(kPageID, page_id); |
| 478 ASSERT_EQ(1U, values.size()); |
| 479 EXPECT_EQ(l10n_util::GetStringUTF16(IDS_AUTOFILL_WARNING_FORM_DISABLED), |
| 480 values[0]); |
| 481 ASSERT_EQ(1U, labels.size()); |
| 482 EXPECT_EQ(string16(), labels[0]); |
| 483 ASSERT_EQ(1U, icons.size()); |
| 484 EXPECT_EQ(string16(), icons[0]); |
| 485 |
| 486 // Now add some Autocomplete suggestions. We should return the autocomplete |
| 487 // suggestions and the warning; these will be culled by the renderer. |
| 488 process()->sink().ClearMessages(); |
| 489 const int kPageID2 = 2; |
| 490 rvh()->ResetAutoFillState(kPageID2); |
| 491 EXPECT_TRUE(autofill_manager_->GetAutoFillSuggestions(false, field)); |
| 492 |
| 493 std::vector<string16> suggestions; |
| 494 suggestions.push_back(ASCIIToUTF16("Jay")); |
| 495 suggestions.push_back(ASCIIToUTF16("Jason")); |
| 496 rvh()->AutocompleteSuggestionsReturned(suggestions); |
| 497 |
| 498 EXPECT_TRUE(GetAutoFillSuggestionsMessage(&page_id, &values, &labels, |
| 499 &icons)); |
| 500 EXPECT_EQ(kPageID2, page_id); |
| 501 ASSERT_EQ(3U, values.size()); |
| 502 EXPECT_EQ(l10n_util::GetStringUTF16(IDS_AUTOFILL_WARNING_FORM_DISABLED), |
| 503 values[0]); |
| 504 EXPECT_EQ(ASCIIToUTF16("Jay"), values[1]); |
| 505 EXPECT_EQ(ASCIIToUTF16("Jason"), values[2]); |
| 506 ASSERT_EQ(3U, labels.size()); |
| 507 EXPECT_EQ(string16(), labels[0]); |
| 508 EXPECT_EQ(string16(), labels[1]); |
| 509 EXPECT_EQ(string16(), labels[2]); |
| 510 ASSERT_EQ(3U, icons.size()); |
| 511 EXPECT_EQ(string16(), icons[0]); |
| 512 EXPECT_EQ(string16(), icons[1]); |
| 513 EXPECT_EQ(string16(), icons[2]); |
| 514 |
| 515 // Now clear the test profiles and try again -- we shouldn't return a warning. |
| 516 test_personal_data_->ClearAutoFillProfiles(); |
| 517 EXPECT_FALSE(autofill_manager_->GetAutoFillSuggestions(false, field)); |
| 399 } | 518 } |
| 400 | 519 |
| 401 // Test that we return all credit card profile suggestions when all form fields | 520 // Test that we return all credit card profile suggestions when all form fields |
| 402 // are empty. | 521 // are empty. |
| 403 TEST_F(AutoFillManagerTest, GetCreditCardSuggestionsEmptyValue) { | 522 TEST_F(AutoFillManagerTest, GetCreditCardSuggestionsEmptyValue) { |
| 404 FormData form; | 523 FormData form; |
| 405 CreateTestCreditCardFormData(&form, true); | 524 CreateTestCreditCardFormData(&form, true); |
| 406 | 525 |
| 407 // Set up our FormStructures. | 526 // Set up our FormStructures. |
| 408 std::vector<FormData> forms; | 527 std::vector<FormData> forms; |
| 409 forms.push_back(form); | 528 forms.push_back(form); |
| 410 autofill_manager_->FormsSeen(forms); | 529 autofill_manager_->FormsSeen(forms); |
| 411 | 530 |
| 412 // The page ID sent to the AutoFillManager from the RenderView, used to send | 531 // The page ID sent to the AutoFillManager from the RenderView, used to send |
| 413 // an IPC message back to the renderer. | 532 // an IPC message back to the renderer. |
| 414 const int kPageID = 1; | 533 const int kPageID = 1; |
| 415 | 534 |
| 416 webkit_glue::FormField field; | 535 webkit_glue::FormField field; |
| 417 autofill_test::CreateTestFormField( | 536 autofill_test::CreateTestFormField( |
| 418 "Card Number", "cardnumber", "", "text", &field); | 537 "Card Number", "cardnumber", "", "text", &field); |
| 419 EXPECT_TRUE(autofill_manager_->GetAutoFillSuggestions(kPageID, false, field)); | 538 rvh()->ResetAutoFillState(kPageID); |
| 539 EXPECT_TRUE(autofill_manager_->GetAutoFillSuggestions(false, field)); |
| 420 | 540 |
| 421 // No suggestions provided, so send an empty vector as the results. | 541 // No suggestions provided, so send an empty vector as the results. |
| 422 // This triggers the combined message send. | 542 // This triggers the combined message send. |
| 423 rvh()->AutocompleteSuggestionsReturned(kPageID, std::vector<string16>()); | 543 rvh()->AutocompleteSuggestionsReturned(std::vector<string16>()); |
| 424 | 544 |
| 425 // Test that we sent the right message to the renderer. | 545 // Test that we sent the right message to the renderer. |
| 426 int page_id = 0; | 546 int page_id = 0; |
| 427 std::vector<string16> values; | 547 std::vector<string16> values; |
| 428 std::vector<string16> labels; | 548 std::vector<string16> labels; |
| 429 std::vector<string16> icons; | 549 std::vector<string16> icons; |
| 430 EXPECT_TRUE(GetAutoFillSuggestionsMessage(&page_id, &values, &labels, | 550 EXPECT_TRUE(GetAutoFillSuggestionsMessage(&page_id, &values, &labels, |
| 431 &icons)); | 551 &icons)); |
| 432 EXPECT_EQ(kPageID, page_id); | 552 EXPECT_EQ(kPageID, page_id); |
| 433 ASSERT_EQ(2U, values.size()); | 553 ASSERT_EQ(2U, values.size()); |
| (...skipping 18 matching lines...) Expand all Loading... |
| 452 forms.push_back(form); | 572 forms.push_back(form); |
| 453 autofill_manager_->FormsSeen(forms); | 573 autofill_manager_->FormsSeen(forms); |
| 454 | 574 |
| 455 // The page ID sent to the AutoFillManager from the RenderView, used to send | 575 // The page ID sent to the AutoFillManager from the RenderView, used to send |
| 456 // an IPC message back to the renderer. | 576 // an IPC message back to the renderer. |
| 457 const int kPageID = 1; | 577 const int kPageID = 1; |
| 458 | 578 |
| 459 webkit_glue::FormField field; | 579 webkit_glue::FormField field; |
| 460 autofill_test::CreateTestFormField( | 580 autofill_test::CreateTestFormField( |
| 461 "Card Number", "cardnumber", "4", "text", &field); | 581 "Card Number", "cardnumber", "4", "text", &field); |
| 462 EXPECT_TRUE(autofill_manager_->GetAutoFillSuggestions(kPageID, false, field)); | 582 rvh()->ResetAutoFillState(kPageID); |
| 583 EXPECT_TRUE(autofill_manager_->GetAutoFillSuggestions(false, field)); |
| 463 | 584 |
| 464 // No suggestions provided, so send an empty vector as the results. | 585 // No suggestions provided, so send an empty vector as the results. |
| 465 // This triggers the combined message send. | 586 // This triggers the combined message send. |
| 466 rvh()->AutocompleteSuggestionsReturned(kPageID, std::vector<string16>()); | 587 rvh()->AutocompleteSuggestionsReturned(std::vector<string16>()); |
| 467 | 588 |
| 468 // Test that we sent the right message to the renderer. | 589 // Test that we sent the right message to the renderer. |
| 469 int page_id = 0; | 590 int page_id = 0; |
| 470 std::vector<string16> values; | 591 std::vector<string16> values; |
| 471 std::vector<string16> labels; | 592 std::vector<string16> labels; |
| 472 std::vector<string16> icons; | 593 std::vector<string16> icons; |
| 473 EXPECT_TRUE(GetAutoFillSuggestionsMessage(&page_id, &values, &labels, | 594 EXPECT_TRUE(GetAutoFillSuggestionsMessage(&page_id, &values, &labels, |
| 474 &icons)); | 595 &icons)); |
| 475 EXPECT_EQ(kPageID, page_id); | 596 EXPECT_EQ(kPageID, page_id); |
| 476 ASSERT_EQ(1U, values.size()); | 597 ASSERT_EQ(1U, values.size()); |
| (...skipping 15 matching lines...) Expand all Loading... |
| 492 forms.push_back(form); | 613 forms.push_back(form); |
| 493 autofill_manager_->FormsSeen(forms); | 614 autofill_manager_->FormsSeen(forms); |
| 494 | 615 |
| 495 // The page ID sent to the AutoFillManager from the RenderView, used to send | 616 // The page ID sent to the AutoFillManager from the RenderView, used to send |
| 496 // an IPC message back to the renderer. | 617 // an IPC message back to the renderer. |
| 497 const int kPageID = 1; | 618 const int kPageID = 1; |
| 498 | 619 |
| 499 webkit_glue::FormField field; | 620 webkit_glue::FormField field; |
| 500 autofill_test::CreateTestFormField( | 621 autofill_test::CreateTestFormField( |
| 501 "Name on Card", "nameoncard", "", "text", &field); | 622 "Name on Card", "nameoncard", "", "text", &field); |
| 502 EXPECT_TRUE(autofill_manager_->GetAutoFillSuggestions(kPageID, false, field)); | 623 rvh()->ResetAutoFillState(kPageID); |
| 624 EXPECT_TRUE(autofill_manager_->GetAutoFillSuggestions(false, field)); |
| 503 | 625 |
| 504 // No suggestions provided, so send an empty vector as the results. | 626 // No suggestions provided, so send an empty vector as the results. |
| 505 // This triggers the combined message send. | 627 // This triggers the combined message send. |
| 506 rvh()->AutocompleteSuggestionsReturned(kPageID, std::vector<string16>()); | 628 rvh()->AutocompleteSuggestionsReturned(std::vector<string16>()); |
| 507 | 629 |
| 508 // Test that we sent the right message to the renderer. | 630 // Test that we sent the right message to the renderer. |
| 509 int page_id = 0; | 631 int page_id = 0; |
| 510 std::vector<string16> values; | 632 std::vector<string16> values; |
| 511 std::vector<string16> labels; | 633 std::vector<string16> labels; |
| 512 std::vector<string16> icons; | 634 std::vector<string16> icons; |
| 513 EXPECT_TRUE(GetAutoFillSuggestionsMessage(&page_id, &values, &labels, | 635 EXPECT_TRUE(GetAutoFillSuggestionsMessage(&page_id, &values, &labels, |
| 514 &icons)); | 636 &icons)); |
| 515 EXPECT_EQ(kPageID, page_id); | 637 EXPECT_EQ(kPageID, page_id); |
| 516 ASSERT_EQ(2U, values.size()); | 638 ASSERT_EQ(2U, values.size()); |
| 517 EXPECT_EQ(ASCIIToUTF16("Elvis Presley"), values[0]); | 639 EXPECT_EQ(ASCIIToUTF16("Elvis Presley"), values[0]); |
| 518 EXPECT_EQ(ASCIIToUTF16("Buddy Holly"), values[1]); | 640 EXPECT_EQ(ASCIIToUTF16("Buddy Holly"), values[1]); |
| 519 ASSERT_EQ(2U, labels.size()); | 641 ASSERT_EQ(2U, labels.size()); |
| 520 EXPECT_EQ(ASCIIToUTF16("*3456"), labels[0]); | 642 EXPECT_EQ(ASCIIToUTF16("*3456"), labels[0]); |
| 521 EXPECT_EQ(ASCIIToUTF16("*8765"), labels[1]); | 643 EXPECT_EQ(ASCIIToUTF16("*8765"), labels[1]); |
| 522 ASSERT_EQ(2U, icons.size()); | 644 ASSERT_EQ(2U, icons.size()); |
| 523 EXPECT_EQ(ASCIIToUTF16("visaCC"), icons[0]); | 645 EXPECT_EQ(ASCIIToUTF16("visaCC"), icons[0]); |
| 524 EXPECT_EQ(ASCIIToUTF16("masterCardCC"), icons[1]); | 646 EXPECT_EQ(ASCIIToUTF16("masterCardCC"), icons[1]); |
| 525 } | 647 } |
| 526 | 648 |
| 527 // Test that we return no credit card profile suggestions when the form is not | 649 // Test that we return a warning explaining that credit card profile suggestions |
| 528 // https. | 650 // are unavailable when the form is not https. |
| 529 TEST_F(AutoFillManagerTest, GetCreditCardSuggestionsNonHTTPS) { | 651 TEST_F(AutoFillManagerTest, GetCreditCardSuggestionsNonHTTPS) { |
| 530 FormData form; | 652 FormData form; |
| 531 CreateTestCreditCardFormData(&form, false); | 653 CreateTestCreditCardFormData(&form, false); |
| 532 | 654 |
| 533 // Set up our FormStructures. | 655 // Set up our FormStructures. |
| 534 std::vector<FormData> forms; | 656 std::vector<FormData> forms; |
| 535 forms.push_back(form); | 657 forms.push_back(form); |
| 536 autofill_manager_->FormsSeen(forms); | 658 autofill_manager_->FormsSeen(forms); |
| 537 | 659 |
| 538 // The page ID sent to the AutoFillManager from the RenderView, used to send | 660 // The page ID sent to the AutoFillManager from the RenderView, used to send |
| 539 // an IPC message back to the renderer. | 661 // an IPC message back to the renderer. |
| 540 const int kPageID = 1; | 662 const int kPageID = 1; |
| 541 | 663 |
| 542 webkit_glue::FormField field; | 664 webkit_glue::FormField field; |
| 543 autofill_test::CreateTestFormField( | 665 autofill_test::CreateTestFormField( |
| 544 "Card Number", "cardnumber", "", "text", &field); | 666 "Card Number", "cardnumber", "", "text", &field); |
| 545 EXPECT_FALSE( | 667 rvh()->ResetAutoFillState(kPageID); |
| 546 autofill_manager_->GetAutoFillSuggestions(kPageID, false, field)); | 668 EXPECT_TRUE(autofill_manager_->GetAutoFillSuggestions(false, field)); |
| 669 |
| 670 // No suggestions provided, so send an empty vector as the results. |
| 671 // This triggers the combined message send. |
| 672 rvh()->AutocompleteSuggestionsReturned(std::vector<string16>()); |
| 673 |
| 674 // Test that we sent the right message to the renderer. |
| 675 int page_id = 0; |
| 676 std::vector<string16> values; |
| 677 std::vector<string16> labels; |
| 678 std::vector<string16> icons; |
| 679 EXPECT_TRUE(GetAutoFillSuggestionsMessage(&page_id, &values, &labels, |
| 680 &icons)); |
| 681 EXPECT_EQ(kPageID, page_id); |
| 682 ASSERT_EQ(1U, values.size()); |
| 683 EXPECT_EQ(l10n_util::GetStringUTF16(IDS_AUTOFILL_WARNING_INSECURE_CONNECTION), |
| 684 values[0]); |
| 685 ASSERT_EQ(1U, labels.size()); |
| 686 EXPECT_EQ(string16(), labels[0]); |
| 687 ASSERT_EQ(1U, icons.size()); |
| 688 EXPECT_EQ(string16(), icons[0]); |
| 689 |
| 690 // Now add some Autocomplete suggestions. We should show the autocomplete |
| 691 // suggestions and the warning. |
| 692 process()->sink().ClearMessages(); |
| 693 const int kPageID2 = 2; |
| 694 rvh()->ResetAutoFillState(kPageID2); |
| 695 EXPECT_TRUE(autofill_manager_->GetAutoFillSuggestions(false, field)); |
| 696 |
| 697 std::vector<string16> suggestions; |
| 698 suggestions.push_back(ASCIIToUTF16("Jay")); |
| 699 suggestions.push_back(ASCIIToUTF16("Jason")); |
| 700 rvh()->AutocompleteSuggestionsReturned(suggestions); |
| 701 |
| 702 EXPECT_TRUE(GetAutoFillSuggestionsMessage(&page_id, &values, &labels, |
| 703 &icons)); |
| 704 EXPECT_EQ(kPageID2, page_id); |
| 705 ASSERT_EQ(3U, values.size()); |
| 706 EXPECT_EQ(l10n_util::GetStringUTF16(IDS_AUTOFILL_WARNING_INSECURE_CONNECTION), |
| 707 values[0]); |
| 708 EXPECT_EQ(ASCIIToUTF16("Jay"), values[1]); |
| 709 EXPECT_EQ(ASCIIToUTF16("Jason"), values[2]); |
| 710 ASSERT_EQ(3U, labels.size()); |
| 711 EXPECT_EQ(string16(), labels[0]); |
| 712 EXPECT_EQ(string16(), labels[1]); |
| 713 EXPECT_EQ(string16(), labels[2]); |
| 714 ASSERT_EQ(3U, icons.size()); |
| 715 EXPECT_EQ(string16(), icons[0]); |
| 716 EXPECT_EQ(string16(), icons[1]); |
| 717 EXPECT_EQ(string16(), icons[2]); |
| 718 |
| 719 // Clear the test credit cards and try again -- we shouldn't return a warning. |
| 720 test_personal_data_->ClearCreditCards(); |
| 721 EXPECT_FALSE(autofill_manager_->GetAutoFillSuggestions(false, field)); |
| 547 } | 722 } |
| 548 | 723 |
| 549 // Test that we return profile and credit card suggestions for combined forms. | 724 // Test that we return profile and credit card suggestions for combined forms. |
| 550 TEST_F(AutoFillManagerTest, GetAddressAndCreditCardSuggestions) { | 725 TEST_F(AutoFillManagerTest, GetAddressAndCreditCardSuggestions) { |
| 551 FormData form; | 726 FormData form; |
| 552 CreateTestAddressFormData(&form); | 727 CreateTestAddressFormData(&form); |
| 553 CreateTestCreditCardFormData(&form, true); | 728 CreateTestCreditCardFormData(&form, true); |
| 554 | 729 |
| 555 // Set up our FormStructures. | 730 // Set up our FormStructures. |
| 556 std::vector<FormData> forms; | 731 std::vector<FormData> forms; |
| 557 forms.push_back(form); | 732 forms.push_back(form); |
| 558 autofill_manager_->FormsSeen(forms); | 733 autofill_manager_->FormsSeen(forms); |
| 559 | 734 |
| 560 // The page ID sent to the AutoFillManager from the RenderView, used to send | 735 // The page ID sent to the AutoFillManager from the RenderView, used to send |
| 561 // an IPC message back to the renderer. | 736 // an IPC message back to the renderer. |
| 562 const int kPageID = 1; | 737 const int kPageID = 1; |
| 563 | 738 |
| 564 webkit_glue::FormField field; | 739 webkit_glue::FormField field; |
| 565 autofill_test::CreateTestFormField( | 740 autofill_test::CreateTestFormField( |
| 566 "First Name", "firstname", "", "text", &field); | 741 "First Name", "firstname", "", "text", &field); |
| 567 EXPECT_TRUE(autofill_manager_->GetAutoFillSuggestions(kPageID, false, field)); | 742 rvh()->ResetAutoFillState(kPageID); |
| 743 EXPECT_TRUE(autofill_manager_->GetAutoFillSuggestions(false, field)); |
| 568 | 744 |
| 569 // No suggestions provided, so send an empty vector as the results. | 745 // No suggestions provided, so send an empty vector as the results. |
| 570 // This triggers the combined message send. | 746 // This triggers the combined message send. |
| 571 rvh()->AutocompleteSuggestionsReturned(kPageID, std::vector<string16>()); | 747 rvh()->AutocompleteSuggestionsReturned(std::vector<string16>()); |
| 572 | 748 |
| 573 // Test that we sent the right address suggestions to the renderer. | 749 // Test that we sent the right address suggestions to the renderer. |
| 574 int page_id = 0; | 750 int page_id = 0; |
| 575 std::vector<string16> values; | 751 std::vector<string16> values; |
| 576 std::vector<string16> labels; | 752 std::vector<string16> labels; |
| 577 std::vector<string16> icons; | 753 std::vector<string16> icons; |
| 578 EXPECT_TRUE(GetAutoFillSuggestionsMessage(&page_id, &values, &labels, | 754 EXPECT_TRUE(GetAutoFillSuggestionsMessage(&page_id, &values, &labels, |
| 579 &icons)); | 755 &icons)); |
| 580 EXPECT_EQ(kPageID, page_id); | 756 EXPECT_EQ(kPageID, page_id); |
| 581 ASSERT_EQ(2U, values.size()); | 757 ASSERT_EQ(2U, values.size()); |
| 582 EXPECT_EQ(ASCIIToUTF16("Elvis"), values[0]); | 758 EXPECT_EQ(ASCIIToUTF16("Elvis"), values[0]); |
| 583 EXPECT_EQ(ASCIIToUTF16("Charles"), values[1]); | 759 EXPECT_EQ(ASCIIToUTF16("Charles"), values[1]); |
| 584 ASSERT_EQ(2U, labels.size()); | 760 ASSERT_EQ(2U, labels.size()); |
| 585 // Inferred labels now include full first relevant field, which in this case | 761 // Inferred labels now include full first relevant field, which in this case |
| 586 // the address #1. | 762 // the address #1. |
| 587 EXPECT_EQ(ASCIIToUTF16("3734 Elvis Presley Blvd."), labels[0]); | 763 EXPECT_EQ(ASCIIToUTF16("3734 Elvis Presley Blvd."), labels[0]); |
| 588 EXPECT_EQ(ASCIIToUTF16("123 Apple St."), labels[1]); | 764 EXPECT_EQ(ASCIIToUTF16("123 Apple St."), labels[1]); |
| 589 ASSERT_EQ(2U, icons.size()); | 765 ASSERT_EQ(2U, icons.size()); |
| 590 EXPECT_EQ(string16(), icons[0]); | 766 EXPECT_EQ(string16(), icons[0]); |
| 591 EXPECT_EQ(string16(), icons[1]); | 767 EXPECT_EQ(string16(), icons[1]); |
| 592 | 768 |
| 593 process()->sink().ClearMessages(); | 769 process()->sink().ClearMessages(); |
| 594 autofill_test::CreateTestFormField( | 770 autofill_test::CreateTestFormField( |
| 595 "Card Number", "cardnumber", "", "text", &field); | 771 "Card Number", "cardnumber", "", "text", &field); |
| 596 EXPECT_TRUE(autofill_manager_->GetAutoFillSuggestions(kPageID, false, field)); | 772 rvh()->ResetAutoFillState(kPageID); |
| 773 EXPECT_TRUE(autofill_manager_->GetAutoFillSuggestions(false, field)); |
| 597 | 774 |
| 598 // No suggestions provided, so send an empty vector as the results. | 775 // No suggestions provided, so send an empty vector as the results. |
| 599 // This triggers the combined message send. | 776 // This triggers the combined message send. |
| 600 rvh()->AutocompleteSuggestionsReturned(kPageID, std::vector<string16>()); | 777 rvh()->AutocompleteSuggestionsReturned(std::vector<string16>()); |
| 601 | 778 |
| 602 // Test that we sent the credit card suggestions to the renderer. | 779 // Test that we sent the credit card suggestions to the renderer. |
| 603 page_id = 0; | 780 page_id = 0; |
| 604 EXPECT_TRUE(GetAutoFillSuggestionsMessage(&page_id, &values, &labels, | 781 EXPECT_TRUE(GetAutoFillSuggestionsMessage(&page_id, &values, &labels, |
| 605 &icons)); | 782 &icons)); |
| 606 EXPECT_EQ(kPageID, page_id); | 783 EXPECT_EQ(kPageID, page_id); |
| 607 ASSERT_EQ(2U, values.size()); | 784 ASSERT_EQ(2U, values.size()); |
| 608 EXPECT_EQ(ASCIIToUTF16("************3456"), values[0]); | 785 EXPECT_EQ(ASCIIToUTF16("************3456"), values[0]); |
| 609 EXPECT_EQ(ASCIIToUTF16("************8765"), values[1]); | 786 EXPECT_EQ(ASCIIToUTF16("************8765"), values[1]); |
| 610 ASSERT_EQ(2U, labels.size()); | 787 ASSERT_EQ(2U, labels.size()); |
| 611 EXPECT_EQ(ASCIIToUTF16("*3456"), labels[0]); | 788 EXPECT_EQ(ASCIIToUTF16("*3456"), labels[0]); |
| 612 EXPECT_EQ(ASCIIToUTF16("*8765"), labels[1]); | 789 EXPECT_EQ(ASCIIToUTF16("*8765"), labels[1]); |
| 613 ASSERT_EQ(2U, icons.size()); | 790 ASSERT_EQ(2U, icons.size()); |
| 614 EXPECT_EQ(ASCIIToUTF16("visaCC"), icons[0]); | 791 EXPECT_EQ(ASCIIToUTF16("visaCC"), icons[0]); |
| 615 EXPECT_EQ(ASCIIToUTF16("masterCardCC"), icons[1]); | 792 EXPECT_EQ(ASCIIToUTF16("masterCardCC"), icons[1]); |
| 616 } | 793 } |
| 617 | 794 |
| 618 // Test that for non-https forms with both address and credit card fields, we | 795 // Test that for non-https forms with both address and credit card fields, we |
| 619 // only return address suggestions. | 796 // only return address suggestions. Instead of credit card suggestions, we |
| 797 // should return a warning explaining that credit card profile suggestions are |
| 798 // unavailable when the form is not https. |
| 620 TEST_F(AutoFillManagerTest, GetAddressAndCreditCardSuggestionsNonHttps) { | 799 TEST_F(AutoFillManagerTest, GetAddressAndCreditCardSuggestionsNonHttps) { |
| 621 FormData form; | 800 FormData form; |
| 622 CreateTestAddressFormData(&form); | 801 CreateTestAddressFormData(&form); |
| 623 CreateTestCreditCardFormData(&form, false); | 802 CreateTestCreditCardFormData(&form, false); |
| 624 | 803 |
| 625 // Set up our FormStructures. | 804 // Set up our FormStructures. |
| 626 std::vector<FormData> forms; | 805 std::vector<FormData> forms; |
| 627 forms.push_back(form); | 806 forms.push_back(form); |
| 628 autofill_manager_->FormsSeen(forms); | 807 autofill_manager_->FormsSeen(forms); |
| 629 | 808 |
| 630 // The page ID sent to the AutoFillManager from the RenderView, used to send | 809 // The page ID sent to the AutoFillManager from the RenderView, used to send |
| 631 // an IPC message back to the renderer. | 810 // an IPC message back to the renderer. |
| 632 const int kPageID = 1; | 811 const int kPageID = 1; |
| 633 | 812 |
| 634 webkit_glue::FormField field; | 813 webkit_glue::FormField field; |
| 635 autofill_test::CreateTestFormField( | 814 autofill_test::CreateTestFormField( |
| 636 "First Name", "firstname", "", "text", &field); | 815 "First Name", "firstname", "", "text", &field); |
| 637 EXPECT_TRUE(autofill_manager_->GetAutoFillSuggestions(kPageID, false, field)); | 816 rvh()->ResetAutoFillState(kPageID); |
| 817 EXPECT_TRUE(autofill_manager_->GetAutoFillSuggestions(false, field)); |
| 638 | 818 |
| 639 // No suggestions provided, so send an empty vector as the results. | 819 // No suggestions provided, so send an empty vector as the results. |
| 640 // This triggers the combined message send. | 820 // This triggers the combined message send. |
| 641 rvh()->AutocompleteSuggestionsReturned(kPageID, std::vector<string16>()); | 821 rvh()->AutocompleteSuggestionsReturned(std::vector<string16>()); |
| 642 | 822 |
| 643 // Test that we sent the right address suggestions to the renderer. | 823 // Test that we sent the right address suggestions to the renderer. |
| 644 int page_id = 0; | 824 int page_id = 0; |
| 645 std::vector<string16> values; | 825 std::vector<string16> values; |
| 646 std::vector<string16> labels; | 826 std::vector<string16> labels; |
| 647 std::vector<string16> icons; | 827 std::vector<string16> icons; |
| 648 EXPECT_TRUE(GetAutoFillSuggestionsMessage(&page_id, &values, &labels, | 828 EXPECT_TRUE(GetAutoFillSuggestionsMessage(&page_id, &values, &labels, |
| 649 &icons)); | 829 &icons)); |
| 650 EXPECT_EQ(kPageID, page_id); | 830 EXPECT_EQ(kPageID, page_id); |
| 651 ASSERT_EQ(2U, values.size()); | 831 ASSERT_EQ(2U, values.size()); |
| 652 EXPECT_EQ(ASCIIToUTF16("Elvis"), values[0]); | 832 EXPECT_EQ(ASCIIToUTF16("Elvis"), values[0]); |
| 653 EXPECT_EQ(ASCIIToUTF16("Charles"), values[1]); | 833 EXPECT_EQ(ASCIIToUTF16("Charles"), values[1]); |
| 654 ASSERT_EQ(2U, labels.size()); | 834 ASSERT_EQ(2U, labels.size()); |
| 655 // Inferred labels now include full first relevant field, which in this case | 835 // Inferred labels now include full first relevant field, which in this case |
| 656 // the address #1. | 836 // the address #1. |
| 657 EXPECT_EQ(ASCIIToUTF16("3734 Elvis Presley Blvd."), labels[0]); | 837 EXPECT_EQ(ASCIIToUTF16("3734 Elvis Presley Blvd."), labels[0]); |
| 658 EXPECT_EQ(ASCIIToUTF16("123 Apple St."), labels[1]); | 838 EXPECT_EQ(ASCIIToUTF16("123 Apple St."), labels[1]); |
| 659 ASSERT_EQ(2U, icons.size()); | 839 ASSERT_EQ(2U, icons.size()); |
| 660 EXPECT_EQ(string16(), icons[0]); | 840 EXPECT_EQ(string16(), icons[0]); |
| 661 EXPECT_EQ(string16(), icons[1]); | 841 EXPECT_EQ(string16(), icons[1]); |
| 662 | 842 |
| 843 process()->sink().ClearMessages(); |
| 663 autofill_test::CreateTestFormField( | 844 autofill_test::CreateTestFormField( |
| 664 "Card Number", "cardnumber", "", "text", &field); | 845 "Card Number", "cardnumber", "", "text", &field); |
| 665 EXPECT_FALSE( | 846 rvh()->ResetAutoFillState(kPageID); |
| 666 autofill_manager_->GetAutoFillSuggestions(kPageID, false, field)); | 847 EXPECT_TRUE(autofill_manager_->GetAutoFillSuggestions(false, field)); |
| 848 |
| 849 // No suggestions provided, so send an empty vector as the results. |
| 850 // This triggers the combined message send. |
| 851 rvh()->AutocompleteSuggestionsReturned(std::vector<string16>()); |
| 852 |
| 853 // Test that we sent the right message to the renderer. |
| 854 EXPECT_TRUE(GetAutoFillSuggestionsMessage(&page_id, &values, &labels, |
| 855 &icons)); |
| 856 EXPECT_EQ(kPageID, page_id); |
| 857 ASSERT_EQ(1U, values.size()); |
| 858 EXPECT_EQ(l10n_util::GetStringUTF16(IDS_AUTOFILL_WARNING_INSECURE_CONNECTION), |
| 859 values[0]); |
| 860 ASSERT_EQ(1U, labels.size()); |
| 861 EXPECT_EQ(string16(), labels[0]); |
| 862 ASSERT_EQ(1U, icons.size()); |
| 863 EXPECT_EQ(string16(), icons[0]); |
| 864 |
| 865 // Clear the test credit cards and try again -- we shouldn't return a warning. |
| 866 test_personal_data_->ClearCreditCards(); |
| 867 EXPECT_FALSE(autofill_manager_->GetAutoFillSuggestions(false, field)); |
| 667 } | 868 } |
| 668 | 869 |
| 669 // Test that we correctly combine autofill and autocomplete suggestions. | 870 // Test that we correctly combine autofill and autocomplete suggestions. |
| 670 TEST_F(AutoFillManagerTest, GetCombinedAutoFillAndAutocompleteSuggestions) { | 871 TEST_F(AutoFillManagerTest, GetCombinedAutoFillAndAutocompleteSuggestions) { |
| 671 FormData form; | 872 FormData form; |
| 672 CreateTestAddressFormData(&form); | 873 CreateTestAddressFormData(&form); |
| 673 | 874 |
| 674 // Set up our FormStructures. | 875 // Set up our FormStructures. |
| 675 std::vector<FormData> forms; | 876 std::vector<FormData> forms; |
| 676 forms.push_back(form); | 877 forms.push_back(form); |
| 677 autofill_manager_->FormsSeen(forms); | 878 autofill_manager_->FormsSeen(forms); |
| 678 | 879 |
| 679 // The page ID sent to the AutoFillManager from the RenderView, used to send | 880 // The page ID sent to the AutoFillManager from the RenderView, used to send |
| 680 // an IPC message back to the renderer. | 881 // an IPC message back to the renderer. |
| 681 const int kPageID = 1; | 882 const int kPageID = 1; |
| 682 | 883 |
| 683 webkit_glue::FormField field; | 884 webkit_glue::FormField field; |
| 684 autofill_test::CreateTestFormField( | 885 autofill_test::CreateTestFormField( |
| 685 "First Name", "firstname", "", "text", &field); | 886 "First Name", "firstname", "", "text", &field); |
| 686 EXPECT_TRUE(autofill_manager_->GetAutoFillSuggestions(kPageID, false, field)); | 887 rvh()->ResetAutoFillState(kPageID); |
| 888 EXPECT_TRUE(autofill_manager_->GetAutoFillSuggestions(false, field)); |
| 687 | 889 |
| 688 // Add some Autocomplete suggestions. | 890 // Add some Autocomplete suggestions. |
| 689 // This triggers the combined message send. | 891 // This triggers the combined message send. |
| 690 std::vector<string16> suggestions; | 892 std::vector<string16> suggestions; |
| 691 suggestions.push_back(ASCIIToUTF16("Jay")); | 893 suggestions.push_back(ASCIIToUTF16("Jay")); |
| 692 suggestions.push_back(ASCIIToUTF16("Jason")); | 894 suggestions.push_back(ASCIIToUTF16("Jason")); |
| 693 rvh()->AutocompleteSuggestionsReturned(kPageID, suggestions); | 895 rvh()->AutocompleteSuggestionsReturned(suggestions); |
| 694 | 896 |
| 695 // Test that we sent the right message to the renderer. | 897 // Test that we sent the right message to the renderer. |
| 696 int page_id = 0; | 898 int page_id = 0; |
| 697 std::vector<string16> values; | 899 std::vector<string16> values; |
| 698 std::vector<string16> labels; | 900 std::vector<string16> labels; |
| 699 std::vector<string16> icons; | 901 std::vector<string16> icons; |
| 700 EXPECT_TRUE(GetAutoFillSuggestionsMessage(&page_id, &values, &labels, | 902 EXPECT_TRUE(GetAutoFillSuggestionsMessage(&page_id, &values, &labels, |
| 701 &icons)); | 903 &icons)); |
| 702 EXPECT_EQ(kPageID, page_id); | 904 EXPECT_EQ(kPageID, page_id); |
| 703 ASSERT_EQ(4U, values.size()); | 905 ASSERT_EQ(4U, values.size()); |
| (...skipping 24 matching lines...) Expand all Loading... |
| 728 forms.push_back(form); | 930 forms.push_back(form); |
| 729 autofill_manager_->FormsSeen(forms); | 931 autofill_manager_->FormsSeen(forms); |
| 730 | 932 |
| 731 // The page ID sent to the AutoFillManager from the RenderView, used to send | 933 // The page ID sent to the AutoFillManager from the RenderView, used to send |
| 732 // an IPC message back to the renderer. | 934 // an IPC message back to the renderer. |
| 733 const int kPageID = 1; | 935 const int kPageID = 1; |
| 734 | 936 |
| 735 webkit_glue::FormField field; | 937 webkit_glue::FormField field; |
| 736 autofill_test::CreateTestFormField( | 938 autofill_test::CreateTestFormField( |
| 737 "First Name", "firstname", "", "text", &field); | 939 "First Name", "firstname", "", "text", &field); |
| 738 EXPECT_TRUE(autofill_manager_->GetAutoFillSuggestions(kPageID, true, field)); | 940 rvh()->ResetAutoFillState(kPageID); |
| 941 EXPECT_TRUE(autofill_manager_->GetAutoFillSuggestions(true, field)); |
| 739 | 942 |
| 740 // No suggestions provided, so send an empty vector as the results. | 943 // No suggestions provided, so send an empty vector as the results. |
| 741 // This triggers the combined message send. | 944 // This triggers the combined message send. |
| 742 rvh()->AutocompleteSuggestionsReturned(kPageID, std::vector<string16>()); | 945 rvh()->AutocompleteSuggestionsReturned(std::vector<string16>()); |
| 743 | 946 |
| 744 // Test that we sent the right message to the renderer. | 947 // Test that we sent the right message to the renderer. |
| 745 int page_id = 0; | 948 int page_id = 0; |
| 746 std::vector<string16> values; | 949 std::vector<string16> values; |
| 747 std::vector<string16> labels; | 950 std::vector<string16> labels; |
| 748 std::vector<string16> icons; | 951 std::vector<string16> icons; |
| 749 EXPECT_TRUE(GetAutoFillSuggestionsMessage(&page_id, &values, &labels, | 952 EXPECT_TRUE(GetAutoFillSuggestionsMessage(&page_id, &values, &labels, |
| 750 &icons)); | 953 &icons)); |
| 751 EXPECT_EQ(kPageID, page_id); | 954 EXPECT_EQ(kPageID, page_id); |
| 752 ASSERT_EQ(2U, values.size()); | 955 ASSERT_EQ(2U, values.size()); |
| (...skipping 18 matching lines...) Expand all Loading... |
| 771 forms.push_back(form); | 974 forms.push_back(form); |
| 772 autofill_manager_->FormsSeen(forms); | 975 autofill_manager_->FormsSeen(forms); |
| 773 | 976 |
| 774 // The page ID sent to the AutoFillManager from the RenderView, used to send | 977 // The page ID sent to the AutoFillManager from the RenderView, used to send |
| 775 // an IPC message back to the renderer. | 978 // an IPC message back to the renderer. |
| 776 const int kPageID = 1; | 979 const int kPageID = 1; |
| 777 | 980 |
| 778 webkit_glue::FormField field; | 981 webkit_glue::FormField field; |
| 779 autofill_test::CreateTestFormField( | 982 autofill_test::CreateTestFormField( |
| 780 "Some Field", "somefield", "", "text", &field); | 983 "Some Field", "somefield", "", "text", &field); |
| 781 EXPECT_FALSE(autofill_manager_->GetAutoFillSuggestions(kPageID, true, field)); | 984 rvh()->ResetAutoFillState(kPageID); |
| 985 EXPECT_FALSE(autofill_manager_->GetAutoFillSuggestions(true, field)); |
| 782 | 986 |
| 783 // Add some Autocomplete suggestions. | 987 // Add some Autocomplete suggestions. |
| 784 // This triggers the combined message send. | 988 // This triggers the combined message send. |
| 785 std::vector<string16> suggestions; | 989 std::vector<string16> suggestions; |
| 786 suggestions.push_back(ASCIIToUTF16("one")); | 990 suggestions.push_back(ASCIIToUTF16("one")); |
| 787 suggestions.push_back(ASCIIToUTF16("two")); | 991 suggestions.push_back(ASCIIToUTF16("two")); |
| 788 rvh()->AutocompleteSuggestionsReturned(kPageID, suggestions); | 992 rvh()->AutocompleteSuggestionsReturned(suggestions); |
| 789 | 993 |
| 790 // Test that we sent the right message to the renderer. | 994 // Test that we sent the right message to the renderer. |
| 791 int page_id = 0; | 995 int page_id = 0; |
| 792 std::vector<string16> values; | 996 std::vector<string16> values; |
| 793 std::vector<string16> labels; | 997 std::vector<string16> labels; |
| 794 std::vector<string16> icons; | 998 std::vector<string16> icons; |
| 795 EXPECT_TRUE(GetAutoFillSuggestionsMessage(&page_id, &values, &labels, | 999 EXPECT_TRUE(GetAutoFillSuggestionsMessage(&page_id, &values, &labels, |
| 796 &icons)); | 1000 &icons)); |
| 797 EXPECT_EQ(kPageID, page_id); | 1001 EXPECT_EQ(kPageID, page_id); |
| 798 ASSERT_EQ(2U, values.size()); | 1002 ASSERT_EQ(2U, values.size()); |
| (...skipping 24 matching lines...) Expand all Loading... |
| 823 "", "", "", "", "", "", "", ""); | 1027 "", "", "", "", "", "", "", ""); |
| 824 autofill_manager_->AddProfile(profile); | 1028 autofill_manager_->AddProfile(profile); |
| 825 | 1029 |
| 826 // The page ID sent to the AutoFillManager from the RenderView, used to send | 1030 // The page ID sent to the AutoFillManager from the RenderView, used to send |
| 827 // an IPC message back to the renderer. | 1031 // an IPC message back to the renderer. |
| 828 const int kPageID = 1; | 1032 const int kPageID = 1; |
| 829 | 1033 |
| 830 webkit_glue::FormField field; | 1034 webkit_glue::FormField field; |
| 831 autofill_test::CreateTestFormField( | 1035 autofill_test::CreateTestFormField( |
| 832 "First Name", "firstname", "", "text", &field); | 1036 "First Name", "firstname", "", "text", &field); |
| 833 EXPECT_TRUE(autofill_manager_->GetAutoFillSuggestions(kPageID, true, field)); | 1037 rvh()->ResetAutoFillState(kPageID); |
| 1038 EXPECT_TRUE(autofill_manager_->GetAutoFillSuggestions(true, field)); |
| 834 | 1039 |
| 835 // No suggestions provided, so send an empty vector as the results. | 1040 // No suggestions provided, so send an empty vector as the results. |
| 836 // This triggers the combined message send. | 1041 // This triggers the combined message send. |
| 837 rvh()->AutocompleteSuggestionsReturned(kPageID, std::vector<string16>()); | 1042 rvh()->AutocompleteSuggestionsReturned(std::vector<string16>()); |
| 838 | 1043 |
| 839 // Test that we sent the right message to the renderer. | 1044 // Test that we sent the right message to the renderer. |
| 840 int page_id = 0; | 1045 int page_id = 0; |
| 841 std::vector<string16> values; | 1046 std::vector<string16> values; |
| 842 std::vector<string16> labels; | 1047 std::vector<string16> labels; |
| 843 std::vector<string16> icons; | 1048 std::vector<string16> icons; |
| 844 EXPECT_TRUE(GetAutoFillSuggestionsMessage(&page_id, &values, &labels, | 1049 EXPECT_TRUE(GetAutoFillSuggestionsMessage(&page_id, &values, &labels, |
| 845 &icons)); | 1050 &icons)); |
| 846 EXPECT_EQ(kPageID, page_id); | 1051 EXPECT_EQ(kPageID, page_id); |
| 847 ASSERT_EQ(2U, values.size()); | 1052 ASSERT_EQ(2U, values.size()); |
| (...skipping 525 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1373 ASSERT_FALSE(profile()->GetPrefs()->GetBoolean( | 1578 ASSERT_FALSE(profile()->GetPrefs()->GetBoolean( |
| 1374 prefs::kAutoFillAuxiliaryProfilesEnabled)); | 1579 prefs::kAutoFillAuxiliaryProfilesEnabled)); |
| 1375 profile()->GetPrefs()->SetBoolean( | 1580 profile()->GetPrefs()->SetBoolean( |
| 1376 prefs::kAutoFillAuxiliaryProfilesEnabled, true); | 1581 prefs::kAutoFillAuxiliaryProfilesEnabled, true); |
| 1377 profile()->GetPrefs()->ClearPref(prefs::kAutoFillAuxiliaryProfilesEnabled); | 1582 profile()->GetPrefs()->ClearPref(prefs::kAutoFillAuxiliaryProfilesEnabled); |
| 1378 ASSERT_FALSE(profile()->GetPrefs()->GetBoolean( | 1583 ASSERT_FALSE(profile()->GetPrefs()->GetBoolean( |
| 1379 prefs::kAutoFillAuxiliaryProfilesEnabled)); | 1584 prefs::kAutoFillAuxiliaryProfilesEnabled)); |
| 1380 #endif | 1585 #endif |
| 1381 } | 1586 } |
| 1382 | 1587 |
| OLD | NEW |