Chromium Code Reviews| Index: ios/web_view/shell/test/earl_grey/shell_matchers.mm |
| diff --git a/ios/web_view/shell/test/earl_grey/shell_matchers.mm b/ios/web_view/shell/test/earl_grey/shell_matchers.mm |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..9a24982640188d199d20916195c987ddb2c433d0 |
| --- /dev/null |
| +++ b/ios/web_view/shell/test/earl_grey/shell_matchers.mm |
| @@ -0,0 +1,62 @@ |
| +// Copyright 2017 The Chromium Authors. All rights reserved. |
| +// Use of this source code is governed by a BSD-style license that can be |
| +// found in the LICENSE file. |
| + |
| +#import "ios/web_view/shell/test/earl_grey/shell_matchers.h" |
| + |
| +#import "base/mac/foundation_util.h" |
|
Eugene But (OOO till 7-30)
2017/03/08 21:42:44
Do we need this? If so, then it should be include,
michaeldo
2017/03/08 21:58:31
Done.
|
| +#include "base/strings/sys_string_conversions.h" |
| +#import "ios/testing/wait_util.h" |
| +#import "ios/web_view/shell/shell_view_controller.h" |
| + |
| +#if !defined(__has_feature) || !__has_feature(objc_arc) |
| +#error "This file requires ARC support." |
| +#endif |
| + |
| +namespace ios_web_view { |
| + |
| +id<GREYMatcher> AddressFieldText(const std::string& text) { |
| + MatchesBlock matches = ^BOOL(UIView* view) { |
| + if (![view isKindOfClass:[UITextField class]]) { |
| + return NO; |
| + } |
| + if (![[view accessibilityLabel] |
| + isEqualToString:kWebViewShellAddressFieldAccessibilityLabel]) { |
| + return NO; |
| + } |
| + UITextField* text_field = base::mac::ObjCCastStrict<UITextField>(view); |
| + NSString* error_message = [NSString |
| + stringWithFormat: |
| + @"Address field text did not match. expected: %@, actual: %@", |
| + base::SysUTF8ToNSString(text), text_field.text]; |
| + GREYAssert(testing::WaitUntilConditionOrTimeout( |
| + testing::kWaitForUIElementTimeout, |
|
Eugene But (OOO till 7-30)
2017/03/08 21:42:44
Do you want to use local variables to improve form
michaeldo
2017/03/08 21:58:31
Done.
|
| + ^{ |
| + return base::SysNSStringToUTF8(text_field.text) == text; |
| + }), |
| + error_message); |
| + return YES; |
| + }; |
| + |
| + DescribeToBlock describe = ^(id<GREYDescription> description) { |
| + [description appendText:@"address field containing "]; |
| + [description appendText:base::SysUTF8ToNSString(text)]; |
| + }; |
| + |
| + return [[GREYElementMatcherBlock alloc] initWithMatchesBlock:matches |
| + descriptionBlock:describe]; |
| +} |
| + |
| +id<GREYMatcher> BackButton() { |
| + return grey_accessibilityLabel(kWebViewShellBackButtonAccessibilityLabel); |
| +} |
| + |
| +id<GREYMatcher> ForwardButton() { |
| + return grey_accessibilityLabel(kWebViewShellForwardButtonAccessibilityLabel); |
| +} |
| + |
| +id<GREYMatcher> AddressField() { |
| + return grey_accessibilityLabel(kWebViewShellAddressFieldAccessibilityLabel); |
| +} |
| + |
| +} // namespace ios_web_view |