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

Side by Side Diff: ios/web/shell/test/earl_grey/shell_matchers.mm

Issue 2448753002: Refactor wait_util so it isn't coupled to EarlGrey. (Closed)
Patch Set: Created 4 years, 1 month 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 #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 #import "ios/testing/earl_grey/matchers.h" 9 #import "ios/testing/earl_grey/matchers.h"
10 #include "ios/testing/earl_grey/wait_util.h" 10 #include "ios/testing/wait_util.h"
11 #import "ios/web/public/web_state/web_state.h" 11 #import "ios/web/public/web_state/web_state.h"
12 #import "ios/web/public/test/earl_grey/web_view_matchers.h" 12 #import "ios/web/public/test/earl_grey/web_view_matchers.h"
13 #import "ios/web/shell/test/app/web_shell_test_util.h" 13 #import "ios/web/shell/test/app/web_shell_test_util.h"
14 #import "ios/web/shell/view_controller.h" 14 #import "ios/web/shell/view_controller.h"
15 15
16 namespace web { 16 namespace web {
17 17
18 id<GREYMatcher> webViewContainingText(const std::string& text) { 18 id<GREYMatcher> webViewContainingText(const std::string& text) {
19 WebState* web_state = shell_test_util::GetCurrentWebState(); 19 WebState* web_state = shell_test_util::GetCurrentWebState();
20 return webViewContainingText(std::move(text), web_state); 20 return webViewContainingText(std::move(text), web_state);
(...skipping 15 matching lines...) Expand all
36 id<GREYMatcher> addressFieldText(std::string text) { 36 id<GREYMatcher> addressFieldText(std::string text) {
37 MatchesBlock matches = ^BOOL(UIView* view) { 37 MatchesBlock matches = ^BOOL(UIView* view) {
38 if (![view isKindOfClass:[UITextField class]]) { 38 if (![view isKindOfClass:[UITextField class]]) {
39 return NO; 39 return NO;
40 } 40 }
41 if (![[view accessibilityLabel] 41 if (![[view accessibilityLabel]
42 isEqualToString:kWebShellAddressFieldAccessibilityLabel]) { 42 isEqualToString:kWebShellAddressFieldAccessibilityLabel]) {
43 return NO; 43 return NO;
44 } 44 }
45 UITextField* text_field = base::mac::ObjCCastStrict<UITextField>(view); 45 UITextField* text_field = base::mac::ObjCCastStrict<UITextField>(view);
46 testing::WaitUntilCondition(testing::kWaitForUIElementTimeout, ^bool() { 46 NSString* errorMessage = [NSString
47 return [text_field.text isEqualToString:base::SysUTF8ToNSString(text)]; 47 stringWithFormat:
48 }); 48 @"Address field text did not match. expected: %@, actual: %@",
49 base::SysUTF8ToNSString(text), text_field.text];
50 GREYAssert(testing::WaitUntilConditionOrTimeout(
51 testing::kWaitForUIElementTimeout,
52 ^() {
53 return [text_field.text
54 isEqualToString:base::SysUTF8ToNSString(text)];
55 }),
56 errorMessage);
49 return YES; 57 return YES;
50 }; 58 };
51 59
52 DescribeToBlock describe = ^(id<GREYDescription> description) { 60 DescribeToBlock describe = ^(id<GREYDescription> description) {
53 [description appendText:@"address field containing "]; 61 [description appendText:@"address field containing "];
54 [description appendText:base::SysUTF8ToNSString(text)]; 62 [description appendText:base::SysUTF8ToNSString(text)];
55 }; 63 };
56 64
57 return [[[GREYElementMatcherBlock alloc] initWithMatchesBlock:matches 65 return [[[GREYElementMatcherBlock alloc] initWithMatchesBlock:matches
58 descriptionBlock:describe] 66 descriptionBlock:describe]
59 autorelease]; 67 autorelease];
60 } 68 }
61 69
62 id<GREYMatcher> backButton() { 70 id<GREYMatcher> backButton() {
63 return grey_accessibilityLabel(kWebShellBackButtonAccessibilityLabel); 71 return grey_accessibilityLabel(kWebShellBackButtonAccessibilityLabel);
64 } 72 }
65 73
66 id<GREYMatcher> forwardButton() { 74 id<GREYMatcher> forwardButton() {
67 return grey_accessibilityLabel(kWebShellForwardButtonAccessibilityLabel); 75 return grey_accessibilityLabel(kWebShellForwardButtonAccessibilityLabel);
68 } 76 }
69 77
70 id<GREYMatcher> addressField() { 78 id<GREYMatcher> addressField() {
71 return grey_accessibilityLabel(kWebShellAddressFieldAccessibilityLabel); 79 return grey_accessibilityLabel(kWebShellAddressFieldAccessibilityLabel);
72 } 80 }
73 81
74 } // namespace web 82 } // namespace web
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698