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