| 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/public/test/earl_grey/web_view_matchers.h" | 5 #import "ios/web/public/test/earl_grey/web_view_matchers.h" |
| 6 | 6 |
| 7 #include <memory> | 7 #include <memory> |
| 8 | 8 |
| 9 #import <WebKit/WebKit.h> | 9 #import <WebKit/WebKit.h> |
| 10 | 10 |
| (...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 72 id<GREYMatcher> webViewCssSelector(const std::string& selector, | 72 id<GREYMatcher> webViewCssSelector(const std::string& selector, |
| 73 web::WebState* webState) { | 73 web::WebState* webState) { |
| 74 return | 74 return |
| 75 [GREYMatchers matcherForWebWithCSSSelector:selector inWebState:webState]; | 75 [GREYMatchers matcherForWebWithCSSSelector:selector inWebState:webState]; |
| 76 } | 76 } |
| 77 | 77 |
| 78 id<GREYMatcher> webViewScrollView(web::WebState* webState) { | 78 id<GREYMatcher> webViewScrollView(web::WebState* webState) { |
| 79 return [GREYMatchers matcherForWebViewScrollViewInWebState:webState]; | 79 return [GREYMatchers matcherForWebViewScrollViewInWebState:webState]; |
| 80 } | 80 } |
| 81 | 81 |
| 82 id<GREYMatcher> webViewMimeType(const std::string& mimeType, |
| 83 web::WebState* webState) { |
| 84 return [GREYMatchers matcherForWebViewMIMEType:mimeType inWebState:webState]; |
| 85 } |
| 86 |
| 82 } // namespace web | 87 } // namespace web |
| 83 | 88 |
| 84 @implementation GREYMatchers (WebViewAdditions) | 89 @implementation GREYMatchers (WebViewAdditions) |
| 85 | 90 |
| 86 + (id<GREYMatcher>)matcherForWebViewContainingText:(const std::string&)text | 91 + (id<GREYMatcher>)matcherForWebViewContainingText:(const std::string&)text |
| 87 inWebState:(web::WebState*)webState { | 92 inWebState:(web::WebState*)webState { |
| 88 MatchesBlock matches = ^BOOL(WKWebView*) { | 93 MatchesBlock matches = ^BOOL(WKWebView*) { |
| 89 __block BOOL didSucceed = NO; | 94 __block BOOL didSucceed = NO; |
| 90 NSDate* deadline = | 95 NSDate* deadline = |
| 91 [NSDate dateWithTimeIntervalSinceNow:testing::kWaitForUIElementTimeout]; | 96 [NSDate dateWithTimeIntervalSinceNow:testing::kWaitForUIElementTimeout]; |
| (...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 156 | 161 |
| 157 DescribeToBlock describe = ^(id<GREYDescription> description) { | 162 DescribeToBlock describe = ^(id<GREYDescription> description) { |
| 158 [description appendText:@"web view scroll view"]; | 163 [description appendText:@"web view scroll view"]; |
| 159 }; | 164 }; |
| 160 | 165 |
| 161 return [[[GREYElementMatcherBlock alloc] initWithMatchesBlock:matches | 166 return [[[GREYElementMatcherBlock alloc] initWithMatchesBlock:matches |
| 162 descriptionBlock:describe] | 167 descriptionBlock:describe] |
| 163 autorelease]; | 168 autorelease]; |
| 164 } | 169 } |
| 165 | 170 |
| 171 + (id<GREYMatcher>)matcherForWebViewMIMEType:(const std::string&)MIMEType |
| 172 inWebState:(web::WebState*)webState { |
| 173 std::string MIMETypeCopy = MIMEType; |
| 174 MatchesBlock matches = ^BOOL(UIView* view) { |
| 175 __block BOOL didSucceed = NO; |
| 176 NSDate* deadline = |
| 177 [NSDate dateWithTimeIntervalSinceNow:testing::kWaitForUIElementTimeout]; |
| 178 while ([[NSDate date] compare:deadline] != NSOrderedDescending) { |
| 179 if (webState->GetContentsMimeType() == MIMETypeCopy) { |
| 180 didSucceed = YES; |
| 181 break; |
| 182 } |
| 183 base::test::ios::SpinRunLoopWithMaxDelay( |
| 184 base::TimeDelta::FromSecondsD(testing::kSpinDelaySeconds)); |
| 185 } |
| 186 return didSucceed; |
| 187 }; |
| 188 |
| 189 DescribeToBlock describe = ^(id<GREYDescription> description) { |
| 190 [description appendText:@"web view MIME type "]; |
| 191 [description appendText:base::SysUTF8ToNSString(MIMETypeCopy)]; |
| 192 }; |
| 193 |
| 194 return grey_allOf(webViewInWebState(webState), |
| 195 [[[GREYElementMatcherBlock alloc] |
| 196 initWithMatchesBlock:matches |
| 197 descriptionBlock:describe] autorelease], |
| 198 nil); |
| 199 } |
| 200 |
| 166 @end | 201 @end |
| OLD | NEW |