Commit f153d7a5 authored by Olivier Robin's avatar Olivier Robin Committed by Commit Bot

Fix Reading List EG tests in landscape mode.

In landscape, some entries are not visible and tests fail.
Allow to scroll to find them.

Bug: 791945
Cq-Include-Trybots: master.tryserver.chromium.mac:ios-simulator-cronet;master.tryserver.chromium.mac:ios-simulator-full-configs
Change-Id: I6119ff89528a67a42501988ccd4db19e457d8fe7
Reviewed-on: https://chromium-review.googlesource.com/808785
Commit-Queue: Olivier Robin <olivierrobin@chromium.org>
Reviewed-by: default avatarGauthier Ambard <gambard@chromium.org>
Cr-Commit-Position: refs/heads/master@{#521710}
parent cfa89ca5
...@@ -81,6 +81,8 @@ readingListCollectionViewController: ...@@ -81,6 +81,8 @@ readingListCollectionViewController:
// Reloads all the data. // Reloads all the data.
- (void)reloadData; - (void)reloadData;
+ (NSString*)accessibilityIdentifier;
@end @end
#endif // IOS_CHROME_BROWSER_UI_READING_LIST_READING_LIST_COLLECTION_VIEW_CONTROLLER_H_ #endif // IOS_CHROME_BROWSER_UI_READING_LIST_READING_LIST_COLLECTION_VIEW_CONTROLLER_H_
...@@ -142,6 +142,10 @@ typedef void (^EntryUpdater)(CollectionViewItem* item); ...@@ -142,6 +142,10 @@ typedef void (^EntryUpdater)(CollectionViewItem* item);
@synthesize shouldMonitorDataSource = _shouldMonitorDataSource; @synthesize shouldMonitorDataSource = _shouldMonitorDataSource;
+ (NSString*)accessibilityIdentifier {
return @"ReadingListCollectionView";
}
#pragma mark lifecycle #pragma mark lifecycle
- (instancetype)initWithDataSource:(id<ReadingListDataSource>)dataSource - (instancetype)initWithDataSource:(id<ReadingListDataSource>)dataSource
...@@ -183,7 +187,8 @@ typedef void (^EntryUpdater)(CollectionViewItem* item); ...@@ -183,7 +187,8 @@ typedef void (^EntryUpdater)(CollectionViewItem* item);
[super viewDidLoad]; [super viewDidLoad];
self.title = l10n_util::GetNSString(IDS_IOS_TOOLS_MENU_READING_LIST); self.title = l10n_util::GetNSString(IDS_IOS_TOOLS_MENU_READING_LIST);
self.collectionView.accessibilityIdentifier =
[ReadingListCollectionViewController accessibilityIdentifier];
// Add "Done" button. // Add "Done" button.
UIBarButtonItem* doneItem = [[UIBarButtonItem alloc] UIBarButtonItem* doneItem = [[UIBarButtonItem alloc]
initWithTitle:l10n_util::GetNSString(IDS_IOS_READING_LIST_DONE_BUTTON) initWithTitle:l10n_util::GetNSString(IDS_IOS_READING_LIST_DONE_BUTTON)
......
...@@ -14,8 +14,10 @@ ...@@ -14,8 +14,10 @@
#include "components/reading_list/core/reading_list_model.h" #include "components/reading_list/core/reading_list_model.h"
#include "ios/chrome/browser/reading_list/reading_list_model_factory.h" #include "ios/chrome/browser/reading_list/reading_list_model_factory.h"
#import "ios/chrome/browser/ui/commands/reading_list_add_command.h" #import "ios/chrome/browser/ui/commands/reading_list_add_command.h"
#import "ios/chrome/browser/ui/reading_list/reading_list_collection_view_controller.h"
#import "ios/chrome/browser/ui/reading_list/reading_list_collection_view_item.h" #import "ios/chrome/browser/ui/reading_list/reading_list_collection_view_item.h"
#import "ios/chrome/browser/ui/reading_list/reading_list_empty_collection_background.h" #import "ios/chrome/browser/ui/reading_list/reading_list_empty_collection_background.h"
#import "ios/chrome/browser/ui/reading_list/reading_list_toolbar_button.h"
#include "ios/chrome/browser/ui/ui_util.h" #include "ios/chrome/browser/ui/ui_util.h"
#include "ios/chrome/grit/ios_strings.h" #include "ios/chrome/grit/ios_strings.h"
#include "ios/chrome/grit/ios_theme_resources.h" #include "ios/chrome/grit/ios_theme_resources.h"
...@@ -105,20 +107,35 @@ ReadingListModel* GetReadingListModel() { ...@@ -105,20 +107,35 @@ ReadingListModel* GetReadingListModel() {
return model; return model;
} }
// Scroll to the top of the Reading List.
void ScrollToTop() {
NSError* error = nil;
[[EarlGrey selectElementWithMatcher:grey_accessibilityID(
[ReadingListCollectionViewController
accessibilityIdentifier])]
performAction:grey_scrollToContentEdge(kGREYContentEdgeTop)
error:&error];
[[GREYUIThreadExecutor sharedInstance] drainUntilIdle];
}
// Asserts the |button_id| button is not visible. // Asserts the |button_id| button is not visible.
void AssertButtonNotVisibleWithID(int button_id) { void AssertButtonNotVisibleWithID(int button_id) {
[[EarlGrey [[EarlGrey
selectElementWithMatcher:chrome_test_util::ButtonWithAccessibilityLabelId( selectElementWithMatcher:
button_id)] grey_allOf(
assertWithMatcher:grey_notVisible()]; chrome_test_util::ButtonWithAccessibilityLabelId(button_id),
grey_ancestor(grey_kindOfClass([ReadingListToolbarButton class])),
nil)] assertWithMatcher:grey_notVisible()];
} }
// Assert the |button_id| button is visible. // Assert the |button_id| button is visible.
void AssertButtonVisibleWithID(int button_id) { void AssertButtonVisibleWithID(int button_id) {
[[EarlGrey [[EarlGrey
selectElementWithMatcher:chrome_test_util::ButtonWithAccessibilityLabelId( selectElementWithMatcher:
button_id)] grey_allOf(
assertWithMatcher:grey_sufficientlyVisible()]; chrome_test_util::ButtonWithAccessibilityLabelId(button_id),
grey_ancestor(grey_kindOfClass([ReadingListToolbarButton class])),
nil)] assertWithMatcher:grey_sufficientlyVisible()];
} }
// Taps the |button_id| button. // Taps the |button_id| button.
...@@ -128,15 +145,22 @@ void TapButtonWithID(int button_id) { ...@@ -128,15 +145,22 @@ void TapButtonWithID(int button_id) {
button_id)] performAction:grey_tap()]; button_id)] performAction:grey_tap()];
} }
// Performs |action| on the entry with the title |entryTitle|. // Performs |action| on the entry with the title |entryTitle|. The view can be
// scrolled down to find the entry.
void performActionOnEntry(const std::string& entryTitle, void performActionOnEntry(const std::string& entryTitle,
id<GREYAction> action) { id<GREYAction> action) {
[[EarlGrey ScrollToTop();
selectElementWithMatcher: id<GREYMatcher> matcher =
grey_allOf(chrome_test_util::StaticTextWithAccessibilityLabel( grey_allOf(chrome_test_util::StaticTextWithAccessibilityLabel(
base::SysUTF8ToNSString(entryTitle)), base::SysUTF8ToNSString(entryTitle)),
grey_ancestor(grey_kindOfClass([ReadingListCell class])), grey_ancestor(grey_kindOfClass([ReadingListCell class])),
grey_sufficientlyVisible(), nil)] performAction:action]; grey_sufficientlyVisible(), nil);
[[[EarlGrey selectElementWithMatcher:matcher]
usingSearchAction:grey_scrollInDirection(kGREYDirectionDown, 100)
onElementWithMatcher:grey_accessibilityID(
[ReadingListCollectionViewController
accessibilityIdentifier])]
performAction:action];
} }
// Taps the entry with the title |entryTitle|. // Taps the entry with the title |entryTitle|.
...@@ -152,13 +176,18 @@ void LongPressEntry(const std::string& entryTitle) { ...@@ -152,13 +176,18 @@ void LongPressEntry(const std::string& entryTitle) {
// Asserts that the entry with the title |entryTitle| is visible. // Asserts that the entry with the title |entryTitle| is visible.
void AssertEntryVisible(const std::string& entryTitle) { void AssertEntryVisible(const std::string& entryTitle) {
[[GREYUIThreadExecutor sharedInstance] drainUntilIdle]; ScrollToTop();
[[EarlGrey [[[EarlGrey
selectElementWithMatcher: selectElementWithMatcher:
grey_allOf(chrome_test_util::StaticTextWithAccessibilityLabel( grey_allOf(chrome_test_util::StaticTextWithAccessibilityLabel(
base::SysUTF8ToNSString(entryTitle)), base::SysUTF8ToNSString(entryTitle)),
grey_ancestor(grey_kindOfClass([ReadingListCell class])), grey_ancestor(grey_kindOfClass([ReadingListCell class])),
nil)] assertWithMatcher:grey_sufficientlyVisible()]; grey_sufficientlyVisible(), nil)]
usingSearchAction:grey_scrollInDirection(kGREYDirectionDown, 100)
onElementWithMatcher:grey_accessibilityID(
[ReadingListCollectionViewController
accessibilityIdentifier])]
assertWithMatcher:grey_notNil()];
} }
// Asserts that all the entries are visible. // Asserts that all the entries are visible.
...@@ -178,12 +207,22 @@ void AssertAllEntriesVisible() { ...@@ -178,12 +207,22 @@ void AssertAllEntriesVisible() {
// Asserts that the entry |title| is not visible. // Asserts that the entry |title| is not visible.
void AssertEntryNotVisible(std::string title) { void AssertEntryNotVisible(std::string title) {
[[GREYUIThreadExecutor sharedInstance] drainUntilIdle]; [[GREYUIThreadExecutor sharedInstance] drainUntilIdle];
[[EarlGrey ScrollToTop();
NSError* error;
[[[EarlGrey
selectElementWithMatcher: selectElementWithMatcher:
grey_allOf(chrome_test_util::StaticTextWithAccessibilityLabel( grey_allOf(chrome_test_util::StaticTextWithAccessibilityLabel(
base::SysUTF8ToNSString(title)), base::SysUTF8ToNSString(title)),
grey_ancestor(grey_kindOfClass([ReadingListCell class])), grey_ancestor(grey_kindOfClass([ReadingListCell class])),
nil)] assertWithMatcher:grey_notVisible()]; grey_sufficientlyVisible(), nil)]
usingSearchAction:grey_scrollInDirection(kGREYDirectionDown, 100)
onElementWithMatcher:grey_accessibilityID(
[ReadingListCollectionViewController
accessibilityIdentifier])]
assertWithMatcher:grey_notNil()
error:&error];
GREYAssertNotNil(error, @"Entry is visible");
} }
// Asserts |header| is visible. // Asserts |header| is visible.
......
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