| 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 #import <WebKit/WebKit.h> | 7 #import <WebKit/WebKit.h> |
| 8 | 8 |
| 9 #include "base/mac/bind_objc_block.h" | 9 #include "base/mac/bind_objc_block.h" |
| 10 #include "base/strings/stringprintf.h" | 10 #include "base/strings/stringprintf.h" |
| (...skipping 156 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 167 | 167 |
| 168 DescribeToBlock describe = ^(id<GREYDescription> description) { | 168 DescribeToBlock describe = ^(id<GREYDescription> description) { |
| 169 [description appendText:@"web view scroll view"]; | 169 [description appendText:@"web view scroll view"]; |
| 170 }; | 170 }; |
| 171 | 171 |
| 172 return [[[GREYElementMatcherBlock alloc] initWithMatchesBlock:matches | 172 return [[[GREYElementMatcherBlock alloc] initWithMatchesBlock:matches |
| 173 descriptionBlock:describe] | 173 descriptionBlock:describe] |
| 174 autorelease]; | 174 autorelease]; |
| 175 } | 175 } |
| 176 | 176 |
| 177 id<GREYMatcher> interstitial(WebState* web_state) { |
| 178 MatchesBlock matches = ^BOOL(WKWebView* view) { |
| 179 web::WebInterstitialImpl* interstitial = |
| 180 static_cast<web::WebInterstitialImpl*>(web_state->GetWebInterstitial()); |
| 181 return interstitial && |
| 182 [view isDescendantOfView:interstitial->GetContentView()]; |
| 183 }; |
| 184 |
| 185 DescribeToBlock describe = ^(id<GREYDescription> description) { |
| 186 [description appendText:@"interstitial displayed"]; |
| 187 }; |
| 188 |
| 189 return grey_allOf(webViewInWebState(web_state), |
| 190 [[[GREYElementMatcherBlock alloc] |
| 191 initWithMatchesBlock:matches |
| 192 descriptionBlock:describe] autorelease], |
| 193 nil); |
| 194 } |
| 195 |
| 177 id<GREYMatcher> interstitialContainingText(NSString* text, | 196 id<GREYMatcher> interstitialContainingText(NSString* text, |
| 178 WebState* web_state) { | 197 WebState* web_state) { |
| 179 MatchesBlock matches = ^BOOL(WKWebView* view) { | 198 MatchesBlock matches = ^BOOL(WKWebView* view) { |
| 180 return WaitUntilConditionOrTimeout(testing::kWaitForUIElementTimeout, ^{ | 199 return WaitUntilConditionOrTimeout(testing::kWaitForUIElementTimeout, ^{ |
| 181 web::WebInterstitialImpl* interstitial = | |
| 182 static_cast<web::WebInterstitialImpl*>( | |
| 183 web_state->GetWebInterstitial()); | |
| 184 if (![view isDescendantOfView:interstitial->GetContentView()]) | |
| 185 return false; | |
| 186 | |
| 187 NSString* script = base::SysUTF8ToNSString(kGetDocumentBodyJavaScript); | 200 NSString* script = base::SysUTF8ToNSString(kGetDocumentBodyJavaScript); |
| 188 id body = ExecuteScriptOnInterstitial(web_state, script); | 201 id body = ExecuteScriptOnInterstitial(web_state, script); |
| 189 return [body containsString:text] ? true : false; | 202 return [body containsString:text] ? true : false; |
| 190 }); | 203 }); |
| 191 }; | 204 }; |
| 192 | 205 |
| 193 DescribeToBlock describe = ^(id<GREYDescription> description) { | 206 DescribeToBlock describe = ^(id<GREYDescription> description) { |
| 194 [description appendText:@"interstitial containing "]; | 207 [description appendText:@"interstitial containing "]; |
| 195 [description appendText:text]; | 208 [description appendText:text]; |
| 196 }; | 209 }; |
| 197 | 210 |
| 198 return grey_allOf(webViewInWebState(web_state), | 211 return grey_allOf(interstitial(web_state), |
| 199 [[[GREYElementMatcherBlock alloc] | 212 [[[GREYElementMatcherBlock alloc] |
| 200 initWithMatchesBlock:matches | 213 initWithMatchesBlock:matches |
| 201 descriptionBlock:describe] autorelease], | 214 descriptionBlock:describe] autorelease], |
| 202 nil); | 215 nil); |
| 203 } | 216 } |
| 204 | 217 |
| 205 } // namespace web | 218 } // namespace web |
| OLD | NEW |