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 130 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
141 // Call |Verify|. | 141 // Call |Verify|. |
142 net::CertVerifyResult actual_result; | 142 net::CertVerifyResult actual_result; |
143 int actual_error = -1; | 143 int actual_error = -1; |
144 CertVerifierBlockAdapter::Params params(cert_.get(), kHostName); | 144 CertVerifierBlockAdapter::Params params(cert_.get(), kHostName); |
145 Verify(&test_adapter, params, &actual_result, &actual_error); | 145 Verify(&test_adapter, params, &actual_result, &actual_error); |
146 | 146 |
147 // Ensure that Verification results are correct. | 147 // Ensure that Verification results are correct. |
148 EXPECT_EQ(kExpectedError, actual_error); | 148 EXPECT_EQ(kExpectedError, actual_error); |
149 } | 149 } |
150 | 150 |
| 151 // Tests that the completion handler passed to |Verify()| is called, even if the |
| 152 // adapter is destroyed. |
| 153 TEST_F(CertVerifierBlockAdapterTest, CompletionHandlerIsAlwaysCalled) { |
| 154 scoped_ptr<net::CertVerifier> verifier(net::CertVerifier::CreateDefault()); |
| 155 scoped_ptr<CertVerifierBlockAdapter> test_adapter( |
| 156 new CertVerifierBlockAdapter(verifier.get(), &net_log_)); |
| 157 |
| 158 // Call |Verify| and destroy the adapter. |
| 159 CertVerifierBlockAdapter::Params params(cert_.get(), kHostName); |
| 160 __block bool verification_completed = false; |
| 161 test_adapter->Verify(params, ^(net::CertVerifyResult, int) { |
| 162 verification_completed = true; |
| 163 }); |
| 164 test_adapter.reset(); |
| 165 |
| 166 // Make sure that the completion handler is called. |
| 167 base::test::ios::WaitUntilCondition(^{ |
| 168 return verification_completed; |
| 169 }, base::MessageLoop::current(), base::TimeDelta()); |
| 170 } |
| 171 |
151 } // namespace web | 172 } // namespace web |
OLD | NEW |