0

[iOSAddAddressManually] Disable 'Save' button at start.

This CL adds the functionality to disable the 'Save' button when we
first open the bottom sheet to add an address manually through settings.

Bug: 393353721
Change-Id: Icc24f85221b9ce1b11b7eab1b34e154a7f0f4aaa
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/6378023
Reviewed-by: Alexis Hétu <sugoi@chromium.org>
Commit-Queue: Sourav Uttam Sinha <sinhasourav@google.com>
Reviewed-by: Noémie St-Onge <noemies@google.com>
Cr-Commit-Position: refs/heads/main@{#1440426}
This commit is contained in:
Sourav
2025-03-31 11:28:15 -07:00
committed by Chromium LUCI CQ
parent 02c615589e
commit f64ec2f778
12 changed files with 75 additions and 26 deletions

@@ -25,7 +25,9 @@
(id<AutofillProfileEditTableViewControllerDelegate>)delegate
userEmail:(NSString*)userEmail
controller:(LegacyChromeTableViewController*)controller
settingsView:(BOOL)settingsView NS_DESIGNATED_INITIALIZER;
settingsView:(BOOL)settingsView
addManualAddress:(BOOL)addManualAddress
NS_DESIGNATED_INITIALIZER;
- (instancetype)init NS_UNAVAILABLE;

@@ -59,6 +59,9 @@ const CGFloat kLineSpacingBetweenErrorAndFooter = 12.0f;
// If YES, denotes that the view is shown in the settings.
BOOL _settingsView;
// If YES, the new address is being added manually.
BOOL _addManualAddress;
// Points to the save/update button in the modal view.
TableViewTextButtonItem* _modalSaveUpdateButton;
@@ -82,7 +85,8 @@ const CGFloat kLineSpacingBetweenErrorAndFooter = 12.0f;
(id<AutofillProfileEditTableViewControllerDelegate>)delegate
userEmail:(NSString*)userEmail
controller:(LegacyChromeTableViewController*)controller
settingsView:(BOOL)settingsView {
settingsView:(BOOL)settingsView
addManualAddress:(BOOL)addManualAddress {
self = [super init];
if (self) {
_delegate = delegate;
@@ -90,6 +94,7 @@ const CGFloat kLineSpacingBetweenErrorAndFooter = 12.0f;
_accountProfile = NO;
_controller = controller;
_settingsView = settingsView;
_addManualAddress = addManualAddress;
_moveToAccountFromSettings = NO;
_dynamicallyLoadInputFieldsEnabled = base::FeatureList::IsEnabled(
kAutofillDynamicallyLoadsFieldsForAddressInput);
@@ -681,7 +686,9 @@ const CGFloat kLineSpacingBetweenErrorAndFooter = 12.0f;
update ? IDS_AUTOFILL_UPDATE_ADDRESS_PROMPT_OK_BUTTON_LABEL
: IDS_AUTOFILL_SAVE_ADDRESS_PROMPT_OK_BUTTON_LABEL);
}
// TODO:(crbug.com/393353721): Set button enabled state.
// The button should initially be disabled when manually adding a new address
// to the account.
buttonFooter.enabled = !_addManualAddress || !_accountProfile;
return buttonFooter;
}

@@ -66,7 +66,8 @@ class AutofillProfileEditTableViewControllerTest
initWithDelegate:autofill_profile_edit_mediator_
userEmail:base::SysUTF16ToNSString(kTestSyncingEmail)
controller:controller()
settingsView:GetParam().is_settings];
settingsView:GetParam().is_settings
addManualAddress:NO];
autofill_profile_edit_mediator_.consumer =
autofill_profile_edit_table_view_controller_;

@@ -100,7 +100,8 @@
initWithDelegate:_autofillProfileEditMediator
userEmail:[_handler userEmail]
controller:editModalViewController
settingsView:NO];
settingsView:NO
addManualAddress:[_handler addingManualAddress]];
_autofillProfileEditMediator.consumer =
_autofillProfileEditTableViewController;
// `editModalViewController` lays down the bottom sheet view and communicates

@@ -39,6 +39,9 @@
// Returns the user's email address.
- (NSString*)userEmail;
// Returns if the address is being added manually.
- (BOOL)addingManualAddress;
@end
#endif // IOS_CHROME_BROWSER_AUTOFILL_UI_BUNDLED_BOTTOM_SHEET_AUTOFILL_EDIT_PROFILE_BOTTOM_SHEET_HANDLER_H_

@@ -99,6 +99,10 @@
: nil;
}
- (BOOL)addingManualAddress {
return NO;
}
#pragma mark - Private
// Retrieves the AutofillSaveUpdateAddressProfileDelegateIOS from the address

@@ -72,4 +72,8 @@
return _userEmail;
}
- (BOOL)addingManualAddress {
return YES;
}
@end

@@ -69,7 +69,8 @@ class LegacyInfobarEditAddressProfileTableViewControllerTest
initWithDelegate:autofill_profile_edit_mediator_
userEmail:base::SysUTF16ToNSString(kTestSyncingEmail)
controller:viewController
settingsView:NO];
settingsView:NO
addManualAddress:NO];
viewController.handler = autofill_profile_edit_table_view_controller_;
autofill_profile_edit_mediator_.consumer =
autofill_profile_edit_table_view_controller_;

@@ -126,7 +126,8 @@ using autofill_address_profile_infobar_overlays::
? base::SysUTF16ToNSString(
self.config->user_email().value())
: nil)controller:editModalViewController
settingsView:NO];
settingsView:NO
addManualAddress:NO];
self.sharedEditViewMediator.consumer = self.sharedEditViewController;
editModalViewController.handler = self.sharedEditViewController;

