Commit a749c1d8 authored by edchin's avatar edchin Committed by Commit Bot

[ios] Add close cell egtest in tab grid

Bug: 804560
Cq-Include-Trybots: master.tryserver.chromium.mac:ios-simulator-cronet;master.tryserver.chromium.mac:ios-simulator-full-configs
Change-Id: I8a7f1779aff808edddc525110c8900cbd9fd8b8a
Reviewed-on: https://chromium-review.googlesource.com/955345Reviewed-by: default avataredchin <edchin@chromium.org>
Reviewed-by: default avatarSergio Collazos <sczs@chromium.org>
Commit-Queue: edchin <edchin@chromium.org>
Cr-Commit-Position: refs/heads/master@{#541925}
parent fe81a901
...@@ -11,9 +11,6 @@ ...@@ -11,9 +11,6 @@
@class GridCell; @class GridCell;
// The accessibility label for the close button for use in test automation.
extern NSString* const kGridCellCloseButtonAccessibilityID;
// Informs the receiver of actions on the cell. // Informs the receiver of actions on the cell.
@protocol GridCellDelegate @protocol GridCellDelegate
- (void)closeButtonTappedForCell:(GridCell*)cell; - (void)closeButtonTappedForCell:(GridCell*)cell;
......
...@@ -5,6 +5,7 @@ ...@@ -5,6 +5,7 @@
#import "ios/chrome/browser/ui/tab_grid/grid_cell.h" #import "ios/chrome/browser/ui/tab_grid/grid_cell.h"
#import "base/logging.h" #import "base/logging.h"
#import "ios/chrome/browser/ui/tab_grid/grid_constants.h"
#import "ios/chrome/browser/ui/tab_grid/top_aligned_image_view.h" #import "ios/chrome/browser/ui/tab_grid/top_aligned_image_view.h"
#include "ios/chrome/grit/ios_strings.h" #include "ios/chrome/grit/ios_strings.h"
#include "ui/base/l10n/l10n_util.h" #include "ui/base/l10n/l10n_util.h"
...@@ -13,9 +14,6 @@ ...@@ -13,9 +14,6 @@
#error "This file requires ARC support." #error "This file requires ARC support."
#endif #endif
NSString* const kGridCellCloseButtonAccessibilityID =
@"GridCellCloseButtonAccessibilityID";
namespace { namespace {
// Height of the top bar containing the icon, title, and close button. // Height of the top bar containing the icon, title, and close button.
const CGFloat kTopBarHeight = 28.0f; const CGFloat kTopBarHeight = 28.0f;
...@@ -205,7 +203,7 @@ const CGFloat kBorderWidth = 6.0f; ...@@ -205,7 +203,7 @@ const CGFloat kBorderWidth = 6.0f;
[closeButton addTarget:self [closeButton addTarget:self
action:@selector(closeButtonTapped:) action:@selector(closeButtonTapped:)
forControlEvents:UIControlEventTouchUpInside]; forControlEvents:UIControlEventTouchUpInside];
closeButton.accessibilityIdentifier = kGridCellCloseButtonAccessibilityID; closeButton.accessibilityIdentifier = kGridCellCloseButtonIdentifier;
[topBar addSubview:iconView]; [topBar addSubview:iconView];
[topBar addSubview:titleLabel]; [topBar addSubview:titleLabel];
......
...@@ -13,4 +13,7 @@ ...@@ -13,4 +13,7 @@
// index]. // index].
extern NSString* const kGridCellIdentifierPrefix; extern NSString* const kGridCellIdentifierPrefix;
// Accessibility identifier for the close button in a grid cell.
extern NSString* const kGridCellCloseButtonIdentifier;
#endif // IOS_CHROME_BROWSER_UI_TAB_GRID_GRID_CONSTANTS_H_ #endif // IOS_CHROME_BROWSER_UI_TAB_GRID_GRID_CONSTANTS_H_
...@@ -10,3 +10,7 @@ ...@@ -10,3 +10,7 @@
// Accessibility identifier prefix of a grid cell. // Accessibility identifier prefix of a grid cell.
NSString* const kGridCellIdentifierPrefix = @"GridCellIdentifierPrefix"; NSString* const kGridCellIdentifierPrefix = @"GridCellIdentifierPrefix";
// Accessibility identifier for the close button in a grid cell.
NSString* const kGridCellCloseButtonIdentifier =
@"GridCellCloseButtonIdentifier";
...@@ -15,15 +15,32 @@ ...@@ -15,15 +15,32 @@
#endif #endif
namespace { namespace {
// Identifer for cell at given |index|.
NSString* IdentifierForCellAtIndex(unsigned int index) {
return [NSString stringWithFormat:@"%@%u", kGridCellIdentifierPrefix, index];
}
// Matcher for cell at |index|.
id<GREYMatcher> CellAtIndex(unsigned int index) {
return grey_allOf(grey_accessibilityID(IdentifierForCellAtIndex(index)),
grey_sufficientlyVisible(), nil);
}
// Matcher for close button for cell at |index|.
id<GREYMatcher> CloseButtonForCellAtIndex(unsigned int index) {
return grey_allOf(
grey_ancestor(grey_accessibilityID(IdentifierForCellAtIndex(index))),
grey_accessibilityID(kGridCellCloseButtonIdentifier),
grey_sufficientlyVisible(), nil);
}
// Matcher for done button in tab grid. // Matcher for done button in tab grid.
id<GREYMatcher> TabGridDoneButton() { id<GREYMatcher> TabGridDoneButton() {
return grey_allOf(grey_accessibilityID(kTabGridDoneButtonAccessibilityID), return grey_allOf(grey_accessibilityID(kTabGridDoneButtonAccessibilityID),
grey_sufficientlyVisible(), nil); grey_sufficientlyVisible(), nil);
} }
// Identifer for cell at given |index|.
NSString* IdentifierForCellAtIndex(unsigned int index) {
return [NSString stringWithFormat:@"%@%u", kGridCellIdentifierPrefix, index];
}
} // namespace } // namespace
@interface TabGridTestCase : ChromeTestCase @interface TabGridTestCase : ChromeTestCase
...@@ -43,11 +60,19 @@ NSString* IdentifierForCellAtIndex(unsigned int index) { ...@@ -43,11 +60,19 @@ NSString* IdentifierForCellAtIndex(unsigned int index) {
- (void)testTappingOnFirstCell { - (void)testTappingOnFirstCell {
[[EarlGrey selectElementWithMatcher:chrome_test_util::ShowTabsButton()] [[EarlGrey selectElementWithMatcher:chrome_test_util::ShowTabsButton()]
performAction:grey_tap()]; performAction:grey_tap()];
[[EarlGrey selectElementWithMatcher:grey_accessibilityID( [[EarlGrey selectElementWithMatcher:CellAtIndex(0)] performAction:grey_tap()];
IdentifierForCellAtIndex(0))]
performAction:grey_tap()];
[[EarlGrey selectElementWithMatcher:chrome_test_util::ShowTabsButton()] [[EarlGrey selectElementWithMatcher:chrome_test_util::ShowTabsButton()]
assertWithMatcher:grey_sufficientlyVisible()]; assertWithMatcher:grey_sufficientlyVisible()];
} }
// Tests that closing the cell shows no tabs.
- (void)testClosingFirstCell {
[[EarlGrey selectElementWithMatcher:chrome_test_util::ShowTabsButton()]
performAction:grey_tap()];
[[EarlGrey selectElementWithMatcher:CloseButtonForCellAtIndex(0)]
performAction:grey_tap()];
[[EarlGrey selectElementWithMatcher:CellAtIndex(0)]
assertWithMatcher:grey_nil()];
}
@end @end
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