Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(219)

Unified Diff: ios/web/shell/test/earl_grey/shell_matchers.mm

Issue 1961063002: Add web shell matcher for address field. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: ios/web/shell/test/earl_grey/shell_matchers.mm
diff --git a/ios/web/shell/test/earl_grey/shell_matchers.mm b/ios/web/shell/test/earl_grey/shell_matchers.mm
index e0e37a1818067d389164e6c80388f7c3f3f8ab96..bb938a688396743143e5b1c6ad358c921a305752 100644
--- a/ios/web/shell/test/earl_grey/shell_matchers.mm
+++ b/ios/web/shell/test/earl_grey/shell_matchers.mm
@@ -4,6 +4,8 @@
#import "ios/web/shell/test/earl_grey/shell_matchers.h"
+#include "base/test/ios/wait_util.h"
+#include "ios/testing/earl_grey/wait_util.h"
#import "ios/web/public/web_state/web_state.h"
#import "ios/web/public/test/earl_grey/web_view_matchers.h"
#import "ios/web/shell/test/app/web_shell_test_util.h"
@@ -11,11 +13,14 @@
namespace web {
-// Shorthand for GREYMatchers::matcherForWebViewContainingText.
id<GREYMatcher> webViewContainingText(NSString* text) {
return [GREYMatchers matcherForWebViewContainingText:text];
}
+id<GREYMatcher> addressFieldText(NSString* text) {
+ return [GREYMatchers matcherForAddressFieldTextEqualTo:text];
+}
+
id<GREYMatcher> backButton() {
return [GREYMatchers matcherForWebShellBackButton];
}
@@ -37,6 +42,39 @@ id<GREYMatcher> addressField() {
return web::webViewContainingText(text, webState);
}
++ (id<GREYMatcher>)matcherForAddressFieldTextEqualTo:(NSString*)text {
+ MatchesBlock matches = ^BOOL(UIView* view) {
+ if (![view isKindOfClass:[UITextField class]]) {
+ return NO;
+ }
+ if (![[view accessibilityLabel]
+ isEqualToString:kWebShellAddressFieldAccessibilityLabel]) {
+ return NO;
+ }
+ UITextField* textField = static_cast<UITextField*>(view);
Eugene But (OOO till 7-30) 2016/05/09 15:59:08 base::mac::ObjCCastStrict
baxley 2016/05/09 17:11:43 Done.
+
+ NSDate* deadline = [NSDate
+ dateWithTimeIntervalSinceNow:earl_grey_support::kWaitForElementTimeout];
Eugene But (OOO till 7-30) 2016/05/09 15:59:08 Can be changed later. This is repetitive code, wh
baxley 2016/05/09 17:11:43 Acknowledged.
+ while ([[NSDate date] compare:deadline] != NSOrderedDescending) {
+ if ([textField.text isEqualToString:text]) {
+ return YES;
+ }
+ base::test::ios::SpinRunLoopWithMaxDelay(
+ base::TimeDelta::FromSecondsD(earl_grey_support::kSpinDelaySeconds));
+ }
+ return NO;
+ };
+
+ DescribeToBlock describe = ^(id<GREYDescription> description) {
+ [description
Eugene But (OOO till 7-30) 2016/05/09 15:59:08 Optional NIT: [description appendText:@"web view
baxley 2016/05/09 17:11:43 Done.
+ appendText:[NSString stringWithFormat:@"web view containing %@", text]];
+ };
+
+ return [[[GREYElementMatcherBlock alloc] initWithMatchesBlock:matches
+ descriptionBlock:describe]
+ autorelease];
+}
+
+ (id<GREYMatcher>)matcherForWebShellBackButton {
return grey_accessibilityLabel(kWebShellBackButtonAccessibilityLabel);
}

Powered by Google App Engine
This is Rietveld 408576698