OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "base/bind.h" | 5 #include "base/bind.h" |
6 #include "base/command_line.h" | 6 #include "base/command_line.h" |
7 #include "base/memory/ref_counted.h" | 7 #include "base/memory/ref_counted.h" |
8 #include "base/memory/weak_ptr.h" | 8 #include "base/memory/weak_ptr.h" |
9 #include "base/message_loop/message_loop.h" | 9 #include "base/message_loop/message_loop.h" |
10 #include "base/prefs/pref_service.h" | 10 #include "base/prefs/pref_service.h" |
(...skipping 474 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
485 value.substr(0, value.size() / 2)); | 485 value.substr(0, value.size() / 2)); |
486 view->ActivateInput(triggering_input); | 486 view->ActivateInput(triggering_input); |
487 ASSERT_EQ(&triggering_input, controller()->input_showing_popup()); | 487 ASSERT_EQ(&triggering_input, controller()->input_showing_popup()); |
488 controller()->DidAcceptSuggestion(string16(), 0); | 488 controller()->DidAcceptSuggestion(string16(), 0); |
489 | 489 |
490 for (size_t i = 0; i < inputs.size(); ++i) { | 490 for (size_t i = 0; i < inputs.size(); ++i) { |
491 EXPECT_EQ(expectations[i], view->GetTextContentsOfInput(inputs[i])); | 491 EXPECT_EQ(expectations[i], view->GetTextContentsOfInput(inputs[i])); |
492 } | 492 } |
493 } | 493 } |
494 | 494 |
| 495 // For now, no matter what, the country must always be US. See |
| 496 // http://crbug.com/247518 |
| 497 IN_PROC_BROWSER_TEST_F(AutofillDialogControllerTest, |
| 498 FillInputFromForeignProfile) { |
| 499 AutofillProfile full_profile(test::GetFullProfile()); |
| 500 full_profile.SetInfo(AutofillType(ADDRESS_HOME_COUNTRY), |
| 501 ASCIIToUTF16("France"), "en-US"); |
| 502 controller()->GetTestingManager()->AddTestingProfile(&full_profile); |
| 503 |
| 504 const DetailInputs& inputs = |
| 505 controller()->RequestedFieldsForSection(SECTION_SHIPPING); |
| 506 const DetailInput& triggering_input = inputs[0]; |
| 507 string16 value = full_profile.GetRawInfo(triggering_input.type); |
| 508 TestableAutofillDialogView* view = controller()->GetTestableView(); |
| 509 view->SetTextContentsOfInput(triggering_input, |
| 510 value.substr(0, value.size() / 2)); |
| 511 view->ActivateInput(triggering_input); |
| 512 |
| 513 ASSERT_EQ(&triggering_input, controller()->input_showing_popup()); |
| 514 controller()->DidAcceptSuggestion(string16(), 0); |
| 515 |
| 516 // All inputs should be filled. |
| 517 AutofillProfileWrapper wrapper(&full_profile); |
| 518 for (size_t i = 0; i < inputs.size(); ++i) { |
| 519 string16 expectation = |
| 520 AutofillType(inputs[i].type).GetStorableType() == ADDRESS_HOME_COUNTRY ? |
| 521 ASCIIToUTF16("United States") : |
| 522 wrapper.GetInfo(AutofillType(inputs[i].type)); |
| 523 EXPECT_EQ(expectation, view->GetTextContentsOfInput(inputs[i])); |
| 524 } |
| 525 |
| 526 // Now simulate some user edits and try again. |
| 527 std::vector<string16> expectations; |
| 528 for (size_t i = 0; i < inputs.size(); ++i) { |
| 529 string16 users_input = i % 2 == 0 ? string16() : ASCIIToUTF16("dummy"); |
| 530 view->SetTextContentsOfInput(inputs[i], users_input); |
| 531 // Empty inputs should be filled, others should be left alone. |
| 532 string16 expectation = |
| 533 &inputs[i] == &triggering_input || users_input.empty() ? |
| 534 wrapper.GetInfo(AutofillType(inputs[i].type)) : |
| 535 users_input; |
| 536 if (AutofillType(inputs[i].type).GetStorableType() == ADDRESS_HOME_COUNTRY) |
| 537 expectation = ASCIIToUTF16("United States"); |
| 538 |
| 539 expectations.push_back(expectation); |
| 540 } |
| 541 |
| 542 view->SetTextContentsOfInput(triggering_input, |
| 543 value.substr(0, value.size() / 2)); |
| 544 view->ActivateInput(triggering_input); |
| 545 ASSERT_EQ(&triggering_input, controller()->input_showing_popup()); |
| 546 controller()->DidAcceptSuggestion(string16(), 0); |
| 547 |
| 548 for (size_t i = 0; i < inputs.size(); ++i) { |
| 549 EXPECT_EQ(expectations[i], view->GetTextContentsOfInput(inputs[i])); |
| 550 } |
| 551 } |
| 552 |
495 // This test makes sure that picking a profile variant in the Autofill | 553 // This test makes sure that picking a profile variant in the Autofill |
496 // popup works as expected. | 554 // popup works as expected. |
497 IN_PROC_BROWSER_TEST_F(AutofillDialogControllerTest, | 555 IN_PROC_BROWSER_TEST_F(AutofillDialogControllerTest, |
498 FillInputFromAutofillVariant) { | 556 FillInputFromAutofillVariant) { |
499 AutofillProfile full_profile(test::GetFullProfile()); | 557 AutofillProfile full_profile(test::GetFullProfile()); |
500 | 558 |
501 // Set up some variant data. | 559 // Set up some variant data. |
502 std::vector<string16> names; | 560 std::vector<string16> names; |
503 names.push_back(ASCIIToUTF16("John Doe")); | 561 names.push_back(ASCIIToUTF16("John Doe")); |
504 names.push_back(ASCIIToUTF16("Jane Doe")); | 562 names.push_back(ASCIIToUTF16("Jane Doe")); |
(...skipping 445 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
950 test::GetVerifiedProfile()); | 1008 test::GetVerifiedProfile()); |
951 | 1009 |
952 TestableAutofillDialogView* view = controller->GetTestableView(); | 1010 TestableAutofillDialogView* view = controller->GetTestableView(); |
953 view->SetTextContentsOfSuggestionInput(SECTION_CC, ASCIIToUTF16("123")); | 1011 view->SetTextContentsOfSuggestionInput(SECTION_CC, ASCIIToUTF16("123")); |
954 view->SubmitForTesting(); | 1012 view->SubmitForTesting(); |
955 ExpectDomMessage("success"); | 1013 ExpectDomMessage("success"); |
956 EXPECT_EQ("123", GetValueForHTMLFieldOfType("cc-csc")); | 1014 EXPECT_EQ("123", GetValueForHTMLFieldOfType("cc-csc")); |
957 } | 1015 } |
958 | 1016 |
959 } // namespace autofill | 1017 } // namespace autofill |
OLD | NEW |