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