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() { ...@@ -51,6 +51,23 @@ id<GREYMatcher> PrintButton() {
return chrome_test_util::ButtonWithAccessibilityLabel(@"Print"); 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 } // namespace
// Earl grey integration tests for Activity Service Controller. // Earl grey integration tests for Activity Service Controller.
...@@ -90,7 +107,9 @@ id<GREYMatcher> PrintButton() { ...@@ -90,7 +107,9 @@ id<GREYMatcher> PrintButton() {
[ChromeEarlGrey waitForErrorPage]; [ChromeEarlGrey waitForErrorPage];
// Execute the Print action. // 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. // Verify that a toast notification appears.
[[EarlGrey selectElementWithMatcher:grey_accessibilityLabel( [[EarlGrey selectElementWithMatcher:grey_accessibilityLabel(
...@@ -118,8 +137,20 @@ id<GREYMatcher> PrintButton() { ...@@ -118,8 +137,20 @@ id<GREYMatcher> PrintButton() {
// Verify that you can share, but that the Print action is not available. // Verify that you can share, but that the Print action is not available.
[ChromeEarlGreyUI openShareMenu]; [ChromeEarlGreyUI openShareMenu];
AssertActivityServiceVisible(); 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 { - (void)testActivityServiceControllerIsDisabled {
...@@ -160,15 +191,13 @@ id<GREYMatcher> PrintButton() { ...@@ -160,15 +191,13 @@ id<GREYMatcher> PrintButton() {
[ChromeEarlGrey loadURL:url]; [ChromeEarlGrey loadURL:url];
[ChromeEarlGreyUI openShareMenu]; [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(); AssertActivityServiceVisible();
[[EarlGrey selectElementWithMatcher:PrintButton()] [[EarlGrey selectElementWithMatcher:CopyButton()]
assertWithMatcher:grey_interactable()]; assertWithMatcher:grey_interactable()];
// Start the Copy action and verify that the share menu gets dismissed. // Start the Copy action and verify that the share menu gets dismissed.
[[EarlGrey [[EarlGrey selectElementWithMatcher:CopyButton()] performAction:grey_tap()];
selectElementWithMatcher:chrome_test_util::ButtonWithAccessibilityLabel(
@"Copy")] performAction:grey_tap()];
AssertActivityServiceNotVisible(); AssertActivityServiceNotVisible();
} }
......
...@@ -165,7 +165,7 @@ const int kMaxFetchCount = 100; ...@@ -165,7 +165,7 @@ const int kMaxFetchCount = 100;
self.searchController.searchResultsUpdater = self; self.searchController.searchResultsUpdater = self;
self.searchController.searchBar.backgroundColor = [UIColor whiteColor]; self.searchController.searchBar.backgroundColor = [UIColor whiteColor];
self.searchController.searchBar.accessibilityIdentifier = self.searchController.searchBar.accessibilityIdentifier =
l10n_util::GetNSStringWithFixup(IDS_IOS_ICON_SEARCH); kHistorySearchControllerSearchBarIdentifier;
// UIKit needs to know which controller will be presenting the // UIKit needs to know which controller will be presenting the
// searchController. If we don't add this trying to dismiss while // searchController. If we don't add this trying to dismiss while
// SearchController is active will fail. // SearchController is active will fail.
......
...@@ -7,6 +7,8 @@ ...@@ -7,6 +7,8 @@
#import <Foundation/Foundation.h> #import <Foundation/Foundation.h>
// Accessibility identifier of the search controller search bar.
extern NSString* const kHistorySearchControllerSearchBarIdentifier;
// Accessibility identifier of the navigation controller done button. // Accessibility identifier of the navigation controller done button.
extern NSString* const kHistoryNavigationControllerDoneButtonIdentifier; extern NSString* const kHistoryNavigationControllerDoneButtonIdentifier;
// Accessibility identifier of the delete toolbar button. // Accessibility identifier of the delete toolbar button.
......
...@@ -8,6 +8,8 @@ ...@@ -8,6 +8,8 @@
#error "This file requires ARC support." #error "This file requires ARC support."
#endif #endif
NSString* const kHistorySearchControllerSearchBarIdentifier =
@"kHistorySearchControllerSearchBarIdentifier";
NSString* const kHistoryNavigationControllerDoneButtonIdentifier = NSString* const kHistoryNavigationControllerDoneButtonIdentifier =
@"kHistoryNavigationControllerDoneButtonIdentifier"; @"kHistoryNavigationControllerDoneButtonIdentifier";
NSString* const kHistoryToolbarDeleteButtonIdentifier = NSString* const kHistoryToolbarDeleteButtonIdentifier =
......
...@@ -120,8 +120,7 @@ id<GREYMatcher> DeleteHistoryEntriesButton() { ...@@ -120,8 +120,7 @@ id<GREYMatcher> DeleteHistoryEntriesButton() {
// Matcher for the search button. // Matcher for the search button.
id<GREYMatcher> SearchIconButton() { id<GREYMatcher> SearchIconButton() {
if (IsUIRefreshPhase1Enabled()) { if (IsUIRefreshPhase1Enabled()) {
return grey_accessibilityID( return grey_accessibilityID(kHistorySearchControllerSearchBarIdentifier);
l10n_util::GetNSStringWithFixup(IDS_IOS_ICON_SEARCH));
} else { } else {
return ButtonWithAccessibilityLabelId(IDS_IOS_ICON_SEARCH); return ButtonWithAccessibilityLabelId(IDS_IOS_ICON_SEARCH);
} }
...@@ -271,8 +270,13 @@ id<GREYMatcher> ConfirmClearBrowsingDataButton() { ...@@ -271,8 +270,13 @@ id<GREYMatcher> ConfirmClearBrowsingDataButton() {
NSString* searchString = NSString* searchString =
[NSString stringWithFormat:@"%s", _URL1.path().c_str()]; [NSString stringWithFormat:@"%s", _URL1.path().c_str()];
[[EarlGrey selectElementWithMatcher:grey_keyWindow()] if (IsUIRefreshPhase1Enabled()) {
performAction:grey_typeText(searchString)]; [[EarlGrey selectElementWithMatcher:SearchIconButton()]
performAction:grey_typeText(searchString)];
} else {
[[EarlGrey selectElementWithMatcher:grey_keyWindow()]
performAction:grey_typeText(searchString)];
}
[[EarlGrey selectElementWithMatcher:HistoryEntry(_URL1, kTitle1)] [[EarlGrey selectElementWithMatcher:HistoryEntry(_URL1, kTitle1)]
assertWithMatcher:grey_notNil()]; assertWithMatcher:grey_notNil()];
[[EarlGrey selectElementWithMatcher:HistoryEntry(_URL2, kTitle2)] [[EarlGrey selectElementWithMatcher:HistoryEntry(_URL2, kTitle2)]
......
...@@ -31,6 +31,21 @@ const char kPDFURL[] = "http://ios/testing/data/http_server_files/testpage.pdf"; ...@@ -31,6 +31,21 @@ const char kPDFURL[] = "http://ios/testing/data/http_server_files/testpage.pdf";
// A test HTML URL. // A test HTML URL.
const char kHTMLURL[] = "http://test"; 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 } // namespace
// Print test cases. These are Earl Grey integration tests. // Print test cases. These are Earl Grey integration tests.
...@@ -92,9 +107,11 @@ const char kHTMLURL[] = "http://test"; ...@@ -92,9 +107,11 @@ const char kHTMLURL[] = "http://test";
} else { } else {
[ChromeEarlGreyUI openShareMenu]; [ChromeEarlGreyUI openShareMenu];
id<GREYMatcher> printButton = id<GREYMatcher> printButton =
grey_allOf(grey_accessibilityLabel(@"Print"), chrome_test_util::ButtonWithAccessibilityLabel(@"Print");
grey_accessibilityTrait(UIAccessibilityTraitButton), nil); [[[EarlGrey selectElementWithMatcher:printButton]
[[EarlGrey selectElementWithMatcher:printButton] performAction:grey_tap()]; usingSearchAction:grey_scrollInDirection(kGREYDirectionRight, 100)
onElementWithMatcher:ShareMenuCollectionView()]
performAction:grey_tap()];
} }
id<GREYMatcher> printerOptionButton = grey_allOf( 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