summaryrefslogtreecommitdiffstats
path: root/content/browser/loader/resource_loader_unittest.cc
diff options
context:
space:
mode:
authordavidben <davidben@chromium.org>2014-12-12 11:23:57 -0800
committerCommit bot <commit-bot@chromium.org>2014-12-12 19:24:22 +0000
commit6cd57dd5cbca53c416f099b985444225d676362a (patch)
tree9f319c853ae3765a0df028ee74973c43247cc527 /content/browser/loader/resource_loader_unittest.cc
parentdebbbb3734c02a339a79f285a6f2c468e275bbb7 (diff)
downloadchromium_src-6cd57dd5cbca53c416f099b985444225d676362a.zip
chromium_src-6cd57dd5cbca53c416f099b985444225d676362a.tar.gz
chromium_src-6cd57dd5cbca53c416f099b985444225d676362a.tar.bz2
Un-refcount SSLClientAuthHandler.
That class doesn't really need to be ref-counted externally. There is one catch: the caller is responsible for ensuring ClientCertStore is alive for the duration of its async operation. Resolve this by detaching it into a ref-counted Core internal to SSLClientAuthHandler. Add a test to test this case. Also make ContentBrowserClient's default client auth hook always select no certificate so content_shell doesn't hang. This relands the rest of https://codereview.chromium.org/596873002 BUG=439134 Review URL: https://codereview.chromium.org/795773002 Cr-Commit-Position: refs/heads/master@{#308142}
Diffstat (limited to 'content/browser/loader/resource_loader_unittest.cc')
-rw-r--r--content/browser/loader/resource_loader_unittest.cc46
1 files changed, 43 insertions, 3 deletions
diff --git a/content/browser/loader/resource_loader_unittest.cc b/content/browser/loader/resource_loader_unittest.cc
index 2af4ffc..9123107 100644
--- a/content/browser/loader/resource_loader_unittest.cc
+++ b/content/browser/loader/resource_loader_unittest.cc
@@ -41,11 +41,13 @@ namespace {
class ClientCertStoreStub : public net::ClientCertStore {
public:
ClientCertStoreStub(const net::CertificateList& certs)
- : response_(certs),
- request_count_(0) {}
+ : response_(certs), async_(false), request_count_(0) {}
~ClientCertStoreStub() override {}
+ // Configures whether the certificates are returned asynchronously or not.
+ void set_async(bool async) { async_ = async; }
+
// Returns |cert_authorities| field of the certificate request passed in the
// most recent call to GetClientCerts().
// TODO(ppi): Make the stub independent from the internal representation of
@@ -68,11 +70,16 @@ class ClientCertStoreStub : public net::ClientCertStore {
++request_count_;
requested_authorities_ = cert_request_info.cert_authorities;
*selected_certs = response_;
- callback.Run();
+ if (async_) {
+ base::MessageLoop::current()->PostTask(FROM_HERE, callback);
+ } else {
+ callback.Run();
+ }
}
private:
const net::CertificateList response_;
+ bool async_;
int request_count_;
std::vector<std::string> requested_authorities_;
};
@@ -437,6 +444,39 @@ TEST_F(ResourceLoaderTest, ClientCertStoreNull) {
EXPECT_EQ(net::CertificateList(), test_client.passed_certs());
}
+TEST_F(ResourceLoaderTest, ClientCertStoreAsyncCancel) {
+ // Set up the test client cert store.
+ scoped_ptr<ClientCertStoreStub> test_store(
+ new ClientCertStoreStub(net::CertificateList()));
+ test_store->set_async(true);
+ EXPECT_EQ(0, test_store->request_count());
+
+ // Ownership of the |test_store| is about to be turned over to ResourceLoader.
+ // We need to keep raw pointer copies to access these objects later.
+ ClientCertStoreStub* raw_ptr_to_store = test_store.get();
+ resource_context_.SetClientCertStore(test_store.Pass());
+
+ // Prepare a dummy certificate request.
+ scoped_refptr<net::SSLCertRequestInfo> cert_request_info(
+ new net::SSLCertRequestInfo());
+ std::vector<std::string> dummy_authority(1, "dummy");
+ cert_request_info->cert_authorities = dummy_authority;
+
+ // Everything is set up. Trigger the resource loader certificate request
+ // event.
+ loader_->OnCertificateRequested(raw_ptr_to_request_, cert_request_info.get());
+
+ // Check if the test store was queried against correct |cert_authorities|.
+ EXPECT_EQ(1, raw_ptr_to_store->request_count());
+ EXPECT_EQ(dummy_authority, raw_ptr_to_store->requested_authorities());
+
+ // Cancel the request before the store calls the callback.
+ loader_.reset();
+
+ // Pump the event loop. There shouldn't be a crash when the callback is run.
+ base::RunLoop().RunUntilIdle();
+}
+
TEST_F(ResourceLoaderTest, ResumeCancelledRequest) {
raw_ptr_resource_handler_->set_defer_request_on_will_start(true);