| 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, false); |
| 313 EXPECT_TRUE(autofill_manager_->GetAutoFillSuggestions(false, field, false)); |
| 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, false); |
| 359 EXPECT_TRUE(autofill_manager_->GetAutoFillSuggestions(false, field, false)); |
| 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, false); |
| 397 EXPECT_FALSE( | 416 EXPECT_FALSE( |
| 398 autofill_manager_->GetAutoFillSuggestions(kPageID, false, field)); | 417 autofill_manager_->GetAutoFillSuggestions(false, field, false)); |
| 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, false); |
| 441 EXPECT_FALSE(autofill_manager_->GetAutoFillSuggestions(false, field, false)); |
| 442 } |
| 443 |
| 444 // Test that we return a warning explaining that autofill suggestions are |
| 445 // unavailable when the website specifies autocomplete="off". |
| 446 TEST_F(AutoFillManagerTest, GetProfileSuggestionsAutofillDisabledByForm) { |
| 447 FormData form; |
| 448 CreateTestAddressFormData(&form); |
| 449 |
| 450 // Set up our FormStructures. |
| 451 std::vector<FormData> forms; |
| 452 forms.push_back(form); |
| 453 autofill_manager_->FormsSeen(forms); |
| 454 |
| 455 // The page ID sent to the AutoFillManager from the RenderView, used to send |
| 456 // an IPC message back to the renderer. |
| 457 const int kPageID = 1; |
| 458 |
| 459 webkit_glue::FormField field; |
| 460 autofill_test::CreateTestFormField( |
| 461 "First Name", "firstname", "", "text", &field); |
| 462 rvh()->ResetAutoFillState(kPageID, true); |
| 463 EXPECT_TRUE(autofill_manager_->GetAutoFillSuggestions(false, field, true)); |
| 464 |
| 465 // No suggestions provided, so send an empty vector as the results. |
| 466 // This triggers the combined message send. |
| 467 rvh()->AutocompleteSuggestionsReturned(std::vector<string16>()); |
| 468 |
| 469 // Test that we sent the right message to the renderer. |
| 470 int page_id = 0; |
| 471 std::vector<string16> values; |
| 472 std::vector<string16> labels; |
| 473 std::vector<string16> icons; |
| 474 EXPECT_TRUE(GetAutoFillSuggestionsMessage(&page_id, &values, &labels, |
| 475 &icons)); |
| 476 EXPECT_EQ(kPageID, page_id); |
| 477 ASSERT_EQ(1U, values.size()); |
| 478 EXPECT_EQ(l10n_util::GetStringUTF16(IDS_AUTOFILL_WARNING_AUTOFILL_DISABLED), |
| 479 values[0]); |
| 480 ASSERT_EQ(1U, labels.size()); |
| 481 EXPECT_EQ(string16(), labels[0]); |
| 482 ASSERT_EQ(1U, icons.size()); |
| 483 EXPECT_EQ(string16(), icons[0]); |
| 484 |
| 485 // Clear the test profiles and try again -- we shouldn't return a warning. |
| 486 process()->sink().ClearMessages(); |
| 487 const int kPageID2 = 2; |
| 488 rvh()->ResetAutoFillState(kPageID2, true); |
| 489 |
| 490 test_personal_data_->ClearAutoFillProfiles(); |
| 491 EXPECT_FALSE(autofill_manager_->GetAutoFillSuggestions(false, field, true)); |
| 492 |
| 493 // Now add some Autocomplete suggestions. We should now return the same |
| 494 // warning as before. |
| 495 std::vector<string16> suggestions; |
| 496 suggestions.push_back(ASCIIToUTF16("Jay")); |
| 497 suggestions.push_back(ASCIIToUTF16("Jason")); |
| 498 rvh()->AutocompleteSuggestionsReturned(suggestions); |
| 499 |
| 500 EXPECT_TRUE(GetAutoFillSuggestionsMessage(&page_id, &values, &labels, |
| 501 &icons)); |
| 502 EXPECT_EQ(kPageID2, page_id); |
| 503 ASSERT_EQ(1U, values.size()); |
| 504 EXPECT_EQ(l10n_util::GetStringUTF16(IDS_AUTOFILL_WARNING_AUTOFILL_DISABLED), |
| 505 values[0]); |
| 506 ASSERT_EQ(1U, labels.size()); |
| 507 EXPECT_EQ(string16(), labels[0]); |
| 508 ASSERT_EQ(1U, icons.size()); |
| 509 EXPECT_EQ(string16(), icons[0]); |
| 510 } |
| 511 |
| 512 // Test that we return no warning when autofill is disabled by the user and also |
| 513 // the website specifies autocomplete="off". |
| 514 TEST_F(AutoFillManagerTest, GetProfileSuggestionsAutofillDisabledByBoth) { |
| 515 FormData form; |
| 516 CreateTestAddressFormData(&form); |
| 517 |
| 518 // Set up our FormStructures. |
| 519 std::vector<FormData> forms; |
| 520 forms.push_back(form); |
| 521 autofill_manager_->FormsSeen(forms); |
| 522 |
| 523 // Disable AutoFill. |
| 524 autofill_manager_->set_autofill_enabled(false); |
| 525 |
| 526 // The page ID sent to the AutoFillManager from the RenderView, used to send |
| 527 // an IPC message back to the renderer. |
| 528 const int kPageID = 1; |
| 529 |
| 530 webkit_glue::FormField field; |
| 531 autofill_test::CreateTestFormField( |
| 532 "First Name", "firstname", "", "text", &field); |
| 533 rvh()->ResetAutoFillState(kPageID, true); |
| 534 EXPECT_FALSE(autofill_manager_->GetAutoFillSuggestions(false, field, true)); |
| 535 } |
| 536 |
| 537 // Test that we return a warning explaining that autofill suggestions are |
| 538 // unavailable when the form method is GET rather than POST. |
| 539 TEST_F(AutoFillManagerTest, GetProfileSuggestionsMethodGet) { |
| 540 FormData form; |
| 541 CreateTestAddressFormData(&form); |
| 542 form.method = ASCIIToUTF16("GET"); |
| 543 |
| 544 // Set up our FormStructures. |
| 545 std::vector<FormData> forms; |
| 546 forms.push_back(form); |
| 547 autofill_manager_->FormsSeen(forms); |
| 548 |
| 549 // The page ID sent to the AutoFillManager from the RenderView, used to send |
| 550 // an IPC message back to the renderer. |
| 551 const int kPageID = 1; |
| 552 |
| 553 webkit_glue::FormField field; |
| 554 autofill_test::CreateTestFormField( |
| 555 "First Name", "firstname", "", "text", &field); |
| 556 rvh()->ResetAutoFillState(kPageID, false); |
| 557 EXPECT_TRUE(autofill_manager_->GetAutoFillSuggestions(false, field, false)); |
| 558 |
| 559 // No suggestions provided, so send an empty vector as the results. |
| 560 // This triggers the combined message send. |
| 561 rvh()->AutocompleteSuggestionsReturned(std::vector<string16>()); |
| 562 |
| 563 // Test that we sent the right message to the renderer. |
| 564 int page_id = 0; |
| 565 std::vector<string16> values; |
| 566 std::vector<string16> labels; |
| 567 std::vector<string16> icons; |
| 568 EXPECT_TRUE(GetAutoFillSuggestionsMessage(&page_id, &values, &labels, |
| 569 &icons)); |
| 570 EXPECT_EQ(kPageID, page_id); |
| 571 ASSERT_EQ(1U, values.size()); |
| 572 EXPECT_EQ(l10n_util::GetStringUTF16(IDS_AUTOFILL_WARNING_AUTOFILL_DISABLED), |
| 573 values[0]); |
| 574 ASSERT_EQ(1U, labels.size()); |
| 575 EXPECT_EQ(string16(), labels[0]); |
| 576 ASSERT_EQ(1U, icons.size()); |
| 577 EXPECT_EQ(string16(), icons[0]); |
| 578 |
| 579 // Now add some Autocomplete suggestions. We should show the autocomplete |
| 580 // suggestions rather than the warning. |
| 581 process()->sink().ClearMessages(); |
| 582 const int kPageID2 = 2; |
| 583 rvh()->ResetAutoFillState(kPageID2, false); |
| 584 EXPECT_TRUE(autofill_manager_->GetAutoFillSuggestions(false, field, false)); |
| 585 |
| 586 std::vector<string16> suggestions; |
| 587 suggestions.push_back(ASCIIToUTF16("Jay")); |
| 588 suggestions.push_back(ASCIIToUTF16("Jason")); |
| 589 rvh()->AutocompleteSuggestionsReturned(suggestions); |
| 590 |
| 591 EXPECT_TRUE(GetAutoFillSuggestionsMessage(&page_id, &values, &labels, |
| 592 &icons)); |
| 593 EXPECT_EQ(kPageID2, page_id); |
| 594 ASSERT_EQ(2U, values.size()); |
| 595 EXPECT_EQ(ASCIIToUTF16("Jay"), values[0]); |
| 596 EXPECT_EQ(ASCIIToUTF16("Jason"), values[1]); |
| 597 ASSERT_EQ(2U, labels.size()); |
| 598 EXPECT_EQ(string16(), labels[0]); |
| 599 EXPECT_EQ(string16(), labels[1]); |
| 600 ASSERT_EQ(2U, icons.size()); |
| 601 EXPECT_EQ(string16(), icons[0]); |
| 602 EXPECT_EQ(string16(), icons[1]); |
| 603 |
| 604 // Now clear the test profiles and try again -- we shouldn't return a warning. |
| 605 test_personal_data_->ClearAutoFillProfiles(); |
| 606 EXPECT_FALSE(autofill_manager_->GetAutoFillSuggestions(false, field, false)); |
| 399 } | 607 } |
| 400 | 608 |
| 401 // Test that we return all credit card profile suggestions when all form fields | 609 // Test that we return all credit card profile suggestions when all form fields |
| 402 // are empty. | 610 // are empty. |
| 403 TEST_F(AutoFillManagerTest, GetCreditCardSuggestionsEmptyValue) { | 611 TEST_F(AutoFillManagerTest, GetCreditCardSuggestionsEmptyValue) { |
| 404 FormData form; | 612 FormData form; |
| 405 CreateTestCreditCardFormData(&form, true); | 613 CreateTestCreditCardFormData(&form, true); |
| 406 | 614 |
| 407 // Set up our FormStructures. | 615 // Set up our FormStructures. |
| 408 std::vector<FormData> forms; | 616 std::vector<FormData> forms; |
| 409 forms.push_back(form); | 617 forms.push_back(form); |
| 410 autofill_manager_->FormsSeen(forms); | 618 autofill_manager_->FormsSeen(forms); |
| 411 | 619 |
| 412 // The page ID sent to the AutoFillManager from the RenderView, used to send | 620 // The page ID sent to the AutoFillManager from the RenderView, used to send |
| 413 // an IPC message back to the renderer. | 621 // an IPC message back to the renderer. |
| 414 const int kPageID = 1; | 622 const int kPageID = 1; |
| 415 | 623 |
| 416 webkit_glue::FormField field; | 624 webkit_glue::FormField field; |
| 417 autofill_test::CreateTestFormField( | 625 autofill_test::CreateTestFormField( |
| 418 "Card Number", "cardnumber", "", "text", &field); | 626 "Card Number", "cardnumber", "", "text", &field); |
| 419 EXPECT_TRUE(autofill_manager_->GetAutoFillSuggestions(kPageID, false, field)); | 627 rvh()->ResetAutoFillState(kPageID, false); |
| 628 EXPECT_TRUE(autofill_manager_->GetAutoFillSuggestions(false, field, false)); |
| 420 | 629 |
| 421 // No suggestions provided, so send an empty vector as the results. | 630 // No suggestions provided, so send an empty vector as the results. |
| 422 // This triggers the combined message send. | 631 // This triggers the combined message send. |
| 423 rvh()->AutocompleteSuggestionsReturned(kPageID, std::vector<string16>()); | 632 rvh()->AutocompleteSuggestionsReturned(std::vector<string16>()); |
| 424 | 633 |
| 425 // Test that we sent the right message to the renderer. | 634 // Test that we sent the right message to the renderer. |
| 426 int page_id = 0; | 635 int page_id = 0; |
| 427 std::vector<string16> values; | 636 std::vector<string16> values; |
| 428 std::vector<string16> labels; | 637 std::vector<string16> labels; |
| 429 std::vector<string16> icons; | 638 std::vector<string16> icons; |
| 430 EXPECT_TRUE(GetAutoFillSuggestionsMessage(&page_id, &values, &labels, | 639 EXPECT_TRUE(GetAutoFillSuggestionsMessage(&page_id, &values, &labels, |
| 431 &icons)); | 640 &icons)); |
| 432 EXPECT_EQ(kPageID, page_id); | 641 EXPECT_EQ(kPageID, page_id); |
| 433 ASSERT_EQ(2U, values.size()); | 642 ASSERT_EQ(2U, values.size()); |
| (...skipping 18 matching lines...) Expand all Loading... |
| 452 forms.push_back(form); | 661 forms.push_back(form); |
| 453 autofill_manager_->FormsSeen(forms); | 662 autofill_manager_->FormsSeen(forms); |
| 454 | 663 |
| 455 // The page ID sent to the AutoFillManager from the RenderView, used to send | 664 // The page ID sent to the AutoFillManager from the RenderView, used to send |
| 456 // an IPC message back to the renderer. | 665 // an IPC message back to the renderer. |
| 457 const int kPageID = 1; | 666 const int kPageID = 1; |
| 458 | 667 |
| 459 webkit_glue::FormField field; | 668 webkit_glue::FormField field; |
| 460 autofill_test::CreateTestFormField( | 669 autofill_test::CreateTestFormField( |
| 461 "Card Number", "cardnumber", "4", "text", &field); | 670 "Card Number", "cardnumber", "4", "text", &field); |
| 462 EXPECT_TRUE(autofill_manager_->GetAutoFillSuggestions(kPageID, false, field)); | 671 rvh()->ResetAutoFillState(kPageID, false); |
| 672 EXPECT_TRUE(autofill_manager_->GetAutoFillSuggestions(false, field, false)); |
| 463 | 673 |
| 464 // No suggestions provided, so send an empty vector as the results. | 674 // No suggestions provided, so send an empty vector as the results. |
| 465 // This triggers the combined message send. | 675 // This triggers the combined message send. |
| 466 rvh()->AutocompleteSuggestionsReturned(kPageID, std::vector<string16>()); | 676 rvh()->AutocompleteSuggestionsReturned(std::vector<string16>()); |
| 467 | 677 |
| 468 // Test that we sent the right message to the renderer. | 678 // Test that we sent the right message to the renderer. |
| 469 int page_id = 0; | 679 int page_id = 0; |
| 470 std::vector<string16> values; | 680 std::vector<string16> values; |
| 471 std::vector<string16> labels; | 681 std::vector<string16> labels; |
| 472 std::vector<string16> icons; | 682 std::vector<string16> icons; |
| 473 EXPECT_TRUE(GetAutoFillSuggestionsMessage(&page_id, &values, &labels, | 683 EXPECT_TRUE(GetAutoFillSuggestionsMessage(&page_id, &values, &labels, |
| 474 &icons)); | 684 &icons)); |
| 475 EXPECT_EQ(kPageID, page_id); | 685 EXPECT_EQ(kPageID, page_id); |
| 476 ASSERT_EQ(1U, values.size()); | 686 ASSERT_EQ(1U, values.size()); |
| (...skipping 15 matching lines...) Expand all Loading... |
| 492 forms.push_back(form); | 702 forms.push_back(form); |
| 493 autofill_manager_->FormsSeen(forms); | 703 autofill_manager_->FormsSeen(forms); |
| 494 | 704 |
| 495 // The page ID sent to the AutoFillManager from the RenderView, used to send | 705 // The page ID sent to the AutoFillManager from the RenderView, used to send |
| 496 // an IPC message back to the renderer. | 706 // an IPC message back to the renderer. |
| 497 const int kPageID = 1; | 707 const int kPageID = 1; |
| 498 | 708 |
| 499 webkit_glue::FormField field; | 709 webkit_glue::FormField field; |
| 500 autofill_test::CreateTestFormField( | 710 autofill_test::CreateTestFormField( |
| 501 "Name on Card", "nameoncard", "", "text", &field); | 711 "Name on Card", "nameoncard", "", "text", &field); |
| 502 EXPECT_TRUE(autofill_manager_->GetAutoFillSuggestions(kPageID, false, field)); | 712 rvh()->ResetAutoFillState(kPageID, false); |
| 713 EXPECT_TRUE(autofill_manager_->GetAutoFillSuggestions(false, field, false)); |
| 503 | 714 |
| 504 // No suggestions provided, so send an empty vector as the results. | 715 // No suggestions provided, so send an empty vector as the results. |
| 505 // This triggers the combined message send. | 716 // This triggers the combined message send. |
| 506 rvh()->AutocompleteSuggestionsReturned(kPageID, std::vector<string16>()); | 717 rvh()->AutocompleteSuggestionsReturned(std::vector<string16>()); |
| 507 | 718 |
| 508 // Test that we sent the right message to the renderer. | 719 // Test that we sent the right message to the renderer. |
| 509 int page_id = 0; | 720 int page_id = 0; |
| 510 std::vector<string16> values; | 721 std::vector<string16> values; |
| 511 std::vector<string16> labels; | 722 std::vector<string16> labels; |
| 512 std::vector<string16> icons; | 723 std::vector<string16> icons; |
| 513 EXPECT_TRUE(GetAutoFillSuggestionsMessage(&page_id, &values, &labels, | 724 EXPECT_TRUE(GetAutoFillSuggestionsMessage(&page_id, &values, &labels, |
| 514 &icons)); | 725 &icons)); |
| 515 EXPECT_EQ(kPageID, page_id); | 726 EXPECT_EQ(kPageID, page_id); |
| 516 ASSERT_EQ(2U, values.size()); | 727 ASSERT_EQ(2U, values.size()); |
| 517 EXPECT_EQ(ASCIIToUTF16("Elvis Presley"), values[0]); | 728 EXPECT_EQ(ASCIIToUTF16("Elvis Presley"), values[0]); |
| 518 EXPECT_EQ(ASCIIToUTF16("Buddy Holly"), values[1]); | 729 EXPECT_EQ(ASCIIToUTF16("Buddy Holly"), values[1]); |
| 519 ASSERT_EQ(2U, labels.size()); | 730 ASSERT_EQ(2U, labels.size()); |
| 520 EXPECT_EQ(ASCIIToUTF16("*3456"), labels[0]); | 731 EXPECT_EQ(ASCIIToUTF16("*3456"), labels[0]); |
| 521 EXPECT_EQ(ASCIIToUTF16("*8765"), labels[1]); | 732 EXPECT_EQ(ASCIIToUTF16("*8765"), labels[1]); |
| 522 ASSERT_EQ(2U, icons.size()); | 733 ASSERT_EQ(2U, icons.size()); |
| 523 EXPECT_EQ(ASCIIToUTF16("visaCC"), icons[0]); | 734 EXPECT_EQ(ASCIIToUTF16("visaCC"), icons[0]); |
| 524 EXPECT_EQ(ASCIIToUTF16("masterCardCC"), icons[1]); | 735 EXPECT_EQ(ASCIIToUTF16("masterCardCC"), icons[1]); |
| 525 } | 736 } |
| 526 | 737 |
| 527 // Test that we return no credit card profile suggestions when the form is not | 738 // Test that we return a warning explaining that credit card profile suggestions |
| 528 // https. | 739 // are unavailable when the form is not https. |
| 529 TEST_F(AutoFillManagerTest, GetCreditCardSuggestionsNonHTTPS) { | 740 TEST_F(AutoFillManagerTest, GetCreditCardSuggestionsNonHTTPS) { |
| 530 FormData form; | 741 FormData form; |
| 531 CreateTestCreditCardFormData(&form, false); | 742 CreateTestCreditCardFormData(&form, false); |
| 532 | 743 |
| 533 // Set up our FormStructures. | 744 // Set up our FormStructures. |
| 534 std::vector<FormData> forms; | 745 std::vector<FormData> forms; |
| 535 forms.push_back(form); | 746 forms.push_back(form); |
| 536 autofill_manager_->FormsSeen(forms); | 747 autofill_manager_->FormsSeen(forms); |
| 537 | 748 |
| 538 // The page ID sent to the AutoFillManager from the RenderView, used to send | 749 // The page ID sent to the AutoFillManager from the RenderView, used to send |
| 539 // an IPC message back to the renderer. | 750 // an IPC message back to the renderer. |
| 540 const int kPageID = 1; | 751 const int kPageID = 1; |
| 541 | 752 |
| 542 webkit_glue::FormField field; | 753 webkit_glue::FormField field; |
| 543 autofill_test::CreateTestFormField( | 754 autofill_test::CreateTestFormField( |
| 544 "Card Number", "cardnumber", "", "text", &field); | 755 "Card Number", "cardnumber", "", "text", &field); |
| 545 EXPECT_FALSE( | 756 rvh()->ResetAutoFillState(kPageID, false); |
| 546 autofill_manager_->GetAutoFillSuggestions(kPageID, false, field)); | 757 EXPECT_TRUE(autofill_manager_->GetAutoFillSuggestions(false, field, false)); |
| 758 |
| 759 // No suggestions provided, so send an empty vector as the results. |
| 760 // This triggers the combined message send. |
| 761 rvh()->AutocompleteSuggestionsReturned(std::vector<string16>()); |
| 762 |
| 763 // Test that we sent the right message to the renderer. |
| 764 int page_id = 0; |
| 765 std::vector<string16> values; |
| 766 std::vector<string16> labels; |
| 767 std::vector<string16> icons; |
| 768 EXPECT_TRUE(GetAutoFillSuggestionsMessage(&page_id, &values, &labels, |
| 769 &icons)); |
| 770 EXPECT_EQ(kPageID, page_id); |
| 771 ASSERT_EQ(1U, values.size()); |
| 772 EXPECT_EQ(l10n_util::GetStringUTF16(IDS_AUTOFILL_WARNING_INSECURE_CONNECTION), |
| 773 values[0]); |
| 774 ASSERT_EQ(1U, labels.size()); |
| 775 EXPECT_EQ(string16(), labels[0]); |
| 776 ASSERT_EQ(1U, icons.size()); |
| 777 EXPECT_EQ(string16(), icons[0]); |
| 778 |
| 779 // Now add some Autocomplete suggestions. We should show the autocomplete |
| 780 // suggestions rather than the warning. |
| 781 process()->sink().ClearMessages(); |
| 782 const int kPageID2 = 2; |
| 783 rvh()->ResetAutoFillState(kPageID2, false); |
| 784 EXPECT_TRUE(autofill_manager_->GetAutoFillSuggestions(false, field, false)); |
| 785 |
| 786 std::vector<string16> suggestions; |
| 787 suggestions.push_back(ASCIIToUTF16("Jay")); |
| 788 suggestions.push_back(ASCIIToUTF16("Jason")); |
| 789 rvh()->AutocompleteSuggestionsReturned(suggestions); |
| 790 |
| 791 EXPECT_TRUE(GetAutoFillSuggestionsMessage(&page_id, &values, &labels, |
| 792 &icons)); |
| 793 EXPECT_EQ(kPageID2, page_id); |
| 794 ASSERT_EQ(2U, values.size()); |
| 795 EXPECT_EQ(ASCIIToUTF16("Jay"), values[0]); |
| 796 EXPECT_EQ(ASCIIToUTF16("Jason"), values[1]); |
| 797 ASSERT_EQ(2U, labels.size()); |
| 798 EXPECT_EQ(string16(), labels[0]); |
| 799 EXPECT_EQ(string16(), labels[1]); |
| 800 ASSERT_EQ(2U, icons.size()); |
| 801 EXPECT_EQ(string16(), icons[0]); |
| 802 EXPECT_EQ(string16(), icons[1]); |
| 803 |
| 804 // Clear the test credit cards and try again -- we shouldn't return a warning. |
| 805 test_personal_data_->ClearCreditCards(); |
| 806 EXPECT_FALSE(autofill_manager_->GetAutoFillSuggestions(false, field, false)); |
| 547 } | 807 } |
| 548 | 808 |
| 549 // Test that we return profile and credit card suggestions for combined forms. | 809 // Test that we return profile and credit card suggestions for combined forms. |
| 550 TEST_F(AutoFillManagerTest, GetAddressAndCreditCardSuggestions) { | 810 TEST_F(AutoFillManagerTest, GetAddressAndCreditCardSuggestions) { |
| 551 FormData form; | 811 FormData form; |
| 552 CreateTestAddressFormData(&form); | 812 CreateTestAddressFormData(&form); |
| 553 CreateTestCreditCardFormData(&form, true); | 813 CreateTestCreditCardFormData(&form, true); |
| 554 | 814 |
| 555 // Set up our FormStructures. | 815 // Set up our FormStructures. |
| 556 std::vector<FormData> forms; | 816 std::vector<FormData> forms; |
| 557 forms.push_back(form); | 817 forms.push_back(form); |
| 558 autofill_manager_->FormsSeen(forms); | 818 autofill_manager_->FormsSeen(forms); |
| 559 | 819 |
| 560 // The page ID sent to the AutoFillManager from the RenderView, used to send | 820 // The page ID sent to the AutoFillManager from the RenderView, used to send |
| 561 // an IPC message back to the renderer. | 821 // an IPC message back to the renderer. |
| 562 const int kPageID = 1; | 822 const int kPageID = 1; |
| 563 | 823 |
| 564 webkit_glue::FormField field; | 824 webkit_glue::FormField field; |
| 565 autofill_test::CreateTestFormField( | 825 autofill_test::CreateTestFormField( |
| 566 "First Name", "firstname", "", "text", &field); | 826 "First Name", "firstname", "", "text", &field); |
| 567 EXPECT_TRUE(autofill_manager_->GetAutoFillSuggestions(kPageID, false, field)); | 827 rvh()->ResetAutoFillState(kPageID, false); |
| 828 EXPECT_TRUE(autofill_manager_->GetAutoFillSuggestions(false, field, false)); |
| 568 | 829 |
| 569 // No suggestions provided, so send an empty vector as the results. | 830 // No suggestions provided, so send an empty vector as the results. |
| 570 // This triggers the combined message send. | 831 // This triggers the combined message send. |
| 571 rvh()->AutocompleteSuggestionsReturned(kPageID, std::vector<string16>()); | 832 rvh()->AutocompleteSuggestionsReturned(std::vector<string16>()); |
| 572 | 833 |
| 573 // Test that we sent the right address suggestions to the renderer. | 834 // Test that we sent the right address suggestions to the renderer. |
| 574 int page_id = 0; | 835 int page_id = 0; |
| 575 std::vector<string16> values; | 836 std::vector<string16> values; |
| 576 std::vector<string16> labels; | 837 std::vector<string16> labels; |
| 577 std::vector<string16> icons; | 838 std::vector<string16> icons; |
| 578 EXPECT_TRUE(GetAutoFillSuggestionsMessage(&page_id, &values, &labels, | 839 EXPECT_TRUE(GetAutoFillSuggestionsMessage(&page_id, &values, &labels, |
| 579 &icons)); | 840 &icons)); |
| 580 EXPECT_EQ(kPageID, page_id); | 841 EXPECT_EQ(kPageID, page_id); |
| 581 ASSERT_EQ(2U, values.size()); | 842 ASSERT_EQ(2U, values.size()); |
| 582 EXPECT_EQ(ASCIIToUTF16("Elvis"), values[0]); | 843 EXPECT_EQ(ASCIIToUTF16("Elvis"), values[0]); |
| 583 EXPECT_EQ(ASCIIToUTF16("Charles"), values[1]); | 844 EXPECT_EQ(ASCIIToUTF16("Charles"), values[1]); |
| 584 ASSERT_EQ(2U, labels.size()); | 845 ASSERT_EQ(2U, labels.size()); |
| 585 // Inferred labels now include full first relevant field, which in this case | 846 // Inferred labels now include full first relevant field, which in this case |
| 586 // the address #1. | 847 // the address #1. |
| 587 EXPECT_EQ(ASCIIToUTF16("3734 Elvis Presley Blvd."), labels[0]); | 848 EXPECT_EQ(ASCIIToUTF16("3734 Elvis Presley Blvd."), labels[0]); |
| 588 EXPECT_EQ(ASCIIToUTF16("123 Apple St."), labels[1]); | 849 EXPECT_EQ(ASCIIToUTF16("123 Apple St."), labels[1]); |
| 589 ASSERT_EQ(2U, icons.size()); | 850 ASSERT_EQ(2U, icons.size()); |
| 590 EXPECT_EQ(string16(), icons[0]); | 851 EXPECT_EQ(string16(), icons[0]); |
| 591 EXPECT_EQ(string16(), icons[1]); | 852 EXPECT_EQ(string16(), icons[1]); |
| 592 | 853 |
| 593 process()->sink().ClearMessages(); | 854 process()->sink().ClearMessages(); |
| 594 autofill_test::CreateTestFormField( | 855 autofill_test::CreateTestFormField( |
| 595 "Card Number", "cardnumber", "", "text", &field); | 856 "Card Number", "cardnumber", "", "text", &field); |
| 596 EXPECT_TRUE(autofill_manager_->GetAutoFillSuggestions(kPageID, false, field)); | 857 rvh()->ResetAutoFillState(kPageID, false); |
| 858 EXPECT_TRUE(autofill_manager_->GetAutoFillSuggestions(false, field, false)); |
| 597 | 859 |
| 598 // No suggestions provided, so send an empty vector as the results. | 860 // No suggestions provided, so send an empty vector as the results. |
| 599 // This triggers the combined message send. | 861 // This triggers the combined message send. |
| 600 rvh()->AutocompleteSuggestionsReturned(kPageID, std::vector<string16>()); | 862 rvh()->AutocompleteSuggestionsReturned(std::vector<string16>()); |
| 601 | 863 |
| 602 // Test that we sent the credit card suggestions to the renderer. | 864 // Test that we sent the credit card suggestions to the renderer. |
| 603 page_id = 0; | 865 page_id = 0; |
| 604 EXPECT_TRUE(GetAutoFillSuggestionsMessage(&page_id, &values, &labels, | 866 EXPECT_TRUE(GetAutoFillSuggestionsMessage(&page_id, &values, &labels, |
| 605 &icons)); | 867 &icons)); |
| 606 EXPECT_EQ(kPageID, page_id); | 868 EXPECT_EQ(kPageID, page_id); |
| 607 ASSERT_EQ(2U, values.size()); | 869 ASSERT_EQ(2U, values.size()); |
| 608 EXPECT_EQ(ASCIIToUTF16("************3456"), values[0]); | 870 EXPECT_EQ(ASCIIToUTF16("************3456"), values[0]); |
| 609 EXPECT_EQ(ASCIIToUTF16("************8765"), values[1]); | 871 EXPECT_EQ(ASCIIToUTF16("************8765"), values[1]); |
| 610 ASSERT_EQ(2U, labels.size()); | 872 ASSERT_EQ(2U, labels.size()); |
| 611 EXPECT_EQ(ASCIIToUTF16("*3456"), labels[0]); | 873 EXPECT_EQ(ASCIIToUTF16("*3456"), labels[0]); |
| 612 EXPECT_EQ(ASCIIToUTF16("*8765"), labels[1]); | 874 EXPECT_EQ(ASCIIToUTF16("*8765"), labels[1]); |
| 613 ASSERT_EQ(2U, icons.size()); | 875 ASSERT_EQ(2U, icons.size()); |
| 614 EXPECT_EQ(ASCIIToUTF16("visaCC"), icons[0]); | 876 EXPECT_EQ(ASCIIToUTF16("visaCC"), icons[0]); |
| 615 EXPECT_EQ(ASCIIToUTF16("masterCardCC"), icons[1]); | 877 EXPECT_EQ(ASCIIToUTF16("masterCardCC"), icons[1]); |
| 616 } | 878 } |
| 617 | 879 |
| 618 // Test that for non-https forms with both address and credit card fields, we | 880 // Test that for non-https forms with both address and credit card fields, we |
| 619 // only return address suggestions. | 881 // only return address suggestions. Instead of credit card suggestions, we |
| 882 // should return a warning explaining that credit card profile suggestions are |
| 883 // unavailable when the form is not https. |
| 620 TEST_F(AutoFillManagerTest, GetAddressAndCreditCardSuggestionsNonHttps) { | 884 TEST_F(AutoFillManagerTest, GetAddressAndCreditCardSuggestionsNonHttps) { |
| 621 FormData form; | 885 FormData form; |
| 622 CreateTestAddressFormData(&form); | 886 CreateTestAddressFormData(&form); |
| 623 CreateTestCreditCardFormData(&form, false); | 887 CreateTestCreditCardFormData(&form, false); |
| 624 | 888 |
| 625 // Set up our FormStructures. | 889 // Set up our FormStructures. |
| 626 std::vector<FormData> forms; | 890 std::vector<FormData> forms; |
| 627 forms.push_back(form); | 891 forms.push_back(form); |
| 628 autofill_manager_->FormsSeen(forms); | 892 autofill_manager_->FormsSeen(forms); |
| 629 | 893 |
| 630 // The page ID sent to the AutoFillManager from the RenderView, used to send | 894 // The page ID sent to the AutoFillManager from the RenderView, used to send |
| 631 // an IPC message back to the renderer. | 895 // an IPC message back to the renderer. |
| 632 const int kPageID = 1; | 896 const int kPageID = 1; |
| 633 | 897 |
| 634 webkit_glue::FormField field; | 898 webkit_glue::FormField field; |
| 635 autofill_test::CreateTestFormField( | 899 autofill_test::CreateTestFormField( |
| 636 "First Name", "firstname", "", "text", &field); | 900 "First Name", "firstname", "", "text", &field); |
| 637 EXPECT_TRUE(autofill_manager_->GetAutoFillSuggestions(kPageID, false, field)); | 901 rvh()->ResetAutoFillState(kPageID, false); |
| 902 EXPECT_TRUE(autofill_manager_->GetAutoFillSuggestions(false, field, false)); |
| 638 | 903 |
| 639 // No suggestions provided, so send an empty vector as the results. | 904 // No suggestions provided, so send an empty vector as the results. |
| 640 // This triggers the combined message send. | 905 // This triggers the combined message send. |
| 641 rvh()->AutocompleteSuggestionsReturned(kPageID, std::vector<string16>()); | 906 rvh()->AutocompleteSuggestionsReturned(std::vector<string16>()); |
| 642 | 907 |
| 643 // Test that we sent the right address suggestions to the renderer. | 908 // Test that we sent the right address suggestions to the renderer. |
| 644 int page_id = 0; | 909 int page_id = 0; |
| 645 std::vector<string16> values; | 910 std::vector<string16> values; |
| 646 std::vector<string16> labels; | 911 std::vector<string16> labels; |
| 647 std::vector<string16> icons; | 912 std::vector<string16> icons; |
| 648 EXPECT_TRUE(GetAutoFillSuggestionsMessage(&page_id, &values, &labels, | 913 EXPECT_TRUE(GetAutoFillSuggestionsMessage(&page_id, &values, &labels, |
| 649 &icons)); | 914 &icons)); |
| 650 EXPECT_EQ(kPageID, page_id); | 915 EXPECT_EQ(kPageID, page_id); |
| 651 ASSERT_EQ(2U, values.size()); | 916 ASSERT_EQ(2U, values.size()); |
| 652 EXPECT_EQ(ASCIIToUTF16("Elvis"), values[0]); | 917 EXPECT_EQ(ASCIIToUTF16("Elvis"), values[0]); |
| 653 EXPECT_EQ(ASCIIToUTF16("Charles"), values[1]); | 918 EXPECT_EQ(ASCIIToUTF16("Charles"), values[1]); |
| 654 ASSERT_EQ(2U, labels.size()); | 919 ASSERT_EQ(2U, labels.size()); |
| 655 // Inferred labels now include full first relevant field, which in this case | 920 // Inferred labels now include full first relevant field, which in this case |
| 656 // the address #1. | 921 // the address #1. |
| 657 EXPECT_EQ(ASCIIToUTF16("3734 Elvis Presley Blvd."), labels[0]); | 922 EXPECT_EQ(ASCIIToUTF16("3734 Elvis Presley Blvd."), labels[0]); |
| 658 EXPECT_EQ(ASCIIToUTF16("123 Apple St."), labels[1]); | 923 EXPECT_EQ(ASCIIToUTF16("123 Apple St."), labels[1]); |
| 659 ASSERT_EQ(2U, icons.size()); | 924 ASSERT_EQ(2U, icons.size()); |
| 660 EXPECT_EQ(string16(), icons[0]); | 925 EXPECT_EQ(string16(), icons[0]); |
| 661 EXPECT_EQ(string16(), icons[1]); | 926 EXPECT_EQ(string16(), icons[1]); |
| 662 | 927 |
| 928 process()->sink().ClearMessages(); |
| 663 autofill_test::CreateTestFormField( | 929 autofill_test::CreateTestFormField( |
| 664 "Card Number", "cardnumber", "", "text", &field); | 930 "Card Number", "cardnumber", "", "text", &field); |
| 665 EXPECT_FALSE( | 931 rvh()->ResetAutoFillState(kPageID, false); |
| 666 autofill_manager_->GetAutoFillSuggestions(kPageID, false, field)); | 932 EXPECT_TRUE(autofill_manager_->GetAutoFillSuggestions(false, field, false)); |
| 933 |
| 934 // No suggestions provided, so send an empty vector as the results. |
| 935 // This triggers the combined message send. |
| 936 rvh()->AutocompleteSuggestionsReturned(std::vector<string16>()); |
| 937 |
| 938 // Test that we sent the right message to the renderer. |
| 939 EXPECT_TRUE(GetAutoFillSuggestionsMessage(&page_id, &values, &labels, |
| 940 &icons)); |
| 941 EXPECT_EQ(kPageID, page_id); |
| 942 ASSERT_EQ(1U, values.size()); |
| 943 EXPECT_EQ(l10n_util::GetStringUTF16(IDS_AUTOFILL_WARNING_INSECURE_CONNECTION), |
| 944 values[0]); |
| 945 ASSERT_EQ(1U, labels.size()); |
| 946 EXPECT_EQ(string16(), labels[0]); |
| 947 ASSERT_EQ(1U, icons.size()); |
| 948 EXPECT_EQ(string16(), icons[0]); |
| 949 |
| 950 // Clear the test credit cards and try again -- we shouldn't return a warning. |
| 951 test_personal_data_->ClearCreditCards(); |
| 952 EXPECT_FALSE(autofill_manager_->GetAutoFillSuggestions(false, field, false)); |
| 667 } | 953 } |
| 668 | 954 |
| 669 // Test that we correctly combine autofill and autocomplete suggestions. | 955 // Test that we correctly combine autofill and autocomplete suggestions. |
| 670 TEST_F(AutoFillManagerTest, GetCombinedAutoFillAndAutocompleteSuggestions) { | 956 TEST_F(AutoFillManagerTest, GetCombinedAutoFillAndAutocompleteSuggestions) { |
| 671 FormData form; | 957 FormData form; |
| 672 CreateTestAddressFormData(&form); | 958 CreateTestAddressFormData(&form); |
| 673 | 959 |
| 674 // Set up our FormStructures. | 960 // Set up our FormStructures. |
| 675 std::vector<FormData> forms; | 961 std::vector<FormData> forms; |
| 676 forms.push_back(form); | 962 forms.push_back(form); |
| 677 autofill_manager_->FormsSeen(forms); | 963 autofill_manager_->FormsSeen(forms); |
| 678 | 964 |
| 679 // The page ID sent to the AutoFillManager from the RenderView, used to send | 965 // The page ID sent to the AutoFillManager from the RenderView, used to send |
| 680 // an IPC message back to the renderer. | 966 // an IPC message back to the renderer. |
| 681 const int kPageID = 1; | 967 const int kPageID = 1; |
| 682 | 968 |
| 683 webkit_glue::FormField field; | 969 webkit_glue::FormField field; |
| 684 autofill_test::CreateTestFormField( | 970 autofill_test::CreateTestFormField( |
| 685 "First Name", "firstname", "", "text", &field); | 971 "First Name", "firstname", "", "text", &field); |
| 686 EXPECT_TRUE(autofill_manager_->GetAutoFillSuggestions(kPageID, false, field)); | 972 rvh()->ResetAutoFillState(kPageID, false); |
| 973 EXPECT_TRUE(autofill_manager_->GetAutoFillSuggestions(false, field, false)); |
| 687 | 974 |
| 688 // Add some Autocomplete suggestions. | 975 // Add some Autocomplete suggestions. |
| 689 // This triggers the combined message send. | 976 // This triggers the combined message send. |
| 690 std::vector<string16> suggestions; | 977 std::vector<string16> suggestions; |
| 691 suggestions.push_back(ASCIIToUTF16("Jay")); | 978 suggestions.push_back(ASCIIToUTF16("Jay")); |
| 692 suggestions.push_back(ASCIIToUTF16("Jason")); | 979 suggestions.push_back(ASCIIToUTF16("Jason")); |
| 693 rvh()->AutocompleteSuggestionsReturned(kPageID, suggestions); | 980 rvh()->AutocompleteSuggestionsReturned(suggestions); |
| 694 | 981 |
| 695 // Test that we sent the right message to the renderer. | 982 // Test that we sent the right message to the renderer. |
| 696 int page_id = 0; | 983 int page_id = 0; |
| 697 std::vector<string16> values; | 984 std::vector<string16> values; |
| 698 std::vector<string16> labels; | 985 std::vector<string16> labels; |
| 699 std::vector<string16> icons; | 986 std::vector<string16> icons; |
| 700 EXPECT_TRUE(GetAutoFillSuggestionsMessage(&page_id, &values, &labels, | 987 EXPECT_TRUE(GetAutoFillSuggestionsMessage(&page_id, &values, &labels, |
| 701 &icons)); | 988 &icons)); |
| 702 EXPECT_EQ(kPageID, page_id); | 989 EXPECT_EQ(kPageID, page_id); |
| 703 ASSERT_EQ(4U, values.size()); | 990 ASSERT_EQ(4U, values.size()); |
| (...skipping 24 matching lines...) Expand all Loading... |
| 728 forms.push_back(form); | 1015 forms.push_back(form); |
| 729 autofill_manager_->FormsSeen(forms); | 1016 autofill_manager_->FormsSeen(forms); |
| 730 | 1017 |
| 731 // The page ID sent to the AutoFillManager from the RenderView, used to send | 1018 // The page ID sent to the AutoFillManager from the RenderView, used to send |
| 732 // an IPC message back to the renderer. | 1019 // an IPC message back to the renderer. |
| 733 const int kPageID = 1; | 1020 const int kPageID = 1; |
| 734 | 1021 |
| 735 webkit_glue::FormField field; | 1022 webkit_glue::FormField field; |
| 736 autofill_test::CreateTestFormField( | 1023 autofill_test::CreateTestFormField( |
| 737 "First Name", "firstname", "", "text", &field); | 1024 "First Name", "firstname", "", "text", &field); |
| 738 EXPECT_TRUE(autofill_manager_->GetAutoFillSuggestions(kPageID, true, field)); | 1025 rvh()->ResetAutoFillState(kPageID, false); |
| 1026 EXPECT_TRUE(autofill_manager_->GetAutoFillSuggestions(true, field, false)); |
| 739 | 1027 |
| 740 // No suggestions provided, so send an empty vector as the results. | 1028 // No suggestions provided, so send an empty vector as the results. |
| 741 // This triggers the combined message send. | 1029 // This triggers the combined message send. |
| 742 rvh()->AutocompleteSuggestionsReturned(kPageID, std::vector<string16>()); | 1030 rvh()->AutocompleteSuggestionsReturned(std::vector<string16>()); |
| 743 | 1031 |
| 744 // Test that we sent the right message to the renderer. | 1032 // Test that we sent the right message to the renderer. |
| 745 int page_id = 0; | 1033 int page_id = 0; |
| 746 std::vector<string16> values; | 1034 std::vector<string16> values; |
| 747 std::vector<string16> labels; | 1035 std::vector<string16> labels; |
| 748 std::vector<string16> icons; | 1036 std::vector<string16> icons; |
| 749 EXPECT_TRUE(GetAutoFillSuggestionsMessage(&page_id, &values, &labels, | 1037 EXPECT_TRUE(GetAutoFillSuggestionsMessage(&page_id, &values, &labels, |
| 750 &icons)); | 1038 &icons)); |
| 751 EXPECT_EQ(kPageID, page_id); | 1039 EXPECT_EQ(kPageID, page_id); |
| 752 ASSERT_EQ(2U, values.size()); | 1040 ASSERT_EQ(2U, values.size()); |
| (...skipping 18 matching lines...) Expand all Loading... |
| 771 forms.push_back(form); | 1059 forms.push_back(form); |
| 772 autofill_manager_->FormsSeen(forms); | 1060 autofill_manager_->FormsSeen(forms); |
| 773 | 1061 |
| 774 // The page ID sent to the AutoFillManager from the RenderView, used to send | 1062 // The page ID sent to the AutoFillManager from the RenderView, used to send |
| 775 // an IPC message back to the renderer. | 1063 // an IPC message back to the renderer. |
| 776 const int kPageID = 1; | 1064 const int kPageID = 1; |
| 777 | 1065 |
| 778 webkit_glue::FormField field; | 1066 webkit_glue::FormField field; |
| 779 autofill_test::CreateTestFormField( | 1067 autofill_test::CreateTestFormField( |
| 780 "Some Field", "somefield", "", "text", &field); | 1068 "Some Field", "somefield", "", "text", &field); |
| 781 EXPECT_FALSE(autofill_manager_->GetAutoFillSuggestions(kPageID, true, field)); | 1069 rvh()->ResetAutoFillState(kPageID, false); |
| 1070 EXPECT_FALSE(autofill_manager_->GetAutoFillSuggestions(true, field, false)); |
| 782 | 1071 |
| 783 // Add some Autocomplete suggestions. | 1072 // Add some Autocomplete suggestions. |
| 784 // This triggers the combined message send. | 1073 // This triggers the combined message send. |
| 785 std::vector<string16> suggestions; | 1074 std::vector<string16> suggestions; |
| 786 suggestions.push_back(ASCIIToUTF16("one")); | 1075 suggestions.push_back(ASCIIToUTF16("one")); |
| 787 suggestions.push_back(ASCIIToUTF16("two")); | 1076 suggestions.push_back(ASCIIToUTF16("two")); |
| 788 rvh()->AutocompleteSuggestionsReturned(kPageID, suggestions); | 1077 rvh()->AutocompleteSuggestionsReturned(suggestions); |
| 789 | 1078 |
| 790 // Test that we sent the right message to the renderer. | 1079 // Test that we sent the right message to the renderer. |
| 791 int page_id = 0; | 1080 int page_id = 0; |
| 792 std::vector<string16> values; | 1081 std::vector<string16> values; |
| 793 std::vector<string16> labels; | 1082 std::vector<string16> labels; |
| 794 std::vector<string16> icons; | 1083 std::vector<string16> icons; |
| 795 EXPECT_TRUE(GetAutoFillSuggestionsMessage(&page_id, &values, &labels, | 1084 EXPECT_TRUE(GetAutoFillSuggestionsMessage(&page_id, &values, &labels, |
| 796 &icons)); | 1085 &icons)); |
| 797 EXPECT_EQ(kPageID, page_id); | 1086 EXPECT_EQ(kPageID, page_id); |
| 798 ASSERT_EQ(2U, values.size()); | 1087 ASSERT_EQ(2U, values.size()); |
| (...skipping 24 matching lines...) Expand all Loading... |
| 823 "", "", "", "", "", "", "", ""); | 1112 "", "", "", "", "", "", "", ""); |
| 824 autofill_manager_->AddProfile(profile); | 1113 autofill_manager_->AddProfile(profile); |
| 825 | 1114 |
| 826 // The page ID sent to the AutoFillManager from the RenderView, used to send | 1115 // The page ID sent to the AutoFillManager from the RenderView, used to send |
| 827 // an IPC message back to the renderer. | 1116 // an IPC message back to the renderer. |
| 828 const int kPageID = 1; | 1117 const int kPageID = 1; |
| 829 | 1118 |
| 830 webkit_glue::FormField field; | 1119 webkit_glue::FormField field; |
| 831 autofill_test::CreateTestFormField( | 1120 autofill_test::CreateTestFormField( |
| 832 "First Name", "firstname", "", "text", &field); | 1121 "First Name", "firstname", "", "text", &field); |
| 833 EXPECT_TRUE(autofill_manager_->GetAutoFillSuggestions(kPageID, true, field)); | 1122 rvh()->ResetAutoFillState(kPageID, false); |
| 1123 EXPECT_TRUE(autofill_manager_->GetAutoFillSuggestions(true, field, false)); |
| 834 | 1124 |
| 835 // No suggestions provided, so send an empty vector as the results. | 1125 // No suggestions provided, so send an empty vector as the results. |
| 836 // This triggers the combined message send. | 1126 // This triggers the combined message send. |
| 837 rvh()->AutocompleteSuggestionsReturned(kPageID, std::vector<string16>()); | 1127 rvh()->AutocompleteSuggestionsReturned(std::vector<string16>()); |
| 838 | 1128 |
| 839 // Test that we sent the right message to the renderer. | 1129 // Test that we sent the right message to the renderer. |
| 840 int page_id = 0; | 1130 int page_id = 0; |
| 841 std::vector<string16> values; | 1131 std::vector<string16> values; |
| 842 std::vector<string16> labels; | 1132 std::vector<string16> labels; |
| 843 std::vector<string16> icons; | 1133 std::vector<string16> icons; |
| 844 EXPECT_TRUE(GetAutoFillSuggestionsMessage(&page_id, &values, &labels, | 1134 EXPECT_TRUE(GetAutoFillSuggestionsMessage(&page_id, &values, &labels, |
| 845 &icons)); | 1135 &icons)); |
| 846 EXPECT_EQ(kPageID, page_id); | 1136 EXPECT_EQ(kPageID, page_id); |
| 847 ASSERT_EQ(2U, values.size()); | 1137 ASSERT_EQ(2U, values.size()); |
| (...skipping 525 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1373 ASSERT_FALSE(profile()->GetPrefs()->GetBoolean( | 1663 ASSERT_FALSE(profile()->GetPrefs()->GetBoolean( |
| 1374 prefs::kAutoFillAuxiliaryProfilesEnabled)); | 1664 prefs::kAutoFillAuxiliaryProfilesEnabled)); |
| 1375 profile()->GetPrefs()->SetBoolean( | 1665 profile()->GetPrefs()->SetBoolean( |
| 1376 prefs::kAutoFillAuxiliaryProfilesEnabled, true); | 1666 prefs::kAutoFillAuxiliaryProfilesEnabled, true); |
| 1377 profile()->GetPrefs()->ClearPref(prefs::kAutoFillAuxiliaryProfilesEnabled); | 1667 profile()->GetPrefs()->ClearPref(prefs::kAutoFillAuxiliaryProfilesEnabled); |
| 1378 ASSERT_FALSE(profile()->GetPrefs()->GetBoolean( | 1668 ASSERT_FALSE(profile()->GetPrefs()->GetBoolean( |
| 1379 prefs::kAutoFillAuxiliaryProfilesEnabled)); | 1669 prefs::kAutoFillAuxiliaryProfilesEnabled)); |
| 1380 #endif | 1670 #endif |
| 1381 } | 1671 } |
| 1382 | 1672 |
| OLD | NEW |