Commit 721e4e10 authored by sczs's avatar sczs Committed by Commit Bot

[ios] Creates a separate file for each Bookmark test suite

Change-Id: I0d32f0f7df8e09cb7abe9a2dcd3266eadf85c434
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1959325
Commit-Queue: Sergio Collazos <sczs@chromium.org>
Reviewed-by: default avatarRohit Rao <rohitrao@chromium.org>
Cr-Commit-Position: refs/heads/master@{#723612}
parent 88698664
......@@ -161,7 +161,12 @@ source_set("eg_tests") {
sources = [
"bookmark_earl_grey_utils.h",
"bookmark_earl_grey_utils.mm",
"bookmarks_accessibility_egtest.mm",
"bookmarks_egtest.mm",
"bookmarks_entries_egtest.mm",
"bookmarks_folders_egtest.mm",
"bookmarks_promo_egtest.mm",
"bookmarks_search_egtest.mm",
]
deps = [
":bookmarks_ui",
......
// 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 "ios/chrome/browser/browser_state/chrome_browser_state.h"
#import "ios/chrome/browser/ui/bookmarks/bookmark_earl_grey_utils.h"
#import "ios/chrome/browser/ui/bookmarks/bookmark_path_cache.h"
#import "ios/chrome/browser/ui/bookmarks/bookmark_ui_constants.h"
#include "ios/chrome/grit/ios_strings.h"
#import "ios/chrome/test/app/chrome_test_util.h"
#import "ios/chrome/test/earl_grey/accessibility_util.h"
#import "ios/chrome/test/earl_grey/chrome_earl_grey.h"
#import "ios/chrome/test/earl_grey/chrome_matchers.h"
#import "ios/chrome/test/earl_grey/chrome_test_case.h"
#import "ios/testing/earl_grey/earl_grey_test.h"
#if !defined(__has_feature) || !__has_feature(objc_arc)
#error "This file requires ARC support."
#endif
using chrome_test_util::ButtonWithAccessibilityLabelId;
// Bookmark accessibility tests for Chrome.
@interface BookmarksAccessibilityTestCase : ChromeTestCase
@end
@implementation BookmarksAccessibilityTestCase
- (void)setUp {
[super setUp];
[ChromeEarlGrey waitForBookmarksToFinishLoading];
[ChromeEarlGrey clearBookmarks];
}
// Tear down called once per test.
- (void)tearDown {
[super tearDown];
[ChromeEarlGrey clearBookmarks];
// Clear position cache so that Bookmarks starts at the root folder in next
// test.
ios::ChromeBrowserState* browser_state =
chrome_test_util::GetOriginalBrowserState();
[BookmarkPathCache
clearBookmarkTopMostRowCacheWithPrefService:browser_state->GetPrefs()];
}
#pragma mark - BookmarksAccessibilityTestCase Tests
// Tests that all elements on the bookmarks landing page are accessible.
- (void)testAccessibilityOnBookmarksLandingPage {
[BookmarkEarlGreyUtils setupStandardBookmarks];
[BookmarkEarlGreyUtils openBookmarks];
[ChromeEarlGrey verifyAccessibilityForCurrentScreen];
}
// Tests that all elements on mobile bookmarks are accessible.
- (void)testAccessibilityOnMobileBookmarks {
[BookmarkEarlGreyUtils setupStandardBookmarks];
[BookmarkEarlGreyUtils openBookmarks];
[BookmarkEarlGreyUtils openMobileBookmarks];
[ChromeEarlGrey verifyAccessibilityForCurrentScreen];
}
// Tests that all elements on the bookmarks folder Edit page are accessible.
- (void)testAccessibilityOnBookmarksFolderEditPage {
[BookmarkEarlGreyUtils setupStandardBookmarks];
[BookmarkEarlGreyUtils openBookmarks];
[BookmarkEarlGreyUtils openMobileBookmarks];
// Invoke Edit through long press.
[[EarlGrey
selectElementWithMatcher:TappableBookmarkNodeWithLabel(@"Folder 1")]
performAction:grey_longPress()];
[[EarlGrey
selectElementWithMatcher:ButtonWithAccessibilityLabelId(
IDS_IOS_BOOKMARK_CONTEXT_MENU_EDIT_FOLDER)]
performAction:grey_tap()];
// Verify that the editor is present.
[[EarlGrey
selectElementWithMatcher:grey_accessibilityID(
kBookmarkFolderEditViewContainerIdentifier)]
assertWithMatcher:grey_notNil()];
[ChromeEarlGrey verifyAccessibilityForCurrentScreen];
}
// Tests that all elements on the bookmarks Edit page are accessible.
- (void)testAccessibilityOnBookmarksEditPage {
[BookmarkEarlGreyUtils setupStandardBookmarks];
[BookmarkEarlGreyUtils openBookmarks];
[BookmarkEarlGreyUtils openMobileBookmarks];
// Invoke Edit through long press.
[[EarlGrey
selectElementWithMatcher:TappableBookmarkNodeWithLabel(@"Second URL")]
performAction:grey_longPress()];
[[EarlGrey selectElementWithMatcher:ButtonWithAccessibilityLabelId(
IDS_IOS_BOOKMARK_CONTEXT_MENU_EDIT)]
performAction:grey_tap()];
// TODO(crbug.com/976930): to support EG2 need to use [ChromeEarlGrey
// verifyAccessibilityForCurrentScreen]
chrome_test_util::VerifyAccessibilityForCurrentScreen();
}
// Tests that all elements on the bookmarks Move page are accessible.
- (void)testAccessibilityOnBookmarksMovePage {
[BookmarkEarlGreyUtils setupStandardBookmarks];
[BookmarkEarlGreyUtils openBookmarks];
[BookmarkEarlGreyUtils openMobileBookmarks];
// Invoke Move through long press.
[[EarlGrey
selectElementWithMatcher:TappableBookmarkNodeWithLabel(@"Folder 1")]
performAction:grey_longPress()];
[[EarlGrey selectElementWithMatcher:ButtonWithAccessibilityLabelId(
IDS_IOS_BOOKMARK_CONTEXT_MENU_MOVE)]
performAction:grey_tap()];
// TODO(crbug.com/976930): to support EG2 need to use [ChromeEarlGrey
// verifyAccessibilityForCurrentScreen]
chrome_test_util::VerifyAccessibilityForCurrentScreen();
}
// Tests that all elements on the bookmarks Move to New Folder page are
// accessible.
- (void)testAccessibilityOnBookmarksMoveToNewFolderPage {
[BookmarkEarlGreyUtils setupStandardBookmarks];
[BookmarkEarlGreyUtils openBookmarks];
[BookmarkEarlGreyUtils openMobileBookmarks];
// Invoke Move through long press.
[[EarlGrey
selectElementWithMatcher:TappableBookmarkNodeWithLabel(@"Folder 1")]
performAction:grey_longPress()];
[[EarlGrey selectElementWithMatcher:ButtonWithAccessibilityLabelId(
IDS_IOS_BOOKMARK_CONTEXT_MENU_MOVE)]
performAction:grey_tap()];
// Tap on "Create New Folder."
[[EarlGrey
selectElementWithMatcher:grey_accessibilityID(
kBookmarkCreateNewFolderCellIdentifier)]
performAction:grey_tap()];
[ChromeEarlGrey verifyAccessibilityForCurrentScreen];
}
// Tests that all elements on bookmarks Delete and Undo are accessible.
- (void)testAccessibilityOnBookmarksDeleteUndo {
[BookmarkEarlGreyUtils setupStandardBookmarks];
[BookmarkEarlGreyUtils openBookmarks];
[BookmarkEarlGreyUtils openMobileBookmarks];
// Change to edit mode
[[EarlGrey
selectElementWithMatcher:grey_accessibilityID(
kBookmarkHomeTrailingButtonIdentifier)]
performAction:grey_tap()];
// Select single URL.
[[EarlGrey
selectElementWithMatcher:TappableBookmarkNodeWithLabel(@"Second URL")]
performAction:grey_tap()];
// Delete it.
[[EarlGrey selectElementWithMatcher:ContextBarLeadingButtonWithLabel(
[BookmarkEarlGreyUtils
contextBarDeleteString])]
performAction:grey_tap()];
// Wait until it's gone.
[BookmarkEarlGreyUtils waitForDeletionOfBookmarkWithTitle:@"Second URL"];
[ChromeEarlGrey verifyAccessibilityForCurrentScreen];
}
// Tests that all elements on the bookmarks Select page are accessible.
- (void)testAccessibilityOnBookmarksSelect {
[BookmarkEarlGreyUtils setupStandardBookmarks];
[BookmarkEarlGreyUtils openBookmarks];
[BookmarkEarlGreyUtils openMobileBookmarks];
// Change to edit mode
[[EarlGrey
selectElementWithMatcher:grey_accessibilityID(
kBookmarkHomeTrailingButtonIdentifier)]
performAction:grey_tap()];
[ChromeEarlGrey verifyAccessibilityForCurrentScreen];
}
@end
This source diff could not be displayed because it is too large. You can view the blob instead.
This diff is collapsed.
This diff is collapsed.
// 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 "components/prefs/pref_service.h"
#include "ios/chrome/browser/browser_state/chrome_browser_state.h"
#include "ios/chrome/browser/pref_names.h"
#import "ios/chrome/browser/ui/authentication/signin_earl_grey_ui.h"
#import "ios/chrome/browser/ui/authentication/signin_earlgrey_utils.h"
#import "ios/chrome/browser/ui/bookmarks/bookmark_earl_grey_utils.h"
#import "ios/chrome/browser/ui/bookmarks/bookmark_path_cache.h"
#import "ios/chrome/browser/ui/bookmarks/bookmark_ui_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/chrome/test/earl_grey/chrome_test_case.h"
#import "ios/public/provider/chrome/browser/signin/fake_chrome_identity.h"
#import "ios/public/provider/chrome/browser/signin/fake_chrome_identity_service.h"
#import "ios/testing/earl_grey/earl_grey_test.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::PrimarySignInButton;
using chrome_test_util::SecondarySignInButton;
// Bookmark promo integration tests for Chrome.
@interface BookmarksPromoTestCase : ChromeTestCase
@end
@implementation BookmarksPromoTestCase
- (void)setUp {
[super setUp];
[ChromeEarlGrey waitForBookmarksToFinishLoading];
[ChromeEarlGrey clearBookmarks];
}
// Tear down called once per test.
- (void)tearDown {
[super tearDown];
[ChromeEarlGrey clearBookmarks];
// Clear position cache so that Bookmarks starts at the root folder in next
// test.
ios::ChromeBrowserState* browser_state =
chrome_test_util::GetOriginalBrowserState();
[BookmarkPathCache
clearBookmarkTopMostRowCacheWithPrefService:browser_state->GetPrefs()];
}
#pragma mark - BookmarksPromoTestCase Tests
// Tests that the promo view is only seen at root level and not in any of the
// child nodes.
- (void)testPromoViewIsSeenOnlyInRootNode {
[BookmarkEarlGreyUtils setupStandardBookmarks];
[BookmarkEarlGreyUtils openBookmarks];
// We are going to set the PromoAlreadySeen preference. Set a teardown handler
// to reset it.
[self setTearDownHandler:^{
[BookmarkEarlGreyUtils setPromoAlreadySeen:NO];
}];
// Check that sign-in promo view is visible.
[BookmarkEarlGreyUtils verifyPromoAlreadySeen:NO];
[SigninEarlGreyUI
checkSigninPromoVisibleWithMode:SigninPromoViewModeColdState];
// Go to child node.
[BookmarkEarlGreyUtils openMobileBookmarks];
// Wait until promo is gone.
[SigninEarlGreyUI checkSigninPromoNotVisible];
// Check that the promo already seen state is not updated.
[BookmarkEarlGreyUtils verifyPromoAlreadySeen:NO];
// Come back to root node, and the promo view should appear.
[[EarlGrey selectElementWithMatcher:NavigateBackButtonTo(@"Bookmarks")]
performAction:grey_tap()];
// Check promo view is still visible.
[[EarlGrey selectElementWithMatcher:PrimarySignInButton()]
assertWithMatcher:grey_sufficientlyVisible()];
}
// Tests that tapping No thanks on the promo make it disappear.
- (void)testPromoNoThanksMakeItDisappear {
[BookmarkEarlGreyUtils setupStandardBookmarks];
[BookmarkEarlGreyUtils openBookmarks];
// We are going to set the PromoAlreadySeen preference. Set a teardown handler
// to reset it.
[self setTearDownHandler:^{
[BookmarkEarlGreyUtils setPromoAlreadySeen:NO];
}];
// Check that sign-in promo view is visible.
[BookmarkEarlGreyUtils verifyPromoAlreadySeen:NO];
[SigninEarlGreyUI
checkSigninPromoVisibleWithMode:SigninPromoViewModeColdState];
// Tap the dismiss button.
[[EarlGrey
selectElementWithMatcher:grey_accessibilityID(kSigninPromoCloseButtonId)]
performAction:grey_tap()];
// Wait until promo is gone.
[SigninEarlGreyUI checkSigninPromoNotVisible];
// Check that the promo already seen state is updated.
[BookmarkEarlGreyUtils verifyPromoAlreadySeen:YES];
}
// Tests the tapping on the primary button of sign-in promo view in a cold
// state makes the sign-in sheet appear, and the promo still appears after
// dismissing the sheet.
- (void)testSignInPromoWithColdStateUsingPrimaryButton {
[BookmarkEarlGreyUtils openBookmarks];
// Check that sign-in promo view are visible.
[BookmarkEarlGreyUtils verifyPromoAlreadySeen:NO];
[SigninEarlGreyUI
checkSigninPromoVisibleWithMode:SigninPromoViewModeColdState];
// Tap the primary button.
[[EarlGrey
selectElementWithMatcher:grey_allOf(PrimarySignInButton(),
grey_sufficientlyVisible(), nil)]
performAction:grey_tap()];
// Cancel the sign-in operation.
[[EarlGrey selectElementWithMatcher:
grey_buttonTitle([l10n_util::GetNSString(
IDS_IOS_ACCOUNT_CONSISTENCY_SETUP_SKIP_BUTTON)
uppercaseString])] performAction:grey_tap()];
// Check that the bookmarks UI reappeared and the cell is still here.
[BookmarkEarlGreyUtils verifyPromoAlreadySeen:NO];
[SigninEarlGreyUI
checkSigninPromoVisibleWithMode:SigninPromoViewModeColdState];
}
// Tests the tapping on the primary button of sign-in promo view in a warm
// state makes the confirmaiton sheet appear, and the promo still appears after
// dismissing the sheet.
- (void)testSignInPromoWithWarmStateUsingPrimaryButton {
[BookmarkEarlGreyUtils setupStandardBookmarks];
[BookmarkEarlGreyUtils openBookmarks];
// Set up a fake identity.
FakeChromeIdentity* identity = [SigninEarlGreyUtils fakeIdentity1];
ios::FakeChromeIdentityService::GetInstanceFromChromeProvider()->AddIdentity(
identity);
// Check that promo is visible.
[BookmarkEarlGreyUtils verifyPromoAlreadySeen:NO];
[SigninEarlGreyUI
checkSigninPromoVisibleWithMode:SigninPromoViewModeWarmState];
// Tap the primary button.
[[EarlGrey
selectElementWithMatcher:grey_allOf(PrimarySignInButton(),
grey_sufficientlyVisible(), nil)]
performAction:grey_tap()];
// Cancel the sign-in operation.
[[EarlGrey selectElementWithMatcher:
grey_buttonTitle([l10n_util::GetNSString(
IDS_IOS_ACCOUNT_CONSISTENCY_SETUP_SKIP_BUTTON)
uppercaseString])] performAction:grey_tap()];
// Check that the bookmarks UI reappeared and the cell is still here.
[SigninEarlGreyUI
checkSigninPromoVisibleWithMode:SigninPromoViewModeWarmState];
[BookmarkEarlGreyUtils verifyPromoAlreadySeen:NO];
}
// Tests the tapping on the secondary button of sign-in promo view in a warm
// state makes the sign-in sheet appear, and the promo still appears after
// dismissing the sheet.
- (void)testSignInPromoWithWarmStateUsingSecondaryButton {
[BookmarkEarlGreyUtils setupStandardBookmarks];
[BookmarkEarlGreyUtils openBookmarks];
// Set up a fake identity.
FakeChromeIdentity* identity = [SigninEarlGreyUtils fakeIdentity1];
ios::FakeChromeIdentityService::GetInstanceFromChromeProvider()->AddIdentity(
identity);
// Check that sign-in promo view are visible.
[BookmarkEarlGreyUtils verifyPromoAlreadySeen:NO];
[SigninEarlGreyUI
checkSigninPromoVisibleWithMode:SigninPromoViewModeWarmState];
// Tap the secondary button.
[[EarlGrey
selectElementWithMatcher:grey_allOf(SecondarySignInButton(),
grey_sufficientlyVisible(), nil)]
performAction:grey_tap()];
// Select the identity to dismiss the identity chooser.
[SigninEarlGreyUI selectIdentityWithEmail:identity.userEmail];
// Tap the CANCEL button.
[[EarlGrey selectElementWithMatcher:
grey_buttonTitle([l10n_util::GetNSString(
IDS_IOS_ACCOUNT_CONSISTENCY_SETUP_SKIP_BUTTON)
uppercaseString])] performAction:grey_tap()];
// Check that the bookmarks UI reappeared and the cell is still here.
[BookmarkEarlGreyUtils verifyPromoAlreadySeen:NO];
[SigninEarlGreyUI
checkSigninPromoVisibleWithMode:SigninPromoViewModeWarmState];
}
// Tests that the sign-in promo should not be shown after been shown 19 times.
- (void)testAutomaticSigninPromoDismiss {
ios::ChromeBrowserState* browser_state =
chrome_test_util::GetOriginalBrowserState();
PrefService* prefs = browser_state->GetPrefs();
prefs->SetInteger(prefs::kIosBookmarkSigninPromoDisplayedCount, 19);
[BookmarkEarlGreyUtils openBookmarks];
// Check the sign-in promo view is visible.
[SigninEarlGreyUI
checkSigninPromoVisibleWithMode:SigninPromoViewModeColdState];
// Check the sign-in promo already-seen state didn't change.
[BookmarkEarlGreyUtils verifyPromoAlreadySeen:NO];
GREYAssertEqual(
20, prefs->GetInteger(prefs::kIosBookmarkSigninPromoDisplayedCount),
@"Should have incremented the display count");
// Close the bookmark view and open it again.
[[EarlGrey selectElementWithMatcher:BookmarkHomeDoneButton()]
performAction:grey_tap()];
[BookmarkEarlGreyUtils openBookmarks];
[[GREYUIThreadExecutor sharedInstance] drainUntilIdle];
// Check that the sign-in promo is not visible anymore.
[SigninEarlGreyUI checkSigninPromoNotVisible];
}
@end
This diff is collapsed.
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