Commit ad5dfc6b authored by sczs's avatar sczs Committed by Commit Bot

[ios] Makes BookmarksFoldersEGTest EG2 compatible.

- Adds verifyFolderExists to BookmarkEarlGrey and its AppInterface.

- Adds ScrollToTop to ChromeActions to be used on Bookmark Folder test.

- Deletes BookmarkEarlGreyUtils since its no longer used.

Change-Id: Ia1eeb07bcfa80f03e263c49d4f89b2592c338903
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1976490
Commit-Queue: Sergio Collazos <sczs@chromium.org>
Reviewed-by: default avatarEugene But <eugenebut@chromium.org>
Cr-Commit-Position: refs/heads/master@{#726604}
parent bc2e4b15
......@@ -172,12 +172,8 @@ source_set("eg_tests") {
":eg_test_support",
"//base",
"//base/test:test_support",
"//components/prefs",
"//components/strings",
"//ios/chrome/app/strings",
"//ios/chrome/browser",
"//ios/chrome/browser/bookmarks:bookmarks_utils",
"//ios/chrome/browser/browser_state",
"//ios/chrome/browser/ui/authentication:eg_test_support",
"//ios/chrome/browser/ui/popup_menu:constants",
"//ios/chrome/browser/ui/table_view:feature_flags",
......@@ -203,8 +199,6 @@ source_set("eg_test_support") {
"bookmark_earl_grey_app_interface.mm",
"bookmark_earl_grey_ui.h",
"bookmark_earl_grey_ui.mm",
"bookmark_earl_grey_utils.h",
"bookmark_earl_grey_utils.mm",
]
deps = [
":bookmarks",
......@@ -246,6 +240,7 @@ source_set("eg2_tests") {
"bookmarks_accessibility_egtest.mm",
"bookmarks_egtest.mm",
"bookmarks_entries_egtest.mm",
"bookmarks_folders_egtest.mm",
"bookmarks_promo_egtest.mm",
"bookmarks_search_egtest.mm",
]
......
......@@ -72,6 +72,10 @@ const GURL GetFrenchUrl();
// bookmarks does exist.
- (void)verifyAbsenceOfBookmarkWithURL:(NSString*)URL;
// Verifies that a folder called |title| exists. GREYAssert is induced if the
// folder doesn't exist.
- (void)verifyExistenceOfFolderWithTitle:(NSString*)title;
#pragma mark - Promo
// Checks that the promo has already been seen or not. GREYAssert is induced if
......
......@@ -111,6 +111,11 @@ const GURL GetFrenchUrl() {
[BookmarkEarlGreyAppInterface verifyAbsenceOfBookmarkWithURL:URL]);
}
- (void)verifyExistenceOfFolderWithTitle:(NSString*)title {
EG_TEST_HELPER_ASSERT_NO_ERROR(
[BookmarkEarlGreyAppInterface verifyExistenceOfFolderWithTitle:title]);
}
#pragma mark - Promo
- (void)verifyPromoAlreadySeen:(BOOL)seen {
......
......@@ -51,6 +51,9 @@
// Verifies the absence of a Bookmark with |URL|.
+ (NSError*)verifyAbsenceOfBookmarkWithURL:(NSString*)URL;
// Verifies that a folder called |title| exists.
+ (NSError*)verifyExistenceOfFolderWithTitle:(NSString*)title;
// Checks that the promo has already been seen or not.
+ (NSError*)verifyPromoAlreadySeen:(BOOL)seen;
......
......@@ -257,6 +257,31 @@
return nil;
}
+ (NSError*)verifyExistenceOfFolderWithTitle:(NSString*)title {
base::string16 folderTitle16(base::SysNSStringToUTF16(title));
ui::TreeNodeIterator<const bookmarks::BookmarkNode> iterator(
[self bookmarkModel] -> root_node());
BOOL folderExists = NO;
while (iterator.has_next()) {
const bookmarks::BookmarkNode* bookmark = iterator.Next();
if (bookmark->is_url())
continue;
// This is a folder.
if (bookmark->GetTitle() == folderTitle16) {
// Folder exists, return.
return nil;
}
}
if (!folderExists)
return testing::NSErrorWithLocalizedDescription(
[NSString stringWithFormat:@"Folder %@ doesn't exist", title]);
return nil;
}
+ (NSError*)verifyPromoAlreadySeen:(BOOL)seen {
ios::ChromeBrowserState* browserState =
chrome_test_util::GetOriginalBrowserState();
......
// 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.
#ifndef IOS_CHROME_BROWSER_UI_BOOKMARKS_BOOKMARK_EARL_GREY_UTILS_H_
#define IOS_CHROME_BROWSER_UI_BOOKMARKS_BOOKMARK_EARL_GREY_UTILS_H_
#import <Foundation/Foundation.h>
// Methods used for the EarlGrey tests.
@interface BookmarkEarlGreyUtils : NSObject
// Clear Bookmarks top most row position cache.
+ (void)clearBookmarksPositionCache;
// Loads a set of default bookmarks in the model for the tests to use.
+ (void)setupStandardBookmarks;
// Loads a large set of bookmarks in the model which is longer than the screen
// height.
+ (void)setupBookmarksWhichExceedsScreenHeight;
// Asserts that |expectedCount| bookmarks exist with the corresponding |title|
// using the BookmarkModel.
+ (void)assertBookmarksWithTitle:(NSString*)title
expectedCount:(NSUInteger)expectedCount;
// Asserts that a folder called |title| exists.
+ (void)assertFolderExists:(NSString*)title;
// Verifies that there is |count| children on the bookmark folder with |name|.
+ (void)assertChildCount:(size_t)count ofFolderWithName:(NSString*)name;
// Removes programmatically the first bookmark with the given title.
+ (void)removeBookmarkWithTitle:(NSString*)title;
+ (void)moveBookmarkWithTitle:(NSString*)bookmarkTitle
toFolderWithTitle:(NSString*)newFolder;
@end
#endif // IOS_CHROME_BROWSER_UI_BOOKMARKS_BOOKMARK_EARL_GREY_UTILS_H_
// 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 "ios/chrome/browser/ui/bookmarks/bookmark_earl_grey_utils.h"
#include "base/mac/foundation_util.h"
#include "base/strings/sys_string_conversions.h"
#import "base/test/ios/wait_util.h"
#include "build/build_config.h"
#include "components/bookmarks/browser/bookmark_model.h"
#include "components/bookmarks/browser/titled_url_match.h"
#include "components/prefs/pref_service.h"
#include "components/strings/grit/components_strings.h"
#include "ios/chrome/browser/bookmarks/bookmark_model_factory.h"
#include "ios/chrome/browser/browser_state/chrome_browser_state.h"
#include "ios/chrome/browser/pref_names.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_path_cache.h"
#import "ios/chrome/browser/ui/bookmarks/bookmark_ui_constants.h"
#import "ios/chrome/browser/ui/bookmarks/bookmark_utils_ios.h"
#import "ios/chrome/browser/ui/popup_menu/popup_menu_constants.h"
#include "ios/chrome/grit/ios_strings.h"
#import "ios/chrome/test/app/chrome_test_util.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/testing/earl_grey/earl_grey_test.h"
#import "ios/web/public/test/http_server/http_server.h"
#include "ui/base/l10n/l10n_util.h"
#include "ui/base/models/tree_node_iterator.h"
#if !defined(__has_feature) || !__has_feature(objc_arc)
#error "This file requires ARC support."
#endif
using chrome_test_util::BookmarksMenuButton;
using chrome_test_util::BookmarksSaveEditDoneButton;
using chrome_test_util::ButtonWithAccessibilityLabel;
using chrome_test_util::ButtonWithAccessibilityLabelId;
using chrome_test_util::CancelButton;
using chrome_test_util::ContextMenuCopyButton;
using chrome_test_util::OmniboxText;
using chrome_test_util::PrimarySignInButton;
using chrome_test_util::SecondarySignInButton;
@implementation BookmarkEarlGreyUtils
#pragma mark - Public Interface
+ (void)clearBookmarksPositionCache {
ios::ChromeBrowserState* browser_state =
chrome_test_util::GetOriginalBrowserState();
[BookmarkPathCache
clearBookmarkTopMostRowCacheWithPrefService:browser_state->GetPrefs()];
}
+ (void)setupStandardBookmarks {
[BookmarkEarlGreyUtils waitForBookmarkModelLoaded:YES];
bookmarks::BookmarkModel* bookmark_model =
ios::BookmarkModelFactory::GetForBrowserState(
chrome_test_util::GetOriginalBrowserState());
NSString* firstTitle = @"First URL";
bookmark_model->AddURL(bookmark_model->mobile_node(), 0,
base::SysNSStringToUTF16(firstTitle), GetFirstUrl());
NSString* secondTitle = @"Second URL";
bookmark_model->AddURL(bookmark_model->mobile_node(), 0,
base::SysNSStringToUTF16(secondTitle), GetSecondUrl());
NSString* frenchTitle = @"French URL";
bookmark_model->AddURL(bookmark_model->mobile_node(), 0,
base::SysNSStringToUTF16(frenchTitle), GetFrenchUrl());
NSString* folderTitle = @"Folder 1";
const bookmarks::BookmarkNode* folder1 = bookmark_model->AddFolder(
bookmark_model->mobile_node(), 0, base::SysNSStringToUTF16(folderTitle));
folderTitle = @"Folder 1.1";
bookmark_model->AddFolder(bookmark_model->mobile_node(), 0,
base::SysNSStringToUTF16(folderTitle));
folderTitle = @"Folder 2";
const bookmarks::BookmarkNode* folder2 = bookmark_model->AddFolder(
folder1, 0, base::SysNSStringToUTF16(folderTitle));
folderTitle = @"Folder 3";
const bookmarks::BookmarkNode* folder3 = bookmark_model->AddFolder(
folder2, 0, base::SysNSStringToUTF16(folderTitle));
const GURL thirdURL = web::test::HttpServer::MakeUrl(
"http://ios/testing/data/http_server_files/chromium_logo_page.html");
NSString* thirdTitle = @"Third URL";
bookmark_model->AddURL(folder3, 0, base::SysNSStringToUTF16(thirdTitle),
thirdURL);
}
+ (void)setupBookmarksWhichExceedsScreenHeight {
[BookmarkEarlGreyUtils waitForBookmarkModelLoaded:YES];
bookmarks::BookmarkModel* bookmark_model =
ios::BookmarkModelFactory::GetForBrowserState(
chrome_test_util::GetOriginalBrowserState());
const GURL dummyURL = web::test::HttpServer::MakeUrl("http://google.com");
bookmark_model->AddURL(bookmark_model->mobile_node(), 0,
base::SysNSStringToUTF16(@"Bottom URL"), dummyURL);
NSString* dummyTitle = @"Dummy URL";
for (int i = 0; i < 20; i++) {
bookmark_model->AddURL(bookmark_model->mobile_node(), 0,
base::SysNSStringToUTF16(dummyTitle), dummyURL);
}
NSString* folderTitle = @"Folder 1";
const bookmarks::BookmarkNode* folder1 = bookmark_model->AddFolder(
bookmark_model->mobile_node(), 0, base::SysNSStringToUTF16(folderTitle));
bookmark_model->AddURL(bookmark_model->mobile_node(), 0,
base::SysNSStringToUTF16(@"Top URL"), dummyURL);
// Add URLs to Folder 1.
bookmark_model->AddURL(folder1, 0, base::SysNSStringToUTF16(dummyTitle),
dummyURL);
bookmark_model->AddURL(folder1, 0, base::SysNSStringToUTF16(@"Bottom 1"),
dummyURL);
for (int i = 0; i < 20; i++) {
bookmark_model->AddURL(folder1, 0, base::SysNSStringToUTF16(dummyTitle),
dummyURL);
}
}
+ (void)assertBookmarksWithTitle:(NSString*)title
expectedCount:(NSUInteger)expectedCount {
// Get BookmarkModel and wait for it to be loaded.
bookmarks::BookmarkModel* bookmarkModel =
ios::BookmarkModelFactory::GetForBrowserState(
chrome_test_util::GetOriginalBrowserState());
// Verify the correct number of bookmarks exist.
base::string16 matchString = base::SysNSStringToUTF16(title);
std::vector<bookmarks::TitledUrlMatch> matches;
bookmarkModel->GetBookmarksMatching(matchString, 50, &matches);
const size_t count = matches.size();
GREYAssertEqual(expectedCount, count, @"Unexpected number of bookmarks");
}
+ (void)assertFolderExists:(NSString*)title {
base::string16 folderTitle16(base::SysNSStringToUTF16(title));
bookmarks::BookmarkModel* bookmark_model =
ios::BookmarkModelFactory::GetForBrowserState(
chrome_test_util::GetOriginalBrowserState());
ui::TreeNodeIterator<const bookmarks::BookmarkNode> iterator(
bookmark_model->root_node());
BOOL folderExists = NO;
while (iterator.has_next()) {
const bookmarks::BookmarkNode* bookmark = iterator.Next();
if (bookmark->is_url())
continue;
// This is a folder.
if (bookmark->GetTitle() == folderTitle16) {
folderExists = YES;
break;
}
}
NSString* assertMessage =
[NSString stringWithFormat:@"Folder %@ doesn't exist", title];
GREYAssert(folderExists, assertMessage);
}
+ (void)assertChildCount:(size_t)count ofFolderWithName:(NSString*)name {
base::string16 name16(base::SysNSStringToUTF16(name));
bookmarks::BookmarkModel* bookmarkModel =
ios::BookmarkModelFactory::GetForBrowserState(
chrome_test_util::GetOriginalBrowserState());
ui::TreeNodeIterator<const bookmarks::BookmarkNode> iterator(
bookmarkModel->root_node());
const bookmarks::BookmarkNode* folder = NULL;
while (iterator.has_next()) {
const bookmarks::BookmarkNode* bookmark = iterator.Next();
if (bookmark->is_folder() && bookmark->GetTitle() == name16) {
folder = bookmark;
break;
}
}
GREYAssert(folder, @"No folder named %@", name);
GREYAssertEqual(folder->children().size(), count,
@"Unexpected number of children in folder '%@': %" PRIuS
" instead of %" PRIuS,
name, folder->children().size(), count);
}
+ (void)removeBookmarkWithTitle:(NSString*)title {
base::string16 name16(base::SysNSStringToUTF16(title));
bookmarks::BookmarkModel* bookmarkModel =
ios::BookmarkModelFactory::GetForBrowserState(
chrome_test_util::GetOriginalBrowserState());
ui::TreeNodeIterator<const bookmarks::BookmarkNode> iterator(
bookmarkModel->root_node());
while (iterator.has_next()) {
const bookmarks::BookmarkNode* bookmark = iterator.Next();
if (bookmark->GetTitle() == name16) {
bookmarkModel->Remove(bookmark);
return;
}
}
GREYFail(@"Could not remove bookmark with name %@", title);
}
+ (void)moveBookmarkWithTitle:(NSString*)bookmarkTitle
toFolderWithTitle:(NSString*)newFolder {
base::string16 name16(base::SysNSStringToUTF16(bookmarkTitle));
bookmarks::BookmarkModel* bookmarkModel =
ios::BookmarkModelFactory::GetForBrowserState(
chrome_test_util::GetOriginalBrowserState());
ui::TreeNodeIterator<const bookmarks::BookmarkNode> iterator(
bookmarkModel->root_node());
const bookmarks::BookmarkNode* bookmark = iterator.Next();
while (iterator.has_next()) {
if (bookmark->GetTitle() == name16) {
break;
}
bookmark = iterator.Next();
}
base::string16 folderName16(base::SysNSStringToUTF16(newFolder));
ui::TreeNodeIterator<const bookmarks::BookmarkNode> iteratorFolder(
bookmarkModel->root_node());
const bookmarks::BookmarkNode* folder = iteratorFolder.Next();
while (iteratorFolder.has_next()) {
if (folder->GetTitle() == folderName16) {
break;
}
folder = iteratorFolder.Next();
}
std::set<const bookmarks::BookmarkNode*> toMove;
toMove.insert(bookmark);
bookmark_utils_ios::MoveBookmarks(toMove, bookmarkModel, folder);
}
#pragma mark - Helpers
+ (void)waitForBookmarkModelLoaded:(BOOL)loaded {
bookmarks::BookmarkModel* bookmarkModel =
ios::BookmarkModelFactory::GetForBrowserState(
chrome_test_util::GetOriginalBrowserState());
GREYAssert(base::test::ios::WaitUntilConditionOrTimeout(
base::test::ios::kWaitForUIElementTimeout,
^{
return bookmarkModel->loaded() == loaded;
}),
@"Bookmark model was not loaded");
}
@end
......@@ -9,12 +9,12 @@
#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_earl_grey_utils.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/app/chrome_test_util.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"
......@@ -36,6 +36,7 @@ using chrome_test_util::ButtonWithAccessibilityLabelId;
using chrome_test_util::ContextBarLeadingButtonWithLabel;
using chrome_test_util::NavigateBackButtonTo;
using chrome_test_util::OmniboxText;
using chrome_test_util::ScrollToTop;
using chrome_test_util::TappableBookmarkNodeWithLabel;
// Bookmark folders integration tests for Chrome.
......@@ -55,7 +56,7 @@ using chrome_test_util::TappableBookmarkNodeWithLabel;
- (void)tearDown {
[super tearDown];
[ChromeEarlGrey clearBookmarks];
[BookmarkEarlGreyUtils clearBookmarksPositionCache];
[BookmarkEarlGrey clearBookmarksPositionCache];
}
#pragma mark - BookmarksTestFolders Tests
......@@ -68,7 +69,7 @@ using chrome_test_util::TappableBookmarkNodeWithLabel;
EARL_GREY_TEST_DISABLED(@"EG1 Fails on iOS 12.");
}
#endif
[BookmarkEarlGreyUtils setupStandardBookmarks];
[BookmarkEarlGrey setupStandardBookmarks];
[BookmarkEarlGreyUI openBookmarks];
[BookmarkEarlGreyUI openMobileBookmarks];
......@@ -126,7 +127,7 @@ using chrome_test_util::TappableBookmarkNodeWithLabel;
assertWithMatcher:grey_sufficientlyVisible()];
// Verify Folder 2 only has one item.
[BookmarkEarlGreyUtils assertChildCount:1 ofFolderWithName:@"Folder 2"];
[BookmarkEarlGrey verifyChildCount:1 inFolderWithName:@"Folder 2"];
// Select Folder 2 as new Change Folder.
[[EarlGrey selectElementWithMatcher:grey_accessibilityID(@"Folder 2")]
......@@ -168,15 +169,15 @@ using chrome_test_util::TappableBookmarkNodeWithLabel;
assertWithMatcher:grey_notVisible()];
// Verify new folder has been created under Folder 2.
[BookmarkEarlGreyUtils assertChildCount:2 ofFolderWithName:@"Folder 2"];
[BookmarkEarlGrey verifyChildCount:2 inFolderWithName:@"Folder 2"];
// Verify new folder has two bookmarks.
[BookmarkEarlGreyUtils assertChildCount:2
ofFolderWithName:@"Title For New Folder"];
[BookmarkEarlGrey verifyChildCount:2
inFolderWithName:@"Title For New Folder"];
}
- (void)testCantDeleteFolderBeingEdited {
[BookmarkEarlGreyUtils setupStandardBookmarks];
[BookmarkEarlGrey setupStandardBookmarks];
[BookmarkEarlGreyUI openBookmarks];
[BookmarkEarlGreyUI openMobileBookmarks];
......@@ -197,7 +198,7 @@ using chrome_test_util::TappableBookmarkNodeWithLabel;
}
- (void)testNavigateAwayFromFolderBeingEdited {
[BookmarkEarlGreyUtils setupBookmarksWhichExceedsScreenHeight];
[BookmarkEarlGrey setupBookmarksWhichExceedsScreenHeight];
[BookmarkEarlGreyUI openBookmarks];
[BookmarkEarlGreyUI openMobileBookmarks];
......@@ -217,16 +218,9 @@ using chrome_test_util::TappableBookmarkNodeWithLabel;
pressReturn:NO];
// Scroll to top to navigate away from the folder being created.
GREYPerformBlock scrollToTopBlock =
^BOOL(id element, __strong NSError** error) {
UIScrollView* view = base::mac::ObjCCastStrict<UIScrollView>(element);
view.contentOffset = CGPointZero;
return YES;
};
[[EarlGrey selectElementWithMatcher:grey_accessibilityID(
kBookmarkHomeTableViewIdentifier)]
performAction:[GREYActionBlock actionWithName:@"Scroll to top"
performBlock:scrollToTopBlock]];
performAction:ScrollToTop()];
// Scroll back to the Folder being created.
[BookmarkEarlGreyUI scrollToBottom];
......@@ -237,7 +231,7 @@ using chrome_test_util::TappableBookmarkNodeWithLabel;
}
- (void)testDeleteSingleFolderNode {
[BookmarkEarlGreyUtils setupStandardBookmarks];
[BookmarkEarlGrey setupStandardBookmarks];
[BookmarkEarlGreyUI openBookmarks];
[BookmarkEarlGreyUI openMobileBookmarks];
......@@ -282,7 +276,7 @@ using chrome_test_util::TappableBookmarkNodeWithLabel;
EARL_GREY_TEST_SKIPPED(@"Test disabled on when feature flag is off.");
}
[BookmarkEarlGreyUtils setupStandardBookmarks];
[BookmarkEarlGrey setupStandardBookmarks];
[BookmarkEarlGreyUI openBookmarks];
[BookmarkEarlGreyUI openMobileBookmarks];
......@@ -316,8 +310,16 @@ using chrome_test_util::TappableBookmarkNodeWithLabel;
// Test when current navigating folder is deleted in background, empty
// background should be shown with context bar buttons disabled.
- (void)testWhenCurrentFolderDeletedInBackground {
[BookmarkEarlGreyUtils setupStandardBookmarks];
// TODO(crbug.com/1034183): Enable for EG2 once NavigateBackButtonTo() is fixed.
#if defined(CHROME_EARL_GREY_2)
#define MAYBE_testWhenCurrentFolderDeletedInBackground \
DISABLED_testWhenCurrentFolderDeletedInBackground
#else
#define MAYBE_testWhenCurrentFolderDeletedInBackground \
testWhenCurrentFolderDeletedInBackground
#endif
- (void)MAYBE_testWhenCurrentFolderDeletedInBackground {
[BookmarkEarlGrey setupStandardBookmarks];
[BookmarkEarlGreyUI openBookmarks];
[BookmarkEarlGreyUI openMobileBookmarks];
......@@ -336,8 +338,8 @@ using chrome_test_util::TappableBookmarkNodeWithLabel;
performAction:grey_tap()];
// Delete the Folder 1 and Folder 2 programmatically in background.
[BookmarkEarlGreyUtils removeBookmarkWithTitle:@"Folder 2"];
[BookmarkEarlGreyUtils removeBookmarkWithTitle:@"Folder 1"];
[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.
......@@ -367,8 +369,14 @@ using chrome_test_util::TappableBookmarkNodeWithLabel;
[BookmarkEarlGreyUI verifyBookmarkFolderIsSeen:@"Folder 1.1"];
}
- (void)testLongPressOnSingleFolder {
[BookmarkEarlGreyUtils setupStandardBookmarks];
// TODO(crbug.com/1034183): Enable for EG2 once NavigateBackButtonTo() is fixed.
#if defined(CHROME_EARL_GREY_2)
#define MAYBE_testLongPressOnSingleFolder DISABLED_testLongPressOnSingleFolder
#else
#define MAYBE_testLongPressOnSingleFolder testLongPressOnSingleFolder
#endif
- (void)MAYBE_testLongPressOnSingleFolder {
[BookmarkEarlGrey setupStandardBookmarks];
[BookmarkEarlGreyUI openBookmarks];
[BookmarkEarlGreyUI openMobileBookmarks];
......@@ -421,7 +429,7 @@ using chrome_test_util::TappableBookmarkNodeWithLabel;
// Verify Edit functionality for single folder selection.
- (void)testEditFunctionalityOnSingleFolder {
[BookmarkEarlGreyUtils setupStandardBookmarks];
[BookmarkEarlGrey setupStandardBookmarks];
[BookmarkEarlGreyUI openBookmarks];
[BookmarkEarlGreyUI openMobileBookmarks];
......@@ -567,7 +575,7 @@ using chrome_test_util::TappableBookmarkNodeWithLabel;
// Verify Move functionality on single folder through long press.
- (void)testMoveFunctionalityOnSingleFolder {
[BookmarkEarlGreyUtils setupStandardBookmarks];
[BookmarkEarlGrey setupStandardBookmarks];
[BookmarkEarlGreyUI openBookmarks];
[BookmarkEarlGreyUI openMobileBookmarks];
......@@ -610,7 +618,7 @@ using chrome_test_util::TappableBookmarkNodeWithLabel;
assertWithMatcher:grey_sufficientlyVisible()];
// Verify Folder 2 only has one item.
[BookmarkEarlGreyUtils assertChildCount:1 ofFolderWithName:@"Folder 2"];
[BookmarkEarlGrey verifyChildCount:1 inFolderWithName:@"Folder 2"];
// Select Folder 2 as new parent folder for "Title For New Folder".
[[EarlGrey
......@@ -642,11 +650,11 @@ using chrome_test_util::TappableBookmarkNodeWithLabel;
[BookmarkEarlGreyUI verifyFolderFlowIsClosed];
// Verify new folder "Title For New Folder" has been created under Folder 2.
[BookmarkEarlGreyUtils assertChildCount:2 ofFolderWithName:@"Folder 2"];
[BookmarkEarlGrey verifyChildCount:2 inFolderWithName:@"Folder 2"];
// Verify new folder "Title For New Folder" has one bookmark folder.
[BookmarkEarlGreyUtils assertChildCount:1
ofFolderWithName:@"Title For New 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
......@@ -670,7 +678,7 @@ using chrome_test_util::TappableBookmarkNodeWithLabel;
EARL_GREY_TEST_DISABLED(@"EG1 Fails on iOS 12.");
}
#endif
[BookmarkEarlGreyUtils setupStandardBookmarks];
[BookmarkEarlGrey setupStandardBookmarks];
[BookmarkEarlGreyUI openBookmarks];
[BookmarkEarlGreyUI openMobileBookmarks];
......@@ -732,8 +740,8 @@ using chrome_test_util::TappableBookmarkNodeWithLabel;
newFolderEnabled:YES];
// Verify new folder "Title For New Folder" has two bookmark folder.
[BookmarkEarlGreyUtils assertChildCount:2
ofFolderWithName:@"Title For New 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.
......@@ -747,7 +755,7 @@ using chrome_test_util::TappableBookmarkNodeWithLabel;
}
- (void)testContextBarForSingleFolderSelection {
[BookmarkEarlGreyUtils setupStandardBookmarks];
[BookmarkEarlGrey setupStandardBookmarks];
[BookmarkEarlGreyUI openBookmarks];
[BookmarkEarlGreyUI openMobileBookmarks];
......@@ -784,7 +792,7 @@ using chrome_test_util::TappableBookmarkNodeWithLabel;
}
- (void)testContextMenuForMultipleFolderSelection {
[BookmarkEarlGreyUtils setupStandardBookmarks];
[BookmarkEarlGrey setupStandardBookmarks];
[BookmarkEarlGreyUI openBookmarks];
[BookmarkEarlGreyUI openMobileBookmarks];
......@@ -828,7 +836,7 @@ using chrome_test_util::TappableBookmarkNodeWithLabel;
EARL_GREY_TEST_DISABLED(@"EG1 Fails on iOS 12.");
}
#endif
[BookmarkEarlGreyUtils setupStandardBookmarks];
[BookmarkEarlGrey setupStandardBookmarks];
[BookmarkEarlGreyUI openBookmarks];
[BookmarkEarlGreyUI openMobileBookmarks];
......@@ -873,8 +881,8 @@ using chrome_test_util::TappableBookmarkNodeWithLabel;
"http://ios/testing/data/http_server_files/fullscreen.html");
NSString* const bookmarkedURLString =
base::SysUTF8ToNSString(bookmarkedURL.spec());
[BookmarkEarlGreyUtils assertBookmarksWithTitle:bookmarkedURLString
expectedCount:0];
[BookmarkEarlGrey verifyBookmarksWithTitle:bookmarkedURLString
expectedCount:0];
// Open the page.
std::string expectedURLContent = bookmarkedURL.GetContent();
[ChromeEarlGrey loadURL:bookmarkedURL];
......@@ -882,7 +890,7 @@ using chrome_test_util::TappableBookmarkNodeWithLabel;
assertWithMatcher:grey_notNil()];
// Verify that the folder has only one element.
[BookmarkEarlGreyUtils assertChildCount:1 ofFolderWithName:@"Sticky Folder"];
[BookmarkEarlGrey verifyChildCount:1 inFolderWithName:@"Sticky Folder"];
// Bookmark the page.
[BookmarkEarlGreyUI starCurrentTab];
......@@ -893,23 +901,31 @@ using chrome_test_util::TappableBookmarkNodeWithLabel;
assertWithMatcher:grey_sufficientlyVisible()];
// Verify that the newly-created bookmark is in the BookmarkModel.
[BookmarkEarlGreyUtils assertBookmarksWithTitle:bookmarkedURLString
expectedCount:1];
[BookmarkEarlGrey verifyBookmarksWithTitle:bookmarkedURLString
expectedCount:1];
// Verify that the folder has now two elements.
[BookmarkEarlGreyUtils assertChildCount:2 ofFolderWithName:@"Sticky Folder"];
[BookmarkEarlGrey verifyChildCount:2 inFolderWithName:@"Sticky Folder"];
}
// Tests the new folder name is committed when name editing is interrupted by
// navigating away.
- (void)testNewFolderNameCommittedOnNavigatingAway {
// TODO(crbug.com/1034183): Enable for EG2 once NavigateBackButtonTo() is fixed.
#if defined(CHROME_EARL_GREY_2)
#define MAYBE_testNewFolderNameCommittedOnNavigatingAway \
DISABLED_testNewFolderNameCommittedOnNavigatingAway
#else
#define MAYBE_testNewFolderNameCommittedOnNavigatingAway \
testNewFolderNameCommittedOnNavigatingAway
#endif
- (void)MAYBE_testNewFolderNameCommittedOnNavigatingAway {
#if defined(CHROME_EARL_GREY_1)
// TODO(crbug.com/1035764): EG1 Test fails on iOS 12.
if (!base::ios::IsRunningOnIOS13OrLater()) {
EARL_GREY_TEST_DISABLED(@"EG1 Fails on iOS 12.");
}
#endif
[BookmarkEarlGreyUtils setupStandardBookmarks];
[BookmarkEarlGrey setupStandardBookmarks];
[BookmarkEarlGreyUI openBookmarks];
[BookmarkEarlGreyUI openMobileBookmarks];
......@@ -948,17 +964,9 @@ using chrome_test_util::TappableBookmarkNodeWithLabel;
pressReturn:NO];
// Interrupt the folder name editing by entering Folder 1
GREYPerformBlock scrollToTopBlock =
^BOOL(id element, __strong NSError** error) {
UIScrollView* view = base::mac::ObjCCastStrict<UIScrollView>(element);
view.contentOffset = CGPointZero;
return YES;
};
[[EarlGrey selectElementWithMatcher:grey_accessibilityID(
kBookmarkHomeTableViewIdentifier)]
performAction:[GREYActionBlock actionWithName:@"Scroll to top"
performBlock:scrollToTopBlock]];
performAction:ScrollToTop()];
[[EarlGrey selectElementWithMatcher:grey_accessibilityID(@"Folder 1")]
performAction:grey_tap()];
......@@ -977,8 +985,7 @@ using chrome_test_util::TappableBookmarkNodeWithLabel;
// Interrupt the folder name editing by tapping on First URL.
[[EarlGrey selectElementWithMatcher:grey_accessibilityID(
kBookmarkHomeTableViewIdentifier)]
performAction:[GREYActionBlock actionWithName:@"Scroll to top"
performBlock:scrollToTopBlock]];
performAction:ScrollToTop()];
[[EarlGrey selectElementWithMatcher:grey_accessibilityID(@"French URL")]
performAction:grey_tap()];
......@@ -992,7 +999,7 @@ using chrome_test_util::TappableBookmarkNodeWithLabel;
// Tests the creation of new folders by tapping on 'New Folder' button of the
// context bar.
- (void)testCreateNewFolderWithContextBar {
[BookmarkEarlGreyUtils setupStandardBookmarks];
[BookmarkEarlGrey setupStandardBookmarks];
[BookmarkEarlGreyUI openBookmarks];
[BookmarkEarlGreyUI openMobileBookmarks];
......@@ -1040,8 +1047,8 @@ using chrome_test_util::TappableBookmarkNodeWithLabel;
performAction:grey_tap()];
// Verify that the newly-created bookmark is in the BookmarkModel.
[BookmarkEarlGreyUtils
assertBookmarksWithTitle:base::SysUTF8ToNSString(expectedURLContent)
[BookmarkEarlGrey
verifyBookmarksWithTitle:base::SysUTF8ToNSString(expectedURLContent)
expectedCount:1];
// Verify that the editor is present.
......@@ -1067,7 +1074,7 @@ using chrome_test_util::TappableBookmarkNodeWithLabel;
kBookmarkEditViewContainerIdentifier)]
assertWithMatcher:grey_notNil()];
[BookmarkEarlGreyUtils assertFolderExists:@"New Folder"];
[BookmarkEarlGrey verifyExistenceOfFolderWithTitle:@"New Folder"];
}
@end
......@@ -48,6 +48,12 @@ id<GREYAction> TapWebElementWithId(const std::string& element_id);
id<GREYAction> TapWebElementWithIdInFrame(const std::string& element_id,
const int frame_index);
// Action to scroll to top of a UIScrollView.
// On iOS 13 the settings menu appears as a card that can be dismissed with a
// downward swipe, for this reason we need to swipe up programmatically to
// avoid dismissing the VC.
id<GREYAction> ScrollToTop();
} // namespace chrome_test_util
#endif // IOS_CHROME_TEST_EARL_GREY_CHROME_ACTIONS_H_
......@@ -53,4 +53,8 @@ id<GREYAction> TapWebElementWithIdInFrame(const std::string& element_id,
inFrameWithIndex:frame_index]];
}
id<GREYAction> ScrollToTop() {
return [ChromeActionsAppInterface scrollToTop];
}
} // namespace chrome_test_util
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