| Index: net/http/disk_cache_based_ssl_host_info_unittest.cc
|
| diff --git a/net/http/disk_cache_based_ssl_host_info_unittest.cc b/net/http/disk_cache_based_ssl_host_info_unittest.cc
|
| new file mode 100644
|
| index 0000000000000000000000000000000000000000..e53a9e35b1ad6c56826a6f69e183c010927511b3
|
| --- /dev/null
|
| +++ b/net/http/disk_cache_based_ssl_host_info_unittest.cc
|
| @@ -0,0 +1,119 @@
|
| +// Copyright (c) 2012 The Chromium Authors. All rights reserved.
|
| +// Use of this source code is governed by a BSD-style license that can be
|
| +// found in the LICENSE file.
|
| +
|
| +#include "base/bind.h"
|
| +#include "base/bind_helpers.h"
|
| +#include "base/compiler_specific.h"
|
| +#include "base/message_loop/message_loop.h"
|
| +#include "net/base/net_errors.h"
|
| +#include "net/cert/mock_cert_verifier.h"
|
| +#include "net/http/disk_cache_based_ssl_host_info.h"
|
| +#include "net/http/mock_http_cache.h"
|
| +#include "net/socket/ssl_host_info.h"
|
| +#include "net/ssl/ssl_config_service.h"
|
| +#include "testing/gtest/include/gtest/gtest.h"
|
| +
|
| +namespace {
|
| +
|
| +// This is an empty transaction, needed to register the URL and the test mode.
|
| +const MockTransaction kHostInfoTransaction = {
|
| + "sslhostinfo:https://www.google.com",
|
| + "",
|
| + base::Time(),
|
| + "",
|
| + net::LOAD_NORMAL,
|
| + "",
|
| + "",
|
| + base::Time(),
|
| + "",
|
| + TEST_MODE_NORMAL,
|
| + NULL,
|
| + 0
|
| +};
|
| +
|
| +// Tests that we can delete a DiskCacheBasedSSLHostInfo object in a
|
| +// completion callback for DiskCacheBasedSSLHostInfo::WaitForDataReady.
|
| +TEST(DiskCacheBasedSSLHostInfo, DeleteInCallback) {
|
| + scoped_ptr<net::CertVerifier> cert_verifier(new net::MockCertVerifier);
|
| + // Use the blocking mock backend factory to force asynchronous completion
|
| + // of ssl_host_info->WaitForDataReady(), so that the callback will run.
|
| + MockBlockingBackendFactory* factory = new MockBlockingBackendFactory();
|
| + MockHttpCache cache(factory);
|
| + net::SSLConfig ssl_config;
|
| + scoped_ptr<net::SSLHostInfo> ssl_host_info(
|
| + new net::DiskCacheBasedSSLHostInfo("https://www.verisign.com", ssl_config,
|
| + cert_verifier.get(),
|
| + cache.http_cache()));
|
| + ssl_host_info->Start();
|
| + net::TestCompletionCallback callback;
|
| + int rv = ssl_host_info->WaitForDataReady(callback.callback());
|
| + EXPECT_EQ(net::ERR_IO_PENDING, rv);
|
| + // Now complete the backend creation and let the callback run.
|
| + factory->FinishCreation();
|
| + EXPECT_EQ(net::OK, callback.GetResult(rv));
|
| +}
|
| +
|
| +// Tests the basic logic of storing, retrieving and updating data.
|
| +TEST(DiskCacheBasedSSLHostInfo, Update) {
|
| + MockHttpCache cache;
|
| + AddMockTransaction(&kHostInfoTransaction);
|
| + net::TestCompletionCallback callback;
|
| +
|
| + // Store a certificate chain.
|
| + scoped_ptr<net::CertVerifier> cert_verifier(new net::MockCertVerifier);
|
| + net::SSLConfig ssl_config;
|
| + scoped_ptr<net::SSLHostInfo> ssl_host_info(
|
| + new net::DiskCacheBasedSSLHostInfo("https://www.google.com", ssl_config,
|
| + cert_verifier.get(),
|
| + cache.http_cache()));
|
| + ssl_host_info->Start();
|
| + int rv = ssl_host_info->WaitForDataReady(callback.callback());
|
| + EXPECT_EQ(net::OK, callback.GetResult(rv));
|
| +
|
| + net::SSLHostInfo::State* state = ssl_host_info->mutable_state();
|
| + EXPECT_TRUE(state->certs.empty());
|
| + state->certs.push_back(std::string("foo"));
|
| + ssl_host_info->Persist();
|
| +
|
| + // Wait until Persist() does the work.
|
| + base::MessageLoop::current()->RunUntilIdle();
|
| +
|
| + // Open the stored certificate chain.
|
| + ssl_host_info.reset(
|
| + new net::DiskCacheBasedSSLHostInfo("https://www.google.com", ssl_config,
|
| + cert_verifier.get(),
|
| + cache.http_cache()));
|
| + ssl_host_info->Start();
|
| + rv = ssl_host_info->WaitForDataReady(callback.callback());
|
| + EXPECT_EQ(net::OK, callback.GetResult(rv));
|
| +
|
| + // And now update the data.
|
| + state = ssl_host_info->mutable_state();
|
| + EXPECT_EQ(1U, state->certs.size());
|
| + EXPECT_EQ("foo", state->certs.front());
|
| + state->certs.push_back(std::string("bar"));
|
| +
|
| + // Fail instead of DCHECKing double creates.
|
| + cache.disk_cache()->set_double_create_check(false);
|
| + ssl_host_info->Persist();
|
| + base::MessageLoop::current()->RunUntilIdle();
|
| +
|
| + // Verify that the state was updated.
|
| + ssl_host_info.reset(
|
| + new net::DiskCacheBasedSSLHostInfo("https://www.google.com", ssl_config,
|
| + cert_verifier.get(),
|
| + cache.http_cache()));
|
| + ssl_host_info->Start();
|
| + rv = ssl_host_info->WaitForDataReady(callback.callback());
|
| + EXPECT_EQ(net::OK, callback.GetResult(rv));
|
| +
|
| + state = ssl_host_info->mutable_state();
|
| + EXPECT_EQ(2U, state->certs.size());
|
| + EXPECT_EQ("foo", state->certs[0]);
|
| + EXPECT_EQ("bar", state->certs[1]);
|
| +
|
| + RemoveMockTransaction(&kHostInfoTransaction);
|
| +}
|
| +
|
| +} // namespace
|
|
|