@@ -6,6 +6,7 @@
#import "components/autofill/core/browser/field_types.h"
#import "components/autofill/ios/common/features.h"
#import "components/strings/grit/components_strings.h"
#import "ios/chrome/browser/authentication/ui_bundled/signin_earl_grey.h"
#import "ios/chrome/browser/authentication/ui_bundled/signin_earl_grey_ui_test_util.h"
#import "ios/chrome/browser/autofill/ui_bundled/autofill_app_interface.h"
#import "ios/chrome/browser/signin/model/fake_system_identity.h"
@@ -22,7 +23,6 @@ using chrome_test_util::ButtonWithAccessibilityLabelId;
using chrome_test_util::SettingsDoneButton;
using chrome_test_util::SettingsMenuBackButton;
using chrome_test_util::SettingsToolbarAddButton;
using chrome_test_util::SettingsToolbarEditButton;
namespace {
@@ -145,6 +145,7 @@ void OpenAddressSettings() {
// Tests adding an account address manually through settings.
- (void)testAddAccountAddressManually {
// The user needs to be signed in for the address to be saved to the account.
[SigninEarlGreyUI signinWithFakeIdentity:[FakeSystemIdentity fakeIdentity1]];
[ChromeEarlGrey waitForSyncTransportStateActiveWithTimeout:base::Seconds(10)];
@@ -183,29 +184,49 @@ void OpenAddressSettings() {
// as expected.
}
// Tests that the toolbar is visible after saving an address manually through
// settings.
- (void)testToolbarVisibility {
// Tests the 'Save' button enabled state when manually adding an address to the
// account.
- (void)testButtonEnabledStateAtStartForAccountAddress {
// TODO(crbug.com/407506623): Fix EGTests on iPad.
if ([ChromeEarlGrey isIPadIdiom]) {
EARL_GREY_TEST_SKIPPED(@"Test fails on iPad currently.");
}
// The user needs to be signed in for the address to be saved to the account.
[SigninEarlGreyUI signinWithFakeIdentity:[FakeSystemIdentity fakeIdentity1]];
[ChromeEarlGrey waitForSyncTransportStateActiveWithTimeout:base::Seconds(10)];
OpenAddressSettings();
// Tap the "Add" button.
[[EarlGrey selectElementWithMatcher:SettingsToolbarAddButton()]
performAction:grey_tap()];
// Fill the required fields.
[self fillRequiredFields];
// Save the profile.
// Ensure the 'Save' button is initially disabled for an account address.
[[EarlGrey selectElementWithMatcher:SaveAddressButton()]
assertWithMatcher:grey_not(grey_enabled())];
// Sign out.
[SigninEarlGrey signOut];
}
// Tests the 'Save' button enabled state when manually adding a local address.
- (void)testButtonEnabledStateAtStartForLocalAddress {
// TODO(crbug.com/407506623): Fix EGTests on iPad.
if ([ChromeEarlGrey isIPadIdiom]) {
EARL_GREY_TEST_SKIPPED(@"Test fails on iPad currently.");
}
OpenAddressSettings();
// Tap the "Add" button.
[[EarlGrey selectElementWithMatcher:SettingsToolbarAddButton()]
performAction:grey_tap()];
// Ensure "Add" button is visible.
[[EarlGrey selectElementWithMatcher:SettingsToolbarAddButton()]
assertWithMatcher:grey_sufficientlyVisible()];
// Ensure "Edit" button is visible.
[[EarlGrey selectElementWithMatcher:SettingsToolbarEditButton()]
assertWithMatcher:grey_sufficientlyVisible()];
// Ensure the 'Save' button is initially enabled for a local address (user is
// signed out).
[[EarlGrey selectElementWithMatcher:SaveAddressButton()]
assertWithMatcher:grey_enabled()];
}
@end

@@ -94,7 +94,8 @@
initWithDelegate:_mediator
userEmail:[self userEmail]
controller:_viewController
settingsView:YES];
settingsView:YES
addManualAddress:NO];
_mediator.consumer = _sharedViewController;
_viewController.handler = _sharedViewController;
_viewController.snackbarCommandsHandler = HandlerForProtocol(

@@ -69,7 +69,8 @@ class AutofillSettingsProfileEditTableViewControllerTest
initWithDelegate:autofill_profile_edit_mediator_
userEmail:nil
controller:viewController
settingsView:YES];
settingsView:YES
addManualAddress:NO];
viewController.handler = autofill_profile_edit_table_view_controller_;
autofill_profile_edit_mediator_.consumer =
autofill_profile_edit_table_view_controller_;
@@ -110,7 +111,8 @@ class AutofillSettingsProfileEditTableViewControllerTestWithUnionViewEnabled
initWithDelegate:autofill_profile_edit_mediator_
userEmail:base::SysUTF16ToNSString(kTestSyncingEmail)
controller:viewController
settingsView:YES];
settingsView:YES
addManualAddress:NO];
viewController.handler = autofill_profile_edit_table_view_controller_;
autofill_profile_edit_mediator_.consumer =
autofill_profile_edit_table_view_controller_;
@@ -205,7 +207,8 @@ class AutofillSettingsProfileEditTableViewControllerWithMigrationButtonTest
initWithDelegate:autofill_profile_edit_mediator_
userEmail:base::SysUTF16ToNSString(kTestSyncingEmail)
controller:viewController
settingsView:YES];
settingsView:YES
addManualAddress:NO];
viewController.handler = autofill_profile_edit_table_view_controller_;
autofill_profile_edit_mediator_.consumer =
autofill_profile_edit_table_view_controller_;