Commit 9bc8b198 authored by David Jean's avatar David Jean Committed by Commit Bot

[ios] Allow searching for bookmark folders

- Stop filtering folders out of search results in mediator.
- When user selects a Folder in search results, recompute and reset the stack
  of view controllers, so that the user is in proper place in the bookmark panel stacks for
  back button functionality.

Video: https://drive.google.com/file/d/18-dhC7ZE4j5tounA9I6LiLNGBtTVyTJM/view?usp=sharing

Bug: 886612
Cq-Include-Trybots: luci.chromium.try:ios-simulator-cronet;luci.chromium.try:ios-simulator-full-configs
Change-Id: I7ac42afcaba937b278548f3a37b8d07b87dc4a67
Reviewed-on: https://chromium-review.googlesource.com/c/1254142
Commit-Queue: David Jean <djean@chromium.org>
Reviewed-by: default avatarSergio Collazos <sczs@chromium.org>
Reviewed-by: default avatarGauthier Ambard <gambard@chromium.org>
Cr-Commit-Position: refs/heads/master@{#596141}
parent 9d3c153f
......@@ -199,9 +199,6 @@ const int kMaxBookmarksSearchResults = 50;
int count = 0;
for (const BookmarkNode* node : nodes) {
if (!node->is_url())
continue;
BookmarkHomeNodeItem* nodeItem =
[[BookmarkHomeNodeItem alloc] initWithType:BookmarkHomeItemTypeBookmark
bookmarkNode:node];
......
......@@ -200,7 +200,7 @@ std::vector<GURL> GetUrlsToOpen(const std::vector<const BookmarkNode*>& nodes) {
@property(nonatomic, readonly, weak) id<ApplicationCommands> dispatcher;
// The current search term. Set to the empty string when no search is active.
@property(nonatomic, assign) NSString* searchTerm;
@property(nonatomic, copy) NSString* searchTerm;
// This ViewController's searchController;
@property(nonatomic, strong) UISearchController* searchController;
......@@ -772,6 +772,53 @@ std::vector<GURL> GetUrlsToOpen(const std::vector<const BookmarkNode*>& nodes) {
}
- (void)handleSelectFolderForNavigation:(const bookmarks::BookmarkNode*)folder {
if (self.sharedState.currentlyShowingSearchResults) {
// Clear bookmark path cache.
int64_t unusedFolderId;
int unusedIndexPathRow;
while ([BookmarkPathCache
getBookmarkTopMostRowCacheWithPrefService:self.browserState->GetPrefs()
model:self.bookmarks
folderId:&unusedFolderId
topMostRow:&unusedIndexPathRow]) {
[BookmarkPathCache
clearBookmarkTopMostRowCacheWithPrefService:self.browserState
->GetPrefs()];
}
// Rebuild folder controller list, going back up the tree.
NSMutableArray<BookmarkHomeViewController*>* stack = [NSMutableArray array];
std::vector<const bookmarks::BookmarkNode*> nodes;
const bookmarks::BookmarkNode* cursor = folder;
while (cursor) {
// Build reversed list of nodes to restore bookmark path below.
nodes.insert(nodes.begin(), cursor);
// Build reversed list of controllers.
BookmarkHomeViewController* controller =
[self createControllerWithRootFolder:cursor];
[stack insertObject:controller atIndex:0];
// Setup now, so that the back button labels shows parent folder
// title and that we don't show large title everywhere.
[self setupNavigationForBookmarkHomeViewController:controller
usingBookmarkNode:cursor];
cursor = cursor->parent();
}
// Reconstruct bookmark path cache.
for (const bookmarks::BookmarkNode* node : nodes) {
[BookmarkPathCache
cacheBookmarkTopMostRowWithPrefService:self.browserState->GetPrefs()
folderId:node->id()
topMostRow:0];
}
[self navigateAway];
[self.navigationController setViewControllers:stack animated:YES];
return;
}
BookmarkHomeViewController* controller =
[self createControllerWithRootFolder:folder];
[self.navigationController pushViewController:controller animated:YES];
......
......@@ -1729,7 +1729,7 @@ id<GREYMatcher> SearchIconButton() {
#pragma mark - BookmarksTestCaseEntries Tests
- (void)testUndoDeleteBookmarkFromSwipe {
// TODO(crbug.com/851227): On UIRefresh non Compact Width on iOS11, the
// TODO(crbug.com/851227): On Compact Width on iOS11, the
// bookmark cell is being deleted by grey_swipeFastInDirection.
// grey_swipeFastInDirectionWithStartPoint doesn't work either and it might
// fail on devices. Disabling this test under these conditions on the
......@@ -1781,7 +1781,7 @@ id<GREYMatcher> SearchIconButton() {
FLAKY_testSwipeToDeleteDisabledInEditMode
#endif
- (void)testSwipeToDeleteDisabledInEditMode {
// TODO(crbug.com/851227): On UIRefresh non Compact Width on iOS11, the
// TODO(crbug.com/851227): On non Compact Width on iOS11, the
// bookmark cell is being deleted by grey_swipeFastInDirection.
// grey_swipeFastInDirectionWithStartPoint doesn't work either and it might
// fail on devices. Disabling this test under these conditions on the
......@@ -4115,10 +4115,10 @@ id<GREYMatcher> SearchIconButton() {
[[EarlGrey selectElementWithMatcher:SearchIconButton()]
performAction:grey_typeText(@"o")];
// Verify that folders are filtered out.
// Verify that folders are not filtered out.
[[EarlGrey
selectElementWithMatcher:TappableBookmarkNodeWithLabel(@"Folder 1")]
assertWithMatcher:grey_nil()];
assertWithMatcher:grey_notNil()];
// Search 'on'.
[[EarlGrey selectElementWithMatcher:SearchIconButton()]
......@@ -4135,6 +4135,10 @@ id<GREYMatcher> SearchIconButton() {
[[EarlGrey
selectElementWithMatcher:TappableBookmarkNodeWithLabel(@"French URL")]
assertWithMatcher:grey_nil()];
// Verify that folders are not filtered out.
[[EarlGrey
selectElementWithMatcher:TappableBookmarkNodeWithLabel(@"Folder 1")]
assertWithMatcher:grey_nil()];
// Search again for 'ony'.
[[EarlGrey selectElementWithMatcher:SearchIconButton()]
......@@ -4338,9 +4342,57 @@ id<GREYMatcher> SearchIconButton() {
assertWithMatcher:grey_notNil()];
}
// Tests that you can swipe items in search mode.
- (void)testSearchItemsCanBeSwipedToDelete {
// TODO(crbug.com/851227): On UIRefresh non Compact Width on iOS11, the
// Tests that you can long press and edit a bookmark folder and see edits
// when going back to search.
- (void)testSearchLongPressEditOnFolder {
[BookmarksTestCase setupStandardBookmarks];
[BookmarksTestCase openBookmarks];
[BookmarksTestCase openMobileBookmarks];
NSString* existingFolderTitle = @"Folder 1.1";
// Search.
[[EarlGrey selectElementWithMatcher:SearchIconButton()]
performAction:grey_typeText(existingFolderTitle)];
// Invoke Edit through long press.
[[EarlGrey selectElementWithMatcher:TappableBookmarkNodeWithLabel(
existingFolderTitle)]
performAction:grey_longPress()];
[[EarlGrey
selectElementWithMatcher:ButtonWithAccessibilityLabelId(
IDS_IOS_BOOKMARK_CONTEXT_MENU_EDIT_FOLDER)]
performAction:grey_tap()];
// Verify that the editor is present.
[[EarlGrey
selectElementWithMatcher:grey_accessibilityID(
kBookmarkFolderEditViewContainerIdentifier)]
assertWithMatcher:grey_notNil()];
NSString* newFolderTitle = @"n7";
[BookmarksTestCase renameBookmarkFolderWithFolderTitle:newFolderTitle];
[[EarlGrey selectElementWithMatcher:BookmarksSaveEditFolderButton()]
performAction:grey_tap()];
// Verify that the change has been made.
[[EarlGrey selectElementWithMatcher:TappableBookmarkNodeWithLabel(
existingFolderTitle)]
assertWithMatcher:grey_nil()];
[[EarlGrey selectElementWithMatcher:SearchIconButton()]
performAction:grey_replaceText(newFolderTitle)];
[[EarlGrey
selectElementWithMatcher:TappableBookmarkNodeWithLabel(newFolderTitle)]
assertWithMatcher:grey_notNil()];
}
// Tests that you can swipe URL items in search mode.
- (void)testSearchUrlCanBeSwipedToDelete {
// TODO(crbug.com/851227): On non Compact Width on iOS11, the
// bookmark cell is being deleted by grey_swipeFastInDirection.
// grey_swipeFastInDirectionWithStartPoint doesn't work either and it might
// fail on devices. Disabling this test under these conditions on the
......@@ -4357,7 +4409,7 @@ id<GREYMatcher> SearchIconButton() {
// Search.
[[EarlGrey selectElementWithMatcher:SearchIconButton()]
performAction:grey_typeText(@"F")];
performAction:grey_typeText(@"First URL")];
[[EarlGrey
selectElementWithMatcher:TappableBookmarkNodeWithLabel(@"First URL")]
......@@ -4368,6 +4420,36 @@ id<GREYMatcher> SearchIconButton() {
assertWithMatcher:grey_notNil()];
}
// Tests that you can swipe folders in search mode.
- (void)testSearchFolderCanBeSwipedToDelete {
// TODO(crbug.com/851227): On non Compact Width on iOS11, the
// bookmark cell is being deleted by grey_swipeFastInDirection.
// grey_swipeFastInDirectionWithStartPoint doesn't work either and it might
// fail on devices. Disabling this test under these conditions on the
// meantime.
if (@available(iOS 11, *)) {
if (!IsCompactWidth()) {
EARL_GREY_TEST_SKIPPED(@"Test disabled on iPad on iOS11.");
}
}
[BookmarksTestCase setupStandardBookmarks];
[BookmarksTestCase openBookmarks];
[BookmarksTestCase openMobileBookmarks];
// Search.
[[EarlGrey selectElementWithMatcher:SearchIconButton()]
performAction:grey_typeText(@"Folder 1")];
[[EarlGrey
selectElementWithMatcher:TappableBookmarkNodeWithLabel(@"Folder 1")]
performAction:grey_swipeFastInDirection(kGREYDirectionLeft)];
// Verify we have a delete button.
[[EarlGrey selectElementWithMatcher:BookmarksDeleteSwipeButton()]
assertWithMatcher:grey_notNil()];
}
// Tests that you can't search while in edit mode.
- (void)testDisablesSearchOnEditMode {
[BookmarksTestCase setupStandardBookmarks];
......@@ -4633,4 +4715,44 @@ id<GREYMatcher> SearchIconButton() {
assertWithMatcher:grey_nil()];
}
// Tests that you can search folders.
- (void)testSearchFolders {
[BookmarksTestCase setupStandardBookmarks];
[BookmarksTestCase openBookmarks];
[BookmarksTestCase openMobileBookmarks];
// Go down Folder 1 / Folder 2 / Folder 3.
[[EarlGrey
selectElementWithMatcher:TappableBookmarkNodeWithLabel(@"Folder 1")]
performAction:grey_tap()];
[[EarlGrey
selectElementWithMatcher:TappableBookmarkNodeWithLabel(@"Folder 2")]
performAction:grey_tap()];
[[EarlGrey
selectElementWithMatcher:TappableBookmarkNodeWithLabel(@"Folder 3")]
performAction:grey_tap()];
// Search and go to folder 1.1.
[[EarlGrey selectElementWithMatcher:SearchIconButton()]
performAction:grey_typeText(@"Folder 1.1")];
[[EarlGrey
selectElementWithMatcher:TappableBookmarkNodeWithLabel(@"Folder 1.1")]
performAction:grey_tap()];
// Go back and verify we are in MobileBooknarks. (i.e. not back to Folder 2)
[[EarlGrey selectElementWithMatcher:NavigateBackButtonTo(@"Mobile Bookmarks")]
performAction:grey_tap()];
// Search and go to Folder 2.
[[EarlGrey selectElementWithMatcher:SearchIconButton()]
performAction:grey_typeText(@"Folder 2")];
[[EarlGrey
selectElementWithMatcher:TappableBookmarkNodeWithLabel(@"Folder 2")]
performAction:grey_tap()];
// Go back and verify we are in Folder 1. (i.e. not back to Mobile Bookmarks)
[[EarlGrey selectElementWithMatcher:NavigateBackButtonTo(@"Folder 1")]
performAction:grey_tap()];
}
@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