diff options
author | dhollowa@chromium.org <dhollowa@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-06-02 01:23:12 +0000 |
---|---|---|
committer | dhollowa@chromium.org <dhollowa@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-06-02 01:23:12 +0000 |
commit | a7837ccc9c5db0b7a6f67bfbc420731aaef3ce04 (patch) | |
tree | eae6b51915d1f86262ea39483043da939e70d635 /chrome/browser | |
parent | e03f3980cc903b21f1a17bb1aa51927107c19cec (diff) | |
download | chromium_src-a7837ccc9c5db0b7a6f67bfbc420731aaef3ce04.zip chromium_src-a7837ccc9c5db0b7a6f67bfbc420731aaef3ce04.tar.gz chromium_src-a7837ccc9c5db0b7a6f67bfbc420731aaef3ce04.tar.bz2 |
AutoFill remove defaults from settings dialog
The new AutoFill dialog mocks eliminate the need for a "default" address and credit card. Removing code related to UI for these defaults. Nib changes: Removed the "Default" radio button from each of the Nibs.
BUG=44621
TEST=AutoFillDialogControllerTest.*:-AutoFillDialogControllerTest.DefaultsChangingLogic
Review URL: http://codereview.chromium.org/2466002
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@48687 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser')
7 files changed, 1 insertions, 295 deletions
diff --git a/chrome/browser/autofill/autofill_address_view_controller_mac.h b/chrome/browser/autofill/autofill_address_view_controller_mac.h index cdbb899..2367f8d 100644 --- a/chrome/browser/autofill/autofill_address_view_controller_mac.h +++ b/chrome/browser/autofill/autofill_address_view_controller_mac.h @@ -31,8 +31,6 @@ class AutoFillProfile; AutoFillDialogController* parentController_; } -@property (readonly) BOOL canAlterDefault; -@property BOOL isDefault; @property (nonatomic, retain) AutoFillAddressModel* addressModel; // Designated initializer. Takes a copy of the data in |profile|, diff --git a/chrome/browser/autofill/autofill_address_view_controller_mac.mm b/chrome/browser/autofill/autofill_address_view_controller_mac.mm index dcf8a12..e3163f8 100644 --- a/chrome/browser/autofill/autofill_address_view_controller_mac.mm +++ b/chrome/browser/autofill/autofill_address_view_controller_mac.mm @@ -12,8 +12,6 @@ @interface AutoFillAddressViewController (PrivateMethods) - (void)labelChanged:(GTMKeyValueChangeNotification*)notification; -- (void)addressesChanged:(GTMKeyValueChangeNotification*)notification; -- (void)defaultChanged:(GTMKeyValueChangeNotification*)notification; @end @implementation AutoFillAddressViewController @@ -38,22 +36,12 @@ parentController_ = parentController; // Register |self| as observer so we can notify parent controller. See - // |observeValueForKeyPath:| for details. + // |labelChanged:| for details. [addressModel_ gtm_addObserver:self forKeyPath:@"label" selector:@selector(labelChanged:) userInfo:nil options:0]; - [parentController_ gtm_addObserver:self - forKeyPath:@"addressLabels" - selector:@selector(addressesChanged:) - userInfo:nil - options:0]; - [parentController_ gtm_addObserver:self - forKeyPath:@"defaultAddressLabel" - selector:@selector(defaultChanged:) - userInfo:nil - options:0]; } return self; } @@ -62,12 +50,6 @@ [addressModel_ gtm_removeObserver:self forKeyPath:@"label" selector:@selector(labelChanged:)]; - [parentController_ gtm_removeObserver:self - forKeyPath:@"addressLabels" - selector:@selector(addressesChanged:)]; - [parentController_ gtm_removeObserver:self - forKeyPath:@"defaultAddressLabel" - selector:@selector(defaultChanged:)]; [addressModel_ release]; [super dealloc]; } @@ -78,16 +60,6 @@ [parentController_ notifyAddressChange:self]; } -- (void)addressesChanged:(GTMKeyValueChangeNotification*)notification { - [self willChangeValueForKey:@"canAlterDefault"]; - [self didChangeValueForKey:@"canAlterDefault"]; -} - -- (void)defaultChanged:(GTMKeyValueChangeNotification*)notification { - [self willChangeValueForKey:@"isDefault"]; - [self didChangeValueForKey:@"isDefault"]; -} - - (IBAction)deleteAddress:(id)sender { [parentController_ deleteAddress:self]; } @@ -96,19 +68,6 @@ [addressModel_ copyModelToProfile:profile]; } -- (BOOL)canAlterDefault { - return [[parentController_ addressLabels] count] > 1; -} - -- (BOOL)isDefault { - return - [[addressModel_ label] isEqual:[parentController_ defaultAddressLabel]]; -} - -- (void)setIsDefault:(BOOL)def { - [parentController_ setDefaultAddressLabel:def ? [addressModel_ label] : nil]; -} - @end diff --git a/chrome/browser/autofill/autofill_credit_card_view_controller_mac.h b/chrome/browser/autofill/autofill_credit_card_view_controller_mac.h index ba62e7a..054252f 100644 --- a/chrome/browser/autofill/autofill_credit_card_view_controller_mac.h +++ b/chrome/browser/autofill/autofill_credit_card_view_controller_mac.h @@ -44,8 +44,6 @@ class CreditCard; AutoFillDialogController* parentController_; } -@property (readonly) BOOL canAlterDefault; -@property BOOL isDefault; @property (nonatomic, retain) AutoFillCreditCardModel* creditCardModel; @property (nonatomic, retain) NSArray* billingAddressContents; @property (nonatomic, retain) NSArray* shippingAddressContents; diff --git a/chrome/browser/autofill/autofill_credit_card_view_controller_mac.mm b/chrome/browser/autofill/autofill_credit_card_view_controller_mac.mm index 0151869..8e7b29c 100644 --- a/chrome/browser/autofill/autofill_credit_card_view_controller_mac.mm +++ b/chrome/browser/autofill/autofill_credit_card_view_controller_mac.mm @@ -10,14 +10,11 @@ #import "chrome/browser/autofill/autofill_dialog_controller_mac.h" #include "chrome/browser/autofill/credit_card.h" #include "grit/generated_resources.h" -#import "third_party/GTM/Foundation/GTMNSObject+KeyValueObserving.h" // Private methods for the |AutoFillCreditCardViewController| class. @interface AutoFillCreditCardViewController (PrivateMethods) - (void)rebuildBillingAddressContents; - (void)rebuildShippingAddressContents; -- (void)creditCardsChanged:(GTMKeyValueChangeNotification*)notification; -- (void)defaultChanged:(GTMKeyValueChangeNotification*)notification; @end @implementation AutoFillCreditCardViewController @@ -45,28 +42,11 @@ // Setup initial state of popups. [self onAddressesChanged:self]; - - [parentController_ gtm_addObserver:self - forKeyPath:@"creditCardLabels" - selector:@selector(creditCardsChanged:) - userInfo:nil - options:0]; - [parentController_ gtm_addObserver:self - forKeyPath:@"defaultCreditCardLabel" - selector:@selector(defaultChanged:) - userInfo:nil - options:0]; } return self; } - (void)dealloc { - [parentController_ gtm_removeObserver:self - forKeyPath:@"creditCardLabels" - selector:@selector(creditCardsChanged:)]; - [parentController_ gtm_removeObserver:self - forKeyPath:@"defaultCreditCardLabel" - selector:@selector(defaultChanged:)]; [creditCardModel_ release]; [billingAddressContents_ release]; [shippingAddressContents_ release]; @@ -101,30 +81,6 @@ creditCard->set_shipping_address(string16()); } -- (void)creditCardsChanged:(GTMKeyValueChangeNotification*)notification { - [self willChangeValueForKey:@"canAlterDefault"]; - [self didChangeValueForKey:@"canAlterDefault"]; -} - -- (void)defaultChanged:(GTMKeyValueChangeNotification*)notification { - [self willChangeValueForKey:@"isDefault"]; - [self didChangeValueForKey:@"isDefault"]; -} - -- (BOOL)canAlterDefault { - return [[parentController_ creditCardLabels] count] > 1; -} - -- (BOOL)isDefault { - return [[creditCardModel_ label] isEqual: - [parentController_ defaultCreditCardLabel]]; -} - -- (void)setIsDefault:(BOOL)def { - [parentController_ setDefaultCreditCardLabel: - def ? [creditCardModel_ label] : nil]; -} - // Builds the |billingAddressContents_| array of strings from the list of // addresses returned by the |parentController_| and additional UI string. // Ensures that current selection is valid, if not reset it. diff --git a/chrome/browser/autofill/autofill_dialog_controller_mac.h b/chrome/browser/autofill/autofill_dialog_controller_mac.h index 220634b..3ea6900 100644 --- a/chrome/browser/autofill/autofill_dialog_controller_mac.h +++ b/chrome/browser/autofill/autofill_dialog_controller_mac.h @@ -43,9 +43,6 @@ class Profile; // Array of |AutoFillCreditCardViewController|. scoped_nsobject<NSMutableArray> creditCardFormViewControllers_; - scoped_nsobject<NSString> defaultAddressLabel_; - scoped_nsobject<NSString> defaultCreditCardLabel_; - AutoFillDialogObserver* observer_; // Weak, not retained. Profile* profile_; // Weak, not retained. AutoFillProfile* importedProfile_; // Weak, not retained. @@ -64,10 +61,6 @@ class Profile; // bound to this in nib. @property (nonatomic) BOOL auxiliaryEnabled; -// Property representing the default profile and credit card. -@property (nonatomic, copy) NSString* defaultAddressLabel; -@property (nonatomic, copy) NSString* defaultCreditCardLabel; - // Main interface for displaying an application modal autofill dialog on screen. // This class method creates a new |AutoFillDialogController| and runs it as a // modal dialog. The controller autoreleases itself when the dialog is closed. diff --git a/chrome/browser/autofill/autofill_dialog_controller_mac.mm b/chrome/browser/autofill/autofill_dialog_controller_mac.mm index 2e3a180..c867497 100644 --- a/chrome/browser/autofill/autofill_dialog_controller_mac.mm +++ b/chrome/browser/autofill/autofill_dialog_controller_mac.mm @@ -180,13 +180,6 @@ void PersonalDataManagerObserver::OnPersonalDataLoaded() { } profile_->GetPrefs()->SetBoolean(prefs::kAutoFillAuxiliaryProfilesEnabled, auxiliaryEnabled_); - // Make sure to use accessors here to save what the user sees. - profile_->GetPrefs()->SetString( - prefs::kAutoFillDefaultProfile, - base::SysNSStringToWide([self defaultAddressLabel])); - profile_->GetPrefs()->SetString( - prefs::kAutoFillDefaultCreditCard, - base::SysNSStringToWide([self defaultCreditCardLabel])); observer_->OnAutoFillDialogApply(&profiles_, &creditCards_); } [self closeDialog]; @@ -223,9 +216,6 @@ void PersonalDataManagerObserver::OnPersonalDataLoaded() { [self willChangeValueForKey:@"addressLabels"]; [addressFormViewControllers_.get() addObject:addressViewController]; [self didChangeValueForKey:@"addressLabels"]; - // Might need to reset the default if added. - [self willChangeValueForKey:@"defaultAddressLabel"]; - [self didChangeValueForKey:@"defaultAddressLabel"]; // Embed the new address into our target view. [childView_ addSubview:[addressViewController view] @@ -263,9 +253,6 @@ void PersonalDataManagerObserver::OnPersonalDataLoaded() { [self willChangeValueForKey:@"creditCardLabels"]; [creditCardFormViewControllers_.get() addObject:creditCardViewController]; [self didChangeValueForKey:@"creditCardLabels"]; - // Might need to reset the default if added. - [self willChangeValueForKey:@"defaultCreditCardLabel"]; - [self didChangeValueForKey:@"defaultCreditCardLabel"]; // Embed the new address into our target view. [childView_ addSubview:[creditCardViewController view] @@ -289,9 +276,6 @@ void PersonalDataManagerObserver::OnPersonalDataLoaded() { [self willChangeValueForKey:@"addressLabels"]; [addressFormViewControllers_.get() removeObjectAtIndex:i]; [self didChangeValueForKey:@"addressLabels"]; - // Might need to reset the default if deleted. - [self willChangeValueForKey:@"defaultAddressLabel"]; - [self didChangeValueForKey:@"defaultAddressLabel"]; [self notifyAddressChange:self]; @@ -312,9 +296,6 @@ void PersonalDataManagerObserver::OnPersonalDataLoaded() { [self willChangeValueForKey:@"creditCardLabels"]; [creditCardFormViewControllers_.get() removeObjectAtIndex:i]; [self didChangeValueForKey:@"creditCardLabels"]; - // Might need to reset the default if deleted. - [self willChangeValueForKey:@"defaultCreditCardLabel"]; - [self didChangeValueForKey:@"defaultCreditCardLabel"]; // Recalculate key view loop to account for change in view tree. [[self window] recalculateKeyViewLoop]; @@ -353,104 +334,6 @@ void PersonalDataManagerObserver::OnPersonalDataLoaded() { return array; } -- (NSString*)defaultAddressLabel { - NSArray* labels = [self addressLabels]; - NSString* def = defaultAddressLabel_.get(); - if ([def length] && [labels containsObject:def]) - return def; - - // No valid default; pick the first item. - if ([labels count]) { - return [labels objectAtIndex:0]; - } else { - return @""; - } -} - -- (void)setDefaultAddressLabel:(NSString*)label { - if (!label) { - // Setting nil means the user un-checked an item. Find a new default. - NSUInteger itemCount = [addressFormViewControllers_ count]; - if (itemCount == 0) { - DCHECK(false) << "Attempt to set default when there are no items."; - return; - } else if (itemCount == 1) { - DCHECK(false) << "Attempt to set default when there is only one item, so " - "it should have been disabled."; - AutoFillAddressViewController* controller = - [addressFormViewControllers_ objectAtIndex:0]; - label = [[controller addressModel] label]; - } else { - AutoFillAddressViewController* controller = - [addressFormViewControllers_ objectAtIndex:0]; - NSString* firstItemsLabel = [[controller addressModel] label]; - - // If they unchecked an item that wasn't the first item, make the first - // item default. - if (![defaultAddressLabel_ isEqual:firstItemsLabel]) { - label = firstItemsLabel; - } else { - // Otherwise they unchecked the first item. Pick the second one for 'em. - AutoFillAddressViewController* controller = - [addressFormViewControllers_ objectAtIndex:1]; - label = [[controller addressModel] label]; - } - } - } - - defaultAddressLabel_.reset([label copy]); - return; -} - -- (NSString*)defaultCreditCardLabel { - NSArray* labels = [self creditCardLabels]; - NSString* def = defaultCreditCardLabel_.get(); - if ([def length] && [labels containsObject:def]) - return def; - - // No valid default; pick the first item. - if ([labels count]) { - return [labels objectAtIndex:0]; - } else { - return @""; - } -} - -- (void)setDefaultCreditCardLabel:(NSString*)label { - if (!label) { - // Setting nil means the user un-checked an item. Find a new default. - NSUInteger itemCount = [creditCardFormViewControllers_ count]; - if (itemCount == 0) { - DCHECK(false) << "Attempt to set default when there are no items."; - return; - } else if (itemCount == 1) { - DCHECK(false) << "Attempt to set default when there is only one item, so " - "it should have been disabled."; - AutoFillCreditCardViewController* controller = - [creditCardFormViewControllers_ objectAtIndex:0]; - label = [[controller creditCardModel] label]; - } else { - AutoFillCreditCardViewController* controller = - [creditCardFormViewControllers_ objectAtIndex:0]; - NSString* firstItemsLabel = [[controller creditCardModel] label]; - - // If they unchecked an item that wasn't the first item, make the first - // item default. - if (![defaultCreditCardLabel_ isEqual:firstItemsLabel]) { - label = firstItemsLabel; - } else { - // Otherwise they unchecked the first item. Pick the second one for 'em. - AutoFillCreditCardViewController* controller = - [creditCardFormViewControllers_ objectAtIndex:1]; - label = [[controller creditCardModel] label]; - } - } - } - - defaultCreditCardLabel_.reset([label copy]); - return; -} - @end @implementation AutoFillDialogController (ExposedForUnitTests) @@ -505,14 +388,6 @@ void PersonalDataManagerObserver::OnPersonalDataLoaded() { // Initialize array of sub-controllers. creditCardFormViewControllers_.reset( [[NSMutableArray alloc] initWithCapacity:0]); - - NSString* defaultAddressLabel = base::SysWideToNSString( - profile_->GetPrefs()->GetString(prefs::kAutoFillDefaultProfile)); - defaultAddressLabel_.reset([defaultAddressLabel retain]); - - NSString* defaultCreditCardLabel = base::SysWideToNSString( - profile_->GetPrefs()->GetString(prefs::kAutoFillDefaultCreditCard)); - defaultCreditCardLabel_.reset([defaultCreditCardLabel retain]); } return self; } @@ -593,13 +468,6 @@ void PersonalDataManagerObserver::OnPersonalDataLoaded() { insertionPoint = [creditCardViewController view]; [[creditCardViewController view] setFrameOrigin:NSMakePoint(0, 0)]; } - - // During initialization the default accessors were returning faulty values - // since the controller arrays weren't set up. Poke our observers. - [self willChangeValueForKey:@"defaultAddressLabel"]; - [self didChangeValueForKey:@"defaultAddressLabel"]; - [self willChangeValueForKey:@"defaultCreditCardLabel"]; - [self didChangeValueForKey:@"defaultCreditCardLabel"]; } - (void)onPersonalDataLoaded:(const std::vector<AutoFillProfile*>&)profiles diff --git a/chrome/browser/autofill/autofill_dialog_controller_mac_unittest.mm b/chrome/browser/autofill/autofill_dialog_controller_mac_unittest.mm index bd72c29..fb1f38e 100644 --- a/chrome/browser/autofill/autofill_dialog_controller_mac_unittest.mm +++ b/chrome/browser/autofill/autofill_dialog_controller_mac_unittest.mm @@ -531,72 +531,6 @@ TEST_F(AutoFillDialogControllerTest, AuxiliaryProfilesChanged) { prefs::kAutoFillAuxiliaryProfilesEnabled)); } -TEST_F(AutoFillDialogControllerTest, DefaultsChangingLogic) { - // Two profiles, two credit cards. - AutoFillProfile profile(ASCIIToUTF16("One"), 1); - profile.SetInfo(AutoFillType(NAME_FIRST), ASCIIToUTF16("Joe")); - profiles().push_back(&profile); - AutoFillProfile profile2(ASCIIToUTF16("Two"), 2); - profile2.SetInfo(AutoFillType(NAME_FIRST), ASCIIToUTF16("Bob")); - profiles().push_back(&profile2); - CreditCard credit_card(ASCIIToUTF16("Visa"), 1); - credit_card.SetInfo(AutoFillType(CREDIT_CARD_NAME), ASCIIToUTF16("Joe")); - credit_cards().push_back(&credit_card); - CreditCard credit_card2(ASCIIToUTF16("Mastercard"), 2); - credit_card2.SetInfo(AutoFillType(CREDIT_CARD_NAME), ASCIIToUTF16("Bob")); - credit_cards().push_back(&credit_card2); - - // Invalid defaults for each. - helper_.profile()->GetPrefs()->SetString( - prefs::kAutoFillDefaultProfile, L"xxxx"); - helper_.profile()->GetPrefs()->SetString( - prefs::kAutoFillDefaultCreditCard, L"yyyy"); - - // Start 'em up. - LoadDialog(); - - // With invalid default values, the first item should be the default. - EXPECT_TRUE([[controller_ defaultAddressLabel] isEqualToString:@"One"]); - EXPECT_TRUE([[controller_ defaultCreditCardLabel] isEqualToString:@"Visa"]); - - // Explicitly set the second to be default and make sure it sticks. - [controller_ setDefaultAddressLabel:@"Two"]; - [controller_ setDefaultCreditCardLabel:@"Mastercard"]; - ASSERT_TRUE([[controller_ defaultAddressLabel] isEqualToString:@"Two"]); - ASSERT_TRUE([[controller_ defaultCreditCardLabel] - isEqualToString:@"Mastercard"]); - - // Deselect the second and the first should become default. - [controller_ setDefaultAddressLabel:nil]; - [controller_ setDefaultCreditCardLabel:nil]; - ASSERT_TRUE([[controller_ defaultAddressLabel] isEqualToString:@"One"]); - ASSERT_TRUE([[controller_ defaultCreditCardLabel] isEqualToString:@"Visa"]); - - // Deselect the first and the second should be come default. - [controller_ setDefaultAddressLabel:nil]; - [controller_ setDefaultCreditCardLabel:nil]; - ASSERT_TRUE([[controller_ defaultAddressLabel] isEqualToString:@"Two"]); - ASSERT_TRUE([[controller_ defaultCreditCardLabel] - isEqualToString:@"Mastercard"]); - - // Delete the second and the first should end up as default. - [controller_ deleteAddress:[[controller_ addressFormViewControllers] - lastObject]]; - [controller_ deleteCreditCard:[[controller_ creditCardFormViewControllers] - lastObject]]; - ASSERT_TRUE([[controller_ defaultAddressLabel] isEqualToString:@"One"]); - ASSERT_TRUE([[controller_ defaultCreditCardLabel] isEqualToString:@"Visa"]); - - // Save and that should end up in the prefs. - [controller_ save:nil]; - ASSERT_TRUE(observer_.hit_); - - ASSERT_EQ(L"One", helper_.profile()->GetPrefs()-> - GetString(prefs::kAutoFillDefaultProfile)); - ASSERT_EQ(L"Visa", helper_.profile()->GetPrefs()-> - GetString(prefs::kAutoFillDefaultCreditCard)); -} - TEST_F(AutoFillDialogControllerTest, WaitForDataToLoad) { AutoFillProfile profile(ASCIIToUTF16("Home"), 0); profiles().push_back(&profile); |