Chromium Code Reviews| OLD | NEW |
|---|---|
| 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 #import "base/mac/foundation_util.h" | |
| 8 #include "base/test/ios/wait_util.h" | |
| 9 #include "ios/testing/earl_grey/wait_util.h" | |
| 7 #import "ios/web/public/web_state/web_state.h" | 10 #import "ios/web/public/web_state/web_state.h" |
| 8 #import "ios/web/public/test/earl_grey/web_view_matchers.h" | 11 #import "ios/web/public/test/earl_grey/web_view_matchers.h" |
| 9 #import "ios/web/shell/test/app/web_shell_test_util.h" | 12 #import "ios/web/shell/test/app/web_shell_test_util.h" |
| 10 #import "ios/web/shell/view_controller.h" | 13 #import "ios/web/shell/view_controller.h" |
| 11 | 14 |
| 12 namespace web { | 15 namespace web { |
| 13 | 16 |
| 14 // Shorthand for GREYMatchers::matcherForWebViewContainingText. | |
| 15 id<GREYMatcher> webViewContainingText(NSString* text) { | 17 id<GREYMatcher> webViewContainingText(NSString* text) { |
| 16 return [GREYMatchers matcherForWebViewContainingText:text]; | 18 return [GREYMatchers matcherForWebViewContainingText:text]; |
| 17 } | 19 } |
| 18 | 20 |
| 21 id<GREYMatcher> addressFieldText(NSString* text) { | |
| 22 return [GREYMatchers matcherForAddressFieldEqualToText:text]; | |
| 23 } | |
| 24 | |
| 19 id<GREYMatcher> backButton() { | 25 id<GREYMatcher> backButton() { |
| 20 return [GREYMatchers matcherForWebShellBackButton]; | 26 return [GREYMatchers matcherForWebShellBackButton]; |
| 21 } | 27 } |
| 22 | 28 |
| 23 id<GREYMatcher> forwardButton() { | 29 id<GREYMatcher> forwardButton() { |
| 24 return [GREYMatchers matcherForWebShellForwardButton]; | 30 return [GREYMatchers matcherForWebShellForwardButton]; |
| 25 } | 31 } |
| 26 | 32 |
| 27 id<GREYMatcher> addressField() { | 33 id<GREYMatcher> addressField() { |
| 28 return [GREYMatchers matcherForWebShellAddressField]; | 34 return [GREYMatchers matcherForWebShellAddressField]; |
| 29 } | 35 } |
| 30 | 36 |
| 31 } // namespace web | 37 } // namespace web |
| 32 | 38 |
| 33 @implementation GREYMatchers (WebShellAdditions) | 39 @implementation GREYMatchers (WebShellAdditions) |
| 34 | 40 |
| 35 + (id<GREYMatcher>)matcherForWebViewContainingText:(NSString*)text { | 41 + (id<GREYMatcher>)matcherForWebViewContainingText:(NSString*)text { |
| 36 web::WebState* webState = web::web_shell_test_util::GetCurrentWebState(); | 42 web::WebState* webState = web::web_shell_test_util::GetCurrentWebState(); |
| 37 return web::webViewContainingText(text, webState); | 43 return web::webViewContainingText(text, webState); |
| 38 } | 44 } |
| 39 | 45 |
| 46 + (id<GREYMatcher>)matcherForAddressFieldEqualToText:(NSString*)text { | |
| 47 MatchesBlock matches = ^BOOL(UIView* view) { | |
| 48 if (![view isKindOfClass:[UITextField class]]) { | |
| 49 return NO; | |
| 50 } | |
| 51 if (![[view accessibilityLabel] | |
| 52 isEqualToString:kWebShellAddressFieldAccessibilityLabel]) { | |
| 53 return NO; | |
| 54 } | |
| 55 UITextField* textField = base::mac::ObjCCastStrict<UITextField>(view); | |
| 56 | |
| 57 NSDate* deadline = | |
| 58 [NSDate dateWithTimeIntervalSinceNow:testing::kWaitForElementTimeout]; | |
| 59 while ([[NSDate date] compare:deadline] != NSOrderedDescending) { | |
| 60 if ([textField.text isEqualToString:text]) { | |
| 61 return YES; | |
| 62 } | |
| 63 base::test::ios::SpinRunLoopWithMaxDelay( | |
| 64 base::TimeDelta::FromSecondsD(testing::kSpinDelaySeconds)); | |
| 65 } | |
| 66 return NO; | |
| 67 }; | |
| 68 | |
| 69 DescribeToBlock describe = ^(id<GREYDescription> description) { | |
| 70 [description | |
|
Eugene But (OOO till 7-30)
2016/05/09 17:58:35
[description appendText:@"web view containing "];
baxley
2016/05/09 18:42:27
Gah. Feel free to preface these comments with "Hey
| |
| 71 appendText:[NSString stringWithFormat:@"web view containing "]]; | |
| 72 [description appendText:text]; | |
| 73 }; | |
| 74 | |
| 75 return [[[GREYElementMatcherBlock alloc] initWithMatchesBlock:matches | |
| 76 descriptionBlock:describe] | |
| 77 autorelease]; | |
| 78 } | |
| 79 | |
| 40 + (id<GREYMatcher>)matcherForWebShellBackButton { | 80 + (id<GREYMatcher>)matcherForWebShellBackButton { |
| 41 return grey_accessibilityLabel(kWebShellBackButtonAccessibilityLabel); | 81 return grey_accessibilityLabel(kWebShellBackButtonAccessibilityLabel); |
| 42 } | 82 } |
| 43 | 83 |
| 44 + (id<GREYMatcher>)matcherForWebShellForwardButton { | 84 + (id<GREYMatcher>)matcherForWebShellForwardButton { |
| 45 return grey_accessibilityLabel(kWebShellForwardButtonAccessibilityLabel); | 85 return grey_accessibilityLabel(kWebShellForwardButtonAccessibilityLabel); |
| 46 } | 86 } |
| 47 | 87 |
| 48 + (id<GREYMatcher>)matcherForWebShellAddressField { | 88 + (id<GREYMatcher>)matcherForWebShellAddressField { |
| 49 return grey_accessibilityLabel(kWebShellAddressFieldAccessibilityLabel); | 89 return grey_accessibilityLabel(kWebShellAddressFieldAccessibilityLabel); |
| 50 } | 90 } |
| 51 | 91 |
| 52 @end | 92 @end |
| OLD | NEW |