| 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/test/wk_web_view_crash_utils.h" | 5 #import "ios/web/test/wk_web_view_crash_utils.h" |
| 6 | 6 |
| 7 #import <Foundation/Foundation.h> | 7 #import <Foundation/Foundation.h> |
| 8 #import <WebKit/WebKit.h> | 8 #import <WebKit/WebKit.h> |
| 9 | 9 |
| 10 #include "base/logging.h" | 10 #include "base/logging.h" |
| (...skipping 21 matching lines...) Expand all Loading... |
| 32 | 32 |
| 33 } // namespace | 33 } // namespace |
| 34 | 34 |
| 35 namespace web { | 35 namespace web { |
| 36 | 36 |
| 37 void SimulateWKWebViewCrash(WKWebView* webView) { | 37 void SimulateWKWebViewCrash(WKWebView* webView) { |
| 38 SEL selector = @selector(webViewWebContentProcessDidTerminate:); | 38 SEL selector = @selector(webViewWebContentProcessDidTerminate:); |
| 39 if ([webView.navigationDelegate respondsToSelector:selector]) { | 39 if ([webView.navigationDelegate respondsToSelector:selector]) { |
| 40 [webView.navigationDelegate performSelector:selector withObject:webView]; | 40 [webView.navigationDelegate performSelector:selector withObject:webView]; |
| 41 } | 41 } |
| 42 #pragma clang diagnostic push |
| 43 #pragma clang diagnostic ignored "-Wundeclared-selector" |
| 42 [webView performSelector:@selector(_processDidExit)]; | 44 [webView performSelector:@selector(_processDidExit)]; |
| 45 #pragma clang diagnostic pop |
| 43 } | 46 } |
| 44 | 47 |
| 45 WKWebView* BuildTerminatedWKWebView() { | 48 WKWebView* BuildTerminatedWKWebView() { |
| 46 id fail = ^void(NSInvocation* invocation) { | 49 id fail = ^void(NSInvocation* invocation) { |
| 47 // Always fails with WKErrorWebContentProcessTerminated error. | 50 // Always fails with WKErrorWebContentProcessTerminated error. |
| 48 NSError* error = | 51 NSError* error = |
| 49 [NSError errorWithDomain:WKErrorDomain | 52 [NSError errorWithDomain:WKErrorDomain |
| 50 code:WKErrorWebContentProcessTerminated | 53 code:WKErrorWebContentProcessTerminated |
| 51 userInfo:nil]; | 54 userInfo:nil]; |
| 52 | 55 |
| 53 void (^completionHandler)(id, NSError*) = | 56 void (^completionHandler)(id, NSError*) = |
| 54 [invocation getArgumentAtIndexAsObject:3]; | 57 [invocation getArgumentAtIndexAsObject:3]; |
| 55 completionHandler(nil, error); | 58 completionHandler(nil, error); |
| 56 }; | 59 }; |
| 57 return BuildMockWKWebViewWithStubbedJSEvalFunction(fail); | 60 return BuildMockWKWebViewWithStubbedJSEvalFunction(fail); |
| 58 } | 61 } |
| 59 | 62 |
| 60 WKWebView* BuildHealthyWKWebView() { | 63 WKWebView* BuildHealthyWKWebView() { |
| 61 id succeed = ^void(NSInvocation* invocation) { | 64 id succeed = ^void(NSInvocation* invocation) { |
| 62 void (^completionHandler)(id, NSError*) = | 65 void (^completionHandler)(id, NSError*) = |
| 63 [invocation getArgumentAtIndexAsObject:3]; | 66 [invocation getArgumentAtIndexAsObject:3]; |
| 64 // Always succceeds with nil result. | 67 // Always succceeds with nil result. |
| 65 completionHandler(nil, nil); | 68 completionHandler(nil, nil); |
| 66 }; | 69 }; |
| 67 return BuildMockWKWebViewWithStubbedJSEvalFunction(succeed); | 70 return BuildMockWKWebViewWithStubbedJSEvalFunction(succeed); |
| 68 } | 71 } |
| 69 | 72 |
| 70 } // namespace web | 73 } // namespace web |
| OLD | NEW |