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

Side by Side Diff: ios/web/web_state/ui/crw_web_controller_unittest.mm

Issue 2146763003: [ios] Cleaned up deprecated SSLError delegate method. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 5 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
OLDNEW
1 // Copyright 2012 The Chromium Authors. All rights reserved. 1 // Copyright 2012 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/web_state/ui/crw_web_controller.h" 5 #import "ios/web/web_state/ui/crw_web_controller.h"
6 6
7 #import <WebKit/WebKit.h> 7 #import <WebKit/WebKit.h>
8 8
9 #include <utility> 9 #include <utility>
10 10
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after
66 // sourceURL passed to webController:shouldBlockPopupWithURL:sourceURL: 66 // sourceURL passed to webController:shouldBlockPopupWithURL:sourceURL:
67 // Used for testing. 67 // Used for testing.
68 @property(nonatomic, assign) GURL sourceURL; 68 @property(nonatomic, assign) GURL sourceURL;
69 // Whether or not the delegate should block popups. 69 // Whether or not the delegate should block popups.
70 @property(nonatomic, assign) BOOL blockPopups; 70 @property(nonatomic, assign) BOOL blockPopups;
71 // A web controller that will be returned by webPageOrdered... methods. 71 // A web controller that will be returned by webPageOrdered... methods.
72 @property(nonatomic, assign) CRWWebController* childWebController; 72 @property(nonatomic, assign) CRWWebController* childWebController;
73 // Blocked popup info received in |webController:didBlockPopup:| call. 73 // Blocked popup info received in |webController:didBlockPopup:| call.
74 // nullptr if that delegate method was not called. 74 // nullptr if that delegate method was not called.
75 @property(nonatomic, readonly) web::BlockedPopupInfo* blockedPopupInfo; 75 @property(nonatomic, readonly) web::BlockedPopupInfo* blockedPopupInfo;
76 // SSL info received in |presentSSLError:forSSLStatus:recoverable:callback:|
77 // call.
78 @property(nonatomic, readonly) net::SSLInfo SSLInfo;
79 // SSL status received in |presentSSLError:forSSLStatus:recoverable:callback:|
80 // call.
81 @property(nonatomic, readonly) web::SSLStatus SSLStatus;
82 // Recoverable flag received in
83 // |presentSSLError:forSSLStatus:recoverable:callback:| call.
84 @property(nonatomic, readonly) BOOL recoverable;
85 // Callback received in |presentSSLError:forSSLStatus:recoverable:callback:|
86 // call.
87 @property(nonatomic, readonly) SSLErrorCallback shouldContinueCallback;
88 @end 76 @end
89 77
90 // Stub implementation for CRWWebUserInterfaceDelegate protocol. 78 // Stub implementation for CRWWebUserInterfaceDelegate protocol.
91 @interface CRWWebUserInterfaceDelegateStub 79 @interface CRWWebUserInterfaceDelegateStub
92 : OCMockComplexTypeHelper<CRWWebUserInterfaceDelegate> 80 : OCMockComplexTypeHelper<CRWWebUserInterfaceDelegate>
93 @end 81 @end
94 82
95 @implementation CRWWebUserInterfaceDelegateStub 83 @implementation CRWWebUserInterfaceDelegateStub
96 84
97 - (void)webController:(CRWWebController*)webController 85 - (void)webController:(CRWWebController*)webController
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after
150 @end 138 @end
151 139
152 @implementation MockInteractionLoader { 140 @implementation MockInteractionLoader {
153 // Backs up the property with the same name. 141 // Backs up the property with the same name.
154 std::unique_ptr<web::BlockedPopupInfo> _blockedPopupInfo; 142 std::unique_ptr<web::BlockedPopupInfo> _blockedPopupInfo;
155 } 143 }
156 @synthesize popupURL = _popupURL; 144 @synthesize popupURL = _popupURL;
157 @synthesize sourceURL = _sourceURL; 145 @synthesize sourceURL = _sourceURL;
158 @synthesize blockPopups = _blockPopups; 146 @synthesize blockPopups = _blockPopups;
159 @synthesize childWebController = _childWebController; 147 @synthesize childWebController = _childWebController;
160 @synthesize SSLInfo = _SSLInfo;
161 @synthesize SSLStatus = _SSLStatus;
162 @synthesize recoverable = _recoverable;
163 @synthesize shouldContinueCallback = _shouldContinueCallback;
164 148
165 typedef void (^webPageOrderedOpenBlankBlockType)(); 149 typedef void (^webPageOrderedOpenBlankBlockType)();
166 typedef void (^webPageOrderedOpenBlockType)(const GURL&, 150 typedef void (^webPageOrderedOpenBlockType)(const GURL&,
167 const web::Referrer&, 151 const web::Referrer&,
168 NSString*, 152 NSString*,
169 BOOL); 153 BOOL);
170 154
171 - (instancetype)initWithRepresentedObject:(id)representedObject { 155 - (instancetype)initWithRepresentedObject:(id)representedObject {
172 self = [super initWithRepresentedObject:representedObject]; 156 self = [super initWithRepresentedObject:representedObject];
173 if (self) { 157 if (self) {
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
207 191
208 - (void)webController:(CRWWebController*)webController 192 - (void)webController:(CRWWebController*)webController
209 didBlockPopup:(const web::BlockedPopupInfo&)blockedPopupInfo { 193 didBlockPopup:(const web::BlockedPopupInfo&)blockedPopupInfo {
210 _blockedPopupInfo.reset(new web::BlockedPopupInfo(blockedPopupInfo)); 194 _blockedPopupInfo.reset(new web::BlockedPopupInfo(blockedPopupInfo));
211 } 195 }
212 196
213 - (web::BlockedPopupInfo*)blockedPopupInfo { 197 - (web::BlockedPopupInfo*)blockedPopupInfo {
214 return _blockedPopupInfo.get(); 198 return _blockedPopupInfo.get();
215 } 199 }
216 200
217 - (void)presentSSLError:(const net::SSLInfo&)info
218 forSSLStatus:(const web::SSLStatus&)status
219 recoverable:(BOOL)recoverable
220 callback:(SSLErrorCallback)shouldContinue {
221 _SSLInfo = info;
222 _SSLStatus = status;
223 _recoverable = recoverable;
224 _shouldContinueCallback = shouldContinue;
225 }
226
227 @end 201 @end
228 202
229 @interface CountingObserver : NSObject<CRWWebControllerObserver> 203 @interface CountingObserver : NSObject<CRWWebControllerObserver>
230 204
231 @property(nonatomic, readonly) int pageLoadedCount; 205 @property(nonatomic, readonly) int pageLoadedCount;
232 @property(nonatomic, readonly) int messageCount; 206 @property(nonatomic, readonly) int messageCount;
233 @end 207 @end
234 208
235 @implementation CountingObserver 209 @implementation CountingObserver
236 @synthesize pageLoadedCount = _pageLoadedCount; 210 @synthesize pageLoadedCount = _pageLoadedCount;
(...skipping 201 matching lines...) Expand 10 before | Expand all | Expand 10 after
438 fromItem.SetURL(MAKE_URL(start)); 412 fromItem.SetURL(MAKE_URL(start));
439 toItem.SetURL(MAKE_URL(end)); 413 toItem.SetURL(MAKE_URL(end));
440 EXPECT_EQ(MAKE_URL([end stringByAppendingString:@"#"]), 414 EXPECT_EQ(MAKE_URL([end stringByAppendingString:@"#"]),
441 [web_controller() URLForHistoryNavigationFromItem:&fromItem 415 [web_controller() URLForHistoryNavigationFromItem:&fromItem
442 toItem:&toItem]); 416 toItem:&toItem]);
443 } 417 }
444 } 418 }
445 } 419 }
446 } 420 }
447 421
448 // Tests that presentSSLError:forSSLStatus:recoverable:callback: is called with
449 // correct arguments if WKWebView fails to load a page with bad SSL cert.
450 // TODO(crbug.com/602298): Remove this test.
451 TEST_F(CRWWebControllerTest, SslCertErrorDeprecatedApi) {
452 ASSERT_FALSE([mockDelegate_ SSLInfo].is_valid());
453
454 scoped_refptr<net::X509Certificate> cert =
455 net::ImportCertFromFile(net::GetTestCertsDirectory(), "ok_cert.pem");
456
457 NSArray* chain = @[ static_cast<id>(cert->os_cert_handle()) ];
458 NSError* error =
459 [NSError errorWithDomain:NSURLErrorDomain
460 code:NSURLErrorServerCertificateHasUnknownRoot
461 userInfo:@{
462 web::kNSErrorPeerCertificateChainKey : chain,
463 }];
464
465 CRWWebControllerContainerView* containerView =
466 static_cast<CRWWebControllerContainerView*>([web_controller() view]);
467 WKWebView* webView =
468 static_cast<WKWebView*>(containerView.webViewContentView.webView);
469 base::scoped_nsobject<NSObject> navigation([[NSObject alloc] init]);
470 [static_cast<id<WKNavigationDelegate>>(web_controller())
471 webView:webView
472 didStartProvisionalNavigation:static_cast<WKNavigation*>(navigation)];
473 [static_cast<id<WKNavigationDelegate>>(web_controller())
474 webView:webView
475 didFailProvisionalNavigation:static_cast<WKNavigation*>(navigation)
476 withError:error];
477
478 // Verify correctness of delegate's method arguments.
479 EXPECT_TRUE([mockDelegate_ SSLInfo].is_valid());
480 EXPECT_EQ(net::CERT_STATUS_INVALID, [mockDelegate_ SSLInfo].cert_status);
481 EXPECT_EQ(net::CERT_STATUS_INVALID, [mockDelegate_ SSLStatus].cert_status);
482 EXPECT_EQ(web::SECURITY_STYLE_AUTHENTICATION_BROKEN,
483 [mockDelegate_ SSLStatus].security_style);
484 EXPECT_FALSE([mockDelegate_ recoverable]);
485 EXPECT_TRUE([mockDelegate_ shouldContinueCallback]);
486 }
487
488 // Tests that AllowCertificateError is called with correct arguments if 422 // Tests that AllowCertificateError is called with correct arguments if
489 // WKWebView fails to load a page with bad SSL cert. 423 // WKWebView fails to load a page with bad SSL cert.
490 TEST_F(CRWWebControllerTest, SslCertError) { 424 TEST_F(CRWWebControllerTest, SslCertError) {
491 // TODO(crbug.com/602298): Remove this call.
492 [web_controller() setDelegate:nil];
493
494 // Last arguments passed to AllowCertificateError must be in default state. 425 // Last arguments passed to AllowCertificateError must be in default state.
495 ASSERT_FALSE(GetWebClient()->last_cert_error_code()); 426 ASSERT_FALSE(GetWebClient()->last_cert_error_code());
496 ASSERT_FALSE(GetWebClient()->last_cert_error_ssl_info().is_valid()); 427 ASSERT_FALSE(GetWebClient()->last_cert_error_ssl_info().is_valid());
497 ASSERT_FALSE(GetWebClient()->last_cert_error_ssl_info().cert_status); 428 ASSERT_FALSE(GetWebClient()->last_cert_error_ssl_info().cert_status);
498 ASSERT_FALSE(GetWebClient()->last_cert_error_request_url().is_valid()); 429 ASSERT_FALSE(GetWebClient()->last_cert_error_request_url().is_valid());
499 ASSERT_TRUE(GetWebClient()->last_cert_error_overridable()); 430 ASSERT_TRUE(GetWebClient()->last_cert_error_overridable());
500 431
501 scoped_refptr<net::X509Certificate> cert = 432 scoped_refptr<net::X509Certificate> cert =
502 net::ImportCertFromFile(net::GetTestCertsDirectory(), "ok_cert.pem"); 433 net::ImportCertFromFile(net::GetTestCertsDirectory(), "ok_cert.pem");
503 434
(...skipping 567 matching lines...) Expand 10 before | Expand all | Expand 10 after
1071 1002
1072 [web_controller() setDelegate:delegate]; 1003 [web_controller() setDelegate:delegate];
1073 web::SimulateWKWebViewCrash(webView_); 1004 web::SimulateWKWebViewCrash(webView_);
1074 1005
1075 EXPECT_OCMOCK_VERIFY(delegate); 1006 EXPECT_OCMOCK_VERIFY(delegate);
1076 EXPECT_FALSE([web_controller() isViewAlive]); 1007 EXPECT_FALSE([web_controller() isViewAlive]);
1077 [web_controller() setDelegate:nil]; 1008 [web_controller() setDelegate:nil];
1078 }; 1009 };
1079 1010
1080 } // namespace 1011 } // namespace
OLDNEW
« ios/web/web_state/ui/crw_web_controller.mm ('K') | « ios/web/web_state/ui/crw_web_controller.mm ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698