Commit 3cf4fda1 authored by Sebastien Lalancette's avatar Sebastien Lalancette Committed by Commit Bot

[iOS] Add Reading List Context Menu EG Tests

Adding EG test coverage for the following context menu actions:
- Open in New Tab
- Open in Incognito
- Mark as Read/Unread
- Copy Link
- Share
- Delete

Bug: 1131831
Change-Id: I204073dfbf06905145363ecb75a4ae4272891073
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2435878
Commit-Queue: Sebastien Lalancette <seblalancette@chromium.org>
Reviewed-by: default avatarSergio Collazos <sczs@chromium.org>
Reviewed-by: default avatarOlivier Robin <olivierrobin@chromium.org>
Cr-Commit-Position: refs/heads/master@{#812460}
parent d59dd4f5
...@@ -43,6 +43,9 @@ ...@@ -43,6 +43,9 @@
#endif #endif
using base::test::ios::kWaitForUIElementTimeout; using base::test::ios::kWaitForUIElementTimeout;
using chrome_test_util::DeleteButton;
using chrome_test_util::ReadingListMarkAsReadButton;
using chrome_test_util::ReadingListMarkAsUnreadButton;
namespace { namespace {
const char kContentToRemove[] = "Text that distillation should remove."; const char kContentToRemove[] = "Text that distillation should remove.";
...@@ -958,20 +961,7 @@ void AssertIsShowingDistillablePage(bool online, const GURL& distillable_url) { ...@@ -958,20 +961,7 @@ void AssertIsShowingDistillablePage(bool online, const GURL& distillable_url) {
TapToolbarButtonWithID(kReadingListToolbarDeleteAllReadButtonID); TapToolbarButtonWithID(kReadingListToolbarDeleteAllReadButtonID);
// Verify the background string is displayed. // Verify the background string is displayed.
if ([ChromeEarlGrey isIllustratedEmptyStatesEnabled]) { [self verifyReadingListIsEmpty];
[[EarlGrey selectElementWithMatcher:grey_accessibilityID(
kTableViewIllustratedEmptyViewID)]
assertWithMatcher:grey_notNil()];
id<GREYMatcher> noReadingListMessageMatcher = grey_allOf(
grey_text(
l10n_util::GetNSString(IDS_IOS_READING_LIST_NO_ENTRIES_MESSAGE)),
grey_sufficientlyVisible(), nil);
[[EarlGrey selectElementWithMatcher:noReadingListMessageMatcher]
assertWithMatcher:grey_notNil()];
} else {
[[EarlGrey selectElementWithMatcher:EmptyBackground()]
assertWithMatcher:grey_notNil()];
}
} }
// Tests that the VC can be dismissed by swiping down. // Tests that the VC can be dismissed by swiping down.
...@@ -1007,4 +997,146 @@ void AssertIsShowingDistillablePage(bool online, const GURL& distillable_url) { ...@@ -1007,4 +997,146 @@ void AssertIsShowingDistillablePage(bool online, const GURL& distillable_url) {
assertWithMatcher:grey_nil()]; assertWithMatcher:grey_nil()];
} }
// Tests the Copy Link context menu action for a reading list entry.
- (void)testContextMenuCopyLink {
AddEntriesAndOpenReadingList();
LongPressEntry(kReadTitle);
// Tap "Copy URL" and wait for the URL to be copied to the pasteboard.
[ChromeEarlGrey
verifyCopyLinkActionWithText:kReadURL
useNewString:[ChromeEarlGrey
isNativeContextMenusEnabled]];
}
// Tests the Open in New Tab context menu action for a reading list entry.
- (void)testContextMenuOpenInNewTab {
GURL distillablePageURL(self.testServer->GetURL(kDistillableURL));
[self addURLToReadingList:distillablePageURL];
LongPressEntry(kDistillableTitle);
// Select "Open in New Tab" and confirm that new tab is opened with selected
// URL.
[ChromeEarlGrey
verifyOpenInNewTabActionWithURL:distillablePageURL.GetContent()];
}
// Tests display and selection of 'Open in New Incognito Tab' in a context menu
// on a history entry.
- (void)testContextMenuOpenInIncognito {
GURL distillablePageURL(self.testServer->GetURL(kDistillableURL));
[self addURLToReadingList:distillablePageURL];
LongPressEntry(kDistillableTitle);
// Select "Open in Incognito" and confirm that new tab is opened with selected
// URL.
[ChromeEarlGrey
verifyOpenInIncognitoActionWithURL:distillablePageURL.GetContent()
useNewString:[ChromeEarlGrey
isNativeContextMenusEnabled]];
}
// Tests the Mark as Read/Unread context menu action for a reading list entry.
- (void)testContextMenuMarkAsReadAndBack {
if (![ChromeEarlGrey isNativeContextMenusEnabled]) {
EARL_GREY_TEST_SKIPPED(
@"Test disabled when Native Context Menus feature flag is off.");
}
AddEntriesAndOpenReadingList();
AssertAllEntriesVisible();
XCTAssertEqual(static_cast<long>(kNumberReadEntries),
[ReadingListAppInterface readEntriesCount]);
XCTAssertEqual(static_cast<long>(kNumberUnreadEntries),
[ReadingListAppInterface unreadEntriesCount]);
// Mark an unread entry as read.
LongPressEntry(kUnreadTitle);
[[EarlGrey selectElementWithMatcher:ReadingListMarkAsReadButton()]
performAction:grey_tap()];
AssertAllEntriesVisible();
XCTAssertEqual(static_cast<long>(kNumberReadEntries + 1),
[ReadingListAppInterface readEntriesCount]);
XCTAssertEqual(static_cast<long>(kNumberUnreadEntries - 1),
[ReadingListAppInterface unreadEntriesCount]);
// Now mark it back as unread.
LongPressEntry(kUnreadTitle);
[[EarlGrey selectElementWithMatcher:ReadingListMarkAsUnreadButton()]
performAction:grey_tap()];
AssertAllEntriesVisible();
XCTAssertEqual(static_cast<long>(kNumberReadEntries),
[ReadingListAppInterface readEntriesCount]);
XCTAssertEqual(static_cast<long>(kNumberUnreadEntries),
[ReadingListAppInterface unreadEntriesCount]);
}
// Tests the Share context menu action for a reading list entry.
- (void)testContextMenuShare {
if (![ChromeEarlGrey isNativeContextMenusEnabled]) {
EARL_GREY_TEST_SKIPPED(
@"Test disabled when Native Context Menus feature flag is off.");
}
GURL distillablePageURL(self.testServer->GetURL(kDistillableURL));
[self addURLToReadingList:distillablePageURL];
LongPressEntry(kDistillableTitle);
[ChromeEarlGrey verifyShareActionWithPageTitle:kDistillableTitle];
}
// Tests the Delete context menu action for a reading list entry.
- (void)testContextMenuDelete {
if (![ChromeEarlGrey isNativeContextMenusEnabled]) {
EARL_GREY_TEST_SKIPPED(
@"Test disabled when Native Context Menus feature flag is off.");
}
GURL distillablePageURL(self.testServer->GetURL(kDistillableURL));
[self addURLToReadingList:distillablePageURL];
LongPressEntry(kDistillableTitle);
[[EarlGrey selectElementWithMatcher:DeleteButton()] performAction:grey_tap()];
[self verifyReadingListIsEmpty];
}
#pragma mark - Helper Methods
- (void)verifyReadingListIsEmpty {
if ([ChromeEarlGrey isIllustratedEmptyStatesEnabled]) {
[[EarlGrey selectElementWithMatcher:grey_accessibilityID(
kTableViewIllustratedEmptyViewID)]
assertWithMatcher:grey_notNil()];
id<GREYMatcher> emptyReadingListMatcher = grey_allOf(
grey_text(
l10n_util::GetNSString(IDS_IOS_READING_LIST_NO_ENTRIES_MESSAGE)),
grey_sufficientlyVisible(), nil);
[[EarlGrey selectElementWithMatcher:emptyReadingListMatcher]
assertWithMatcher:grey_notNil()];
} else {
[[EarlGrey selectElementWithMatcher:EmptyBackground()]
assertWithMatcher:grey_notNil()];
}
}
- (void)addURLToReadingList:(const GURL&)URL {
[ReadingListAppInterface forceConnectionToWifi];
// Open http://potato
[ChromeEarlGrey loadURL:URL];
[ChromeEarlGrey waitForPageToFinishLoading];
AddCurrentPageToReadingList();
[ChromeEarlGrey closeCurrentTab];
[ChromeEarlGrey openNewTab];
OpenReadingList();
}
@end @end
...@@ -330,6 +330,12 @@ id<GREYMatcher> EditButton(BOOL use_new_string); ...@@ -330,6 +330,12 @@ id<GREYMatcher> EditButton(BOOL use_new_string);
// Matcher for the Move option on the updated context menus. // Matcher for the Move option on the updated context menus.
id<GREYMatcher> MoveButton(); id<GREYMatcher> MoveButton();
// Matcher for the Mark as Read option on the Reading List's context menus.
id<GREYMatcher> ReadingListMarkAsReadButton();
// Matcher for the Mark as Unread option on the Reading List's context menus.
id<GREYMatcher> ReadingListMarkAsUnreadButton();
// Matcher for the Delete option on the updated context menus. // Matcher for the Delete option on the updated context menus.
id<GREYMatcher> DeleteButton(); id<GREYMatcher> DeleteButton();
......
...@@ -412,6 +412,14 @@ id<GREYMatcher> MoveButton() { ...@@ -412,6 +412,14 @@ id<GREYMatcher> MoveButton() {
return [ChromeMatchersAppInterface moveButton]; return [ChromeMatchersAppInterface moveButton];
} }
id<GREYMatcher> ReadingListMarkAsReadButton() {
return [ChromeMatchersAppInterface readingListMarkAsReadButton];
}
id<GREYMatcher> ReadingListMarkAsUnreadButton() {
return [ChromeMatchersAppInterface readingListMarkAsUnreadButton];
}
id<GREYMatcher> DeleteButton() { id<GREYMatcher> DeleteButton() {
return [ChromeMatchersAppInterface deleteButton]; return [ChromeMatchersAppInterface deleteButton];
} }
......
...@@ -335,6 +335,12 @@ ...@@ -335,6 +335,12 @@
// Matcher for the Move option on the updated context menus. // Matcher for the Move option on the updated context menus.
+ (id<GREYMatcher>)moveButton; + (id<GREYMatcher>)moveButton;
// Matcher for the Mark as Read option on the Reading List's context menus.
+ (id<GREYMatcher>)readingListMarkAsReadButton;
// Matcher for the Mark as Unread option on the Reading List's context menus.
+ (id<GREYMatcher>)readingListMarkAsUnreadButton;
// Matcher for the Share option on the updated context menus. // Matcher for the Share option on the updated context menus.
+ (id<GREYMatcher>)deleteButton; + (id<GREYMatcher>)deleteButton;
......
...@@ -704,6 +704,17 @@ UIView* SubviewWithAccessibilityIdentifier(NSString* accessibility_id, ...@@ -704,6 +704,17 @@ UIView* SubviewWithAccessibilityIdentifier(NSString* accessibility_id,
buttonWithAccessibilityLabelID:IDS_IOS_BOOKMARK_CONTEXT_MENU_MOVE]; buttonWithAccessibilityLabelID:IDS_IOS_BOOKMARK_CONTEXT_MENU_MOVE];
} }
+ (id<GREYMatcher>)readingListMarkAsReadButton {
return [ChromeMatchersAppInterface
buttonWithAccessibilityLabelID:IDS_IOS_READING_LIST_MARK_AS_READ_ACTION];
}
+ (id<GREYMatcher>)readingListMarkAsUnreadButton {
return [ChromeMatchersAppInterface
buttonWithAccessibilityLabelID:
IDS_IOS_READING_LIST_MARK_AS_UNREAD_ACTION];
}
+ (id<GREYMatcher>)deleteButton { + (id<GREYMatcher>)deleteButton {
return [ChromeMatchersAppInterface return [ChromeMatchersAppInterface
buttonWithAccessibilityLabelID:IDS_IOS_DELETE_ACTION_TITLE]; buttonWithAccessibilityLabelID:IDS_IOS_DELETE_ACTION_TITLE];
......
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