Commit 2b743374 authored by sczs's avatar sczs Committed by Commit Bot

[ios] Fixes crash in Bookmarks scrolling while NewFolder is being edited

- Checks the IndexPath instead of the Cell on canEditRow, the previous method was causing new cells
not to be on edit Mode when the table did was on edit Mode.
- Moves back the editingCell setup to cellForRowAtIndexPath (like legacy) since it was crashing
 on willDisplayCell.
- Creates a test to check the previous case.

Bug: 854185
Cq-Include-Trybots: luci.chromium.try:ios-simulator-full-configs;master.tryserver.chromium.mac:ios-simulator-cronet
Change-Id: Ic4f7b27a6a48d48d26a68b9297a4b17e535a542f
Reviewed-on: https://chromium-review.googlesource.com/1112675Reviewed-by: default avataredchin <edchin@chromium.org>
Commit-Queue: Sergio Collazos <sczs@chromium.org>
Cr-Commit-Position: refs/heads/master@{#569894}
parent fbe272fb
...@@ -1718,7 +1718,22 @@ const CGFloat kShadowRadius = 12.0f; ...@@ -1718,7 +1718,22 @@ const CGFloat kShadowRadius = 12.0f;
if (item.type == BookmarkHomeItemTypeBookmark) { if (item.type == BookmarkHomeItemTypeBookmark) {
BookmarkHomeNodeItem* nodeItem = BookmarkHomeNodeItem* nodeItem =
base::mac::ObjCCastStrict<BookmarkHomeNodeItem>(item); base::mac::ObjCCastStrict<BookmarkHomeNodeItem>(item);
if (!experimental_flags::IsBookmarksUIRebootEnabled()) { if (experimental_flags::IsBookmarksUIRebootEnabled()) {
if (nodeItem.bookmarkNode->is_folder() &&
nodeItem.bookmarkNode == self.sharedState.editingFolderNode) {
TableViewBookmarkFolderCell* tableCell =
base::mac::ObjCCastStrict<TableViewBookmarkFolderCell>(cell);
// Delay starting edit, so that the cell is fully created. This is
// needed when scrolling away and then back into the editingCell,
// without the delay the cell will resign first responder before its
// created.
dispatch_async(dispatch_get_main_queue(), ^{
self.sharedState.editingFolderCell = tableCell;
[tableCell startEdit];
tableCell.textDelegate = self;
});
}
} else {
BookmarkTableCell* tableCell = BookmarkTableCell* tableCell =
base::mac::ObjCCastStrict<BookmarkTableCell>(cell); base::mac::ObjCCastStrict<BookmarkTableCell>(cell);
if (nodeItem.bookmarkNode == self.sharedState.editingFolderNode) { if (nodeItem.bookmarkNode == self.sharedState.editingFolderNode) {
...@@ -1730,6 +1745,7 @@ const CGFloat kShadowRadius = 12.0f; ...@@ -1730,6 +1745,7 @@ const CGFloat kShadowRadius = 12.0f;
}); });
} }
} }
// Cancel previous load attempts. // Cancel previous load attempts.
[self cancelLoadingFaviconAtIndexPath:indexPath]; [self cancelLoadingFaviconAtIndexPath:indexPath];
// Load the favicon from cache. If not found, try fetching it from a // Load the favicon from cache. If not found, try fetching it from a
...@@ -1751,8 +1767,8 @@ const CGFloat kShadowRadius = 12.0f; ...@@ -1751,8 +1767,8 @@ const CGFloat kShadowRadius = 12.0f;
// If the cell at |indexPath| is being edited (which happens when creating a // If the cell at |indexPath| is being edited (which happens when creating a
// new Folder) return NO. // new Folder) return NO.
if (self.sharedState.editingFolderCell == if ([tableView indexPathForCell:self.sharedState.editingFolderCell] ==
[self.tableView cellForRowAtIndexPath:indexPath]) { indexPath) {
return NO; return NO;
} }
...@@ -1867,25 +1883,4 @@ const CGFloat kShadowRadius = 12.0f; ...@@ -1867,25 +1883,4 @@ const CGFloat kShadowRadius = 12.0f;
} }
} }
- (void)tableView:(UITableView*)tableView
willDisplayCell:(UITableViewCell*)cell
forRowAtIndexPath:(NSIndexPath*)indexPath {
if (experimental_flags::IsBookmarksUIRebootEnabled()) {
TableViewItem* item =
[self.sharedState.tableViewModel itemAtIndexPath:indexPath];
if (item.type == BookmarkHomeItemTypeBookmark) {
BookmarkHomeNodeItem* nodeItem =
base::mac::ObjCCastStrict<BookmarkHomeNodeItem>(item);
if (nodeItem.bookmarkNode->is_folder() &&
nodeItem.bookmarkNode == self.sharedState.editingFolderNode) {
TableViewBookmarkFolderCell* tableCell =
base::mac::ObjCCastStrict<TableViewBookmarkFolderCell>(cell);
self.sharedState.editingFolderCell = tableCell;
[tableCell startEdit];
tableCell.textDelegate = self;
}
}
}
}
@end @end
...@@ -3309,6 +3309,37 @@ id<GREYMatcher> TappableBookmarkNodeWithLabel(NSString* label) { ...@@ -3309,6 +3309,37 @@ id<GREYMatcher> TappableBookmarkNodeWithLabel(NSString* label) {
assertWithMatcher:grey_nil()]; assertWithMatcher:grey_nil()];
} }
- (void)testNavigateAwayFromFolderBeingEdited {
[BookmarksTestCase setupBookmarksWhichExceedsScreenHeight];
[BookmarksTestCase openBookmarks];
[BookmarksTestCase openMobileBookmarks];
// Verify bottom URL is not visible before scrolling to bottom (make sure
// setupBookmarksWhichExceedsScreenHeight works as expected).
[[EarlGrey selectElementWithMatcher:grey_accessibilityID(@"Bottom URL")]
assertWithMatcher:grey_notVisible()];
// Verify the top URL is visible (isn't covered by the navigation bar).
[[EarlGrey selectElementWithMatcher:grey_accessibilityID(@"Top URL")]
assertWithMatcher:grey_sufficientlyVisible()];
// Test new folder could be created. This verifies bookmarks scrolled to
// bottom successfully for folder name editng.
NSString* newFolderTitle = @"New Folder";
[BookmarksTestCase createNewBookmarkFolderWithFolderTitle:newFolderTitle
pressReturn:NO];
// Scroll to top to navigate away from the folder being created.
[BookmarksTestCase scrollToTop];
// Scroll back to the Folder being created.
[BookmarksTestCase scrollToBottom];
// Folder should still be in Edit mode, because of this match for Value.
[[EarlGrey selectElementWithMatcher:grey_accessibilityValue(@"New Folder")]
assertWithMatcher:grey_notNil()];
}
- (void)testDeleteSingleFolderNode { - (void)testDeleteSingleFolderNode {
[BookmarksTestCase setupStandardBookmarks]; [BookmarksTestCase setupStandardBookmarks];
[BookmarksTestCase openBookmarks]; [BookmarksTestCase openBookmarks];
......
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