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

Side by Side Diff: net/url_request/url_request_unittest.cc

Issue 43115: Change the bad-certificate handler for SSL (using NSS) to return an... (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: '' Created 11 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) 2006-2008 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2006-2008 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 "net/url_request/url_request_unittest.h" 5 #include "net/url_request/url_request_unittest.h"
6 6
7 #include "build/build_config.h" 7 #include "build/build_config.h"
8 8
9 #if defined(OS_WIN) 9 #if defined(OS_WIN)
10 #include <windows.h> 10 #include <windows.h>
(...skipping 183 matching lines...) Expand 10 before | Expand all | Expand 10 after
194 DCHECK_EQ(url_request_metrics.object_count, 0); 194 DCHECK_EQ(url_request_metrics.object_count, 0);
195 #endif 195 #endif
196 } 196 }
197 197
198 class HTTPSRequestTest : public testing::Test { 198 class HTTPSRequestTest : public testing::Test {
199 }; 199 };
200 200
201 #if defined(OS_MACOSX) 201 #if defined(OS_MACOSX)
202 // ssl_client_socket_mac.cc crashes currently in GetSSLInfo 202 // ssl_client_socket_mac.cc crashes currently in GetSSLInfo
203 // when called on a connection with an unrecognized certificate 203 // when called on a connection with an unrecognized certificate
204 #define MAYBE_HTTPSGetTest DISABLED_HTTPSGetTest 204 #define MAYBE_HTTPSGetTest DISABLED_HTTPSGetTest
205 #define MAYBE_HTTPSMismatchedTest DISABLED_HTTPSMismatchedTest
206 #define MAYBE_HTTPSExpiredTest DISABLED_HTTPSExpiredTest
205 #else 207 #else
206 #define MAYBE_HTTPSGetTest HTTPSGetTest 208 #define MAYBE_HTTPSGetTest HTTPSGetTest
209 #define MAYBE_HTTPSMismatchedTest HTTPSMismatchedTest
210 #define MAYBE_HTTPSExpiredTest HTTPSExpiredTest
207 #endif 211 #endif
208 212
209 TEST_F(HTTPSRequestTest, MAYBE_HTTPSGetTest) { 213 TEST_F(HTTPSRequestTest, MAYBE_HTTPSGetTest) {
210 // Note: tools/testserver/testserver.py does not need 214 // Note: tools/testserver/testserver.py does not need
211 // a working document root to server the pages / and /hello.html, 215 // a working document root to server the pages / and /hello.html,
212 // so this test doesn't really need to specify a document root. 216 // so this test doesn't really need to specify a document root.
213 // But if it did, a good one would be net/data/ssl. 217 // But if it did, a good one would be net/data/ssl.
214 scoped_refptr<HTTPSTestServer> server = 218 scoped_refptr<HTTPSTestServer> server =
215 HTTPSTestServer::CreateGoodServer(L"net/data/ssl"); 219 HTTPSTestServer::CreateGoodServer(L"net/data/ssl");
216 ASSERT_TRUE(NULL != server.get()); 220 ASSERT_TRUE(NULL != server.get());
217 221
218 TestDelegate d; 222 TestDelegate d;
219 { 223 {
220 TestURLRequest r(server->TestServerPage(""), &d); 224 TestURLRequest r(server->TestServerPage(""), &d);
221 225
222 r.Start(); 226 r.Start();
223 EXPECT_TRUE(r.is_pending()); 227 EXPECT_TRUE(r.is_pending());
224 228
225 MessageLoop::current()->Run(); 229 MessageLoop::current()->Run();
226 230
227 EXPECT_EQ(1, d.response_started_count()); 231 EXPECT_EQ(1, d.response_started_count());
228 EXPECT_FALSE(d.received_data_before_response()); 232 EXPECT_FALSE(d.received_data_before_response());
229 EXPECT_NE(0, d.bytes_received()); 233 EXPECT_NE(0, d.bytes_received());
230 } 234 }
231 #ifndef NDEBUG 235 #ifndef NDEBUG
232 DCHECK_EQ(url_request_metrics.object_count, 0); 236 DCHECK_EQ(url_request_metrics.object_count, 0);
233 #endif 237 #endif
234 } 238 }
235 239
236 // TODO(dkegel): add test for expired and mismatched certificates here 240 TEST_F(HTTPSRequestTest, MAYBE_HTTPSMismatchedTest) {
241 scoped_refptr<HTTPSTestServer> server =
242 HTTPSTestServer::CreateMismatchedServer(L"net/data/ssl");
243 ASSERT_TRUE(NULL != server.get());
244
245 bool err_allowed = true;
246 for (int i = 0; i < 2 ; i++, err_allowed = !err_allowed) {
247 TestDelegate d;
248 {
249 d.set_allow_certificate_errors(err_allowed);
250 TestURLRequest r(server->TestServerPage(""), &d);
251
252 r.Start();
253 EXPECT_TRUE(r.is_pending());
254
255 MessageLoop::current()->Run();
256
257 EXPECT_EQ(1, d.response_started_count());
258 EXPECT_FALSE(d.received_data_before_response());
259 EXPECT_TRUE(d.have_certificate_errors());
260 if (err_allowed)
261 EXPECT_NE(0, d.bytes_received());
262 else
263 EXPECT_EQ(0, d.bytes_received());
264 }
265 }
266 }
267
268 TEST_F(HTTPSRequestTest, MAYBE_HTTPSExpiredTest) {
269 scoped_refptr<HTTPSTestServer> server =
270 HTTPSTestServer::CreateExpiredServer(L"net/data/ssl");
271 ASSERT_TRUE(NULL != server.get());
272
273 // Iterate from false to true, just so that we do the opposite of the
274 // previous test in order to increase test coverage.
275 bool err_allowed = false;
276 for (int i = 0; i < 2 ; i++, err_allowed = !err_allowed) {
277 TestDelegate d;
278 {
279 d.set_allow_certificate_errors(err_allowed);
280 TestURLRequest r(server->TestServerPage(""), &d);
281
282 r.Start();
283 EXPECT_TRUE(r.is_pending());
284
285 MessageLoop::current()->Run();
286
287 EXPECT_EQ(1, d.response_started_count());
288 EXPECT_FALSE(d.received_data_before_response());
289 EXPECT_TRUE(d.have_certificate_errors());
290 if (err_allowed)
291 EXPECT_NE(0, d.bytes_received());
292 else
293 EXPECT_EQ(0, d.bytes_received());
294 }
295 }
296 }
237 297
238 TEST_F(URLRequestTest, CancelTest) { 298 TEST_F(URLRequestTest, CancelTest) {
239 TestDelegate d; 299 TestDelegate d;
240 { 300 {
241 TestURLRequest r(GURL("http://www.google.com/"), &d); 301 TestURLRequest r(GURL("http://www.google.com/"), &d);
242 302
243 r.Start(); 303 r.Start();
244 EXPECT_TRUE(r.is_pending()); 304 EXPECT_TRUE(r.is_pending());
245 305
246 r.Cancel(); 306 r.Cancel();
(...skipping 907 matching lines...) Expand 10 before | Expand all | Expand 10 after
1154 1214
1155 int64 file_size = 0; 1215 int64 file_size = 0;
1156 file_util::GetFileSize(app_path, &file_size); 1216 file_util::GetFileSize(app_path, &file_size);
1157 1217
1158 EXPECT_TRUE(!r.is_pending()); 1218 EXPECT_TRUE(!r.is_pending());
1159 EXPECT_EQ(1, d.response_started_count()); 1219 EXPECT_EQ(1, d.response_started_count());
1160 EXPECT_FALSE(d.received_data_before_response()); 1220 EXPECT_FALSE(d.received_data_before_response());
1161 EXPECT_EQ(d.bytes_received(), 0); 1221 EXPECT_EQ(d.bytes_received(), 0);
1162 } 1222 }
1163 } 1223 }
OLDNEW
« net/http/http_network_transaction_unittest.cc ('K') | « net/url_request/url_request_unittest.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698