OLD | NEW |
1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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/web/net/cert_verifier_block_adapter.h" | 5 #include "ios/web/net/cert_verifier_block_adapter.h" |
6 | 6 |
7 #include "base/message_loop/message_loop.h" | 7 #include "base/message_loop/message_loop.h" |
8 #include "base/test/ios/wait_util.h" | 8 #include "base/test/ios/wait_util.h" |
9 #include "ios/web/public/test/test_web_thread_bundle.h" | 9 #include "ios/web/public/test/test_web_thread_bundle.h" |
10 #include "net/base/net_errors.h" | 10 #include "net/base/net_errors.h" |
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
80 | 80 |
81 // Ensure that Verification results are correct. | 81 // Ensure that Verification results are correct. |
82 EXPECT_EQ(kExpectedError, actual_error); | 82 EXPECT_EQ(kExpectedError, actual_error); |
83 EXPECT_EQ(expected_result.cert_status, actual_result.cert_status); | 83 EXPECT_EQ(expected_result.cert_status, actual_result.cert_status); |
84 } | 84 } |
85 | 85 |
86 // Tests |Verify| with default params and asynchronous verification using real | 86 // Tests |Verify| with default params and asynchronous verification using real |
87 // net::CertVerifier and ok_cert.pem cert. | 87 // net::CertVerifier and ok_cert.pem cert. |
88 TEST_F(CertVerifierBlockAdapterTest, DefaultParamsAndAsync) { | 88 TEST_F(CertVerifierBlockAdapterTest, DefaultParamsAndAsync) { |
89 // Call |Verify|. | 89 // Call |Verify|. |
90 scoped_ptr<net::CertVerifier> verifier(net::CertVerifier::CreateDefault()); | 90 std::unique_ptr<net::CertVerifier> verifier( |
| 91 net::CertVerifier::CreateDefault()); |
91 CertVerifierBlockAdapter test_adapter(verifier.get(), &net_log_); | 92 CertVerifierBlockAdapter test_adapter(verifier.get(), &net_log_); |
92 CertVerifierBlockAdapter::Params params(cert_.get(), kHostName); | 93 CertVerifierBlockAdapter::Params params(cert_.get(), kHostName); |
93 net::CertVerifyResult actual_result; | 94 net::CertVerifyResult actual_result; |
94 int actual_error = -1; | 95 int actual_error = -1; |
95 Verify(&test_adapter, params, &actual_result, &actual_error); | 96 Verify(&test_adapter, params, &actual_result, &actual_error); |
96 | 97 |
97 // Ensure that Verification results are correct. | 98 // Ensure that Verification results are correct. |
98 EXPECT_FALSE(actual_result.is_issued_by_known_root); | 99 EXPECT_FALSE(actual_result.is_issued_by_known_root); |
99 EXPECT_EQ(net::ERR_CERT_AUTHORITY_INVALID, actual_error); | 100 EXPECT_EQ(net::ERR_CERT_AUTHORITY_INVALID, actual_error); |
100 } | 101 } |
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
144 CertVerifierBlockAdapter::Params params(cert_.get(), kHostName); | 145 CertVerifierBlockAdapter::Params params(cert_.get(), kHostName); |
145 Verify(&test_adapter, params, &actual_result, &actual_error); | 146 Verify(&test_adapter, params, &actual_result, &actual_error); |
146 | 147 |
147 // Ensure that Verification results are correct. | 148 // Ensure that Verification results are correct. |
148 EXPECT_EQ(kExpectedError, actual_error); | 149 EXPECT_EQ(kExpectedError, actual_error); |
149 } | 150 } |
150 | 151 |
151 // Tests that the completion handler passed to |Verify()| is called, even if the | 152 // Tests that the completion handler passed to |Verify()| is called, even if the |
152 // adapter is destroyed. | 153 // adapter is destroyed. |
153 TEST_F(CertVerifierBlockAdapterTest, CompletionHandlerIsAlwaysCalled) { | 154 TEST_F(CertVerifierBlockAdapterTest, CompletionHandlerIsAlwaysCalled) { |
154 scoped_ptr<net::CertVerifier> verifier(net::CertVerifier::CreateDefault()); | 155 std::unique_ptr<net::CertVerifier> verifier( |
155 scoped_ptr<CertVerifierBlockAdapter> test_adapter( | 156 net::CertVerifier::CreateDefault()); |
| 157 std::unique_ptr<CertVerifierBlockAdapter> test_adapter( |
156 new CertVerifierBlockAdapter(verifier.get(), &net_log_)); | 158 new CertVerifierBlockAdapter(verifier.get(), &net_log_)); |
157 | 159 |
158 // Call |Verify| and destroy the adapter. | 160 // Call |Verify| and destroy the adapter. |
159 CertVerifierBlockAdapter::Params params(cert_.get(), kHostName); | 161 CertVerifierBlockAdapter::Params params(cert_.get(), kHostName); |
160 __block bool verification_completed = false; | 162 __block bool verification_completed = false; |
161 test_adapter->Verify(params, ^(net::CertVerifyResult, int) { | 163 test_adapter->Verify(params, ^(net::CertVerifyResult, int) { |
162 verification_completed = true; | 164 verification_completed = true; |
163 }); | 165 }); |
164 test_adapter.reset(); | 166 test_adapter.reset(); |
165 | 167 |
166 // Make sure that the completion handler is called. | 168 // Make sure that the completion handler is called. |
167 base::test::ios::WaitUntilCondition(^{ | 169 base::test::ios::WaitUntilCondition(^{ |
168 return verification_completed; | 170 return verification_completed; |
169 }, base::MessageLoop::current(), base::TimeDelta()); | 171 }, base::MessageLoop::current(), base::TimeDelta()); |
170 } | 172 } |
171 | 173 |
172 } // namespace web | 174 } // namespace web |
OLD | NEW |