Commit 20b05097 authored by Rohit Rao's avatar Rohit Rao Committed by Commit Bot

[ios] Fixes ui_egtests to scroll the share menu if needed.

When the UIRefresh flag is enabled, additional actions are added to the
share menu.  These actions end up pushing the Print action off of the
first screenful of items, so tests must be updated to scroll the
collection view if needed.

Also converts a History egtest to use a constant for an a11y identifier
and to avoid inadvertently dismissing the history ui.

BUG=825431

Cq-Include-Trybots: luci.chromium.try:ios-simulator-full-configs;master.tryserver.chromium.mac:ios-simulator-cronet
Change-Id: I1efebb04d1de54dcef7c2c7d3374eff2c61c9838
Reviewed-on: https://chromium-review.googlesource.com/1083723Reviewed-by: default avatarJustin Cohen <justincohen@chromium.org>
Commit-Queue: Rohit Rao <rohitrao@chromium.org>
Cr-Commit-Position: refs/heads/master@{#563978}
parent 0ea7f3c0
......@@ -51,6 +51,23 @@ id<GREYMatcher> PrintButton() {
return chrome_test_util::ButtonWithAccessibilityLabel(@"Print");
}
// Returns a button with a copy label.
id<GREYMatcher> CopyButton() {
return chrome_test_util::ButtonWithAccessibilityLabel(@"Copy");
}
// Returns the collection view for the activity services menu. Since this is a
// system widget, it does not have an a11y id. Instead, search for a
// UICollectionView that is the superview of the "Copy" menu item. There are
// two nested UICollectionViews in the activity services menu, so choose the
// innermost one.
id<GREYMatcher> ShareMenuCollectionView() {
return grey_allOf(
grey_kindOfClass([UICollectionView class]), grey_descendant(CopyButton()),
// Looking for a nested UICollectionView.
grey_descendant(grey_kindOfClass([UICollectionView class])), nil);
}
} // namespace
// Earl grey integration tests for Activity Service Controller.
......@@ -90,7 +107,9 @@ id<GREYMatcher> PrintButton() {
[ChromeEarlGrey waitForErrorPage];
// Execute the Print action.
[[EarlGrey selectElementWithMatcher:PrintButton()] performAction:grey_tap()];
[[[EarlGrey selectElementWithMatcher:PrintButton()]
usingSearchAction:grey_scrollInDirection(kGREYDirectionRight, 100)
onElementWithMatcher:ShareMenuCollectionView()] performAction:grey_tap()];
// Verify that a toast notification appears.
[[EarlGrey selectElementWithMatcher:grey_accessibilityLabel(
......@@ -118,8 +137,20 @@ id<GREYMatcher> PrintButton() {
// Verify that you can share, but that the Print action is not available.
[ChromeEarlGreyUI openShareMenu];
AssertActivityServiceVisible();
[[EarlGrey selectElementWithMatcher:PrintButton()]
assertWithMatcher:grey_nil()];
// To verify that the Print action is missing, scroll through the entire
// collection view using grey_scrollInDirection(), then make sure the
// operation failed with kGREYInteractionElementNotFoundErrorCode.
NSError* error;
[[[EarlGrey selectElementWithMatcher:PrintButton()]
usingSearchAction:grey_scrollInDirection(kGREYDirectionRight, 100)
onElementWithMatcher:ShareMenuCollectionView()]
assertWithMatcher:grey_notNil()
error:&error];
GREYAssert([error.domain isEqual:kGREYInteractionErrorDomain] &&
error.code == kGREYInteractionElementNotFoundErrorCode,
@"Print action was unexpectedly present");
}
- (void)testActivityServiceControllerIsDisabled {
......@@ -160,15 +191,13 @@ id<GREYMatcher> PrintButton() {
[ChromeEarlGrey loadURL:url];
[ChromeEarlGreyUI openShareMenu];
// Verify that the share menu is up and contains a Print action.
// Verify that the share menu is up and contains a Copy action.
AssertActivityServiceVisible();
[[EarlGrey selectElementWithMatcher:PrintButton()]
[[EarlGrey selectElementWithMatcher:CopyButton()]
assertWithMatcher:grey_interactable()];
// Start the Copy action and verify that the share menu gets dismissed.
[[EarlGrey
selectElementWithMatcher:chrome_test_util::ButtonWithAccessibilityLabel(
@"Copy")] performAction:grey_tap()];
[[EarlGrey selectElementWithMatcher:CopyButton()] performAction:grey_tap()];
AssertActivityServiceNotVisible();
}
......
......@@ -165,7 +165,7 @@ const int kMaxFetchCount = 100;
self.searchController.searchResultsUpdater = self;
self.searchController.searchBar.backgroundColor = [UIColor whiteColor];
self.searchController.searchBar.accessibilityIdentifier =
l10n_util::GetNSStringWithFixup(IDS_IOS_ICON_SEARCH);
kHistorySearchControllerSearchBarIdentifier;
// UIKit needs to know which controller will be presenting the
// searchController. If we don't add this trying to dismiss while
// SearchController is active will fail.
......
......@@ -7,6 +7,8 @@
#import <Foundation/Foundation.h>
// Accessibility identifier of the search controller search bar.
extern NSString* const kHistorySearchControllerSearchBarIdentifier;
// Accessibility identifier of the navigation controller done button.
extern NSString* const kHistoryNavigationControllerDoneButtonIdentifier;
// Accessibility identifier of the delete toolbar button.
......
......@@ -8,6 +8,8 @@
#error "This file requires ARC support."
#endif
NSString* const kHistorySearchControllerSearchBarIdentifier =
@"kHistorySearchControllerSearchBarIdentifier";
NSString* const kHistoryNavigationControllerDoneButtonIdentifier =
@"kHistoryNavigationControllerDoneButtonIdentifier";
NSString* const kHistoryToolbarDeleteButtonIdentifier =
......
......@@ -120,8 +120,7 @@ id<GREYMatcher> DeleteHistoryEntriesButton() {
// Matcher for the search button.
id<GREYMatcher> SearchIconButton() {
if (IsUIRefreshPhase1Enabled()) {
return grey_accessibilityID(
l10n_util::GetNSStringWithFixup(IDS_IOS_ICON_SEARCH));
return grey_accessibilityID(kHistorySearchControllerSearchBarIdentifier);
} else {
return ButtonWithAccessibilityLabelId(IDS_IOS_ICON_SEARCH);
}
......@@ -271,8 +270,13 @@ id<GREYMatcher> ConfirmClearBrowsingDataButton() {
NSString* searchString =
[NSString stringWithFormat:@"%s", _URL1.path().c_str()];
[[EarlGrey selectElementWithMatcher:grey_keyWindow()]
performAction:grey_typeText(searchString)];
if (IsUIRefreshPhase1Enabled()) {
[[EarlGrey selectElementWithMatcher:SearchIconButton()]
performAction:grey_typeText(searchString)];
} else {
[[EarlGrey selectElementWithMatcher:grey_keyWindow()]
performAction:grey_typeText(searchString)];
}
[[EarlGrey selectElementWithMatcher:HistoryEntry(_URL1, kTitle1)]
assertWithMatcher:grey_notNil()];
[[EarlGrey selectElementWithMatcher:HistoryEntry(_URL2, kTitle2)]
......
......@@ -31,6 +31,21 @@ const char kPDFURL[] = "http://ios/testing/data/http_server_files/testpage.pdf";
// A test HTML URL.
const char kHTMLURL[] = "http://test";
// Returns the collection view for the activity services menu. Since this is a
// system widget, it does not have an a11y id. Instead, search for a
// UICollectionView that is the superview of the "Copy" menu item. There are
// two nested UICollectionViews in the activity services menu, so choose the
// innermost one.
id<GREYMatcher> ShareMenuCollectionView() {
id<GREYMatcher> copyButton =
chrome_test_util::ButtonWithAccessibilityLabel(@"Copy");
return grey_allOf(
grey_kindOfClass([UICollectionView class]), grey_descendant(copyButton),
// Looking for a nested UICollectionView.
grey_descendant(grey_kindOfClass([UICollectionView class])), nil);
}
} // namespace
// Print test cases. These are Earl Grey integration tests.
......@@ -92,9 +107,11 @@ const char kHTMLURL[] = "http://test";
} else {
[ChromeEarlGreyUI openShareMenu];
id<GREYMatcher> printButton =
grey_allOf(grey_accessibilityLabel(@"Print"),
grey_accessibilityTrait(UIAccessibilityTraitButton), nil);
[[EarlGrey selectElementWithMatcher:printButton] performAction:grey_tap()];
chrome_test_util::ButtonWithAccessibilityLabel(@"Print");
[[[EarlGrey selectElementWithMatcher:printButton]
usingSearchAction:grey_scrollInDirection(kGREYDirectionRight, 100)
onElementWithMatcher:ShareMenuCollectionView()]
performAction:grey_tap()];
}
id<GREYMatcher> printerOptionButton = grey_allOf(
......
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