Commit caad310e authored by Sebastien Lalancette's avatar Sebastien Lalancette Committed by Commit Bot

[iOS] Add History Context Menu EG Tests

- Fixed the Copy Link test that wouldn't pass on devices.
- Reused helper function for Open In New Tab and Incognito actions.
- Added test coverage the new context menu actions:
  - Share
  - Delete

Bug: 1131831,1067812
Change-Id: Ic5b6e4487aea4bd7c972f5ca8caf6632e4c6dbd8
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2435329Reviewed-by: default avatarGauthier Ambard <gambard@chromium.org>
Reviewed-by: default avatarSergio Collazos <sczs@chromium.org>
Commit-Queue: Sebastien Lalancette <seblalancette@chromium.org>
Cr-Commit-Position: refs/heads/master@{#811680}
parent 0ab4099c
......@@ -33,12 +33,10 @@
#endif
using chrome_test_util::ButtonWithAccessibilityLabelId;
using chrome_test_util::CopyLinkButton;
using chrome_test_util::HistoryEntry;
using chrome_test_util::NavigationBarDoneButton;
using chrome_test_util::OpenLinkInNewTabButton;
using chrome_test_util::OpenLinkInIncognitoButton;
using chrome_test_util::OpenLinkInNewWindowButton;
using chrome_test_util::DeleteButton;
namespace {
char kURL1[] = "/firstURL";
......@@ -392,12 +390,7 @@ std::unique_ptr<net::test_server::HttpResponse> StandardResponse(
// Select "Open in New Tab" and confirm that new tab is opened with selected
// URL.
[[EarlGrey selectElementWithMatcher:OpenLinkInNewTabButton()]
performAction:grey_tap()];
[[EarlGrey selectElementWithMatcher:chrome_test_util::OmniboxText(
_URL1.GetContent())]
assertWithMatcher:grey_notNil()];
[ChromeEarlGrey waitForMainTabCount:2];
[ChromeEarlGrey verifyOpenInNewTabActionWithURL:_URL1.GetContent()];
}
// Tests display and selection of 'Open in New Window' in a context menu on a
......@@ -444,31 +437,15 @@ std::unique_ptr<net::test_server::HttpResponse> StandardResponse(
// Select "Open in New Incognito Tab" and confirm that new tab is opened in
// incognito with the selected URL.
[[EarlGrey selectElementWithMatcher:OpenLinkInIncognitoButton([ChromeEarlGrey
isNativeContextMenusEnabled])]
performAction:grey_tap()];
[[EarlGrey selectElementWithMatcher:chrome_test_util::OmniboxText(
_URL1.GetContent())]
assertWithMatcher:grey_notNil()];
[ChromeEarlGrey waitForMainTabCount:1];
[ChromeEarlGrey waitForIncognitoTabCount:1];
[ChromeEarlGrey
verifyOpenInIncognitoActionWithURL:_URL1.GetContent()
useNewString:[ChromeEarlGrey
isNativeContextMenusEnabled]];
}
// Tests display and selection of 'Copy URL' in a context menu on a history
// entry.
// TODO(crbug.com/1067812): Test won't pass on devices.
#if TARGET_IPHONE_SIMULATOR
#define MAYBE_testContextMenuCopy testContextMenuCopy
#else
#define MAYBE_testContextMenuCopy DISABLED_testContextMenuCopy
#endif
- (void)MAYBE_testContextMenuCopy {
ProceduralBlock clearPasteboard = ^{
[[UIPasteboard generalPasteboard] setURLs:nil];
};
[self setTearDownHandler:clearPasteboard];
clearPasteboard();
- (void)testContextMenuCopy {
[self loadTestURLs];
[self openHistoryPanel];
......@@ -478,16 +455,66 @@ std::unique_ptr<net::test_server::HttpResponse> StandardResponse(
performAction:grey_longPress()];
// Tap "Copy URL" and wait for the URL to be copied to the pasteboard.
[[EarlGrey selectElementWithMatcher:CopyLinkButton([ChromeEarlGrey
isNativeContextMenusEnabled])]
performAction:grey_tap()];
bool success = base::test::ios::WaitUntilConditionOrTimeout(
base::test::ios::kWaitForUIElementTimeout, ^{
return _URL1 ==
net::GURLWithNSURL([UIPasteboard generalPasteboard].URL);
});
GREYAssertTrue(success, @"Pasteboard URL was not set to %s",
_URL1.spec().c_str());
[ChromeEarlGrey
verifyCopyLinkActionWithText:[NSString stringWithUTF8String:_URL1.spec()
.c_str()]
useNewString:[ChromeEarlGrey
isNativeContextMenusEnabled]];
}
// Tests display and selection of "Share" in the context menu for a history
// entry.
- (void)testContextMenuShare {
if (![ChromeEarlGrey isNativeContextMenusEnabled]) {
EARL_GREY_TEST_SKIPPED(
@"Test disabled when Native Context Menus feature flag is off.");
}
[self loadTestURLs];
[self openHistoryPanel];
// Long press on the history element.
[[EarlGrey
selectElementWithMatcher:HistoryEntry(_URL1.GetOrigin().spec(), kTitle1)]
performAction:grey_longPress()];
[ChromeEarlGrey
verifyShareActionWithPageTitle:[NSString stringWithUTF8String:kTitle1]];
}
// Tests the Delete context menu action for a History entry.
- (void)testContextMenuDelete {
if (![ChromeEarlGrey isNativeContextMenusEnabled]) {
EARL_GREY_TEST_SKIPPED(
@"Test disabled when Native Context Menus feature flag is off.");
}
[self loadTestURLs];
[self openHistoryPanel];
// Long press on the history element.
[[EarlGrey
selectElementWithMatcher:HistoryEntry(_URL1.GetOrigin().spec(), kTitle1)]
performAction:grey_longPress()];
[[EarlGrey selectElementWithMatcher:DeleteButton()] performAction:grey_tap()];
// Assert that the deleted entry is gone and the other two remain.
[[EarlGrey
selectElementWithMatcher:HistoryEntry(_URL1.GetOrigin().spec(), kTitle1)]
assertWithMatcher:grey_nil()];
// Wait for the animations to be done, then validate.
[ChromeEarlGrey
waitForSufficientlyVisibleElementWithMatcher:HistoryEntry(
_URL2.GetOrigin().spec(),
kTitle2)];
[[EarlGrey
selectElementWithMatcher:HistoryEntry(_URL2.GetOrigin().spec(), kTitle2)]
assertWithMatcher:grey_notNil()];
[[EarlGrey selectElementWithMatcher:HistoryEntry(_URL3.GetOrigin().spec(),
_URL3.GetContent())]
assertWithMatcher:grey_notNil()];
}
// Tests that the VC can be dismissed by swiping down.
......
......@@ -321,7 +321,8 @@ GURL TestPageURL() {
// Tests the Copy Link action on a recent tab's context menu.
- (void)testContextMenuCopyLink {
if (![ChromeEarlGrey isNativeContextMenusEnabled]) {
EARL_GREY_TEST_SKIPPED(@"Test disabled on when feature flag is off.");
EARL_GREY_TEST_SKIPPED(
@"Test disabled when Native Context Menus feature flag is off.");
}
[self loadTestURL];
......@@ -338,7 +339,8 @@ GURL TestPageURL() {
// Tests the Open in New Tab action on a recent tab's context menu.
- (void)testContextMenuOpenInNewTab {
if (![ChromeEarlGrey isNativeContextMenusEnabled]) {
EARL_GREY_TEST_SKIPPED(@"Test disabled on when feature flag is off.");
EARL_GREY_TEST_SKIPPED(
@"Test disabled when Native Context Menus feature flag is off.");
}
[self loadTestURL];
......@@ -355,7 +357,8 @@ GURL TestPageURL() {
// Tests the Share action on a recent tab's context menu.
- (void)testContextMenuShare {
if (![ChromeEarlGrey isNativeContextMenusEnabled]) {
EARL_GREY_TEST_SKIPPED(@"Test disabled on when feature flag is off.");
EARL_GREY_TEST_SKIPPED(
@"Test disabled when Native Context Menus feature flag is off.");
}
[self loadTestURL];
......
......@@ -160,7 +160,8 @@ char kResponse3[] = "Test Page 3 content";
// Tests the Copy Link action on a recent tab's context menu.
- (void)testRecentTabsContextMenuCopyLink {
if (![ChromeEarlGrey isNativeContextMenusEnabled]) {
EARL_GREY_TEST_SKIPPED(@"Test disabled on when feature flag is off.");
EARL_GREY_TEST_SKIPPED(
@"Test disabled when Native Context Menus feature flag is off.");
}
[self prepareRecentTabWithURL:_URL1 response:kResponse1];
......@@ -175,7 +176,8 @@ char kResponse3[] = "Test Page 3 content";
// Tests the Open in New Tab action on a recent tab's context menu.
- (void)testRecentTabsContextMenuOpenInNewTab {
if (![ChromeEarlGrey isNativeContextMenusEnabled]) {
EARL_GREY_TEST_SKIPPED(@"Test disabled on when feature flag is off.");
EARL_GREY_TEST_SKIPPED(
@"Test disabled when Native Context Menus feature flag is off.");
}
[self prepareRecentTabWithURL:_URL1 response:kResponse1];
......@@ -191,7 +193,8 @@ char kResponse3[] = "Test Page 3 content";
// Tests the Share action on a recent tab's context menu.
- (void)testRecentTabsContextMenuShare {
if (![ChromeEarlGrey isNativeContextMenusEnabled]) {
EARL_GREY_TEST_SKIPPED(@"Test disabled on when feature flag is off.");
EARL_GREY_TEST_SKIPPED(
@"Test disabled when Native Context Menus feature flag is off.");
}
[self prepareRecentTabWithURL:_URL1 response:kResponse1];
......
......@@ -582,6 +582,12 @@ id ExecuteJavaScript(NSString* javascript, NSError* __autoreleasing* out_error);
// present in the omnibox.
- (void)verifyOpenInNewTabActionWithURL:(const std::string&)URL;
// Taps on the Open in Incognito context menu action and waits for the |URL| to
// be present in the omnibox. |useNewString| determines which action string
// to use.
- (void)verifyOpenInIncognitoActionWithURL:(const std::string&)URL
useNewString:(BOOL)useNewString;
// Taps on the Share context menu action and validates that the ActivityView
// was brought up with |pageTitle| in its header.
- (void)verifyShareActionWithPageTitle:(NSString*)pageTitle;
......
......@@ -41,6 +41,7 @@ using base::test::ios::WaitUntilConditionOrTimeout;
using chrome_test_util::ActivityViewHeader;
using chrome_test_util::CopyLinkButton;
using chrome_test_util::OpenLinkInNewTabButton;
using chrome_test_util::OpenLinkInIncognitoButton;
using chrome_test_util::ShareButton;
namespace {
......@@ -1058,6 +1059,7 @@ GREY_STUB_CLASS_IN_APP_MAIN_QUEUE(ChromeEarlGreyAppInterface)
- (void)verifyCopyLinkActionWithText:(NSString*)text
useNewString:(BOOL)useNewString {
[ChromeEarlGreyAppInterface clearPasteboardURLs];
[[EarlGrey selectElementWithMatcher:CopyLinkButton(useNewString)]
performAction:grey_tap()];
[self verifyStringCopied:text];
......@@ -1065,12 +1067,31 @@ GREY_STUB_CLASS_IN_APP_MAIN_QUEUE(ChromeEarlGreyAppInterface)
- (void)verifyOpenInNewTabActionWithURL:(const std::string&)URL {
// Check tab count prior to execution.
NSUInteger oldTabCount = [ChromeEarlGreyAppInterface mainTabCount];
NSUInteger oldRegularTabCount = [ChromeEarlGreyAppInterface mainTabCount];
NSUInteger oldIncognitoTabCount =
[ChromeEarlGreyAppInterface incognitoTabCount];
[[EarlGrey selectElementWithMatcher:OpenLinkInNewTabButton()]
performAction:grey_tap()];
[self waitForMainTabCount:oldTabCount + 1];
[self waitForMainTabCount:oldRegularTabCount + 1];
[self waitForIncognitoTabCount:oldIncognitoTabCount];
[[EarlGrey selectElementWithMatcher:chrome_test_util::OmniboxText(URL)]
assertWithMatcher:grey_notNil()];
}
- (void)verifyOpenInIncognitoActionWithURL:(const std::string&)URL
useNewString:(BOOL)useNewString {
// Check tab count prior to execution.
NSUInteger oldRegularTabCount = [ChromeEarlGreyAppInterface mainTabCount];
NSUInteger oldIncognitoTabCount =
[ChromeEarlGreyAppInterface incognitoTabCount];
[[EarlGrey selectElementWithMatcher:OpenLinkInIncognitoButton(useNewString)]
performAction:grey_tap()];
[self waitForIncognitoTabCount:oldIncognitoTabCount + 1];
[self waitForMainTabCount:oldRegularTabCount];
[[EarlGrey selectElementWithMatcher:chrome_test_util::OmniboxText(URL)]
assertWithMatcher:grey_notNil()];
}
......
......@@ -482,6 +482,9 @@
#pragma mark - Pasteboard utilities
// Clears the URLs stored in the pasteboard, from the tested app's perspective.
+ (void)clearPasteboardURLs;
// Retrieves the currently stored string on the pasteboard from the tested app's
// perspective.
+ (NSString*)pasteboardString;
......
......@@ -840,6 +840,10 @@ NSString* SerializedPref(const PrefService::Preference* pref) {
#pragma mark - Pasteboard utilities
+ (void)clearPasteboardURLs {
[[UIPasteboard generalPasteboard] setURLs:nil];
}
+ (NSString*)pasteboardString {
return [UIPasteboard generalPasteboard].string;
}
......
......@@ -330,7 +330,7 @@ id<GREYMatcher> EditButton(BOOL use_new_string);
// Matcher for the Move option on the updated context menus.
id<GREYMatcher> MoveButton();
// Matcher for the Share option on the updated context menus.
// Matcher for the Delete option on the updated context menus.
id<GREYMatcher> DeleteButton();
// Returns matcher for the Copy item on the old-style context menu.
......
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