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

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

Issue 13145003: Rewrite std::string("") to std::string(), Linux edition. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Ugh Created 7 years, 8 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) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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 "build/build_config.h" 5 #include "build/build_config.h"
6 6
7 #if defined(OS_WIN) 7 #if defined(OS_WIN)
8 #include <windows.h> 8 #include <windows.h>
9 #include <shlobj.h> 9 #include <shlobj.h>
10 #endif 10 #endif
(...skipping 2559 matching lines...) Expand 10 before | Expand all | Expand 10 after
2570 BlockingNetworkDelegate network_delegate( 2570 BlockingNetworkDelegate network_delegate(
2571 BlockingNetworkDelegate::AUTO_CALLBACK); 2571 BlockingNetworkDelegate::AUTO_CALLBACK);
2572 network_delegate.set_block_on(BlockingNetworkDelegate::ON_BEFORE_URL_REQUEST); 2572 network_delegate.set_block_on(BlockingNetworkDelegate::ON_BEFORE_URL_REQUEST);
2573 network_delegate.set_retval(ERR_EMPTY_RESPONSE); 2573 network_delegate.set_retval(ERR_EMPTY_RESPONSE);
2574 2574
2575 TestURLRequestContextWithProxy context( 2575 TestURLRequestContextWithProxy context(
2576 test_server_.host_port_pair().ToString(), 2576 test_server_.host_port_pair().ToString(),
2577 &network_delegate); 2577 &network_delegate);
2578 2578
2579 { 2579 {
2580 URLRequest r(test_server_.GetURL(""), &d, &context); 2580 URLRequest r(test_server_.GetURL(std::string()), &d, &context);
2581 2581
2582 r.Start(); 2582 r.Start();
2583 MessageLoop::current()->Run(); 2583 MessageLoop::current()->Run();
2584 2584
2585 EXPECT_EQ(URLRequestStatus::FAILED, r.status().status()); 2585 EXPECT_EQ(URLRequestStatus::FAILED, r.status().status());
2586 EXPECT_EQ(ERR_EMPTY_RESPONSE, r.status().error()); 2586 EXPECT_EQ(ERR_EMPTY_RESPONSE, r.status().error());
2587 EXPECT_EQ(1, network_delegate.created_requests()); 2587 EXPECT_EQ(1, network_delegate.created_requests());
2588 EXPECT_EQ(0, network_delegate.destroyed_requests()); 2588 EXPECT_EQ(0, network_delegate.destroyed_requests());
2589 } 2589 }
2590 EXPECT_EQ(1, network_delegate.destroyed_requests()); 2590 EXPECT_EQ(1, network_delegate.destroyed_requests());
(...skipping 28 matching lines...) Expand all
2619 } 2619 }
2620 EXPECT_EQ(1, network_delegate.destroyed_requests()); 2620 EXPECT_EQ(1, network_delegate.destroyed_requests());
2621 } 2621 }
2622 2622
2623 // The following 3 tests check that the network delegate can cancel a request 2623 // The following 3 tests check that the network delegate can cancel a request
2624 // synchronously in various stages of the request. 2624 // synchronously in various stages of the request.
2625 TEST_F(URLRequestTestHTTP, NetworkDelegateCancelRequestSynchronously1) { 2625 TEST_F(URLRequestTestHTTP, NetworkDelegateCancelRequestSynchronously1) {
2626 ASSERT_TRUE(test_server_.Start()); 2626 ASSERT_TRUE(test_server_.Start());
2627 NetworkDelegateCancelRequest(BlockingNetworkDelegate::SYNCHRONOUS, 2627 NetworkDelegateCancelRequest(BlockingNetworkDelegate::SYNCHRONOUS,
2628 BlockingNetworkDelegate::ON_BEFORE_URL_REQUEST, 2628 BlockingNetworkDelegate::ON_BEFORE_URL_REQUEST,
2629 test_server_.GetURL("")); 2629 test_server_.GetURL(std::string()));
2630 } 2630 }
2631 2631
2632 TEST_F(URLRequestTestHTTP, NetworkDelegateCancelRequestSynchronously2) { 2632 TEST_F(URLRequestTestHTTP, NetworkDelegateCancelRequestSynchronously2) {
2633 ASSERT_TRUE(test_server_.Start()); 2633 ASSERT_TRUE(test_server_.Start());
2634 NetworkDelegateCancelRequest(BlockingNetworkDelegate::SYNCHRONOUS, 2634 NetworkDelegateCancelRequest(BlockingNetworkDelegate::SYNCHRONOUS,
2635 BlockingNetworkDelegate::ON_BEFORE_SEND_HEADERS, 2635 BlockingNetworkDelegate::ON_BEFORE_SEND_HEADERS,
2636 test_server_.GetURL("")); 2636 test_server_.GetURL(std::string()));
2637 } 2637 }
2638 2638
2639 TEST_F(URLRequestTestHTTP, NetworkDelegateCancelRequestSynchronously3) { 2639 TEST_F(URLRequestTestHTTP, NetworkDelegateCancelRequestSynchronously3) {
2640 ASSERT_TRUE(test_server_.Start()); 2640 ASSERT_TRUE(test_server_.Start());
2641 NetworkDelegateCancelRequest(BlockingNetworkDelegate::SYNCHRONOUS, 2641 NetworkDelegateCancelRequest(BlockingNetworkDelegate::SYNCHRONOUS,
2642 BlockingNetworkDelegate::ON_HEADERS_RECEIVED, 2642 BlockingNetworkDelegate::ON_HEADERS_RECEIVED,
2643 test_server_.GetURL("")); 2643 test_server_.GetURL(std::string()));
2644 } 2644 }
2645 2645
2646 // The following 3 tests check that the network delegate can cancel a request 2646 // The following 3 tests check that the network delegate can cancel a request
2647 // asynchronously in various stages of the request. 2647 // asynchronously in various stages of the request.
2648 TEST_F(URLRequestTestHTTP, NetworkDelegateCancelRequestAsynchronously1) { 2648 TEST_F(URLRequestTestHTTP, NetworkDelegateCancelRequestAsynchronously1) {
2649 ASSERT_TRUE(test_server_.Start()); 2649 ASSERT_TRUE(test_server_.Start());
2650 NetworkDelegateCancelRequest(BlockingNetworkDelegate::AUTO_CALLBACK, 2650 NetworkDelegateCancelRequest(BlockingNetworkDelegate::AUTO_CALLBACK,
2651 BlockingNetworkDelegate::ON_BEFORE_URL_REQUEST, 2651 BlockingNetworkDelegate::ON_BEFORE_URL_REQUEST,
2652 test_server_.GetURL("")); 2652 test_server_.GetURL(std::string()));
2653 } 2653 }
2654 2654
2655 TEST_F(URLRequestTestHTTP, NetworkDelegateCancelRequestAsynchronously2) { 2655 TEST_F(URLRequestTestHTTP, NetworkDelegateCancelRequestAsynchronously2) {
2656 ASSERT_TRUE(test_server_.Start()); 2656 ASSERT_TRUE(test_server_.Start());
2657 NetworkDelegateCancelRequest(BlockingNetworkDelegate::AUTO_CALLBACK, 2657 NetworkDelegateCancelRequest(BlockingNetworkDelegate::AUTO_CALLBACK,
2658 BlockingNetworkDelegate::ON_BEFORE_SEND_HEADERS, 2658 BlockingNetworkDelegate::ON_BEFORE_SEND_HEADERS,
2659 test_server_.GetURL("")); 2659 test_server_.GetURL(std::string()));
2660 } 2660 }
2661 2661
2662 TEST_F(URLRequestTestHTTP, NetworkDelegateCancelRequestAsynchronously3) { 2662 TEST_F(URLRequestTestHTTP, NetworkDelegateCancelRequestAsynchronously3) {
2663 ASSERT_TRUE(test_server_.Start()); 2663 ASSERT_TRUE(test_server_.Start());
2664 NetworkDelegateCancelRequest(BlockingNetworkDelegate::AUTO_CALLBACK, 2664 NetworkDelegateCancelRequest(BlockingNetworkDelegate::AUTO_CALLBACK,
2665 BlockingNetworkDelegate::ON_HEADERS_RECEIVED, 2665 BlockingNetworkDelegate::ON_HEADERS_RECEIVED,
2666 test_server_.GetURL("")); 2666 test_server_.GetURL(std::string()));
2667 } 2667 }
2668 2668
2669 // Tests that the network delegate can block and redirect a request to a new 2669 // Tests that the network delegate can block and redirect a request to a new
2670 // URL. 2670 // URL.
2671 TEST_F(URLRequestTestHTTP, NetworkDelegateRedirectRequest) { 2671 TEST_F(URLRequestTestHTTP, NetworkDelegateRedirectRequest) {
2672 ASSERT_TRUE(test_server_.Start()); 2672 ASSERT_TRUE(test_server_.Start());
2673 2673
2674 TestDelegate d; 2674 TestDelegate d;
2675 BlockingNetworkDelegate network_delegate( 2675 BlockingNetworkDelegate network_delegate(
2676 BlockingNetworkDelegate::AUTO_CALLBACK); 2676 BlockingNetworkDelegate::AUTO_CALLBACK);
(...skipping 308 matching lines...) Expand 10 before | Expand all | Expand 10 after
2985 TestDelegate d; 2985 TestDelegate d;
2986 BlockingNetworkDelegate network_delegate( 2986 BlockingNetworkDelegate network_delegate(
2987 BlockingNetworkDelegate::USER_CALLBACK); 2987 BlockingNetworkDelegate::USER_CALLBACK);
2988 network_delegate.set_block_on(BlockingNetworkDelegate::ON_BEFORE_URL_REQUEST); 2988 network_delegate.set_block_on(BlockingNetworkDelegate::ON_BEFORE_URL_REQUEST);
2989 2989
2990 TestURLRequestContext context(true); 2990 TestURLRequestContext context(true);
2991 context.set_network_delegate(&network_delegate); 2991 context.set_network_delegate(&network_delegate);
2992 context.Init(); 2992 context.Init();
2993 2993
2994 { 2994 {
2995 URLRequest r(test_server_.GetURL(""), &d, &context); 2995 URLRequest r(test_server_.GetURL(std::string()), &d, &context);
2996 2996
2997 r.Start(); 2997 r.Start();
2998 MessageLoop::current()->Run(); 2998 MessageLoop::current()->Run();
2999 EXPECT_EQ(BlockingNetworkDelegate::ON_BEFORE_URL_REQUEST, 2999 EXPECT_EQ(BlockingNetworkDelegate::ON_BEFORE_URL_REQUEST,
3000 network_delegate.stage_blocked_for_callback()); 3000 network_delegate.stage_blocked_for_callback());
3001 EXPECT_EQ(0, network_delegate.completed_requests()); 3001 EXPECT_EQ(0, network_delegate.completed_requests());
3002 // Cancel before callback. 3002 // Cancel before callback.
3003 r.Cancel(); 3003 r.Cancel();
3004 // Ensure that network delegate is notified. 3004 // Ensure that network delegate is notified.
3005 EXPECT_EQ(1, network_delegate.completed_requests()); 3005 EXPECT_EQ(1, network_delegate.completed_requests());
(...skipping 15 matching lines...) Expand all
3021 BlockingNetworkDelegate network_delegate( 3021 BlockingNetworkDelegate network_delegate(
3022 BlockingNetworkDelegate::USER_CALLBACK); 3022 BlockingNetworkDelegate::USER_CALLBACK);
3023 network_delegate.set_block_on( 3023 network_delegate.set_block_on(
3024 BlockingNetworkDelegate::ON_BEFORE_SEND_HEADERS); 3024 BlockingNetworkDelegate::ON_BEFORE_SEND_HEADERS);
3025 3025
3026 TestURLRequestContext context(true); 3026 TestURLRequestContext context(true);
3027 context.set_network_delegate(&network_delegate); 3027 context.set_network_delegate(&network_delegate);
3028 context.Init(); 3028 context.Init();
3029 3029
3030 { 3030 {
3031 URLRequest r(test_server_.GetURL(""), &d, &context); 3031 URLRequest r(test_server_.GetURL(std::string()), &d, &context);
3032 3032
3033 r.Start(); 3033 r.Start();
3034 MessageLoop::current()->Run(); 3034 MessageLoop::current()->Run();
3035 EXPECT_EQ(BlockingNetworkDelegate::ON_BEFORE_SEND_HEADERS, 3035 EXPECT_EQ(BlockingNetworkDelegate::ON_BEFORE_SEND_HEADERS,
3036 network_delegate.stage_blocked_for_callback()); 3036 network_delegate.stage_blocked_for_callback());
3037 EXPECT_EQ(0, network_delegate.completed_requests()); 3037 EXPECT_EQ(0, network_delegate.completed_requests());
3038 // Cancel before callback. 3038 // Cancel before callback.
3039 r.Cancel(); 3039 r.Cancel();
3040 // Ensure that network delegate is notified. 3040 // Ensure that network delegate is notified.
3041 EXPECT_EQ(1, network_delegate.completed_requests()); 3041 EXPECT_EQ(1, network_delegate.completed_requests());
(...skipping 14 matching lines...) Expand all
3056 TestDelegate d; 3056 TestDelegate d;
3057 BlockingNetworkDelegate network_delegate( 3057 BlockingNetworkDelegate network_delegate(
3058 BlockingNetworkDelegate::USER_CALLBACK); 3058 BlockingNetworkDelegate::USER_CALLBACK);
3059 network_delegate.set_block_on(BlockingNetworkDelegate::ON_HEADERS_RECEIVED); 3059 network_delegate.set_block_on(BlockingNetworkDelegate::ON_HEADERS_RECEIVED);
3060 3060
3061 TestURLRequestContext context(true); 3061 TestURLRequestContext context(true);
3062 context.set_network_delegate(&network_delegate); 3062 context.set_network_delegate(&network_delegate);
3063 context.Init(); 3063 context.Init();
3064 3064
3065 { 3065 {
3066 URLRequest r(test_server_.GetURL(""), &d, &context); 3066 URLRequest r(test_server_.GetURL(std::string()), &d, &context);
3067 3067
3068 r.Start(); 3068 r.Start();
3069 MessageLoop::current()->Run(); 3069 MessageLoop::current()->Run();
3070 EXPECT_EQ(BlockingNetworkDelegate::ON_HEADERS_RECEIVED, 3070 EXPECT_EQ(BlockingNetworkDelegate::ON_HEADERS_RECEIVED,
3071 network_delegate.stage_blocked_for_callback()); 3071 network_delegate.stage_blocked_for_callback());
3072 EXPECT_EQ(0, network_delegate.completed_requests()); 3072 EXPECT_EQ(0, network_delegate.completed_requests());
3073 // Cancel before callback. 3073 // Cancel before callback.
3074 r.Cancel(); 3074 r.Cancel();
3075 // Ensure that network delegate is notified. 3075 // Ensure that network delegate is notified.
3076 EXPECT_EQ(1, network_delegate.completed_requests()); 3076 EXPECT_EQ(1, network_delegate.completed_requests());
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after
3140 EXPECT_EQ(URLRequestStatus::FAILED, r.status().status()); 3140 EXPECT_EQ(URLRequestStatus::FAILED, r.status().status());
3141 EXPECT_EQ(ERR_TUNNEL_CONNECTION_FAILED, r.status().error()); 3141 EXPECT_EQ(ERR_TUNNEL_CONNECTION_FAILED, r.status().error());
3142 } 3142 }
3143 } 3143 }
3144 3144
3145 TEST_F(URLRequestTestHTTP, GetTest_NoCache) { 3145 TEST_F(URLRequestTestHTTP, GetTest_NoCache) {
3146 ASSERT_TRUE(test_server_.Start()); 3146 ASSERT_TRUE(test_server_.Start());
3147 3147
3148 TestDelegate d; 3148 TestDelegate d;
3149 { 3149 {
3150 URLRequest r(test_server_.GetURL(""), &d, &default_context_); 3150 URLRequest r(test_server_.GetURL(std::string()), &d, &default_context_);
3151 3151
3152 r.Start(); 3152 r.Start();
3153 EXPECT_TRUE(r.is_pending()); 3153 EXPECT_TRUE(r.is_pending());
3154 3154
3155 MessageLoop::current()->Run(); 3155 MessageLoop::current()->Run();
3156 3156
3157 EXPECT_EQ(1, d.response_started_count()); 3157 EXPECT_EQ(1, d.response_started_count());
3158 EXPECT_FALSE(d.received_data_before_response()); 3158 EXPECT_FALSE(d.received_data_before_response());
3159 EXPECT_NE(0, d.bytes_received()); 3159 EXPECT_NE(0, d.bytes_received());
3160 EXPECT_EQ(test_server_.host_port_pair().host(), 3160 EXPECT_EQ(test_server_.host_port_pair().host(),
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after
3206 upper_bound = num_cookies; 3206 upper_bound = num_cookies;
3207 } 3207 }
3208 // Success: the test did not crash. 3208 // Success: the test did not crash.
3209 } 3209 }
3210 3210
3211 TEST_F(URLRequestTestHTTP, GetTest) { 3211 TEST_F(URLRequestTestHTTP, GetTest) {
3212 ASSERT_TRUE(test_server_.Start()); 3212 ASSERT_TRUE(test_server_.Start());
3213 3213
3214 TestDelegate d; 3214 TestDelegate d;
3215 { 3215 {
3216 URLRequest r(test_server_.GetURL(""), &d, &default_context_); 3216 URLRequest r(test_server_.GetURL(std::string()), &d, &default_context_);
3217 3217
3218 r.Start(); 3218 r.Start();
3219 EXPECT_TRUE(r.is_pending()); 3219 EXPECT_TRUE(r.is_pending());
3220 3220
3221 MessageLoop::current()->Run(); 3221 MessageLoop::current()->Run();
3222 3222
3223 EXPECT_EQ(1, d.response_started_count()); 3223 EXPECT_EQ(1, d.response_started_count());
3224 EXPECT_FALSE(d.received_data_before_response()); 3224 EXPECT_FALSE(d.received_data_before_response());
3225 EXPECT_NE(0, d.bytes_received()); 3225 EXPECT_NE(0, d.bytes_received());
3226 EXPECT_EQ(test_server_.host_port_pair().host(), 3226 EXPECT_EQ(test_server_.host_port_pair().host(),
3227 r.GetSocketAddress().host()); 3227 r.GetSocketAddress().host());
3228 EXPECT_EQ(test_server_.host_port_pair().port(), 3228 EXPECT_EQ(test_server_.host_port_pair().port(),
3229 r.GetSocketAddress().port()); 3229 r.GetSocketAddress().port());
3230 } 3230 }
3231 } 3231 }
3232 3232
3233 TEST_F(URLRequestTestHTTP, GetTestLoadTiming) { 3233 TEST_F(URLRequestTestHTTP, GetTestLoadTiming) {
3234 ASSERT_TRUE(test_server_.Start()); 3234 ASSERT_TRUE(test_server_.Start());
3235 3235
3236 TestDelegate d; 3236 TestDelegate d;
3237 { 3237 {
3238 URLRequest r(test_server_.GetURL(""), &d, &default_context_); 3238 URLRequest r(test_server_.GetURL(std::string()), &d, &default_context_);
3239 3239
3240 r.Start(); 3240 r.Start();
3241 EXPECT_TRUE(r.is_pending()); 3241 EXPECT_TRUE(r.is_pending());
3242 3242
3243 MessageLoop::current()->Run(); 3243 MessageLoop::current()->Run();
3244 3244
3245 LoadTimingInfo load_timing_info; 3245 LoadTimingInfo load_timing_info;
3246 r.GetLoadTimingInfo(&load_timing_info); 3246 r.GetLoadTimingInfo(&load_timing_info);
3247 TestLoadTimingNotReused(load_timing_info, CONNECT_TIMING_HAS_DNS_TIMES); 3247 TestLoadTimingNotReused(load_timing_info, CONNECT_TIMING_HAS_DNS_TIMES);
3248 3248
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after
3312 ASSERT_TRUE(test_server_.Start()); 3312 ASSERT_TRUE(test_server_.Start());
3313 3313
3314 TestServer https_test_server( 3314 TestServer https_test_server(
3315 TestServer::TYPE_HTTPS, TestServer::kLocalhost, 3315 TestServer::TYPE_HTTPS, TestServer::kLocalhost,
3316 base::FilePath(FILE_PATH_LITERAL("net/data/ssl"))); 3316 base::FilePath(FILE_PATH_LITERAL("net/data/ssl")));
3317 ASSERT_TRUE(https_test_server.Start()); 3317 ASSERT_TRUE(https_test_server.Start());
3318 3318
3319 // An https server is sent a request with an https referer, 3319 // An https server is sent a request with an https referer,
3320 // and responds with a redirect to an http url. The http 3320 // and responds with a redirect to an http url. The http
3321 // server should not be sent the referer. 3321 // server should not be sent the referer.
3322 GURL http_destination = test_server_.GetURL(""); 3322 GURL http_destination = test_server_.GetURL(std::string());
3323 TestDelegate d; 3323 TestDelegate d;
3324 URLRequest req(https_test_server.GetURL( 3324 URLRequest req(https_test_server.GetURL(
3325 "server-redirect?" + http_destination.spec()), &d, &default_context_); 3325 "server-redirect?" + http_destination.spec()), &d, &default_context_);
3326 req.set_referrer("https://www.referrer.com/"); 3326 req.set_referrer("https://www.referrer.com/");
3327 req.Start(); 3327 req.Start();
3328 MessageLoop::current()->Run(); 3328 MessageLoop::current()->Run();
3329 3329
3330 EXPECT_EQ(1, d.response_started_count()); 3330 EXPECT_EQ(1, d.response_started_count());
3331 EXPECT_EQ(1, d.received_redirect_count()); 3331 EXPECT_EQ(1, d.received_redirect_count());
3332 EXPECT_EQ(http_destination, req.url()); 3332 EXPECT_EQ(http_destination, req.url());
3333 EXPECT_EQ(std::string(), req.referrer()); 3333 EXPECT_EQ(std::string(), req.referrer());
3334 } 3334 }
3335 3335
3336 TEST_F(URLRequestTestHTTP, RedirectLoadTiming) { 3336 TEST_F(URLRequestTestHTTP, RedirectLoadTiming) {
3337 ASSERT_TRUE(test_server_.Start()); 3337 ASSERT_TRUE(test_server_.Start());
3338 3338
3339 GURL destination_url = test_server_.GetURL(""); 3339 GURL destination_url = test_server_.GetURL(std::string());
3340 GURL original_url = test_server_.GetURL( 3340 GURL original_url =
3341 "server-redirect?" + destination_url.spec()); 3341 test_server_.GetURL("server-redirect?" + destination_url.spec());
3342 TestDelegate d; 3342 TestDelegate d;
3343 URLRequest req(original_url, &d, &default_context_); 3343 URLRequest req(original_url, &d, &default_context_);
3344 req.Start(); 3344 req.Start();
3345 MessageLoop::current()->Run(); 3345 MessageLoop::current()->Run();
3346 3346
3347 EXPECT_EQ(1, d.response_started_count()); 3347 EXPECT_EQ(1, d.response_started_count());
3348 EXPECT_EQ(1, d.received_redirect_count()); 3348 EXPECT_EQ(1, d.received_redirect_count());
3349 EXPECT_EQ(destination_url, req.url()); 3349 EXPECT_EQ(destination_url, req.url());
3350 EXPECT_EQ(original_url, req.original_url()); 3350 EXPECT_EQ(original_url, req.original_url());
3351 ASSERT_EQ(2U, req.url_chain().size()); 3351 ASSERT_EQ(2U, req.url_chain().size());
(...skipping 15 matching lines...) Expand all
3367 // before the ones recorded for the second request. 3367 // before the ones recorded for the second request.
3368 EXPECT_NE(load_timing_info_before_redirect.socket_log_id, 3368 EXPECT_NE(load_timing_info_before_redirect.socket_log_id,
3369 load_timing_info.socket_log_id); 3369 load_timing_info.socket_log_id);
3370 EXPECT_LE(load_timing_info_before_redirect.receive_headers_end, 3370 EXPECT_LE(load_timing_info_before_redirect.receive_headers_end,
3371 load_timing_info.connect_timing.connect_start); 3371 load_timing_info.connect_timing.connect_start);
3372 } 3372 }
3373 3373
3374 TEST_F(URLRequestTestHTTP, MultipleRedirectTest) { 3374 TEST_F(URLRequestTestHTTP, MultipleRedirectTest) {
3375 ASSERT_TRUE(test_server_.Start()); 3375 ASSERT_TRUE(test_server_.Start());
3376 3376
3377 GURL destination_url = test_server_.GetURL(""); 3377 GURL destination_url = test_server_.GetURL(std::string());
3378 GURL middle_redirect_url = test_server_.GetURL( 3378 GURL middle_redirect_url =
3379 "server-redirect?" + destination_url.spec()); 3379 test_server_.GetURL("server-redirect?" + destination_url.spec());
3380 GURL original_url = test_server_.GetURL( 3380 GURL original_url = test_server_.GetURL(
3381 "server-redirect?" + middle_redirect_url.spec()); 3381 "server-redirect?" + middle_redirect_url.spec());
3382 TestDelegate d; 3382 TestDelegate d;
3383 URLRequest req(original_url, &d, &default_context_); 3383 URLRequest req(original_url, &d, &default_context_);
3384 req.Start(); 3384 req.Start();
3385 MessageLoop::current()->Run(); 3385 MessageLoop::current()->Run();
3386 3386
3387 EXPECT_EQ(1, d.response_started_count()); 3387 EXPECT_EQ(1, d.response_started_count());
3388 EXPECT_EQ(2, d.received_redirect_count()); 3388 EXPECT_EQ(2, d.received_redirect_count());
3389 EXPECT_EQ(destination_url, req.url()); 3389 EXPECT_EQ(destination_url, req.url());
(...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after
3485 EXPECT_EQ(0, d.bytes_received()); 3485 EXPECT_EQ(0, d.bytes_received());
3486 EXPECT_FALSE(d.received_data_before_response()); 3486 EXPECT_FALSE(d.received_data_before_response());
3487 } 3487 }
3488 } 3488 }
3489 3489
3490 TEST_F(URLRequestTestHTTP, CancelTest2) { 3490 TEST_F(URLRequestTestHTTP, CancelTest2) {
3491 ASSERT_TRUE(test_server_.Start()); 3491 ASSERT_TRUE(test_server_.Start());
3492 3492
3493 TestDelegate d; 3493 TestDelegate d;
3494 { 3494 {
3495 URLRequest r(test_server_.GetURL(""), &d, &default_context_); 3495 URLRequest r(test_server_.GetURL(std::string()), &d, &default_context_);
3496 3496
3497 d.set_cancel_in_response_started(true); 3497 d.set_cancel_in_response_started(true);
3498 3498
3499 r.Start(); 3499 r.Start();
3500 EXPECT_TRUE(r.is_pending()); 3500 EXPECT_TRUE(r.is_pending());
3501 3501
3502 MessageLoop::current()->Run(); 3502 MessageLoop::current()->Run();
3503 3503
3504 EXPECT_EQ(1, d.response_started_count()); 3504 EXPECT_EQ(1, d.response_started_count());
3505 EXPECT_EQ(0, d.bytes_received()); 3505 EXPECT_EQ(0, d.bytes_received());
3506 EXPECT_FALSE(d.received_data_before_response()); 3506 EXPECT_FALSE(d.received_data_before_response());
3507 EXPECT_EQ(URLRequestStatus::CANCELED, r.status().status()); 3507 EXPECT_EQ(URLRequestStatus::CANCELED, r.status().status());
3508 } 3508 }
3509 } 3509 }
3510 3510
3511 TEST_F(URLRequestTestHTTP, CancelTest3) { 3511 TEST_F(URLRequestTestHTTP, CancelTest3) {
3512 ASSERT_TRUE(test_server_.Start()); 3512 ASSERT_TRUE(test_server_.Start());
3513 3513
3514 TestDelegate d; 3514 TestDelegate d;
3515 { 3515 {
3516 URLRequest r(test_server_.GetURL(""), &d, &default_context_); 3516 URLRequest r(test_server_.GetURL(std::string()), &d, &default_context_);
3517 3517
3518 d.set_cancel_in_received_data(true); 3518 d.set_cancel_in_received_data(true);
3519 3519
3520 r.Start(); 3520 r.Start();
3521 EXPECT_TRUE(r.is_pending()); 3521 EXPECT_TRUE(r.is_pending());
3522 3522
3523 MessageLoop::current()->Run(); 3523 MessageLoop::current()->Run();
3524 3524
3525 EXPECT_EQ(1, d.response_started_count()); 3525 EXPECT_EQ(1, d.response_started_count());
3526 // There is no guarantee about how much data was received 3526 // There is no guarantee about how much data was received
3527 // before the cancel was issued. It could have been 0 bytes, 3527 // before the cancel was issued. It could have been 0 bytes,
3528 // or it could have been all the bytes. 3528 // or it could have been all the bytes.
3529 // EXPECT_EQ(0, d.bytes_received()); 3529 // EXPECT_EQ(0, d.bytes_received());
3530 EXPECT_FALSE(d.received_data_before_response()); 3530 EXPECT_FALSE(d.received_data_before_response());
3531 EXPECT_EQ(URLRequestStatus::CANCELED, r.status().status()); 3531 EXPECT_EQ(URLRequestStatus::CANCELED, r.status().status());
3532 } 3532 }
3533 } 3533 }
3534 3534
3535 TEST_F(URLRequestTestHTTP, CancelTest4) { 3535 TEST_F(URLRequestTestHTTP, CancelTest4) {
3536 ASSERT_TRUE(test_server_.Start()); 3536 ASSERT_TRUE(test_server_.Start());
3537 3537
3538 TestDelegate d; 3538 TestDelegate d;
3539 { 3539 {
3540 URLRequest r(test_server_.GetURL(""), &d, &default_context_); 3540 URLRequest r(test_server_.GetURL(std::string()), &d, &default_context_);
3541 3541
3542 r.Start(); 3542 r.Start();
3543 EXPECT_TRUE(r.is_pending()); 3543 EXPECT_TRUE(r.is_pending());
3544 3544
3545 // The request will be implicitly canceled when it is destroyed. The 3545 // The request will be implicitly canceled when it is destroyed. The
3546 // test delegate must not post a quit message when this happens because 3546 // test delegate must not post a quit message when this happens because
3547 // this test doesn't actually have a message loop. The quit message would 3547 // this test doesn't actually have a message loop. The quit message would
3548 // get put on this thread's message queue and the next test would exit 3548 // get put on this thread's message queue and the next test would exit
3549 // early, causing problems. 3549 // early, causing problems.
3550 d.set_quit_on_complete(false); 3550 d.set_quit_on_complete(false);
(...skipping 938 matching lines...) Expand 10 before | Expand all | Expand 10 after
4489 }; 4489 };
4490 4490
4491 TEST_F(HTTPSRequestTest, HTTPSGetTest) { 4491 TEST_F(HTTPSRequestTest, HTTPSGetTest) {
4492 TestServer test_server(TestServer::TYPE_HTTPS, 4492 TestServer test_server(TestServer::TYPE_HTTPS,
4493 TestServer::kLocalhost, 4493 TestServer::kLocalhost,
4494 base::FilePath(FILE_PATH_LITERAL("net/data/ssl"))); 4494 base::FilePath(FILE_PATH_LITERAL("net/data/ssl")));
4495 ASSERT_TRUE(test_server.Start()); 4495 ASSERT_TRUE(test_server.Start());
4496 4496
4497 TestDelegate d; 4497 TestDelegate d;
4498 { 4498 {
4499 URLRequest r(test_server.GetURL(""), &d, &default_context_); 4499 URLRequest r(test_server.GetURL(std::string()), &d, &default_context_);
4500 r.Start(); 4500 r.Start();
4501 EXPECT_TRUE(r.is_pending()); 4501 EXPECT_TRUE(r.is_pending());
4502 4502
4503 MessageLoop::current()->Run(); 4503 MessageLoop::current()->Run();
4504 4504
4505 EXPECT_EQ(1, d.response_started_count()); 4505 EXPECT_EQ(1, d.response_started_count());
4506 EXPECT_FALSE(d.received_data_before_response()); 4506 EXPECT_FALSE(d.received_data_before_response());
4507 EXPECT_NE(0, d.bytes_received()); 4507 EXPECT_NE(0, d.bytes_received());
4508 CheckSSLInfo(r.ssl_info()); 4508 CheckSSLInfo(r.ssl_info());
4509 EXPECT_EQ(test_server.host_port_pair().host(), 4509 EXPECT_EQ(test_server.host_port_pair().host(),
4510 r.GetSocketAddress().host()); 4510 r.GetSocketAddress().host());
4511 EXPECT_EQ(test_server.host_port_pair().port(), 4511 EXPECT_EQ(test_server.host_port_pair().port(),
4512 r.GetSocketAddress().port()); 4512 r.GetSocketAddress().port());
4513 } 4513 }
4514 } 4514 }
4515 4515
4516 TEST_F(HTTPSRequestTest, HTTPSMismatchedTest) { 4516 TEST_F(HTTPSRequestTest, HTTPSMismatchedTest) {
4517 TestServer::SSLOptions ssl_options( 4517 TestServer::SSLOptions ssl_options(
4518 TestServer::SSLOptions::CERT_MISMATCHED_NAME); 4518 TestServer::SSLOptions::CERT_MISMATCHED_NAME);
4519 TestServer test_server(TestServer::TYPE_HTTPS, 4519 TestServer test_server(TestServer::TYPE_HTTPS,
4520 ssl_options, 4520 ssl_options,
4521 base::FilePath(FILE_PATH_LITERAL("net/data/ssl"))); 4521 base::FilePath(FILE_PATH_LITERAL("net/data/ssl")));
4522 ASSERT_TRUE(test_server.Start()); 4522 ASSERT_TRUE(test_server.Start());
4523 4523
4524 bool err_allowed = true; 4524 bool err_allowed = true;
4525 for (int i = 0; i < 2 ; i++, err_allowed = !err_allowed) { 4525 for (int i = 0; i < 2 ; i++, err_allowed = !err_allowed) {
4526 TestDelegate d; 4526 TestDelegate d;
4527 { 4527 {
4528 d.set_allow_certificate_errors(err_allowed); 4528 d.set_allow_certificate_errors(err_allowed);
4529 URLRequest r(test_server.GetURL(""), &d, &default_context_); 4529 URLRequest r(test_server.GetURL(std::string()), &d, &default_context_);
4530 4530
4531 r.Start(); 4531 r.Start();
4532 EXPECT_TRUE(r.is_pending()); 4532 EXPECT_TRUE(r.is_pending());
4533 4533
4534 MessageLoop::current()->Run(); 4534 MessageLoop::current()->Run();
4535 4535
4536 EXPECT_EQ(1, d.response_started_count()); 4536 EXPECT_EQ(1, d.response_started_count());
4537 EXPECT_FALSE(d.received_data_before_response()); 4537 EXPECT_FALSE(d.received_data_before_response());
4538 EXPECT_TRUE(d.have_certificate_errors()); 4538 EXPECT_TRUE(d.have_certificate_errors());
4539 if (err_allowed) { 4539 if (err_allowed) {
(...skipping 14 matching lines...) Expand all
4554 base::FilePath(FILE_PATH_LITERAL("net/data/ssl"))); 4554 base::FilePath(FILE_PATH_LITERAL("net/data/ssl")));
4555 ASSERT_TRUE(test_server.Start()); 4555 ASSERT_TRUE(test_server.Start());
4556 4556
4557 // Iterate from false to true, just so that we do the opposite of the 4557 // Iterate from false to true, just so that we do the opposite of the
4558 // previous test in order to increase test coverage. 4558 // previous test in order to increase test coverage.
4559 bool err_allowed = false; 4559 bool err_allowed = false;
4560 for (int i = 0; i < 2 ; i++, err_allowed = !err_allowed) { 4560 for (int i = 0; i < 2 ; i++, err_allowed = !err_allowed) {
4561 TestDelegate d; 4561 TestDelegate d;
4562 { 4562 {
4563 d.set_allow_certificate_errors(err_allowed); 4563 d.set_allow_certificate_errors(err_allowed);
4564 URLRequest r(test_server.GetURL(""), &d, &default_context_); 4564 URLRequest r(test_server.GetURL(std::string()), &d, &default_context_);
4565 4565
4566 r.Start(); 4566 r.Start();
4567 EXPECT_TRUE(r.is_pending()); 4567 EXPECT_TRUE(r.is_pending());
4568 4568
4569 MessageLoop::current()->Run(); 4569 MessageLoop::current()->Run();
4570 4570
4571 EXPECT_EQ(1, d.response_started_count()); 4571 EXPECT_EQ(1, d.response_started_count());
4572 EXPECT_FALSE(d.received_data_before_response()); 4572 EXPECT_FALSE(d.received_data_before_response());
4573 EXPECT_TRUE(d.have_certificate_errors()); 4573 EXPECT_TRUE(d.have_certificate_errors());
4574 if (err_allowed) { 4574 if (err_allowed) {
(...skipping 23 matching lines...) Expand all
4598 TestServer::SSLOptions::TLS_INTOLERANT_TLS1_1; 4598 TestServer::SSLOptions::TLS_INTOLERANT_TLS1_1;
4599 TestServer test_server(TestServer::TYPE_HTTPS, 4599 TestServer test_server(TestServer::TYPE_HTTPS,
4600 ssl_options, 4600 ssl_options,
4601 base::FilePath(FILE_PATH_LITERAL("net/data/ssl"))); 4601 base::FilePath(FILE_PATH_LITERAL("net/data/ssl")));
4602 ASSERT_TRUE(test_server.Start()); 4602 ASSERT_TRUE(test_server.Start());
4603 4603
4604 TestDelegate d; 4604 TestDelegate d;
4605 TestURLRequestContext context(true); 4605 TestURLRequestContext context(true);
4606 context.Init(); 4606 context.Init();
4607 d.set_allow_certificate_errors(true); 4607 d.set_allow_certificate_errors(true);
4608 URLRequest r(test_server.GetURL(""), &d, &context); 4608 URLRequest r(test_server.GetURL(std::string()), &d, &context);
4609 r.Start(); 4609 r.Start();
4610 4610
4611 MessageLoop::current()->Run(); 4611 MessageLoop::current()->Run();
4612 4612
4613 EXPECT_EQ(1, d.response_started_count()); 4613 EXPECT_EQ(1, d.response_started_count());
4614 EXPECT_NE(0, d.bytes_received()); 4614 EXPECT_NE(0, d.bytes_received());
4615 EXPECT_EQ(static_cast<int>(SSL_CONNECTION_VERSION_TLS1), 4615 EXPECT_EQ(static_cast<int>(SSL_CONNECTION_VERSION_TLS1),
4616 SSLConnectionStatusToVersion(r.ssl_info().connection_status)); 4616 SSLConnectionStatusToVersion(r.ssl_info().connection_status));
4617 EXPECT_TRUE(r.ssl_info().connection_status & SSL_CONNECTION_VERSION_FALLBACK); 4617 EXPECT_TRUE(r.ssl_info().connection_status & SSL_CONNECTION_VERSION_FALLBACK);
4618 } 4618 }
(...skipping 158 matching lines...) Expand 10 before | Expand all | Expand 10 after
4777 ssl_options.tls_intolerant = TestServer::SSLOptions::TLS_INTOLERANT_ALL; 4777 ssl_options.tls_intolerant = TestServer::SSLOptions::TLS_INTOLERANT_ALL;
4778 TestServer test_server(TestServer::TYPE_HTTPS, 4778 TestServer test_server(TestServer::TYPE_HTTPS,
4779 ssl_options, 4779 ssl_options,
4780 base::FilePath(FILE_PATH_LITERAL("net/data/ssl"))); 4780 base::FilePath(FILE_PATH_LITERAL("net/data/ssl")));
4781 ASSERT_TRUE(test_server.Start()); 4781 ASSERT_TRUE(test_server.Start());
4782 4782
4783 TestDelegate d; 4783 TestDelegate d;
4784 TestURLRequestContext context(true); 4784 TestURLRequestContext context(true);
4785 context.Init(); 4785 context.Init();
4786 d.set_allow_certificate_errors(true); 4786 d.set_allow_certificate_errors(true);
4787 URLRequest r(test_server.GetURL(""), &d, &context); 4787 URLRequest r(test_server.GetURL(std::string()), &d, &context);
4788 r.Start(); 4788 r.Start();
4789 4789
4790 MessageLoop::current()->Run(); 4790 MessageLoop::current()->Run();
4791 4791
4792 EXPECT_EQ(1, d.response_started_count()); 4792 EXPECT_EQ(1, d.response_started_count());
4793 EXPECT_NE(0, d.bytes_received()); 4793 EXPECT_NE(0, d.bytes_received());
4794 EXPECT_EQ(static_cast<int>(SSL_CONNECTION_VERSION_SSL3), 4794 EXPECT_EQ(static_cast<int>(SSL_CONNECTION_VERSION_SSL3),
4795 SSLConnectionStatusToVersion(r.ssl_info().connection_status)); 4795 SSLConnectionStatusToVersion(r.ssl_info().connection_status));
4796 EXPECT_TRUE(r.ssl_info().connection_status & SSL_CONNECTION_VERSION_FALLBACK); 4796 EXPECT_TRUE(r.ssl_info().connection_status & SSL_CONNECTION_VERSION_FALLBACK);
4797 } 4797 }
(...skipping 27 matching lines...) Expand all
4825 TEST_F(HTTPSRequestTest, ClientAuthTest) { 4825 TEST_F(HTTPSRequestTest, ClientAuthTest) {
4826 TestServer::SSLOptions ssl_options; 4826 TestServer::SSLOptions ssl_options;
4827 ssl_options.request_client_certificate = true; 4827 ssl_options.request_client_certificate = true;
4828 TestServer test_server(TestServer::TYPE_HTTPS, 4828 TestServer test_server(TestServer::TYPE_HTTPS,
4829 ssl_options, 4829 ssl_options,
4830 base::FilePath(FILE_PATH_LITERAL("net/data/ssl"))); 4830 base::FilePath(FILE_PATH_LITERAL("net/data/ssl")));
4831 ASSERT_TRUE(test_server.Start()); 4831 ASSERT_TRUE(test_server.Start());
4832 4832
4833 SSLClientAuthTestDelegate d; 4833 SSLClientAuthTestDelegate d;
4834 { 4834 {
4835 URLRequest r(test_server.GetURL(""), &d, &default_context_); 4835 URLRequest r(test_server.GetURL(std::string()), &d, &default_context_);
4836 4836
4837 r.Start(); 4837 r.Start();
4838 EXPECT_TRUE(r.is_pending()); 4838 EXPECT_TRUE(r.is_pending());
4839 4839
4840 MessageLoop::current()->Run(); 4840 MessageLoop::current()->Run();
4841 4841
4842 EXPECT_EQ(1, d.on_certificate_requested_count()); 4842 EXPECT_EQ(1, d.on_certificate_requested_count());
4843 EXPECT_FALSE(d.received_data_before_response()); 4843 EXPECT_FALSE(d.received_data_before_response());
4844 EXPECT_EQ(0, d.bytes_received()); 4844 EXPECT_EQ(0, d.bytes_received());
4845 4845
(...skipping 219 matching lines...) Expand 10 before | Expand all | Expand 10 after
5065 CertStatus* out_cert_status) { 5065 CertStatus* out_cert_status) {
5066 // We always overwrite out_cert_status. 5066 // We always overwrite out_cert_status.
5067 *out_cert_status = 0; 5067 *out_cert_status = 0;
5068 TestServer test_server(TestServer::TYPE_HTTPS, 5068 TestServer test_server(TestServer::TYPE_HTTPS,
5069 ssl_options, 5069 ssl_options,
5070 base::FilePath(FILE_PATH_LITERAL("net/data/ssl"))); 5070 base::FilePath(FILE_PATH_LITERAL("net/data/ssl")));
5071 ASSERT_TRUE(test_server.Start()); 5071 ASSERT_TRUE(test_server.Start());
5072 5072
5073 TestDelegate d; 5073 TestDelegate d;
5074 d.set_allow_certificate_errors(true); 5074 d.set_allow_certificate_errors(true);
5075 URLRequest r(test_server.GetURL(""), &d, &context_); 5075 URLRequest r(test_server.GetURL(std::string()), &d, &context_);
5076 r.Start(); 5076 r.Start();
5077 5077
5078 MessageLoop::current()->Run(); 5078 MessageLoop::current()->Run();
5079 5079
5080 EXPECT_EQ(1, d.response_started_count()); 5080 EXPECT_EQ(1, d.response_started_count());
5081 *out_cert_status = r.ssl_info().cert_status; 5081 *out_cert_status = r.ssl_info().cert_status;
5082 } 5082 }
5083 5083
5084 virtual ~HTTPSOCSPTest() { 5084 virtual ~HTTPSOCSPTest() {
5085 #if defined(USE_NSS) || defined(OS_IOS) 5085 #if defined(USE_NSS) || defined(OS_IOS)
(...skipping 626 matching lines...) Expand 10 before | Expand all | Expand 10 after
5712 5712
5713 EXPECT_FALSE(r.is_pending()); 5713 EXPECT_FALSE(r.is_pending());
5714 EXPECT_EQ(1, d->response_started_count()); 5714 EXPECT_EQ(1, d->response_started_count());
5715 EXPECT_FALSE(d->received_data_before_response()); 5715 EXPECT_FALSE(d->received_data_before_response());
5716 EXPECT_EQ(d->bytes_received(), static_cast<int>(file_size)); 5716 EXPECT_EQ(d->bytes_received(), static_cast<int>(file_size));
5717 } 5717 }
5718 } 5718 }
5719 #endif // !defined(DISABLE_FTP_SUPPORT) 5719 #endif // !defined(DISABLE_FTP_SUPPORT)
5720 5720
5721 } // namespace net 5721 } // namespace net
OLDNEW
« no previous file with comments | « net/url_request/url_request_throttler_unittest.cc ('k') | net/websockets/websocket_net_log_params_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698