| OLD | NEW |
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 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 #include "ios/chrome/browser/ssl/ios_ssl_error_handler.h" | 5 #include "ios/chrome/browser/ssl/ios_ssl_error_handler.h" |
| 6 | 6 |
| 7 #include "base/mac/bind_objc_block.h" | 7 #include "base/mac/bind_objc_block.h" |
| 8 #include "ios/chrome/browser/browser_state/test_chrome_browser_state.h" | 8 #include "ios/chrome/browser/browser_state/test_chrome_browser_state.h" |
| 9 #include "ios/web/public/interstitials/web_interstitial.h" | 9 #include "ios/web/public/interstitials/web_interstitial.h" |
| 10 #import "ios/web/public/test/web_test_with_web_state.h" | 10 #import "ios/web/public/test/web_test_with_web_state.h" |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 48 }; | 48 }; |
| 49 | 49 |
| 50 // Tests non-overridable error handling. | 50 // Tests non-overridable error handling. |
| 51 TEST_F(IOSSSLErrorHandlerTest, NonOverridable) { | 51 TEST_F(IOSSSLErrorHandlerTest, NonOverridable) { |
| 52 net::SSLInfo ssl_info; | 52 net::SSLInfo ssl_info; |
| 53 ssl_info.cert = cert(); | 53 ssl_info.cert = cert(); |
| 54 GURL url(kTestHostName); | 54 GURL url(kTestHostName); |
| 55 __block bool do_not_proceed_callback_called = false; | 55 __block bool do_not_proceed_callback_called = false; |
| 56 IOSSSLErrorHandler::HandleSSLError( | 56 IOSSSLErrorHandler::HandleSSLError( |
| 57 web_state(), net::ERR_CERT_AUTHORITY_INVALID, ssl_info, url, false, | 57 web_state(), net::ERR_CERT_AUTHORITY_INVALID, ssl_info, url, false, |
| 58 base::BindBlock(^(bool proceed) { | 58 base::BindBlockArc(^(bool proceed) { |
| 59 EXPECT_FALSE(proceed); | 59 EXPECT_FALSE(proceed); |
| 60 do_not_proceed_callback_called = true; | 60 do_not_proceed_callback_called = true; |
| 61 })); | 61 })); |
| 62 | 62 |
| 63 // Make sure that interstitial is displayed. | 63 // Make sure that interstitial is displayed. |
| 64 EXPECT_TRUE(web_state()->IsShowingWebInterstitial()); | 64 EXPECT_TRUE(web_state()->IsShowingWebInterstitial()); |
| 65 web::WebInterstitial* interstitial = web_state()->GetWebInterstitial(); | 65 web::WebInterstitial* interstitial = web_state()->GetWebInterstitial(); |
| 66 EXPECT_TRUE(interstitial); | 66 EXPECT_TRUE(interstitial); |
| 67 | 67 |
| 68 // Make sure callback is called on dismissal. | 68 // Make sure callback is called on dismissal. |
| 69 interstitial->DontProceed(); | 69 interstitial->DontProceed(); |
| 70 EXPECT_TRUE(do_not_proceed_callback_called); | 70 EXPECT_TRUE(do_not_proceed_callback_called); |
| 71 } | 71 } |
| 72 | 72 |
| 73 // Tests proceed with overridable error. | 73 // Tests proceed with overridable error. |
| 74 // Flaky: http://crbug.com/660343. | 74 // Flaky: http://crbug.com/660343. |
| 75 TEST_F(IOSSSLErrorHandlerTest, DISABLED_OverridableProceed) { | 75 TEST_F(IOSSSLErrorHandlerTest, DISABLED_OverridableProceed) { |
| 76 net::SSLInfo ssl_info; | 76 net::SSLInfo ssl_info; |
| 77 ssl_info.cert = cert(); | 77 ssl_info.cert = cert(); |
| 78 GURL url(kTestHostName); | 78 GURL url(kTestHostName); |
| 79 __block bool proceed_callback_called = false; | 79 __block bool proceed_callback_called = false; |
| 80 IOSSSLErrorHandler::HandleSSLError( | 80 IOSSSLErrorHandler::HandleSSLError( |
| 81 web_state(), net::ERR_CERT_AUTHORITY_INVALID, ssl_info, url, true, | 81 web_state(), net::ERR_CERT_AUTHORITY_INVALID, ssl_info, url, true, |
| 82 base::BindBlock(^(bool proceed) { | 82 base::BindBlockArc(^(bool proceed) { |
| 83 EXPECT_TRUE(proceed); | 83 EXPECT_TRUE(proceed); |
| 84 proceed_callback_called = true; | 84 proceed_callback_called = true; |
| 85 })); | 85 })); |
| 86 | 86 |
| 87 // Make sure that interstitial is displayed. | 87 // Make sure that interstitial is displayed. |
| 88 EXPECT_TRUE(web_state()->IsShowingWebInterstitial()); | 88 EXPECT_TRUE(web_state()->IsShowingWebInterstitial()); |
| 89 web::WebInterstitial* interstitial = web_state()->GetWebInterstitial(); | 89 web::WebInterstitial* interstitial = web_state()->GetWebInterstitial(); |
| 90 EXPECT_TRUE(interstitial); | 90 EXPECT_TRUE(interstitial); |
| 91 | 91 |
| 92 // Make sure callback is called on dismissal. | 92 // Make sure callback is called on dismissal. |
| 93 interstitial->Proceed(); | 93 interstitial->Proceed(); |
| 94 EXPECT_TRUE(proceed_callback_called); | 94 EXPECT_TRUE(proceed_callback_called); |
| 95 } | 95 } |
| 96 | 96 |
| 97 // Tests do not proceed with overridable error. | 97 // Tests do not proceed with overridable error. |
| 98 TEST_F(IOSSSLErrorHandlerTest, OverridableDontProceed) { | 98 TEST_F(IOSSSLErrorHandlerTest, OverridableDontProceed) { |
| 99 net::SSLInfo ssl_info; | 99 net::SSLInfo ssl_info; |
| 100 ssl_info.cert = cert(); | 100 ssl_info.cert = cert(); |
| 101 GURL url(kTestHostName); | 101 GURL url(kTestHostName); |
| 102 __block bool do_not_proceed_callback_called = false; | 102 __block bool do_not_proceed_callback_called = false; |
| 103 IOSSSLErrorHandler::HandleSSLError( | 103 IOSSSLErrorHandler::HandleSSLError( |
| 104 web_state(), net::ERR_CERT_AUTHORITY_INVALID, ssl_info, url, true, | 104 web_state(), net::ERR_CERT_AUTHORITY_INVALID, ssl_info, url, true, |
| 105 base::BindBlock(^(bool proceed) { | 105 base::BindBlockArc(^(bool proceed) { |
| 106 EXPECT_FALSE(proceed); | 106 EXPECT_FALSE(proceed); |
| 107 do_not_proceed_callback_called = true; | 107 do_not_proceed_callback_called = true; |
| 108 })); | 108 })); |
| 109 | 109 |
| 110 // Make sure that interstitial is displayed. | 110 // Make sure that interstitial is displayed. |
| 111 EXPECT_TRUE(web_state()->IsShowingWebInterstitial()); | 111 EXPECT_TRUE(web_state()->IsShowingWebInterstitial()); |
| 112 web::WebInterstitial* interstitial = web_state()->GetWebInterstitial(); | 112 web::WebInterstitial* interstitial = web_state()->GetWebInterstitial(); |
| 113 EXPECT_TRUE(interstitial); | 113 EXPECT_TRUE(interstitial); |
| 114 | 114 |
| 115 // Make sure callback is called on dismissal. | 115 // Make sure callback is called on dismissal. |
| 116 interstitial->DontProceed(); | 116 interstitial->DontProceed(); |
| 117 EXPECT_TRUE(do_not_proceed_callback_called); | 117 EXPECT_TRUE(do_not_proceed_callback_called); |
| 118 } | 118 } |
| OLD | NEW |