blob: 986c8bff0610e6a3c3e4432e24fa50132b76bb2e [file] [log] [blame]
// Copyright 2019 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#import <UIKit/UIKit.h>
#import <XCTest/XCTest.h>
#include "base/ios/ios_util.h"
#include "base/mac/foundation_util.h"
#include "base/strings/sys_string_conversions.h"
#include "components/strings/grit/components_strings.h"
#import "ios/chrome/browser/ui/bookmarks/bookmark_earl_grey.h"
#import "ios/chrome/browser/ui/bookmarks/bookmark_earl_grey_ui.h"
#import "ios/chrome/browser/ui/bookmarks/bookmark_ui_constants.h"
#import "ios/chrome/browser/ui/table_view/feature_flags.h"
#include "ios/chrome/grit/ios_strings.h"
#import "ios/chrome/test/earl_grey/chrome_actions.h"
#import "ios/chrome/test/earl_grey/chrome_earl_grey.h"
#import "ios/chrome/test/earl_grey/chrome_earl_grey_ui.h"
#import "ios/chrome/test/earl_grey/chrome_matchers.h"
#import "ios/chrome/test/earl_grey/web_http_server_chrome_test_case.h"
#import "ios/testing/earl_grey/earl_grey_test.h"
#include "net/test/embedded_test_server/embedded_test_server.h"
#include "ui/base/l10n/l10n_util.h"
#if !defined(__has_feature) || !__has_feature(objc_arc)
#error "This file requires ARC support."
#endif
using chrome_test_util::BookmarksDeleteSwipeButton;
using chrome_test_util::BookmarkHomeDoneButton;
using chrome_test_util::BookmarksNavigationBarBackButton;
using chrome_test_util::BookmarksSaveEditDoneButton;
using chrome_test_util::BookmarksSaveEditFolderButton;
using chrome_test_util::ContextBarCenterButtonWithLabel;
using chrome_test_util::ButtonWithAccessibilityLabelId;
using chrome_test_util::ContextBarLeadingButtonWithLabel;
using chrome_test_util::OmniboxText;
using chrome_test_util::ScrollToTop;
using chrome_test_util::TappableBookmarkNodeWithLabel;
// Bookmark folders integration tests for Chrome.
@interface BookmarksFoldersTestCase : WebHttpServerChromeTestCase
@end
@implementation BookmarksFoldersTestCase
- (void)setUp {
[super setUp];
[ChromeEarlGrey waitForBookmarksToFinishLoading];
[ChromeEarlGrey clearBookmarks];
}
// Tear down called once per test.
- (void)tearDown {
[super tearDown];
[ChromeEarlGrey clearBookmarks];
[BookmarkEarlGrey clearBookmarksPositionCache];
}
#pragma mark - BookmarksTestFolders Tests
// Tests moving bookmarks into a new folder created in the moving process.
- (void)testCreateNewFolderWhileMovingBookmarks {
[BookmarkEarlGrey setupStandardBookmarks];
[BookmarkEarlGreyUI openBookmarks];
[BookmarkEarlGreyUI openMobileBookmarks];
// Change to edit mode
[[EarlGrey
selectElementWithMatcher:grey_accessibilityID(
kBookmarkHomeTrailingButtonIdentifier)]
performAction:grey_tap()];
// Select URLs.
[[EarlGrey
selectElementWithMatcher:TappableBookmarkNodeWithLabel(@"Second URL")]
performAction:grey_tap()];
[[EarlGrey
selectElementWithMatcher:TappableBookmarkNodeWithLabel(@"First URL")]
performAction:grey_tap()];
// Tap context menu.
[[EarlGrey
selectElementWithMatcher:ContextBarCenterButtonWithLabel(
[BookmarkEarlGreyUI contextBarMoreString])]
performAction:grey_tap()];
// Tap on Move.
[[EarlGrey selectElementWithMatcher:ButtonWithAccessibilityLabelId(
IDS_IOS_BOOKMARK_CONTEXT_MENU_MOVE)]
performAction:grey_tap()];
// Choose to move the bookmark into a new folder.
[[EarlGrey
selectElementWithMatcher:grey_accessibilityID(
kBookmarkCreateNewFolderCellIdentifier)]
performAction:grey_tap()];
// Enter custom new folder name.
[BookmarkEarlGreyUI
renameBookmarkFolderWithFolderTitle:@"Title For New Folder"];
// Verify current parent folder (Change Folder) is Bookmarks folder.
[[EarlGrey
selectElementWithMatcher:grey_allOf(
grey_accessibilityID(@"Change Folder"),
grey_accessibilityLabel(@"Mobile Bookmarks"),
nil)]
assertWithMatcher:grey_sufficientlyVisible()];
// Choose new parent folder (Change Folder).
[[EarlGrey selectElementWithMatcher:grey_accessibilityID(@"Change Folder")]
performAction:grey_tap()];
// Verify folder picker UI is displayed.
[[EarlGrey
selectElementWithMatcher:
grey_accessibilityID(kBookmarkFolderPickerViewContainerIdentifier)]
assertWithMatcher:grey_sufficientlyVisible()];
// Verify Folder 2 only has one item.
[BookmarkEarlGrey verifyChildCount:1 inFolderWithName:@"Folder 2"];
// Select Folder 2 as new Change Folder.
[[EarlGrey selectElementWithMatcher:grey_accessibilityID(@"Folder 2")]
performAction:grey_tap()];
// Verify folder picker is dismissed and folder creator is now visible.
[[EarlGrey
selectElementWithMatcher:
grey_accessibilityID(kBookmarkFolderCreateViewContainerIdentifier)]
assertWithMatcher:grey_sufficientlyVisible()];
[[EarlGrey
selectElementWithMatcher:
grey_accessibilityID(kBookmarkFolderPickerViewContainerIdentifier)]
assertWithMatcher:grey_notVisible()];
// Verify picked parent folder (Change Folder) is Folder 2.
[[EarlGrey
selectElementWithMatcher:grey_allOf(
grey_accessibilityID(@"Change Folder"),
grey_accessibilityLabel(@"Folder 2"), nil)]
assertWithMatcher:grey_sufficientlyVisible()];
// Tap Done to close bookmark move flow.
[[EarlGrey selectElementWithMatcher:BookmarksSaveEditFolderButton()]
performAction:grey_tap()];
// Verify all folder flow UI is now closed.
[[EarlGrey
selectElementWithMatcher:
grey_accessibilityID(kBookmarkFolderCreateViewContainerIdentifier)]
assertWithMatcher:grey_notVisible()];
[[EarlGrey
selectElementWithMatcher:
grey_accessibilityID(kBookmarkFolderPickerViewContainerIdentifier)]
assertWithMatcher:grey_notVisible()];
[[EarlGrey
selectElementWithMatcher:grey_accessibilityID(
kBookmarkFolderEditViewContainerIdentifier)]
assertWithMatcher:grey_notVisible()];
// Verify new folder has been created under Folder 2.
[BookmarkEarlGrey verifyChildCount:2 inFolderWithName:@"Folder 2"];
// Verify new folder has two bookmarks.
[BookmarkEarlGrey verifyChildCount:2
inFolderWithName:@"Title For New Folder"];
}
- (void)testCantDeleteFolderBeingEdited {
[BookmarkEarlGrey setupStandardBookmarks];
[BookmarkEarlGreyUI openBookmarks];
[BookmarkEarlGreyUI openMobileBookmarks];
// Create a new folder and type "New Folder 1" without pressing return.
NSString* newFolderTitle = @"New Folder";
[BookmarkEarlGreyUI createNewBookmarkFolderWithFolderTitle:newFolderTitle
pressReturn:NO];
// Swipe action to try to delete the newly created folder while its name its
// being edited.
[[EarlGrey
selectElementWithMatcher:TappableBookmarkNodeWithLabel(@"New Folder")]
performAction:grey_swipeFastInDirection(kGREYDirectionLeft)];
// Verify the delete confirmation button doesn't show up.
[[EarlGrey selectElementWithMatcher:BookmarksDeleteSwipeButton()]
assertWithMatcher:grey_nil()];
}
- (void)testNavigateAwayFromFolderBeingEdited {
[BookmarkEarlGrey setupBookmarksWhichExceedsScreenHeight];
[BookmarkEarlGreyUI openBookmarks];
[BookmarkEarlGreyUI 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";
[BookmarkEarlGreyUI createNewBookmarkFolderWithFolderTitle:newFolderTitle
pressReturn:NO];
// Scroll to top to navigate away from the folder being created.
[[EarlGrey selectElementWithMatcher:grey_accessibilityID(
kBookmarkHomeTableViewIdentifier)]
performAction:ScrollToTop()];
// Scroll back to the Folder being created.
[BookmarkEarlGreyUI 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 {
[BookmarkEarlGrey setupStandardBookmarks];
[BookmarkEarlGreyUI openBookmarks];
[BookmarkEarlGreyUI openMobileBookmarks];
// Change to edit mode
[[EarlGrey
selectElementWithMatcher:grey_accessibilityID(
kBookmarkHomeTrailingButtonIdentifier)]
performAction:grey_tap()];
// Select single URL.
[[EarlGrey
selectElementWithMatcher:TappableBookmarkNodeWithLabel(@"Folder 1")]
performAction:grey_tap()];
// Delete it.
[[EarlGrey
selectElementWithMatcher:ContextBarLeadingButtonWithLabel(
[BookmarkEarlGreyUI contextBarDeleteString])]
performAction:grey_tap()];
// Wait until it's gone.
[BookmarkEarlGreyUI waitForDeletionOfBookmarkWithTitle:@"Folder 1"];
// Press undo
[[EarlGrey selectElementWithMatcher:grey_accessibilityID(@"Undo")]
performAction:grey_tap()];
// Verify it's back.
[[EarlGrey selectElementWithMatcher:grey_accessibilityID(@"Folder 1")]
assertWithMatcher:grey_notNil()];
// Verify edit mode is closed (context bar back to default state).
[BookmarkEarlGreyUI verifyContextBarInDefaultStateWithSelectEnabled:YES
newFolderEnabled:YES];
}
- (void)testSwipeDownToDismissFromEditFolder {
if (!base::ios::IsRunningOnOrLater(13, 0, 0)) {
EARL_GREY_TEST_SKIPPED(@"Test disabled on iOS 12 and lower.");
}
if (!IsCollectionsCardPresentationStyleEnabled()) {
EARL_GREY_TEST_SKIPPED(@"Test disabled on when feature flag is off.");
}
[BookmarkEarlGrey setupStandardBookmarks];
[BookmarkEarlGreyUI openBookmarks];
[BookmarkEarlGreyUI openMobileBookmarks];
// Invoke Move through long press.
[[EarlGrey
selectElementWithMatcher:TappableBookmarkNodeWithLabel(@"Folder 1.1")]
performAction:grey_longPress()];
[[EarlGrey selectElementWithMatcher:ButtonWithAccessibilityLabelId(
IDS_IOS_BOOKMARK_CONTEXT_MENU_MOVE)]
performAction:grey_tap()];
// Check that the TableView is presented.
[[EarlGrey
selectElementWithMatcher:
grey_accessibilityID(kBookmarkFolderPickerViewContainerIdentifier)]
assertWithMatcher:grey_notNil()];
// Swipe TableView down.
[[EarlGrey
selectElementWithMatcher:
grey_accessibilityID(kBookmarkFolderPickerViewContainerIdentifier)]
performAction:grey_swipeFastInDirection(kGREYDirectionDown)];
// Check that the TableView has been dismissed.
[[EarlGrey
selectElementWithMatcher:
grey_accessibilityID(kBookmarkFolderPickerViewContainerIdentifier)]
assertWithMatcher:grey_nil()];
}
// Test when current navigating folder is deleted in background, empty
// background should be shown with context bar buttons disabled.
- (void)testWhenCurrentFolderDeletedInBackground {
[BookmarkEarlGrey setupStandardBookmarks];
[BookmarkEarlGreyUI openBookmarks];
[BookmarkEarlGreyUI openMobileBookmarks];
// Enter Folder 1
[[EarlGrey selectElementWithMatcher:grey_accessibilityID(@"Folder 1")]
performAction:grey_tap()];
// Enter Folder 2
[[EarlGrey selectElementWithMatcher:grey_accessibilityID(@"Folder 2")]
performAction:grey_tap()];
// Change to edit mode, using context menu.
[[EarlGrey
selectElementWithMatcher:grey_accessibilityID(
kBookmarkHomeTrailingButtonIdentifier)]
performAction:grey_tap()];
// Delete the Folder 1 and Folder 2 programmatically in background.
[BookmarkEarlGrey removeBookmarkWithTitle:@"Folder 2"];
[BookmarkEarlGrey removeBookmarkWithTitle:@"Folder 1"];
// Verify edit mode is close automatically (context bar switched back to
// default state) and both select and new folder button are disabled.
[BookmarkEarlGreyUI verifyContextBarInDefaultStateWithSelectEnabled:NO
newFolderEnabled:NO];
// Verify the empty background appears.
[BookmarkEarlGreyUI verifyEmptyBackgroundAppears];
// Come back to Folder 1 (which is also deleted).
[[EarlGrey selectElementWithMatcher:BookmarksNavigationBarBackButton()]
performAction:grey_tap()];
// Verify both select and new folder button are disabled.
[BookmarkEarlGreyUI verifyContextBarInDefaultStateWithSelectEnabled:NO
newFolderEnabled:NO];
// Verify the empty background appears.
[BookmarkEarlGreyUI verifyEmptyBackgroundAppears];
// Come back to Mobile Bookmarks.
[[EarlGrey selectElementWithMatcher:BookmarksNavigationBarBackButton()]
performAction:grey_tap()];
// Ensure Folder 1.1 is seen, that means it successfully comes back to Mobile
// Bookmarks.
[BookmarkEarlGreyUI verifyBookmarkFolderIsSeen:@"Folder 1.1"];
}
- (void)testLongPressOnSingleFolder {
[BookmarkEarlGrey setupStandardBookmarks];
[BookmarkEarlGreyUI openBookmarks];
[BookmarkEarlGreyUI openMobileBookmarks];
[[EarlGrey
selectElementWithMatcher:TappableBookmarkNodeWithLabel(@"Folder 1")]
performAction:grey_longPress()];
[BookmarkEarlGreyUI verifyContextMenuForSingleFolderWithEditEnabled:YES];
[BookmarkEarlGreyUI dismissContextMenu];
[ChromeEarlGrey waitForMatcher:grey_allOf(BookmarksNavigationBarBackButton(),
grey_interactable(), nil)];
// Come back to the root.
[[EarlGrey selectElementWithMatcher:BookmarksNavigationBarBackButton()]
performAction:grey_tap()];
// Long press on Mobile Bookmarks.
[[EarlGrey selectElementWithMatcher:TappableBookmarkNodeWithLabel(
@"Mobile Bookmarks")]
performAction:grey_longPress()];
// Verify it doesn't show the context menu. (long press is disabled on
// permanent node.)
if ([ChromeEarlGrey isNativeContextMenusEnabled]) {
// We cannot locate new context menus any way, therefore we'll use the
// 'Edit' action presence as proxy.
[[EarlGrey selectElementWithMatcher:chrome_test_util::
BookmarksContextMenuEditButton()]
assertWithMatcher:grey_nil()];
} else {
[[EarlGrey selectElementWithMatcher:grey_accessibilityID(
kBookmarkHomeContextMenuIdentifier)]
assertWithMatcher:grey_nil()];
}
}
// Verify Edit functionality for single folder selection.
- (void)testEditFunctionalityOnSingleFolder {
[BookmarkEarlGrey setupStandardBookmarks];
[BookmarkEarlGreyUI openBookmarks];
[BookmarkEarlGreyUI openMobileBookmarks];
// 1. Edit the folder title at edit page.
// Invoke Edit through long press.
[[EarlGrey
selectElementWithMatcher:TappableBookmarkNodeWithLabel(@"Folder 1")]
performAction:grey_longPress()];
id<GREYMatcher> editFolderMatcher =
[ChromeEarlGrey isNativeContextMenusEnabled]
? chrome_test_util::BookmarksContextMenuEditButton()
: ButtonWithAccessibilityLabelId(
IDS_IOS_BOOKMARK_CONTEXT_MENU_EDIT_FOLDER);
[[EarlGrey selectElementWithMatcher:editFolderMatcher]
performAction:grey_tap()];
// Verify that the editor is present.
[[EarlGrey
selectElementWithMatcher:grey_accessibilityID(
kBookmarkFolderEditViewContainerIdentifier)]
assertWithMatcher:grey_notNil()];
NSString* existingFolderTitle = @"Folder 1";
NSString* newFolderTitle = @"New Folder Title";
[BookmarkEarlGreyUI renameBookmarkFolderWithFolderTitle:newFolderTitle];
[[EarlGrey selectElementWithMatcher:BookmarksSaveEditFolderButton()]
performAction:grey_tap()];
// Verify that the change has been made.
[[EarlGrey selectElementWithMatcher:grey_accessibilityID(existingFolderTitle)]
assertWithMatcher:grey_nil()];
[[EarlGrey selectElementWithMatcher:grey_accessibilityID(newFolderTitle)]
assertWithMatcher:grey_notNil()];
// Verify edit mode is closed (context bar back to default state).
[BookmarkEarlGreyUI verifyContextBarInDefaultStateWithSelectEnabled:YES
newFolderEnabled:YES];
// 2. Move a single folder at edit page.
// Change to edit mode
[[EarlGrey
selectElementWithMatcher:grey_accessibilityID(
kBookmarkHomeTrailingButtonIdentifier)]
performAction:grey_tap()];
// Select single folder.
[[EarlGrey
selectElementWithMatcher:TappableBookmarkNodeWithLabel(newFolderTitle)]
performAction:grey_tap()];
// Move the "New Folder Title" to "Folder 1.1".
[BookmarkEarlGreyUI
tapOnContextMenuButton:IDS_IOS_BOOKMARK_CONTEXT_MENU_EDIT_FOLDER
openEditor:kBookmarkFolderEditViewContainerIdentifier
setParentFolderTo:@"Folder 1.1"
from:@"Mobile Bookmarks"];
// Verify edit mode remains.
[BookmarkEarlGreyUI verifyContextBarInEditMode];
// Close edit mode.
[BookmarkEarlGreyUI closeContextBarEditMode];
// Navigate to "Folder 1.1" and verify "New Folder Title" is under it.
[[EarlGrey
selectElementWithMatcher:TappableBookmarkNodeWithLabel(@"Folder 1.1")]
performAction:grey_tap()];
[[EarlGrey selectElementWithMatcher:grey_accessibilityID(newFolderTitle)]
assertWithMatcher:grey_sufficientlyVisible()];
// 3. Test the cancel button at edit page.
// Change to edit mode
[[EarlGrey
selectElementWithMatcher:grey_accessibilityID(
kBookmarkHomeTrailingButtonIdentifier)]
performAction:grey_tap()];
// Select single folder.
[[EarlGrey selectElementWithMatcher:grey_accessibilityID(newFolderTitle)]
performAction:grey_tap()];
// Tap cancel after modifying the title.
[BookmarkEarlGreyUI
tapOnContextMenuButton:IDS_IOS_BOOKMARK_CONTEXT_MENU_EDIT_FOLDER
openEditor:kBookmarkFolderEditViewContainerIdentifier
modifyTextField:@"Title_textField"
to:@"Dummy"
dismissWith:@"Cancel"];
// Verify that the bookmark was not updated.
[[EarlGrey selectElementWithMatcher:grey_accessibilityID(newFolderTitle)]
assertWithMatcher:grey_sufficientlyVisible()];
// Verify edit mode is stayed.
[BookmarkEarlGreyUI verifyContextBarInEditMode];
// 4. Test the delete button at edit page.
// Tap context menu.
[[EarlGrey
selectElementWithMatcher:ContextBarCenterButtonWithLabel(
[BookmarkEarlGreyUI contextBarMoreString])]
performAction:grey_tap()];
[[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()];
[[EarlGrey
selectElementWithMatcher:grey_accessibilityID(
kBookmarkFolderEditorDeleteButtonIdentifier)]
performAction:grey_tap()];
// Wait for Undo toast to go away from screen.
[BookmarkEarlGreyUI waitForUndoToastToGoAway];
// Verify that the folder is deleted.
[[EarlGrey selectElementWithMatcher:grey_accessibilityID(newFolderTitle)]
assertWithMatcher:grey_notVisible()];
// 5. Verify that when adding a new folder, edit mode will not mistakenly come
// back (crbug.com/781783).
// Create a new folder.
[BookmarkEarlGreyUI createNewBookmarkFolderWithFolderTitle:newFolderTitle
pressReturn:YES];
// Tap on the new folder.
[[EarlGrey selectElementWithMatcher:grey_accessibilityID(newFolderTitle)]
performAction:grey_tap()];
// Verify we enter the new folder. (instead of selecting it in edit mode).
[BookmarkEarlGreyUI verifyEmptyBackgroundAppears];
}
// Verify Move functionality on single folder through long press.
- (void)testMoveFunctionalityOnSingleFolder {
[BookmarkEarlGrey setupStandardBookmarks];
[BookmarkEarlGreyUI openBookmarks];
[BookmarkEarlGreyUI openMobileBookmarks];
// Invoke Move through long press.
[[EarlGrey
selectElementWithMatcher:TappableBookmarkNodeWithLabel(@"Folder 1.1")]
performAction:grey_longPress()];
[[EarlGrey selectElementWithMatcher:ButtonWithAccessibilityLabelId(
IDS_IOS_BOOKMARK_CONTEXT_MENU_MOVE)]
performAction:grey_tap()];
// Choose to move the bookmark folder - "Folder 1" into a new folder.
[[EarlGrey
selectElementWithMatcher:grey_accessibilityID(
kBookmarkCreateNewFolderCellIdentifier)]
performAction:grey_tap()];
// Enter custom new folder name.
[BookmarkEarlGreyUI
renameBookmarkFolderWithFolderTitle:@"Title For New Folder"];
// Verify current parent folder for "Title For New Folder" folder is "Mobile
// Bookmarks" folder.
[[EarlGrey
selectElementWithMatcher:grey_allOf(
grey_accessibilityID(@"Change Folder"),
grey_accessibilityLabel(@"Mobile Bookmarks"),
nil)]
assertWithMatcher:grey_sufficientlyVisible()];
// Choose new parent folder for "Title For New Folder" folder.
[[EarlGrey selectElementWithMatcher:grey_accessibilityID(@"Change Folder")]
performAction:grey_tap()];
// Verify folder picker UI is displayed.
[[EarlGrey
selectElementWithMatcher:
grey_accessibilityID(kBookmarkFolderPickerViewContainerIdentifier)]
assertWithMatcher:grey_sufficientlyVisible()];
// Verify Folder 2 only has one item.
[BookmarkEarlGrey verifyChildCount:1 inFolderWithName:@"Folder 2"];
// Select Folder 2 as new parent folder for "Title For New Folder".
[[EarlGrey
selectElementWithMatcher:TappableBookmarkNodeWithLabel(@"Folder 2")]
performAction:grey_tap()];
// Verify folder picker is dismissed and folder creator is now visible.
[[EarlGrey
selectElementWithMatcher:
grey_accessibilityID(kBookmarkFolderCreateViewContainerIdentifier)]
assertWithMatcher:grey_sufficientlyVisible()];
[[EarlGrey
selectElementWithMatcher:
grey_accessibilityID(kBookmarkFolderPickerViewContainerIdentifier)]
assertWithMatcher:grey_notVisible()];
// Verify picked parent folder is Folder 2.
[[EarlGrey
selectElementWithMatcher:grey_allOf(
grey_accessibilityID(@"Change Folder"),
grey_accessibilityLabel(@"Folder 2"), nil)]
assertWithMatcher:grey_sufficientlyVisible()];
// Tap Done to close bookmark move flow.
[[EarlGrey selectElementWithMatcher:BookmarksSaveEditFolderButton()]
performAction:grey_tap()];
// Verify all folder flow UI is now closed.
[BookmarkEarlGreyUI verifyFolderFlowIsClosed];
// Verify new folder "Title For New Folder" has been created under Folder 2.
[BookmarkEarlGrey verifyChildCount:2 inFolderWithName:@"Folder 2"];
// Verify new folder "Title For New Folder" has one bookmark folder.
[BookmarkEarlGrey verifyChildCount:1
inFolderWithName:@"Title For New Folder"];
// Drill down to where "Folder 1.1" has been moved and assert it's presence.
[[EarlGrey
selectElementWithMatcher:TappableBookmarkNodeWithLabel(@"Folder 1")]
performAction:grey_tap()];
[[EarlGrey
selectElementWithMatcher:TappableBookmarkNodeWithLabel(@"Folder 2")]
performAction:grey_tap()];
[[EarlGrey selectElementWithMatcher:TappableBookmarkNodeWithLabel(
@"Title For New Folder")]
performAction:grey_tap()];
[[EarlGrey selectElementWithMatcher:grey_accessibilityID(@"Folder 1.1")]
assertWithMatcher:grey_sufficientlyVisible()];
}
// Verify Move functionality on multiple folder selection.
- (void)testMoveFunctionalityOnMultipleFolder {
[BookmarkEarlGrey setupStandardBookmarks];
[BookmarkEarlGreyUI openBookmarks];
[BookmarkEarlGreyUI openMobileBookmarks];
// Change to edit mode, using context menu.
[[EarlGrey
selectElementWithMatcher:grey_accessibilityID(
kBookmarkHomeTrailingButtonIdentifier)]
performAction:grey_tap()];
// Select multiple folders.
[[EarlGrey
selectElementWithMatcher:TappableBookmarkNodeWithLabel(@"Folder 1.1")]
performAction:grey_tap()];
[[EarlGrey
selectElementWithMatcher:TappableBookmarkNodeWithLabel(@"Folder 1")]
performAction:grey_tap()];
// Tap context menu.
[[EarlGrey
selectElementWithMatcher:ContextBarCenterButtonWithLabel(
[BookmarkEarlGreyUI contextBarMoreString])]
performAction:grey_tap()];
[[EarlGrey selectElementWithMatcher:ButtonWithAccessibilityLabelId(
IDS_IOS_BOOKMARK_CONTEXT_MENU_MOVE)]
performAction:grey_tap()];
// Choose to move into a new folder. By tapping on the New Folder Cell.
[[EarlGrey
selectElementWithMatcher:grey_accessibilityID(
kBookmarkCreateNewFolderCellIdentifier)]
performAction:grey_tap()];
// Enter custom new folder name.
[BookmarkEarlGreyUI
renameBookmarkFolderWithFolderTitle:@"Title For New Folder"];
// Verify current parent folder for "Title For New Folder" folder is "Mobile
// Bookmarks" folder.
[[EarlGrey
selectElementWithMatcher:grey_allOf(
grey_accessibilityID(@"Change Folder"),
grey_accessibilityLabel(@"Mobile Bookmarks"),
nil)]
assertWithMatcher:grey_sufficientlyVisible()];
// Tap Done to close bookmark move flow.
[[EarlGrey selectElementWithMatcher:BookmarksSaveEditFolderButton()]
performAction:grey_tap()];
// Verify all folder flow UI is now closed.
[BookmarkEarlGreyUI verifyFolderFlowIsClosed];
// Wait for Undo toast to go away from screen.
[BookmarkEarlGreyUI waitForUndoToastToGoAway];
// Verify edit mode is closed (context bar back to default state).
[BookmarkEarlGreyUI verifyContextBarInDefaultStateWithSelectEnabled:YES
newFolderEnabled:YES];
// Verify new folder "Title For New Folder" has two bookmark folder.
[BookmarkEarlGrey verifyChildCount:2
inFolderWithName:@"Title For New Folder"];
// Drill down to where "Folder 1.1" and "Folder 1" have been moved and assert
// it's presence.
[[EarlGrey selectElementWithMatcher:TappableBookmarkNodeWithLabel(
@"Title For New Folder")]
performAction:grey_tap()];
[[EarlGrey selectElementWithMatcher:grey_accessibilityID(@"Folder 1.1")]
assertWithMatcher:grey_sufficientlyVisible()];
[[EarlGrey selectElementWithMatcher:grey_accessibilityID(@"Folder 1")]
assertWithMatcher:grey_sufficientlyVisible()];
}
- (void)testContextBarForSingleFolderSelection {
[BookmarkEarlGrey setupStandardBookmarks];
[BookmarkEarlGreyUI openBookmarks];
[BookmarkEarlGreyUI openMobileBookmarks];
// Change to edit mode
[[EarlGrey
selectElementWithMatcher:grey_accessibilityID(
kBookmarkHomeTrailingButtonIdentifier)]
performAction:grey_tap()];
// Select Folder.
[[EarlGrey
selectElementWithMatcher:TappableBookmarkNodeWithLabel(@"Folder 1")]
performAction:grey_tap()];
// Tap context menu.
[[EarlGrey
selectElementWithMatcher:ContextBarCenterButtonWithLabel(
[BookmarkEarlGreyUI contextBarMoreString])]
performAction:grey_tap()];
// Tap Edit Folder.
[[EarlGrey
selectElementWithMatcher:ButtonWithAccessibilityLabelId(
IDS_IOS_BOOKMARK_CONTEXT_MENU_EDIT_FOLDER)]
performAction:grey_tap()];
// Verify it shows edit view controller. Uses notNil() instead of
// sufficientlyVisible() because the large title in the navigation bar causes
// less than 75% of the table view to be visible.
[[EarlGrey
selectElementWithMatcher:grey_accessibilityID(
kBookmarkFolderEditViewContainerIdentifier)]
assertWithMatcher:grey_notNil()];
}
- (void)testContextMenuForMultipleFolderSelection {
[BookmarkEarlGrey setupStandardBookmarks];
[BookmarkEarlGreyUI openBookmarks];
[BookmarkEarlGreyUI openMobileBookmarks];
// Change to edit mode
[[EarlGrey
selectElementWithMatcher:grey_accessibilityID(
kBookmarkHomeTrailingButtonIdentifier)]
performAction:grey_tap()];
// Select Folders.
[[EarlGrey
selectElementWithMatcher:TappableBookmarkNodeWithLabel(@"Folder 1")]
performAction:grey_tap()];
[[EarlGrey
selectElementWithMatcher:TappableBookmarkNodeWithLabel(@"Folder 1.1")]
performAction:grey_tap()];
// Tap context menu.
[[EarlGrey
selectElementWithMatcher:ContextBarCenterButtonWithLabel(
[BookmarkEarlGreyUI contextBarMoreString])]
performAction:grey_tap()];
// Verify it shows the context menu.
[[EarlGrey selectElementWithMatcher:grey_accessibilityID(
kBookmarkHomeContextMenuIdentifier)]
assertWithMatcher:grey_sufficientlyVisible()];
// Verify options on context menu.
[[EarlGrey selectElementWithMatcher:ButtonWithAccessibilityLabelId(
IDS_IOS_BOOKMARK_CONTEXT_MENU_MOVE)]
assertWithMatcher:grey_sufficientlyVisible()];
}
// Tests that the default folder bookmarks are saved in is updated to the last
// used folder.
- (void)testStickyDefaultFolder {
[BookmarkEarlGrey setupStandardBookmarks];
[BookmarkEarlGreyUI openBookmarks];
[BookmarkEarlGreyUI openMobileBookmarks];
// Invoke Edit through long press.
[[EarlGrey
selectElementWithMatcher:TappableBookmarkNodeWithLabel(@"First URL")]
performAction:grey_longPress()];
[[EarlGrey selectElementWithMatcher:chrome_test_util::
BookmarksContextMenuEditButton()]
performAction:grey_tap()];
// Tap the Folder button.
[[EarlGrey selectElementWithMatcher:grey_accessibilityID(@"Change Folder")]
performAction:grey_tap()];
// Create a new folder.
[BookmarkEarlGreyUI addFolderWithName:@"Sticky Folder"];
// Verify that the editor is present. Uses notNil() instead of
// sufficientlyVisible() because the large title in the navigation bar causes
// less than 75% of the table view to be visible.
[[EarlGrey selectElementWithMatcher:grey_accessibilityID(
kBookmarkEditViewContainerIdentifier)]
assertWithMatcher:grey_notNil()];
// Tap the Done button.
[[EarlGrey selectElementWithMatcher:BookmarksSaveEditDoneButton()]
performAction:grey_tap()];
[[EarlGrey selectElementWithMatcher:grey_accessibilityID(
kBookmarkEditViewContainerIdentifier)]
assertWithMatcher:grey_notVisible()];
// Close bookmarks
[[EarlGrey selectElementWithMatcher:BookmarkHomeDoneButton()]
performAction:grey_tap()];
// Second, bookmark a page.
// Verify that the bookmark that is going to be added is not in the
// BookmarkModel.
GREYAssertTrue(self.testServer->Start(), @"Server did not start.");
const GURL bookmarkedURL = self.testServer->GetURL("/fullscreen.html");
NSString* const bookmarkedURLString =
base::SysUTF8ToNSString(bookmarkedURL.spec());
[BookmarkEarlGrey verifyBookmarksWithTitle:bookmarkedURLString
expectedCount:0];
// Open the page.
std::string expectedURLContent = bookmarkedURL.GetContent();
[ChromeEarlGrey loadURL:bookmarkedURL];
[[EarlGrey selectElementWithMatcher:OmniboxText(expectedURLContent)]
assertWithMatcher:grey_notNil()];
// Verify that the folder has only one element.
[BookmarkEarlGrey verifyChildCount:1 inFolderWithName:@"Sticky Folder"];
// Bookmark the page.
[BookmarkEarlGreyUI starCurrentTab];
// Verify the snackbar title.
[[EarlGrey selectElementWithMatcher:grey_accessibilityLabel(
@"Bookmarked to Sticky Folder")]
assertWithMatcher:grey_sufficientlyVisible()];
// Verify that the newly-created bookmark is in the BookmarkModel.
[BookmarkEarlGrey verifyBookmarksWithTitle:bookmarkedURLString
expectedCount:1];
// Verify that the folder has now two elements.
[BookmarkEarlGrey verifyChildCount:2 inFolderWithName:@"Sticky Folder"];
}
// Tests the new folder name is committed when name editing is interrupted by
// navigating away.
- (void)testNewFolderNameCommittedOnNavigatingAway {
[BookmarkEarlGrey setupStandardBookmarks];
[BookmarkEarlGreyUI openBookmarks];
[BookmarkEarlGreyUI openMobileBookmarks];
// Create a new folder and type "New Folder 1" without pressing return.
NSString* newFolderTitle = @"New Folder 1";
[BookmarkEarlGreyUI createNewBookmarkFolderWithFolderTitle:newFolderTitle
pressReturn:NO];
// Interrupt the folder name editing by tapping on back.
[[EarlGrey selectElementWithMatcher:BookmarksNavigationBarBackButton()]
performAction:grey_tap()];
// Come back to Mobile Bookmarks.
[BookmarkEarlGreyUI openMobileBookmarks];
// Verify folder name "New Folder 1" was committed.
[BookmarkEarlGreyUI verifyFolderCreatedWithTitle:newFolderTitle];
// Create a new folder and type "New Folder 2" without pressing return.
newFolderTitle = @"New Folder 2";
[BookmarkEarlGreyUI createNewBookmarkFolderWithFolderTitle:newFolderTitle
pressReturn:NO];
// Interrupt the folder name editing by tapping on done.
[[EarlGrey selectElementWithMatcher:BookmarkHomeDoneButton()]
performAction:grey_tap()];
// Reopen bookmarks.
[BookmarkEarlGreyUI openBookmarks];
// Verify folder name "New Folder 2" was committed.
[BookmarkEarlGreyUI verifyFolderCreatedWithTitle:newFolderTitle];
// Create a new folder and type "New Folder 3" without pressing return.
newFolderTitle = @"New Folder 3";
[BookmarkEarlGreyUI createNewBookmarkFolderWithFolderTitle:newFolderTitle
pressReturn:NO];
// Interrupt the folder name editing by entering Folder 1
[[EarlGrey selectElementWithMatcher:grey_accessibilityID(
kBookmarkHomeTableViewIdentifier)]
performAction:ScrollToTop()];
[[EarlGrey selectElementWithMatcher:grey_accessibilityID(@"Folder 1")]
performAction:grey_tap()];
// Come back to Mobile Bookmarks.
[[EarlGrey selectElementWithMatcher:BookmarksNavigationBarBackButton()]
performAction:grey_tap()];
// Verify folder name "New Folder 3" was committed.
[BookmarkEarlGreyUI verifyFolderCreatedWithTitle:newFolderTitle];
// Create a new folder and type "New Folder 4" without pressing return.
newFolderTitle = @"New Folder 4";
[BookmarkEarlGreyUI createNewBookmarkFolderWithFolderTitle:newFolderTitle
pressReturn:NO];
// Interrupt the folder name editing by tapping on First URL.
[[EarlGrey selectElementWithMatcher:grey_accessibilityID(
kBookmarkHomeTableViewIdentifier)]
performAction:ScrollToTop()];
[[EarlGrey selectElementWithMatcher:grey_accessibilityID(@"French URL")]
performAction:grey_tap()];
// Reopen bookmarks.
[BookmarkEarlGreyUI openBookmarks];
// Verify folder name "New Folder 4" was committed.
[BookmarkEarlGreyUI verifyFolderCreatedWithTitle:newFolderTitle];
}
// Tests the creation of new folders by tapping on 'New Folder' button of the
// context bar.
- (void)testCreateNewFolderWithContextBar {
[BookmarkEarlGrey setupStandardBookmarks];
[BookmarkEarlGreyUI openBookmarks];
[BookmarkEarlGreyUI openMobileBookmarks];
// Create a new folder and name it "New Folder 1".
NSString* newFolderTitle = @"New Folder 1";
[BookmarkEarlGreyUI createNewBookmarkFolderWithFolderTitle:newFolderTitle
pressReturn:YES];
// Verify "New Folder 1" is created.
[BookmarkEarlGreyUI verifyFolderCreatedWithTitle:newFolderTitle];
// Create a new folder and name it "New Folder 2".
newFolderTitle = @"New Folder 2";
[BookmarkEarlGreyUI createNewBookmarkFolderWithFolderTitle:newFolderTitle
pressReturn:YES];
// Verify "New Folder 2" is created.
[BookmarkEarlGreyUI verifyFolderCreatedWithTitle:newFolderTitle];
// Verify context bar does not change after editing folder name.
[BookmarkEarlGreyUI verifyContextBarInDefaultStateWithSelectEnabled:YES
newFolderEnabled:YES];
}
// Test the creation of a bookmark and new folder (by tapping on the star).
- (void)testAddBookmarkInNewFolder {
GREYAssertTrue(self.testServer->Start(), @"Server did not start.");
const GURL bookmarkedURL = self.testServer->GetURL("/pony.html");
std::string expectedURLContent = bookmarkedURL.GetContent();
[ChromeEarlGrey loadURL:bookmarkedURL];
[[EarlGrey selectElementWithMatcher:OmniboxText(expectedURLContent)]
assertWithMatcher:grey_notNil()];
[BookmarkEarlGreyUI starCurrentTab];
// Verify the snackbar title.
[[EarlGrey selectElementWithMatcher:grey_accessibilityLabel(@"Bookmarked")]
assertWithMatcher:grey_notNil()];
// Tap on the snackbar.
NSString* snackbarLabel =
l10n_util::GetNSString(IDS_IOS_NAVIGATION_BAR_EDIT_BUTTON);
[[EarlGrey selectElementWithMatcher:grey_accessibilityLabel(snackbarLabel)]
performAction:grey_tap()];
// Verify that the newly-created bookmark is in the BookmarkModel.
[BookmarkEarlGrey
verifyBookmarksWithTitle:base::SysUTF8ToNSString(expectedURLContent)
expectedCount:1];
// Verify that the editor is present.
[[EarlGrey selectElementWithMatcher:grey_accessibilityID(
kBookmarkEditViewContainerIdentifier)]
assertWithMatcher:grey_notNil()];
[[EarlGrey
selectElementWithMatcher:grey_allOf(
grey_accessibilityID(@"Change Folder"),
grey_accessibilityLabel(@"Mobile Bookmarks"),
nil)] assertWithMatcher:grey_notNil()];
// Tap the Folder button.
[[EarlGrey selectElementWithMatcher:grey_accessibilityID(@"Change Folder")]
performAction:grey_tap()];
// Create a new folder with default name.
[BookmarkEarlGreyUI addFolderWithName:nil];
// Verify that the editor is present.
[[EarlGrey selectElementWithMatcher:grey_accessibilityID(
kBookmarkEditViewContainerIdentifier)]
assertWithMatcher:grey_notNil()];
[BookmarkEarlGrey verifyExistenceOfFolderWithTitle:@"New Folder"];
}
@end