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

Side by Side 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 unified diff | Download patch
OLDNEW
1 // Copyright 2016 The Chromium Authors. All rights reserved. 1 // Copyright 2016 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #import "ios/web/shell/test/earl_grey/shell_matchers.h" 5 #import "ios/web/shell/test/earl_grey/shell_matchers.h"
6 6
7 #include "base/test/ios/wait_util.h"
8 #include "ios/testing/earl_grey/wait_util.h"
7 #import "ios/web/public/web_state/web_state.h" 9 #import "ios/web/public/web_state/web_state.h"
8 #import "ios/web/public/test/earl_grey/web_view_matchers.h" 10 #import "ios/web/public/test/earl_grey/web_view_matchers.h"
9 #import "ios/web/shell/test/app/web_shell_test_util.h" 11 #import "ios/web/shell/test/app/web_shell_test_util.h"
10 #import "ios/web/shell/view_controller.h" 12 #import "ios/web/shell/view_controller.h"
11 13
12 namespace web { 14 namespace web {
13 15
14 // Shorthand for GREYMatchers::matcherForWebViewContainingText.
15 id<GREYMatcher> webViewContainingText(NSString* text) { 16 id<GREYMatcher> webViewContainingText(NSString* text) {
16 return [GREYMatchers matcherForWebViewContainingText:text]; 17 return [GREYMatchers matcherForWebViewContainingText:text];
17 } 18 }
18 19
20 id<GREYMatcher> addressFieldText(NSString* text) {
21 return [GREYMatchers matcherForAddressFieldTextEqualTo:text];
22 }
23
19 id<GREYMatcher> backButton() { 24 id<GREYMatcher> backButton() {
20 return [GREYMatchers matcherForWebShellBackButton]; 25 return [GREYMatchers matcherForWebShellBackButton];
21 } 26 }
22 27
23 id<GREYMatcher> forwardButton() { 28 id<GREYMatcher> forwardButton() {
24 return [GREYMatchers matcherForWebShellForwardButton]; 29 return [GREYMatchers matcherForWebShellForwardButton];
25 } 30 }
26 31
27 id<GREYMatcher> addressField() { 32 id<GREYMatcher> addressField() {
28 return [GREYMatchers matcherForWebShellAddressField]; 33 return [GREYMatchers matcherForWebShellAddressField];
29 } 34 }
30 35
31 } // namespace web 36 } // namespace web
32 37
33 @implementation GREYMatchers (WebShellAdditions) 38 @implementation GREYMatchers (WebShellAdditions)
34 39
35 + (id<GREYMatcher>)matcherForWebViewContainingText:(NSString*)text { 40 + (id<GREYMatcher>)matcherForWebViewContainingText:(NSString*)text {
36 web::WebState* webState = web::web_shell_test_util::GetCurrentWebState(); 41 web::WebState* webState = web::web_shell_test_util::GetCurrentWebState();
37 return web::webViewContainingText(text, webState); 42 return web::webViewContainingText(text, webState);
38 } 43 }
39 44
45 + (id<GREYMatcher>)matcherForAddressFieldTextEqualTo:(NSString*)text {
46 MatchesBlock matches = ^BOOL(UIView* view) {
47 if (![view isKindOfClass:[UITextField class]]) {
48 return NO;
49 }
50 if (![[view accessibilityLabel]
51 isEqualToString:kWebShellAddressFieldAccessibilityLabel]) {
52 return NO;
53 }
54 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.
55
56 NSDate* deadline = [NSDate
57 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.
58 while ([[NSDate date] compare:deadline] != NSOrderedDescending) {
59 if ([textField.text isEqualToString:text]) {
60 return YES;
61 }
62 base::test::ios::SpinRunLoopWithMaxDelay(
63 base::TimeDelta::FromSecondsD(earl_grey_support::kSpinDelaySeconds));
64 }
65 return NO;
66 };
67
68 DescribeToBlock describe = ^(id<GREYDescription> description) {
69 [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.
70 appendText:[NSString stringWithFormat:@"web view containing %@", text]];
71 };
72
73 return [[[GREYElementMatcherBlock alloc] initWithMatchesBlock:matches
74 descriptionBlock:describe]
75 autorelease];
76 }
77
40 + (id<GREYMatcher>)matcherForWebShellBackButton { 78 + (id<GREYMatcher>)matcherForWebShellBackButton {
41 return grey_accessibilityLabel(kWebShellBackButtonAccessibilityLabel); 79 return grey_accessibilityLabel(kWebShellBackButtonAccessibilityLabel);
42 } 80 }
43 81
44 + (id<GREYMatcher>)matcherForWebShellForwardButton { 82 + (id<GREYMatcher>)matcherForWebShellForwardButton {
45 return grey_accessibilityLabel(kWebShellForwardButtonAccessibilityLabel); 83 return grey_accessibilityLabel(kWebShellForwardButtonAccessibilityLabel);
46 } 84 }
47 85
48 + (id<GREYMatcher>)matcherForWebShellAddressField { 86 + (id<GREYMatcher>)matcherForWebShellAddressField {
49 return grey_accessibilityLabel(kWebShellAddressFieldAccessibilityLabel); 87 return grey_accessibilityLabel(kWebShellAddressFieldAccessibilityLabel);
50 } 88 }
51 89
52 @end 90 @end
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698