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

Side by Side Diff: net/http/disk_cache_based_ssl_host_info_unittest.cc

Issue 9476035: Make CertVerifier a pure virtual interface. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 8 years, 9 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 | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 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 "base/bind.h" 5 #include "base/bind.h"
6 #include "base/bind_helpers.h" 6 #include "base/bind_helpers.h"
7 #include "base/compiler_specific.h" 7 #include "base/compiler_specific.h"
8 #include "base/message_loop.h" 8 #include "base/message_loop.h"
9 #include "net/base/multi_threaded_cert_verifier.h"
9 #include "net/base/net_errors.h" 10 #include "net/base/net_errors.h"
10 #include "net/base/ssl_config_service.h" 11 #include "net/base/ssl_config_service.h"
11 #include "net/http/disk_cache_based_ssl_host_info.h" 12 #include "net/http/disk_cache_based_ssl_host_info.h"
12 #include "net/http/mock_http_cache.h" 13 #include "net/http/mock_http_cache.h"
13 #include "testing/gtest/include/gtest/gtest.h" 14 #include "testing/gtest/include/gtest/gtest.h"
14 15
15 namespace { 16 namespace {
16 17
17 // This is an empty transaction, needed to register the URL and the test mode. 18 // This is an empty transaction, needed to register the URL and the test mode.
18 const MockTransaction kHostInfoTransaction = { 19 const MockTransaction kHostInfoTransaction = {
19 "sslhostinfo:https://www.google.com", 20 "sslhostinfo:https://www.google.com",
20 "", 21 "",
21 base::Time(), 22 base::Time(),
22 "", 23 "",
23 net::LOAD_NORMAL, 24 net::LOAD_NORMAL,
24 "", 25 "",
25 "", 26 "",
26 base::Time(), 27 base::Time(),
27 "", 28 "",
28 TEST_MODE_NORMAL, 29 TEST_MODE_NORMAL,
29 NULL, 30 NULL,
30 0 31 0
31 }; 32 };
32 33
33 // Tests that we can delete a DiskCacheBasedSSLHostInfo object in a 34 // Tests that we can delete a DiskCacheBasedSSLHostInfo object in a
34 // completion callback for DiskCacheBasedSSLHostInfo::WaitForDataReady. 35 // completion callback for DiskCacheBasedSSLHostInfo::WaitForDataReady.
35 TEST(DiskCacheBasedSSLHostInfo, DeleteInCallback) { 36 TEST(DiskCacheBasedSSLHostInfo, DeleteInCallback) {
36 net::CertVerifier cert_verifier; 37 net::MultiThreadedCertVerifier cert_verifier;
37 // Use the blocking mock backend factory to force asynchronous completion 38 // Use the blocking mock backend factory to force asynchronous completion
38 // of ssl_host_info->WaitForDataReady(), so that the callback will run. 39 // of ssl_host_info->WaitForDataReady(), so that the callback will run.
39 MockBlockingBackendFactory* factory = new MockBlockingBackendFactory(); 40 MockBlockingBackendFactory* factory = new MockBlockingBackendFactory();
40 MockHttpCache cache(factory); 41 MockHttpCache cache(factory);
41 net::SSLConfig ssl_config; 42 net::SSLConfig ssl_config;
42 scoped_ptr<net::SSLHostInfo> ssl_host_info( 43 scoped_ptr<net::SSLHostInfo> ssl_host_info(
43 new net::DiskCacheBasedSSLHostInfo("https://www.verisign.com", ssl_config, 44 new net::DiskCacheBasedSSLHostInfo("https://www.verisign.com", ssl_config,
44 &cert_verifier, cache.http_cache())); 45 &cert_verifier, cache.http_cache()));
45 ssl_host_info->Start(); 46 ssl_host_info->Start();
46 net::TestCompletionCallback callback; 47 net::TestCompletionCallback callback;
47 int rv = ssl_host_info->WaitForDataReady(callback.callback()); 48 int rv = ssl_host_info->WaitForDataReady(callback.callback());
48 EXPECT_EQ(net::ERR_IO_PENDING, rv); 49 EXPECT_EQ(net::ERR_IO_PENDING, rv);
49 // Now complete the backend creation and let the callback run. 50 // Now complete the backend creation and let the callback run.
50 factory->FinishCreation(); 51 factory->FinishCreation();
51 EXPECT_EQ(net::OK, callback.GetResult(rv)); 52 EXPECT_EQ(net::OK, callback.GetResult(rv));
52 } 53 }
53 54
54 // Tests the basic logic of storing, retrieving and updating data. 55 // Tests the basic logic of storing, retrieving and updating data.
55 TEST(DiskCacheBasedSSLHostInfo, Update) { 56 TEST(DiskCacheBasedSSLHostInfo, Update) {
56 MockHttpCache cache; 57 MockHttpCache cache;
57 AddMockTransaction(&kHostInfoTransaction); 58 AddMockTransaction(&kHostInfoTransaction);
58 net::TestCompletionCallback callback; 59 net::TestCompletionCallback callback;
59 60
60 // Store a certificate chain. 61 // Store a certificate chain.
61 net::CertVerifier cert_verifier; 62 net::MultiThreadedCertVerifier cert_verifier;
62 net::SSLConfig ssl_config; 63 net::SSLConfig ssl_config;
63 scoped_ptr<net::SSLHostInfo> ssl_host_info( 64 scoped_ptr<net::SSLHostInfo> ssl_host_info(
64 new net::DiskCacheBasedSSLHostInfo("https://www.google.com", ssl_config, 65 new net::DiskCacheBasedSSLHostInfo("https://www.google.com", ssl_config,
65 &cert_verifier, cache.http_cache())); 66 &cert_verifier, cache.http_cache()));
66 ssl_host_info->Start(); 67 ssl_host_info->Start();
67 int rv = ssl_host_info->WaitForDataReady(callback.callback()); 68 int rv = ssl_host_info->WaitForDataReady(callback.callback());
68 EXPECT_EQ(net::OK, callback.GetResult(rv)); 69 EXPECT_EQ(net::OK, callback.GetResult(rv));
69 70
70 net::SSLHostInfo::State* state = ssl_host_info->mutable_state(); 71 net::SSLHostInfo::State* state = ssl_host_info->mutable_state();
71 EXPECT_TRUE(state->certs.empty()); 72 EXPECT_TRUE(state->certs.empty());
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
104 105
105 state = ssl_host_info->mutable_state(); 106 state = ssl_host_info->mutable_state();
106 EXPECT_EQ(2U, state->certs.size()); 107 EXPECT_EQ(2U, state->certs.size());
107 EXPECT_EQ("foo", state->certs[0]); 108 EXPECT_EQ("foo", state->certs[0]);
108 EXPECT_EQ("bar", state->certs[1]); 109 EXPECT_EQ("bar", state->certs[1]);
109 110
110 RemoveMockTransaction(&kHostInfoTransaction); 111 RemoveMockTransaction(&kHostInfoTransaction);
111 } 112 }
112 113
113 } // namespace 114 } // namespace
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698