Commit db5b3088 authored by Stepan Khapugin's avatar Stepan Khapugin Committed by Commit Bot

[multiball] Add a11y identifier to windows.

Adds an identifier for EGTests to each window. This will allow matching
specific windows in tests.

Bug: none
Change-Id: I9d04ee645ec1658181d5580a8f4c2060b6927940
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2463565
Auto-Submit: Stepan Khapugin <stkhapugin@chromium.org>
Reviewed-by: default avatarMark Cogan <marq@chromium.org>
Commit-Queue: Stepan Khapugin <stkhapugin@chromium.org>
Cr-Commit-Position: refs/heads/master@{#816167}
parent 895d2f64
...@@ -39,6 +39,16 @@ NSString* const kOriginDetectedKey = @"OriginDetectedKey"; ...@@ -39,6 +39,16 @@ NSString* const kOriginDetectedKey = @"OriginDetectedKey";
// Sizing of the window is handled by UIKit. // Sizing of the window is handled by UIKit.
_window = [[ChromeOverlayWindow alloc] init]; _window = [[ChromeOverlayWindow alloc] init];
CustomizeUIWindowAppearance(_window); CustomizeUIWindowAppearance(_window);
if (@available(iOS 13, *)) {
// Assign an a11y identifier for using in EGTest.
// See comment for [ChromeMatchersAppInterface windowWithNumber:] matcher
// for context.
self.sceneState.window.accessibilityIdentifier =
[NSString stringWithFormat:@"%ld", UIApplication.sharedApplication
.connectedScenes.count -
1];
}
} }
return _window; return _window;
} }
......
...@@ -13,6 +13,14 @@ ...@@ -13,6 +13,14 @@
namespace chrome_test_util { namespace chrome_test_util {
// Matcher for a window with a given number.
// Window numbers are assigned at scene creation. Normally, each EGTest will
// start with exactly one window with number 0. Each time a window is created,
// it is assigned an accessibility identifier equal to the number of connected
// scenes (stored as NSString). This means typically any windows created in a
// test will have consecutive numbers.
id<GREYMatcher> WindowWithNumber(int window_number);
// Matcher for element with accessibility label corresponding to |message_id| // Matcher for element with accessibility label corresponding to |message_id|
// and accessibility trait UIAccessibilityTraitButton. // and accessibility trait UIAccessibilityTraitButton.
id<GREYMatcher> ButtonWithAccessibilityLabelId(int message_id); id<GREYMatcher> ButtonWithAccessibilityLabelId(int message_id);
......
...@@ -16,6 +16,10 @@ GREY_STUB_CLASS_IN_APP_MAIN_QUEUE(ChromeMatchersAppInterface) ...@@ -16,6 +16,10 @@ GREY_STUB_CLASS_IN_APP_MAIN_QUEUE(ChromeMatchersAppInterface)
namespace chrome_test_util { namespace chrome_test_util {
id<GREYMatcher> WindowWithNumber(int window_number) {
return [ChromeMatchersAppInterface windowWithNumber:window_number];
}
id<GREYMatcher> ButtonWithAccessibilityLabel(NSString* label) { id<GREYMatcher> ButtonWithAccessibilityLabel(NSString* label) {
return [ChromeMatchersAppInterface buttonWithAccessibilityLabel:label]; return [ChromeMatchersAppInterface buttonWithAccessibilityLabel:label];
} }
......
...@@ -15,6 +15,14 @@ ...@@ -15,6 +15,14 @@
// define the matchers in the app process. // define the matchers in the app process.
@interface ChromeMatchersAppInterface : NSObject @interface ChromeMatchersAppInterface : NSObject
// Matcher for a window with a given number.
// Window numbers are assigned at scene creation. Normally, each EGTest will
// start with exactly one window with number 0. Each time a window is created,
// it is assigned an accessibility identifier equal to the number of connected
// scenes (stored as NSString). This means typically any windows created in a
// test will have consecutive numbers.
+ (id<GREYMatcher>)windowWithNumber:(int)windowNumber;
// Matcher for element with accessibility label corresponding to |label| and // Matcher for element with accessibility label corresponding to |label| and
// accessibility trait UIAccessibilityTraitButton. // accessibility trait UIAccessibilityTraitButton.
+ (id<GREYMatcher>)buttonWithAccessibilityLabel:(NSString*)label; + (id<GREYMatcher>)buttonWithAccessibilityLabel:(NSString*)label;
......
...@@ -129,6 +129,12 @@ UIView* SubviewWithAccessibilityIdentifier(NSString* accessibility_id, ...@@ -129,6 +129,12 @@ UIView* SubviewWithAccessibilityIdentifier(NSString* accessibility_id,
@implementation ChromeMatchersAppInterface @implementation ChromeMatchersAppInterface
+ (id<GREYMatcher>)windowWithNumber:(int)windowNumber {
return grey_allOf(
grey_accessibilityLabel([NSString stringWithFormat:@"%d", windowNumber]),
grey_kindOfClass([UIWindow class]), nil);
}
+ (id<GREYMatcher>)buttonWithAccessibilityLabel:(NSString*)label { + (id<GREYMatcher>)buttonWithAccessibilityLabel:(NSString*)label {
return grey_allOf(grey_accessibilityLabel(label), return grey_allOf(grey_accessibilityLabel(label),
grey_accessibilityTrait(UIAccessibilityTraitButton), nil); grey_accessibilityTrait(UIAccessibilityTraitButton), nil);
......
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