[go: nahoru, domu]

blob: 6f3afe56f1c76ec49eb422701e1d3c8027331c13 [file] [log] [blame]
// Copyright 2019 The Chromium Authors
// 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>
#import "base/apple/foundation_util.h"
#import "base/i18n/message_formatter.h"
#import "base/ios/ios_util.h"
#import "base/strings/sys_string_conversions.h"
#import "base/strings/utf_string_conversions.h"
#import "components/bookmarks/common/bookmark_features.h"
#import "components/bookmarks/common/storage_type.h"
#import "components/strings/grit/components_strings.h"
#import "components/sync/base/features.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/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"
#import "net/test/embedded_test_server/embedded_test_server.h"
#import "ui/base/l10n/l10n_util.h"
using chrome_test_util::BookmarksDeleteSwipeButton;
using chrome_test_util::BookmarksHomeDoneButton;
using chrome_test_util::BookmarksNavigationBarBackButton;
using chrome_test_util::BookmarksSaveEditDoneButton;
using chrome_test_util::BookmarksSaveEditFolderButton;
using chrome_test_util::ButtonWithAccessibilityLabelId;
using chrome_test_util::ContextBarCenterButtonWithLabel;
using chrome_test_util::ContextBarLeadingButtonWithLabel;
using chrome_test_util::OmniboxText;
using chrome_test_util::ScrollToTop;
using chrome_test_util::TabGridEditButton;
using chrome_test_util::TappableBookmarkNodeWithLabel;
// Bookmark folders integration tests for Chrome.
@interface BookmarksFolderChooserTestCase : WebHttpServerChromeTestCase
@end
@implementation BookmarksFolderChooserTestCase
- (AppLaunchConfiguration)appConfigurationForTestCase {
AppLaunchConfiguration config;
if ([self isRunningTest:@selector
(testCreateNewLocalOrSyncableFolderDefaultDestination)]) {
config.features_enabled.push_back(syncer::kEnableBookmarksAccountStorage);
} else if ([self isRunningTest:@selector
(testCreateNewFolderDefaultDestinationLegacy)]) {
// Legacy test verifies pre-EnableBookmarksAccountStorage behavior.
config.features_disabled.push_back(syncer::kEnableBookmarksAccountStorage);
}
return config;
}
- (void)setUp {
[super setUp];
[BookmarkEarlGrey waitForBookmarkModelsLoaded];
[BookmarkEarlGrey clearBookmarks];
}
// Tear down called once per test.
- (void)tearDown {
[super tearDown];
[BookmarkEarlGrey clearBookmarks];
[BookmarkEarlGrey clearBookmarksPositionCache];
}
#pragma mark - BookmarksFolderChooser Tests
// Tests that new folder is created under `Mobile Bookmarks` by default.
// TODO(crbug.com/1442459): Add this test after support is available.
// - (void)testCreateNewAccountFolderDefaultDestination {}
// Tests that new folder is created under `Mobile Bookmarks` by default.
- (void)testCreateNewLocalOrSyncableFolderDefaultDestination {
[BookmarkEarlGrey
setupStandardBookmarksInStorage:bookmarks::StorageType::kLocalOrSyncable];
[BookmarkEarlGreyUI openBookmarks];
[BookmarkEarlGreyUI openMobileBookmarks];
// Open `Folder 3` nested in `Folder 1->Folder 2`.
[[EarlGrey
selectElementWithMatcher:TappableBookmarkNodeWithLabel(@"Folder 1")]
performAction:grey_tap()];
[[EarlGrey
selectElementWithMatcher:TappableBookmarkNodeWithLabel(@"Folder 2")]
performAction:grey_tap()];
// Long press on `Folder 3` and try to move it to a new folder.
[[EarlGrey
selectElementWithMatcher:TappableBookmarkNodeWithLabel(@"Folder 3")]
performAction:grey_longPress()];
[[EarlGrey selectElementWithMatcher:ButtonWithAccessibilityLabelId(
IDS_IOS_BOOKMARK_CONTEXT_MENU_MOVE)]
performAction:grey_tap()];
[[EarlGrey selectElementWithMatcher:
grey_accessibilityID(
kBookmarkCreateNewLocalOrSyncableFolderCellIdentifier)]
performAction:grey_tap()];
// Verify default parent folder is 'Mobile Bookmarks'.
[[EarlGrey
selectElementWithMatcher:grey_allOf(
grey_accessibilityID(@"Change Folder"),
grey_accessibilityLabel(@"Mobile Bookmarks"),
nil)]
assertWithMatcher:grey_sufficientlyVisible()];
}
// Tests that new folder is created under the old parent folder by default.
- (void)testCreateNewFolderDefaultDestinationLegacy {
[BookmarkEarlGrey
setupStandardBookmarksInStorage:bookmarks::StorageType::kLocalOrSyncable];
[BookmarkEarlGreyUI openBookmarks];
[BookmarkEarlGreyUI openMobileBookmarks];
// Open `Folder 3` nested in `Folder 1->Folder 2`.
[[EarlGrey
selectElementWithMatcher:TappableBookmarkNodeWithLabel(@"Folder 1")]
performAction:grey_tap()];
[[EarlGrey
selectElementWithMatcher:TappableBookmarkNodeWithLabel(@"Folder 2")]
performAction:grey_tap()];
// Long press on `Folder 3` and try to move it to a new folder.
[[EarlGrey
selectElementWithMatcher:TappableBookmarkNodeWithLabel(@"Folder 3")]
performAction:grey_longPress()];
[[EarlGrey selectElementWithMatcher:ButtonWithAccessibilityLabelId(
IDS_IOS_BOOKMARK_CONTEXT_MENU_MOVE)]
performAction:grey_tap()];
[[EarlGrey selectElementWithMatcher:
grey_accessibilityID(
kBookmarkCreateNewLocalOrSyncableFolderCellIdentifier)]
performAction:grey_tap()];
// Verify default parent folder is 'Folder 2'.
[[EarlGrey
selectElementWithMatcher:grey_allOf(
grey_accessibilityID(@"Change Folder"),
grey_accessibilityLabel(@"Folder 2"), nil)]
assertWithMatcher:grey_sufficientlyVisible()];
}
// Tests moving bookmarks into a new folder created in the moving process.
- (void)testCreateNewFolderWhileMovingBookmarks {
[BookmarkEarlGrey
setupStandardBookmarksInStorage:bookmarks::StorageType::kLocalOrSyncable];
[BookmarkEarlGreyUI openBookmarks];
[BookmarkEarlGreyUI openMobileBookmarks];
// Change to edit mode
[[EarlGrey
selectElementWithMatcher:grey_accessibilityID(
kBookmarksHomeTrailingButtonIdentifier)]
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(
kBookmarkCreateNewLocalOrSyncableFolderCellIdentifier)]
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"
inStorage:bookmarks::StorageType::kLocalOrSyncable];
// 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"
inStorage:bookmarks::StorageType::kLocalOrSyncable];
// Verify new folder has two bookmarks.
[BookmarkEarlGrey verifyChildCount:2
inFolderWithName:@"Title For New Folder"
inStorage:bookmarks::StorageType::kLocalOrSyncable];
}
- (void)testCantDeleteFolderBeingEdited {
[BookmarkEarlGrey
setupStandardBookmarksInStorage:bookmarks::StorageType::kLocalOrSyncable];
[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:grey_allOf(grey_accessibilityID(@"New Folder"),
grey_minimumVisiblePercent(0.7), nil)]
performAction:grey_swipeFastInDirection(kGREYDirectionLeft)];
// Verify the delete confirmation button doesn't show up.
[[EarlGrey selectElementWithMatcher:BookmarksDeleteSwipeButton()]
assertWithMatcher:grey_nil()];
}
- (void)testNavigateAwayFromFolderBeingEdited {
[BookmarkEarlGrey setupBookmarksWhichExceedsScreenHeightInStorage:
bookmarks::StorageType::kLocalOrSyncable];
[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(
kBookmarksHomeTableViewIdentifier)]
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_allOf(
grey_accessibilityValue(@"New Folder"),
grey_sufficientlyVisible(), nil)]
assertWithMatcher:grey_notNil()];
}
- (void)testDeleteSingleFolderNode {
[BookmarkEarlGrey
setupStandardBookmarksInStorage:bookmarks::StorageType::kLocalOrSyncable];
[BookmarkEarlGreyUI openBookmarks];
[BookmarkEarlGreyUI openMobileBookmarks];
// Change to edit mode
[[EarlGrey
selectElementWithMatcher:grey_accessibilityID(
kBookmarksHomeTrailingButtonIdentifier)]
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 {
[BookmarkEarlGrey
setupStandardBookmarksInStorage:bookmarks::StorageType::kLocalOrSyncable];
[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
setupStandardBookmarksInStorage:bookmarks::StorageType::kLocalOrSyncable];
[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(
kBookmarksHomeTrailingButtonIdentifier)]
performAction:grey_tap()];
// Delete the Folder 1 and Folder 2 programmatically in background.
[BookmarkEarlGrey
removeBookmarkWithTitle:@"Folder 2"
inStorage:bookmarks::StorageType::kLocalOrSyncable];
[BookmarkEarlGrey
removeBookmarkWithTitle:@"Folder 1"
inStorage:bookmarks::StorageType::kLocalOrSyncable];
// 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
setupStandardBookmarksInStorage:bookmarks::StorageType::kLocalOrSyncable];
[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()];
// 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()];
}
// Verify Edit functionality for single folder selection.
- (void)testEditFunctionalityOnSingleFolder {
[BookmarkEarlGrey
setupStandardBookmarksInStorage:bookmarks::StorageType::kLocalOrSyncable];
[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 =
chrome_test_util::BookmarksContextMenuEditButton();
[[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(
kBookmarksHomeTrailingButtonIdentifier)]
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(
kBookmarksHomeTrailingButtonIdentifier)]
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
setupStandardBookmarksInStorage:bookmarks::StorageType::kLocalOrSyncable];
[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(
kBookmarkCreateNewLocalOrSyncableFolderCellIdentifier)]
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"
inStorage:bookmarks::StorageType::kLocalOrSyncable];
// 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"
inStorage:bookmarks::StorageType::kLocalOrSyncable];
// Verify new folder "Title For New Folder" has one bookmark folder.
[BookmarkEarlGrey verifyChildCount:1
inFolderWithName:@"Title For New Folder"
inStorage:bookmarks::StorageType::kLocalOrSyncable];
// 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
setupStandardBookmarksInStorage:bookmarks::StorageType::kLocalOrSyncable];
[BookmarkEarlGreyUI openBookmarks];
[BookmarkEarlGreyUI openMobileBookmarks];
// Change to edit mode, using context menu.
[[EarlGrey
selectElementWithMatcher:grey_accessibilityID(
kBookmarksHomeTrailingButtonIdentifier)]
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(
kBookmarkCreateNewLocalOrSyncableFolderCellIdentifier)]
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"
inStorage:bookmarks::StorageType::kLocalOrSyncable];
// 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
setupStandardBookmarksInStorage:bookmarks::StorageType::kLocalOrSyncable];
[BookmarkEarlGreyUI openBookmarks];
[BookmarkEarlGreyUI openMobileBookmarks];
// Change to edit mode
[[EarlGrey
selectElementWithMatcher:grey_accessibilityID(
kBookmarksHomeTrailingButtonIdentifier)]
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
setupStandardBookmarksInStorage:bookmarks::StorageType::kLocalOrSyncable];
[BookmarkEarlGreyUI openBookmarks];
[BookmarkEarlGreyUI openMobileBookmarks];
// Change to edit mode
[[EarlGrey
selectElementWithMatcher:grey_accessibilityID(
kBookmarksHomeTrailingButtonIdentifier)]
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(
kBookmarksHomeContextMenuIdentifier)]
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
setupStandardBookmarksInStorage:bookmarks::StorageType::kLocalOrSyncable];
[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:BookmarksHomeDoneButton()]
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
inStorage:bookmarks::StorageType::kLocalOrSyncable];
// 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.
NSString* folderTitle = @"Sticky Folder";
[BookmarkEarlGrey verifyChildCount:1
inFolderWithName:folderTitle
inStorage:bookmarks::StorageType::kLocalOrSyncable];
// Bookmark the page.
[BookmarkEarlGreyUI starCurrentTab];
// Verify the snackbar title.
std::u16string title = base::SysNSStringToUTF16(folderTitle);
std::u16string pattern =
l10n_util::GetStringUTF16(IDS_IOS_BOOKMARK_PAGE_SAVED_FOLDER);
std::u16string result = base::i18n::MessageFormatter::FormatWithNamedArgs(
pattern, "count", 1, "title", title);
[[EarlGrey selectElementWithMatcher:grey_accessibilityLabel(
base::SysUTF16ToNSString(result))]
assertWithMatcher:grey_sufficientlyVisible()];
// Verify that the newly-created bookmark is in the BookmarkModel.
[BookmarkEarlGrey
verifyBookmarksWithTitle:bookmarkedURLString
expectedCount:1
inStorage:bookmarks::StorageType::kLocalOrSyncable];
// Verify that the folder has now two elements.
[BookmarkEarlGrey verifyChildCount:2
inFolderWithName:@"Sticky Folder"
inStorage:bookmarks::StorageType::kLocalOrSyncable];
}
// Tests the new folder name is committed when name editing is interrupted by
// navigating away.
- (void)testNewFolderNameCommittedOnNavigatingAway {
[BookmarkEarlGrey
setupStandardBookmarksInStorage:bookmarks::StorageType::kLocalOrSyncable];
[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:BookmarksHomeDoneButton()]
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(
kBookmarksHomeTableViewIdentifier)]
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(
kBookmarksHomeTableViewIdentifier)]
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
setupStandardBookmarksInStorage:bookmarks::StorageType::kLocalOrSyncable];
[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_BOOKMARK_SNACKBAR_EDIT_BOOKMARK);
[[EarlGrey
selectElementWithMatcher:grey_allOf(
grey_accessibilityLabel(snackbarLabel),
grey_userInteractionEnabled(),
grey_not(TabGridEditButton()), nil)]
performAction:grey_tap()];
// Verify that the newly-created bookmark is in the BookmarkModel.
[BookmarkEarlGrey
verifyBookmarksWithTitle:base::SysUTF8ToNSString(expectedURLContent)
expectedCount:1
inStorage:bookmarks::StorageType::kLocalOrSyncable];
// 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"
inStorage:bookmarks::StorageType::
kLocalOrSyncable];
}
@end