| OLD | NEW |
| 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 140 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 151 | 151 |
| 152 EXPECT_FALSE(load_timing_info.request_start_time.is_null()); | 152 EXPECT_FALSE(load_timing_info.request_start_time.is_null()); |
| 153 EXPECT_FALSE(load_timing_info.request_start.is_null()); | 153 EXPECT_FALSE(load_timing_info.request_start.is_null()); |
| 154 | 154 |
| 155 ExpectConnectTimingHasNoTimes(load_timing_info.connect_timing); | 155 ExpectConnectTimingHasNoTimes(load_timing_info.connect_timing); |
| 156 | 156 |
| 157 EXPECT_LE(load_timing_info.request_start, | 157 EXPECT_LE(load_timing_info.request_start, |
| 158 load_timing_info.proxy_resolve_start); | 158 load_timing_info.proxy_resolve_start); |
| 159 EXPECT_LE(load_timing_info.proxy_resolve_start, | 159 EXPECT_LE(load_timing_info.proxy_resolve_start, |
| 160 load_timing_info.proxy_resolve_end); | 160 load_timing_info.proxy_resolve_end); |
| 161 EXPECT_LE(load_timing_info.proxy_resolve_end, | 161 EXPECT_LE(load_timing_info.proxy_resolve_end, load_timing_info.send_start); |
| 162 load_timing_info.send_start); | |
| 163 EXPECT_LE(load_timing_info.send_start, load_timing_info.send_end); | 162 EXPECT_LE(load_timing_info.send_start, load_timing_info.send_end); |
| 164 EXPECT_LE(load_timing_info.send_end, load_timing_info.receive_headers_end); | 163 EXPECT_LE(load_timing_info.send_end, load_timing_info.receive_headers_end); |
| 165 } | 164 } |
| 166 | 165 |
| 167 // Tests load timing information in the case of a cache hit, when no cache | 166 // Tests load timing information in the case of a cache hit, when no cache |
| 168 // validation request was sent over the wire. | 167 // validation request was sent over the wire. |
| 169 base::StringPiece TestNetResourceProvider(int key) { | 168 base::StringPiece TestNetResourceProvider(int key) { |
| 170 return "header"; | 169 return "header"; |
| 171 } | 170 } |
| 172 | 171 |
| (...skipping 25 matching lines...) Expand all Loading... |
| 198 EXPECT_LE(load_timing_info.request_start, load_timing_info.send_start); | 197 EXPECT_LE(load_timing_info.request_start, load_timing_info.send_start); |
| 199 EXPECT_LE(load_timing_info.send_start, load_timing_info.send_end); | 198 EXPECT_LE(load_timing_info.send_start, load_timing_info.send_end); |
| 200 EXPECT_LE(load_timing_info.send_end, load_timing_info.receive_headers_end); | 199 EXPECT_LE(load_timing_info.send_end, load_timing_info.receive_headers_end); |
| 201 | 200 |
| 202 EXPECT_TRUE(load_timing_info.proxy_resolve_start.is_null()); | 201 EXPECT_TRUE(load_timing_info.proxy_resolve_start.is_null()); |
| 203 EXPECT_TRUE(load_timing_info.proxy_resolve_end.is_null()); | 202 EXPECT_TRUE(load_timing_info.proxy_resolve_end.is_null()); |
| 204 } | 203 } |
| 205 | 204 |
| 206 // Tests load timing in the case that there is no HTTP response. This can be | 205 // Tests load timing in the case that there is no HTTP response. This can be |
| 207 // used to test in the case of errors or non-HTTP requests. | 206 // used to test in the case of errors or non-HTTP requests. |
| 208 void TestLoadTimingNoHttpResponse( | 207 void TestLoadTimingNoHttpResponse(const net::LoadTimingInfo& load_timing_info) { |
| 209 const net::LoadTimingInfo& load_timing_info) { | |
| 210 EXPECT_FALSE(load_timing_info.socket_reused); | 208 EXPECT_FALSE(load_timing_info.socket_reused); |
| 211 EXPECT_EQ(net::NetLog::Source::kInvalidId, load_timing_info.socket_log_id); | 209 EXPECT_EQ(net::NetLog::Source::kInvalidId, load_timing_info.socket_log_id); |
| 212 | 210 |
| 213 // Only the request times should be non-null. | 211 // Only the request times should be non-null. |
| 214 EXPECT_FALSE(load_timing_info.request_start_time.is_null()); | 212 EXPECT_FALSE(load_timing_info.request_start_time.is_null()); |
| 215 EXPECT_FALSE(load_timing_info.request_start.is_null()); | 213 EXPECT_FALSE(load_timing_info.request_start.is_null()); |
| 216 | 214 |
| 217 ExpectConnectTimingHasNoTimes(load_timing_info.connect_timing); | 215 ExpectConnectTimingHasNoTimes(load_timing_info.connect_timing); |
| 218 | 216 |
| 219 EXPECT_TRUE(load_timing_info.proxy_resolve_start.is_null()); | 217 EXPECT_TRUE(load_timing_info.proxy_resolve_start.is_null()); |
| (...skipping 19 matching lines...) Expand all Loading... |
| 239 new UploadBytesElementReader(data, strlen(data))); | 237 new UploadBytesElementReader(data, strlen(data))); |
| 240 return UploadDataStream::CreateWithReader(reader.Pass(), 0); | 238 return UploadDataStream::CreateWithReader(reader.Pass(), 0); |
| 241 } | 239 } |
| 242 | 240 |
| 243 // Verify that the SSLInfo of a successful SSL connection has valid values. | 241 // Verify that the SSLInfo of a successful SSL connection has valid values. |
| 244 void CheckSSLInfo(const SSLInfo& ssl_info) { | 242 void CheckSSLInfo(const SSLInfo& ssl_info) { |
| 245 // -1 means unknown. 0 means no encryption. | 243 // -1 means unknown. 0 means no encryption. |
| 246 EXPECT_GT(ssl_info.security_bits, 0); | 244 EXPECT_GT(ssl_info.security_bits, 0); |
| 247 | 245 |
| 248 // The cipher suite TLS_NULL_WITH_NULL_NULL (0) must not be negotiated. | 246 // The cipher suite TLS_NULL_WITH_NULL_NULL (0) must not be negotiated. |
| 249 int cipher_suite = SSLConnectionStatusToCipherSuite( | 247 int cipher_suite = |
| 250 ssl_info.connection_status); | 248 SSLConnectionStatusToCipherSuite(ssl_info.connection_status); |
| 251 EXPECT_NE(0, cipher_suite); | 249 EXPECT_NE(0, cipher_suite); |
| 252 } | 250 } |
| 253 | 251 |
| 254 void CheckFullRequestHeaders(const HttpRequestHeaders& headers, | 252 void CheckFullRequestHeaders(const HttpRequestHeaders& headers, |
| 255 const GURL& host_url) { | 253 const GURL& host_url) { |
| 256 std::string sent_value; | 254 std::string sent_value; |
| 257 | 255 |
| 258 EXPECT_TRUE(headers.GetHeader("Host", &sent_value)); | 256 EXPECT_TRUE(headers.GetHeader("Host", &sent_value)); |
| 259 EXPECT_EQ(GetHostAndOptionalPort(host_url), sent_value); | 257 EXPECT_EQ(GetHostAndOptionalPort(host_url), sent_value); |
| 260 | 258 |
| (...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 330 // |auth_credentials_| will be passed with the response. | 328 // |auth_credentials_| will be passed with the response. |
| 331 void set_auth_retval(AuthRequiredResponse auth_retval) { | 329 void set_auth_retval(AuthRequiredResponse auth_retval) { |
| 332 ASSERT_NE(USER_CALLBACK, block_mode_); | 330 ASSERT_NE(USER_CALLBACK, block_mode_); |
| 333 ASSERT_NE(AUTH_REQUIRED_RESPONSE_IO_PENDING, auth_retval); | 331 ASSERT_NE(AUTH_REQUIRED_RESPONSE_IO_PENDING, auth_retval); |
| 334 auth_retval_ = auth_retval; | 332 auth_retval_ = auth_retval; |
| 335 } | 333 } |
| 336 void set_auth_credentials(const AuthCredentials& auth_credentials) { | 334 void set_auth_credentials(const AuthCredentials& auth_credentials) { |
| 337 auth_credentials_ = auth_credentials; | 335 auth_credentials_ = auth_credentials; |
| 338 } | 336 } |
| 339 | 337 |
| 340 void set_redirect_url(const GURL& url) { | 338 void set_redirect_url(const GURL& url) { redirect_url_ = url; } |
| 341 redirect_url_ = url; | |
| 342 } | |
| 343 | 339 |
| 344 void set_block_on(int block_on) { | 340 void set_block_on(int block_on) { block_on_ = block_on; } |
| 345 block_on_ = block_on; | |
| 346 } | |
| 347 | 341 |
| 348 // Allows the user to check in which state did we block. | 342 // Allows the user to check in which state did we block. |
| 349 Stage stage_blocked_for_callback() const { | 343 Stage stage_blocked_for_callback() const { |
| 350 EXPECT_EQ(USER_CALLBACK, block_mode_); | 344 EXPECT_EQ(USER_CALLBACK, block_mode_); |
| 351 return stage_blocked_for_callback_; | 345 return stage_blocked_for_callback_; |
| 352 } | 346 } |
| 353 | 347 |
| 354 private: | 348 private: |
| 355 void RunCallback(int response, const CompletionCallback& callback); | 349 void RunCallback(int response, const CompletionCallback& callback); |
| 356 void RunAuthCallback(AuthRequiredResponse response, | 350 void RunAuthCallback(AuthRequiredResponse response, |
| (...skipping 30 matching lines...) Expand all Loading... |
| 387 | 381 |
| 388 // Configuration parameters, can be adjusted by public methods: | 382 // Configuration parameters, can be adjusted by public methods: |
| 389 const BlockMode block_mode_; | 383 const BlockMode block_mode_; |
| 390 | 384 |
| 391 // Values returned on blocking stages when mode is SYNCHRONOUS or | 385 // Values returned on blocking stages when mode is SYNCHRONOUS or |
| 392 // AUTO_CALLBACK. For USER_CALLBACK these are set automatically to IO_PENDING. | 386 // AUTO_CALLBACK. For USER_CALLBACK these are set automatically to IO_PENDING. |
| 393 int retval_; // To be returned in non-auth stages. | 387 int retval_; // To be returned in non-auth stages. |
| 394 AuthRequiredResponse auth_retval_; | 388 AuthRequiredResponse auth_retval_; |
| 395 | 389 |
| 396 GURL redirect_url_; // Used if non-empty during OnBeforeURLRequest. | 390 GURL redirect_url_; // Used if non-empty during OnBeforeURLRequest. |
| 397 int block_on_; // Bit mask: in which stages to block. | 391 int block_on_; // Bit mask: in which stages to block. |
| 398 | 392 |
| 399 // |auth_credentials_| will be copied to |*target_auth_credential_| on | 393 // |auth_credentials_| will be copied to |*target_auth_credential_| on |
| 400 // callback. | 394 // callback. |
| 401 AuthCredentials auth_credentials_; | 395 AuthCredentials auth_credentials_; |
| 402 AuthCredentials* target_auth_credentials_; | 396 AuthCredentials* target_auth_credentials_; |
| 403 | 397 |
| 404 // Internal variables, not set by not the user: | 398 // Internal variables, not set by not the user: |
| 405 // Last blocked stage waiting for user callback (unused if |block_mode_| != | 399 // Last blocked stage waiting for user callback (unused if |block_mode_| != |
| 406 // USER_CALLBACK). | 400 // USER_CALLBACK). |
| 407 Stage stage_blocked_for_callback_; | 401 Stage stage_blocked_for_callback_; |
| (...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 494 allowed_unsafe_redirect_url); | 488 allowed_unsafe_redirect_url); |
| 495 | 489 |
| 496 return MaybeBlockStage(ON_HEADERS_RECEIVED, callback); | 490 return MaybeBlockStage(ON_HEADERS_RECEIVED, callback); |
| 497 } | 491 } |
| 498 | 492 |
| 499 NetworkDelegate::AuthRequiredResponse BlockingNetworkDelegate::OnAuthRequired( | 493 NetworkDelegate::AuthRequiredResponse BlockingNetworkDelegate::OnAuthRequired( |
| 500 URLRequest* request, | 494 URLRequest* request, |
| 501 const AuthChallengeInfo& auth_info, | 495 const AuthChallengeInfo& auth_info, |
| 502 const AuthCallback& callback, | 496 const AuthCallback& callback, |
| 503 AuthCredentials* credentials) { | 497 AuthCredentials* credentials) { |
| 504 TestNetworkDelegate::OnAuthRequired(request, auth_info, callback, | 498 TestNetworkDelegate::OnAuthRequired( |
| 505 credentials); | 499 request, auth_info, callback, credentials); |
| 506 // Check that the user has provided callback for the previous blocked stage. | 500 // Check that the user has provided callback for the previous blocked stage. |
| 507 EXPECT_EQ(NOT_BLOCKED, stage_blocked_for_callback_); | 501 EXPECT_EQ(NOT_BLOCKED, stage_blocked_for_callback_); |
| 508 | 502 |
| 509 if ((block_on_ & ON_AUTH_REQUIRED) == 0) { | 503 if ((block_on_ & ON_AUTH_REQUIRED) == 0) { |
| 510 return AUTH_REQUIRED_RESPONSE_NO_ACTION; | 504 return AUTH_REQUIRED_RESPONSE_NO_ACTION; |
| 511 } | 505 } |
| 512 | 506 |
| 513 target_auth_credentials_ = credentials; | 507 target_auth_credentials_ = credentials; |
| 514 | 508 |
| 515 switch (block_mode_) { | 509 switch (block_mode_) { |
| 516 case SYNCHRONOUS: | 510 case SYNCHRONOUS: |
| 517 if (auth_retval_ == AUTH_REQUIRED_RESPONSE_SET_AUTH) | 511 if (auth_retval_ == AUTH_REQUIRED_RESPONSE_SET_AUTH) |
| 518 *target_auth_credentials_ = auth_credentials_; | 512 *target_auth_credentials_ = auth_credentials_; |
| 519 return auth_retval_; | 513 return auth_retval_; |
| 520 | 514 |
| 521 case AUTO_CALLBACK: | 515 case AUTO_CALLBACK: |
| 522 base::MessageLoop::current()->PostTask( | 516 base::MessageLoop::current()->PostTask( |
| 523 FROM_HERE, | 517 FROM_HERE, |
| 524 base::Bind(&BlockingNetworkDelegate::RunAuthCallback, | 518 base::Bind(&BlockingNetworkDelegate::RunAuthCallback, |
| 525 weak_factory_.GetWeakPtr(), auth_retval_, callback)); | 519 weak_factory_.GetWeakPtr(), |
| 520 auth_retval_, |
| 521 callback)); |
| 526 return AUTH_REQUIRED_RESPONSE_IO_PENDING; | 522 return AUTH_REQUIRED_RESPONSE_IO_PENDING; |
| 527 | 523 |
| 528 case USER_CALLBACK: | 524 case USER_CALLBACK: |
| 529 auth_callback_ = callback; | 525 auth_callback_ = callback; |
| 530 stage_blocked_for_callback_ = ON_AUTH_REQUIRED; | 526 stage_blocked_for_callback_ = ON_AUTH_REQUIRED; |
| 531 base::MessageLoop::current()->PostTask(FROM_HERE, | 527 base::MessageLoop::current()->PostTask(FROM_HERE, |
| 532 base::MessageLoop::QuitClosure()); | 528 base::MessageLoop::QuitClosure()); |
| 533 return AUTH_REQUIRED_RESPONSE_IO_PENDING; | 529 return AUTH_REQUIRED_RESPONSE_IO_PENDING; |
| 534 } | 530 } |
| 535 NOTREACHED(); | 531 NOTREACHED(); |
| (...skipping 19 matching lines...) Expand all Loading... |
| 555 | 551 |
| 556 switch (block_mode_) { | 552 switch (block_mode_) { |
| 557 case SYNCHRONOUS: | 553 case SYNCHRONOUS: |
| 558 EXPECT_NE(OK, retval_); | 554 EXPECT_NE(OK, retval_); |
| 559 return retval_; | 555 return retval_; |
| 560 | 556 |
| 561 case AUTO_CALLBACK: | 557 case AUTO_CALLBACK: |
| 562 base::MessageLoop::current()->PostTask( | 558 base::MessageLoop::current()->PostTask( |
| 563 FROM_HERE, | 559 FROM_HERE, |
| 564 base::Bind(&BlockingNetworkDelegate::RunCallback, | 560 base::Bind(&BlockingNetworkDelegate::RunCallback, |
| 565 weak_factory_.GetWeakPtr(), retval_, callback)); | 561 weak_factory_.GetWeakPtr(), |
| 562 retval_, |
| 563 callback)); |
| 566 return ERR_IO_PENDING; | 564 return ERR_IO_PENDING; |
| 567 | 565 |
| 568 case USER_CALLBACK: | 566 case USER_CALLBACK: |
| 569 callback_ = callback; | 567 callback_ = callback; |
| 570 stage_blocked_for_callback_ = stage; | 568 stage_blocked_for_callback_ = stage; |
| 571 base::MessageLoop::current()->PostTask(FROM_HERE, | 569 base::MessageLoop::current()->PostTask(FROM_HERE, |
| 572 base::MessageLoop::QuitClosure()); | 570 base::MessageLoop::QuitClosure()); |
| 573 return ERR_IO_PENDING; | 571 return ERR_IO_PENDING; |
| 574 } | 572 } |
| 575 NOTREACHED(); | 573 NOTREACHED(); |
| (...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 643 EXPECT_FALSE(r.GetFullRequestHeaders(&headers)); | 641 EXPECT_FALSE(r.GetFullRequestHeaders(&headers)); |
| 644 } | 642 } |
| 645 } | 643 } |
| 646 | 644 |
| 647 TEST_F(URLRequestTest, DataURLImageTest) { | 645 TEST_F(URLRequestTest, DataURLImageTest) { |
| 648 TestDelegate d; | 646 TestDelegate d; |
| 649 { | 647 { |
| 650 // Use our nice little Chrome logo. | 648 // Use our nice little Chrome logo. |
| 651 URLRequest r( | 649 URLRequest r( |
| 652 GURL( | 650 GURL( |
| 653 "data:image/png;base64," | 651 "data:image/png;base64," |
| 654 "iVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAYAAAAf8/9hAAADVklEQVQ4jX2TfUwUBBjG3" | 652 "iVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAYAAAAf8/" |
| 655 "w1y+HGcd9dxhXR8T4awOccJGgOSWclHImznLkTlSw0DDQXkrmgYgbUYnlQTqQxIEVxitD" | 653 "9hAAADVklEQVQ4jX2TfUwUBBjG3" |
| 656 "5UMCATRA1CEEg+Qjw3bWDxIauJv/5oumqs39/P827vnucRmYN0gyF01GI5MpCVdW0gO7t" | 654 "w1y+" |
| 657 "vNC+vqSEtbZefk5NuLv1jdJ46p/zw0HeH4+PHr3h7c1mjoV2t5rKzMx1+fg9bAgK6zHq9" | 655 "HGcd9dxhXR8T4awOccJGgOSWclHImznLkTlSw0DDQXkrmgYgbUYnlQTqQxIEVxitD" |
| 658 "cU5z+LpA3xOtx34+vTeT21onRuzssC3zxbbSwC13d/pFuC7CkIMDxQpF7r/MWq12UctI1" | 656 "5UMCATRA1CEEg+Qjw3bWDxIauJv/5oumqs39/" |
| 659 "dWWm99ypqSYmRUBdKem8MkrO/kgaTt1O7YzlpzE5GIVd0WYUqt57yWf2McHTObYPbVD+Z" | 657 "P827vnucRmYN0gyF01GI5MpCVdW0gO7t" |
| 660 "wbtlLTVMZ3BW+TnLyXLaWtmEq6WJVbT3HBh3Svj2HQQcm43XwmtoYM6vVKleh0uoWvnzW" | 658 "vNC+vqSEtbZefk5NuLv1jdJ46p/" |
| 661 "3v3MpidruPTQPf0bia7sJOtBM0ufTWNvus/nkDFHF9ZS+uYVjRUasMeHUmyLYtcklTvzW" | 659 "zw0HeH4+PHr3h7c1mjoV2t5rKzMx1+fg9bAgK6zHq9" |
| 662 "GFZnNOXczThvpKIzjcahSqIzkvDLayDq6D3eOjtBbNUEIZYyqsvj4V4wY92eNJ4IoyhTb" | 660 "cU5z+LpA3xOtx34+vTeT21onRuzssC3zxbbSwC13d/pFuC7CkIMDxQpF7r/" |
| 663 "xXX1T5xsV9tm9r4TQwHLiZw/pdDZJea8TKmsmR/K0uLh/GwnCHghTja6lPhphezPfO5/5" | 661 "MWq12UctI1" |
| 664 "MrVvMzNaI3+ERHfrFzPKQukrQGI4d/3EFD/3E2mVNYvi4at7CXWREaxZGD+3hg28zD3gV" | 662 "dWWm99ypqSYmRUBdKem8MkrO/" |
| 665 "Md6q5c8GdosynKmSeRuGzpjyl1/9UDGtPR5HeaKT8Wjo17WXk579BXVUhN64ehF9fhRtq" | 663 "kgaTt1O7YzlpzE5GIVd0WYUqt57yWf2McHTObYPbVD+Z" |
| 666 "/uxxZKzNiZFGD0wRC3NFROZ5mwIPL/96K/rKMMLrIzF9uhHr+/sYH7DAbwlgC4J+R2Z7F" | 664 "wbtlLTVMZ3BW+" |
| 667 "Ux1qLnV7MGF40smVSoJ/jvHRfYhQeUJd/SnYtGWhPHR0Sz+GE2F2yth0B36Vcz2KpnufB" | 665 "TnLyXLaWtmEq6WJVbT3HBh3Svj2HQQcm43XwmtoYM6vVKleh0uoWvnzW" |
| 668 "JbsysjjW4kblBUiIjiURUWqJY65zxbnTy57GQyH58zgy0QBtTQv5gH15XMdKkYu+TGaJM" | 666 "3v3MpidruPTQPf0bia7sJOtBM0ufTWNvus/" |
| 669 "nlm2O34uI4b9tflqp1+QEFGzoW/ulmcofcpkZCYJhDfSpme7QcrHa+Xfji8paEQkTkSfm" | 667 "nkDFHF9ZS+uYVjRUasMeHUmyLYtcklTvzW" |
| 670 "moRWRNZr/F1KfVMjW+IKEnv2FwZfKdzt0BQR6lClcZR0EfEXEfv/G6W9iLiIyCoReV5En" | 668 "GFZnNOXczThvpKIzjcahSqIzkvDLayDq6D3eOjtBbNUEIZYyqsvj4V4wY92eNJ4Ioy" |
| 671 "hORIBHx+ufPj/gLB/zGI/G4Bk0AAAAASUVORK5CYII="), | 669 "hTb" |
| 670 "xXX1T5xsV9tm9r4TQwHLiZw/pdDZJea8TKmsmR/K0uLh/" |
| 671 "GwnCHghTja6lPhphezPfO5/5" |
| 672 "MrVvMzNaI3+ERHfrFzPKQukrQGI4d/3EFD/" |
| 673 "3E2mVNYvi4at7CXWREaxZGD+3hg28zD3gV" |
| 674 "Md6q5c8GdosynKmSeRuGzpjyl1/" |
| 675 "9UDGtPR5HeaKT8Wjo17WXk579BXVUhN64ehF9fhRtq" |
| 676 "/uxxZKzNiZFGD0wRC3NFROZ5mwIPL/96K/rKMMLrIzF9uhHr+/" |
| 677 "sYH7DAbwlgC4J+R2Z7F" |
| 678 "Ux1qLnV7MGF40smVSoJ/jvHRfYhQeUJd/" |
| 679 "SnYtGWhPHR0Sz+GE2F2yth0B36Vcz2KpnufB" |
| 680 "JbsysjjW4kblBUiIjiURUWqJY65zxbnTy57GQyH58zgy0QBtTQv5gH15XMdKkYu+" |
| 681 "TGaJM" |
| 682 "nlm2O34uI4b9tflqp1+QEFGzoW/" |
| 683 "ulmcofcpkZCYJhDfSpme7QcrHa+Xfji8paEQkTkSfm" |
| 684 "moRWRNZr/F1KfVMjW+IKEnv2FwZfKdzt0BQR6lClcZR0EfEXEfv/" |
| 685 "G6W9iLiIyCoReV5En" |
| 686 "hORIBHx+ufPj/gLB/zGI/G4Bk0AAAAASUVORK5CYII="), |
| 672 DEFAULT_PRIORITY, | 687 DEFAULT_PRIORITY, |
| 673 &d, | 688 &d, |
| 674 &default_context_); | 689 &default_context_); |
| 675 | 690 |
| 676 r.Start(); | 691 r.Start(); |
| 677 EXPECT_TRUE(r.is_pending()); | 692 EXPECT_TRUE(r.is_pending()); |
| 678 | 693 |
| 679 base::RunLoop().Run(); | 694 base::RunLoop().Run(); |
| 680 | 695 |
| 681 EXPECT_TRUE(!r.is_pending()); | 696 EXPECT_TRUE(!r.is_pending()); |
| (...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 755 std::string partial_buffer_string(buffer.get() + first_byte_position, | 770 std::string partial_buffer_string(buffer.get() + first_byte_position, |
| 756 buffer.get() + last_byte_position + 1); | 771 buffer.get() + last_byte_position + 1); |
| 757 | 772 |
| 758 TestDelegate d; | 773 TestDelegate d; |
| 759 { | 774 { |
| 760 URLRequest r(temp_url, DEFAULT_PRIORITY, &d, &default_context_); | 775 URLRequest r(temp_url, DEFAULT_PRIORITY, &d, &default_context_); |
| 761 | 776 |
| 762 HttpRequestHeaders headers; | 777 HttpRequestHeaders headers; |
| 763 headers.SetHeader( | 778 headers.SetHeader( |
| 764 HttpRequestHeaders::kRange, | 779 HttpRequestHeaders::kRange, |
| 765 net::HttpByteRange::Bounded( | 780 net::HttpByteRange::Bounded(first_byte_position, last_byte_position) |
| 766 first_byte_position, last_byte_position).GetHeaderValue()); | 781 .GetHeaderValue()); |
| 767 r.SetExtraRequestHeaders(headers); | 782 r.SetExtraRequestHeaders(headers); |
| 768 r.Start(); | 783 r.Start(); |
| 769 EXPECT_TRUE(r.is_pending()); | 784 EXPECT_TRUE(r.is_pending()); |
| 770 | 785 |
| 771 base::RunLoop().Run(); | 786 base::RunLoop().Run(); |
| 772 EXPECT_TRUE(!r.is_pending()); | 787 EXPECT_TRUE(!r.is_pending()); |
| 773 EXPECT_EQ(1, d.response_started_count()); | 788 EXPECT_EQ(1, d.response_started_count()); |
| 774 EXPECT_FALSE(d.received_data_before_response()); | 789 EXPECT_FALSE(d.received_data_before_response()); |
| 775 EXPECT_EQ(static_cast<int>(content_length), d.bytes_received()); | 790 EXPECT_EQ(static_cast<int>(content_length), d.bytes_received()); |
| 776 // Don't use EXPECT_EQ, it will print out a lot of garbage if check failed. | 791 // Don't use EXPECT_EQ, it will print out a lot of garbage if check failed. |
| (...skipping 21 matching lines...) Expand all Loading... |
| 798 const size_t content_length = last_byte_position - first_byte_position + 1; | 813 const size_t content_length = last_byte_position - first_byte_position + 1; |
| 799 std::string partial_buffer_string(buffer.get() + first_byte_position, | 814 std::string partial_buffer_string(buffer.get() + first_byte_position, |
| 800 buffer.get() + last_byte_position + 1); | 815 buffer.get() + last_byte_position + 1); |
| 801 | 816 |
| 802 TestDelegate d; | 817 TestDelegate d; |
| 803 { | 818 { |
| 804 URLRequest r(temp_url, DEFAULT_PRIORITY, &d, &default_context_); | 819 URLRequest r(temp_url, DEFAULT_PRIORITY, &d, &default_context_); |
| 805 | 820 |
| 806 HttpRequestHeaders headers; | 821 HttpRequestHeaders headers; |
| 807 headers.SetHeader(HttpRequestHeaders::kRange, | 822 headers.SetHeader(HttpRequestHeaders::kRange, |
| 808 net::HttpByteRange::RightUnbounded( | 823 net::HttpByteRange::RightUnbounded(first_byte_position) |
| 809 first_byte_position).GetHeaderValue()); | 824 .GetHeaderValue()); |
| 810 r.SetExtraRequestHeaders(headers); | 825 r.SetExtraRequestHeaders(headers); |
| 811 r.Start(); | 826 r.Start(); |
| 812 EXPECT_TRUE(r.is_pending()); | 827 EXPECT_TRUE(r.is_pending()); |
| 813 | 828 |
| 814 base::RunLoop().Run(); | 829 base::RunLoop().Run(); |
| 815 EXPECT_TRUE(!r.is_pending()); | 830 EXPECT_TRUE(!r.is_pending()); |
| 816 EXPECT_EQ(1, d.response_started_count()); | 831 EXPECT_EQ(1, d.response_started_count()); |
| 817 EXPECT_FALSE(d.received_data_before_response()); | 832 EXPECT_FALSE(d.received_data_before_response()); |
| 818 EXPECT_EQ(static_cast<int>(content_length), d.bytes_received()); | 833 EXPECT_EQ(static_cast<int>(content_length), d.bytes_received()); |
| 819 // Don't use EXPECT_EQ, it will print out a lot of garbage if check failed. | 834 // Don't use EXPECT_EQ, it will print out a lot of garbage if check failed. |
| (...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 909 app_path = app_path.AppendASCII("url_request_unittest"); | 924 app_path = app_path.AppendASCII("url_request_unittest"); |
| 910 app_path = app_path.AppendASCII("with-headers.html"); | 925 app_path = app_path.AppendASCII("with-headers.html"); |
| 911 | 926 |
| 912 std::wstring lnk_path = app_path.value() + L".lnk"; | 927 std::wstring lnk_path = app_path.value() + L".lnk"; |
| 913 | 928 |
| 914 base::win::ScopedCOMInitializer com_initializer; | 929 base::win::ScopedCOMInitializer com_initializer; |
| 915 | 930 |
| 916 // Temporarily create a shortcut for test | 931 // Temporarily create a shortcut for test |
| 917 { | 932 { |
| 918 base::win::ScopedComPtr<IShellLink> shell; | 933 base::win::ScopedComPtr<IShellLink> shell; |
| 919 ASSERT_TRUE(SUCCEEDED(shell.CreateInstance(CLSID_ShellLink, NULL, | 934 ASSERT_TRUE(SUCCEEDED( |
| 920 CLSCTX_INPROC_SERVER))); | 935 shell.CreateInstance(CLSID_ShellLink, NULL, CLSCTX_INPROC_SERVER))); |
| 921 base::win::ScopedComPtr<IPersistFile> persist; | 936 base::win::ScopedComPtr<IPersistFile> persist; |
| 922 ASSERT_TRUE(SUCCEEDED(shell.QueryInterface(persist.Receive()))); | 937 ASSERT_TRUE(SUCCEEDED(shell.QueryInterface(persist.Receive()))); |
| 923 EXPECT_TRUE(SUCCEEDED(shell->SetPath(app_path.value().c_str()))); | 938 EXPECT_TRUE(SUCCEEDED(shell->SetPath(app_path.value().c_str()))); |
| 924 EXPECT_TRUE(SUCCEEDED(shell->SetDescription(L"ResolveShortcutTest"))); | 939 EXPECT_TRUE(SUCCEEDED(shell->SetDescription(L"ResolveShortcutTest"))); |
| 925 EXPECT_TRUE(SUCCEEDED(persist->Save(lnk_path.c_str(), TRUE))); | 940 EXPECT_TRUE(SUCCEEDED(persist->Save(lnk_path.c_str(), TRUE))); |
| 926 } | 941 } |
| 927 | 942 |
| 928 TestDelegate d; | 943 TestDelegate d; |
| 929 { | 944 { |
| 930 URLRequest r(FilePathToFileURL(base::FilePath(lnk_path)), | 945 URLRequest r(FilePathToFileURL(base::FilePath(lnk_path)), |
| 931 DEFAULT_PRIORITY, | 946 DEFAULT_PRIORITY, |
| 932 &d, | 947 &d, |
| 933 &default_context_); | 948 &default_context_); |
| 934 | 949 |
| 935 r.Start(); | 950 r.Start(); |
| 936 EXPECT_TRUE(r.is_pending()); | 951 EXPECT_TRUE(r.is_pending()); |
| 937 | 952 |
| 938 base::RunLoop().Run(); | 953 base::RunLoop().Run(); |
| 939 | 954 |
| 940 WIN32_FILE_ATTRIBUTE_DATA data; | 955 WIN32_FILE_ATTRIBUTE_DATA data; |
| 941 GetFileAttributesEx(app_path.value().c_str(), | 956 GetFileAttributesEx(app_path.value().c_str(), GetFileExInfoStandard, &data); |
| 942 GetFileExInfoStandard, &data); | 957 HANDLE file = CreateFile(app_path.value().c_str(), |
| 943 HANDLE file = CreateFile(app_path.value().c_str(), GENERIC_READ, | 958 GENERIC_READ, |
| 944 FILE_SHARE_READ, NULL, OPEN_EXISTING, | 959 FILE_SHARE_READ, |
| 945 FILE_ATTRIBUTE_NORMAL, NULL); | 960 NULL, |
| 961 OPEN_EXISTING, |
| 962 FILE_ATTRIBUTE_NORMAL, |
| 963 NULL); |
| 946 EXPECT_NE(INVALID_HANDLE_VALUE, file); | 964 EXPECT_NE(INVALID_HANDLE_VALUE, file); |
| 947 scoped_ptr<char[]> buffer(new char[data.nFileSizeLow]); | 965 scoped_ptr<char[]> buffer(new char[data.nFileSizeLow]); |
| 948 DWORD read_size; | 966 DWORD read_size; |
| 949 BOOL result; | 967 BOOL result; |
| 950 result = ReadFile(file, buffer.get(), data.nFileSizeLow, | 968 result = ReadFile(file, buffer.get(), data.nFileSizeLow, &read_size, NULL); |
| 951 &read_size, NULL); | |
| 952 std::string content(buffer.get(), read_size); | 969 std::string content(buffer.get(), read_size); |
| 953 CloseHandle(file); | 970 CloseHandle(file); |
| 954 | 971 |
| 955 EXPECT_TRUE(!r.is_pending()); | 972 EXPECT_TRUE(!r.is_pending()); |
| 956 EXPECT_EQ(1, d.received_redirect_count()); | 973 EXPECT_EQ(1, d.received_redirect_count()); |
| 957 EXPECT_EQ(content, d.data_received()); | 974 EXPECT_EQ(content, d.data_received()); |
| 958 } | 975 } |
| 959 | 976 |
| 960 // Clean the shortcut | 977 // Clean the shortcut |
| 961 DeleteFile(lnk_path.c_str()); | 978 DeleteFile(lnk_path.c_str()); |
| (...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1058 | 1075 |
| 1059 ASSERT_EQ(1, d.received_redirect_count()); | 1076 ASSERT_EQ(1, d.received_redirect_count()); |
| 1060 ASSERT_FALSE(req.status().is_success()); | 1077 ASSERT_FALSE(req.status().is_success()); |
| 1061 } | 1078 } |
| 1062 #endif | 1079 #endif |
| 1063 | 1080 |
| 1064 // Custom URLRequestJobs for use with interceptor tests | 1081 // Custom URLRequestJobs for use with interceptor tests |
| 1065 class RestartTestJob : public URLRequestTestJob { | 1082 class RestartTestJob : public URLRequestTestJob { |
| 1066 public: | 1083 public: |
| 1067 RestartTestJob(URLRequest* request, NetworkDelegate* network_delegate) | 1084 RestartTestJob(URLRequest* request, NetworkDelegate* network_delegate) |
| 1068 : URLRequestTestJob(request, network_delegate, true) {} | 1085 : URLRequestTestJob(request, network_delegate, true) {} |
| 1086 |
| 1069 protected: | 1087 protected: |
| 1070 virtual void StartAsync() OVERRIDE { | 1088 virtual void StartAsync() OVERRIDE { this->NotifyRestartRequired(); } |
| 1071 this->NotifyRestartRequired(); | 1089 |
| 1072 } | |
| 1073 private: | 1090 private: |
| 1074 virtual ~RestartTestJob() {} | 1091 virtual ~RestartTestJob() {} |
| 1075 }; | 1092 }; |
| 1076 | 1093 |
| 1077 class CancelTestJob : public URLRequestTestJob { | 1094 class CancelTestJob : public URLRequestTestJob { |
| 1078 public: | 1095 public: |
| 1079 explicit CancelTestJob(URLRequest* request, NetworkDelegate* network_delegate) | 1096 explicit CancelTestJob(URLRequest* request, NetworkDelegate* network_delegate) |
| 1080 : URLRequestTestJob(request, network_delegate, true) {} | 1097 : URLRequestTestJob(request, network_delegate, true) {} |
| 1098 |
| 1081 protected: | 1099 protected: |
| 1082 virtual void StartAsync() OVERRIDE { | 1100 virtual void StartAsync() OVERRIDE { request_->Cancel(); } |
| 1083 request_->Cancel(); | 1101 |
| 1084 } | |
| 1085 private: | 1102 private: |
| 1086 virtual ~CancelTestJob() {} | 1103 virtual ~CancelTestJob() {} |
| 1087 }; | 1104 }; |
| 1088 | 1105 |
| 1089 class CancelThenRestartTestJob : public URLRequestTestJob { | 1106 class CancelThenRestartTestJob : public URLRequestTestJob { |
| 1090 public: | 1107 public: |
| 1091 explicit CancelThenRestartTestJob(URLRequest* request, | 1108 explicit CancelThenRestartTestJob(URLRequest* request, |
| 1092 NetworkDelegate* network_delegate) | 1109 NetworkDelegate* network_delegate) |
| 1093 : URLRequestTestJob(request, network_delegate, true) { | 1110 : URLRequestTestJob(request, network_delegate, true) {} |
| 1094 } | 1111 |
| 1095 protected: | 1112 protected: |
| 1096 virtual void StartAsync() OVERRIDE { | 1113 virtual void StartAsync() OVERRIDE { |
| 1097 request_->Cancel(); | 1114 request_->Cancel(); |
| 1098 this->NotifyRestartRequired(); | 1115 this->NotifyRestartRequired(); |
| 1099 } | 1116 } |
| 1117 |
| 1100 private: | 1118 private: |
| 1101 virtual ~CancelThenRestartTestJob() {} | 1119 virtual ~CancelThenRestartTestJob() {} |
| 1102 }; | 1120 }; |
| 1103 | 1121 |
| 1104 // An Interceptor for use with interceptor tests | 1122 // An Interceptor for use with interceptor tests |
| 1105 class TestInterceptor : URLRequest::Interceptor { | 1123 class TestInterceptor : URLRequest::Interceptor { |
| 1106 public: | 1124 public: |
| 1107 TestInterceptor() | 1125 TestInterceptor() |
| 1108 : intercept_main_request_(false), restart_main_request_(false), | 1126 : intercept_main_request_(false), |
| 1109 cancel_main_request_(false), cancel_then_restart_main_request_(false), | 1127 restart_main_request_(false), |
| 1128 cancel_main_request_(false), |
| 1129 cancel_then_restart_main_request_(false), |
| 1110 simulate_main_network_error_(false), | 1130 simulate_main_network_error_(false), |
| 1111 intercept_redirect_(false), cancel_redirect_request_(false), | 1131 intercept_redirect_(false), |
| 1112 intercept_final_response_(false), cancel_final_request_(false), | 1132 cancel_redirect_request_(false), |
| 1113 did_intercept_main_(false), did_restart_main_(false), | 1133 intercept_final_response_(false), |
| 1114 did_cancel_main_(false), did_cancel_then_restart_main_(false), | 1134 cancel_final_request_(false), |
| 1135 did_intercept_main_(false), |
| 1136 did_restart_main_(false), |
| 1137 did_cancel_main_(false), |
| 1138 did_cancel_then_restart_main_(false), |
| 1115 did_simulate_error_main_(false), | 1139 did_simulate_error_main_(false), |
| 1116 did_intercept_redirect_(false), did_cancel_redirect_(false), | 1140 did_intercept_redirect_(false), |
| 1117 did_intercept_final_(false), did_cancel_final_(false) { | 1141 did_cancel_redirect_(false), |
| 1142 did_intercept_final_(false), |
| 1143 did_cancel_final_(false) { |
| 1118 URLRequest::Deprecated::RegisterRequestInterceptor(this); | 1144 URLRequest::Deprecated::RegisterRequestInterceptor(this); |
| 1119 } | 1145 } |
| 1120 | 1146 |
| 1121 virtual ~TestInterceptor() { | 1147 virtual ~TestInterceptor() { |
| 1122 URLRequest::Deprecated::UnregisterRequestInterceptor(this); | 1148 URLRequest::Deprecated::UnregisterRequestInterceptor(this); |
| 1123 } | 1149 } |
| 1124 | 1150 |
| 1125 virtual URLRequestJob* MaybeIntercept( | 1151 virtual URLRequestJob* MaybeIntercept( |
| 1126 URLRequest* request, | 1152 URLRequest* request, |
| 1127 NetworkDelegate* network_delegate) OVERRIDE { | 1153 NetworkDelegate* network_delegate) OVERRIDE { |
| (...skipping 15 matching lines...) Expand all Loading... |
| 1143 if (simulate_main_network_error_) { | 1169 if (simulate_main_network_error_) { |
| 1144 simulate_main_network_error_ = false; | 1170 simulate_main_network_error_ = false; |
| 1145 did_simulate_error_main_ = true; | 1171 did_simulate_error_main_ = true; |
| 1146 // will error since the requeted url is not one of its canned urls | 1172 // will error since the requeted url is not one of its canned urls |
| 1147 return new URLRequestTestJob(request, network_delegate, true); | 1173 return new URLRequestTestJob(request, network_delegate, true); |
| 1148 } | 1174 } |
| 1149 if (!intercept_main_request_) | 1175 if (!intercept_main_request_) |
| 1150 return NULL; | 1176 return NULL; |
| 1151 intercept_main_request_ = false; | 1177 intercept_main_request_ = false; |
| 1152 did_intercept_main_ = true; | 1178 did_intercept_main_ = true; |
| 1153 URLRequestTestJob* job = new URLRequestTestJob(request, | 1179 URLRequestTestJob* job = new URLRequestTestJob( |
| 1154 network_delegate, | 1180 request, network_delegate, main_headers_, main_data_, true); |
| 1155 main_headers_, | |
| 1156 main_data_, | |
| 1157 true); | |
| 1158 job->set_load_timing_info(main_request_load_timing_info_); | 1181 job->set_load_timing_info(main_request_load_timing_info_); |
| 1159 return job; | 1182 return job; |
| 1160 } | 1183 } |
| 1161 | 1184 |
| 1162 virtual URLRequestJob* MaybeInterceptRedirect( | 1185 virtual URLRequestJob* MaybeInterceptRedirect( |
| 1163 URLRequest* request, | 1186 URLRequest* request, |
| 1164 NetworkDelegate* network_delegate, | 1187 NetworkDelegate* network_delegate, |
| 1165 const GURL& location) OVERRIDE { | 1188 const GURL& location) OVERRIDE { |
| 1166 if (cancel_redirect_request_) { | 1189 if (cancel_redirect_request_) { |
| 1167 cancel_redirect_request_ = false; | 1190 cancel_redirect_request_ = false; |
| 1168 did_cancel_redirect_ = true; | 1191 did_cancel_redirect_ = true; |
| 1169 return new CancelTestJob(request, network_delegate); | 1192 return new CancelTestJob(request, network_delegate); |
| 1170 } | 1193 } |
| 1171 if (!intercept_redirect_) | 1194 if (!intercept_redirect_) |
| 1172 return NULL; | 1195 return NULL; |
| 1173 intercept_redirect_ = false; | 1196 intercept_redirect_ = false; |
| 1174 did_intercept_redirect_ = true; | 1197 did_intercept_redirect_ = true; |
| 1175 return new URLRequestTestJob(request, | 1198 return new URLRequestTestJob( |
| 1176 network_delegate, | 1199 request, network_delegate, redirect_headers_, redirect_data_, true); |
| 1177 redirect_headers_, | |
| 1178 redirect_data_, | |
| 1179 true); | |
| 1180 } | 1200 } |
| 1181 | 1201 |
| 1182 virtual URLRequestJob* MaybeInterceptResponse( | 1202 virtual URLRequestJob* MaybeInterceptResponse( |
| 1183 URLRequest* request, NetworkDelegate* network_delegate) OVERRIDE { | 1203 URLRequest* request, |
| 1204 NetworkDelegate* network_delegate) OVERRIDE { |
| 1184 if (cancel_final_request_) { | 1205 if (cancel_final_request_) { |
| 1185 cancel_final_request_ = false; | 1206 cancel_final_request_ = false; |
| 1186 did_cancel_final_ = true; | 1207 did_cancel_final_ = true; |
| 1187 return new CancelTestJob(request, network_delegate); | 1208 return new CancelTestJob(request, network_delegate); |
| 1188 } | 1209 } |
| 1189 if (!intercept_final_response_) | 1210 if (!intercept_final_response_) |
| 1190 return NULL; | 1211 return NULL; |
| 1191 intercept_final_response_ = false; | 1212 intercept_final_response_ = false; |
| 1192 did_intercept_final_ = true; | 1213 did_intercept_final_ = true; |
| 1193 return new URLRequestTestJob(request, | 1214 return new URLRequestTestJob( |
| 1194 network_delegate, | 1215 request, network_delegate, final_headers_, final_data_, true); |
| 1195 final_headers_, | |
| 1196 final_data_, | |
| 1197 true); | |
| 1198 } | 1216 } |
| 1199 | 1217 |
| 1200 // Whether to intercept the main request, and if so the response to return and | 1218 // Whether to intercept the main request, and if so the response to return and |
| 1201 // the LoadTimingInfo to use. | 1219 // the LoadTimingInfo to use. |
| 1202 bool intercept_main_request_; | 1220 bool intercept_main_request_; |
| 1203 std::string main_headers_; | 1221 std::string main_headers_; |
| 1204 std::string main_data_; | 1222 std::string main_data_; |
| 1205 LoadTimingInfo main_request_load_timing_info_; | 1223 LoadTimingInfo main_request_load_timing_info_; |
| 1206 | 1224 |
| 1207 // Other actions we take at MaybeIntercept time | 1225 // Other actions we take at MaybeIntercept time |
| (...skipping 24 matching lines...) Expand all Loading... |
| 1232 bool did_cancel_main_; | 1250 bool did_cancel_main_; |
| 1233 bool did_cancel_then_restart_main_; | 1251 bool did_cancel_then_restart_main_; |
| 1234 bool did_simulate_error_main_; | 1252 bool did_simulate_error_main_; |
| 1235 bool did_intercept_redirect_; | 1253 bool did_intercept_redirect_; |
| 1236 bool did_cancel_redirect_; | 1254 bool did_cancel_redirect_; |
| 1237 bool did_intercept_final_; | 1255 bool did_intercept_final_; |
| 1238 bool did_cancel_final_; | 1256 bool did_cancel_final_; |
| 1239 | 1257 |
| 1240 // Static getters for canned response header and data strings | 1258 // Static getters for canned response header and data strings |
| 1241 | 1259 |
| 1242 static std::string ok_data() { | 1260 static std::string ok_data() { return URLRequestTestJob::test_data_1(); } |
| 1243 return URLRequestTestJob::test_data_1(); | |
| 1244 } | |
| 1245 | 1261 |
| 1246 static std::string ok_headers() { | 1262 static std::string ok_headers() { return URLRequestTestJob::test_headers(); } |
| 1247 return URLRequestTestJob::test_headers(); | |
| 1248 } | |
| 1249 | 1263 |
| 1250 static std::string redirect_data() { | 1264 static std::string redirect_data() { return std::string(); } |
| 1251 return std::string(); | |
| 1252 } | |
| 1253 | 1265 |
| 1254 static std::string redirect_headers() { | 1266 static std::string redirect_headers() { |
| 1255 return URLRequestTestJob::test_redirect_headers(); | 1267 return URLRequestTestJob::test_redirect_headers(); |
| 1256 } | 1268 } |
| 1257 | 1269 |
| 1258 static std::string error_data() { | 1270 static std::string error_data() { |
| 1259 return std::string("ohhh nooooo mr. bill!"); | 1271 return std::string("ohhh nooooo mr. bill!"); |
| 1260 } | 1272 } |
| 1261 | 1273 |
| 1262 static std::string error_headers() { | 1274 static std::string error_headers() { |
| (...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1306 TEST_F(URLRequestTest, InterceptRedirect) { | 1318 TEST_F(URLRequestTest, InterceptRedirect) { |
| 1307 TestInterceptor interceptor; | 1319 TestInterceptor interceptor; |
| 1308 | 1320 |
| 1309 // intercept the main request and respond with a redirect | 1321 // intercept the main request and respond with a redirect |
| 1310 interceptor.intercept_main_request_ = true; | 1322 interceptor.intercept_main_request_ = true; |
| 1311 interceptor.main_headers_ = TestInterceptor::redirect_headers(); | 1323 interceptor.main_headers_ = TestInterceptor::redirect_headers(); |
| 1312 interceptor.main_data_ = TestInterceptor::redirect_data(); | 1324 interceptor.main_data_ = TestInterceptor::redirect_data(); |
| 1313 | 1325 |
| 1314 // intercept that redirect and respond a final OK response | 1326 // intercept that redirect and respond a final OK response |
| 1315 interceptor.intercept_redirect_ = true; | 1327 interceptor.intercept_redirect_ = true; |
| 1316 interceptor.redirect_headers_ = TestInterceptor::ok_headers(); | 1328 interceptor.redirect_headers_ = TestInterceptor::ok_headers(); |
| 1317 interceptor.redirect_data_ = TestInterceptor::ok_data(); | 1329 interceptor.redirect_data_ = TestInterceptor::ok_data(); |
| 1318 | 1330 |
| 1319 TestDelegate d; | 1331 TestDelegate d; |
| 1320 URLRequest req(GURL("http://test_intercept/foo"), | 1332 URLRequest req(GURL("http://test_intercept/foo"), |
| 1321 DEFAULT_PRIORITY, | 1333 DEFAULT_PRIORITY, |
| 1322 &d, | 1334 &d, |
| 1323 &default_context_); | 1335 &default_context_); |
| 1324 req.set_method("GET"); | 1336 req.set_method("GET"); |
| 1325 req.Start(); | 1337 req.Start(); |
| 1326 base::RunLoop().Run(); | 1338 base::RunLoop().Run(); |
| (...skipping 647 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1974 : SpawnedTestServer(SpawnedTestServer::TYPE_HTTP, | 1986 : SpawnedTestServer(SpawnedTestServer::TYPE_HTTP, |
| 1975 ScopedCustomUrlRequestTestHttpHost::value(), | 1987 ScopedCustomUrlRequestTestHttpHost::value(), |
| 1976 base::FilePath()) {} | 1988 base::FilePath()) {} |
| 1977 }; | 1989 }; |
| 1978 | 1990 |
| 1979 TEST_F(URLRequestTest, DelayedCookieCallback) { | 1991 TEST_F(URLRequestTest, DelayedCookieCallback) { |
| 1980 LocalHttpTestServer test_server; | 1992 LocalHttpTestServer test_server; |
| 1981 ASSERT_TRUE(test_server.Start()); | 1993 ASSERT_TRUE(test_server.Start()); |
| 1982 | 1994 |
| 1983 TestURLRequestContext context; | 1995 TestURLRequestContext context; |
| 1984 scoped_refptr<DelayedCookieMonster> delayed_cm = | 1996 scoped_refptr<DelayedCookieMonster> delayed_cm = new DelayedCookieMonster(); |
| 1985 new DelayedCookieMonster(); | |
| 1986 scoped_refptr<CookieStore> cookie_store = delayed_cm; | 1997 scoped_refptr<CookieStore> cookie_store = delayed_cm; |
| 1987 context.set_cookie_store(delayed_cm.get()); | 1998 context.set_cookie_store(delayed_cm.get()); |
| 1988 | 1999 |
| 1989 // Set up a cookie. | 2000 // Set up a cookie. |
| 1990 { | 2001 { |
| 1991 TestNetworkDelegate network_delegate; | 2002 TestNetworkDelegate network_delegate; |
| 1992 context.set_network_delegate(&network_delegate); | 2003 context.set_network_delegate(&network_delegate); |
| 1993 TestDelegate d; | 2004 TestDelegate d; |
| 1994 URLRequest req(test_server.GetURL("set-cookie?CookieToNotSend=1"), | 2005 URLRequest req(test_server.GetURL("set-cookie?CookieToNotSend=1"), |
| 1995 DEFAULT_PRIORITY, | 2006 DEFAULT_PRIORITY, |
| (...skipping 11 matching lines...) Expand all Loading... |
| 2007 TestNetworkDelegate network_delegate; | 2018 TestNetworkDelegate network_delegate; |
| 2008 context.set_network_delegate(&network_delegate); | 2019 context.set_network_delegate(&network_delegate); |
| 2009 TestDelegate d; | 2020 TestDelegate d; |
| 2010 URLRequest req(test_server.GetURL("echoheader?Cookie"), | 2021 URLRequest req(test_server.GetURL("echoheader?Cookie"), |
| 2011 DEFAULT_PRIORITY, | 2022 DEFAULT_PRIORITY, |
| 2012 &d, | 2023 &d, |
| 2013 &context); | 2024 &context); |
| 2014 req.Start(); | 2025 req.Start(); |
| 2015 base::RunLoop().Run(); | 2026 base::RunLoop().Run(); |
| 2016 | 2027 |
| 2017 EXPECT_TRUE(d.data_received().find("CookieToNotSend=1") | 2028 EXPECT_TRUE(d.data_received().find("CookieToNotSend=1") != |
| 2018 != std::string::npos); | 2029 std::string::npos); |
| 2019 EXPECT_EQ(0, network_delegate.blocked_get_cookies_count()); | 2030 EXPECT_EQ(0, network_delegate.blocked_get_cookies_count()); |
| 2020 EXPECT_EQ(0, network_delegate.blocked_set_cookie_count()); | 2031 EXPECT_EQ(0, network_delegate.blocked_set_cookie_count()); |
| 2021 } | 2032 } |
| 2022 } | 2033 } |
| 2023 | 2034 |
| 2024 TEST_F(URLRequestTest, DoNotSendCookies) { | 2035 TEST_F(URLRequestTest, DoNotSendCookies) { |
| 2025 LocalHttpTestServer test_server; | 2036 LocalHttpTestServer test_server; |
| 2026 ASSERT_TRUE(test_server.Start()); | 2037 ASSERT_TRUE(test_server.Start()); |
| 2027 | 2038 |
| 2028 // Set up a cookie. | 2039 // Set up a cookie. |
| (...skipping 16 matching lines...) Expand all Loading... |
| 2045 TestNetworkDelegate network_delegate; | 2056 TestNetworkDelegate network_delegate; |
| 2046 default_context_.set_network_delegate(&network_delegate); | 2057 default_context_.set_network_delegate(&network_delegate); |
| 2047 TestDelegate d; | 2058 TestDelegate d; |
| 2048 URLRequest req(test_server.GetURL("echoheader?Cookie"), | 2059 URLRequest req(test_server.GetURL("echoheader?Cookie"), |
| 2049 DEFAULT_PRIORITY, | 2060 DEFAULT_PRIORITY, |
| 2050 &d, | 2061 &d, |
| 2051 &default_context_); | 2062 &default_context_); |
| 2052 req.Start(); | 2063 req.Start(); |
| 2053 base::RunLoop().Run(); | 2064 base::RunLoop().Run(); |
| 2054 | 2065 |
| 2055 EXPECT_TRUE(d.data_received().find("CookieToNotSend=1") | 2066 EXPECT_TRUE(d.data_received().find("CookieToNotSend=1") != |
| 2056 != std::string::npos); | 2067 std::string::npos); |
| 2057 EXPECT_EQ(0, network_delegate.blocked_get_cookies_count()); | 2068 EXPECT_EQ(0, network_delegate.blocked_get_cookies_count()); |
| 2058 EXPECT_EQ(0, network_delegate.blocked_set_cookie_count()); | 2069 EXPECT_EQ(0, network_delegate.blocked_set_cookie_count()); |
| 2059 } | 2070 } |
| 2060 | 2071 |
| 2061 // Verify that the cookie isn't sent when LOAD_DO_NOT_SEND_COOKIES is set. | 2072 // Verify that the cookie isn't sent when LOAD_DO_NOT_SEND_COOKIES is set. |
| 2062 { | 2073 { |
| 2063 TestNetworkDelegate network_delegate; | 2074 TestNetworkDelegate network_delegate; |
| 2064 default_context_.set_network_delegate(&network_delegate); | 2075 default_context_.set_network_delegate(&network_delegate); |
| 2065 TestDelegate d; | 2076 TestDelegate d; |
| 2066 URLRequest req(test_server.GetURL("echoheader?Cookie"), | 2077 URLRequest req(test_server.GetURL("echoheader?Cookie"), |
| 2067 DEFAULT_PRIORITY, | 2078 DEFAULT_PRIORITY, |
| 2068 &d, | 2079 &d, |
| 2069 &default_context_); | 2080 &default_context_); |
| 2070 req.SetLoadFlags(LOAD_DO_NOT_SEND_COOKIES); | 2081 req.SetLoadFlags(LOAD_DO_NOT_SEND_COOKIES); |
| 2071 req.Start(); | 2082 req.Start(); |
| 2072 base::RunLoop().Run(); | 2083 base::RunLoop().Run(); |
| 2073 | 2084 |
| 2074 EXPECT_TRUE(d.data_received().find("Cookie: CookieToNotSend=1") | 2085 EXPECT_TRUE(d.data_received().find("Cookie: CookieToNotSend=1") == |
| 2075 == std::string::npos); | 2086 std::string::npos); |
| 2076 | 2087 |
| 2077 // LOAD_DO_NOT_SEND_COOKIES does not trigger OnGetCookies. | 2088 // LOAD_DO_NOT_SEND_COOKIES does not trigger OnGetCookies. |
| 2078 EXPECT_EQ(0, network_delegate.blocked_get_cookies_count()); | 2089 EXPECT_EQ(0, network_delegate.blocked_get_cookies_count()); |
| 2079 EXPECT_EQ(0, network_delegate.blocked_set_cookie_count()); | 2090 EXPECT_EQ(0, network_delegate.blocked_set_cookie_count()); |
| 2080 } | 2091 } |
| 2081 } | 2092 } |
| 2082 | 2093 |
| 2083 TEST_F(URLRequestTest, DoNotSaveCookies) { | 2094 TEST_F(URLRequestTest, DoNotSaveCookies) { |
| 2084 LocalHttpTestServer test_server; | 2095 LocalHttpTestServer test_server; |
| 2085 ASSERT_TRUE(test_server.Start()); | 2096 ASSERT_TRUE(test_server.Start()); |
| (...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2127 TestNetworkDelegate network_delegate; | 2138 TestNetworkDelegate network_delegate; |
| 2128 default_context_.set_network_delegate(&network_delegate); | 2139 default_context_.set_network_delegate(&network_delegate); |
| 2129 TestDelegate d; | 2140 TestDelegate d; |
| 2130 URLRequest req(test_server.GetURL("echoheader?Cookie"), | 2141 URLRequest req(test_server.GetURL("echoheader?Cookie"), |
| 2131 DEFAULT_PRIORITY, | 2142 DEFAULT_PRIORITY, |
| 2132 &d, | 2143 &d, |
| 2133 &default_context_); | 2144 &default_context_); |
| 2134 req.Start(); | 2145 req.Start(); |
| 2135 base::RunLoop().Run(); | 2146 base::RunLoop().Run(); |
| 2136 | 2147 |
| 2137 EXPECT_TRUE(d.data_received().find("CookieToNotSave=1") | 2148 EXPECT_TRUE(d.data_received().find("CookieToNotSave=1") == |
| 2138 == std::string::npos); | 2149 std::string::npos); |
| 2139 EXPECT_TRUE(d.data_received().find("CookieToNotUpdate=2") | 2150 EXPECT_TRUE(d.data_received().find("CookieToNotUpdate=2") != |
| 2140 != std::string::npos); | 2151 std::string::npos); |
| 2141 | 2152 |
| 2142 EXPECT_EQ(0, network_delegate.blocked_get_cookies_count()); | 2153 EXPECT_EQ(0, network_delegate.blocked_get_cookies_count()); |
| 2143 EXPECT_EQ(0, network_delegate.blocked_set_cookie_count()); | 2154 EXPECT_EQ(0, network_delegate.blocked_set_cookie_count()); |
| 2144 EXPECT_EQ(0, network_delegate.set_cookie_count()); | 2155 EXPECT_EQ(0, network_delegate.set_cookie_count()); |
| 2145 } | 2156 } |
| 2146 } | 2157 } |
| 2147 | 2158 |
| 2148 TEST_F(URLRequestTest, DoNotSendCookies_ViaPolicy) { | 2159 TEST_F(URLRequestTest, DoNotSendCookies_ViaPolicy) { |
| 2149 LocalHttpTestServer test_server; | 2160 LocalHttpTestServer test_server; |
| 2150 ASSERT_TRUE(test_server.Start()); | 2161 ASSERT_TRUE(test_server.Start()); |
| (...skipping 19 matching lines...) Expand all Loading... |
| 2170 TestNetworkDelegate network_delegate; | 2181 TestNetworkDelegate network_delegate; |
| 2171 default_context_.set_network_delegate(&network_delegate); | 2182 default_context_.set_network_delegate(&network_delegate); |
| 2172 TestDelegate d; | 2183 TestDelegate d; |
| 2173 URLRequest req(test_server.GetURL("echoheader?Cookie"), | 2184 URLRequest req(test_server.GetURL("echoheader?Cookie"), |
| 2174 DEFAULT_PRIORITY, | 2185 DEFAULT_PRIORITY, |
| 2175 &d, | 2186 &d, |
| 2176 &default_context_); | 2187 &default_context_); |
| 2177 req.Start(); | 2188 req.Start(); |
| 2178 base::RunLoop().Run(); | 2189 base::RunLoop().Run(); |
| 2179 | 2190 |
| 2180 EXPECT_TRUE(d.data_received().find("CookieToNotSend=1") | 2191 EXPECT_TRUE(d.data_received().find("CookieToNotSend=1") != |
| 2181 != std::string::npos); | 2192 std::string::npos); |
| 2182 | 2193 |
| 2183 EXPECT_EQ(0, network_delegate.blocked_get_cookies_count()); | 2194 EXPECT_EQ(0, network_delegate.blocked_get_cookies_count()); |
| 2184 EXPECT_EQ(0, network_delegate.blocked_set_cookie_count()); | 2195 EXPECT_EQ(0, network_delegate.blocked_set_cookie_count()); |
| 2185 } | 2196 } |
| 2186 | 2197 |
| 2187 // Verify that the cookie isn't sent. | 2198 // Verify that the cookie isn't sent. |
| 2188 { | 2199 { |
| 2189 TestNetworkDelegate network_delegate; | 2200 TestNetworkDelegate network_delegate; |
| 2190 default_context_.set_network_delegate(&network_delegate); | 2201 default_context_.set_network_delegate(&network_delegate); |
| 2191 TestDelegate d; | 2202 TestDelegate d; |
| 2192 network_delegate.set_cookie_options(TestNetworkDelegate::NO_GET_COOKIES); | 2203 network_delegate.set_cookie_options(TestNetworkDelegate::NO_GET_COOKIES); |
| 2193 URLRequest req(test_server.GetURL("echoheader?Cookie"), | 2204 URLRequest req(test_server.GetURL("echoheader?Cookie"), |
| 2194 DEFAULT_PRIORITY, | 2205 DEFAULT_PRIORITY, |
| 2195 &d, | 2206 &d, |
| 2196 &default_context_); | 2207 &default_context_); |
| 2197 req.Start(); | 2208 req.Start(); |
| 2198 base::RunLoop().Run(); | 2209 base::RunLoop().Run(); |
| 2199 | 2210 |
| 2200 EXPECT_TRUE(d.data_received().find("Cookie: CookieToNotSend=1") | 2211 EXPECT_TRUE(d.data_received().find("Cookie: CookieToNotSend=1") == |
| 2201 == std::string::npos); | 2212 std::string::npos); |
| 2202 | 2213 |
| 2203 EXPECT_EQ(1, network_delegate.blocked_get_cookies_count()); | 2214 EXPECT_EQ(1, network_delegate.blocked_get_cookies_count()); |
| 2204 EXPECT_EQ(0, network_delegate.blocked_set_cookie_count()); | 2215 EXPECT_EQ(0, network_delegate.blocked_set_cookie_count()); |
| 2205 } | 2216 } |
| 2206 } | 2217 } |
| 2207 | 2218 |
| 2208 TEST_F(URLRequestTest, DoNotSaveCookies_ViaPolicy) { | 2219 TEST_F(URLRequestTest, DoNotSaveCookies_ViaPolicy) { |
| 2209 LocalHttpTestServer test_server; | 2220 LocalHttpTestServer test_server; |
| 2210 ASSERT_TRUE(test_server.Start()); | 2221 ASSERT_TRUE(test_server.Start()); |
| 2211 | 2222 |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2249 TestNetworkDelegate network_delegate; | 2260 TestNetworkDelegate network_delegate; |
| 2250 default_context_.set_network_delegate(&network_delegate); | 2261 default_context_.set_network_delegate(&network_delegate); |
| 2251 TestDelegate d; | 2262 TestDelegate d; |
| 2252 URLRequest req(test_server.GetURL("echoheader?Cookie"), | 2263 URLRequest req(test_server.GetURL("echoheader?Cookie"), |
| 2253 DEFAULT_PRIORITY, | 2264 DEFAULT_PRIORITY, |
| 2254 &d, | 2265 &d, |
| 2255 &default_context_); | 2266 &default_context_); |
| 2256 req.Start(); | 2267 req.Start(); |
| 2257 base::RunLoop().Run(); | 2268 base::RunLoop().Run(); |
| 2258 | 2269 |
| 2259 EXPECT_TRUE(d.data_received().find("CookieToNotSave=1") | 2270 EXPECT_TRUE(d.data_received().find("CookieToNotSave=1") == |
| 2260 == std::string::npos); | 2271 std::string::npos); |
| 2261 EXPECT_TRUE(d.data_received().find("CookieToNotUpdate=2") | 2272 EXPECT_TRUE(d.data_received().find("CookieToNotUpdate=2") != |
| 2262 != std::string::npos); | 2273 std::string::npos); |
| 2263 | 2274 |
| 2264 EXPECT_EQ(0, network_delegate.blocked_get_cookies_count()); | 2275 EXPECT_EQ(0, network_delegate.blocked_get_cookies_count()); |
| 2265 EXPECT_EQ(0, network_delegate.blocked_set_cookie_count()); | 2276 EXPECT_EQ(0, network_delegate.blocked_set_cookie_count()); |
| 2266 } | 2277 } |
| 2267 } | 2278 } |
| 2268 | 2279 |
| 2269 TEST_F(URLRequestTest, DoNotSaveEmptyCookies) { | 2280 TEST_F(URLRequestTest, DoNotSaveEmptyCookies) { |
| 2270 LocalHttpTestServer test_server; | 2281 LocalHttpTestServer test_server; |
| 2271 ASSERT_TRUE(test_server.Start()); | 2282 ASSERT_TRUE(test_server.Start()); |
| 2272 | 2283 |
| (...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2313 TestNetworkDelegate network_delegate; | 2324 TestNetworkDelegate network_delegate; |
| 2314 default_context_.set_network_delegate(&network_delegate); | 2325 default_context_.set_network_delegate(&network_delegate); |
| 2315 TestDelegate d; | 2326 TestDelegate d; |
| 2316 URLRequest req(test_server.GetURL("echoheader?Cookie"), | 2327 URLRequest req(test_server.GetURL("echoheader?Cookie"), |
| 2317 DEFAULT_PRIORITY, | 2328 DEFAULT_PRIORITY, |
| 2318 &d, | 2329 &d, |
| 2319 &default_context_); | 2330 &default_context_); |
| 2320 req.Start(); | 2331 req.Start(); |
| 2321 base::RunLoop().Run(); | 2332 base::RunLoop().Run(); |
| 2322 | 2333 |
| 2323 EXPECT_TRUE(d.data_received().find("CookieToNotSend=1") | 2334 EXPECT_TRUE(d.data_received().find("CookieToNotSend=1") != |
| 2324 != std::string::npos); | 2335 std::string::npos); |
| 2325 | 2336 |
| 2326 EXPECT_EQ(0, network_delegate.blocked_get_cookies_count()); | 2337 EXPECT_EQ(0, network_delegate.blocked_get_cookies_count()); |
| 2327 EXPECT_EQ(0, network_delegate.blocked_set_cookie_count()); | 2338 EXPECT_EQ(0, network_delegate.blocked_set_cookie_count()); |
| 2328 } | 2339 } |
| 2329 | 2340 |
| 2330 // Verify that the cookie isn't sent. | 2341 // Verify that the cookie isn't sent. |
| 2331 { | 2342 { |
| 2332 TestNetworkDelegate network_delegate; | 2343 TestNetworkDelegate network_delegate; |
| 2333 default_context_.set_network_delegate(&network_delegate); | 2344 default_context_.set_network_delegate(&network_delegate); |
| 2334 TestDelegate d; | 2345 TestDelegate d; |
| 2335 network_delegate.set_cookie_options(TestNetworkDelegate::NO_GET_COOKIES); | 2346 network_delegate.set_cookie_options(TestNetworkDelegate::NO_GET_COOKIES); |
| 2336 URLRequest req(test_server.GetURL("echoheader?Cookie"), | 2347 URLRequest req(test_server.GetURL("echoheader?Cookie"), |
| 2337 DEFAULT_PRIORITY, | 2348 DEFAULT_PRIORITY, |
| 2338 &d, | 2349 &d, |
| 2339 &default_context_); | 2350 &default_context_); |
| 2340 req.Start(); | 2351 req.Start(); |
| 2341 base::RunLoop().Run(); | 2352 base::RunLoop().Run(); |
| 2342 | 2353 |
| 2343 EXPECT_TRUE(d.data_received().find("Cookie: CookieToNotSend=1") | 2354 EXPECT_TRUE(d.data_received().find("Cookie: CookieToNotSend=1") == |
| 2344 == std::string::npos); | 2355 std::string::npos); |
| 2345 | 2356 |
| 2346 EXPECT_EQ(1, network_delegate.blocked_get_cookies_count()); | 2357 EXPECT_EQ(1, network_delegate.blocked_get_cookies_count()); |
| 2347 EXPECT_EQ(0, network_delegate.blocked_set_cookie_count()); | 2358 EXPECT_EQ(0, network_delegate.blocked_set_cookie_count()); |
| 2348 } | 2359 } |
| 2349 } | 2360 } |
| 2350 | 2361 |
| 2351 TEST_F(URLRequestTest, DoNotSaveCookies_ViaPolicy_Async) { | 2362 TEST_F(URLRequestTest, DoNotSaveCookies_ViaPolicy_Async) { |
| 2352 LocalHttpTestServer test_server; | 2363 LocalHttpTestServer test_server; |
| 2353 ASSERT_TRUE(test_server.Start()); | 2364 ASSERT_TRUE(test_server.Start()); |
| 2354 | 2365 |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2392 TestNetworkDelegate network_delegate; | 2403 TestNetworkDelegate network_delegate; |
| 2393 default_context_.set_network_delegate(&network_delegate); | 2404 default_context_.set_network_delegate(&network_delegate); |
| 2394 TestDelegate d; | 2405 TestDelegate d; |
| 2395 URLRequest req(test_server.GetURL("echoheader?Cookie"), | 2406 URLRequest req(test_server.GetURL("echoheader?Cookie"), |
| 2396 DEFAULT_PRIORITY, | 2407 DEFAULT_PRIORITY, |
| 2397 &d, | 2408 &d, |
| 2398 &default_context_); | 2409 &default_context_); |
| 2399 req.Start(); | 2410 req.Start(); |
| 2400 base::RunLoop().Run(); | 2411 base::RunLoop().Run(); |
| 2401 | 2412 |
| 2402 EXPECT_TRUE(d.data_received().find("CookieToNotSave=1") | 2413 EXPECT_TRUE(d.data_received().find("CookieToNotSave=1") == |
| 2403 == std::string::npos); | 2414 std::string::npos); |
| 2404 EXPECT_TRUE(d.data_received().find("CookieToNotUpdate=2") | 2415 EXPECT_TRUE(d.data_received().find("CookieToNotUpdate=2") != |
| 2405 != std::string::npos); | 2416 std::string::npos); |
| 2406 | 2417 |
| 2407 EXPECT_EQ(0, network_delegate.blocked_get_cookies_count()); | 2418 EXPECT_EQ(0, network_delegate.blocked_get_cookies_count()); |
| 2408 EXPECT_EQ(0, network_delegate.blocked_set_cookie_count()); | 2419 EXPECT_EQ(0, network_delegate.blocked_set_cookie_count()); |
| 2409 } | 2420 } |
| 2410 } | 2421 } |
| 2411 | 2422 |
| 2412 // FixedDateNetworkDelegate swaps out the server's HTTP Date response header | 2423 // FixedDateNetworkDelegate swaps out the server's HTTP Date response header |
| 2413 // value for the |fixed_date| argument given to the constructor. | 2424 // value for the |fixed_date| argument given to the constructor. |
| 2414 class FixedDateNetworkDelegate : public TestNetworkDelegate { | 2425 class FixedDateNetworkDelegate : public TestNetworkDelegate { |
| 2415 public: | 2426 public: |
| (...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2509 DEFAULT_PRIORITY, | 2520 DEFAULT_PRIORITY, |
| 2510 &d, | 2521 &d, |
| 2511 &default_context_); | 2522 &default_context_); |
| 2512 req.Start(); | 2523 req.Start(); |
| 2513 base::RunLoop().Run(); | 2524 base::RunLoop().Run(); |
| 2514 | 2525 |
| 2515 EXPECT_TRUE(d.data_received().find("StillGood=1") != std::string::npos); | 2526 EXPECT_TRUE(d.data_received().find("StillGood=1") != std::string::npos); |
| 2516 } | 2527 } |
| 2517 } | 2528 } |
| 2518 | 2529 |
| 2519 | |
| 2520 // Check that it is impossible to change the referrer in the extra headers of | 2530 // Check that it is impossible to change the referrer in the extra headers of |
| 2521 // an URLRequest. | 2531 // an URLRequest. |
| 2522 TEST_F(URLRequestTest, DoNotOverrideReferrer) { | 2532 TEST_F(URLRequestTest, DoNotOverrideReferrer) { |
| 2523 LocalHttpTestServer test_server; | 2533 LocalHttpTestServer test_server; |
| 2524 ASSERT_TRUE(test_server.Start()); | 2534 ASSERT_TRUE(test_server.Start()); |
| 2525 | 2535 |
| 2526 // If extra headers contain referer and the request contains a referer, | 2536 // If extra headers contain referer and the request contains a referer, |
| 2527 // only the latter shall be respected. | 2537 // only the latter shall be respected. |
| 2528 { | 2538 { |
| 2529 TestDelegate d; | 2539 TestDelegate d; |
| (...skipping 30 matching lines...) Expand all Loading... |
| 2560 req.Start(); | 2570 req.Start(); |
| 2561 base::RunLoop().Run(); | 2571 base::RunLoop().Run(); |
| 2562 | 2572 |
| 2563 EXPECT_EQ("None", d.data_received()); | 2573 EXPECT_EQ("None", d.data_received()); |
| 2564 } | 2574 } |
| 2565 } | 2575 } |
| 2566 | 2576 |
| 2567 class URLRequestTestHTTP : public URLRequestTest { | 2577 class URLRequestTestHTTP : public URLRequestTest { |
| 2568 public: | 2578 public: |
| 2569 URLRequestTestHTTP() | 2579 URLRequestTestHTTP() |
| 2570 : test_server_(base::FilePath(FILE_PATH_LITERAL( | 2580 : test_server_(base::FilePath( |
| 2571 "net/data/url_request_unittest"))) { | 2581 FILE_PATH_LITERAL("net/data/url_request_unittest"))) {} |
| 2572 } | |
| 2573 | 2582 |
| 2574 protected: | 2583 protected: |
| 2575 // Requests |redirect_url|, which must return a HTTP 3xx redirect. | 2584 // Requests |redirect_url|, which must return a HTTP 3xx redirect. |
| 2576 // |request_method| is the method to use for the initial request. | 2585 // |request_method| is the method to use for the initial request. |
| 2577 // |redirect_method| is the method that is expected to be used for the second | 2586 // |redirect_method| is the method that is expected to be used for the second |
| 2578 // request, after redirection. | 2587 // request, after redirection. |
| 2579 // If |include_data| is true, data is uploaded with the request. The | 2588 // If |include_data| is true, data is uploaded with the request. The |
| 2580 // response body is expected to match it exactly, if and only if | 2589 // response body is expected to match it exactly, if and only if |
| 2581 // |request_method| == |redirect_method|. | 2590 // |request_method| == |redirect_method|. |
| 2582 void HTTPRedirectMethodTest(const GURL& redirect_url, | 2591 void HTTPRedirectMethodTest(const GURL& redirect_url, |
| (...skipping 23 matching lines...) Expand all Loading... |
| 2606 EXPECT_NE(kData, d.data_received()); | 2615 EXPECT_NE(kData, d.data_received()); |
| 2607 } | 2616 } |
| 2608 } | 2617 } |
| 2609 if (HasFailure()) | 2618 if (HasFailure()) |
| 2610 LOG(WARNING) << "Request method was: " << request_method; | 2619 LOG(WARNING) << "Request method was: " << request_method; |
| 2611 } | 2620 } |
| 2612 | 2621 |
| 2613 void HTTPUploadDataOperationTest(const std::string& method) { | 2622 void HTTPUploadDataOperationTest(const std::string& method) { |
| 2614 const int kMsgSize = 20000; // multiple of 10 | 2623 const int kMsgSize = 20000; // multiple of 10 |
| 2615 const int kIterations = 50; | 2624 const int kIterations = 50; |
| 2616 char* uploadBytes = new char[kMsgSize+1]; | 2625 char* uploadBytes = new char[kMsgSize + 1]; |
| 2617 char* ptr = uploadBytes; | 2626 char* ptr = uploadBytes; |
| 2618 char marker = 'a'; | 2627 char marker = 'a'; |
| 2619 for (int idx = 0; idx < kMsgSize/10; idx++) { | 2628 for (int idx = 0; idx < kMsgSize / 10; idx++) { |
| 2620 memcpy(ptr, "----------", 10); | 2629 memcpy(ptr, "----------", 10); |
| 2621 ptr += 10; | 2630 ptr += 10; |
| 2622 if (idx % 100 == 0) { | 2631 if (idx % 100 == 0) { |
| 2623 ptr--; | 2632 ptr--; |
| 2624 *ptr++ = marker; | 2633 *ptr++ = marker; |
| 2625 if (++marker > 'z') | 2634 if (++marker > 'z') |
| 2626 marker = 'a'; | 2635 marker = 'a'; |
| 2627 } | 2636 } |
| 2628 } | 2637 } |
| 2629 uploadBytes[kMsgSize] = '\0'; | 2638 uploadBytes[kMsgSize] = '\0'; |
| (...skipping 127 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2757 EXPECT_EQ(0, d.received_redirect_count()); | 2766 EXPECT_EQ(0, d.received_redirect_count()); |
| 2758 | 2767 |
| 2759 EXPECT_EQ(1, network_delegate.error_count()); | 2768 EXPECT_EQ(1, network_delegate.error_count()); |
| 2760 EXPECT_EQ(ERR_TUNNEL_CONNECTION_FAILED, network_delegate.last_error()); | 2769 EXPECT_EQ(ERR_TUNNEL_CONNECTION_FAILED, network_delegate.last_error()); |
| 2761 } | 2770 } |
| 2762 } | 2771 } |
| 2763 | 2772 |
| 2764 // Tests that we can block and asynchronously return OK in various stages. | 2773 // Tests that we can block and asynchronously return OK in various stages. |
| 2765 TEST_F(URLRequestTestHTTP, NetworkDelegateBlockAsynchronously) { | 2774 TEST_F(URLRequestTestHTTP, NetworkDelegateBlockAsynchronously) { |
| 2766 static const BlockingNetworkDelegate::Stage blocking_stages[] = { | 2775 static const BlockingNetworkDelegate::Stage blocking_stages[] = { |
| 2767 BlockingNetworkDelegate::ON_BEFORE_URL_REQUEST, | 2776 BlockingNetworkDelegate::ON_BEFORE_URL_REQUEST, |
| 2768 BlockingNetworkDelegate::ON_BEFORE_SEND_HEADERS, | 2777 BlockingNetworkDelegate::ON_BEFORE_SEND_HEADERS, |
| 2769 BlockingNetworkDelegate::ON_HEADERS_RECEIVED | 2778 BlockingNetworkDelegate::ON_HEADERS_RECEIVED}; |
| 2770 }; | |
| 2771 static const size_t blocking_stages_length = arraysize(blocking_stages); | 2779 static const size_t blocking_stages_length = arraysize(blocking_stages); |
| 2772 | 2780 |
| 2773 ASSERT_TRUE(test_server_.Start()); | 2781 ASSERT_TRUE(test_server_.Start()); |
| 2774 | 2782 |
| 2775 TestDelegate d; | 2783 TestDelegate d; |
| 2776 BlockingNetworkDelegate network_delegate( | 2784 BlockingNetworkDelegate network_delegate( |
| 2777 BlockingNetworkDelegate::USER_CALLBACK); | 2785 BlockingNetworkDelegate::USER_CALLBACK); |
| 2778 network_delegate.set_block_on( | 2786 network_delegate.set_block_on( |
| 2779 BlockingNetworkDelegate::ON_BEFORE_URL_REQUEST | | 2787 BlockingNetworkDelegate::ON_BEFORE_URL_REQUEST | |
| 2780 BlockingNetworkDelegate::ON_BEFORE_SEND_HEADERS | | 2788 BlockingNetworkDelegate::ON_BEFORE_SEND_HEADERS | |
| (...skipping 295 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3076 EXPECT_EQ(0, r.status().error()); | 3084 EXPECT_EQ(0, r.status().error()); |
| 3077 EXPECT_EQ(200, r.GetResponseCode()); | 3085 EXPECT_EQ(200, r.GetResponseCode()); |
| 3078 EXPECT_TRUE(d.auth_required_called()); | 3086 EXPECT_TRUE(d.auth_required_called()); |
| 3079 EXPECT_EQ(1, network_delegate.created_requests()); | 3087 EXPECT_EQ(1, network_delegate.created_requests()); |
| 3080 EXPECT_EQ(0, network_delegate.destroyed_requests()); | 3088 EXPECT_EQ(0, network_delegate.destroyed_requests()); |
| 3081 } | 3089 } |
| 3082 EXPECT_EQ(1, network_delegate.destroyed_requests()); | 3090 EXPECT_EQ(1, network_delegate.destroyed_requests()); |
| 3083 } | 3091 } |
| 3084 | 3092 |
| 3085 TEST_F(URLRequestTestHTTP, | 3093 TEST_F(URLRequestTestHTTP, |
| 3086 NetworkDelegateOnAuthRequiredSyncNoAction_GetFullRequestHeaders) { | 3094 NetworkDelegateOnAuthRequiredSyncNoAction_GetFullRequestHeaders) { |
| 3087 ASSERT_TRUE(test_server_.Start()); | 3095 ASSERT_TRUE(test_server_.Start()); |
| 3088 | 3096 |
| 3089 TestDelegate d; | 3097 TestDelegate d; |
| 3090 BlockingNetworkDelegate network_delegate( | 3098 BlockingNetworkDelegate network_delegate( |
| 3091 BlockingNetworkDelegate::SYNCHRONOUS); | 3099 BlockingNetworkDelegate::SYNCHRONOUS); |
| 3092 | 3100 |
| 3093 TestURLRequestContext context(true); | 3101 TestURLRequestContext context(true); |
| 3094 context.set_network_delegate(&network_delegate); | 3102 context.set_network_delegate(&network_delegate); |
| 3095 context.Init(); | 3103 context.Init(); |
| 3096 | 3104 |
| (...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3149 EXPECT_FALSE(d.auth_required_called()); | 3157 EXPECT_FALSE(d.auth_required_called()); |
| 3150 EXPECT_EQ(1, network_delegate.created_requests()); | 3158 EXPECT_EQ(1, network_delegate.created_requests()); |
| 3151 EXPECT_EQ(0, network_delegate.destroyed_requests()); | 3159 EXPECT_EQ(0, network_delegate.destroyed_requests()); |
| 3152 } | 3160 } |
| 3153 EXPECT_EQ(1, network_delegate.destroyed_requests()); | 3161 EXPECT_EQ(1, network_delegate.destroyed_requests()); |
| 3154 } | 3162 } |
| 3155 | 3163 |
| 3156 // Same as above, but also tests that GetFullRequestHeaders returns the proper | 3164 // Same as above, but also tests that GetFullRequestHeaders returns the proper |
| 3157 // headers (for the first or second request) when called at the proper times. | 3165 // headers (for the first or second request) when called at the proper times. |
| 3158 TEST_F(URLRequestTestHTTP, | 3166 TEST_F(URLRequestTestHTTP, |
| 3159 NetworkDelegateOnAuthRequiredSyncSetAuth_GetFullRequestHeaders) { | 3167 NetworkDelegateOnAuthRequiredSyncSetAuth_GetFullRequestHeaders) { |
| 3160 ASSERT_TRUE(test_server_.Start()); | 3168 ASSERT_TRUE(test_server_.Start()); |
| 3161 | 3169 |
| 3162 TestDelegate d; | 3170 TestDelegate d; |
| 3163 BlockingNetworkDelegate network_delegate( | 3171 BlockingNetworkDelegate network_delegate( |
| 3164 BlockingNetworkDelegate::SYNCHRONOUS); | 3172 BlockingNetworkDelegate::SYNCHRONOUS); |
| 3165 network_delegate.set_block_on(BlockingNetworkDelegate::ON_AUTH_REQUIRED); | 3173 network_delegate.set_block_on(BlockingNetworkDelegate::ON_AUTH_REQUIRED); |
| 3166 network_delegate.set_auth_retval( | 3174 network_delegate.set_auth_retval( |
| 3167 NetworkDelegate::AUTH_REQUIRED_RESPONSE_SET_AUTH); | 3175 NetworkDelegate::AUTH_REQUIRED_RESPONSE_SET_AUTH); |
| 3168 | 3176 |
| 3169 network_delegate.set_auth_credentials(AuthCredentials(kUser, kSecret)); | 3177 network_delegate.set_auth_credentials(AuthCredentials(kUser, kSecret)); |
| (...skipping 483 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3653 TEST_F(URLRequestTestHTTP, GetZippedTest) { | 3661 TEST_F(URLRequestTestHTTP, GetZippedTest) { |
| 3654 ASSERT_TRUE(test_server_.Start()); | 3662 ASSERT_TRUE(test_server_.Start()); |
| 3655 | 3663 |
| 3656 // Parameter that specifies the Content-Length field in the response: | 3664 // Parameter that specifies the Content-Length field in the response: |
| 3657 // C - Compressed length. | 3665 // C - Compressed length. |
| 3658 // U - Uncompressed length. | 3666 // U - Uncompressed length. |
| 3659 // L - Large length (larger than both C & U). | 3667 // L - Large length (larger than both C & U). |
| 3660 // M - Medium length (between C & U). | 3668 // M - Medium length (between C & U). |
| 3661 // S - Small length (smaller than both C & U). | 3669 // S - Small length (smaller than both C & U). |
| 3662 const char test_parameters[] = "CULMS"; | 3670 const char test_parameters[] = "CULMS"; |
| 3663 const int num_tests = arraysize(test_parameters)- 1; // Skip NULL. | 3671 const int num_tests = arraysize(test_parameters) - 1; // Skip NULL. |
| 3664 // C & U should be OK. | 3672 // C & U should be OK. |
| 3665 // L & M are larger than the data sent, and show an error. | 3673 // L & M are larger than the data sent, and show an error. |
| 3666 // S has too little data, but we seem to accept it. | 3674 // S has too little data, but we seem to accept it. |
| 3667 const bool test_expect_success[num_tests] = | 3675 const bool test_expect_success[num_tests] = {true, true, false, false, true}; |
| 3668 { true, true, false, false, true }; | |
| 3669 | 3676 |
| 3670 for (int i = 0; i < num_tests ; i++) { | 3677 for (int i = 0; i < num_tests; i++) { |
| 3671 TestDelegate d; | 3678 TestDelegate d; |
| 3672 { | 3679 { |
| 3673 std::string test_file = | 3680 std::string test_file = base::StringPrintf( |
| 3674 base::StringPrintf("compressedfiles/BullRunSpeech.txt?%c", | 3681 "compressedfiles/BullRunSpeech.txt?%c", test_parameters[i]); |
| 3675 test_parameters[i]); | |
| 3676 | 3682 |
| 3677 TestNetworkDelegate network_delegate; // Must outlive URLRequest. | 3683 TestNetworkDelegate network_delegate; // Must outlive URLRequest. |
| 3678 TestURLRequestContext context(true); | 3684 TestURLRequestContext context(true); |
| 3679 context.set_network_delegate(&network_delegate); | 3685 context.set_network_delegate(&network_delegate); |
| 3680 context.Init(); | 3686 context.Init(); |
| 3681 | 3687 |
| 3682 URLRequest r( | 3688 URLRequest r( |
| 3683 test_server_.GetURL(test_file), DEFAULT_PRIORITY, &d, &context); | 3689 test_server_.GetURL(test_file), DEFAULT_PRIORITY, &d, &context); |
| 3684 r.Start(); | 3690 r.Start(); |
| 3685 EXPECT_TRUE(r.is_pending()); | 3691 EXPECT_TRUE(r.is_pending()); |
| (...skipping 14 matching lines...) Expand all Loading... |
| 3700 << " Parameter = \"" << test_file << "\""; | 3706 << " Parameter = \"" << test_file << "\""; |
| 3701 } | 3707 } |
| 3702 } | 3708 } |
| 3703 } | 3709 } |
| 3704 } | 3710 } |
| 3705 | 3711 |
| 3706 TEST_F(URLRequestTestHTTP, HTTPSToHTTPRedirectNoRefererTest) { | 3712 TEST_F(URLRequestTestHTTP, HTTPSToHTTPRedirectNoRefererTest) { |
| 3707 ASSERT_TRUE(test_server_.Start()); | 3713 ASSERT_TRUE(test_server_.Start()); |
| 3708 | 3714 |
| 3709 SpawnedTestServer https_test_server( | 3715 SpawnedTestServer https_test_server( |
| 3710 SpawnedTestServer::TYPE_HTTPS, SpawnedTestServer::kLocalhost, | 3716 SpawnedTestServer::TYPE_HTTPS, |
| 3717 SpawnedTestServer::kLocalhost, |
| 3711 base::FilePath(FILE_PATH_LITERAL("net/data/ssl"))); | 3718 base::FilePath(FILE_PATH_LITERAL("net/data/ssl"))); |
| 3712 ASSERT_TRUE(https_test_server.Start()); | 3719 ASSERT_TRUE(https_test_server.Start()); |
| 3713 | 3720 |
| 3714 // An https server is sent a request with an https referer, | 3721 // An https server is sent a request with an https referer, |
| 3715 // and responds with a redirect to an http url. The http | 3722 // and responds with a redirect to an http url. The http |
| 3716 // server should not be sent the referer. | 3723 // server should not be sent the referer. |
| 3717 GURL http_destination = test_server_.GetURL(std::string()); | 3724 GURL http_destination = test_server_.GetURL(std::string()); |
| 3718 TestDelegate d; | 3725 TestDelegate d; |
| 3719 URLRequest req( | 3726 URLRequest req( |
| 3720 https_test_server.GetURL("server-redirect?" + http_destination.spec()), | 3727 https_test_server.GetURL("server-redirect?" + http_destination.spec()), |
| (...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3768 EXPECT_LE(load_timing_info_before_redirect.receive_headers_end, | 3775 EXPECT_LE(load_timing_info_before_redirect.receive_headers_end, |
| 3769 load_timing_info.connect_timing.connect_start); | 3776 load_timing_info.connect_timing.connect_start); |
| 3770 } | 3777 } |
| 3771 | 3778 |
| 3772 TEST_F(URLRequestTestHTTP, MultipleRedirectTest) { | 3779 TEST_F(URLRequestTestHTTP, MultipleRedirectTest) { |
| 3773 ASSERT_TRUE(test_server_.Start()); | 3780 ASSERT_TRUE(test_server_.Start()); |
| 3774 | 3781 |
| 3775 GURL destination_url = test_server_.GetURL(std::string()); | 3782 GURL destination_url = test_server_.GetURL(std::string()); |
| 3776 GURL middle_redirect_url = | 3783 GURL middle_redirect_url = |
| 3777 test_server_.GetURL("server-redirect?" + destination_url.spec()); | 3784 test_server_.GetURL("server-redirect?" + destination_url.spec()); |
| 3778 GURL original_url = test_server_.GetURL( | 3785 GURL original_url = |
| 3779 "server-redirect?" + middle_redirect_url.spec()); | 3786 test_server_.GetURL("server-redirect?" + middle_redirect_url.spec()); |
| 3780 TestDelegate d; | 3787 TestDelegate d; |
| 3781 URLRequest req(original_url, DEFAULT_PRIORITY, &d, &default_context_); | 3788 URLRequest req(original_url, DEFAULT_PRIORITY, &d, &default_context_); |
| 3782 req.Start(); | 3789 req.Start(); |
| 3783 base::RunLoop().Run(); | 3790 base::RunLoop().Run(); |
| 3784 | 3791 |
| 3785 EXPECT_EQ(1, d.response_started_count()); | 3792 EXPECT_EQ(1, d.response_started_count()); |
| 3786 EXPECT_EQ(2, d.received_redirect_count()); | 3793 EXPECT_EQ(2, d.received_redirect_count()); |
| 3787 EXPECT_EQ(destination_url, req.url()); | 3794 EXPECT_EQ(destination_url, req.url()); |
| 3788 EXPECT_EQ(original_url, req.original_url()); | 3795 EXPECT_EQ(original_url, req.original_url()); |
| 3789 ASSERT_EQ(3U, req.url_chain().size()); | 3796 ASSERT_EQ(3U, req.url_chain().size()); |
| (...skipping 16 matching lines...) Expand all Loading... |
| 3806 typedef base::Callback<void()> Callback; | 3813 typedef base::Callback<void()> Callback; |
| 3807 | 3814 |
| 3808 // Each time delegate information is added to the URLRequest, the resulting | 3815 // Each time delegate information is added to the URLRequest, the resulting |
| 3809 // load state is checked. The expected load state after each request is | 3816 // load state is checked. The expected load state after each request is |
| 3810 // passed in as an argument. | 3817 // passed in as an argument. |
| 3811 static void Run(URLRequest* url_request, | 3818 static void Run(URLRequest* url_request, |
| 3812 LoadState expected_first_load_state, | 3819 LoadState expected_first_load_state, |
| 3813 LoadState expected_second_load_state, | 3820 LoadState expected_second_load_state, |
| 3814 LoadState expected_third_load_state, | 3821 LoadState expected_third_load_state, |
| 3815 const Callback& callback) { | 3822 const Callback& callback) { |
| 3816 AsyncDelegateLogger* logger = new AsyncDelegateLogger( | 3823 AsyncDelegateLogger* logger = |
| 3817 url_request, | 3824 new AsyncDelegateLogger(url_request, |
| 3818 expected_first_load_state, | 3825 expected_first_load_state, |
| 3819 expected_second_load_state, | 3826 expected_second_load_state, |
| 3820 expected_third_load_state, | 3827 expected_third_load_state, |
| 3821 callback); | 3828 callback); |
| 3822 logger->Start(); | 3829 logger->Start(); |
| 3823 } | 3830 } |
| 3824 | 3831 |
| 3825 // Checks that the log entries, starting with log_position, contain the | 3832 // Checks that the log entries, starting with log_position, contain the |
| 3826 // DELEGATE_INFO NetLog events that an AsyncDelegateLogger should have | 3833 // DELEGATE_INFO NetLog events that an AsyncDelegateLogger should have |
| 3827 // recorded. Returns the index of entry after the expected number of | 3834 // recorded. Returns the index of entry after the expected number of |
| 3828 // events this logged, or entries.size() if there aren't enough entries. | 3835 // events this logged, or entries.size() if there aren't enough entries. |
| 3829 static size_t CheckDelegateInfo( | 3836 static size_t CheckDelegateInfo( |
| 3830 const CapturingNetLog::CapturedEntryList& entries, size_t log_position) { | 3837 const CapturingNetLog::CapturedEntryList& entries, |
| 3838 size_t log_position) { |
| 3831 // There should be 4 DELEGATE_INFO events: Two begins and two ends. | 3839 // There should be 4 DELEGATE_INFO events: Two begins and two ends. |
| 3832 if (log_position + 3 >= entries.size()) { | 3840 if (log_position + 3 >= entries.size()) { |
| 3833 ADD_FAILURE() << "Not enough log entries"; | 3841 ADD_FAILURE() << "Not enough log entries"; |
| 3834 return entries.size(); | 3842 return entries.size(); |
| 3835 } | 3843 } |
| 3836 std::string delegate_info; | 3844 std::string delegate_info; |
| 3837 EXPECT_EQ(NetLog::TYPE_DELEGATE_INFO, entries[log_position].type); | 3845 EXPECT_EQ(NetLog::TYPE_DELEGATE_INFO, entries[log_position].type); |
| 3838 EXPECT_EQ(NetLog::PHASE_BEGIN, entries[log_position].phase); | 3846 EXPECT_EQ(NetLog::PHASE_BEGIN, entries[log_position].phase); |
| 3839 EXPECT_TRUE(entries[log_position].GetStringValue("delegate_info", | 3847 EXPECT_TRUE( |
| 3840 &delegate_info)); | 3848 entries[log_position].GetStringValue("delegate_info", &delegate_info)); |
| 3841 EXPECT_EQ(kFirstDelegateInfo, delegate_info); | 3849 EXPECT_EQ(kFirstDelegateInfo, delegate_info); |
| 3842 | 3850 |
| 3843 ++log_position; | 3851 ++log_position; |
| 3844 EXPECT_EQ(NetLog::TYPE_DELEGATE_INFO, entries[log_position].type); | 3852 EXPECT_EQ(NetLog::TYPE_DELEGATE_INFO, entries[log_position].type); |
| 3845 EXPECT_EQ(NetLog::PHASE_END, entries[log_position].phase); | 3853 EXPECT_EQ(NetLog::PHASE_END, entries[log_position].phase); |
| 3846 | 3854 |
| 3847 ++log_position; | 3855 ++log_position; |
| 3848 EXPECT_EQ(NetLog::TYPE_DELEGATE_INFO, entries[log_position].type); | 3856 EXPECT_EQ(NetLog::TYPE_DELEGATE_INFO, entries[log_position].type); |
| 3849 EXPECT_EQ(NetLog::PHASE_BEGIN, entries[log_position].phase); | 3857 EXPECT_EQ(NetLog::PHASE_BEGIN, entries[log_position].phase); |
| 3850 EXPECT_TRUE(entries[log_position].GetStringValue("delegate_info", | 3858 EXPECT_TRUE( |
| 3851 &delegate_info)); | 3859 entries[log_position].GetStringValue("delegate_info", &delegate_info)); |
| 3852 EXPECT_EQ(kSecondDelegateInfo, delegate_info); | 3860 EXPECT_EQ(kSecondDelegateInfo, delegate_info); |
| 3853 | 3861 |
| 3854 ++log_position; | 3862 ++log_position; |
| 3855 EXPECT_EQ(NetLog::TYPE_DELEGATE_INFO, entries[log_position].type); | 3863 EXPECT_EQ(NetLog::TYPE_DELEGATE_INFO, entries[log_position].type); |
| 3856 EXPECT_EQ(NetLog::PHASE_END, entries[log_position].phase); | 3864 EXPECT_EQ(NetLog::PHASE_END, entries[log_position].phase); |
| 3857 | 3865 |
| 3858 return log_position + 1; | 3866 return log_position + 1; |
| 3859 } | 3867 } |
| 3860 | 3868 |
| 3861 // Find delegate request begin and end messages for OnBeforeNetworkStart. | 3869 // Find delegate request begin and end messages for OnBeforeNetworkStart. |
| (...skipping 17 matching lines...) Expand all Loading... |
| 3879 | 3887 |
| 3880 AsyncDelegateLogger(URLRequest* url_request, | 3888 AsyncDelegateLogger(URLRequest* url_request, |
| 3881 LoadState expected_first_load_state, | 3889 LoadState expected_first_load_state, |
| 3882 LoadState expected_second_load_state, | 3890 LoadState expected_second_load_state, |
| 3883 LoadState expected_third_load_state, | 3891 LoadState expected_third_load_state, |
| 3884 const Callback& callback) | 3892 const Callback& callback) |
| 3885 : url_request_(url_request), | 3893 : url_request_(url_request), |
| 3886 expected_first_load_state_(expected_first_load_state), | 3894 expected_first_load_state_(expected_first_load_state), |
| 3887 expected_second_load_state_(expected_second_load_state), | 3895 expected_second_load_state_(expected_second_load_state), |
| 3888 expected_third_load_state_(expected_third_load_state), | 3896 expected_third_load_state_(expected_third_load_state), |
| 3889 callback_(callback) { | 3897 callback_(callback) {} |
| 3890 } | |
| 3891 | 3898 |
| 3892 ~AsyncDelegateLogger() {} | 3899 ~AsyncDelegateLogger() {} |
| 3893 | 3900 |
| 3894 void Start() { | 3901 void Start() { |
| 3895 url_request_->LogBlockedBy(kFirstDelegateInfo); | 3902 url_request_->LogBlockedBy(kFirstDelegateInfo); |
| 3896 LoadStateWithParam load_state = url_request_->GetLoadState(); | 3903 LoadStateWithParam load_state = url_request_->GetLoadState(); |
| 3897 EXPECT_EQ(expected_first_load_state_, load_state.state); | 3904 EXPECT_EQ(expected_first_load_state_, load_state.state); |
| 3898 EXPECT_NE(ASCIIToUTF16(kFirstDelegateInfo), load_state.param); | 3905 EXPECT_NE(ASCIIToUTF16(kFirstDelegateInfo), load_state.param); |
| 3899 base::MessageLoop::current()->PostTask( | 3906 base::MessageLoop::current()->PostTask( |
| 3900 FROM_HERE, | 3907 FROM_HERE, base::Bind(&AsyncDelegateLogger::LogSecondDelegate, this)); |
| 3901 base::Bind(&AsyncDelegateLogger::LogSecondDelegate, this)); | |
| 3902 } | 3908 } |
| 3903 | 3909 |
| 3904 void LogSecondDelegate() { | 3910 void LogSecondDelegate() { |
| 3905 url_request_->LogAndReportBlockedBy(kSecondDelegateInfo); | 3911 url_request_->LogAndReportBlockedBy(kSecondDelegateInfo); |
| 3906 LoadStateWithParam load_state = url_request_->GetLoadState(); | 3912 LoadStateWithParam load_state = url_request_->GetLoadState(); |
| 3907 EXPECT_EQ(expected_second_load_state_, load_state.state); | 3913 EXPECT_EQ(expected_second_load_state_, load_state.state); |
| 3908 if (expected_second_load_state_ == LOAD_STATE_WAITING_FOR_DELEGATE) { | 3914 if (expected_second_load_state_ == LOAD_STATE_WAITING_FOR_DELEGATE) { |
| 3909 EXPECT_EQ(ASCIIToUTF16(kSecondDelegateInfo), load_state.param); | 3915 EXPECT_EQ(ASCIIToUTF16(kSecondDelegateInfo), load_state.param); |
| 3910 } else { | 3916 } else { |
| 3911 EXPECT_NE(ASCIIToUTF16(kSecondDelegateInfo), load_state.param); | 3917 EXPECT_NE(ASCIIToUTF16(kSecondDelegateInfo), load_state.param); |
| 3912 } | 3918 } |
| 3913 base::MessageLoop::current()->PostTask( | 3919 base::MessageLoop::current()->PostTask( |
| 3914 FROM_HERE, | 3920 FROM_HERE, base::Bind(&AsyncDelegateLogger::LogComplete, this)); |
| 3915 base::Bind(&AsyncDelegateLogger::LogComplete, this)); | |
| 3916 } | 3921 } |
| 3917 | 3922 |
| 3918 void LogComplete() { | 3923 void LogComplete() { |
| 3919 url_request_->LogUnblocked(); | 3924 url_request_->LogUnblocked(); |
| 3920 LoadStateWithParam load_state = url_request_->GetLoadState(); | 3925 LoadStateWithParam load_state = url_request_->GetLoadState(); |
| 3921 EXPECT_EQ(expected_third_load_state_, load_state.state); | 3926 EXPECT_EQ(expected_third_load_state_, load_state.state); |
| 3922 if (expected_second_load_state_ == LOAD_STATE_WAITING_FOR_DELEGATE) | 3927 if (expected_second_load_state_ == LOAD_STATE_WAITING_FOR_DELEGATE) |
| 3923 EXPECT_EQ(base::string16(), load_state.param); | 3928 EXPECT_EQ(base::string16(), load_state.param); |
| 3924 callback_.Run(); | 3929 callback_.Run(); |
| 3925 } | 3930 } |
| (...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3974 URLRequest* request, | 3979 URLRequest* request, |
| 3975 const AuthChallengeInfo& auth_info, | 3980 const AuthChallengeInfo& auth_info, |
| 3976 const AuthCallback& callback, | 3981 const AuthCallback& callback, |
| 3977 AuthCredentials* credentials) OVERRIDE { | 3982 AuthCredentials* credentials) OVERRIDE { |
| 3978 AsyncDelegateLogger::Run( | 3983 AsyncDelegateLogger::Run( |
| 3979 request, | 3984 request, |
| 3980 LOAD_STATE_WAITING_FOR_DELEGATE, | 3985 LOAD_STATE_WAITING_FOR_DELEGATE, |
| 3981 LOAD_STATE_WAITING_FOR_DELEGATE, | 3986 LOAD_STATE_WAITING_FOR_DELEGATE, |
| 3982 LOAD_STATE_WAITING_FOR_DELEGATE, | 3987 LOAD_STATE_WAITING_FOR_DELEGATE, |
| 3983 base::Bind(&AsyncLoggingNetworkDelegate::SetAuthAndResume, | 3988 base::Bind(&AsyncLoggingNetworkDelegate::SetAuthAndResume, |
| 3984 callback, credentials)); | 3989 callback, |
| 3990 credentials)); |
| 3985 return AUTH_REQUIRED_RESPONSE_IO_PENDING; | 3991 return AUTH_REQUIRED_RESPONSE_IO_PENDING; |
| 3986 } | 3992 } |
| 3987 | 3993 |
| 3988 private: | 3994 private: |
| 3989 static int RunCallbackAsynchronously( | 3995 static int RunCallbackAsynchronously(URLRequest* request, |
| 3990 URLRequest* request, | 3996 const CompletionCallback& callback) { |
| 3991 const CompletionCallback& callback) { | 3997 AsyncDelegateLogger::Run(request, |
| 3992 AsyncDelegateLogger::Run( | 3998 LOAD_STATE_WAITING_FOR_DELEGATE, |
| 3993 request, | 3999 LOAD_STATE_WAITING_FOR_DELEGATE, |
| 3994 LOAD_STATE_WAITING_FOR_DELEGATE, | 4000 LOAD_STATE_WAITING_FOR_DELEGATE, |
| 3995 LOAD_STATE_WAITING_FOR_DELEGATE, | 4001 base::Bind(callback, OK)); |
| 3996 LOAD_STATE_WAITING_FOR_DELEGATE, | |
| 3997 base::Bind(callback, OK)); | |
| 3998 return ERR_IO_PENDING; | 4002 return ERR_IO_PENDING; |
| 3999 } | 4003 } |
| 4000 | 4004 |
| 4001 static void SetAuthAndResume(const AuthCallback& callback, | 4005 static void SetAuthAndResume(const AuthCallback& callback, |
| 4002 AuthCredentials* credentials) { | 4006 AuthCredentials* credentials) { |
| 4003 *credentials = AuthCredentials(kUser, kSecret); | 4007 *credentials = AuthCredentials(kUser, kSecret); |
| 4004 callback.Run(NetworkDelegate::AUTH_REQUIRED_RESPONSE_SET_AUTH); | 4008 callback.Run(NetworkDelegate::AUTH_REQUIRED_RESPONSE_SET_AUTH); |
| 4005 } | 4009 } |
| 4006 | 4010 |
| 4007 DISALLOW_COPY_AND_ASSIGN(AsyncLoggingNetworkDelegate); | 4011 DISALLOW_COPY_AND_ASSIGN(AsyncLoggingNetworkDelegate); |
| (...skipping 30 matching lines...) Expand all Loading... |
| 4038 const GURL& new_url, | 4042 const GURL& new_url, |
| 4039 bool* defer_redirect) OVERRIDE { | 4043 bool* defer_redirect) OVERRIDE { |
| 4040 *defer_redirect = true; | 4044 *defer_redirect = true; |
| 4041 AsyncDelegateLogger::Run( | 4045 AsyncDelegateLogger::Run( |
| 4042 request, | 4046 request, |
| 4043 LOAD_STATE_WAITING_FOR_DELEGATE, | 4047 LOAD_STATE_WAITING_FOR_DELEGATE, |
| 4044 LOAD_STATE_WAITING_FOR_DELEGATE, | 4048 LOAD_STATE_WAITING_FOR_DELEGATE, |
| 4045 LOAD_STATE_WAITING_FOR_DELEGATE, | 4049 LOAD_STATE_WAITING_FOR_DELEGATE, |
| 4046 base::Bind( | 4050 base::Bind( |
| 4047 &AsyncLoggingUrlRequestDelegate::OnReceivedRedirectLoggingComplete, | 4051 &AsyncLoggingUrlRequestDelegate::OnReceivedRedirectLoggingComplete, |
| 4048 base::Unretained(this), request, new_url)); | 4052 base::Unretained(this), |
| 4053 request, |
| 4054 new_url)); |
| 4049 } | 4055 } |
| 4050 | 4056 |
| 4051 virtual void OnResponseStarted(URLRequest* request) OVERRIDE { | 4057 virtual void OnResponseStarted(URLRequest* request) OVERRIDE { |
| 4052 AsyncDelegateLogger::Run( | 4058 AsyncDelegateLogger::Run( |
| 4053 request, | 4059 request, |
| 4054 LOAD_STATE_WAITING_FOR_DELEGATE, | 4060 LOAD_STATE_WAITING_FOR_DELEGATE, |
| 4055 LOAD_STATE_WAITING_FOR_DELEGATE, | 4061 LOAD_STATE_WAITING_FOR_DELEGATE, |
| 4056 LOAD_STATE_WAITING_FOR_DELEGATE, | 4062 LOAD_STATE_WAITING_FOR_DELEGATE, |
| 4057 base::Bind( | 4063 base::Bind( |
| 4058 &AsyncLoggingUrlRequestDelegate::OnResponseStartedLoggingComplete, | 4064 &AsyncLoggingUrlRequestDelegate::OnResponseStartedLoggingComplete, |
| 4059 base::Unretained(this), request)); | 4065 base::Unretained(this), |
| 4066 request)); |
| 4060 } | 4067 } |
| 4061 | 4068 |
| 4062 virtual void OnReadCompleted(URLRequest* request, | 4069 virtual void OnReadCompleted(URLRequest* request, int bytes_read) OVERRIDE { |
| 4063 int bytes_read) OVERRIDE { | |
| 4064 AsyncDelegateLogger::Run( | 4070 AsyncDelegateLogger::Run( |
| 4065 request, | 4071 request, |
| 4066 LOAD_STATE_IDLE, | 4072 LOAD_STATE_IDLE, |
| 4067 LOAD_STATE_IDLE, | 4073 LOAD_STATE_IDLE, |
| 4068 LOAD_STATE_IDLE, | 4074 LOAD_STATE_IDLE, |
| 4069 base::Bind( | 4075 base::Bind( |
| 4070 &AsyncLoggingUrlRequestDelegate::AfterReadCompletedLoggingComplete, | 4076 &AsyncLoggingUrlRequestDelegate::AfterReadCompletedLoggingComplete, |
| 4071 base::Unretained(this), request, bytes_read)); | 4077 base::Unretained(this), |
| 4078 request, |
| 4079 bytes_read)); |
| 4072 } | 4080 } |
| 4073 | 4081 |
| 4074 private: | 4082 private: |
| 4075 void OnReceivedRedirectLoggingComplete(URLRequest* request, | 4083 void OnReceivedRedirectLoggingComplete(URLRequest* request, |
| 4076 const GURL& new_url) { | 4084 const GURL& new_url) { |
| 4077 bool defer_redirect = false; | 4085 bool defer_redirect = false; |
| 4078 TestDelegate::OnReceivedRedirect(request, new_url, &defer_redirect); | 4086 TestDelegate::OnReceivedRedirect(request, new_url, &defer_redirect); |
| 4079 // FollowDeferredRedirect should not be called after cancellation. | 4087 // FollowDeferredRedirect should not be called after cancellation. |
| 4080 if (cancel_stage_ == CANCEL_ON_RECEIVED_REDIRECT) | 4088 if (cancel_stage_ == CANCEL_ON_RECEIVED_REDIRECT) |
| 4081 return; | 4089 return; |
| (...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 4126 | 4134 |
| 4127 base::RunLoop().Run(); | 4135 base::RunLoop().Run(); |
| 4128 | 4136 |
| 4129 EXPECT_EQ(200, r.GetResponseCode()); | 4137 EXPECT_EQ(200, r.GetResponseCode()); |
| 4130 EXPECT_EQ(URLRequestStatus::SUCCESS, r.status().status()); | 4138 EXPECT_EQ(URLRequestStatus::SUCCESS, r.status().status()); |
| 4131 } | 4139 } |
| 4132 | 4140 |
| 4133 CapturingNetLog::CapturedEntryList entries; | 4141 CapturingNetLog::CapturedEntryList entries; |
| 4134 net_log_.GetEntries(&entries); | 4142 net_log_.GetEntries(&entries); |
| 4135 size_t log_position = ExpectLogContainsSomewhereAfter( | 4143 size_t log_position = ExpectLogContainsSomewhereAfter( |
| 4136 entries, | 4144 entries, 0, NetLog::TYPE_DELEGATE_INFO, NetLog::PHASE_BEGIN); |
| 4137 0, | |
| 4138 NetLog::TYPE_DELEGATE_INFO, | |
| 4139 NetLog::PHASE_BEGIN); | |
| 4140 | 4145 |
| 4141 log_position = AsyncDelegateLogger::CheckDelegateInfo(entries, log_position); | 4146 log_position = AsyncDelegateLogger::CheckDelegateInfo(entries, log_position); |
| 4142 | 4147 |
| 4143 // Nothing else should add any delegate info to the request. | 4148 // Nothing else should add any delegate info to the request. |
| 4144 EXPECT_FALSE(LogContainsEntryWithTypeAfter( | 4149 EXPECT_FALSE(LogContainsEntryWithTypeAfter( |
| 4145 entries, log_position + 1, NetLog::TYPE_DELEGATE_INFO)); | 4150 entries, log_position + 1, NetLog::TYPE_DELEGATE_INFO)); |
| 4146 } | 4151 } |
| 4147 | 4152 |
| 4148 // Tests handling of delegate info from a network delegate. | 4153 // Tests handling of delegate info from a network delegate. |
| 4149 TEST_F(URLRequestTestHTTP, NetworkDelegateInfo) { | 4154 TEST_F(URLRequestTestHTTP, NetworkDelegateInfo) { |
| (...skipping 22 matching lines...) Expand all Loading... |
| 4172 EXPECT_EQ(URLRequestStatus::SUCCESS, r.status().status()); | 4177 EXPECT_EQ(URLRequestStatus::SUCCESS, r.status().status()); |
| 4173 EXPECT_EQ(1, network_delegate.created_requests()); | 4178 EXPECT_EQ(1, network_delegate.created_requests()); |
| 4174 EXPECT_EQ(0, network_delegate.destroyed_requests()); | 4179 EXPECT_EQ(0, network_delegate.destroyed_requests()); |
| 4175 } | 4180 } |
| 4176 EXPECT_EQ(1, network_delegate.destroyed_requests()); | 4181 EXPECT_EQ(1, network_delegate.destroyed_requests()); |
| 4177 | 4182 |
| 4178 size_t log_position = 0; | 4183 size_t log_position = 0; |
| 4179 CapturingNetLog::CapturedEntryList entries; | 4184 CapturingNetLog::CapturedEntryList entries; |
| 4180 net_log_.GetEntries(&entries); | 4185 net_log_.GetEntries(&entries); |
| 4181 for (size_t i = 0; i < 3; ++i) { | 4186 for (size_t i = 0; i < 3; ++i) { |
| 4182 log_position = ExpectLogContainsSomewhereAfter( | 4187 log_position = |
| 4183 entries, | 4188 ExpectLogContainsSomewhereAfter(entries, |
| 4184 log_position + 1, | 4189 log_position + 1, |
| 4185 NetLog::TYPE_URL_REQUEST_DELEGATE, | 4190 NetLog::TYPE_URL_REQUEST_DELEGATE, |
| 4186 NetLog::PHASE_BEGIN); | 4191 NetLog::PHASE_BEGIN); |
| 4187 | 4192 |
| 4188 log_position = AsyncDelegateLogger::CheckDelegateInfo(entries, | 4193 log_position = |
| 4189 log_position + 1); | 4194 AsyncDelegateLogger::CheckDelegateInfo(entries, log_position + 1); |
| 4190 | 4195 |
| 4191 ASSERT_LT(log_position, entries.size()); | 4196 ASSERT_LT(log_position, entries.size()); |
| 4192 EXPECT_EQ(NetLog::TYPE_URL_REQUEST_DELEGATE, entries[log_position].type); | 4197 EXPECT_EQ(NetLog::TYPE_URL_REQUEST_DELEGATE, entries[log_position].type); |
| 4193 EXPECT_EQ(NetLog::PHASE_END, entries[log_position].phase); | 4198 EXPECT_EQ(NetLog::PHASE_END, entries[log_position].phase); |
| 4194 | 4199 |
| 4195 if (i == 1) { | 4200 if (i == 1) { |
| 4196 log_position = AsyncDelegateLogger::ExpectBeforeNetworkEvents( | 4201 log_position = AsyncDelegateLogger::ExpectBeforeNetworkEvents( |
| 4197 entries, log_position + 1); | 4202 entries, log_position + 1); |
| 4198 } | 4203 } |
| 4199 } | 4204 } |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 4232 EXPECT_EQ(0, network_delegate.destroyed_requests()); | 4237 EXPECT_EQ(0, network_delegate.destroyed_requests()); |
| 4233 } | 4238 } |
| 4234 EXPECT_EQ(1, network_delegate.destroyed_requests()); | 4239 EXPECT_EQ(1, network_delegate.destroyed_requests()); |
| 4235 | 4240 |
| 4236 size_t log_position = 0; | 4241 size_t log_position = 0; |
| 4237 CapturingNetLog::CapturedEntryList entries; | 4242 CapturingNetLog::CapturedEntryList entries; |
| 4238 net_log_.GetEntries(&entries); | 4243 net_log_.GetEntries(&entries); |
| 4239 // The NetworkDelegate logged information in OnBeforeURLRequest, | 4244 // The NetworkDelegate logged information in OnBeforeURLRequest, |
| 4240 // OnBeforeSendHeaders, and OnHeadersReceived. | 4245 // OnBeforeSendHeaders, and OnHeadersReceived. |
| 4241 for (size_t i = 0; i < 3; ++i) { | 4246 for (size_t i = 0; i < 3; ++i) { |
| 4242 log_position = ExpectLogContainsSomewhereAfter( | 4247 log_position = |
| 4243 entries, | 4248 ExpectLogContainsSomewhereAfter(entries, |
| 4244 log_position + 1, | 4249 log_position + 1, |
| 4245 NetLog::TYPE_URL_REQUEST_DELEGATE, | 4250 NetLog::TYPE_URL_REQUEST_DELEGATE, |
| 4246 NetLog::PHASE_BEGIN); | 4251 NetLog::PHASE_BEGIN); |
| 4247 | 4252 |
| 4248 log_position = AsyncDelegateLogger::CheckDelegateInfo(entries, | 4253 log_position = |
| 4249 log_position + 1); | 4254 AsyncDelegateLogger::CheckDelegateInfo(entries, log_position + 1); |
| 4250 | 4255 |
| 4251 ASSERT_LT(log_position, entries.size()); | 4256 ASSERT_LT(log_position, entries.size()); |
| 4252 EXPECT_EQ(NetLog::TYPE_URL_REQUEST_DELEGATE, entries[log_position].type); | 4257 EXPECT_EQ(NetLog::TYPE_URL_REQUEST_DELEGATE, entries[log_position].type); |
| 4253 EXPECT_EQ(NetLog::PHASE_END, entries[log_position].phase); | 4258 EXPECT_EQ(NetLog::PHASE_END, entries[log_position].phase); |
| 4254 | 4259 |
| 4255 if (i == 1) { | 4260 if (i == 1) { |
| 4256 log_position = AsyncDelegateLogger::ExpectBeforeNetworkEvents( | 4261 log_position = AsyncDelegateLogger::ExpectBeforeNetworkEvents( |
| 4257 entries, log_position + 1); | 4262 entries, log_position + 1); |
| 4258 } | 4263 } |
| 4259 } | 4264 } |
| 4260 | 4265 |
| 4261 // The URLRequest::Delegate then gets informed about the redirect. | 4266 // The URLRequest::Delegate then gets informed about the redirect. |
| 4262 log_position = ExpectLogContainsSomewhereAfter( | 4267 log_position = |
| 4263 entries, | 4268 ExpectLogContainsSomewhereAfter(entries, |
| 4264 log_position + 1, | 4269 log_position + 1, |
| 4265 NetLog::TYPE_URL_REQUEST_DELEGATE, | 4270 NetLog::TYPE_URL_REQUEST_DELEGATE, |
| 4266 NetLog::PHASE_BEGIN); | 4271 NetLog::PHASE_BEGIN); |
| 4267 | 4272 |
| 4268 // The NetworkDelegate logged information in the same three events as before. | 4273 // The NetworkDelegate logged information in the same three events as before. |
| 4269 for (size_t i = 0; i < 3; ++i) { | 4274 for (size_t i = 0; i < 3; ++i) { |
| 4270 log_position = ExpectLogContainsSomewhereAfter( | 4275 log_position = |
| 4271 entries, | 4276 ExpectLogContainsSomewhereAfter(entries, |
| 4272 log_position + 1, | 4277 log_position + 1, |
| 4273 NetLog::TYPE_URL_REQUEST_DELEGATE, | 4278 NetLog::TYPE_URL_REQUEST_DELEGATE, |
| 4274 NetLog::PHASE_BEGIN); | 4279 NetLog::PHASE_BEGIN); |
| 4275 | 4280 |
| 4276 log_position = AsyncDelegateLogger::CheckDelegateInfo(entries, | 4281 log_position = |
| 4277 log_position + 1); | 4282 AsyncDelegateLogger::CheckDelegateInfo(entries, log_position + 1); |
| 4278 | 4283 |
| 4279 ASSERT_LT(log_position, entries.size()); | 4284 ASSERT_LT(log_position, entries.size()); |
| 4280 EXPECT_EQ(NetLog::TYPE_URL_REQUEST_DELEGATE, entries[log_position].type); | 4285 EXPECT_EQ(NetLog::TYPE_URL_REQUEST_DELEGATE, entries[log_position].type); |
| 4281 EXPECT_EQ(NetLog::PHASE_END, entries[log_position].phase); | 4286 EXPECT_EQ(NetLog::PHASE_END, entries[log_position].phase); |
| 4282 } | 4287 } |
| 4283 | 4288 |
| 4284 EXPECT_FALSE(LogContainsEntryWithTypeAfter( | 4289 EXPECT_FALSE(LogContainsEntryWithTypeAfter( |
| 4285 entries, log_position + 1, NetLog::TYPE_DELEGATE_INFO)); | 4290 entries, log_position + 1, NetLog::TYPE_DELEGATE_INFO)); |
| 4286 } | 4291 } |
| 4287 | 4292 |
| (...skipping 28 matching lines...) Expand all Loading... |
| 4316 } | 4321 } |
| 4317 EXPECT_EQ(1, network_delegate.destroyed_requests()); | 4322 EXPECT_EQ(1, network_delegate.destroyed_requests()); |
| 4318 | 4323 |
| 4319 size_t log_position = 0; | 4324 size_t log_position = 0; |
| 4320 CapturingNetLog::CapturedEntryList entries; | 4325 CapturingNetLog::CapturedEntryList entries; |
| 4321 net_log_.GetEntries(&entries); | 4326 net_log_.GetEntries(&entries); |
| 4322 // The NetworkDelegate should have logged information in OnBeforeURLRequest, | 4327 // The NetworkDelegate should have logged information in OnBeforeURLRequest, |
| 4323 // OnBeforeSendHeaders, OnHeadersReceived, OnAuthRequired, and then again in | 4328 // OnBeforeSendHeaders, OnHeadersReceived, OnAuthRequired, and then again in |
| 4324 // OnBeforeURLRequest and OnBeforeSendHeaders. | 4329 // OnBeforeURLRequest and OnBeforeSendHeaders. |
| 4325 for (size_t i = 0; i < 6; ++i) { | 4330 for (size_t i = 0; i < 6; ++i) { |
| 4326 log_position = ExpectLogContainsSomewhereAfter( | 4331 log_position = |
| 4327 entries, | 4332 ExpectLogContainsSomewhereAfter(entries, |
| 4328 log_position + 1, | 4333 log_position + 1, |
| 4329 NetLog::TYPE_URL_REQUEST_DELEGATE, | 4334 NetLog::TYPE_URL_REQUEST_DELEGATE, |
| 4330 NetLog::PHASE_BEGIN); | 4335 NetLog::PHASE_BEGIN); |
| 4331 | 4336 |
| 4332 log_position = AsyncDelegateLogger::CheckDelegateInfo(entries, | 4337 log_position = |
| 4333 log_position + 1); | 4338 AsyncDelegateLogger::CheckDelegateInfo(entries, log_position + 1); |
| 4334 | 4339 |
| 4335 ASSERT_LT(log_position, entries.size()); | 4340 ASSERT_LT(log_position, entries.size()); |
| 4336 EXPECT_EQ(NetLog::TYPE_URL_REQUEST_DELEGATE, entries[log_position].type); | 4341 EXPECT_EQ(NetLog::TYPE_URL_REQUEST_DELEGATE, entries[log_position].type); |
| 4337 EXPECT_EQ(NetLog::PHASE_END, entries[log_position].phase); | 4342 EXPECT_EQ(NetLog::PHASE_END, entries[log_position].phase); |
| 4338 | 4343 |
| 4339 if (i == 1) { | 4344 if (i == 1) { |
| 4340 log_position = AsyncDelegateLogger::ExpectBeforeNetworkEvents( | 4345 log_position = AsyncDelegateLogger::ExpectBeforeNetworkEvents( |
| 4341 entries, log_position + 1); | 4346 entries, log_position + 1); |
| 4342 } | 4347 } |
| 4343 } | 4348 } |
| (...skipping 29 matching lines...) Expand all Loading... |
| 4373 | 4378 |
| 4374 EXPECT_EQ(200, r.GetResponseCode()); | 4379 EXPECT_EQ(200, r.GetResponseCode()); |
| 4375 EXPECT_EQ(URLRequestStatus::SUCCESS, r.status().status()); | 4380 EXPECT_EQ(URLRequestStatus::SUCCESS, r.status().status()); |
| 4376 } | 4381 } |
| 4377 | 4382 |
| 4378 CapturingNetLog::CapturedEntryList entries; | 4383 CapturingNetLog::CapturedEntryList entries; |
| 4379 net_log_.GetEntries(&entries); | 4384 net_log_.GetEntries(&entries); |
| 4380 | 4385 |
| 4381 size_t log_position = 0; | 4386 size_t log_position = 0; |
| 4382 | 4387 |
| 4383 log_position = AsyncDelegateLogger::ExpectBeforeNetworkEvents( | 4388 log_position = |
| 4384 entries, log_position); | 4389 AsyncDelegateLogger::ExpectBeforeNetworkEvents(entries, log_position); |
| 4385 | 4390 |
| 4386 // The delegate info should only have been logged on header complete. Other | 4391 // The delegate info should only have been logged on header complete. Other |
| 4387 // times it should silently be ignored. | 4392 // times it should silently be ignored. |
| 4388 log_position = | 4393 log_position = |
| 4389 ExpectLogContainsSomewhereAfter(entries, | 4394 ExpectLogContainsSomewhereAfter(entries, |
| 4390 log_position + 1, | 4395 log_position + 1, |
| 4391 NetLog::TYPE_URL_REQUEST_DELEGATE, | 4396 NetLog::TYPE_URL_REQUEST_DELEGATE, |
| 4392 NetLog::PHASE_BEGIN); | 4397 NetLog::PHASE_BEGIN); |
| 4393 | 4398 |
| 4394 log_position = AsyncDelegateLogger::CheckDelegateInfo(entries, | 4399 log_position = |
| 4395 log_position + 1); | 4400 AsyncDelegateLogger::CheckDelegateInfo(entries, log_position + 1); |
| 4396 | 4401 |
| 4397 ASSERT_LT(log_position, entries.size()); | 4402 ASSERT_LT(log_position, entries.size()); |
| 4398 EXPECT_EQ(NetLog::TYPE_URL_REQUEST_DELEGATE, entries[log_position].type); | 4403 EXPECT_EQ(NetLog::TYPE_URL_REQUEST_DELEGATE, entries[log_position].type); |
| 4399 EXPECT_EQ(NetLog::PHASE_END, entries[log_position].phase); | 4404 EXPECT_EQ(NetLog::PHASE_END, entries[log_position].phase); |
| 4400 | 4405 |
| 4401 EXPECT_FALSE(LogContainsEntryWithTypeAfter( | 4406 EXPECT_FALSE(LogContainsEntryWithTypeAfter( |
| 4402 entries, log_position + 1, NetLog::TYPE_DELEGATE_INFO)); | 4407 entries, log_position + 1, NetLog::TYPE_DELEGATE_INFO)); |
| 4403 EXPECT_FALSE(LogContainsEntryWithTypeAfter( | 4408 EXPECT_FALSE(LogContainsEntryWithTypeAfter( |
| 4404 entries, log_position + 1, NetLog::TYPE_URL_REQUEST_DELEGATE)); | 4409 entries, log_position + 1, NetLog::TYPE_URL_REQUEST_DELEGATE)); |
| 4405 } | 4410 } |
| (...skipping 25 matching lines...) Expand all Loading... |
| 4431 | 4436 |
| 4432 CapturingNetLog::CapturedEntryList entries; | 4437 CapturingNetLog::CapturedEntryList entries; |
| 4433 net_log_.GetEntries(&entries); | 4438 net_log_.GetEntries(&entries); |
| 4434 | 4439 |
| 4435 // Delegate info should only have been logged in OnReceivedRedirect and | 4440 // Delegate info should only have been logged in OnReceivedRedirect and |
| 4436 // OnResponseStarted. | 4441 // OnResponseStarted. |
| 4437 size_t log_position = 0; | 4442 size_t log_position = 0; |
| 4438 for (int i = 0; i < 2; ++i) { | 4443 for (int i = 0; i < 2; ++i) { |
| 4439 if (i == 0) { | 4444 if (i == 0) { |
| 4440 log_position = AsyncDelegateLogger::ExpectBeforeNetworkEvents( | 4445 log_position = AsyncDelegateLogger::ExpectBeforeNetworkEvents( |
| 4441 entries, log_position) + 1; | 4446 entries, log_position) + |
| 4447 1; |
| 4442 } | 4448 } |
| 4443 | 4449 |
| 4444 log_position = ExpectLogContainsSomewhereAfter( | 4450 log_position = |
| 4445 entries, | 4451 ExpectLogContainsSomewhereAfter(entries, |
| 4446 log_position, | 4452 log_position, |
| 4447 NetLog::TYPE_URL_REQUEST_DELEGATE, | 4453 NetLog::TYPE_URL_REQUEST_DELEGATE, |
| 4448 NetLog::PHASE_BEGIN); | 4454 NetLog::PHASE_BEGIN); |
| 4449 | 4455 |
| 4450 log_position = AsyncDelegateLogger::CheckDelegateInfo(entries, | 4456 log_position = |
| 4451 log_position + 1); | 4457 AsyncDelegateLogger::CheckDelegateInfo(entries, log_position + 1); |
| 4452 | 4458 |
| 4453 ASSERT_LT(log_position, entries.size()); | 4459 ASSERT_LT(log_position, entries.size()); |
| 4454 EXPECT_EQ(NetLog::TYPE_URL_REQUEST_DELEGATE, entries[log_position].type); | 4460 EXPECT_EQ(NetLog::TYPE_URL_REQUEST_DELEGATE, entries[log_position].type); |
| 4455 EXPECT_EQ(NetLog::PHASE_END, entries[log_position].phase); | 4461 EXPECT_EQ(NetLog::PHASE_END, entries[log_position].phase); |
| 4456 } | 4462 } |
| 4457 | 4463 |
| 4458 EXPECT_FALSE(LogContainsEntryWithTypeAfter( | 4464 EXPECT_FALSE(LogContainsEntryWithTypeAfter( |
| 4459 entries, log_position + 1, NetLog::TYPE_DELEGATE_INFO)); | 4465 entries, log_position + 1, NetLog::TYPE_DELEGATE_INFO)); |
| 4460 EXPECT_FALSE(LogContainsEntryWithTypeAfter( | 4466 EXPECT_FALSE(LogContainsEntryWithTypeAfter( |
| 4461 entries, log_position + 1, NetLog::TYPE_URL_REQUEST_DELEGATE)); | 4467 entries, log_position + 1, NetLog::TYPE_URL_REQUEST_DELEGATE)); |
| 4462 } | 4468 } |
| 4463 | 4469 |
| 4464 // Tests handling of delegate info from a URLRequest::Delegate in the case of | 4470 // Tests handling of delegate info from a URLRequest::Delegate in the case of |
| 4465 // an HTTP redirect, with cancellation at various points. | 4471 // an HTTP redirect, with cancellation at various points. |
| 4466 TEST_F(URLRequestTestHTTP, URLRequestDelegateOnRedirectCancelled) { | 4472 TEST_F(URLRequestTestHTTP, URLRequestDelegateOnRedirectCancelled) { |
| 4467 ASSERT_TRUE(test_server_.Start()); | 4473 ASSERT_TRUE(test_server_.Start()); |
| 4468 | 4474 |
| 4469 const AsyncLoggingUrlRequestDelegate::CancelStage kCancelStages[] = { | 4475 const AsyncLoggingUrlRequestDelegate::CancelStage kCancelStages[] = { |
| 4470 AsyncLoggingUrlRequestDelegate::CANCEL_ON_RECEIVED_REDIRECT, | 4476 AsyncLoggingUrlRequestDelegate::CANCEL_ON_RECEIVED_REDIRECT, |
| 4471 AsyncLoggingUrlRequestDelegate::CANCEL_ON_RESPONSE_STARTED, | 4477 AsyncLoggingUrlRequestDelegate::CANCEL_ON_RESPONSE_STARTED, |
| 4472 AsyncLoggingUrlRequestDelegate::CANCEL_ON_READ_COMPLETED, | 4478 AsyncLoggingUrlRequestDelegate::CANCEL_ON_READ_COMPLETED, |
| 4473 }; | 4479 }; |
| 4474 | 4480 |
| 4475 for (size_t test_case = 0; test_case < arraysize(kCancelStages); | 4481 for (size_t test_case = 0; test_case < arraysize(kCancelStages); |
| 4476 ++test_case) { | 4482 ++test_case) { |
| 4477 AsyncLoggingUrlRequestDelegate request_delegate(kCancelStages[test_case]); | 4483 AsyncLoggingUrlRequestDelegate request_delegate(kCancelStages[test_case]); |
| 4478 TestURLRequestContext context(true); | 4484 TestURLRequestContext context(true); |
| 4479 CapturingNetLog net_log; | 4485 CapturingNetLog net_log; |
| 4480 context.set_network_delegate(NULL); | 4486 context.set_network_delegate(NULL); |
| 4481 context.set_net_log(&net_log); | 4487 context.set_net_log(&net_log); |
| 4482 context.Init(); | 4488 context.Init(); |
| (...skipping 13 matching lines...) Expand all Loading... |
| 4496 net_log.GetEntries(&entries); | 4502 net_log.GetEntries(&entries); |
| 4497 | 4503 |
| 4498 // Delegate info is always logged in both OnReceivedRedirect and | 4504 // Delegate info is always logged in both OnReceivedRedirect and |
| 4499 // OnResponseStarted. In the CANCEL_ON_RECEIVED_REDIRECT, the | 4505 // OnResponseStarted. In the CANCEL_ON_RECEIVED_REDIRECT, the |
| 4500 // OnResponseStarted delegate call is after cancellation, but logging is | 4506 // OnResponseStarted delegate call is after cancellation, but logging is |
| 4501 // still currently supported in that call. | 4507 // still currently supported in that call. |
| 4502 size_t log_position = 0; | 4508 size_t log_position = 0; |
| 4503 for (int i = 0; i < 2; ++i) { | 4509 for (int i = 0; i < 2; ++i) { |
| 4504 if (i == 0) { | 4510 if (i == 0) { |
| 4505 log_position = AsyncDelegateLogger::ExpectBeforeNetworkEvents( | 4511 log_position = AsyncDelegateLogger::ExpectBeforeNetworkEvents( |
| 4506 entries, log_position) + 1; | 4512 entries, log_position) + |
| 4513 1; |
| 4507 } | 4514 } |
| 4508 | 4515 |
| 4509 log_position = ExpectLogContainsSomewhereAfter( | 4516 log_position = |
| 4510 entries, | 4517 ExpectLogContainsSomewhereAfter(entries, |
| 4511 log_position, | 4518 log_position, |
| 4512 NetLog::TYPE_URL_REQUEST_DELEGATE, | 4519 NetLog::TYPE_URL_REQUEST_DELEGATE, |
| 4513 NetLog::PHASE_BEGIN); | 4520 NetLog::PHASE_BEGIN); |
| 4514 | 4521 |
| 4515 log_position = AsyncDelegateLogger::CheckDelegateInfo(entries, | 4522 log_position = |
| 4516 log_position + 1); | 4523 AsyncDelegateLogger::CheckDelegateInfo(entries, log_position + 1); |
| 4517 | 4524 |
| 4518 ASSERT_LT(log_position, entries.size()); | 4525 ASSERT_LT(log_position, entries.size()); |
| 4519 EXPECT_EQ(NetLog::TYPE_URL_REQUEST_DELEGATE, entries[log_position].type); | 4526 EXPECT_EQ(NetLog::TYPE_URL_REQUEST_DELEGATE, entries[log_position].type); |
| 4520 EXPECT_EQ(NetLog::PHASE_END, entries[log_position].phase); | 4527 EXPECT_EQ(NetLog::PHASE_END, entries[log_position].phase); |
| 4521 } | 4528 } |
| 4522 | 4529 |
| 4523 EXPECT_FALSE(LogContainsEntryWithTypeAfter( | 4530 EXPECT_FALSE(LogContainsEntryWithTypeAfter( |
| 4524 entries, log_position + 1, NetLog::TYPE_DELEGATE_INFO)); | 4531 entries, log_position + 1, NetLog::TYPE_DELEGATE_INFO)); |
| 4525 EXPECT_FALSE(LogContainsEntryWithTypeAfter( | 4532 EXPECT_FALSE(LogContainsEntryWithTypeAfter( |
| 4526 entries, log_position + 1, NetLog::TYPE_URL_REQUEST_DELEGATE)); | 4533 entries, log_position + 1, NetLog::TYPE_URL_REQUEST_DELEGATE)); |
| (...skipping 12 matching lines...) Expand all Loading... |
| 4539 TestDelegate::OnReceivedRedirect(request, new_url, defer_redirect); | 4546 TestDelegate::OnReceivedRedirect(request, new_url, defer_redirect); |
| 4540 request->SetExtraRequestHeaderByName(kExtraHeader, kExtraValue, false); | 4547 request->SetExtraRequestHeaderByName(kExtraHeader, kExtraValue, false); |
| 4541 } | 4548 } |
| 4542 }; | 4549 }; |
| 4543 | 4550 |
| 4544 } // namespace | 4551 } // namespace |
| 4545 | 4552 |
| 4546 TEST_F(URLRequestTestHTTP, RedirectWithAdditionalHeadersTest) { | 4553 TEST_F(URLRequestTestHTTP, RedirectWithAdditionalHeadersTest) { |
| 4547 ASSERT_TRUE(test_server_.Start()); | 4554 ASSERT_TRUE(test_server_.Start()); |
| 4548 | 4555 |
| 4549 GURL destination_url = test_server_.GetURL( | 4556 GURL destination_url = |
| 4550 "echoheader?" + std::string(kExtraHeader)); | 4557 test_server_.GetURL("echoheader?" + std::string(kExtraHeader)); |
| 4551 GURL original_url = test_server_.GetURL( | 4558 GURL original_url = |
| 4552 "server-redirect?" + destination_url.spec()); | 4559 test_server_.GetURL("server-redirect?" + destination_url.spec()); |
| 4553 RedirectWithAdditionalHeadersDelegate d; | 4560 RedirectWithAdditionalHeadersDelegate d; |
| 4554 URLRequest req(original_url, DEFAULT_PRIORITY, &d, &default_context_); | 4561 URLRequest req(original_url, DEFAULT_PRIORITY, &d, &default_context_); |
| 4555 req.Start(); | 4562 req.Start(); |
| 4556 base::RunLoop().Run(); | 4563 base::RunLoop().Run(); |
| 4557 | 4564 |
| 4558 std::string value; | 4565 std::string value; |
| 4559 const HttpRequestHeaders& headers = req.extra_request_headers(); | 4566 const HttpRequestHeaders& headers = req.extra_request_headers(); |
| 4560 EXPECT_TRUE(headers.GetHeader(kExtraHeader, &value)); | 4567 EXPECT_TRUE(headers.GetHeader(kExtraHeader, &value)); |
| 4561 EXPECT_EQ(kExtraValue, value); | 4568 EXPECT_EQ(kExtraValue, value); |
| 4562 EXPECT_FALSE(req.is_pending()); | 4569 EXPECT_FALSE(req.is_pending()); |
| 4563 EXPECT_FALSE(req.is_redirecting()); | 4570 EXPECT_FALSE(req.is_redirecting()); |
| 4564 EXPECT_EQ(kExtraValue, d.data_received()); | 4571 EXPECT_EQ(kExtraValue, d.data_received()); |
| 4565 } | 4572 } |
| 4566 | 4573 |
| 4567 namespace { | 4574 namespace { |
| 4568 | 4575 |
| 4569 const char kExtraHeaderToRemove[] = "To-Be-Removed"; | 4576 const char kExtraHeaderToRemove[] = "To-Be-Removed"; |
| 4570 | 4577 |
| 4571 class RedirectWithHeaderRemovalDelegate : public TestDelegate { | 4578 class RedirectWithHeaderRemovalDelegate : public TestDelegate { |
| 4572 virtual void OnReceivedRedirect(net::URLRequest* request, | 4579 virtual void OnReceivedRedirect(net::URLRequest* request, |
| 4573 const GURL& new_url, | 4580 const GURL& new_url, |
| 4574 bool* defer_redirect) OVERRIDE { | 4581 bool* defer_redirect) OVERRIDE { |
| 4575 TestDelegate::OnReceivedRedirect(request, new_url, defer_redirect); | 4582 TestDelegate::OnReceivedRedirect(request, new_url, defer_redirect); |
| 4576 request->RemoveRequestHeaderByName(kExtraHeaderToRemove); | 4583 request->RemoveRequestHeaderByName(kExtraHeaderToRemove); |
| 4577 } | 4584 } |
| 4578 }; | 4585 }; |
| 4579 | 4586 |
| 4580 } // namespace | 4587 } // namespace |
| 4581 | 4588 |
| 4582 TEST_F(URLRequestTestHTTP, RedirectWithHeaderRemovalTest) { | 4589 TEST_F(URLRequestTestHTTP, RedirectWithHeaderRemovalTest) { |
| 4583 ASSERT_TRUE(test_server_.Start()); | 4590 ASSERT_TRUE(test_server_.Start()); |
| 4584 | 4591 |
| 4585 GURL destination_url = test_server_.GetURL( | 4592 GURL destination_url = |
| 4586 "echoheader?" + std::string(kExtraHeaderToRemove)); | 4593 test_server_.GetURL("echoheader?" + std::string(kExtraHeaderToRemove)); |
| 4587 GURL original_url = test_server_.GetURL( | 4594 GURL original_url = |
| 4588 "server-redirect?" + destination_url.spec()); | 4595 test_server_.GetURL("server-redirect?" + destination_url.spec()); |
| 4589 RedirectWithHeaderRemovalDelegate d; | 4596 RedirectWithHeaderRemovalDelegate d; |
| 4590 URLRequest req(original_url, DEFAULT_PRIORITY, &d, &default_context_); | 4597 URLRequest req(original_url, DEFAULT_PRIORITY, &d, &default_context_); |
| 4591 req.SetExtraRequestHeaderByName(kExtraHeaderToRemove, "dummy", false); | 4598 req.SetExtraRequestHeaderByName(kExtraHeaderToRemove, "dummy", false); |
| 4592 req.Start(); | 4599 req.Start(); |
| 4593 base::RunLoop().Run(); | 4600 base::RunLoop().Run(); |
| 4594 | 4601 |
| 4595 std::string value; | 4602 std::string value; |
| 4596 const HttpRequestHeaders& headers = req.extra_request_headers(); | 4603 const HttpRequestHeaders& headers = req.extra_request_headers(); |
| 4597 EXPECT_FALSE(headers.GetHeader(kExtraHeaderToRemove, &value)); | 4604 EXPECT_FALSE(headers.GetHeader(kExtraHeaderToRemove, &value)); |
| 4598 EXPECT_FALSE(req.is_pending()); | 4605 EXPECT_FALSE(req.is_pending()); |
| (...skipping 189 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 4788 path = path.Append(FILE_PATH_LITERAL("net")); | 4795 path = path.Append(FILE_PATH_LITERAL("net")); |
| 4789 path = path.Append(FILE_PATH_LITERAL("data")); | 4796 path = path.Append(FILE_PATH_LITERAL("data")); |
| 4790 path = path.Append(FILE_PATH_LITERAL("url_request_unittest")); | 4797 path = path.Append(FILE_PATH_LITERAL("url_request_unittest")); |
| 4791 path = path.Append(FILE_PATH_LITERAL("with-headers.html")); | 4798 path = path.Append(FILE_PATH_LITERAL("with-headers.html")); |
| 4792 element_readers.push_back( | 4799 element_readers.push_back( |
| 4793 new UploadFileElementReader(base::MessageLoopProxy::current().get(), | 4800 new UploadFileElementReader(base::MessageLoopProxy::current().get(), |
| 4794 path, | 4801 path, |
| 4795 0, | 4802 0, |
| 4796 kuint64max, | 4803 kuint64max, |
| 4797 base::Time())); | 4804 base::Time())); |
| 4798 r.set_upload(make_scoped_ptr( | 4805 r.set_upload( |
| 4799 new UploadDataStream(element_readers.Pass(), 0))); | 4806 make_scoped_ptr(new UploadDataStream(element_readers.Pass(), 0))); |
| 4800 | 4807 |
| 4801 r.Start(); | 4808 r.Start(); |
| 4802 EXPECT_TRUE(r.is_pending()); | 4809 EXPECT_TRUE(r.is_pending()); |
| 4803 | 4810 |
| 4804 base::RunLoop().Run(); | 4811 base::RunLoop().Run(); |
| 4805 | 4812 |
| 4806 int64 size = 0; | 4813 int64 size = 0; |
| 4807 ASSERT_EQ(true, base::GetFileSize(path, &size)); | 4814 ASSERT_EQ(true, base::GetFileSize(path, &size)); |
| 4808 scoped_ptr<char[]> buf(new char[size]); | 4815 scoped_ptr<char[]> buf(new char[size]); |
| 4809 | 4816 |
| 4810 ASSERT_EQ(size, base::ReadFile(path, buf.get(), size)); | 4817 ASSERT_EQ(size, base::ReadFile(path, buf.get(), size)); |
| 4811 | 4818 |
| 4812 ASSERT_EQ(1, d.response_started_count()) | 4819 ASSERT_EQ(1, d.response_started_count()) |
| 4813 << "request failed: " << r.status().status() | 4820 << "request failed: " << r.status().status() |
| 4814 << ", error: " << r.status().error(); | 4821 << ", error: " << r.status().error(); |
| 4815 | 4822 |
| 4816 EXPECT_FALSE(d.received_data_before_response()); | 4823 EXPECT_FALSE(d.received_data_before_response()); |
| 4817 | 4824 |
| 4818 EXPECT_EQ(size, d.bytes_received()); | 4825 EXPECT_EQ(size, d.bytes_received()); |
| 4819 EXPECT_EQ(std::string(&buf[0], size), d.data_received()); | 4826 EXPECT_EQ(std::string(&buf[0], size), d.data_received()); |
| 4820 } | 4827 } |
| 4821 } | 4828 } |
| 4822 | 4829 |
| 4823 TEST_F(URLRequestTestHTTP, PostUnreadableFileTest) { | 4830 TEST_F(URLRequestTestHTTP, PostUnreadableFileTest) { |
| 4824 ASSERT_TRUE(test_server_.Start()); | 4831 ASSERT_TRUE(test_server_.Start()); |
| 4825 | 4832 |
| 4826 TestDelegate d; | 4833 TestDelegate d; |
| 4827 { | 4834 { |
| 4828 URLRequest r(test_server_.GetURL("echo"), DEFAULT_PRIORITY, | 4835 URLRequest r( |
| 4829 &d, &default_context_); | 4836 test_server_.GetURL("echo"), DEFAULT_PRIORITY, &d, &default_context_); |
| 4830 r.set_method("POST"); | 4837 r.set_method("POST"); |
| 4831 | 4838 |
| 4832 ScopedVector<UploadElementReader> element_readers; | 4839 ScopedVector<UploadElementReader> element_readers; |
| 4833 | 4840 |
| 4834 element_readers.push_back(new UploadFileElementReader( | 4841 element_readers.push_back(new UploadFileElementReader( |
| 4835 base::MessageLoopProxy::current().get(), | 4842 base::MessageLoopProxy::current().get(), |
| 4836 base::FilePath(FILE_PATH_LITERAL( | 4843 base::FilePath(FILE_PATH_LITERAL( |
| 4837 "c:\\path\\to\\non\\existant\\file.randomness.12345")), | 4844 "c:\\path\\to\\non\\existant\\file.randomness.12345")), |
| 4838 0, | 4845 0, |
| 4839 kuint64max, | 4846 kuint64max, |
| 4840 base::Time())); | 4847 base::Time())); |
| 4841 r.set_upload(make_scoped_ptr( | 4848 r.set_upload( |
| 4842 new UploadDataStream(element_readers.Pass(), 0))); | 4849 make_scoped_ptr(new UploadDataStream(element_readers.Pass(), 0))); |
| 4843 | 4850 |
| 4844 r.Start(); | 4851 r.Start(); |
| 4845 EXPECT_TRUE(r.is_pending()); | 4852 EXPECT_TRUE(r.is_pending()); |
| 4846 | 4853 |
| 4847 base::RunLoop().Run(); | 4854 base::RunLoop().Run(); |
| 4848 | 4855 |
| 4849 EXPECT_TRUE(d.request_failed()); | 4856 EXPECT_TRUE(d.request_failed()); |
| 4850 EXPECT_FALSE(d.received_data_before_response()); | 4857 EXPECT_FALSE(d.received_data_before_response()); |
| 4851 EXPECT_EQ(0, d.bytes_received()); | 4858 EXPECT_EQ(0, d.bytes_received()); |
| 4852 EXPECT_EQ(URLRequestStatus::FAILED, r.status().status()); | 4859 EXPECT_EQ(URLRequestStatus::FAILED, r.status().status()); |
| (...skipping 109 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 4962 default_context_.transport_security_state(); | 4969 default_context_.transport_security_state(); |
| 4963 bool sni_available = true; | 4970 bool sni_available = true; |
| 4964 TransportSecurityState::DomainState domain_state; | 4971 TransportSecurityState::DomainState domain_state; |
| 4965 EXPECT_TRUE(security_state->GetDomainState( | 4972 EXPECT_TRUE(security_state->GetDomainState( |
| 4966 SpawnedTestServer::kLocalhost, sni_available, &domain_state)); | 4973 SpawnedTestServer::kLocalhost, sni_available, &domain_state)); |
| 4967 EXPECT_EQ(TransportSecurityState::DomainState::MODE_FORCE_HTTPS, | 4974 EXPECT_EQ(TransportSecurityState::DomainState::MODE_FORCE_HTTPS, |
| 4968 domain_state.upgrade_mode); | 4975 domain_state.upgrade_mode); |
| 4969 EXPECT_TRUE(domain_state.sts_include_subdomains); | 4976 EXPECT_TRUE(domain_state.sts_include_subdomains); |
| 4970 EXPECT_FALSE(domain_state.pkp_include_subdomains); | 4977 EXPECT_FALSE(domain_state.pkp_include_subdomains); |
| 4971 #if defined(OS_ANDROID) | 4978 #if defined(OS_ANDROID) |
| 4972 // Android's CertVerifyProc does not (yet) handle pins. | 4979 // Android's CertVerifyProc does not (yet) handle pins. |
| 4973 #else | 4980 #else |
| 4974 EXPECT_FALSE(domain_state.HasPublicKeyPins()); | 4981 EXPECT_FALSE(domain_state.HasPublicKeyPins()); |
| 4975 #endif | 4982 #endif |
| 4976 } | 4983 } |
| 4977 | 4984 |
| 4978 // Android's CertVerifyProc does not (yet) handle pins. Therefore, it will | 4985 // Android's CertVerifyProc does not (yet) handle pins. Therefore, it will |
| 4979 // reject HPKP headers, and a test setting only HPKP headers will fail (no | 4986 // reject HPKP headers, and a test setting only HPKP headers will fail (no |
| 4980 // DomainState present because header rejected). | 4987 // DomainState present because header rejected). |
| 4981 #if defined(OS_ANDROID) | 4988 #if defined(OS_ANDROID) |
| 4982 #define MAYBE_ProcessPKP DISABLED_ProcessPKP | 4989 #define MAYBE_ProcessPKP DISABLED_ProcessPKP |
| (...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 5067 // We should have set parameters from the first header, not the second. | 5074 // We should have set parameters from the first header, not the second. |
| 5068 TransportSecurityState* security_state = | 5075 TransportSecurityState* security_state = |
| 5069 default_context_.transport_security_state(); | 5076 default_context_.transport_security_state(); |
| 5070 bool sni_available = true; | 5077 bool sni_available = true; |
| 5071 TransportSecurityState::DomainState domain_state; | 5078 TransportSecurityState::DomainState domain_state; |
| 5072 EXPECT_TRUE(security_state->GetDomainState( | 5079 EXPECT_TRUE(security_state->GetDomainState( |
| 5073 SpawnedTestServer::kLocalhost, sni_available, &domain_state)); | 5080 SpawnedTestServer::kLocalhost, sni_available, &domain_state)); |
| 5074 EXPECT_EQ(TransportSecurityState::DomainState::MODE_FORCE_HTTPS, | 5081 EXPECT_EQ(TransportSecurityState::DomainState::MODE_FORCE_HTTPS, |
| 5075 domain_state.upgrade_mode); | 5082 domain_state.upgrade_mode); |
| 5076 #if defined(OS_ANDROID) | 5083 #if defined(OS_ANDROID) |
| 5077 // Android's CertVerifyProc does not (yet) handle pins. | 5084 // Android's CertVerifyProc does not (yet) handle pins. |
| 5078 #else | 5085 #else |
| 5079 EXPECT_TRUE(domain_state.HasPublicKeyPins()); | 5086 EXPECT_TRUE(domain_state.HasPublicKeyPins()); |
| 5080 #endif | 5087 #endif |
| 5081 EXPECT_NE(domain_state.upgrade_expiry, | 5088 EXPECT_NE(domain_state.upgrade_expiry, |
| 5082 domain_state.dynamic_spki_hashes_expiry); | 5089 domain_state.dynamic_spki_hashes_expiry); |
| 5083 | 5090 |
| 5084 // Even though there is an HSTS header asserting includeSubdomains, it is | 5091 // Even though there is an HSTS header asserting includeSubdomains, it is |
| 5085 // the *second* such header, and we MUST process only the first. | 5092 // the *second* such header, and we MUST process only the first. |
| 5086 EXPECT_FALSE(domain_state.sts_include_subdomains); | 5093 EXPECT_FALSE(domain_state.sts_include_subdomains); |
| 5087 // includeSubdomains does not occur in the test HPKP header. | 5094 // includeSubdomains does not occur in the test HPKP header. |
| (...skipping 21 matching lines...) Expand all Loading... |
| 5109 | 5116 |
| 5110 TransportSecurityState* security_state = | 5117 TransportSecurityState* security_state = |
| 5111 default_context_.transport_security_state(); | 5118 default_context_.transport_security_state(); |
| 5112 bool sni_available = true; | 5119 bool sni_available = true; |
| 5113 TransportSecurityState::DomainState domain_state; | 5120 TransportSecurityState::DomainState domain_state; |
| 5114 EXPECT_TRUE(security_state->GetDomainState( | 5121 EXPECT_TRUE(security_state->GetDomainState( |
| 5115 SpawnedTestServer::kLocalhost, sni_available, &domain_state)); | 5122 SpawnedTestServer::kLocalhost, sni_available, &domain_state)); |
| 5116 EXPECT_EQ(TransportSecurityState::DomainState::MODE_FORCE_HTTPS, | 5123 EXPECT_EQ(TransportSecurityState::DomainState::MODE_FORCE_HTTPS, |
| 5117 domain_state.upgrade_mode); | 5124 domain_state.upgrade_mode); |
| 5118 #if defined(OS_ANDROID) | 5125 #if defined(OS_ANDROID) |
| 5119 // Android's CertVerifyProc does not (yet) handle pins. | 5126 // Android's CertVerifyProc does not (yet) handle pins. |
| 5120 #else | 5127 #else |
| 5121 EXPECT_TRUE(domain_state.HasPublicKeyPins()); | 5128 EXPECT_TRUE(domain_state.HasPublicKeyPins()); |
| 5122 #endif | 5129 #endif |
| 5123 EXPECT_NE(domain_state.upgrade_expiry, | 5130 EXPECT_NE(domain_state.upgrade_expiry, |
| 5124 domain_state.dynamic_spki_hashes_expiry); | 5131 domain_state.dynamic_spki_hashes_expiry); |
| 5125 | 5132 |
| 5126 EXPECT_TRUE(domain_state.sts_include_subdomains); | 5133 EXPECT_TRUE(domain_state.sts_include_subdomains); |
| 5127 EXPECT_FALSE(domain_state.pkp_include_subdomains); | 5134 EXPECT_FALSE(domain_state.pkp_include_subdomains); |
| 5128 } | 5135 } |
| 5129 | 5136 |
| (...skipping 288 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 5418 // the reference fragment of the target URL must not be modified. | 5425 // the reference fragment of the target URL must not be modified. |
| 5419 TEST_F(URLRequestTestHTTP, RedirectJobWithReferenceFragment) { | 5426 TEST_F(URLRequestTestHTTP, RedirectJobWithReferenceFragment) { |
| 5420 ASSERT_TRUE(test_server_.Start()); | 5427 ASSERT_TRUE(test_server_.Start()); |
| 5421 | 5428 |
| 5422 GURL original_url(test_server_.GetURL("original#should-not-be-appended")); | 5429 GURL original_url(test_server_.GetURL("original#should-not-be-appended")); |
| 5423 GURL redirect_url(test_server_.GetURL("echo")); | 5430 GURL redirect_url(test_server_.GetURL("echo")); |
| 5424 | 5431 |
| 5425 TestDelegate d; | 5432 TestDelegate d; |
| 5426 URLRequest r(original_url, DEFAULT_PRIORITY, &d, &default_context_); | 5433 URLRequest r(original_url, DEFAULT_PRIORITY, &d, &default_context_); |
| 5427 | 5434 |
| 5428 URLRequestRedirectJob* job = new URLRequestRedirectJob( | 5435 URLRequestRedirectJob* job = |
| 5429 &r, &default_network_delegate_, redirect_url, | 5436 new URLRequestRedirectJob(&r, |
| 5430 URLRequestRedirectJob::REDIRECT_302_FOUND, "Very Good Reason"); | 5437 &default_network_delegate_, |
| 5438 redirect_url, |
| 5439 URLRequestRedirectJob::REDIRECT_302_FOUND, |
| 5440 "Very Good Reason"); |
| 5431 AddTestInterceptor()->set_main_intercept_job(job); | 5441 AddTestInterceptor()->set_main_intercept_job(job); |
| 5432 | 5442 |
| 5433 r.Start(); | 5443 r.Start(); |
| 5434 base::RunLoop().Run(); | 5444 base::RunLoop().Run(); |
| 5435 | 5445 |
| 5436 EXPECT_EQ(URLRequestStatus::SUCCESS, r.status().status()); | 5446 EXPECT_EQ(URLRequestStatus::SUCCESS, r.status().status()); |
| 5437 EXPECT_EQ(net::OK, r.status().error()); | 5447 EXPECT_EQ(net::OK, r.status().error()); |
| 5438 EXPECT_EQ(original_url, r.original_url()); | 5448 EXPECT_EQ(original_url, r.original_url()); |
| 5439 EXPECT_EQ(redirect_url, r.url()); | 5449 EXPECT_EQ(redirect_url, r.url()); |
| 5440 } | 5450 } |
| (...skipping 378 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 5819 d.set_credentials(AuthCredentials(kUser, kSecret)); | 5829 d.set_credentials(AuthCredentials(kUser, kSecret)); |
| 5820 | 5830 |
| 5821 URLRequest r(url_requiring_auth, DEFAULT_PRIORITY, &d, &context); | 5831 URLRequest r(url_requiring_auth, DEFAULT_PRIORITY, &d, &context); |
| 5822 r.Start(); | 5832 r.Start(); |
| 5823 | 5833 |
| 5824 base::RunLoop().Run(); | 5834 base::RunLoop().Run(); |
| 5825 | 5835 |
| 5826 EXPECT_TRUE(d.data_received().find("user/secret") != std::string::npos); | 5836 EXPECT_TRUE(d.data_received().find("user/secret") != std::string::npos); |
| 5827 | 5837 |
| 5828 // Make sure we sent the cookie in the restarted transaction. | 5838 // Make sure we sent the cookie in the restarted transaction. |
| 5829 EXPECT_TRUE(d.data_received().find("Cookie: got_challenged=true") | 5839 EXPECT_TRUE(d.data_received().find("Cookie: got_challenged=true") != |
| 5830 != std::string::npos); | 5840 std::string::npos); |
| 5831 } | 5841 } |
| 5832 | 5842 |
| 5833 // Same test as above, except this time the restart is initiated earlier | 5843 // Same test as above, except this time the restart is initiated earlier |
| 5834 // (without user intervention since identity is embedded in the URL). | 5844 // (without user intervention since identity is embedded in the URL). |
| 5835 { | 5845 { |
| 5836 TestNetworkDelegate network_delegate; // Must outlive URLRequest. | 5846 TestNetworkDelegate network_delegate; // Must outlive URLRequest. |
| 5837 TestURLRequestContext context(true); | 5847 TestURLRequestContext context(true); |
| 5838 context.set_network_delegate(&network_delegate); | 5848 context.set_network_delegate(&network_delegate); |
| 5839 context.Init(); | 5849 context.Init(); |
| 5840 | 5850 |
| 5841 TestDelegate d; | 5851 TestDelegate d; |
| 5842 | 5852 |
| 5843 GURL::Replacements replacements; | 5853 GURL::Replacements replacements; |
| 5844 std::string username("user2"); | 5854 std::string username("user2"); |
| 5845 std::string password("secret"); | 5855 std::string password("secret"); |
| 5846 replacements.SetUsernameStr(username); | 5856 replacements.SetUsernameStr(username); |
| 5847 replacements.SetPasswordStr(password); | 5857 replacements.SetPasswordStr(password); |
| 5848 GURL url_with_identity = url_requiring_auth.ReplaceComponents(replacements); | 5858 GURL url_with_identity = url_requiring_auth.ReplaceComponents(replacements); |
| 5849 | 5859 |
| 5850 URLRequest r(url_with_identity, DEFAULT_PRIORITY, &d, &context); | 5860 URLRequest r(url_with_identity, DEFAULT_PRIORITY, &d, &context); |
| 5851 r.Start(); | 5861 r.Start(); |
| 5852 | 5862 |
| 5853 base::RunLoop().Run(); | 5863 base::RunLoop().Run(); |
| 5854 | 5864 |
| 5855 EXPECT_TRUE(d.data_received().find("user2/secret") != std::string::npos); | 5865 EXPECT_TRUE(d.data_received().find("user2/secret") != std::string::npos); |
| 5856 | 5866 |
| 5857 // Make sure we sent the cookie in the restarted transaction. | 5867 // Make sure we sent the cookie in the restarted transaction. |
| 5858 EXPECT_TRUE(d.data_received().find("Cookie: got_challenged=true") | 5868 EXPECT_TRUE(d.data_received().find("Cookie: got_challenged=true") != |
| 5859 != std::string::npos); | 5869 std::string::npos); |
| 5860 } | 5870 } |
| 5861 } | 5871 } |
| 5862 | 5872 |
| 5863 // Tests that load timing works as expected with auth and the cache. | 5873 // Tests that load timing works as expected with auth and the cache. |
| 5864 TEST_F(URLRequestTestHTTP, BasicAuthLoadTiming) { | 5874 TEST_F(URLRequestTestHTTP, BasicAuthLoadTiming) { |
| 5865 ASSERT_TRUE(test_server_.Start()); | 5875 ASSERT_TRUE(test_server_.Start()); |
| 5866 | 5876 |
| 5867 // populate the cache | 5877 // populate the cache |
| 5868 { | 5878 { |
| 5869 TestDelegate d; | 5879 TestDelegate d; |
| (...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 5938 URLRequest req(test_server_.GetURL("files/redirect-to-echoall"), | 5948 URLRequest req(test_server_.GetURL("files/redirect-to-echoall"), |
| 5939 DEFAULT_PRIORITY, | 5949 DEFAULT_PRIORITY, |
| 5940 &d, | 5950 &d, |
| 5941 &default_context_); | 5951 &default_context_); |
| 5942 req.set_method("POST"); | 5952 req.set_method("POST"); |
| 5943 req.set_upload(make_scoped_ptr(CreateSimpleUploadData(kData))); | 5953 req.set_upload(make_scoped_ptr(CreateSimpleUploadData(kData))); |
| 5944 | 5954 |
| 5945 // Set headers (some of which are specific to the POST). | 5955 // Set headers (some of which are specific to the POST). |
| 5946 HttpRequestHeaders headers; | 5956 HttpRequestHeaders headers; |
| 5947 headers.AddHeadersFromString( | 5957 headers.AddHeadersFromString( |
| 5948 "Content-Type: multipart/form-data; " | 5958 "Content-Type: multipart/form-data; " |
| 5949 "boundary=----WebKitFormBoundaryAADeAA+NAAWMAAwZ\r\n" | 5959 "boundary=----WebKitFormBoundaryAADeAA+NAAWMAAwZ\r\n" |
| 5950 "Accept: text/xml,application/xml,application/xhtml+xml,text/html;q=0.9," | 5960 "Accept: text/xml,application/xml,application/xhtml+xml,text/html;q=0.9," |
| 5951 "text/plain;q=0.8,image/png,*/*;q=0.5\r\n" | 5961 "text/plain;q=0.8,image/png,*/*;q=0.5\r\n" |
| 5952 "Accept-Language: en-US,en\r\n" | 5962 "Accept-Language: en-US,en\r\n" |
| 5953 "Accept-Charset: ISO-8859-1,*,utf-8\r\n" | 5963 "Accept-Charset: ISO-8859-1,*,utf-8\r\n" |
| 5954 "Content-Length: 11\r\n" | 5964 "Content-Length: 11\r\n" |
| 5955 "Origin: http://localhost:1337/"); | 5965 "Origin: http://localhost:1337/"); |
| 5956 req.SetExtraRequestHeaders(headers); | 5966 req.SetExtraRequestHeaders(headers); |
| 5957 req.Start(); | 5967 req.Start(); |
| 5958 base::RunLoop().Run(); | 5968 base::RunLoop().Run(); |
| 5959 | 5969 |
| 5960 std::string mime_type; | 5970 std::string mime_type; |
| 5961 req.GetMimeType(&mime_type); | 5971 req.GetMimeType(&mime_type); |
| 5962 EXPECT_EQ("text/html", mime_type); | 5972 EXPECT_EQ("text/html", mime_type); |
| 5963 | 5973 |
| 5964 const std::string& data = d.data_received(); | 5974 const std::string& data = d.data_received(); |
| 5965 | 5975 |
| (...skipping 113 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 6079 DEFAULT_PRIORITY, | 6089 DEFAULT_PRIORITY, |
| 6080 &d, | 6090 &d, |
| 6081 &default_context_); | 6091 &default_context_); |
| 6082 req.set_method("POST"); | 6092 req.set_method("POST"); |
| 6083 req.set_upload(make_scoped_ptr(CreateSimpleUploadData(kData))); | 6093 req.set_upload(make_scoped_ptr(CreateSimpleUploadData(kData))); |
| 6084 HttpRequestHeaders headers; | 6094 HttpRequestHeaders headers; |
| 6085 headers.SetHeader(HttpRequestHeaders::kContentLength, | 6095 headers.SetHeader(HttpRequestHeaders::kContentLength, |
| 6086 base::UintToString(arraysize(kData) - 1)); | 6096 base::UintToString(arraysize(kData) - 1)); |
| 6087 req.SetExtraRequestHeaders(headers); | 6097 req.SetExtraRequestHeaders(headers); |
| 6088 | 6098 |
| 6089 URLRequestRedirectJob* job = new URLRequestRedirectJob( | 6099 URLRequestRedirectJob* job = |
| 6090 &req, &default_network_delegate_, test_server_.GetURL("echo"), | 6100 new URLRequestRedirectJob(&req, |
| 6091 URLRequestRedirectJob::REDIRECT_302_FOUND, "Very Good Reason"); | 6101 &default_network_delegate_, |
| 6102 test_server_.GetURL("echo"), |
| 6103 URLRequestRedirectJob::REDIRECT_302_FOUND, |
| 6104 "Very Good Reason"); |
| 6092 AddTestInterceptor()->set_main_intercept_job(job); | 6105 AddTestInterceptor()->set_main_intercept_job(job); |
| 6093 | 6106 |
| 6094 req.Start(); | 6107 req.Start(); |
| 6095 base::RunLoop().Run(); | 6108 base::RunLoop().Run(); |
| 6096 EXPECT_EQ("GET", req.method()); | 6109 EXPECT_EQ("GET", req.method()); |
| 6097 } | 6110 } |
| 6098 | 6111 |
| 6099 TEST_F(URLRequestTestHTTP, InterceptPost307RedirectPost) { | 6112 TEST_F(URLRequestTestHTTP, InterceptPost307RedirectPost) { |
| 6100 ASSERT_TRUE(test_server_.Start()); | 6113 ASSERT_TRUE(test_server_.Start()); |
| 6101 | 6114 |
| 6102 const char kData[] = "hello world"; | 6115 const char kData[] = "hello world"; |
| 6103 | 6116 |
| 6104 TestDelegate d; | 6117 TestDelegate d; |
| 6105 URLRequest req(test_server_.GetURL("empty.html"), | 6118 URLRequest req(test_server_.GetURL("empty.html"), |
| 6106 DEFAULT_PRIORITY, | 6119 DEFAULT_PRIORITY, |
| 6107 &d, | 6120 &d, |
| 6108 &default_context_); | 6121 &default_context_); |
| 6109 req.set_method("POST"); | 6122 req.set_method("POST"); |
| 6110 req.set_upload(make_scoped_ptr(CreateSimpleUploadData(kData))); | 6123 req.set_upload(make_scoped_ptr(CreateSimpleUploadData(kData))); |
| 6111 HttpRequestHeaders headers; | 6124 HttpRequestHeaders headers; |
| 6112 headers.SetHeader(HttpRequestHeaders::kContentLength, | 6125 headers.SetHeader(HttpRequestHeaders::kContentLength, |
| 6113 base::UintToString(arraysize(kData) - 1)); | 6126 base::UintToString(arraysize(kData) - 1)); |
| 6114 req.SetExtraRequestHeaders(headers); | 6127 req.SetExtraRequestHeaders(headers); |
| 6115 | 6128 |
| 6116 URLRequestRedirectJob* job = new URLRequestRedirectJob( | 6129 URLRequestRedirectJob* job = new URLRequestRedirectJob( |
| 6117 &req, &default_network_delegate_, test_server_.GetURL("echo"), | 6130 &req, |
| 6131 &default_network_delegate_, |
| 6132 test_server_.GetURL("echo"), |
| 6118 URLRequestRedirectJob::REDIRECT_307_TEMPORARY_REDIRECT, | 6133 URLRequestRedirectJob::REDIRECT_307_TEMPORARY_REDIRECT, |
| 6119 "Very Good Reason"); | 6134 "Very Good Reason"); |
| 6120 AddTestInterceptor()->set_main_intercept_job(job); | 6135 AddTestInterceptor()->set_main_intercept_job(job); |
| 6121 | 6136 |
| 6122 req.Start(); | 6137 req.Start(); |
| 6123 base::RunLoop().Run(); | 6138 base::RunLoop().Run(); |
| 6124 EXPECT_EQ("POST", req.method()); | 6139 EXPECT_EQ("POST", req.method()); |
| 6125 EXPECT_EQ(kData, d.data_received()); | 6140 EXPECT_EQ(kData, d.data_received()); |
| 6126 } | 6141 } |
| 6127 | 6142 |
| (...skipping 155 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 6283 TestURLRequestContext context(true); | 6298 TestURLRequestContext context(true); |
| 6284 context.set_network_delegate(&network_delegate); | 6299 context.set_network_delegate(&network_delegate); |
| 6285 context.Init(); | 6300 context.Init(); |
| 6286 // We override the HttpUserAgentSettings after initialization because empty | 6301 // We override the HttpUserAgentSettings after initialization because empty |
| 6287 // entries get overridden by Init(). | 6302 // entries get overridden by Init(). |
| 6288 context.set_http_user_agent_settings(NULL); | 6303 context.set_http_user_agent_settings(NULL); |
| 6289 | 6304 |
| 6290 struct { | 6305 struct { |
| 6291 const char* request; | 6306 const char* request; |
| 6292 const char* expected_response; | 6307 const char* expected_response; |
| 6293 } tests[] = { { "echoheader?Accept-Language", "None" }, | 6308 } tests[] = {{"echoheader?Accept-Language", "None"}, |
| 6294 { "echoheader?Accept-Charset", "None" }, | 6309 {"echoheader?Accept-Charset", "None"}, |
| 6295 { "echoheader?User-Agent", "" } }; | 6310 {"echoheader?User-Agent", ""}}; |
| 6296 | 6311 |
| 6297 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(tests); i++) { | 6312 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(tests); i++) { |
| 6298 TestDelegate d; | 6313 TestDelegate d; |
| 6299 URLRequest req( | 6314 URLRequest req( |
| 6300 test_server_.GetURL(tests[i].request), DEFAULT_PRIORITY, &d, &context); | 6315 test_server_.GetURL(tests[i].request), DEFAULT_PRIORITY, &d, &context); |
| 6301 req.Start(); | 6316 req.Start(); |
| 6302 base::RunLoop().Run(); | 6317 base::RunLoop().Run(); |
| 6303 EXPECT_EQ(tests[i].expected_response, d.data_received()) | 6318 EXPECT_EQ(tests[i].expected_response, d.data_received()) |
| 6304 << " Request = \"" << tests[i].request << "\""; | 6319 << " Request = \"" << tests[i].request << "\""; |
| 6305 } | 6320 } |
| 6306 } | 6321 } |
| 6307 | 6322 |
| 6308 // Make sure that URLRequest passes on its priority updates to | 6323 // Make sure that URLRequest passes on its priority updates to |
| 6309 // newly-created jobs after the first one. | 6324 // newly-created jobs after the first one. |
| 6310 TEST_F(URLRequestTestHTTP, SetSubsequentJobPriority) { | 6325 TEST_F(URLRequestTestHTTP, SetSubsequentJobPriority) { |
| 6311 ASSERT_TRUE(test_server_.Start()); | 6326 ASSERT_TRUE(test_server_.Start()); |
| 6312 | 6327 |
| 6313 TestDelegate d; | 6328 TestDelegate d; |
| 6314 URLRequest req(test_server_.GetURL("empty.html"), | 6329 URLRequest req(test_server_.GetURL("empty.html"), |
| 6315 DEFAULT_PRIORITY, | 6330 DEFAULT_PRIORITY, |
| 6316 &d, | 6331 &d, |
| 6317 &default_context_); | 6332 &default_context_); |
| 6318 EXPECT_EQ(DEFAULT_PRIORITY, req.priority()); | 6333 EXPECT_EQ(DEFAULT_PRIORITY, req.priority()); |
| 6319 | 6334 |
| 6320 scoped_refptr<URLRequestRedirectJob> redirect_job = | 6335 scoped_refptr<URLRequestRedirectJob> redirect_job = |
| 6321 new URLRequestRedirectJob( | 6336 new URLRequestRedirectJob(&req, |
| 6322 &req, &default_network_delegate_, test_server_.GetURL("echo"), | 6337 &default_network_delegate_, |
| 6323 URLRequestRedirectJob::REDIRECT_302_FOUND, "Very Good Reason"); | 6338 test_server_.GetURL("echo"), |
| 6339 URLRequestRedirectJob::REDIRECT_302_FOUND, |
| 6340 "Very Good Reason"); |
| 6324 AddTestInterceptor()->set_main_intercept_job(redirect_job.get()); | 6341 AddTestInterceptor()->set_main_intercept_job(redirect_job.get()); |
| 6325 | 6342 |
| 6326 req.SetPriority(LOW); | 6343 req.SetPriority(LOW); |
| 6327 req.Start(); | 6344 req.Start(); |
| 6328 EXPECT_TRUE(req.is_pending()); | 6345 EXPECT_TRUE(req.is_pending()); |
| 6329 | 6346 |
| 6330 scoped_refptr<URLRequestTestJob> job = | 6347 scoped_refptr<URLRequestTestJob> job = |
| 6331 new URLRequestTestJob(&req, &default_network_delegate_); | 6348 new URLRequestTestJob(&req, &default_network_delegate_); |
| 6332 AddTestInterceptor()->set_main_intercept_job(job.get()); | 6349 AddTestInterceptor()->set_main_intercept_job(job.get()); |
| 6333 | 6350 |
| (...skipping 14 matching lines...) Expand all Loading... |
| 6348 params.proxy_service = default_context_.proxy_service(); | 6365 params.proxy_service = default_context_.proxy_service(); |
| 6349 params.ssl_config_service = default_context_.ssl_config_service(); | 6366 params.ssl_config_service = default_context_.ssl_config_service(); |
| 6350 params.http_auth_handler_factory = | 6367 params.http_auth_handler_factory = |
| 6351 default_context_.http_auth_handler_factory(); | 6368 default_context_.http_auth_handler_factory(); |
| 6352 params.network_delegate = &default_network_delegate_; | 6369 params.network_delegate = &default_network_delegate_; |
| 6353 params.http_server_properties = default_context_.http_server_properties(); | 6370 params.http_server_properties = default_context_.http_server_properties(); |
| 6354 scoped_ptr<HttpNetworkLayer> network_layer( | 6371 scoped_ptr<HttpNetworkLayer> network_layer( |
| 6355 new HttpNetworkLayer(new HttpNetworkSession(params))); | 6372 new HttpNetworkLayer(new HttpNetworkSession(params))); |
| 6356 network_layer->OnSuspend(); | 6373 network_layer->OnSuspend(); |
| 6357 | 6374 |
| 6358 HttpCache http_cache(network_layer.release(), default_context_.net_log(), | 6375 HttpCache http_cache(network_layer.release(), |
| 6376 default_context_.net_log(), |
| 6359 HttpCache::DefaultBackend::InMemory(0)); | 6377 HttpCache::DefaultBackend::InMemory(0)); |
| 6360 | 6378 |
| 6361 TestURLRequestContext context(true); | 6379 TestURLRequestContext context(true); |
| 6362 context.set_http_transaction_factory(&http_cache); | 6380 context.set_http_transaction_factory(&http_cache); |
| 6363 context.Init(); | 6381 context.Init(); |
| 6364 | 6382 |
| 6365 TestDelegate d; | 6383 TestDelegate d; |
| 6366 URLRequest req(GURL("http://127.0.0.1/"), | 6384 URLRequest req(GURL("http://127.0.0.1/"), DEFAULT_PRIORITY, &d, &context); |
| 6367 DEFAULT_PRIORITY, | |
| 6368 &d, | |
| 6369 &context); | |
| 6370 req.Start(); | 6385 req.Start(); |
| 6371 base::RunLoop().Run(); | 6386 base::RunLoop().Run(); |
| 6372 | 6387 |
| 6373 EXPECT_TRUE(d.request_failed()); | 6388 EXPECT_TRUE(d.request_failed()); |
| 6374 EXPECT_EQ(URLRequestStatus::FAILED, req.status().status()); | 6389 EXPECT_EQ(URLRequestStatus::FAILED, req.status().status()); |
| 6375 EXPECT_EQ(ERR_NETWORK_IO_SUSPENDED, req.status().error()); | 6390 EXPECT_EQ(ERR_NETWORK_IO_SUSPENDED, req.status().error()); |
| 6376 } | 6391 } |
| 6377 | 6392 |
| 6378 // Check that creating a network request while entering/exiting suspend mode | 6393 // Check that creating a network request while entering/exiting suspend mode |
| 6379 // fails as it should in the case there is no cache. This is the only case | 6394 // fails as it should in the case there is no cache. This is the only case |
| (...skipping 11 matching lines...) Expand all Loading... |
| 6391 params.network_delegate = &default_network_delegate_; | 6406 params.network_delegate = &default_network_delegate_; |
| 6392 params.http_server_properties = default_context_.http_server_properties(); | 6407 params.http_server_properties = default_context_.http_server_properties(); |
| 6393 HttpNetworkLayer network_layer(new HttpNetworkSession(params)); | 6408 HttpNetworkLayer network_layer(new HttpNetworkSession(params)); |
| 6394 network_layer.OnSuspend(); | 6409 network_layer.OnSuspend(); |
| 6395 | 6410 |
| 6396 TestURLRequestContext context(true); | 6411 TestURLRequestContext context(true); |
| 6397 context.set_http_transaction_factory(&network_layer); | 6412 context.set_http_transaction_factory(&network_layer); |
| 6398 context.Init(); | 6413 context.Init(); |
| 6399 | 6414 |
| 6400 TestDelegate d; | 6415 TestDelegate d; |
| 6401 URLRequest req(GURL("http://127.0.0.1/"), | 6416 URLRequest req(GURL("http://127.0.0.1/"), DEFAULT_PRIORITY, &d, &context); |
| 6402 DEFAULT_PRIORITY, | |
| 6403 &d, | |
| 6404 &context); | |
| 6405 req.Start(); | 6417 req.Start(); |
| 6406 base::RunLoop().Run(); | 6418 base::RunLoop().Run(); |
| 6407 | 6419 |
| 6408 EXPECT_TRUE(d.request_failed()); | 6420 EXPECT_TRUE(d.request_failed()); |
| 6409 EXPECT_EQ(URLRequestStatus::FAILED, req.status().status()); | 6421 EXPECT_EQ(URLRequestStatus::FAILED, req.status().status()); |
| 6410 EXPECT_EQ(ERR_NETWORK_IO_SUSPENDED, req.status().error()); | 6422 EXPECT_EQ(ERR_NETWORK_IO_SUSPENDED, req.status().error()); |
| 6411 } | 6423 } |
| 6412 | 6424 |
| 6413 class HTTPSRequestTest : public testing::Test { | 6425 class HTTPSRequestTest : public testing::Test { |
| 6414 public: | 6426 public: |
| (...skipping 23 matching lines...) Expand all Loading... |
| 6438 &default_context_); | 6450 &default_context_); |
| 6439 r.Start(); | 6451 r.Start(); |
| 6440 EXPECT_TRUE(r.is_pending()); | 6452 EXPECT_TRUE(r.is_pending()); |
| 6441 | 6453 |
| 6442 base::RunLoop().Run(); | 6454 base::RunLoop().Run(); |
| 6443 | 6455 |
| 6444 EXPECT_EQ(1, d.response_started_count()); | 6456 EXPECT_EQ(1, d.response_started_count()); |
| 6445 EXPECT_FALSE(d.received_data_before_response()); | 6457 EXPECT_FALSE(d.received_data_before_response()); |
| 6446 EXPECT_NE(0, d.bytes_received()); | 6458 EXPECT_NE(0, d.bytes_received()); |
| 6447 CheckSSLInfo(r.ssl_info()); | 6459 CheckSSLInfo(r.ssl_info()); |
| 6448 EXPECT_EQ(test_server.host_port_pair().host(), | 6460 EXPECT_EQ(test_server.host_port_pair().host(), r.GetSocketAddress().host()); |
| 6449 r.GetSocketAddress().host()); | 6461 EXPECT_EQ(test_server.host_port_pair().port(), r.GetSocketAddress().port()); |
| 6450 EXPECT_EQ(test_server.host_port_pair().port(), | |
| 6451 r.GetSocketAddress().port()); | |
| 6452 } | 6462 } |
| 6453 } | 6463 } |
| 6454 | 6464 |
| 6455 TEST_F(HTTPSRequestTest, HTTPSMismatchedTest) { | 6465 TEST_F(HTTPSRequestTest, HTTPSMismatchedTest) { |
| 6456 SpawnedTestServer::SSLOptions ssl_options( | 6466 SpawnedTestServer::SSLOptions ssl_options( |
| 6457 SpawnedTestServer::SSLOptions::CERT_MISMATCHED_NAME); | 6467 SpawnedTestServer::SSLOptions::CERT_MISMATCHED_NAME); |
| 6458 SpawnedTestServer test_server( | 6468 SpawnedTestServer test_server( |
| 6459 SpawnedTestServer::TYPE_HTTPS, | 6469 SpawnedTestServer::TYPE_HTTPS, |
| 6460 ssl_options, | 6470 ssl_options, |
| 6461 base::FilePath(FILE_PATH_LITERAL("net/data/ssl"))); | 6471 base::FilePath(FILE_PATH_LITERAL("net/data/ssl"))); |
| 6462 ASSERT_TRUE(test_server.Start()); | 6472 ASSERT_TRUE(test_server.Start()); |
| 6463 | 6473 |
| 6464 bool err_allowed = true; | 6474 bool err_allowed = true; |
| 6465 for (int i = 0; i < 2 ; i++, err_allowed = !err_allowed) { | 6475 for (int i = 0; i < 2; i++, err_allowed = !err_allowed) { |
| 6466 TestDelegate d; | 6476 TestDelegate d; |
| 6467 { | 6477 { |
| 6468 d.set_allow_certificate_errors(err_allowed); | 6478 d.set_allow_certificate_errors(err_allowed); |
| 6469 URLRequest r(test_server.GetURL(std::string()), | 6479 URLRequest r(test_server.GetURL(std::string()), |
| 6470 DEFAULT_PRIORITY, | 6480 DEFAULT_PRIORITY, |
| 6471 &d, | 6481 &d, |
| 6472 &default_context_); | 6482 &default_context_); |
| 6473 | 6483 |
| 6474 r.Start(); | 6484 r.Start(); |
| 6475 EXPECT_TRUE(r.is_pending()); | 6485 EXPECT_TRUE(r.is_pending()); |
| (...skipping 18 matching lines...) Expand all Loading... |
| 6494 SpawnedTestServer::SSLOptions::CERT_EXPIRED); | 6504 SpawnedTestServer::SSLOptions::CERT_EXPIRED); |
| 6495 SpawnedTestServer test_server( | 6505 SpawnedTestServer test_server( |
| 6496 SpawnedTestServer::TYPE_HTTPS, | 6506 SpawnedTestServer::TYPE_HTTPS, |
| 6497 ssl_options, | 6507 ssl_options, |
| 6498 base::FilePath(FILE_PATH_LITERAL("net/data/ssl"))); | 6508 base::FilePath(FILE_PATH_LITERAL("net/data/ssl"))); |
| 6499 ASSERT_TRUE(test_server.Start()); | 6509 ASSERT_TRUE(test_server.Start()); |
| 6500 | 6510 |
| 6501 // Iterate from false to true, just so that we do the opposite of the | 6511 // Iterate from false to true, just so that we do the opposite of the |
| 6502 // previous test in order to increase test coverage. | 6512 // previous test in order to increase test coverage. |
| 6503 bool err_allowed = false; | 6513 bool err_allowed = false; |
| 6504 for (int i = 0; i < 2 ; i++, err_allowed = !err_allowed) { | 6514 for (int i = 0; i < 2; i++, err_allowed = !err_allowed) { |
| 6505 TestDelegate d; | 6515 TestDelegate d; |
| 6506 { | 6516 { |
| 6507 d.set_allow_certificate_errors(err_allowed); | 6517 d.set_allow_certificate_errors(err_allowed); |
| 6508 URLRequest r(test_server.GetURL(std::string()), | 6518 URLRequest r(test_server.GetURL(std::string()), |
| 6509 DEFAULT_PRIORITY, | 6519 DEFAULT_PRIORITY, |
| 6510 &d, | 6520 &d, |
| 6511 &default_context_); | 6521 &default_context_); |
| 6512 | 6522 |
| 6513 r.Start(); | 6523 r.Start(); |
| 6514 EXPECT_TRUE(r.is_pending()); | 6524 EXPECT_TRUE(r.is_pending()); |
| 6515 | 6525 |
| 6516 base::RunLoop().Run(); | 6526 base::RunLoop().Run(); |
| 6517 | 6527 |
| 6518 EXPECT_EQ(1, d.response_started_count()); | 6528 EXPECT_EQ(1, d.response_started_count()); |
| 6519 EXPECT_FALSE(d.received_data_before_response()); | 6529 EXPECT_FALSE(d.received_data_before_response()); |
| 6520 EXPECT_TRUE(d.have_certificate_errors()); | 6530 EXPECT_TRUE(d.have_certificate_errors()); |
| 6521 if (err_allowed) { | 6531 if (err_allowed) { |
| 6522 EXPECT_NE(0, d.bytes_received()); | 6532 EXPECT_NE(0, d.bytes_received()); |
| 6523 CheckSSLInfo(r.ssl_info()); | 6533 CheckSSLInfo(r.ssl_info()); |
| 6524 } else { | 6534 } else { |
| 6525 EXPECT_EQ(0, d.bytes_received()); | 6535 EXPECT_EQ(0, d.bytes_received()); |
| 6526 } | 6536 } |
| 6527 } | 6537 } |
| 6528 } | 6538 } |
| 6529 } | 6539 } |
| 6530 | 6540 |
| 6531 // Tests TLSv1.1 -> TLSv1 fallback. Verifies that we don't fall back more | 6541 // Tests TLSv1.1 -> TLSv1 fallback. Verifies that we don't fall back more |
| 6532 // than necessary. | 6542 // than necessary. |
| 6533 TEST_F(HTTPSRequestTest, TLSv1Fallback) { | 6543 TEST_F(HTTPSRequestTest, TLSv1Fallback) { |
| 6534 // The OpenSSL library in use may not support TLS 1.1. | 6544 // The OpenSSL library in use may not support TLS 1.1. |
| 6535 #if !defined(USE_OPENSSL) | 6545 #if !defined(USE_OPENSSL) |
| 6536 EXPECT_GT(kDefaultSSLVersionMax, SSL_PROTOCOL_VERSION_TLS1); | 6546 EXPECT_GT(kDefaultSSLVersionMax, SSL_PROTOCOL_VERSION_TLS1); |
| 6537 #endif | 6547 #endif |
| 6538 if (kDefaultSSLVersionMax <= SSL_PROTOCOL_VERSION_TLS1) | 6548 if (kDefaultSSLVersionMax <= SSL_PROTOCOL_VERSION_TLS1) |
| 6539 return; | 6549 return; |
| 6540 | 6550 |
| 6541 SpawnedTestServer::SSLOptions ssl_options( | 6551 SpawnedTestServer::SSLOptions ssl_options( |
| 6542 SpawnedTestServer::SSLOptions::CERT_OK); | 6552 SpawnedTestServer::SSLOptions::CERT_OK); |
| 6543 ssl_options.tls_intolerant = | 6553 ssl_options.tls_intolerant = |
| 6544 SpawnedTestServer::SSLOptions::TLS_INTOLERANT_TLS1_1; | 6554 SpawnedTestServer::SSLOptions::TLS_INTOLERANT_TLS1_1; |
| (...skipping 123 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 6668 // MockHostResolver in order to direct www.google.com to the testserver. | 6678 // MockHostResolver in order to direct www.google.com to the testserver. |
| 6669 // By default, MockHostResolver maps all hosts to 127.0.0.1. | 6679 // By default, MockHostResolver maps all hosts to 127.0.0.1. |
| 6670 | 6680 |
| 6671 MockHostResolver host_resolver; | 6681 MockHostResolver host_resolver; |
| 6672 TestNetworkDelegate network_delegate; // Must outlive URLRequest. | 6682 TestNetworkDelegate network_delegate; // Must outlive URLRequest. |
| 6673 TestURLRequestContext context(true); | 6683 TestURLRequestContext context(true); |
| 6674 context.set_network_delegate(&network_delegate); | 6684 context.set_network_delegate(&network_delegate); |
| 6675 context.set_host_resolver(&host_resolver); | 6685 context.set_host_resolver(&host_resolver); |
| 6676 TransportSecurityState transport_security_state; | 6686 TransportSecurityState transport_security_state; |
| 6677 TransportSecurityState::DomainState domain_state; | 6687 TransportSecurityState::DomainState domain_state; |
| 6678 EXPECT_TRUE(transport_security_state.GetDomainState("www.google.com", true, | 6688 EXPECT_TRUE(transport_security_state.GetDomainState( |
| 6679 &domain_state)); | 6689 "www.google.com", true, &domain_state)); |
| 6680 context.set_transport_security_state(&transport_security_state); | 6690 context.set_transport_security_state(&transport_security_state); |
| 6681 context.Init(); | 6691 context.Init(); |
| 6682 | 6692 |
| 6683 TestDelegate d; | 6693 TestDelegate d; |
| 6684 URLRequest r(GURL(base::StringPrintf("https://www.google.com:%d", | 6694 URLRequest r(GURL(base::StringPrintf("https://www.google.com:%d", |
| 6685 test_server.host_port_pair().port())), | 6695 test_server.host_port_pair().port())), |
| 6686 DEFAULT_PRIORITY, | 6696 DEFAULT_PRIORITY, |
| 6687 &d, | 6697 &d, |
| 6688 &context); | 6698 &context); |
| 6689 | 6699 |
| 6690 r.Start(); | 6700 r.Start(); |
| 6691 EXPECT_TRUE(r.is_pending()); | 6701 EXPECT_TRUE(r.is_pending()); |
| 6692 | 6702 |
| 6693 base::RunLoop().Run(); | 6703 base::RunLoop().Run(); |
| 6694 | 6704 |
| 6695 EXPECT_EQ(1, d.response_started_count()); | 6705 EXPECT_EQ(1, d.response_started_count()); |
| 6696 EXPECT_FALSE(d.received_data_before_response()); | 6706 EXPECT_FALSE(d.received_data_before_response()); |
| 6697 EXPECT_TRUE(d.have_certificate_errors()); | 6707 EXPECT_TRUE(d.have_certificate_errors()); |
| 6698 EXPECT_TRUE(d.certificate_errors_are_fatal()); | 6708 EXPECT_TRUE(d.certificate_errors_are_fatal()); |
| 6699 | 6709 |
| 6700 // Get a fresh copy of the state, and check that it hasn't been updated. | 6710 // Get a fresh copy of the state, and check that it hasn't been updated. |
| 6701 TransportSecurityState::DomainState new_domain_state; | 6711 TransportSecurityState::DomainState new_domain_state; |
| 6702 EXPECT_TRUE(transport_security_state.GetDomainState("www.google.com", true, | 6712 EXPECT_TRUE(transport_security_state.GetDomainState( |
| 6703 &new_domain_state)); | 6713 "www.google.com", true, &new_domain_state)); |
| 6704 EXPECT_EQ(new_domain_state.upgrade_mode, domain_state.upgrade_mode); | 6714 EXPECT_EQ(new_domain_state.upgrade_mode, domain_state.upgrade_mode); |
| 6705 EXPECT_EQ(new_domain_state.sts_include_subdomains, | 6715 EXPECT_EQ(new_domain_state.sts_include_subdomains, |
| 6706 domain_state.sts_include_subdomains); | 6716 domain_state.sts_include_subdomains); |
| 6707 EXPECT_EQ(new_domain_state.pkp_include_subdomains, | 6717 EXPECT_EQ(new_domain_state.pkp_include_subdomains, |
| 6708 domain_state.pkp_include_subdomains); | 6718 domain_state.pkp_include_subdomains); |
| 6709 EXPECT_TRUE(FingerprintsEqual(new_domain_state.static_spki_hashes, | 6719 EXPECT_TRUE(FingerprintsEqual(new_domain_state.static_spki_hashes, |
| 6710 domain_state.static_spki_hashes)); | 6720 domain_state.static_spki_hashes)); |
| 6711 EXPECT_TRUE(FingerprintsEqual(new_domain_state.dynamic_spki_hashes, | 6721 EXPECT_TRUE(FingerprintsEqual(new_domain_state.dynamic_spki_hashes, |
| 6712 domain_state.dynamic_spki_hashes)); | 6722 domain_state.dynamic_spki_hashes)); |
| 6713 EXPECT_TRUE(FingerprintsEqual(new_domain_state.bad_static_spki_hashes, | 6723 EXPECT_TRUE(FingerprintsEqual(new_domain_state.bad_static_spki_hashes, |
| 6714 domain_state.bad_static_spki_hashes)); | 6724 domain_state.bad_static_spki_hashes)); |
| 6715 } | 6725 } |
| 6716 | 6726 |
| 6717 // Make sure HSTS preserves a POST request's method and body. | 6727 // Make sure HSTS preserves a POST request's method and body. |
| 6718 TEST_F(HTTPSRequestTest, HSTSPreservesPosts) { | 6728 TEST_F(HTTPSRequestTest, HSTSPreservesPosts) { |
| 6719 static const char kData[] = "hello world"; | 6729 static const char kData[] = "hello world"; |
| 6720 | 6730 |
| 6721 SpawnedTestServer::SSLOptions ssl_options( | 6731 SpawnedTestServer::SSLOptions ssl_options( |
| 6722 SpawnedTestServer::SSLOptions::CERT_OK); | 6732 SpawnedTestServer::SSLOptions::CERT_OK); |
| 6723 SpawnedTestServer test_server( | 6733 SpawnedTestServer test_server( |
| 6724 SpawnedTestServer::TYPE_HTTPS, | 6734 SpawnedTestServer::TYPE_HTTPS, |
| 6725 ssl_options, | 6735 ssl_options, |
| 6726 base::FilePath(FILE_PATH_LITERAL("net/data/ssl"))); | 6736 base::FilePath(FILE_PATH_LITERAL("net/data/ssl"))); |
| 6727 ASSERT_TRUE(test_server.Start()); | 6737 ASSERT_TRUE(test_server.Start()); |
| 6728 | 6738 |
| 6729 | |
| 6730 // Per spec, TransportSecurityState expects a domain name, rather than an IP | 6739 // Per spec, TransportSecurityState expects a domain name, rather than an IP |
| 6731 // address, so a MockHostResolver is needed to redirect www.somewhere.com to | 6740 // address, so a MockHostResolver is needed to redirect www.somewhere.com to |
| 6732 // the SpawnedTestServer. By default, MockHostResolver maps all hosts | 6741 // the SpawnedTestServer. By default, MockHostResolver maps all hosts |
| 6733 // to 127.0.0.1. | 6742 // to 127.0.0.1. |
| 6734 MockHostResolver host_resolver; | 6743 MockHostResolver host_resolver; |
| 6735 | 6744 |
| 6736 // Force https for www.somewhere.com. | 6745 // Force https for www.somewhere.com. |
| 6737 TransportSecurityState transport_security_state; | 6746 TransportSecurityState transport_security_state; |
| 6738 base::Time expiry = base::Time::Now() + base::TimeDelta::FromDays(1000); | 6747 base::Time expiry = base::Time::Now() + base::TimeDelta::FromDays(1000); |
| 6739 bool include_subdomains = false; | 6748 bool include_subdomains = false; |
| 6740 transport_security_state.AddHSTS("www.somewhere.com", expiry, | 6749 transport_security_state.AddHSTS( |
| 6741 include_subdomains); | 6750 "www.somewhere.com", expiry, include_subdomains); |
| 6742 | 6751 |
| 6743 TestNetworkDelegate network_delegate; // Must outlive URLRequest. | 6752 TestNetworkDelegate network_delegate; // Must outlive URLRequest. |
| 6744 | 6753 |
| 6745 TestURLRequestContext context(true); | 6754 TestURLRequestContext context(true); |
| 6746 context.set_host_resolver(&host_resolver); | 6755 context.set_host_resolver(&host_resolver); |
| 6747 context.set_transport_security_state(&transport_security_state); | 6756 context.set_transport_security_state(&transport_security_state); |
| 6748 context.set_network_delegate(&network_delegate); | 6757 context.set_network_delegate(&network_delegate); |
| 6749 context.Init(); | 6758 context.Init(); |
| 6750 | 6759 |
| 6751 TestDelegate d; | 6760 TestDelegate d; |
| (...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 6799 EXPECT_NE(0, d.bytes_received()); | 6808 EXPECT_NE(0, d.bytes_received()); |
| 6800 EXPECT_EQ(static_cast<int>(SSL_CONNECTION_VERSION_SSL3), | 6809 EXPECT_EQ(static_cast<int>(SSL_CONNECTION_VERSION_SSL3), |
| 6801 SSLConnectionStatusToVersion(r.ssl_info().connection_status)); | 6810 SSLConnectionStatusToVersion(r.ssl_info().connection_status)); |
| 6802 EXPECT_TRUE(r.ssl_info().connection_status & SSL_CONNECTION_VERSION_FALLBACK); | 6811 EXPECT_TRUE(r.ssl_info().connection_status & SSL_CONNECTION_VERSION_FALLBACK); |
| 6803 } | 6812 } |
| 6804 | 6813 |
| 6805 namespace { | 6814 namespace { |
| 6806 | 6815 |
| 6807 class SSLClientAuthTestDelegate : public TestDelegate { | 6816 class SSLClientAuthTestDelegate : public TestDelegate { |
| 6808 public: | 6817 public: |
| 6809 SSLClientAuthTestDelegate() : on_certificate_requested_count_(0) { | 6818 SSLClientAuthTestDelegate() : on_certificate_requested_count_(0) {} |
| 6810 } | |
| 6811 virtual void OnCertificateRequested( | 6819 virtual void OnCertificateRequested( |
| 6812 URLRequest* request, | 6820 URLRequest* request, |
| 6813 SSLCertRequestInfo* cert_request_info) OVERRIDE { | 6821 SSLCertRequestInfo* cert_request_info) OVERRIDE { |
| 6814 on_certificate_requested_count_++; | 6822 on_certificate_requested_count_++; |
| 6815 base::MessageLoop::current()->Quit(); | 6823 base::MessageLoop::current()->Quit(); |
| 6816 } | 6824 } |
| 6817 int on_certificate_requested_count() { | 6825 int on_certificate_requested_count() { |
| 6818 return on_certificate_requested_count_; | 6826 return on_certificate_requested_count_; |
| 6819 } | 6827 } |
| 6828 |
| 6820 private: | 6829 private: |
| 6821 int on_certificate_requested_count_; | 6830 int on_certificate_requested_count_; |
| 6822 }; | 6831 }; |
| 6823 | 6832 |
| 6824 } // namespace | 6833 } // namespace |
| 6825 | 6834 |
| 6826 // TODO(davidben): Test the rest of the code. Specifically, | 6835 // TODO(davidben): Test the rest of the code. Specifically, |
| 6827 // - Filtering which certificates to select. | 6836 // - Filtering which certificates to select. |
| 6828 // - Sending a certificate back. | 6837 // - Sending a certificate back. |
| 6829 // - Getting a certificate request in an SSL renegotiation sending the | 6838 // - Getting a certificate request in an SSL renegotiation sending the |
| (...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 6887 &default_context_); | 6896 &default_context_); |
| 6888 | 6897 |
| 6889 r.Start(); | 6898 r.Start(); |
| 6890 EXPECT_TRUE(r.is_pending()); | 6899 EXPECT_TRUE(r.is_pending()); |
| 6891 | 6900 |
| 6892 base::RunLoop().Run(); | 6901 base::RunLoop().Run(); |
| 6893 | 6902 |
| 6894 EXPECT_EQ(1, d.response_started_count()); | 6903 EXPECT_EQ(1, d.response_started_count()); |
| 6895 } | 6904 } |
| 6896 | 6905 |
| 6897 reinterpret_cast<HttpCache*>(default_context_.http_transaction_factory())-> | 6906 reinterpret_cast<HttpCache*>(default_context_.http_transaction_factory()) |
| 6898 CloseAllConnections(); | 6907 ->CloseAllConnections(); |
| 6899 | 6908 |
| 6900 { | 6909 { |
| 6901 TestDelegate d; | 6910 TestDelegate d; |
| 6902 URLRequest r(test_server.GetURL("ssl-session-cache"), | 6911 URLRequest r(test_server.GetURL("ssl-session-cache"), |
| 6903 DEFAULT_PRIORITY, | 6912 DEFAULT_PRIORITY, |
| 6904 &d, | 6913 &d, |
| 6905 &default_context_); | 6914 &default_context_); |
| 6906 | 6915 |
| 6907 r.Start(); | 6916 r.Start(); |
| 6908 EXPECT_TRUE(r.is_pending()); | 6917 EXPECT_TRUE(r.is_pending()); |
| (...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 6973 params.cert_verifier = default_context_.cert_verifier(); | 6982 params.cert_verifier = default_context_.cert_verifier(); |
| 6974 params.transport_security_state = default_context_.transport_security_state(); | 6983 params.transport_security_state = default_context_.transport_security_state(); |
| 6975 params.proxy_service = default_context_.proxy_service(); | 6984 params.proxy_service = default_context_.proxy_service(); |
| 6976 params.ssl_config_service = default_context_.ssl_config_service(); | 6985 params.ssl_config_service = default_context_.ssl_config_service(); |
| 6977 params.http_auth_handler_factory = | 6986 params.http_auth_handler_factory = |
| 6978 default_context_.http_auth_handler_factory(); | 6987 default_context_.http_auth_handler_factory(); |
| 6979 params.network_delegate = &default_network_delegate_; | 6988 params.network_delegate = &default_network_delegate_; |
| 6980 params.http_server_properties = default_context_.http_server_properties(); | 6989 params.http_server_properties = default_context_.http_server_properties(); |
| 6981 params.ssl_session_cache_shard = "alternate"; | 6990 params.ssl_session_cache_shard = "alternate"; |
| 6982 | 6991 |
| 6983 scoped_ptr<net::HttpCache> cache(new net::HttpCache( | 6992 scoped_ptr<net::HttpCache> cache( |
| 6984 new net::HttpNetworkSession(params), | 6993 new net::HttpCache(new net::HttpNetworkSession(params), |
| 6985 net::HttpCache::DefaultBackend::InMemory(0))); | 6994 net::HttpCache::DefaultBackend::InMemory(0))); |
| 6986 | 6995 |
| 6987 default_context_.set_http_transaction_factory(cache.get()); | 6996 default_context_.set_http_transaction_factory(cache.get()); |
| 6988 | 6997 |
| 6989 { | 6998 { |
| 6990 TestDelegate d; | 6999 TestDelegate d; |
| 6991 URLRequest r(test_server.GetURL("ssl-session-cache"), | 7000 URLRequest r(test_server.GetURL("ssl-session-cache"), |
| 6992 DEFAULT_PRIORITY, | 7001 DEFAULT_PRIORITY, |
| 6993 &d, | 7002 &d, |
| 6994 &default_context_); | 7003 &default_context_); |
| 6995 | 7004 |
| (...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 7065 &default_context_); | 7074 &default_context_); |
| 7066 | 7075 |
| 7067 r.Start(); | 7076 r.Start(); |
| 7068 EXPECT_TRUE(r.is_pending()); | 7077 EXPECT_TRUE(r.is_pending()); |
| 7069 | 7078 |
| 7070 base::RunLoop().Run(); | 7079 base::RunLoop().Run(); |
| 7071 | 7080 |
| 7072 EXPECT_EQ(1, d.response_started_count()); | 7081 EXPECT_EQ(1, d.response_started_count()); |
| 7073 } | 7082 } |
| 7074 | 7083 |
| 7075 reinterpret_cast<HttpCache*>(default_context_.http_transaction_factory())-> | 7084 reinterpret_cast<HttpCache*>(default_context_.http_transaction_factory()) |
| 7076 CloseAllConnections(); | 7085 ->CloseAllConnections(); |
| 7077 | 7086 |
| 7078 // Now change the certificate to be acceptable (so that the response is | 7087 // Now change the certificate to be acceptable (so that the response is |
| 7079 // loaded), and ensure that no session id is presented to the peer. | 7088 // loaded), and ensure that no session id is presented to the peer. |
| 7080 cert_verifier_.set_default_result(net::OK); | 7089 cert_verifier_.set_default_result(net::OK); |
| 7081 { | 7090 { |
| 7082 TestDelegate d; | 7091 TestDelegate d; |
| 7083 URLRequest r(test_server.GetURL("ssl-session-cache"), | 7092 URLRequest r(test_server.GetURL("ssl-session-cache"), |
| 7084 DEFAULT_PRIORITY, | 7093 DEFAULT_PRIORITY, |
| 7085 &d, | 7094 &d, |
| 7086 &default_context_); | 7095 &default_context_); |
| (...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 7146 virtual ~TestSSLConfigService() {} | 7155 virtual ~TestSSLConfigService() {} |
| 7147 | 7156 |
| 7148 private: | 7157 private: |
| 7149 const bool ev_enabled_; | 7158 const bool ev_enabled_; |
| 7150 const bool online_rev_checking_; | 7159 const bool online_rev_checking_; |
| 7151 const bool rev_checking_required_local_anchors_; | 7160 const bool rev_checking_required_local_anchors_; |
| 7152 }; | 7161 }; |
| 7153 | 7162 |
| 7154 // This the fingerprint of the "Testing CA" certificate used by the testserver. | 7163 // This the fingerprint of the "Testing CA" certificate used by the testserver. |
| 7155 // See net/data/ssl/certificates/ocsp-test-root.pem. | 7164 // See net/data/ssl/certificates/ocsp-test-root.pem. |
| 7156 static const SHA1HashValue kOCSPTestCertFingerprint = | 7165 static const SHA1HashValue kOCSPTestCertFingerprint = { |
| 7157 { { 0xf1, 0xad, 0xf6, 0xce, 0x42, 0xac, 0xe7, 0xb4, 0xf4, 0x24, | 7166 {0xf1, 0xad, 0xf6, 0xce, 0x42, 0xac, 0xe7, 0xb4, 0xf4, 0x24, 0xdb, 0x1a, |
| 7158 0xdb, 0x1a, 0xf7, 0xa0, 0x9f, 0x09, 0xa1, 0xea, 0xf1, 0x5c } }; | 7167 0xf7, 0xa0, 0x9f, 0x09, 0xa1, 0xea, 0xf1, 0x5c}}; |
| 7159 | 7168 |
| 7160 // This is the SHA256, SPKI hash of the "Testing CA" certificate used by the | 7169 // This is the SHA256, SPKI hash of the "Testing CA" certificate used by the |
| 7161 // testserver. | 7170 // testserver. |
| 7162 static const SHA256HashValue kOCSPTestCertSPKI = { { | 7171 static const SHA256HashValue kOCSPTestCertSPKI = {{ |
| 7163 0xee, 0xe6, 0x51, 0x2d, 0x4c, 0xfa, 0xf7, 0x3e, | 7172 0xee, 0xe6, 0x51, 0x2d, 0x4c, 0xfa, 0xf7, 0x3e, 0x6c, 0xd8, 0xca, 0x67, |
| 7164 0x6c, 0xd8, 0xca, 0x67, 0xed, 0xb5, 0x5d, 0x49, | 7173 0xed, 0xb5, 0x5d, 0x49, 0x76, 0xe1, 0x52, 0xa7, 0x6e, 0x0e, 0xa0, 0x74, |
| 7165 0x76, 0xe1, 0x52, 0xa7, 0x6e, 0x0e, 0xa0, 0x74, | 7174 0x09, 0x75, 0xe6, 0x23, 0x24, 0xbd, 0x1b, 0x28, |
| 7166 0x09, 0x75, 0xe6, 0x23, 0x24, 0xbd, 0x1b, 0x28, | 7175 }}; |
| 7167 } }; | |
| 7168 | 7176 |
| 7169 // This is the policy OID contained in the certificates that testserver | 7177 // This is the policy OID contained in the certificates that testserver |
| 7170 // generates. | 7178 // generates. |
| 7171 static const char kOCSPTestCertPolicy[] = "1.3.6.1.4.1.11129.2.4.1"; | 7179 static const char kOCSPTestCertPolicy[] = "1.3.6.1.4.1.11129.2.4.1"; |
| 7172 | 7180 |
| 7173 class HTTPSOCSPTest : public HTTPSRequestTest { | 7181 class HTTPSOCSPTest : public HTTPSRequestTest { |
| 7174 public: | 7182 public: |
| 7175 HTTPSOCSPTest() | 7183 HTTPSOCSPTest() |
| 7176 : context_(true), | 7184 : context_(true), |
| 7177 ev_test_policy_( | 7185 ev_test_policy_(new ScopedTestEVPolicy(EVRootCAMetadata::GetInstance(), |
| 7178 new ScopedTestEVPolicy(EVRootCAMetadata::GetInstance(), | 7186 kOCSPTestCertFingerprint, |
| 7179 kOCSPTestCertFingerprint, | 7187 kOCSPTestCertPolicy)) {} |
| 7180 kOCSPTestCertPolicy)) { | |
| 7181 } | |
| 7182 | 7188 |
| 7183 virtual void SetUp() OVERRIDE { | 7189 virtual void SetUp() OVERRIDE { |
| 7184 SetupContext(&context_); | 7190 SetupContext(&context_); |
| 7185 context_.Init(); | 7191 context_.Init(); |
| 7186 | 7192 |
| 7187 scoped_refptr<net::X509Certificate> root_cert = | 7193 scoped_refptr<net::X509Certificate> root_cert = |
| 7188 ImportCertFromFile(GetTestCertsDirectory(), "ocsp-test-root.pem"); | 7194 ImportCertFromFile(GetTestCertsDirectory(), "ocsp-test-root.pem"); |
| 7189 CHECK_NE(static_cast<X509Certificate*>(NULL), root_cert); | 7195 CHECK_NE(static_cast<X509Certificate*>(NULL), root_cert); |
| 7190 test_root_.reset(new ScopedTestRoot(root_cert.get())); | 7196 test_root_.reset(new ScopedTestRoot(root_cert.get())); |
| 7191 | 7197 |
| (...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 7266 } | 7272 } |
| 7267 | 7273 |
| 7268 // SystemUsesChromiumEVMetadata returns true iff the current operating system | 7274 // SystemUsesChromiumEVMetadata returns true iff the current operating system |
| 7269 // uses Chromium's EV metadata (i.e. EVRootCAMetadata). If it does not, then | 7275 // uses Chromium's EV metadata (i.e. EVRootCAMetadata). If it does not, then |
| 7270 // several tests are effected because our testing EV certificate won't be | 7276 // several tests are effected because our testing EV certificate won't be |
| 7271 // recognised as EV. | 7277 // recognised as EV. |
| 7272 static bool SystemUsesChromiumEVMetadata() { | 7278 static bool SystemUsesChromiumEVMetadata() { |
| 7273 #if defined(USE_OPENSSL_CERTS) && !defined(OS_ANDROID) | 7279 #if defined(USE_OPENSSL_CERTS) && !defined(OS_ANDROID) |
| 7274 // http://crbug.com/117478 - OpenSSL does not support EV validation. | 7280 // http://crbug.com/117478 - OpenSSL does not support EV validation. |
| 7275 return false; | 7281 return false; |
| 7276 #elif (defined(OS_MACOSX) && !defined(OS_IOS)) || defined(OS_ANDROID) | 7282 #elif(defined(OS_MACOSX) && !defined(OS_IOS)) || defined(OS_ANDROID) |
| 7277 // On OS X and Android, we use the system to tell us whether a certificate is | 7283 // On OS X and Android, we use the system to tell us whether a certificate is |
| 7278 // EV or not and the system won't recognise our testing root. | 7284 // EV or not and the system won't recognise our testing root. |
| 7279 return false; | 7285 return false; |
| 7280 #else | 7286 #else |
| 7281 return true; | 7287 return true; |
| 7282 #endif | 7288 #endif |
| 7283 } | 7289 } |
| 7284 | 7290 |
| 7285 static bool SystemSupportsOCSP() { | 7291 static bool SystemSupportsOCSP() { |
| 7286 #if defined(USE_OPENSSL) | 7292 #if defined(USE_OPENSSL) |
| (...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 7363 protected: | 7369 protected: |
| 7364 virtual void SetupContext(URLRequestContext* context) OVERRIDE { | 7370 virtual void SetupContext(URLRequestContext* context) OVERRIDE { |
| 7365 context->set_ssl_config_service( | 7371 context->set_ssl_config_service( |
| 7366 new TestSSLConfigService(false /* check for EV */, | 7372 new TestSSLConfigService(false /* check for EV */, |
| 7367 false /* online revocation checking */, | 7373 false /* online revocation checking */, |
| 7368 true /* require rev. checking for local | 7374 true /* require rev. checking for local |
| 7369 anchors */)); | 7375 anchors */)); |
| 7370 } | 7376 } |
| 7371 }; | 7377 }; |
| 7372 | 7378 |
| 7373 | |
| 7374 TEST_F(HTTPSHardFailTest, FailsOnOCSPInvalid) { | 7379 TEST_F(HTTPSHardFailTest, FailsOnOCSPInvalid) { |
| 7375 if (!SystemSupportsOCSP()) { | 7380 if (!SystemSupportsOCSP()) { |
| 7376 LOG(WARNING) << "Skipping test because system doesn't support OCSP"; | 7381 LOG(WARNING) << "Skipping test because system doesn't support OCSP"; |
| 7377 return; | 7382 return; |
| 7378 } | 7383 } |
| 7379 | 7384 |
| 7380 if (!SystemSupportsHardFailRevocationChecking()) { | 7385 if (!SystemSupportsHardFailRevocationChecking()) { |
| 7381 LOG(WARNING) << "Skipping test because system doesn't support hard fail " | 7386 LOG(WARNING) << "Skipping test because system doesn't support hard fail " |
| 7382 << "revocation checking"; | 7387 << "revocation checking"; |
| 7383 return; | 7388 return; |
| 7384 } | 7389 } |
| 7385 | 7390 |
| 7386 SpawnedTestServer::SSLOptions ssl_options( | 7391 SpawnedTestServer::SSLOptions ssl_options( |
| 7387 SpawnedTestServer::SSLOptions::CERT_AUTO); | 7392 SpawnedTestServer::SSLOptions::CERT_AUTO); |
| 7388 ssl_options.ocsp_status = SpawnedTestServer::SSLOptions::OCSP_INVALID; | 7393 ssl_options.ocsp_status = SpawnedTestServer::SSLOptions::OCSP_INVALID; |
| 7389 | 7394 |
| 7390 CertStatus cert_status; | 7395 CertStatus cert_status; |
| 7391 DoConnection(ssl_options, &cert_status); | 7396 DoConnection(ssl_options, &cert_status); |
| 7392 | 7397 |
| 7393 EXPECT_EQ(CERT_STATUS_REVOKED, | 7398 EXPECT_EQ(CERT_STATUS_REVOKED, cert_status & CERT_STATUS_REVOKED); |
| 7394 cert_status & CERT_STATUS_REVOKED); | |
| 7395 | 7399 |
| 7396 // Without a positive OCSP response, we shouldn't show the EV status. | 7400 // Without a positive OCSP response, we shouldn't show the EV status. |
| 7397 EXPECT_TRUE(cert_status & CERT_STATUS_REV_CHECKING_ENABLED); | 7401 EXPECT_TRUE(cert_status & CERT_STATUS_REV_CHECKING_ENABLED); |
| 7398 } | 7402 } |
| 7399 | 7403 |
| 7400 class HTTPSEVCRLSetTest : public HTTPSOCSPTest { | 7404 class HTTPSEVCRLSetTest : public HTTPSOCSPTest { |
| 7401 protected: | 7405 protected: |
| 7402 virtual void SetupContext(URLRequestContext* context) OVERRIDE { | 7406 virtual void SetupContext(URLRequestContext* context) OVERRIDE { |
| 7403 context->set_ssl_config_service( | 7407 context->set_ssl_config_service( |
| 7404 new TestSSLConfigService(true /* check for EV */, | 7408 new TestSSLConfigService(true /* check for EV */, |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 7437 } | 7441 } |
| 7438 | 7442 |
| 7439 SpawnedTestServer::SSLOptions ssl_options( | 7443 SpawnedTestServer::SSLOptions ssl_options( |
| 7440 SpawnedTestServer::SSLOptions::CERT_AUTO); | 7444 SpawnedTestServer::SSLOptions::CERT_AUTO); |
| 7441 ssl_options.ocsp_status = SpawnedTestServer::SSLOptions::OCSP_REVOKED; | 7445 ssl_options.ocsp_status = SpawnedTestServer::SSLOptions::OCSP_REVOKED; |
| 7442 SSLConfigService::SetCRLSet(scoped_refptr<CRLSet>()); | 7446 SSLConfigService::SetCRLSet(scoped_refptr<CRLSet>()); |
| 7443 | 7447 |
| 7444 CertStatus cert_status; | 7448 CertStatus cert_status; |
| 7445 DoConnection(ssl_options, &cert_status); | 7449 DoConnection(ssl_options, &cert_status); |
| 7446 | 7450 |
| 7447 // Currently only works for Windows. When using NSS or OS X, it's not | 7451 // Currently only works for Windows. When using NSS or OS X, it's not |
| 7448 // possible to determine whether the check failed because of actual | 7452 // possible to determine whether the check failed because of actual |
| 7449 // revocation or because there was an OCSP failure. | 7453 // revocation or because there was an OCSP failure. |
| 7450 #if defined(OS_WIN) | 7454 #if defined(OS_WIN) |
| 7451 EXPECT_EQ(CERT_STATUS_REVOKED, cert_status & CERT_STATUS_ALL_ERRORS); | 7455 EXPECT_EQ(CERT_STATUS_REVOKED, cert_status & CERT_STATUS_ALL_ERRORS); |
| 7452 #else | 7456 #else |
| 7453 EXPECT_EQ(0u, cert_status & CERT_STATUS_ALL_ERRORS); | 7457 EXPECT_EQ(0u, cert_status & CERT_STATUS_ALL_ERRORS); |
| 7454 #endif | 7458 #endif |
| 7455 | 7459 |
| 7456 EXPECT_FALSE(cert_status & CERT_STATUS_IS_EV); | 7460 EXPECT_FALSE(cert_status & CERT_STATUS_IS_EV); |
| 7457 EXPECT_EQ(SystemUsesChromiumEVMetadata(), | 7461 EXPECT_EQ(SystemUsesChromiumEVMetadata(), |
| 7458 static_cast<bool>(cert_status & CERT_STATUS_REV_CHECKING_ENABLED)); | 7462 static_cast<bool>(cert_status & CERT_STATUS_REV_CHECKING_ENABLED)); |
| 7459 } | 7463 } |
| (...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 7506 TEST_F(HTTPSEVCRLSetTest, FreshCRLSetCovered) { | 7510 TEST_F(HTTPSEVCRLSetTest, FreshCRLSetCovered) { |
| 7507 if (!SystemSupportsOCSP()) { | 7511 if (!SystemSupportsOCSP()) { |
| 7508 LOG(WARNING) << "Skipping test because system doesn't support OCSP"; | 7512 LOG(WARNING) << "Skipping test because system doesn't support OCSP"; |
| 7509 return; | 7513 return; |
| 7510 } | 7514 } |
| 7511 | 7515 |
| 7512 SpawnedTestServer::SSLOptions ssl_options( | 7516 SpawnedTestServer::SSLOptions ssl_options( |
| 7513 SpawnedTestServer::SSLOptions::CERT_AUTO); | 7517 SpawnedTestServer::SSLOptions::CERT_AUTO); |
| 7514 ssl_options.ocsp_status = SpawnedTestServer::SSLOptions::OCSP_INVALID; | 7518 ssl_options.ocsp_status = SpawnedTestServer::SSLOptions::OCSP_INVALID; |
| 7515 SSLConfigService::SetCRLSet( | 7519 SSLConfigService::SetCRLSet( |
| 7516 scoped_refptr<CRLSet>(CRLSet::ForTesting( | 7520 scoped_refptr<CRLSet>(CRLSet::ForTesting(false, &kOCSPTestCertSPKI, ""))); |
| 7517 false, &kOCSPTestCertSPKI, ""))); | |
| 7518 | 7521 |
| 7519 CertStatus cert_status; | 7522 CertStatus cert_status; |
| 7520 DoConnection(ssl_options, &cert_status); | 7523 DoConnection(ssl_options, &cert_status); |
| 7521 | 7524 |
| 7522 // With a fresh CRLSet that covers the issuing certificate, we shouldn't do a | 7525 // With a fresh CRLSet that covers the issuing certificate, we shouldn't do a |
| 7523 // revocation check for EV. | 7526 // revocation check for EV. |
| 7524 EXPECT_EQ(0u, cert_status & CERT_STATUS_ALL_ERRORS); | 7527 EXPECT_EQ(0u, cert_status & CERT_STATUS_ALL_ERRORS); |
| 7525 EXPECT_EQ(SystemUsesChromiumEVMetadata(), | 7528 EXPECT_EQ(SystemUsesChromiumEVMetadata(), |
| 7526 static_cast<bool>(cert_status & CERT_STATUS_IS_EV)); | 7529 static_cast<bool>(cert_status & CERT_STATUS_IS_EV)); |
| 7527 EXPECT_FALSE( | 7530 EXPECT_FALSE( |
| (...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 7613 TEST_F(HTTPSCRLSetTest, CRLSetRevoked) { | 7616 TEST_F(HTTPSCRLSetTest, CRLSetRevoked) { |
| 7614 #if defined(USE_OPENSSL) | 7617 #if defined(USE_OPENSSL) |
| 7615 LOG(WARNING) << "Skipping test because system doesn't support CRLSets"; | 7618 LOG(WARNING) << "Skipping test because system doesn't support CRLSets"; |
| 7616 return; | 7619 return; |
| 7617 #endif | 7620 #endif |
| 7618 | 7621 |
| 7619 SpawnedTestServer::SSLOptions ssl_options( | 7622 SpawnedTestServer::SSLOptions ssl_options( |
| 7620 SpawnedTestServer::SSLOptions::CERT_AUTO); | 7623 SpawnedTestServer::SSLOptions::CERT_AUTO); |
| 7621 ssl_options.ocsp_status = SpawnedTestServer::SSLOptions::OCSP_OK; | 7624 ssl_options.ocsp_status = SpawnedTestServer::SSLOptions::OCSP_OK; |
| 7622 ssl_options.cert_serial = 10; | 7625 ssl_options.cert_serial = 10; |
| 7623 SSLConfigService::SetCRLSet( | 7626 SSLConfigService::SetCRLSet(scoped_refptr<CRLSet>( |
| 7624 scoped_refptr<CRLSet>(CRLSet::ForTesting( | 7627 CRLSet::ForTesting(false, &kOCSPTestCertSPKI, "\x0a"))); |
| 7625 false, &kOCSPTestCertSPKI, "\x0a"))); | |
| 7626 | 7628 |
| 7627 CertStatus cert_status = 0; | 7629 CertStatus cert_status = 0; |
| 7628 DoConnection(ssl_options, &cert_status); | 7630 DoConnection(ssl_options, &cert_status); |
| 7629 | 7631 |
| 7630 // If the certificate is recorded as revoked in the CRLSet, that should be | 7632 // If the certificate is recorded as revoked in the CRLSet, that should be |
| 7631 // reflected without online revocation checking. | 7633 // reflected without online revocation checking. |
| 7632 EXPECT_EQ(CERT_STATUS_REVOKED, cert_status & CERT_STATUS_ALL_ERRORS); | 7634 EXPECT_EQ(CERT_STATUS_REVOKED, cert_status & CERT_STATUS_ALL_ERRORS); |
| 7633 EXPECT_FALSE(cert_status & CERT_STATUS_IS_EV); | 7635 EXPECT_FALSE(cert_status & CERT_STATUS_IS_EV); |
| 7634 EXPECT_FALSE( | 7636 EXPECT_FALSE( |
| 7635 static_cast<bool>(cert_status & CERT_STATUS_REV_CHECKING_ENABLED)); | 7637 static_cast<bool>(cert_status & CERT_STATUS_REV_CHECKING_ENABLED)); |
| 7636 } | 7638 } |
| 7637 #endif // !defined(OS_IOS) | 7639 #endif // !defined(OS_IOS) |
| 7638 | 7640 |
| 7639 #if !defined(DISABLE_FTP_SUPPORT) | 7641 #if !defined(DISABLE_FTP_SUPPORT) |
| 7640 class URLRequestTestFTP : public URLRequestTest { | 7642 class URLRequestTestFTP : public URLRequestTest { |
| 7641 public: | 7643 public: |
| 7642 URLRequestTestFTP() | 7644 URLRequestTestFTP() |
| 7643 : test_server_(SpawnedTestServer::TYPE_FTP, SpawnedTestServer::kLocalhost, | 7645 : test_server_(SpawnedTestServer::TYPE_FTP, |
| 7644 base::FilePath()) { | 7646 SpawnedTestServer::kLocalhost, |
| 7645 } | 7647 base::FilePath()) {} |
| 7646 | 7648 |
| 7647 protected: | 7649 protected: |
| 7648 SpawnedTestServer test_server_; | 7650 SpawnedTestServer test_server_; |
| 7649 }; | 7651 }; |
| 7650 | 7652 |
| 7651 // Make sure an FTP request using an unsafe ports fails. | 7653 // Make sure an FTP request using an unsafe ports fails. |
| 7652 TEST_F(URLRequestTestFTP, UnsafePort) { | 7654 TEST_F(URLRequestTestFTP, UnsafePort) { |
| 7653 ASSERT_TRUE(test_server_.Start()); | 7655 ASSERT_TRUE(test_server_.Start()); |
| 7654 | 7656 |
| 7655 URLRequestJobFactoryImpl job_factory; | 7657 URLRequestJobFactoryImpl job_factory; |
| 7656 FtpNetworkLayer ftp_transaction_factory(default_context_.host_resolver()); | 7658 FtpNetworkLayer ftp_transaction_factory(default_context_.host_resolver()); |
| 7657 | 7659 |
| 7658 GURL url("ftp://127.0.0.1:7"); | 7660 GURL url("ftp://127.0.0.1:7"); |
| 7659 job_factory.SetProtocolHandler( | 7661 job_factory.SetProtocolHandler( |
| 7660 "ftp", | 7662 "ftp", new FtpProtocolHandler(&ftp_transaction_factory)); |
| 7661 new FtpProtocolHandler(&ftp_transaction_factory)); | |
| 7662 default_context_.set_job_factory(&job_factory); | 7663 default_context_.set_job_factory(&job_factory); |
| 7663 | 7664 |
| 7664 TestDelegate d; | 7665 TestDelegate d; |
| 7665 { | 7666 { |
| 7666 URLRequest r(url, DEFAULT_PRIORITY, &d, &default_context_); | 7667 URLRequest r(url, DEFAULT_PRIORITY, &d, &default_context_); |
| 7667 r.Start(); | 7668 r.Start(); |
| 7668 EXPECT_TRUE(r.is_pending()); | 7669 EXPECT_TRUE(r.is_pending()); |
| 7669 | 7670 |
| 7670 base::RunLoop().Run(); | 7671 base::RunLoop().Run(); |
| 7671 | 7672 |
| (...skipping 322 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 7994 | 7995 |
| 7995 EXPECT_FALSE(r.is_pending()); | 7996 EXPECT_FALSE(r.is_pending()); |
| 7996 EXPECT_EQ(1, d->response_started_count()); | 7997 EXPECT_EQ(1, d->response_started_count()); |
| 7997 EXPECT_FALSE(d->received_data_before_response()); | 7998 EXPECT_FALSE(d->received_data_before_response()); |
| 7998 EXPECT_EQ(d->bytes_received(), static_cast<int>(file_size)); | 7999 EXPECT_EQ(d->bytes_received(), static_cast<int>(file_size)); |
| 7999 } | 8000 } |
| 8000 } | 8001 } |
| 8001 #endif // !defined(DISABLE_FTP_SUPPORT) | 8002 #endif // !defined(DISABLE_FTP_SUPPORT) |
| 8002 | 8003 |
| 8003 } // namespace net | 8004 } // namespace net |
| OLD | NEW |