Commit ffe9f7d6 authored by Viktor Semeniuk's avatar Viktor Semeniuk Committed by Commit Bot

[iOS] Replacing Back button with Cancel during editing

This change replace back button with cancel during editing.

Bug: 1146127
Change-Id: I7feed5cdc201d2239d0dd957119a31330f5b23ec
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2526085
Commit-Queue: Viktor Semeniuk <vsemeniuk@google.com>
Reviewed-by: default avatarSergio Collazos <sczs@chromium.org>
Reviewed-by: default avatarGauthier Ambard <gambard@chromium.org>
Cr-Commit-Position: refs/heads/master@{#831082}
parent 895dc6c8
...@@ -133,8 +133,10 @@ typedef NS_ENUM(NSInteger, ReauthenticationReason) { ...@@ -133,8 +133,10 @@ typedef NS_ENUM(NSInteger, ReauthenticationReason) {
if (self.tableView.editing) { if (self.tableView.editing) {
// If password or username value was changed show confirmation dialog before // If password or username value was changed show confirmation dialog before
// saving password. Editing mode will be exited only if user confirm saving. // saving password. Editing mode will be exited only if user confirm saving.
if (self.password.password != self.passwordTextItem.textFieldValue || if (![self.password.password
self.password.username != self.usernameTextItem.textFieldValue) { isEqualToString:self.passwordTextItem.textFieldValue] ||
![self.password.username
isEqualToString:self.usernameTextItem.textFieldValue]) {
[self.handler showPasswordEditDialogWithOrigin:self.password.origin]; [self.handler showPasswordEditDialogWithOrigin:self.password.origin];
} else { } else {
[self passwordEditingConfirmed]; [self passwordEditingConfirmed];
...@@ -185,6 +187,10 @@ typedef NS_ENUM(NSInteger, ReauthenticationReason) { ...@@ -185,6 +187,10 @@ typedef NS_ENUM(NSInteger, ReauthenticationReason) {
} }
} }
- (BOOL)showCancelDuringEditing {
return YES;
}
#pragma mark - Items #pragma mark - Items
- (TableViewTextEditItem*)websiteItem { - (TableViewTextEditItem*)websiteItem {
......
...@@ -49,6 +49,7 @@ GREY_STUB_CLASS_IN_APP_MAIN_QUEUE(PasswordSettingsAppInterface); ...@@ -49,6 +49,7 @@ GREY_STUB_CLASS_IN_APP_MAIN_QUEUE(PasswordSettingsAppInterface);
using chrome_test_util::ButtonWithAccessibilityLabel; using chrome_test_util::ButtonWithAccessibilityLabel;
using chrome_test_util::ButtonWithAccessibilityLabelId; using chrome_test_util::ButtonWithAccessibilityLabelId;
using chrome_test_util::NavigationBarCancelButton;
using chrome_test_util::NavigationBarDoneButton; using chrome_test_util::NavigationBarDoneButton;
using chrome_test_util::SettingsDoneButton; using chrome_test_util::SettingsDoneButton;
using chrome_test_util::SettingsMenuBackButton; using chrome_test_util::SettingsMenuBackButton;
...@@ -691,20 +692,10 @@ void CopyPasswordDetailWithID(int detail_id) { ...@@ -691,20 +692,10 @@ void CopyPasswordDetailWithID(int detail_id) {
[[EarlGrey selectElementWithMatcher:DeleteButton()] performAction:grey_tap()]; [[EarlGrey selectElementWithMatcher:DeleteButton()] performAction:grey_tap()];
// Tap the alert's Cancel button to cancel. // Close the dialog by taping on Password Details screen.
if ([ChromeEarlGrey isIPadIdiom]) { [[EarlGrey selectElementWithMatcher:grey_accessibilityID(
[[EarlGrey selectElementWithMatcher:grey_accessibilityID( kPasswordDetailsTableViewId)]
kPasswordDetailsTableViewId)] performAction:grey_tap()];
performAction:grey_tap()];
} else {
[[EarlGrey
selectElementWithMatcher:grey_allOf(
ButtonWithAccessibilityLabel(
l10n_util::GetNSString(
IDS_IOS_CANCEL_PASSWORD_DELETION)),
grey_interactable(), nullptr)]
performAction:grey_tap()];
}
// Check that the current view is still the detail view. // Check that the current view is still the detail view.
[[EarlGrey selectElementWithMatcher:grey_accessibilityID( [[EarlGrey selectElementWithMatcher:grey_accessibilityID(
...@@ -717,6 +708,8 @@ void CopyPasswordDetailWithID(int detail_id) { ...@@ -717,6 +708,8 @@ void CopyPasswordDetailWithID(int detail_id) {
// Go back to the list view and verify that the password is still in the // Go back to the list view and verify that the password is still in the
// list. // list.
[[EarlGrey selectElementWithMatcher:NavigationBarCancelButton()]
performAction:grey_tap()];
[[EarlGrey selectElementWithMatcher:SettingsMenuBackButton()] [[EarlGrey selectElementWithMatcher:SettingsMenuBackButton()]
performAction:grey_tap()]; performAction:grey_tap()];
[GetInteractionForPasswordEntry(@"example.com, concrete username") [GetInteractionForPasswordEntry(@"example.com, concrete username")
...@@ -836,6 +829,8 @@ void CopyPasswordDetailWithID(int detail_id) { ...@@ -836,6 +829,8 @@ void CopyPasswordDetailWithID(int detail_id) {
[[EarlGrey selectElementWithMatcher:DeleteButton()] [[EarlGrey selectElementWithMatcher:DeleteButton()]
assertWithMatcher:grey_notNil()]; assertWithMatcher:grey_notNil()];
[[EarlGrey selectElementWithMatcher:NavigationBarCancelButton()]
performAction:grey_tap()];
[[EarlGrey selectElementWithMatcher:SettingsMenuBackButton()] [[EarlGrey selectElementWithMatcher:SettingsMenuBackButton()]
performAction:grey_tap()]; performAction:grey_tap()];
[[EarlGrey selectElementWithMatcher:SettingsMenuBackButton()] [[EarlGrey selectElementWithMatcher:SettingsMenuBackButton()]
...@@ -1455,6 +1450,8 @@ void CopyPasswordDetailWithID(int detail_id) { ...@@ -1455,6 +1450,8 @@ void CopyPasswordDetailWithID(int detail_id) {
[[EarlGrey selectElementWithMatcher:PasswordDetailPassword()] [[EarlGrey selectElementWithMatcher:PasswordDetailPassword()]
assertWithMatcher:grey_textFieldValue(@"new password")]; assertWithMatcher:grey_textFieldValue(@"new password")];
[[EarlGrey selectElementWithMatcher:NavigationBarCancelButton()]
performAction:grey_tap()];
[[EarlGrey selectElementWithMatcher:SettingsMenuBackButton()] [[EarlGrey selectElementWithMatcher:SettingsMenuBackButton()]
performAction:grey_tap()]; performAction:grey_tap()];
[[EarlGrey selectElementWithMatcher:SettingsMenuBackButton()] [[EarlGrey selectElementWithMatcher:SettingsMenuBackButton()]
...@@ -1570,9 +1567,49 @@ void CopyPasswordDetailWithID(int detail_id) { ...@@ -1570,9 +1567,49 @@ void CopyPasswordDetailWithID(int detail_id) {
assertWithMatcher:grey_allOf(grey_sufficientlyVisible(), assertWithMatcher:grey_allOf(grey_sufficientlyVisible(),
grey_not(grey_enabled()), nil)]; grey_not(grey_enabled()), nil)];
[[EarlGrey selectElementWithMatcher:NavigationBarCancelButton()]
performAction:grey_tap()];
[[EarlGrey selectElementWithMatcher:SettingsMenuBackButton()]
performAction:grey_tap()];
[[EarlGrey selectElementWithMatcher:SettingsMenuBackButton()] [[EarlGrey selectElementWithMatcher:SettingsMenuBackButton()]
performAction:grey_tap()]; performAction:grey_tap()];
[[EarlGrey selectElementWithMatcher:SettingsDoneButton()]
performAction:grey_tap()];
}
// Checks that attempts to edit a username provide appropriate feedback.
- (void)testCancelDuringEditing {
SaveExamplePasswordForm();
OpenPasswordSettings();
[GetInteractionForPasswordEntry(@"example.com, concrete username")
performAction:grey_tap()];
// Check the snackbar in case of successful reauthentication.
[PasswordSettingsAppInterface setUpMockReauthenticationModule];
[PasswordSettingsAppInterface mockReauthenticationModuleExpectedResult:
ReauthenticationResult::kSuccess];
TapEdit();
[[EarlGrey selectElementWithMatcher:PasswordDetailPassword()]
performAction:grey_replaceText(@"new password")];
[[EarlGrey selectElementWithMatcher:NavigationBarCancelButton()]
performAction:grey_tap()];
// Test that password value is unchanged.
[GetInteractionForPasswordDetailItem(ShowPasswordButton())
performAction:grey_tap()];
[[EarlGrey selectElementWithMatcher:PasswordDetailPassword()]
assertWithMatcher:grey_textFieldValue(@"concrete password")];
[[EarlGrey selectElementWithMatcher:SettingsMenuBackButton()]
performAction:grey_tap()];
[[EarlGrey selectElementWithMatcher:SettingsMenuBackButton()] [[EarlGrey selectElementWithMatcher:SettingsMenuBackButton()]
performAction:grey_tap()]; performAction:grey_tap()];
[[EarlGrey selectElementWithMatcher:SettingsDoneButton()] [[EarlGrey selectElementWithMatcher:SettingsDoneButton()]
......
...@@ -61,6 +61,10 @@ ...@@ -61,6 +61,10 @@
// editing mode of this controller. // editing mode of this controller.
- (void)editButtonPressed; - (void)editButtonPressed;
// Returns NO. Subclasses should overload this if the cancel button should be
// shown during editing.
- (BOOL)showCancelDuringEditing;
// Called when this ViewController toolbar's delete item has been tapped. // Called when this ViewController toolbar's delete item has been tapped.
// |indexPaths| is the index paths of the currently selected item to be deleted. // |indexPaths| is the index paths of the currently selected item to be deleted.
// Default implementation removes the items. // Default implementation removes the items.
......
...@@ -51,6 +51,10 @@ const CGFloat kActivityIndicatorDimensionIPhone = 56; ...@@ -51,6 +51,10 @@ const CGFloat kActivityIndicatorDimensionIPhone = 56;
// store the item while the interaction is prevented. // store the item while the interaction is prevented.
@property(nonatomic, strong) UIBarButtonItem* savedBarButtonItem; @property(nonatomic, strong) UIBarButtonItem* savedBarButtonItem;
// Back button on navigation panel. This is used to store back button while it
// is replaced with Cancel during editing.
@property(nonatomic, strong) UIBarButtonItem* backButtonItem;
// Veil preventing interactions with the TableView. // Veil preventing interactions with the TableView.
@property(nonatomic, strong) UIView* veil; @property(nonatomic, strong) UIView* veil;
...@@ -79,6 +83,13 @@ const CGFloat kActivityIndicatorDimensionIPhone = 56; ...@@ -79,6 +83,13 @@ const CGFloat kActivityIndicatorDimensionIPhone = 56;
} else { } else {
self.navigationItem.rightBarButtonItem = [self doneButtonIfNeeded]; self.navigationItem.rightBarButtonItem = [self doneButtonIfNeeded];
} }
// Update Cancel/Back button.
if (self.showCancelDuringEditing) {
self.navigationItem.leftBarButtonItem =
self.tableView.editing ? [self createEditModeCancelButton]
: self.backButtonItem;
}
} }
- (void)reloadData { - (void)reloadData {
...@@ -127,6 +138,8 @@ const CGFloat kActivityIndicatorDimensionIPhone = 56; ...@@ -127,6 +138,8 @@ const CGFloat kActivityIndicatorDimensionIPhone = 56;
self.navigationItem.largeTitleDisplayMode = self.navigationItem.largeTitleDisplayMode =
UINavigationItemLargeTitleDisplayModeNever; UINavigationItemLargeTitleDisplayModeNever;
self.backButtonItem = self.navigationItem.leftBarButtonItem;
} }
- (void)viewWillAppear:(BOOL)animated { - (void)viewWillAppear:(BOOL)animated {
...@@ -253,6 +266,21 @@ const CGFloat kActivityIndicatorDimensionIPhone = 56; ...@@ -253,6 +266,21 @@ const CGFloat kActivityIndicatorDimensionIPhone = 56;
action:@selector(editButtonPressed)]; action:@selector(editButtonPressed)];
} }
- (UIBarButtonItem*)createEditModeCancelButton {
// Create a custom Cancel bar button item.
return [[UIBarButtonItem alloc]
initWithBarButtonSystemItem:UIBarButtonSystemItemCancel
target:self
action:@selector(cancelEditing)];
}
// Quits editing mode and reloads data to the state before editing.
- (void)cancelEditing {
[self setEditing:!self.tableView.editing animated:YES];
[self updateUIForEditState];
[self reloadData];
}
#pragma mark - Subclassing #pragma mark - Subclassing
- (BOOL)shouldHideToolbar { - (BOOL)shouldHideToolbar {
...@@ -267,6 +295,10 @@ const CGFloat kActivityIndicatorDimensionIPhone = 56; ...@@ -267,6 +295,10 @@ const CGFloat kActivityIndicatorDimensionIPhone = 56;
return NO; return NO;
} }
- (BOOL)showCancelDuringEditing {
return NO;
}
- (void)editButtonPressed { - (void)editButtonPressed {
[self setEditing:!self.tableView.editing animated:YES]; [self setEditing:!self.tableView.editing animated:YES];
[self updateUIForEditState]; [self updateUIForEditState];
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment