OLD | NEW |
(Empty) | |
| 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 |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #import "ios/web_view/test/web_view_interaction_test_util.h" |
| 6 |
| 7 #import <ChromeWebView/ChromeWebView.h> |
| 8 |
| 9 #import "ios/testing/wait_util.h" |
| 10 |
| 11 #if !defined(__has_feature) || !__has_feature(objc_arc) |
| 12 #error "This file requires ARC support." |
| 13 #endif |
| 14 |
| 15 namespace ios_web_view { |
| 16 namespace test { |
| 17 |
| 18 bool TapChromeWebViewElementWithId(CWVWebView* web_view, NSString* element_id) { |
| 19 // TODO(crbug.com/725524): Share this script with Chrome. |
| 20 NSString* script = [NSString |
| 21 stringWithFormat:@"(function() {" |
| 22 " var element = document.getElementById('%@');" |
| 23 " if (element) {" |
| 24 " element.click();" |
| 25 " return true;" |
| 26 " }" |
| 27 " return false;" |
| 28 "})();", |
| 29 element_id]; |
| 30 __block bool did_complete = false; |
| 31 __block bool element_found = false; |
| 32 [web_view evaluateJavaScript:script |
| 33 completionHandler:^(id result, NSError*) { |
| 34 did_complete = true; |
| 35 element_found = [result boolValue]; |
| 36 }]; |
| 37 |
| 38 testing::WaitUntilConditionOrTimeout(testing::kWaitForJSCompletionTimeout, ^{ |
| 39 return did_complete; |
| 40 }); |
| 41 |
| 42 return element_found; |
| 43 } |
| 44 |
| 45 } // namespace test |
| 46 } // namespace ios_web_view |
OLD | NEW |