OLD | NEW |
1 // Copyright 2017 The Chromium Authors. All rights reserved. | 1 // Copyright 2017 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_view/test/web_view_test_util.h" | 5 #import "ios/web_view/test/web_view_test_util.h" |
6 | 6 |
7 #import <ChromeWebView/ChromeWebView.h> | 7 #import <ChromeWebView/ChromeWebView.h> |
8 | 8 |
9 #import "ios/testing/wait_util.h" | 9 #import "ios/testing/wait_util.h" |
10 | 10 |
11 #if !defined(__has_feature) || !__has_feature(objc_arc) | 11 #if !defined(__has_feature) || !__has_feature(objc_arc) |
12 #error "This file requires ARC support." | 12 #error "This file requires ARC support." |
13 #endif | 13 #endif |
14 | 14 |
15 using testing::WaitUntilConditionOrTimeout; | 15 using testing::WaitUntilConditionOrTimeout; |
16 | 16 |
17 namespace ios_web_view { | 17 namespace ios_web_view { |
18 namespace test { | 18 namespace test { |
19 | 19 |
20 CWVWebView* CreateWebView() { | 20 CWVWebView* CreateWebView() { |
21 return [[CWVWebView alloc] | 21 return [[CWVWebView alloc] |
22 initWithFrame:UIScreen.mainScreen.bounds | 22 initWithFrame:UIScreen.mainScreen.bounds |
23 configuration:[CWVWebViewConfiguration defaultConfiguration]]; | 23 configuration:[CWVWebViewConfiguration defaultConfiguration]]; |
24 } | 24 } |
25 | 25 |
26 bool TapChromeWebViewElementWithId(CWVWebView* web_view, NSString* element_id) { | 26 bool LoadUrl(CWVWebView* web_view, NSURL* url) { |
| 27 [web_view loadRequest:[NSURLRequest requestWithURL:url]]; |
| 28 |
| 29 return WaitForWebViewLoadCompletionOrTimeout(web_view); |
| 30 } |
| 31 |
| 32 bool TapWebViewElementWithId(CWVWebView* web_view, NSString* element_id) { |
27 // TODO(crbug.com/725524): Share this script with Chrome. | 33 // TODO(crbug.com/725524): Share this script with Chrome. |
28 NSString* script = [NSString | 34 NSString* script = [NSString |
29 stringWithFormat:@"(function() {" | 35 stringWithFormat:@"(function() {" |
30 " var element = document.getElementById('%@');" | 36 " var element = document.getElementById('%@');" |
31 " if (element) {" | 37 " if (element) {" |
32 " element.click();" | 38 " element.click();" |
33 " return true;" | 39 " return true;" |
34 " }" | 40 " }" |
35 " return false;" | 41 " return false;" |
36 "})();", | 42 "})();", |
(...skipping 24 matching lines...) Expand all Loading... |
61 | 67 |
62 bool WaitForWebViewContainingTextOrTimeout(CWVWebView* web_view, | 68 bool WaitForWebViewContainingTextOrTimeout(CWVWebView* web_view, |
63 NSString* text) { | 69 NSString* text) { |
64 return WaitUntilConditionOrTimeout(testing::kWaitForUIElementTimeout, ^{ | 70 return WaitUntilConditionOrTimeout(testing::kWaitForUIElementTimeout, ^{ |
65 id body = ios_web_view::test::EvaluateJavaScript( | 71 id body = ios_web_view::test::EvaluateJavaScript( |
66 web_view, @"document.body ? document.body.textContent : null", nil); | 72 web_view, @"document.body ? document.body.textContent : null", nil); |
67 return [body isKindOfClass:[NSString class]] && [body containsString:text]; | 73 return [body isKindOfClass:[NSString class]] && [body containsString:text]; |
68 }); | 74 }); |
69 } | 75 } |
70 | 76 |
| 77 bool WaitForWebViewLoadCompletionOrTimeout(CWVWebView* web_view) { |
| 78 return WaitUntilConditionOrTimeout(testing::kWaitForPageLoadTimeout, ^{ |
| 79 return !web_view.loading; |
| 80 }); |
| 81 } |
| 82 |
71 } // namespace test | 83 } // namespace test |
72 } // namespace ios_web_view | 84 } // namespace ios_web_view |
OLD | NEW |