diff options
author | dhollowa@chromium.org <dhollowa@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-07-23 18:01:35 +0000 |
---|---|---|
committer | dhollowa@chromium.org <dhollowa@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-07-23 18:01:35 +0000 |
commit | 2b1223cc579afff030e8b59d3f1859eccf867556 (patch) | |
tree | ac6e3c8493ad77f0617aeee2834531f17a7a73aa | |
parent | f9c1f09a66f96929bd1d75d7aceaf3d8146cb9b6 (diff) | |
download | chromium_src-2b1223cc579afff030e8b59d3f1859eccf867556.zip chromium_src-2b1223cc579afff030e8b59d3f1859eccf867556.tar.gz chromium_src-2b1223cc579afff030e8b59d3f1859eccf867556.tar.bz2 |
AutoFill credit card settings dialog should display obfuscated number in edit field
Changes the AutoFillTextField class to properly initialize obfuscated credit card text in text field on the credit card editor sheet. Adds additional unit tests to verify that obfuscated text appears to the user.
Nib changes: Adds outlet for the credit card number text field for use in unit tests.
BUG=49988
TEST=AutoFillDialogControllerTest.CreditCardDataMutation
Review URL: http://codereview.chromium.org/2878050
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@53489 0039d316-1c4b-4281-b951-d872f2087c98
6 files changed, 75 insertions, 18 deletions
diff --git a/chrome/app/nibs/AutoFillCreditCardSheet.xib b/chrome/app/nibs/AutoFillCreditCardSheet.xib index 35ba3db..df91a8d1 100644 --- a/chrome/app/nibs/AutoFillCreditCardSheet.xib +++ b/chrome/app/nibs/AutoFillCreditCardSheet.xib @@ -666,6 +666,14 @@ </object> <int key="connectionID">252</int> </object> + <object class="IBConnectionRecord"> + <object class="IBOutletConnection" key="connection"> + <string key="label">creditCardNumberField_</string> + <reference key="source" ref="1001"/> + <reference key="destination" ref="289669180"/> + </object> + <int key="connectionID">257</int> + </object> </object> <object class="IBMutableOrderedSet" key="objectRecords"> <object class="NSArray" key="orderedObjects"> @@ -1000,6 +1008,7 @@ <string>-3.IBPluginDependency</string> <string>102.IBPluginDependency</string> <string>103.IBPluginDependency</string> + <string>104.IBEditorWindowLastContentRect</string> <string>104.IBPluginDependency</string> <string>105.IBPluginDependency</string> <string>106.IBPluginDependency</string> @@ -1048,6 +1057,7 @@ <string>com.apple.InterfaceBuilder.CocoaPlugin</string> <string>com.apple.InterfaceBuilder.CocoaPlugin</string> <string>com.apple.InterfaceBuilder.CocoaPlugin</string> + <string>{{549, 708}, {196, 63}}</string> <string>com.apple.InterfaceBuilder.CocoaPlugin</string> <string>com.apple.InterfaceBuilder.CocoaPlugin</string> <string>com.apple.InterfaceBuilder.CocoaPlugin</string> @@ -1063,9 +1073,9 @@ <string>com.apple.InterfaceBuilder.CocoaPlugin</string> <string>com.apple.InterfaceBuilder.CocoaPlugin</string> <string>com.apple.InterfaceBuilder.CocoaPlugin</string> - <string>{{465, 904}, {400, 225}}</string> + <string>{{413, 619}, {400, 225}}</string> <string>com.apple.InterfaceBuilder.CocoaPlugin</string> - <string>{{465, 904}, {400, 225}}</string> + <string>{{413, 619}, {400, 225}}</string> <boolean value="NO"/> <string>com.apple.InterfaceBuilder.CocoaPlugin</string> <string>AutoFillTextField</string> @@ -1108,7 +1118,7 @@ </object> </object> <nil key="sourceID"/> - <int key="maxID">256</int> + <int key="maxID">257</int> </object> <object class="IBClassDescriber" key="IBDocument.Classes"> <object class="NSMutableArray" key="referencedPartialClassDescriptions"> @@ -1135,6 +1145,7 @@ <bool key="EncodedWithXMLCoder">YES</bool> <string>billingAddressPopup_</string> <string>caption_</string> + <string>creditCardNumberField_</string> <string>expirationMonthPopup_</string> <string>expirationYearPopup_</string> </object> @@ -1142,6 +1153,7 @@ <bool key="EncodedWithXMLCoder">YES</bool> <string>NSPopUpButton</string> <string>NSTextField</string> + <string>NSTextField</string> <string>NSPopUpButton</string> <string>NSPopUpButton</string> </object> @@ -1226,6 +1238,13 @@ </object> </object> <object class="IBPartialClassDescription"> + <string key="className">NSView</string> + <object class="IBClassDescriptionSource" key="sourceIdentifier"> + <string key="majorKey">IBProjectSource</string> + <string key="minorKey">browser/cocoa/view_id_util.h</string> + </object> + </object> + <object class="IBPartialClassDescription"> <string key="className">NSWindow</string> <object class="IBClassDescriptionSource" key="sourceIdentifier"> <string key="majorKey">IBProjectSource</string> @@ -1816,6 +1835,27 @@ <string key="className">NSObject</string> <object class="IBClassDescriptionSource" key="sourceIdentifier"> <string key="majorKey">IBFrameworkSource</string> + <string key="minorKey">QuartzCore.framework/Headers/CAAnimation.h</string> + </object> + </object> + <object class="IBPartialClassDescription"> + <string key="className">NSObject</string> + <object class="IBClassDescriptionSource" key="sourceIdentifier"> + <string key="majorKey">IBFrameworkSource</string> + <string key="minorKey">QuartzCore.framework/Headers/CALayer.h</string> + </object> + </object> + <object class="IBPartialClassDescription"> + <string key="className">NSObject</string> + <object class="IBClassDescriptionSource" key="sourceIdentifier"> + <string key="majorKey">IBFrameworkSource</string> + <string key="minorKey">QuartzCore.framework/Headers/CIImageProvider.h</string> + </object> + </object> + <object class="IBPartialClassDescription"> + <string key="className">NSObject</string> + <object class="IBClassDescriptionSource" key="sourceIdentifier"> + <string key="majorKey">IBFrameworkSource</string> <string key="minorKey">SecurityInterface.framework/Headers/SFAuthorizationView.h</string> </object> </object> diff --git a/chrome/browser/autofill/autofill_credit_card_sheet_controller_mac.h b/chrome/browser/autofill/autofill_credit_card_sheet_controller_mac.h index 6fa281d..dd9461f 100644 --- a/chrome/browser/autofill/autofill_credit_card_sheet_controller_mac.h +++ b/chrome/browser/autofill/autofill_credit_card_sheet_controller_mac.h @@ -33,6 +33,10 @@ typedef NSInteger AutoFillCreditCardMode; // "New credit card" or "Edit credit card" depending on context. IBOutlet NSTextField* caption_; + // The credit card number field. This is here for unit testing purposes. + // The text of this field is obfuscated until edited. + IBOutlet NSTextField* creditCardNumberField_; + // The primary model for this controller. The model is instantiated // from within |initWithCreditCard:|. We do not hold it as a scoped_nsobject // because it is exposed as a KVO compliant property. @@ -79,4 +83,9 @@ typedef NSInteger AutoFillCreditCardMode; @end +// Interface exposed for unit testing. +@interface AutoFillCreditCardSheetController (ExposedForUnitTests) +- (NSTextField*)creditCardNumberField; +@end + #endif // CHROME_BROWSER_AUTOFILL_AUTOFILL_CREDIT_CARD_SHEET_CONTROLLER_MAC_ diff --git a/chrome/browser/autofill/autofill_credit_card_sheet_controller_mac.mm b/chrome/browser/autofill/autofill_credit_card_sheet_controller_mac.mm index 3a483c5..0c54efd 100644 --- a/chrome/browser/autofill/autofill_credit_card_sheet_controller_mac.mm +++ b/chrome/browser/autofill/autofill_credit_card_sheet_controller_mac.mm @@ -12,6 +12,13 @@ #include "chrome/browser/autofill/credit_card.h" #include "grit/generated_resources.h" +// Interface exposed for unit testing. +@implementation AutoFillCreditCardSheetController (ExposedForUnitTests) +- (NSTextField*)creditCardNumberField { + return creditCardNumberField_; +} +@end + // Private methods for the |AutoFillCreditCardSheetController| class. @interface AutoFillCreditCardSheetController (PrivateMethods) - (void)buildBillingAddressContents; diff --git a/chrome/browser/autofill/autofill_dialog_controller_mac_unittest.mm b/chrome/browser/autofill/autofill_dialog_controller_mac_unittest.mm index 96276e4..ac6833d 100644 --- a/chrome/browser/autofill/autofill_dialog_controller_mac_unittest.mm +++ b/chrome/browser/autofill/autofill_dialog_controller_mac_unittest.mm @@ -313,12 +313,18 @@ TEST_F(AutoFillDialogControllerTest, CreditCardDataMutation) { EXPECT_TRUE([[cm expirationMonth] isEqualToString:@"01"]); EXPECT_TRUE([[cm expirationYear] isEqualToString:@"2012"]); + // Check that user-visible text is obfuscated. + NSTextField* numberField = [sheet creditCardNumberField]; + ASSERT_TRUE(numberField != nil); + EXPECT_TRUE([[numberField stringValue] isEqualToString:@"************1121"]); + [sheet save:nil]; [controller_ save:nil]; ASSERT_TRUE(observer_.hit_); ASSERT_TRUE(observer_.credit_cards_.size() == 1); + // Don't compare unique ids. credit_cards()[0]->set_unique_id(observer_.credit_cards_[0].unique_id()); ASSERT_EQ(observer_.credit_cards_[0], *credit_cards()[0]); } diff --git a/chrome/browser/autofill/autofill_text_field_mac.h b/chrome/browser/autofill/autofill_text_field_mac.h index a774aca..e17bc95 100644 --- a/chrome/browser/autofill/autofill_text_field_mac.h +++ b/chrome/browser/autofill/autofill_text_field_mac.h @@ -9,8 +9,6 @@ #import "base/scoped_nsobject.h" -#define AUTOFILL_CC_TAG 22 - // Subclass of NSTextField with special abilities: // - automatically scrolls containing NSScrollView to visually reveal itself // on focus diff --git a/chrome/browser/autofill/autofill_text_field_mac.mm b/chrome/browser/autofill/autofill_text_field_mac.mm index ff5b1a0..509b1a6 100644 --- a/chrome/browser/autofill/autofill_text_field_mac.mm +++ b/chrome/browser/autofill/autofill_text_field_mac.mm @@ -10,22 +10,18 @@ @implementation AutoFillTextField - (void)awakeFromNib { - if ([self tag] == AUTOFILL_CC_TAG) + // Fields tagged with this value in the nib file will be treated as credit + // card number fields. + const int kAutoFillCreditCardTag = 22; + + if ([self tag] == kAutoFillCreditCardTag) { isCreditCardField_ = YES; -} -// Override NSResponder method for when the text field may gain focus. We -// call |scrollRectToVisible| to ensure that this text field is visible within -// the scrolling area. -- (BOOL)becomeFirstResponder { - // Vertical inset is negative to indicate "outset". Provides some visual - // space above and below when tabbing between fields. - const CGFloat kVerticalInset = -40.0; - BOOL becoming = [super becomeFirstResponder]; - if (becoming) { - [self scrollRectToVisible:NSInsetRect([self bounds], 0.0, kVerticalInset)]; + // KVO bindings initialize fields prior to |awakeFromNib|. In the credit + // card field case we need to re-initialize the value to the obfuscated + // version. + [self setObjectValue:[self objectValue]]; } - return becoming; } - (void)setObjectValue:(id)object { @@ -51,6 +47,7 @@ // fetched if it is changed, and since we force selection, that should clear // the obfuscation. Nevertheless, we'll be paranoid here since we don't want // the obfuscating ***s to end up in the database. + NOTREACHED(); return obfuscatedValue_.get(); } else { return [super objectValue]; |