Commit 366e10e9 authored by Dominic Battré's avatar Dominic Battré Committed by Commit Bot

Revert "[ios] Added bookmark search"

This reverts commit 1dba3ee8.

Reason for revert: Speculative revert due to Failures on ios_chrome_bookmarks_egtests (iPhone X iOS 12.0)

Original change's description:
> [ios] Added bookmark search
> 
> When opening:
> https://drive.google.com/file/d/1z4iyQgQOL9jUFNfIf9Qg1SmFz9INxN88/view?usp=sharing
> When searching:
> https://drive.google.com/file/d/1wdMrOC9GDzh7e97HY-1ObHergJH0rnoC/view?usp=sharing
> 
> In action:
> https://drive.google.com/file/d/14NMZ4mkCUZM8QNyopWHQ6MyDX939bcni/view?usp=sharing
> 
> Bug: 879570
> Cq-Include-Trybots: luci.chromium.try:ios-simulator-cronet;luci.chromium.try:ios-simulator-full-configs
> Change-Id: I51f88361a79703c55f03e2befb745ca3701ce577
> Reviewed-on: https://chromium-review.googlesource.com/1193932
> Commit-Queue: David Jean <djean@chromium.org>
> Reviewed-by: Sergio Collazos <sczs@chromium.org>
> Reviewed-by: Gauthier Ambard <gambard@chromium.org>
> Cr-Commit-Position: refs/heads/master@{#589861}

TBR=sczs@chromium.org,gambard@chromium.org,djean@chromium.org

Change-Id: Ia9b723b9a69cb7aa4cf00f339f380a15a7e64109
No-Presubmit: true
No-Tree-Checks: true
No-Try: true
Bug: 879570
Cq-Include-Trybots: luci.chromium.try:ios-simulator-cronet;luci.chromium.try:ios-simulator-full-configs
Reviewed-on: https://chromium-review.googlesource.com/1215866Reviewed-by: default avatarDominic Battré <battre@chromium.org>
Commit-Queue: Dominic Battré <battre@chromium.org>
Cr-Commit-Position: refs/heads/master@{#589890}
parent 628c1e15
......@@ -36,12 +36,6 @@ class ChromeBrowserState;
// existing data first.
- (void)computeBookmarkTableViewData;
// Rebuilds the table view model data for the bookmarks matching the given text.
// Deletes any existing data first. If no items found, an entry with
// |noResults' message is added to the table.
- (void)computeBookmarkTableViewDataMatching:(NSString*)searchText
orShowMessageWhenNoResults:(NSString*)noResults;
@end
#endif // IOS_CHROME_BROWSER_UI_BOOKMARKS_BOOKMARK_HOME_MEDIATOR_H_
......@@ -6,10 +6,7 @@
#include "base/logging.h"
#include "base/mac/foundation_util.h"
#include "base/strings/sys_string_conversions.h"
#include "components/bookmarks/browser/bookmark_model.h"
#include "components/bookmarks/browser/bookmark_utils.h"
#include "components/bookmarks/browser/titled_url_match.h"
#include "ios/chrome/browser/browser_state/chrome_browser_state.h"
#import "ios/chrome/browser/sync/synced_sessions_bridge.h"
#import "ios/chrome/browser/ui/authentication/signin_promo_view_mediator.h"
......@@ -20,7 +17,6 @@
#import "ios/chrome/browser/ui/bookmarks/cells/bookmark_home_node_item.h"
#import "ios/chrome/browser/ui/bookmarks/cells/bookmark_home_promo_item.h"
#import "ios/chrome/browser/ui/signin_interaction/public/signin_presenter.h"
#import "ios/chrome/browser/ui/table_view/cells/table_view_text_item.h"
#import "ios/chrome/browser/ui/table_view/table_view_model.h"
#if !defined(__has_feature) || !__has_feature(objc_arc)
......@@ -29,11 +25,6 @@
using bookmarks::BookmarkNode;
namespace {
// Maximum number of entries to fetch when searching.
const int kMaxBookmarksSearchResults = 50;
} // namespace
@interface BookmarkHomeMediator ()<BookmarkHomePromoItemDelegate,
BookmarkModelBridgeObserver,
BookmarkPromoControllerDelegate,
......@@ -105,12 +96,16 @@ const int kMaxBookmarksSearchResults = 50;
// Computes the bookmarks table view based on the current root node.
- (void)computeBookmarkTableViewData {
[self deleteAllItemsOrAddSectionWithIdentifier:
BookmarkHomeSectionIdentifierBookmarks];
[self deleteAllItemsOrAddSectionWithIdentifier:
BookmarkHomeSectionIdentifierMessages];
// Regenerate the list of all bookmarks.
if ([self.sharedState.tableViewModel
hasSectionForSectionIdentifier:
BookmarkHomeSectionIdentifierBookmarks]) {
[self.sharedState.tableViewModel
removeSectionWithIdentifier:BookmarkHomeSectionIdentifierBookmarks];
}
[self.sharedState.tableViewModel
addSectionWithIdentifier:BookmarkHomeSectionIdentifierBookmarks];
if (!self.sharedState.bookmarkModel->loaded() ||
!self.sharedState.tableViewDisplayedRootNode) {
[self updateTableViewBackground];
......@@ -183,47 +178,6 @@ const int kMaxBookmarksSearchResults = 50;
}
}
- (void)computeBookmarkTableViewDataMatching:(NSString*)searchText
orShowMessageWhenNoResults:(NSString*)noResults {
[self deleteAllItemsOrAddSectionWithIdentifier:
BookmarkHomeSectionIdentifierBookmarks];
[self deleteAllItemsOrAddSectionWithIdentifier:
BookmarkHomeSectionIdentifierMessages];
std::vector<const BookmarkNode*> nodes;
bookmarks::QueryFields query;
query.word_phrase_query.reset(new base::string16);
*query.word_phrase_query = base::SysNSStringToUTF16(searchText);
GetBookmarksMatchingProperties(self.sharedState.bookmarkModel, query,
kMaxBookmarksSearchResults, &nodes);
int count = 0;
for (const BookmarkNode* node : nodes) {
if (!node->is_url())
continue;
BookmarkHomeNodeItem* nodeItem =
[[BookmarkHomeNodeItem alloc] initWithType:BookmarkHomeItemTypeBookmark
bookmarkNode:node];
[self.sharedState.tableViewModel
addItem:nodeItem
toSectionWithIdentifier:BookmarkHomeSectionIdentifierBookmarks];
count++;
}
if (count == 0) {
TableViewTextItem* item =
[[TableViewTextItem alloc] initWithType:BookmarkHomeItemTypeMessage];
item.textAlignment = NSTextAlignmentLeft;
item.textColor = [UIColor darkGrayColor];
item.text = noResults;
[self.sharedState.tableViewModel
addItem:item
toSectionWithIdentifier:BookmarkHomeSectionIdentifierMessages];
return;
}
}
- (void)updateTableViewBackground {
// If the current root node is the outermost root, check if we need to show
// the spinner backgound. Otherwise, check if we need to show the empty
......@@ -317,10 +271,6 @@ const int kMaxBookmarksSearchResults = 50;
// The node has not changed, but its children have.
- (void)bookmarkNodeChildrenChanged:(const BookmarkNode*)bookmarkNode {
// In search mode, we want to refresh any changes (like undo).
if (self.sharedState.currentlyShowingSearchResults) {
[self.consumer refreshContents];
}
// The current root folder's children changed. Reload everything.
// (When adding new folder, table is already been updated. So no need to
// reload here.)
......@@ -345,9 +295,7 @@ const int kMaxBookmarksSearchResults = 50;
// |node| was deleted from |folder|.
- (void)bookmarkNodeDeleted:(const BookmarkNode*)node
fromFolder:(const BookmarkNode*)folder {
if (self.sharedState.currentlyShowingSearchResults) {
[self.consumer refreshContents];
} else if (self.sharedState.tableViewDisplayedRootNode == node) {
if (self.sharedState.tableViewDisplayedRootNode == node) {
self.sharedState.tableViewDisplayedRootNode = NULL;
[self.consumer refreshContents];
}
......@@ -456,17 +404,4 @@ const int kMaxBookmarksSearchResults = 50;
!self.sharedState.tableViewDisplayedRootNode->empty();
}
// Delete all items for the given |sectionIdentifier| section, or create it
// if it doesn't exist, hence ensuring the section exists and is empty.
- (void)deleteAllItemsOrAddSectionWithIdentifier:(NSInteger)sectionIdentifier {
if ([self.sharedState.tableViewModel
hasSectionForSectionIdentifier:sectionIdentifier]) {
[self.sharedState.tableViewModel
deleteAllItemsFromSectionWithIdentifier:sectionIdentifier];
} else {
[self.sharedState.tableViewModel
addSectionWithIdentifier:sectionIdentifier];
}
}
@end
......@@ -24,13 +24,11 @@ class BookmarkNode;
typedef NS_ENUM(NSInteger, BookmarkHomeSectionIdentifier) {
BookmarkHomeSectionIdentifierPromo = kSectionIdentifierEnumZero,
BookmarkHomeSectionIdentifierBookmarks,
BookmarkHomeSectionIdentifierMessages,
};
typedef NS_ENUM(NSInteger, BookmarkHomeItemType) {
BookmarkHomeItemTypePromo = kItemTypeEnumZero,
BookmarkHomeItemTypeBookmark,
BookmarkHomeItemTypeMessage,
};
@protocol BookmarkHomeSharedStateObserver
......@@ -66,9 +64,6 @@ typedef NS_ENUM(NSInteger, BookmarkHomeItemType) {
// If the table view is in edit mode.
@property(nonatomic, assign) BOOL currentlyInEditMode;
// If the table view showing search results.
@property(nonatomic, assign) BOOL currentlyShowingSearchResults;
// The set of nodes currently being edited.
@property(nonatomic, readonly, assign)
std::set<const bookmarks::BookmarkNode*>& editNodes;
......
......@@ -35,7 +35,6 @@ const NSUInteger kMaxDownloadFaviconCount = 50;
@synthesize addingNewFolder = _addingNewFolder;
@synthesize bookmarkModel = _bookmarkModel;
@synthesize currentlyInEditMode = _currentlyInEditMode;
@synthesize currentlyShowingSearchResults = _currentlyShowingSearchResults;
@synthesize editingFolderCell = _editingFolderCell;
@synthesize editingFolderNode = _editingFolderNode;
@synthesize faviconDownloadCount = _faviconDownloadCount;
......
......@@ -102,7 +102,7 @@ const CGFloat kEstimatedRowHeight = 65.0;
// dynamic type) height. If the dynamic font is too large or too small it will
// result in a small offset on the cache, in order to prevent this we need to
// calculate this value dynamically.
const int kRowsHiddenByNavigationBar = 3;
const int kRowsHiddenByNavigationBar = 2;
// NetworkTrafficAnnotationTag for fetching favicon from a Google server.
const net::NetworkTrafficAnnotationTag kTrafficAnnotation =
......@@ -140,16 +140,7 @@ std::vector<GURL> GetUrlsToOpen(const std::vector<const BookmarkNode*>& nodes) {
const CGFloat kShadowOpacity = 0.12f;
// Shadow radius for the NavigationController Toolbar.
const CGFloat kShadowRadius = 12.0f;
// Vertical offset from the top, to center search bar and cancel button in the
// header.
const CGFloat kVerticalOffsetForSearchHeader = 6.0f;
// The Alpha value used by the SearchBar when disabled.
const CGFloat kAlphaForDisabledSearchBar = 0.5f;
// The Alpha (on white) used for the scrim covering current data until data
// is filtered out.
const CGFloat kWhiteAlphaForSearchScrim = 0.2f;
// The duration for scrim to fade in or out.
const NSTimeInterval kScrimFadeDuration = 0.2;
} // namespace
// An AlertCoordinator with the "Action Sheet" style that does not provide an
......@@ -178,8 +169,6 @@ const NSTimeInterval kScrimFadeDuration = 0.2;
BookmarkModelBridgeObserver,
BookmarkTableCellTitleEditDelegate,
UIGestureRecognizerDelegate,
UISearchControllerDelegate,
UISearchResultsUpdating,
UITableViewDataSource,
UITableViewDelegate> {
// Bridge to register for bookmark changes.
......@@ -235,21 +224,12 @@ const NSTimeInterval kScrimFadeDuration = 0.2;
// Dispatcher for sending commands.
@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;
// This ViewController's searchController;
@property(nonatomic, strong) UISearchController* searchController;
// Navigation UIToolbar Delete button.
@property(nonatomic, strong) UIBarButtonItem* deleteButton;
// Navigation UIToolbar More button.
@property(nonatomic, strong) UIBarButtonItem* moreButton;
// Scrim when search box in focused.
@property(nonatomic, strong) UIControl* scrimView;
// Background shown when there is no bookmarks or folders at the current root
// node.
@property(nonatomic, strong) BookmarkEmptyBackground* emptyTableBackgroundView;
......@@ -279,11 +259,8 @@ const NSTimeInterval kScrimFadeDuration = 0.2;
@synthesize isReconstructingFromCache = _isReconstructingFromCache;
@synthesize sharedState = _sharedState;
@synthesize mediator = _mediator;
@synthesize searchController = _searchController;
@synthesize searchTerm = _searchTerm;
@synthesize deleteButton = _deleteButton;
@synthesize moreButton = _moreButton;
@synthesize scrimView = _scrimView;
@synthesize spinnerView = _spinnerView;
@synthesize emptyTableBackgroundView = _emptyTableBackgroundView;
@synthesize actionSheetCoordinator = _actionSheetCoordinator;
......@@ -419,53 +396,6 @@ const NSTimeInterval kScrimFadeDuration = 0.2;
self.navigationController.toolbar.accessibilityIdentifier =
kBookmarkHomeUIToolbarIdentifier;
// SearchController Configuration.
// Init the searchController with nil so the results are displayed on the same
// TableView.
self.searchController =
[[UISearchController alloc] initWithSearchResultsController:nil];
self.searchController.dimsBackgroundDuringPresentation = NO;
self.searchController.searchBar.userInteractionEnabled = NO;
self.searchController.delegate = self;
self.searchController.searchResultsUpdater = self;
self.searchController.searchBar.backgroundColor = [UIColor clearColor];
self.searchController.searchBar.accessibilityIdentifier =
kBookmarkHomeSearchBarIdentifier;
// UIKit needs to know which controller will be presenting the
// searchController. If we don't add this trying to dismiss while
// SearchController is active will fail.
self.definesPresentationContext = YES;
self.scrimView = [[UIControl alloc] initWithFrame:self.tableView.bounds];
self.scrimView.backgroundColor =
[UIColor colorWithWhite:0 alpha:kWhiteAlphaForSearchScrim];
self.scrimView.translatesAutoresizingMaskIntoConstraints = NO;
self.scrimView.autoresizingMask =
UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight;
self.scrimView.accessibilityIdentifier = kBookmarkHomeSearchScrimIdentifier;
[self.scrimView addTarget:self
action:@selector(dismissSearchController:)
forControlEvents:UIControlEventAllTouchEvents];
// For iOS 11 and later, place the search bar in the navigation bar. Otherwise
// place the search bar in the table view's header.
if (@available(iOS 11, *)) {
self.navigationItem.searchController = self.searchController;
self.navigationItem.hidesSearchBarWhenScrolling = NO;
// Center search bar vertically so it looks centered in the header when
// searching. The cancel button is centered / decentered on viewWillAppear
// and viewDidDisappear.
UIOffset offset = UIOffsetMake(0.0f, kVerticalOffsetForSearchHeader);
self.searchController.searchBar.searchFieldBackgroundPositionAdjustment =
offset;
} else {
self.tableView.tableHeaderView = self.searchController.searchBar;
}
self.searchTerm = @"";
if (self.bookmarks->loaded()) {
[self loadBookmarkViews];
} else {
......@@ -486,29 +416,6 @@ const NSTimeInterval kScrimFadeDuration = 0.2;
} else {
self.navigationController.toolbarHidden = YES;
}
if (@available(iOS 11, *)) {
// Center search bar's cancel button vertically so it looks centered.
// We change the cancel button proxy styles, so we will return it to
// default in viewDidDisappear.
UIOffset offset = UIOffsetMake(0.0f, kVerticalOffsetForSearchHeader);
UIBarButtonItem* cancelButton = [UIBarButtonItem
appearanceWhenContainedInInstancesOfClasses:@[ [UISearchBar class] ]];
[cancelButton setTitlePositionAdjustment:offset
forBarMetrics:UIBarMetricsDefault];
}
}
- (void)viewWillDisappear:(BOOL)animated {
[super viewWillDisappear:animated];
if (@available(iOS 11, *)) {
// Restore to default origin offset for cancel button proxy style.
UIBarButtonItem* cancelButton = [UIBarButtonItem
appearanceWhenContainedInInstancesOfClasses:@[ [UISearchBar class] ]];
[cancelButton setTitlePositionAdjustment:UIOffsetZero
forBarMetrics:UIBarMetricsDefault];
}
}
- (void)viewDidLayoutSubviews {
......@@ -562,7 +469,6 @@ const NSTimeInterval kScrimFadeDuration = 0.2;
self.sharedState.tableViewModel = self.tableViewModel;
self.sharedState.tableView = self.tableView;
self.sharedState.observer = self;
self.sharedState.currentlyShowingSearchResults = NO;
// Configure the table view.
self.sharedState.tableView.accessibilityIdentifier = @"bookmarksTableView";
......@@ -601,9 +507,6 @@ const NSTimeInterval kScrimFadeDuration = 0.2;
if (self.isReconstructingFromCache) {
[self setupUIStackCacheIfApplicable];
}
self.searchController.searchBar.userInteractionEnabled = YES;
DCHECK(self.bookmarks->loaded());
DCHECK([self isViewLoaded]);
}
......@@ -620,13 +523,7 @@ const NSTimeInterval kScrimFadeDuration = 0.2;
#pragma mark - BookmarkHomeConsumer
- (void)refreshContents {
if (self.sharedState.currentlyShowingSearchResults) {
NSString* noResults = l10n_util::GetNSString(IDS_HISTORY_NO_SEARCH_RESULTS);
[self.mediator computeBookmarkTableViewDataMatching:self.searchTerm
orShowMessageWhenNoResults:noResults];
} else {
[self.mediator computeBookmarkTableViewData];
}
[self.mediator computeBookmarkTableViewData];
[self cancelAllFaviconLoads];
[self handleRefreshContextBar];
[self.sharedState.editingFolderCell stopEdit];
......@@ -679,10 +576,8 @@ const NSTimeInterval kScrimFadeDuration = 0.2;
BookmarkHomeViewController* strongSelf = weakSelf;
// GetLargeIconOrFallbackStyleFromGoogleServerSkippingLocalCache
// is not cancellable. So need to check if node has been changed
// before proceeding to favicon update. Also when searching,
// indexPath can point beyond the end of the current list if the
// icon was for a previous, longer, filtered view of items.
if (!strongSelf || ![strongSelf hasItemAtIndexPath:indexPath] ||
// before proceeding to favicon update.
if (!strongSelf ||
[strongSelf nodeAtIndexPath:indexPath] != node) {
return;
}
......@@ -701,12 +596,6 @@ const NSTimeInterval kScrimFadeDuration = 0.2;
/*may_page_url_be_private=*/true, kTrafficAnnotation,
base::BindRepeating(faviconLoadedFromServerBlock));
}
// Due to search filtering, we also need to validate the indexPath
// requested versus what is in the table now.
if (![strongSelf hasItemAtIndexPath:indexPath] ||
[strongSelf nodeAtIndexPath:indexPath] != node) {
return;
}
[strongSelf updateCellAtIndexPath:indexPath
withLargeIconResult:result
fallbackText:fallbackText];
......@@ -999,7 +888,7 @@ const NSTimeInterval kScrimFadeDuration = 0.2;
// Early return if the controller has been deallocated.
if (!strongSelf)
return;
[UIView animateWithDuration:kScrimFadeDuration
[UIView animateWithDuration:0.2
animations:^{
strongSelf.spinnerView.alpha = 0.0;
}
......@@ -1201,15 +1090,11 @@ const NSTimeInterval kScrimFadeDuration = 0.2;
return controller;
}
// Sets the editing mode for tableView, update context bar and search state
// accordingly.
// Sets the editing mode for tableView, update context bar state accordingly.
- (void)setTableViewEditing:(BOOL)editing {
self.sharedState.currentlyInEditMode = editing;
[self setContextBarState:editing ? BookmarksContextBarBeginSelection
: BookmarksContextBarDefault];
self.searchController.searchBar.userInteractionEnabled = !editing;
self.searchController.searchBar.alpha =
editing ? kAlphaForDisabledSearchBar : 1.0;
}
// Row selection of the tableView will be cleared after reloadData. This
......@@ -1301,10 +1186,6 @@ const NSTimeInterval kScrimFadeDuration = 0.2;
return nullptr;
}
- (BOOL)hasItemAtIndexPath:(NSIndexPath*)indexPath {
return [self.sharedState.tableViewModel hasItemAtIndexPath:indexPath];
}
- (BOOL)hasBookmarksOrFolders {
return self.sharedState.tableViewDisplayedRootNode &&
!self.sharedState.tableViewDisplayedRootNode->empty();
......@@ -1325,40 +1206,6 @@ const NSTimeInterval kScrimFadeDuration = 0.2;
return nodes;
}
// Dismiss the search controller when there's a touch event on the scrim.
- (void)dismissSearchController:(UIControl*)sender {
if (self.searchController.active) {
self.searchController.active = NO;
}
}
- (void)showScrim {
self.navigationController.toolbarHidden = YES;
self.scrimView.alpha = 0.0f;
CGSize contentSize = self.tableView.contentSize;
self.scrimView.frame =
CGRectMake(0.0f, 0.0f, contentSize.width,
std::max(contentSize.height, self.view.bounds.size.height));
[self.tableView addSubview:self.scrimView];
[UIView animateWithDuration:kScrimFadeDuration
animations:^{
self.scrimView.alpha = 1.0f;
}];
}
- (void)hideScrimAndMaybeRestoreContexBar:(BOOL)restoreContextBar {
[UIView animateWithDuration:kScrimFadeDuration
animations:^{
self.scrimView.alpha = 0.0f;
}
completion:^(BOOL finished) {
[self.scrimView removeFromSuperview];
if (restoreContextBar) {
[self setupContextBar];
}
}];
}
#pragma mark - Loading and Empty States
// Shows loading spinner background view.
......@@ -1901,55 +1748,6 @@ const NSTimeInterval kScrimFadeDuration = 0.2;
[self.actionSheetCoordinator start];
}
#pragma mark UISearchResultsUpdating
- (void)updateSearchResultsForSearchController:
(UISearchController*)searchController {
DCHECK_EQ(self.searchController, searchController);
NSString* text = searchController.searchBar.text;
self.searchTerm = text;
if (text.length == 0) {
if (self.sharedState.currentlyShowingSearchResults) {
self.sharedState.currentlyShowingSearchResults = NO;
// Restore current list.
[self.mediator computeBookmarkTableViewData];
[self.sharedState.tableView reloadData];
[self showScrim];
}
} else {
if (!self.sharedState.currentlyShowingSearchResults) {
self.sharedState.currentlyShowingSearchResults = YES;
[self hideScrimAndMaybeRestoreContexBar:NO];
}
// Replace current list with search result, but doesn't change
// the 'regular' model for this page, which we can restore when search
// is terminated.
NSString* noResults = l10n_util::GetNSString(IDS_HISTORY_NO_SEARCH_RESULTS);
[self.mediator computeBookmarkTableViewDataMatching:text
orShowMessageWhenNoResults:noResults];
[self.sharedState.tableView reloadData];
}
}
#pragma mark UISearchControllerDelegate
- (void)willPresentSearchController:(UISearchController*)searchController {
[self showScrim];
}
- (void)willDismissSearchController:(UISearchController*)searchController {
// Avoid scrim being put back on in updateSearchResultsForSearchController.
self.sharedState.currentlyShowingSearchResults = NO;
// Restore current list.
[self.mediator computeBookmarkTableViewData];
[self.sharedState.tableView reloadData];
}
- (void)didDismissSearchController:(UISearchController*)searchController {
[self hideScrimAndMaybeRestoreContexBar:YES];
}
#pragma mark - BookmarkHomeSharedStateObserver
- (void)sharedStateDidClearEditNodes:(BookmarkHomeSharedState*)sharedState {
......@@ -2008,10 +1806,6 @@ const NSTimeInterval kScrimFadeDuration = 0.2;
- (BOOL)tableView:(UITableView*)tableView
canEditRowAtIndexPath:(NSIndexPath*)indexPath {
// Filtered results are always a Url and never in edit mode.
if (self.sharedState.currentlyShowingSearchResults) {
return YES;
}
TableViewItem* item =
[self.sharedState.tableViewModel itemAtIndexPath:indexPath];
if (item.type != BookmarkHomeItemTypeBookmark) {
......@@ -2058,10 +1852,6 @@ const NSTimeInterval kScrimFadeDuration = 0.2;
- (BOOL)tableView:(UITableView*)tableView
canMoveRowAtIndexPath:(NSIndexPath*)indexPath {
// No reorering with filtered results.
if (self.sharedState.currentlyShowingSearchResults) {
return NO;
}
TableViewItem* item =
[self.sharedState.tableViewModel itemAtIndexPath:indexPath];
if (item.type != BookmarkHomeItemTypeBookmark) {
......@@ -2075,8 +1865,7 @@ const NSTimeInterval kScrimFadeDuration = 0.2;
- (void)tableView:(UITableView*)tableView
moveRowAtIndexPath:(NSIndexPath*)sourceIndexPath
toIndexPath:(NSIndexPath*)destinationIndexPath {
if (sourceIndexPath.row == destinationIndexPath.row ||
self.sharedState.currentlyShowingSearchResults) {
if (sourceIndexPath.row == destinationIndexPath.row) {
return;
}
const BookmarkNode* node = [self nodeAtIndexPath:sourceIndexPath];
......
......@@ -26,8 +26,7 @@ TEST_F(BookmarkHomeViewControllerTest,
dispatcher:nil];
[controller setRootNode:_bookmarkModel->mobile_node()];
// Two sections: Messages and Bookmarks.
EXPECT_EQ(2, [controller numberOfSectionsInTableView:controller.tableView]);
EXPECT_EQ(1, [controller numberOfSectionsInTableView:controller.tableView]);
}
}
......
......@@ -332,7 +332,7 @@ enum class PresentedState {
self.bookmarkEditor.delegate = nil;
self.bookmarkEditor = nil;
[self.bookmarkNavigationController
[_parentController
dismissViewControllerAnimated:animated
completion:^{
self.bookmarkNavigationController = nil;
......@@ -346,7 +346,7 @@ enum class PresentedState {
return;
DCHECK(self.bookmarkNavigationController);
[self.bookmarkNavigationController
[_parentController
dismissViewControllerAnimated:animated
completion:^{
self.folderEditor.delegate = nil;
......
......@@ -42,10 +42,6 @@ extern NSString* const kBookmarkHomeCenterButtonIdentifier;
extern NSString* const kBookmarkHomeTrailingButtonIdentifier;
// Accessibility identifier of the BookmarkHomeVC UIToolbar.
extern NSString* const kBookmarkHomeUIToolbarIdentifier;
// Accessibility identifier of the BookmarkHomeVC search bar.
extern NSString* const kBookmarkHomeSearchBarIdentifier;
// Accessibility identifier of the search scrim.
extern NSString* const kBookmarkHomeSearchScrimIdentifier;
// Cell Layout constants:
// The space between UIViews inside the cell.
......
......@@ -38,10 +38,6 @@ NSString* const kBookmarkHomeTrailingButtonIdentifier =
@"kBookmarkHomeTrailingButtonIdentifier";
NSString* const kBookmarkHomeUIToolbarIdentifier =
@"kBookmarkHomeUIToolbarIdentifier";
NSString* const kBookmarkHomeSearchBarIdentifier =
@"kBookmarkHomeSearchBarIdentifier";
NSString* const kBookmarkHomeSearchScrimIdentifier =
@"kBookmarkHomeSearchScrimIdentifier";
const CGFloat kBookmarkCellViewSpacing = 10.0f;
const CGFloat kBookmarkCellVerticalInset = 11.0f;
......
......@@ -58,7 +58,6 @@ using chrome_test_util::ButtonWithAccessibilityLabelId;
using chrome_test_util::ContextMenuCopyButton;
using chrome_test_util::PrimarySignInButton;
using chrome_test_util::SecondarySignInButton;
using chrome_test_util::CancelButton;
namespace {
......@@ -181,11 +180,6 @@ id<GREYMatcher> TappableBookmarkNodeWithLabel(NSString* label) {
nil);
}
// Matcher for the search button.
id<GREYMatcher> SearchIconButton() {
return grey_accessibilityID(kBookmarkHomeSearchBarIdentifier);
}
} // namespace
// Bookmark integration tests for Chrome.
......@@ -1689,34 +1683,6 @@ id<GREYMatcher> SearchIconButton() {
[BookmarksTestCase waitForUndoToastToGoAway];
}
+ (void)tapOnLongPressContextMenuButton:(int)menuButtonId
onItem:(id<GREYMatcher>)item
openEditor:(NSString*)editorId
modifyTextField:(NSString*)textFieldId
to:(NSString*)newName
dismissWith:(NSString*)dismissButtonId {
// Invoke Edit through item context menu.
[[EarlGrey selectElementWithMatcher:item] performAction:grey_longPress()];
[[EarlGrey
selectElementWithMatcher:ButtonWithAccessibilityLabelId(menuButtonId)]
performAction:grey_tap()];
// Verify that the editor is present.
[[EarlGrey selectElementWithMatcher:grey_accessibilityID(editorId)]
assertWithMatcher:grey_notNil()];
// Edit textfield.
[[EarlGrey selectElementWithMatcher:grey_accessibilityID(textFieldId)]
performAction:grey_replaceText(newName)];
// Dismiss editor.
[[EarlGrey selectElementWithMatcher:grey_accessibilityID(dismissButtonId)]
performAction:grey_tap()];
[[EarlGrey selectElementWithMatcher:grey_accessibilityID(editorId)]
assertWithMatcher:grey_notVisible()];
}
+ (void)tapOnContextMenuButton:(int)menuButtonId
openEditor:(NSString*)editorId
modifyTextField:(NSString*)textFieldId
......@@ -4146,354 +4112,3 @@ id<GREYMatcher> SearchIconButton() {
}
@end
// Bookmark search integration tests for Chrome.
@interface BookmarksTestCaseSearch : ChromeTestCase
@end
@implementation BookmarksTestCaseSearch
- (void)setUp {
[super setUp];
[ChromeEarlGrey waitForBookmarksToFinishLoading];
GREYAssert(chrome_test_util::ClearBookmarks(),
@"Not all bookmarks were removed.");
}
// Tear down called once per test.
- (void)tearDown {
[super tearDown];
GREYAssert(chrome_test_util::ClearBookmarks(),
@"Not all bookmarks were removed.");
// Clear position cache so that Bookmarks starts at the root folder in next
// test.
ios::ChromeBrowserState* browser_state =
chrome_test_util::GetOriginalBrowserState();
[BookmarkPathCache
clearBookmarkTopMostRowCacheWithPrefService:browser_state->GetPrefs()];
}
#pragma mark - BookmarksTestCaseSearch Tests
// Test that the search bar is shown on root.
- (void)testSearchBarShownOnRoot {
[BookmarksTestCase setupStandardBookmarks];
[BookmarksTestCase openBookmarks];
// Verify the search bar is shown.
[[EarlGrey selectElementWithMatcher:SearchIconButton()]
assertWithMatcher:grey_allOf(grey_sufficientlyVisible(),
grey_userInteractionEnabled(), nil)];
}
// Test that the search bar is shown on mobile list.
- (void)testSearchBarShownOnMobileBookmarks {
[BookmarksTestCase setupStandardBookmarks];
[BookmarksTestCase openBookmarks];
[BookmarksTestCase openMobileBookmarks];
// Verify the search bar is shown.
[[EarlGrey selectElementWithMatcher:SearchIconButton()]
assertWithMatcher:grey_allOf(grey_sufficientlyVisible(),
grey_userInteractionEnabled(), nil)];
}
// Test the search.
- (void)testSearchResults {
[BookmarksTestCase setupStandardBookmarks];
[BookmarksTestCase openBookmarks];
[BookmarksTestCase openMobileBookmarks];
// Verify we have our 3 items.
[[EarlGrey
selectElementWithMatcher:TappableBookmarkNodeWithLabel(@"First URL")]
assertWithMatcher:grey_notNil()];
[[EarlGrey
selectElementWithMatcher:TappableBookmarkNodeWithLabel(@"Second URL")]
assertWithMatcher:grey_notNil()];
[[EarlGrey
selectElementWithMatcher:TappableBookmarkNodeWithLabel(@"French URL")]
assertWithMatcher:grey_notNil()];
// Search 'o'.
[[EarlGrey selectElementWithMatcher:SearchIconButton()]
performAction:grey_typeText(@"o")];
// Verify that folders are filtered out.
[[EarlGrey
selectElementWithMatcher:TappableBookmarkNodeWithLabel(@"Folder 1")]
assertWithMatcher:grey_nil()];
// Search 'on'.
[[EarlGrey selectElementWithMatcher:SearchIconButton()]
performAction:grey_typeText(@"n")];
// Verify we are left only with the "First" and "Second" one.
// 'on' matches 'pony.html' and 'Second'
[[EarlGrey
selectElementWithMatcher:TappableBookmarkNodeWithLabel(@"First URL")]
assertWithMatcher:grey_notNil()];
[[EarlGrey
selectElementWithMatcher:TappableBookmarkNodeWithLabel(@"Second URL")]
assertWithMatcher:grey_notNil()];
[[EarlGrey
selectElementWithMatcher:TappableBookmarkNodeWithLabel(@"French URL")]
assertWithMatcher:grey_nil()];
// Search again for 'ony'.
[[EarlGrey selectElementWithMatcher:SearchIconButton()]
performAction:grey_typeText(@"y")];
// Verify we are left only with the "First" one for 'pony.html'.
[[EarlGrey
selectElementWithMatcher:TappableBookmarkNodeWithLabel(@"First URL")]
assertWithMatcher:grey_notNil()];
[[EarlGrey
selectElementWithMatcher:TappableBookmarkNodeWithLabel(@"Second URL")]
assertWithMatcher:grey_nil()];
[[EarlGrey
selectElementWithMatcher:TappableBookmarkNodeWithLabel(@"French URL")]
assertWithMatcher:grey_nil()];
}
// Test that you get 'No Results' when no matching bookmarks are found.
- (void)testSearchWithNoResults {
[BookmarksTestCase setupStandardBookmarks];
[BookmarksTestCase openBookmarks];
[BookmarksTestCase openMobileBookmarks];
// Search 'zz'.
[[EarlGrey selectElementWithMatcher:SearchIconButton()]
performAction:grey_typeText(@"zz")];
// Verify that we have a 'No Results' label somewhere.
[[EarlGrey selectElementWithMatcher:grey_text(l10n_util::GetNSString(
IDS_HISTORY_NO_SEARCH_RESULTS))]
assertWithMatcher:grey_notNil()];
}
// Test that scrim is shown while search box is enabled with no queries.
- (void)testSearchScrimShownWhenSearchBoxEnabled {
[BookmarksTestCase setupStandardBookmarks];
[BookmarksTestCase openBookmarks];
[BookmarksTestCase openMobileBookmarks];
[[EarlGrey selectElementWithMatcher:SearchIconButton()]
performAction:grey_tap()];
// Verify that scrim is visible.
[[EarlGrey selectElementWithMatcher:grey_accessibilityID(
kBookmarkHomeSearchScrimIdentifier)]
assertWithMatcher:grey_notNil()];
// Searching.
[[EarlGrey selectElementWithMatcher:SearchIconButton()]
performAction:grey_typeText(@"i")];
// Verify that scrim is not visible.
[[EarlGrey selectElementWithMatcher:grey_accessibilityID(
kBookmarkHomeSearchScrimIdentifier)]
assertWithMatcher:grey_nil()];
// Go back to original folder content.
[[EarlGrey selectElementWithMatcher:SearchIconButton()]
performAction:grey_clearText()];
// Verify that scrim is visible again.
[[EarlGrey selectElementWithMatcher:grey_accessibilityID(
kBookmarkHomeSearchScrimIdentifier)]
assertWithMatcher:grey_notNil()];
// Cancel.
[[EarlGrey selectElementWithMatcher:CancelButton()] performAction:grey_tap()];
// Verify that scrim is not visible.
[[EarlGrey selectElementWithMatcher:grey_accessibilityID(
kBookmarkHomeSearchScrimIdentifier)]
assertWithMatcher:grey_nil()];
}
// Test that tapping scrim while search box is enabled dismisses the search
// controller.
- (void)testSearchTapOnScrimCancelsSearchController {
[BookmarksTestCase setupStandardBookmarks];
[BookmarksTestCase openBookmarks];
[BookmarksTestCase openMobileBookmarks];
[[EarlGrey selectElementWithMatcher:SearchIconButton()]
performAction:grey_tap()];
// Tap on scrim.
[[EarlGrey selectElementWithMatcher:grey_accessibilityID(
kBookmarkHomeSearchScrimIdentifier)]
performAction:grey_tap()];
// Verify that scrim is not visible.
[[EarlGrey selectElementWithMatcher:grey_accessibilityID(
kBookmarkHomeSearchScrimIdentifier)]
assertWithMatcher:grey_nil()];
// Verifiy we went back to original folder content.
[[EarlGrey
selectElementWithMatcher:TappableBookmarkNodeWithLabel(@"First URL")]
assertWithMatcher:grey_notNil()];
[[EarlGrey
selectElementWithMatcher:TappableBookmarkNodeWithLabel(@"Second URL")]
assertWithMatcher:grey_notNil()];
[[EarlGrey
selectElementWithMatcher:TappableBookmarkNodeWithLabel(@"French URL")]
assertWithMatcher:grey_notNil()];
}
// Test cancelling search restores the node's bookmarks.
- (void)testSearchCancelRestoresNodeBookmarks {
[BookmarksTestCase setupStandardBookmarks];
[BookmarksTestCase openBookmarks];
[BookmarksTestCase openMobileBookmarks];
// Search.
[[EarlGrey selectElementWithMatcher:SearchIconButton()]
performAction:grey_typeText(@"X")];
// Verify we have no items.
[[EarlGrey
selectElementWithMatcher:TappableBookmarkNodeWithLabel(@"First URL")]
assertWithMatcher:grey_nil()];
[[EarlGrey
selectElementWithMatcher:TappableBookmarkNodeWithLabel(@"Second URL")]
assertWithMatcher:grey_nil()];
[[EarlGrey
selectElementWithMatcher:TappableBookmarkNodeWithLabel(@"French URL")]
assertWithMatcher:grey_nil()];
// Cancel.
[[EarlGrey selectElementWithMatcher:CancelButton()] performAction:grey_tap()];
// Verify all items are back.
[[EarlGrey
selectElementWithMatcher:TappableBookmarkNodeWithLabel(@"First URL")]
assertWithMatcher:grey_notNil()];
[[EarlGrey
selectElementWithMatcher:TappableBookmarkNodeWithLabel(@"Second URL")]
assertWithMatcher:grey_notNil()];
[[EarlGrey
selectElementWithMatcher:TappableBookmarkNodeWithLabel(@"French URL")]
assertWithMatcher:grey_notNil()];
}
// Test that the navigation bar isn't shown when search is focused.
- (void)testSearchHidesNavigationBar {
[BookmarksTestCase setupStandardBookmarks];
[BookmarksTestCase openBookmarks];
[BookmarksTestCase openMobileBookmarks];
// Search.
[[EarlGrey selectElementWithMatcher:SearchIconButton()]
performAction:grey_typeText(@"F")];
// Verify we have no navigation bar.
// Verify the context bar is shown.
[[EarlGrey selectElementWithMatcher:grey_accessibilityID(
kBookmarkHomeUIToolbarIdentifier)]
assertWithMatcher:grey_nil()];
}
// Test that you can long press and edit a bookmark and see edits when going
// back to search.
- (void)testSearchLongPressEditOnURL {
[BookmarksTestCase setupStandardBookmarks];
[BookmarksTestCase openBookmarks];
[BookmarksTestCase openMobileBookmarks];
// Search.
[[EarlGrey selectElementWithMatcher:SearchIconButton()]
performAction:grey_typeText(@"First")];
// Invoke Edit through context menu.
[BookmarksTestCase
tapOnLongPressContextMenuButton:IDS_IOS_BOOKMARK_CONTEXT_MENU_EDIT
onItem:TappableBookmarkNodeWithLabel(
@"First URL")
openEditor:kBookmarkEditViewContainerIdentifier
modifyTextField:@"Title Field_textField"
to:@"n6"
dismissWith:
kBookmarkEditNavigationBarDoneButtonIdentifier];
// Should not find it anymore.
[[EarlGrey
selectElementWithMatcher:TappableBookmarkNodeWithLabel(@"First URL")]
assertWithMatcher:grey_nil()];
// Search with new name.
[[EarlGrey selectElementWithMatcher:SearchIconButton()]
performAction:grey_replaceText(@"n6")];
// Should now find it again.
[[EarlGrey selectElementWithMatcher:TappableBookmarkNodeWithLabel(@"n6")]
assertWithMatcher:grey_notNil()];
}
// Test that you can swipe items in search mode.
- (void)testSearchItemsCanBeSwipedToDelete {
// TODO(crbug.com/851227): On UIRefresh 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 (experimental_flags::IsBookmarksUIRebootEnabled() && !IsCompactWidth()) {
EARL_GREY_TEST_SKIPPED(@"Test disabled on UIRefresh iPad on iOS11.");
}
}
[BookmarksTestCase setupStandardBookmarks];
[BookmarksTestCase openBookmarks];
[BookmarksTestCase openMobileBookmarks];
// Search.
[[EarlGrey selectElementWithMatcher:SearchIconButton()]
performAction:grey_typeText(@"F")];
[[EarlGrey
selectElementWithMatcher:TappableBookmarkNodeWithLabel(@"First URL")]
performAction:grey_swipeFastInDirection(kGREYDirectionLeft)];
// Verify we have a delete button.
[[EarlGrey selectElementWithMatcher:BookmarksDeleteSwipeButton()]
assertWithMatcher:grey_notNil()];
}
// Test that you can't search while in edit mode.
- (void)testDisablesSearchOnEditMode {
[BookmarksTestCase setupStandardBookmarks];
[BookmarksTestCase openBookmarks];
[BookmarksTestCase openMobileBookmarks];
// Verify search bar is enabled.
[[EarlGrey selectElementWithMatcher:grey_kindOfClass(
NSClassFromString(@"UISearchBar"))]
assertWithMatcher:grey_userInteractionEnabled()];
// Change to edit mode
[[EarlGrey
selectElementWithMatcher:grey_accessibilityID(
kBookmarkHomeTrailingButtonIdentifier)]
performAction:grey_tap()];
// Verify search bar is disabled.
[[EarlGrey selectElementWithMatcher:grey_kindOfClass(
NSClassFromString(@"UISearchBar"))]
assertWithMatcher:grey_not(grey_userInteractionEnabled())];
// Cancel edito mode.
[BookmarksTestCase closeContextBarEditMode];
// Verify search bar is enabled.
[[EarlGrey selectElementWithMatcher:grey_kindOfClass(
NSClassFromString(@"UISearchBar"))]
assertWithMatcher:grey_userInteractionEnabled()];
}
@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