Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(111)

Side by Side Diff: ios/web/test/wk_web_view_crash_utils.mm

Issue 2436903002: Removed uses of IsRunningOnIOS9OrLater in crw_web_ or wk_web_view_ (Closed)
Patch Set: Created 4 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | ios/web/web_state/crw_web_view_proxy_impl.mm » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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/ios/ios_util.h"
11 #include "base/logging.h" 10 #include "base/logging.h"
12 #import "base/mac/scoped_nsobject.h" 11 #import "base/mac/scoped_nsobject.h"
13 #include "ios/web/public/test/test_browser_state.h" 12 #include "ios/web/public/test/test_browser_state.h"
14 #import "ios/web/public/web_view_creation_util.h" 13 #import "ios/web/public/web_view_creation_util.h"
15 #import "third_party/ocmock/OCMock/NSInvocation+OCMAdditions.h" 14 #import "third_party/ocmock/OCMock/NSInvocation+OCMAdditions.h"
16 #import "third_party/ocmock/OCMock/OCMock.h" 15 #import "third_party/ocmock/OCMock/OCMock.h"
17 16
18 namespace { 17 namespace {
19 18
20 // Returns an OCMocked WKWebView whose |evaluateJavaScript:completionHandler:| 19 // Returns an OCMocked WKWebView whose |evaluateJavaScript:completionHandler:|
21 // method has been mocked to execute |block| instead. |block| cannot be nil. 20 // method has been mocked to execute |block| instead. |block| cannot be nil.
22 WKWebView* CreateMockWKWebViewWithStubbedJSEvalFunction( 21 WKWebView* CreateMockWKWebViewWithStubbedJSEvalFunction(
23 void (^block)(NSInvocation*)) { 22 void (^block)(NSInvocation*)) {
24 DCHECK(block); 23 DCHECK(block);
25 web::TestBrowserState browser_state; 24 web::TestBrowserState browser_state;
26 base::scoped_nsobject<WKWebView> webView( 25 base::scoped_nsobject<WKWebView> webView(
27 web::CreateWKWebView(CGRectZero, &browser_state)); 26 web::CreateWKWebView(CGRectZero, &browser_state));
28 id mockWebView = [OCMockObject partialMockForObject:webView]; 27 id mockWebView = [OCMockObject partialMockForObject:webView];
29 [[[mockWebView stub] andDo:^void(NSInvocation* invocation) { 28 [[[mockWebView stub] andDo:^void(NSInvocation* invocation) {
30 block(invocation); 29 block(invocation);
31 }] evaluateJavaScript:OCMOCK_ANY completionHandler:OCMOCK_ANY]; 30 }] evaluateJavaScript:OCMOCK_ANY completionHandler:OCMOCK_ANY];
32 return [mockWebView retain]; 31 return [mockWebView retain];
33 } 32 }
34 33
35 } // namespace 34 } // namespace
36 35
37 namespace web { 36 namespace web {
38 37
39 void SimulateWKWebViewCrash(WKWebView* webView) { 38 void SimulateWKWebViewCrash(WKWebView* webView) {
40 if (base::ios::IsRunningOnIOS9OrLater()) { 39 SEL selector = @selector(webViewWebContentProcessDidTerminate:);
41 SEL selector = @selector(webViewWebContentProcessDidTerminate:); 40 if ([webView.navigationDelegate respondsToSelector:selector]) {
42 if ([webView.navigationDelegate respondsToSelector:selector]) { 41 [webView.navigationDelegate performSelector:selector withObject:webView];
43 [webView.navigationDelegate performSelector:selector withObject:webView];
44 }
45 } 42 }
46 [webView performSelector:@selector(_processDidExit)]; 43 [webView performSelector:@selector(_processDidExit)];
47 } 44 }
48 45
49 WKWebView* CreateTerminatedWKWebView() { 46 WKWebView* CreateTerminatedWKWebView() {
50 id fail = ^void(NSInvocation* invocation) { 47 id fail = ^void(NSInvocation* invocation) {
51 // Always fails with WKErrorWebContentProcessTerminated error. 48 // Always fails with WKErrorWebContentProcessTerminated error.
52 NSError* error = 49 NSError* error =
53 [NSError errorWithDomain:WKErrorDomain 50 [NSError errorWithDomain:WKErrorDomain
54 code:WKErrorWebContentProcessTerminated 51 code:WKErrorWebContentProcessTerminated
(...skipping 10 matching lines...) Expand all
65 id succeed = ^void(NSInvocation* invocation) { 62 id succeed = ^void(NSInvocation* invocation) {
66 void (^completionHandler)(id, NSError*) = 63 void (^completionHandler)(id, NSError*) =
67 [invocation getArgumentAtIndexAsObject:3]; 64 [invocation getArgumentAtIndexAsObject:3];
68 // Always succceeds with nil result. 65 // Always succceeds with nil result.
69 completionHandler(nil, nil); 66 completionHandler(nil, nil);
70 }; 67 };
71 return CreateMockWKWebViewWithStubbedJSEvalFunction(succeed); 68 return CreateMockWKWebViewWithStubbedJSEvalFunction(succeed);
72 } 69 }
73 70
74 } // namespace web 71 } // namespace web
OLDNEW
« no previous file with comments | « no previous file | ios/web/web_state/crw_web_view_proxy_impl.mm » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698