diff options
author | isherman@chromium.org <isherman@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2013-10-30 03:45:21 +0000 |
---|---|---|
committer | isherman@chromium.org <isherman@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2013-10-30 03:45:21 +0000 |
commit | 30ed0a9b8936b1b7631c1eb76c5b0f440dc938c3 (patch) | |
tree | 8138e6dadd5ce386e076530c793b5f4dd2e48c8a | |
parent | 39327261e00e51b28d6543e296772aed26eb40a6 (diff) | |
download | chromium_src-30ed0a9b8936b1b7631c1eb76c5b0f440dc938c3.zip chromium_src-30ed0a9b8936b1b7631c1eb76c5b0f440dc938c3.tar.gz chromium_src-30ed0a9b8936b1b7631c1eb76c5b0f440dc938c3.tar.bz2 |
[rAc OSX] Return CVC data from Autofill dialog.
BUG=310856
TEST=browser_tests
R=groby@chromium.org
Review URL: https://codereview.chromium.org/49233006
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@231730 0039d316-1c4b-4281-b951-d872f2087c98
5 files changed, 62 insertions, 6 deletions
diff --git a/chrome/browser/ui/autofill/autofill_dialog_controller_browsertest.cc b/chrome/browser/ui/autofill/autofill_dialog_controller_browsertest.cc index 7e99478..93cda44d 100644 --- a/chrome/browser/ui/autofill/autofill_dialog_controller_browsertest.cc +++ b/chrome/browser/ui/autofill/autofill_dialog_controller_browsertest.cc @@ -301,6 +301,16 @@ class AutofillDialogControllerTest : public InProcessBrowserTest { "document.forms[0].requestAutocomplete();" "send('clicked');" "};" + "function getValueForFieldOfType(type) {" + " var fields = document.getElementsByTagName('input');" + " for (var i = 0; i < fields.length; i++) {" + " if (fields[i].autocomplete == type) {" + " send(fields[i].value);" + " return;" + " }" + " }" + " send('');" + "};" "</script>" "</body>" "</html>")); @@ -328,6 +338,19 @@ class AutofillDialogControllerTest : public InProcessBrowserTest { EXPECT_EQ("\"" + expected + "\"", message); } + // Returns the value filled into the first field with autocomplete attribute + // equal to |autocomplete_type|, or an empty string if there is no such field. + std::string GetValueForHTMLFieldOfType(const std::string& autocomplete_type) { + content::RenderViewHost* render_view_host = + browser()->tab_strip_model()->GetActiveWebContents()-> + GetRenderViewHost(); + std::string script = "getValueForFieldOfType('" + autocomplete_type + "');"; + std::string result; + EXPECT_TRUE(content::ExecuteScriptAndExtractString(render_view_host, script, + &result)); + return result; + } + void AddCreditcardToProfile(Profile* profile, const CreditCard& card) { PersonalDataManagerFactory::GetForProfile(profile)->AddCreditCard(card); WaitForWebDB(); @@ -821,8 +844,6 @@ IN_PROC_BROWSER_TEST_F(AutofillDialogControllerTest, MAYBE_PreservedSections) { } #endif // defined(TOOLKIT_VIEWS) || defined(OS_MACOSX) -// TODO(groby): figure out if the CVC challenge code actually works on Mac. -#if !defined(OS_MACOSX) IN_PROC_BROWSER_TEST_F(AutofillDialogControllerTest, GeneratedCardLastFourAfterVerifyCvv) { std::vector<std::string> usernames; @@ -873,7 +894,6 @@ IN_PROC_BROWSER_TEST_F(AutofillDialogControllerTest, EXPECT_EQ(1, test_generated_bubble_controller()->bubbles_shown()); EXPECT_EQ(last_four, test_generated_bubble_controller()->backing_card_name()); } -#endif // !defined(OS_MACOSX) // Simulates the user successfully signing in to the dialog for the first time. // The controller listens for nav entry commits and should not destroy the web @@ -905,4 +925,21 @@ IN_PROC_BROWSER_TEST_F(AutofillDialogControllerTest, SignInNoCrash) { EXPECT_TRUE(account_chooser_model.WalletIsSelected()); } +// Verify that filling a form works correctly, including filling the CVC when +// that is requested separately. +IN_PROC_BROWSER_TEST_F(AutofillDialogControllerTest, FillFormIncludesCVC) { + AutofillDialogControllerImpl* controller = + SetUpHtmlAndInvoke("<input autocomplete='cc-csc'>"); + + AddCreditcardToProfile(controller->profile(), test::GetVerifiedCreditCard()); + AddAutofillProfileToProfile(controller->profile(), + test::GetVerifiedProfile()); + + TestableAutofillDialogView* view = controller->GetTestableView(); + view->SetTextContentsOfSuggestionInput(SECTION_CC, ASCIIToUTF16("123")); + view->SubmitForTesting(); + ExpectDomMessage("success"); + EXPECT_EQ("123", GetValueForHTMLFieldOfType("cc-csc")); +} + } // namespace autofill diff --git a/chrome/browser/ui/cocoa/autofill/autofill_dialog_cocoa.h b/chrome/browser/ui/cocoa/autofill/autofill_dialog_cocoa.h index 16a4ea0..0b7edaf 100644 --- a/chrome/browser/ui/cocoa/autofill/autofill_dialog_cocoa.h +++ b/chrome/browser/ui/cocoa/autofill/autofill_dialog_cocoa.h @@ -147,6 +147,7 @@ class AutofillDialogCocoa : public AutofillDialogView, forInput:(const autofill::DetailInput&)input; - (void)getInputs:(autofill::DetailOutputMap*)outputs forSection:(autofill::DialogSection)section; +- (NSString*)getCvc; - (BOOL)saveDetailsLocally; - (content::NavigationController*)showSignIn; - (void)hideSignIn; diff --git a/chrome/browser/ui/cocoa/autofill/autofill_dialog_cocoa.mm b/chrome/browser/ui/cocoa/autofill/autofill_dialog_cocoa.mm index 2751e27..32076a8 100644 --- a/chrome/browser/ui/cocoa/autofill/autofill_dialog_cocoa.mm +++ b/chrome/browser/ui/cocoa/autofill/autofill_dialog_cocoa.mm @@ -131,7 +131,7 @@ void AutofillDialogCocoa::GetUserInput(DialogSection section, } string16 AutofillDialogCocoa::GetCvc() { - return string16(); + return base::SysNSStringToUTF16([sheet_delegate_ getCvc]); } bool AutofillDialogCocoa::HitTestInput(const DetailInput& input, @@ -572,6 +572,16 @@ void AutofillDialogCocoa::OnConstrainedWindowClosed( [[mainContainer_ sectionForId:section] getInputs:output]; } +- (NSString*)getCvc { + autofill::DialogSection section = autofill::SECTION_CC; + NSString* value = [[mainContainer_ sectionForId:section] suggestionText]; + if (!value) { + section = autofill::SECTION_CC_BILLING; + value = [[mainContainer_ sectionForId:section] suggestionText]; + } + return value; +} + - (BOOL)saveDetailsLocally { return [mainContainer_ saveDetailsLocally]; } diff --git a/chrome/browser/ui/cocoa/autofill/autofill_section_container.h b/chrome/browser/ui/cocoa/autofill/autofill_section_container.h index af19070..6bdbcb5 100644 --- a/chrome/browser/ui/cocoa/autofill/autofill_section_container.h +++ b/chrome/browser/ui/cocoa/autofill/autofill_section_container.h @@ -67,7 +67,7 @@ namespace autofill { // Designated initializer. Queries |delegate| for the list of desired input // fields for |section|. - (id)initWithDelegate:(autofill::AutofillDialogViewDelegate*)delegate - forSection:(autofill::DialogSection)section; + forSection:(autofill::DialogSection)section; // Populates |output| with mappings from field identification to input value. - (void)getInputs:(autofill::DetailOutputMap*)output; @@ -85,6 +85,10 @@ namespace autofill { // Validate this section. Validation rules depend on |validationType|. - (BOOL)validateFor:(autofill::ValidationType)validationType; +// Returns the value of the |suggestContainer_|'s input field, or nil if no +// suggestion is currently showing. +- (NSString*)suggestionText; + @end @interface AutofillSectionContainer (ForTesting) @@ -95,7 +99,7 @@ namespace autofill { // Sets the value for the field matching |input|. Does nothing if the field is // not part of this section. - (void)setFieldValue:(NSString*)text - forInput:(const autofill::DetailInput&)input; + forInput:(const autofill::DetailInput&)input; // Sets the value for the suggestion text field. - (void)setSuggestionFieldValue:(NSString*)text; diff --git a/chrome/browser/ui/cocoa/autofill/autofill_section_container.mm b/chrome/browser/ui/cocoa/autofill/autofill_section_container.mm index 59343e0..2ba0561 100644 --- a/chrome/browser/ui/cocoa/autofill/autofill_section_container.mm +++ b/chrome/browser/ui/cocoa/autofill/autofill_section_container.mm @@ -366,6 +366,10 @@ bool CompareInputRows(const autofill::DetailInput* input1, return !messages.HasErrors(); } +- (NSString*)suggestionText { + return showSuggestions_ ? [[suggestContainer_ inputField] stringValue] : nil; +} + #pragma mark Internal API for AutofillSectionContainer. - (void)textfieldEditedOrActivated:(NSControl<AutofillInputField>*)field |