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

Side by Side Diff: content/browser/loader/resource_loader_unittest.cc

Issue 2838243002: Remove client_certs from SSLCertRequestInfo. (Closed)
Patch Set: revert stray whitespace change Created 3 years, 7 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
OLDNEW
1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2013 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 "content/browser/loader/resource_loader.h" 5 #include "content/browser/loader/resource_loader.h"
6 6
7 #include <stddef.h> 7 #include <stddef.h>
8 #include <stdint.h> 8 #include <stdint.h>
9 9
10 #include <deque> 10 #include <deque>
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after
83 requested_authorities_(requested_authorities), 83 requested_authorities_(requested_authorities),
84 request_count_(request_count) { 84 request_count_(request_count) {
85 requested_authorities_->clear(); 85 requested_authorities_->clear();
86 *request_count_ = 0; 86 *request_count_ = 0;
87 } 87 }
88 88
89 ~ClientCertStoreStub() override {} 89 ~ClientCertStoreStub() override {}
90 90
91 // net::ClientCertStore: 91 // net::ClientCertStore:
92 void GetClientCerts(const net::SSLCertRequestInfo& cert_request_info, 92 void GetClientCerts(const net::SSLCertRequestInfo& cert_request_info,
93 net::CertificateList* selected_certs, 93 const ClientCertListCallback& callback) override {
94 const base::Closure& callback) override {
95 *requested_authorities_ = cert_request_info.cert_authorities; 94 *requested_authorities_ = cert_request_info.cert_authorities;
96 ++(*request_count_); 95 ++(*request_count_);
97 96
98 *selected_certs = response_; 97 callback.Run(response_);
99 callback.Run();
100 } 98 }
101 99
102 private: 100 private:
103 const net::CertificateList response_; 101 const net::CertificateList response_;
104 std::vector<std::string>* requested_authorities_; 102 std::vector<std::string>* requested_authorities_;
105 int* request_count_; 103 int* request_count_;
106 }; 104 };
107 105
108 // Client certificate store which destroys its resource loader before the 106 // Client certificate store which destroys its resource loader before the
109 // asynchronous GetClientCerts callback is called. 107 // asynchronous GetClientCerts callback is called.
110 class LoaderDestroyingCertStore : public net::ClientCertStore { 108 class LoaderDestroyingCertStore : public net::ClientCertStore {
111 public: 109 public:
112 // Creates a client certificate store which, when looked up, posts a task to 110 // Creates a client certificate store which, when looked up, posts a task to
113 // reset |loader| and then call the callback. The caller is responsible for 111 // reset |loader| and then call the callback. The caller is responsible for
114 // ensuring the pointers remain valid until the process is complete. 112 // ensuring the pointers remain valid until the process is complete.
115 LoaderDestroyingCertStore(std::unique_ptr<ResourceLoader>* loader, 113 LoaderDestroyingCertStore(std::unique_ptr<ResourceLoader>* loader,
116 const base::Closure& on_loader_deleted_callback) 114 const base::Closure& on_loader_deleted_callback)
117 : loader_(loader), 115 : loader_(loader),
118 on_loader_deleted_callback_(on_loader_deleted_callback) {} 116 on_loader_deleted_callback_(on_loader_deleted_callback) {}
119 117
120 // net::ClientCertStore: 118 // net::ClientCertStore:
121 void GetClientCerts(const net::SSLCertRequestInfo& cert_request_info, 119 void GetClientCerts(
122 net::CertificateList* selected_certs, 120 const net::SSLCertRequestInfo& cert_request_info,
123 const base::Closure& cert_selected_callback) override { 121 const ClientCertListCallback& cert_selected_callback) override {
124 // Don't destroy |loader_| while it's on the stack. 122 // Don't destroy |loader_| while it's on the stack.
125 base::ThreadTaskRunnerHandle::Get()->PostTask( 123 base::ThreadTaskRunnerHandle::Get()->PostTask(
126 FROM_HERE, base::Bind(&LoaderDestroyingCertStore::DoCallback, 124 FROM_HERE, base::Bind(&LoaderDestroyingCertStore::DoCallback,
127 base::Unretained(loader_), 125 base::Unretained(loader_), cert_selected_callback,
128 cert_selected_callback,
129 on_loader_deleted_callback_)); 126 on_loader_deleted_callback_));
130 } 127 }
131 128
132 private: 129 private:
133 // This needs to be static because |loader| owns the 130 // This needs to be static because |loader| owns the
134 // LoaderDestroyingCertStore (ClientCertStores are actually handles, and not 131 // LoaderDestroyingCertStore (ClientCertStores are actually handles, and not
135 // global cert stores). 132 // global cert stores).
136 static void DoCallback(std::unique_ptr<ResourceLoader>* loader, 133 static void DoCallback(std::unique_ptr<ResourceLoader>* loader,
137 const base::Closure& cert_selected_callback, 134 const ClientCertListCallback& cert_selected_callback,
138 const base::Closure& on_loader_deleted_callback) { 135 const base::Closure& on_loader_deleted_callback) {
139 loader->reset(); 136 loader->reset();
140 cert_selected_callback.Run(); 137 cert_selected_callback.Run(net::CertificateList());
141 on_loader_deleted_callback.Run(); 138 on_loader_deleted_callback.Run();
142 } 139 }
143 140
144 std::unique_ptr<ResourceLoader>* loader_; 141 std::unique_ptr<ResourceLoader>* loader_;
145 base::Closure on_loader_deleted_callback_; 142 base::Closure on_loader_deleted_callback_;
146 143
147 DISALLOW_COPY_AND_ASSIGN(LoaderDestroyingCertStore); 144 DISALLOW_COPY_AND_ASSIGN(LoaderDestroyingCertStore);
148 }; 145 };
149 146
150 // A mock URLRequestJob which simulates an SSL client auth request. 147 // A mock URLRequestJob which simulates an SSL client auth request.
(...skipping 122 matching lines...) Expand 10 before | Expand all | Expand 10 after
273 void WaitForSelectCertificate() { 270 void WaitForSelectCertificate() {
274 select_certificate_run_loop_.Run(); 271 select_certificate_run_loop_.Run();
275 // Process any pending messages - just so tests can check if 272 // Process any pending messages - just so tests can check if
276 // SelectClientCertificate was called more than once. 273 // SelectClientCertificate was called more than once.
277 base::RunLoop().RunUntilIdle(); 274 base::RunLoop().RunUntilIdle();
278 } 275 }
279 276
280 void SelectClientCertificate( 277 void SelectClientCertificate(
281 WebContents* web_contents, 278 WebContents* web_contents,
282 net::SSLCertRequestInfo* cert_request_info, 279 net::SSLCertRequestInfo* cert_request_info,
280 net::CertificateList client_certs,
283 std::unique_ptr<ClientCertificateDelegate> delegate) override { 281 std::unique_ptr<ClientCertificateDelegate> delegate) override {
284 EXPECT_FALSE(delegate_.get()); 282 EXPECT_FALSE(delegate_.get());
285 283
286 ++call_count_; 284 ++call_count_;
287 passed_certs_ = cert_request_info->client_certs; 285 passed_certs_ = std::move(client_certs);
288 delegate_ = std::move(delegate); 286 delegate_ = std::move(delegate);
289 select_certificate_run_loop_.Quit(); 287 select_certificate_run_loop_.Quit();
290 } 288 }
291 289
292 int call_count() { return call_count_; } 290 int call_count() { return call_count_; }
293 net::CertificateList passed_certs() { return passed_certs_; } 291 net::CertificateList passed_certs() { return passed_certs_; }
294 292
295 void ContinueWithCertificate(net::X509Certificate* cert) { 293 void ContinueWithCertificate(net::X509Certificate* cert) {
296 delegate_->ContinueWithCertificate(cert); 294 delegate_->ContinueWithCertificate(cert);
297 delegate_.reset(); 295 delegate_.reset();
(...skipping 1261 matching lines...) Expand 10 before | Expand all | Expand 10 after
1559 1557
1560 // Tests that the effective connection type is not set on non-main frame 1558 // Tests that the effective connection type is not set on non-main frame
1561 // requests. 1559 // requests.
1562 TEST_F(EffectiveConnectionTypeResourceLoaderTest, DoesNotBelongToMainFrame) { 1560 TEST_F(EffectiveConnectionTypeResourceLoaderTest, DoesNotBelongToMainFrame) {
1563 VerifyEffectiveConnectionType(RESOURCE_TYPE_OBJECT, false, 1561 VerifyEffectiveConnectionType(RESOURCE_TYPE_OBJECT, false,
1564 net::EFFECTIVE_CONNECTION_TYPE_3G, 1562 net::EFFECTIVE_CONNECTION_TYPE_3G,
1565 net::EFFECTIVE_CONNECTION_TYPE_UNKNOWN); 1563 net::EFFECTIVE_CONNECTION_TYPE_UNKNOWN);
1566 } 1564 }
1567 1565
1568 } // namespace content 1566 } // namespace content
OLDNEW
« no previous file with comments | « chromecast/browser/cast_content_browser_client.cc ('k') | content/browser/ssl/ssl_client_auth_handler.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698