Commit 54857f43 authored by Marti Wong's avatar Marti Wong Committed by Commit Bot

Fix the new bookmark folder name issue on iPad when keyboard dismiss.

Fix the issue that when editing the new folder name on iPad and tap on
the 'hide keyboard' button, the folder name is supposed to commit but
doesn't.  An egtest is added to prevent this bug from happening again.

Bug: 794155
Change-Id: Ie0ef4c1af7f87c55051876bd08331c5d0a0e40a8
Reviewed-on: https://chromium-review.googlesource.com/826585Reviewed-by: default avatarSylvain Defresne <sdefresne@chromium.org>
Commit-Queue: Marti Wong <martiw@chromium.org>
Cr-Commit-Position: refs/heads/master@{#524058}
parent 057e45ea
......@@ -2213,6 +2213,39 @@ id<GREYMatcher> TappableBookmarkNodeWithLabel(NSString* label) {
[BookmarksNewGenTestCase verifyFolderCreatedWithTitle:newFolderTitle];
}
// Tests the new folder name is committed when "hide keyboard" button is
// pressed. (iPad specific)
- (void)testNewFolderNameCommittedWhenKeyboardDismissedOnIpad {
// Tablet only (handset keyboard does not have "hide keyboard" button).
if (!IsIPadIdiom()) {
EARL_GREY_TEST_SKIPPED(@"Test not supported on iPhone");
}
base::test::ScopedFeatureList scoped_feature_list;
scoped_feature_list.InitAndEnableFeature(kBookmarkNewGeneration);
[BookmarksNewGenTestCase setupStandardBookmarks];
[BookmarksNewGenTestCase openBookmarks];
[BookmarksNewGenTestCase openMobileBookmarks];
// Create a new folder and type "New Folder 1" without pressing return.
NSString* newFolderTitle = @"New Folder 1";
[BookmarksNewGenTestCase createNewBookmarkFolderWithFolderTitle:newFolderTitle
pressReturn:NO];
// Tap on the "hide keyboard" button.
id<GREYMatcher> hideKeyboard = grey_accessibilityLabel(@"Hide keyboard");
[[EarlGrey selectElementWithMatcher:hideKeyboard] performAction:grey_tap()];
// Tap on "New Folder 1".
[[EarlGrey selectElementWithMatcher:grey_accessibilityID(@"New Folder 1")]
performAction:grey_tap()];
// Verify the empty background appears. (If "New Folder 1" is commited,
// tapping on it will enter it and see a empty background. Instead of
// re-editing it (crbug.com/794155)).
[self verifyEmptyBackgroundAppears];
}
- (void)testEmptyBackgroundAndSelectButton {
base::test::ScopedFeatureList scoped_feature_list;
scoped_feature_list.InitAndEnableFeature(kBookmarkNewGeneration);
......
......@@ -39,6 +39,9 @@ const CGFloat kBookmarkTableCellImagePadding = 16.0;
// Lists the accessibility elements that are to be seen by UIAccessibility.
@property(nonatomic, readonly) NSMutableArray* accessibilityElements;
// True when title text has ended editing and committed.
@property(nonatomic, assign) BOOL isTextCommitted;
@end
@implementation BookmarkTableCell
......@@ -48,6 +51,7 @@ const CGFloat kBookmarkTableCellImagePadding = 16.0;
@synthesize textDelegate = _textDelegate;
@synthesize separatorView = _separatorView;
@synthesize accessibilityElements = _accessibilityElements;
@synthesize isTextCommitted = _isTextCommitted;
#pragma mark - Initializer
......@@ -147,6 +151,7 @@ const CGFloat kBookmarkTableCellImagePadding = 16.0;
}
- (void)startEdit {
self.isTextCommitted = NO;
self.titleText.userInteractionEnabled = YES;
self.titleText.enablesReturnKeyAutomatically = YES;
self.titleText.keyboardType = UIKeyboardTypeDefault;
......@@ -168,6 +173,10 @@ const CGFloat kBookmarkTableCellImagePadding = 16.0;
}
- (void)stopEdit {
if (self.isTextCommitted) {
return;
}
self.isTextCommitted = YES;
[self.textDelegate textDidChangeTo:self.titleText.text];
self.titleText.userInteractionEnabled = NO;
[self.titleText endEditing:YES];
......@@ -259,10 +268,15 @@ const CGFloat kBookmarkTableCellImagePadding = 16.0;
// This method hides the keyboard when the return key is pressed.
- (BOOL)textFieldShouldReturn:(UITextField*)textField {
[self.textDelegate textDidChangeTo:self.titleText.text];
self.titleText.userInteractionEnabled = NO;
[textField endEditing:YES];
[self stopEdit];
return YES;
}
// This method is called when titleText resigns its first responder status.
// (when return/dimiss key is pressed, or when navigating away.)
- (void)textFieldDidEndEditing:(UITextField*)textField
reason:(UITextFieldDidEndEditingReason)reason {
[self stopEdit];
}
@end
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