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

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

Issue 17127002: Correctly integrate StoragePartition into TestingProfile. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: fix InstantNTP test. Created 7 years, 5 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) 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 "base/message_loop/message_loop.h" 7 #include "base/run_loop.h"
8 #include "content/browser/browser_thread_impl.h" 8 #include "content/browser/browser_thread_impl.h"
9 #include "content/browser/loader/resource_loader_delegate.h" 9 #include "content/browser/loader/resource_loader_delegate.h"
10 #include "content/public/browser/resource_request_info.h" 10 #include "content/public/browser/resource_request_info.h"
11 #include "content/public/test/mock_resource_context.h" 11 #include "content/public/test/mock_resource_context.h"
12 #include "content/public/test/test_browser_thread_bundle.h"
12 #include "content/test/test_content_browser_client.h" 13 #include "content/test/test_content_browser_client.h"
13 #include "net/cert/x509_certificate.h" 14 #include "net/cert/x509_certificate.h"
14 #include "net/ssl/client_cert_store.h" 15 #include "net/ssl/client_cert_store.h"
15 #include "net/ssl/ssl_cert_request_info.h" 16 #include "net/ssl/ssl_cert_request_info.h"
16 #include "net/url_request/url_request.h" 17 #include "net/url_request/url_request.h"
18 #include "net/url_request/url_request_test_util.h"
17 #include "testing/gtest/include/gtest/gtest.h" 19 #include "testing/gtest/include/gtest/gtest.h"
18 20
19 namespace content { 21 namespace content {
20 namespace { 22 namespace {
21 23
22 // Stub client certificate store that returns a preset list of certificates for 24 // Stub client certificate store that returns a preset list of certificates for
23 // each request and records the arguments of the most recent request for later 25 // each request and records the arguments of the most recent request for later
24 // inspection. 26 // inspection.
25 class ClientCertStoreStub : public net::ClientCertStore { 27 class ClientCertStoreStub : public net::ClientCertStore {
26 public: 28 public:
(...skipping 110 matching lines...) Expand 10 before | Expand all | Expand 10 after
137 private: 139 private:
138 net::CertificateList passed_certs_; 140 net::CertificateList passed_certs_;
139 int call_count_; 141 int call_count_;
140 }; 142 };
141 143
142 } // namespace 144 } // namespace
143 145
144 class ResourceLoaderTest : public testing::Test, 146 class ResourceLoaderTest : public testing::Test,
145 public ResourceLoaderDelegate { 147 public ResourceLoaderDelegate {
146 protected: 148 protected:
147 // testing::Test: 149 ResourceLoaderTest()
148 virtual void SetUp() OVERRIDE { 150 : thread_bundle_(content::TestBrowserThreadBundle::IO_MAINLOOP),
149 message_loop_.reset(new base::MessageLoop(base::MessageLoop::TYPE_IO)); 151 resource_context_(&test_url_request_context_) {
150 ui_thread_.reset(
151 new BrowserThreadImpl(BrowserThread::UI, message_loop_.get()));
152 io_thread_.reset(new BrowserThreadImpl(BrowserThread::IO,
153 message_loop_.get()));
154 } 152 }
155 153
156 // ResourceLoaderDelegate: 154 // ResourceLoaderDelegate:
157 virtual ResourceDispatcherHostLoginDelegate* CreateLoginDelegate( 155 virtual ResourceDispatcherHostLoginDelegate* CreateLoginDelegate(
158 ResourceLoader* loader, 156 ResourceLoader* loader,
159 net::AuthChallengeInfo* auth_info) OVERRIDE { 157 net::AuthChallengeInfo* auth_info) OVERRIDE {
160 return NULL; 158 return NULL;
161 } 159 }
162 virtual bool AcceptAuthRequest( 160 virtual bool AcceptAuthRequest(
163 ResourceLoader* loader, 161 ResourceLoader* loader,
164 net::AuthChallengeInfo* auth_info) OVERRIDE { 162 net::AuthChallengeInfo* auth_info) OVERRIDE {
165 return false; 163 return false;
166 }; 164 };
167 virtual bool AcceptSSLClientCertificateRequest( 165 virtual bool AcceptSSLClientCertificateRequest(
168 ResourceLoader* loader, 166 ResourceLoader* loader,
169 net::SSLCertRequestInfo* cert_info) OVERRIDE { 167 net::SSLCertRequestInfo* cert_info) OVERRIDE {
170 return true; 168 return true;
171 } 169 }
172 virtual bool HandleExternalProtocol(ResourceLoader* loader, 170 virtual bool HandleExternalProtocol(ResourceLoader* loader,
173 const GURL& url) OVERRIDE { 171 const GURL& url) OVERRIDE {
174 return false; 172 return false;
175 } 173 }
176 virtual void DidStartRequest(ResourceLoader* loader) OVERRIDE {} 174 virtual void DidStartRequest(ResourceLoader* loader) OVERRIDE {}
177 virtual void DidReceiveRedirect(ResourceLoader* loader, 175 virtual void DidReceiveRedirect(ResourceLoader* loader,
178 const GURL& new_url) OVERRIDE {} 176 const GURL& new_url) OVERRIDE {}
179 virtual void DidReceiveResponse(ResourceLoader* loader) OVERRIDE {} 177 virtual void DidReceiveResponse(ResourceLoader* loader) OVERRIDE {}
180 virtual void DidFinishLoading(ResourceLoader* loader) OVERRIDE {} 178 virtual void DidFinishLoading(ResourceLoader* loader) OVERRIDE {}
181 179
182 scoped_ptr<base::MessageLoop> message_loop_; 180 content::TestBrowserThreadBundle thread_bundle_;
183 scoped_ptr<BrowserThreadImpl> ui_thread_;
184 scoped_ptr<BrowserThreadImpl> io_thread_;
185 181
182 net::TestURLRequestContext test_url_request_context_;
186 content::MockResourceContext resource_context_; 183 content::MockResourceContext resource_context_;
187 }; 184 };
188 185
189 // When OpenSSL is used, client cert store is not being queried in 186 // When OpenSSL is used, client cert store is not being queried in
190 // ResourceLoader. 187 // ResourceLoader.
191 #if !defined(USE_OPENSSL) 188 #if !defined(USE_OPENSSL)
192 // Verifies if a call to net::UrlRequest::Delegate::OnCertificateRequested() 189 // Verifies if a call to net::UrlRequest::Delegate::OnCertificateRequested()
193 // causes client cert store to be queried for certificates and if the returned 190 // causes client cert store to be queried for certificates and if the returned
194 // certificates are correctly passed to the content browser client for 191 // certificates are correctly passed to the content browser client for
195 // selection. 192 // selection.
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
229 std::vector<std::string> dummy_authority(1, "dummy"); 226 std::vector<std::string> dummy_authority(1, "dummy");
230 cert_request_info->cert_authorities = dummy_authority; 227 cert_request_info->cert_authorities = dummy_authority;
231 228
232 // Plug in test content browser client. 229 // Plug in test content browser client.
233 SelectCertificateBrowserClient test_client; 230 SelectCertificateBrowserClient test_client;
234 ContentBrowserClient* old_client = SetBrowserClientForTesting(&test_client); 231 ContentBrowserClient* old_client = SetBrowserClientForTesting(&test_client);
235 232
236 // Everything is set up. Trigger the resource loader certificate request event 233 // Everything is set up. Trigger the resource loader certificate request event
237 // and run the message loop. 234 // and run the message loop.
238 loader.OnCertificateRequested(raw_ptr_to_request, cert_request_info.get()); 235 loader.OnCertificateRequested(raw_ptr_to_request, cert_request_info.get());
239 message_loop_->RunUntilIdle(); 236 base::RunLoop().RunUntilIdle();
240 237
241 // Restore the original content browser client. 238 // Restore the original content browser client.
242 SetBrowserClientForTesting(old_client); 239 SetBrowserClientForTesting(old_client);
243 240
244 // Check if the test store was queried against correct |cert_authorities|. 241 // Check if the test store was queried against correct |cert_authorities|.
245 EXPECT_EQ(1, raw_ptr_to_store->request_count()); 242 EXPECT_EQ(1, raw_ptr_to_store->request_count());
246 EXPECT_EQ(dummy_authority, raw_ptr_to_store->requested_authorities()); 243 EXPECT_EQ(dummy_authority, raw_ptr_to_store->requested_authorities());
247 244
248 // Check if the retrieved certificates were passed to the content browser 245 // Check if the retrieved certificates were passed to the content browser
249 // client. 246 // client.
250 EXPECT_EQ(1, test_client.call_count()); 247 EXPECT_EQ(1, test_client.call_count());
251 EXPECT_EQ(dummy_certs, test_client.passed_certs()); 248 EXPECT_EQ(dummy_certs, test_client.passed_certs());
252 } 249 }
253 #endif // !defined(OPENSSL) 250 #endif // !defined(OPENSSL)
254 251
255 } // namespace content 252 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698