| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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/js_test_util.h" | 5 #import "ios/web/public/test/js_test_util.h" |
| 6 | 6 |
| 7 #import <WebKit/WebKit.h> | 7 #import <WebKit/WebKit.h> |
| 8 | 8 |
| 9 #import "base/logging.h" | 9 #import "base/logging.h" |
| 10 #import "base/mac/scoped_nsobject.h" | 10 #import "base/mac/scoped_nsobject.h" |
| (...skipping 19 matching lines...) Expand all Loading... |
| 30 return [[result retain] autorelease]; | 30 return [[result retain] autorelease]; |
| 31 } | 31 } |
| 32 | 32 |
| 33 id ExecuteJavaScript(CRWJSInjectionReceiver* receiver, NSString* script) { | 33 id ExecuteJavaScript(CRWJSInjectionReceiver* receiver, NSString* script) { |
| 34 base::scoped_nsobject<CRWJSInjectionManager> manager( | 34 base::scoped_nsobject<CRWJSInjectionManager> manager( |
| 35 [[CRWJSInjectionManager alloc] initWithReceiver:receiver]); | 35 [[CRWJSInjectionManager alloc] initWithReceiver:receiver]); |
| 36 return ExecuteJavaScript(manager, script); | 36 return ExecuteJavaScript(manager, script); |
| 37 } | 37 } |
| 38 | 38 |
| 39 id ExecuteJavaScript(WKWebView* web_view, NSString* script) { | 39 id ExecuteJavaScript(WKWebView* web_view, NSString* script) { |
| 40 return ExecuteJavaScript(web_view, script, nullptr); |
| 41 } |
| 42 |
| 43 id ExecuteJavaScript(WKWebView* web_view, NSString* script, NSError** error) { |
| 40 __block base::scoped_nsobject<id> result; | 44 __block base::scoped_nsobject<id> result; |
| 41 __block bool completed = false; | 45 __block bool completed = false; |
| 42 [web_view evaluateJavaScript:script | 46 [web_view evaluateJavaScript:script |
| 43 completionHandler:^(id evaluation_result, NSError* error) { | 47 completionHandler:^(id script_result, NSError* script_error) { |
| 44 DCHECK(!error); | 48 result.reset([script_result copy]); |
| 45 result.reset([evaluation_result copy]); | 49 if (error) |
| 50 *error = [[script_error copy] autorelease]; |
| 46 completed = true; | 51 completed = true; |
| 47 }]; | 52 }]; |
| 48 base::test::ios::WaitUntilCondition(^{ | 53 base::test::ios::WaitUntilCondition(^{ |
| 49 return completed; | 54 return completed; |
| 50 }); | 55 }); |
| 51 return [[result retain] autorelease]; | 56 return [[result retain] autorelease]; |
| 52 } | 57 } |
| 53 | 58 |
| 54 } // namespace web | 59 } // namespace web |
| 55 | 60 |
| OLD | NEW |