| OLD | NEW |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 <shlobj.h> | 8 #include <shlobj.h> |
| 9 #include <windows.h> | 9 #include <windows.h> |
| 10 #elif defined(USE_NSS) | 10 #elif defined(USE_NSS) |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 46 #include "net/url_request/url_request.h" | 46 #include "net/url_request/url_request.h" |
| 47 #include "net/url_request/url_request_file_dir_job.h" | 47 #include "net/url_request/url_request_file_dir_job.h" |
| 48 #include "net/url_request/url_request_http_job.h" | 48 #include "net/url_request/url_request_http_job.h" |
| 49 #include "net/url_request/url_request_test_job.h" | 49 #include "net/url_request/url_request_test_job.h" |
| 50 #include "net/url_request/url_request_test_util.h" | 50 #include "net/url_request/url_request_test_util.h" |
| 51 #include "testing/gtest/include/gtest/gtest.h" | 51 #include "testing/gtest/include/gtest/gtest.h" |
| 52 #include "testing/platform_test.h" | 52 #include "testing/platform_test.h" |
| 53 | 53 |
| 54 using base::Time; | 54 using base::Time; |
| 55 | 55 |
| 56 namespace net { |
| 57 |
| 56 namespace { | 58 namespace { |
| 57 | 59 |
| 58 const string16 kChrome(ASCIIToUTF16("chrome")); | 60 const string16 kChrome(ASCIIToUTF16("chrome")); |
| 59 const string16 kSecret(ASCIIToUTF16("secret")); | 61 const string16 kSecret(ASCIIToUTF16("secret")); |
| 60 const string16 kUser(ASCIIToUTF16("user")); | 62 const string16 kUser(ASCIIToUTF16("user")); |
| 61 | 63 |
| 62 base::StringPiece TestNetResourceProvider(int key) { | 64 base::StringPiece TestNetResourceProvider(int key) { |
| 63 return "header"; | 65 return "header"; |
| 64 } | 66 } |
| 65 | 67 |
| (...skipping 16 matching lines...) Expand all Loading... |
| 82 srand(seed); | 84 srand(seed); |
| 83 } | 85 } |
| 84 | 86 |
| 85 for (size_t i = 0; i < len; i++) { | 87 for (size_t i = 0; i < len; i++) { |
| 86 buffer[i] = static_cast<char>(rand()); | 88 buffer[i] = static_cast<char>(rand()); |
| 87 if (!buffer[i]) | 89 if (!buffer[i]) |
| 88 buffer[i] = 'g'; | 90 buffer[i] = 'g'; |
| 89 } | 91 } |
| 90 } | 92 } |
| 91 | 93 |
| 92 scoped_refptr<net::UploadData> CreateSimpleUploadData(const char* data) { | 94 scoped_refptr<UploadData> CreateSimpleUploadData(const char* data) { |
| 93 scoped_refptr<net::UploadData> upload(new net::UploadData); | 95 scoped_refptr<UploadData> upload(new UploadData); |
| 94 upload->AppendBytes(data, strlen(data)); | 96 upload->AppendBytes(data, strlen(data)); |
| 95 return upload; | 97 return upload; |
| 96 } | 98 } |
| 97 | 99 |
| 98 // Verify that the SSLInfo of a successful SSL connection has valid values. | 100 // Verify that the SSLInfo of a successful SSL connection has valid values. |
| 99 void CheckSSLInfo(const net::SSLInfo& ssl_info) { | 101 void CheckSSLInfo(const SSLInfo& ssl_info) { |
| 100 // Allow ChromeFrame fake SSLInfo to get through. | 102 // Allow ChromeFrame fake SSLInfo to get through. |
| 101 if (ssl_info.cert.get() && | 103 if (ssl_info.cert.get() && |
| 102 ssl_info.cert.get()->issuer().GetDisplayName() == "Chrome Internal") { | 104 ssl_info.cert.get()->issuer().GetDisplayName() == "Chrome Internal") { |
| 103 // -1 means unknown. | 105 // -1 means unknown. |
| 104 EXPECT_EQ(ssl_info.security_bits, -1); | 106 EXPECT_EQ(ssl_info.security_bits, -1); |
| 105 return; | 107 return; |
| 106 } | 108 } |
| 107 | 109 |
| 108 // -1 means unknown. 0 means no encryption. | 110 // -1 means unknown. 0 means no encryption. |
| 109 EXPECT_GT(ssl_info.security_bits, 0); | 111 EXPECT_GT(ssl_info.security_bits, 0); |
| 110 | 112 |
| 111 // The cipher suite TLS_NULL_WITH_NULL_NULL (0) must not be negotiated. | 113 // The cipher suite TLS_NULL_WITH_NULL_NULL (0) must not be negotiated. |
| 112 int cipher_suite = net::SSLConnectionStatusToCipherSuite( | 114 int cipher_suite = SSLConnectionStatusToCipherSuite( |
| 113 ssl_info.connection_status); | 115 ssl_info.connection_status); |
| 114 EXPECT_NE(0, cipher_suite); | 116 EXPECT_NE(0, cipher_suite); |
| 115 } | 117 } |
| 116 | 118 |
| 117 } // namespace | 119 } // namespace |
| 118 | 120 |
| 119 // Inherit PlatformTest since we require the autorelease pool on Mac OS X.f | 121 // Inherit PlatformTest since we require the autorelease pool on Mac OS X.f |
| 120 class URLRequestTest : public PlatformTest { | 122 class URLRequestTest : public PlatformTest { |
| 121 public: | 123 public: |
| 122 static void SetUpTestCase() { | 124 static void SetUpTestCase() { |
| 123 net::URLRequest::AllowFileAccess(); | 125 URLRequest::AllowFileAccess(); |
| 124 } | 126 } |
| 125 }; | 127 }; |
| 126 | 128 |
| 127 class URLRequestTestHTTP : public URLRequestTest { | 129 class URLRequestTestHTTP : public URLRequestTest { |
| 128 public: | 130 public: |
| 129 URLRequestTestHTTP() | 131 URLRequestTestHTTP() |
| 130 : test_server_(net::TestServer::TYPE_HTTP, | 132 : test_server_(TestServer::TYPE_HTTP, |
| 131 FilePath(FILE_PATH_LITERAL( | 133 FilePath(FILE_PATH_LITERAL( |
| 132 "net/data/url_request_unittest"))) { | 134 "net/data/url_request_unittest"))) { |
| 133 } | 135 } |
| 134 | 136 |
| 135 protected: | 137 protected: |
| 136 void HTTPUploadDataOperationTest(const std::string& method) { | 138 void HTTPUploadDataOperationTest(const std::string& method) { |
| 137 const int kMsgSize = 20000; // multiple of 10 | 139 const int kMsgSize = 20000; // multiple of 10 |
| 138 const int kIterations = 50; | 140 const int kIterations = 50; |
| 139 char *uploadBytes = new char[kMsgSize+1]; | 141 char *uploadBytes = new char[kMsgSize+1]; |
| 140 char *ptr = uploadBytes; | 142 char *ptr = uploadBytes; |
| 141 char marker = 'a'; | 143 char marker = 'a'; |
| 142 for (int idx = 0; idx < kMsgSize/10; idx++) { | 144 for (int idx = 0; idx < kMsgSize/10; idx++) { |
| 143 memcpy(ptr, "----------", 10); | 145 memcpy(ptr, "----------", 10); |
| 144 ptr += 10; | 146 ptr += 10; |
| 145 if (idx % 100 == 0) { | 147 if (idx % 100 == 0) { |
| 146 ptr--; | 148 ptr--; |
| 147 *ptr++ = marker; | 149 *ptr++ = marker; |
| 148 if (++marker > 'z') | 150 if (++marker > 'z') |
| 149 marker = 'a'; | 151 marker = 'a'; |
| 150 } | 152 } |
| 151 } | 153 } |
| 152 uploadBytes[kMsgSize] = '\0'; | 154 uploadBytes[kMsgSize] = '\0'; |
| 153 | 155 |
| 154 scoped_refptr<net::URLRequestContext> context(new TestURLRequestContext()); | 156 scoped_refptr<URLRequestContext> context(new TestURLRequestContext()); |
| 155 | 157 |
| 156 for (int i = 0; i < kIterations; ++i) { | 158 for (int i = 0; i < kIterations; ++i) { |
| 157 TestDelegate d; | 159 TestDelegate d; |
| 158 net::URLRequest r(test_server_.GetURL("echo"), &d); | 160 URLRequest r(test_server_.GetURL("echo"), &d); |
| 159 r.set_context(context); | 161 r.set_context(context); |
| 160 r.set_method(method.c_str()); | 162 r.set_method(method.c_str()); |
| 161 | 163 |
| 162 r.AppendBytesToUpload(uploadBytes, kMsgSize); | 164 r.AppendBytesToUpload(uploadBytes, kMsgSize); |
| 163 | 165 |
| 164 r.Start(); | 166 r.Start(); |
| 165 EXPECT_TRUE(r.is_pending()); | 167 EXPECT_TRUE(r.is_pending()); |
| 166 | 168 |
| 167 MessageLoop::current()->Run(); | 169 MessageLoop::current()->Run(); |
| 168 | 170 |
| (...skipping 25 matching lines...) Expand all Loading... |
| 194 ASSERT_EQ(1, d->response_started_count()) << "request failed: " << | 196 ASSERT_EQ(1, d->response_started_count()) << "request failed: " << |
| 195 (int) r->status().status() << ", os error: " << r->status().os_error(); | 197 (int) r->status().status() << ", os error: " << r->status().os_error(); |
| 196 | 198 |
| 197 EXPECT_FALSE(d->received_data_before_response()); | 199 EXPECT_FALSE(d->received_data_before_response()); |
| 198 | 200 |
| 199 ASSERT_EQ(strlen(expected_data), static_cast<size_t>(d->bytes_received())); | 201 ASSERT_EQ(strlen(expected_data), static_cast<size_t>(d->bytes_received())); |
| 200 EXPECT_EQ(0, memcmp(d->data_received().c_str(), expected_data, | 202 EXPECT_EQ(0, memcmp(d->data_received().c_str(), expected_data, |
| 201 strlen(expected_data))); | 203 strlen(expected_data))); |
| 202 } | 204 } |
| 203 | 205 |
| 204 net::TestServer test_server_; | 206 TestServer test_server_; |
| 205 }; | 207 }; |
| 206 | 208 |
| 207 // In this unit test, we're using the HTTPTestServer as a proxy server and | 209 // In this unit test, we're using the HTTPTestServer as a proxy server and |
| 208 // issuing a CONNECT request with the magic host name "www.redirect.com". | 210 // issuing a CONNECT request with the magic host name "www.redirect.com". |
| 209 // The HTTPTestServer will return a 302 response, which we should not | 211 // The HTTPTestServer will return a 302 response, which we should not |
| 210 // follow. | 212 // follow. |
| 211 TEST_F(URLRequestTestHTTP, ProxyTunnelRedirectTest) { | 213 TEST_F(URLRequestTestHTTP, ProxyTunnelRedirectTest) { |
| 212 ASSERT_TRUE(test_server_.Start()); | 214 ASSERT_TRUE(test_server_.Start()); |
| 213 | 215 |
| 214 TestDelegate d; | 216 TestDelegate d; |
| 215 { | 217 { |
| 216 net::URLRequest r(GURL("https://www.redirect.com/"), &d); | 218 URLRequest r(GURL("https://www.redirect.com/"), &d); |
| 217 r.set_context( | 219 r.set_context( |
| 218 new TestURLRequestContext(test_server_.host_port_pair().ToString())); | 220 new TestURLRequestContext(test_server_.host_port_pair().ToString())); |
| 219 | 221 |
| 220 r.Start(); | 222 r.Start(); |
| 221 EXPECT_TRUE(r.is_pending()); | 223 EXPECT_TRUE(r.is_pending()); |
| 222 | 224 |
| 223 MessageLoop::current()->Run(); | 225 MessageLoop::current()->Run(); |
| 224 | 226 |
| 225 EXPECT_EQ(net::URLRequestStatus::FAILED, r.status().status()); | 227 EXPECT_EQ(URLRequestStatus::FAILED, r.status().status()); |
| 226 EXPECT_EQ(net::ERR_TUNNEL_CONNECTION_FAILED, r.status().os_error()); | 228 EXPECT_EQ(ERR_TUNNEL_CONNECTION_FAILED, r.status().os_error()); |
| 227 EXPECT_EQ(1, d.response_started_count()); | 229 EXPECT_EQ(1, d.response_started_count()); |
| 228 // We should not have followed the redirect. | 230 // We should not have followed the redirect. |
| 229 EXPECT_EQ(0, d.received_redirect_count()); | 231 EXPECT_EQ(0, d.received_redirect_count()); |
| 230 } | 232 } |
| 231 } | 233 } |
| 232 | 234 |
| 233 // This is the same as the previous test, but checks that the network delegate | 235 // This is the same as the previous test, but checks that the network delegate |
| 234 // registers the error. | 236 // registers the error. |
| 235 TEST_F(URLRequestTestHTTP, NetworkDelegateTunnelConnectionFailed) { | 237 TEST_F(URLRequestTestHTTP, NetworkDelegateTunnelConnectionFailed) { |
| 236 ASSERT_TRUE(test_server_.Start()); | 238 ASSERT_TRUE(test_server_.Start()); |
| 237 | 239 |
| 238 TestDelegate d; | 240 TestDelegate d; |
| 239 { | 241 { |
| 240 net::URLRequest r(GURL("https://www.redirect.com/"), &d); | 242 URLRequest r(GURL("https://www.redirect.com/"), &d); |
| 241 scoped_refptr<TestURLRequestContext> context( | 243 scoped_refptr<TestURLRequestContext> context( |
| 242 new TestURLRequestContext(test_server_.host_port_pair().ToString())); | 244 new TestURLRequestContext(test_server_.host_port_pair().ToString())); |
| 243 TestNetworkDelegate network_delegate; | 245 TestNetworkDelegate network_delegate; |
| 244 context->set_network_delegate(&network_delegate); | 246 context->set_network_delegate(&network_delegate); |
| 245 r.set_context(context); | 247 r.set_context(context); |
| 246 | 248 |
| 247 r.Start(); | 249 r.Start(); |
| 248 EXPECT_TRUE(r.is_pending()); | 250 EXPECT_TRUE(r.is_pending()); |
| 249 | 251 |
| 250 MessageLoop::current()->Run(); | 252 MessageLoop::current()->Run(); |
| 251 | 253 |
| 252 EXPECT_EQ(net::URLRequestStatus::FAILED, r.status().status()); | 254 EXPECT_EQ(URLRequestStatus::FAILED, r.status().status()); |
| 253 EXPECT_EQ(net::ERR_TUNNEL_CONNECTION_FAILED, r.status().os_error()); | 255 EXPECT_EQ(ERR_TUNNEL_CONNECTION_FAILED, r.status().os_error()); |
| 254 EXPECT_EQ(1, d.response_started_count()); | 256 EXPECT_EQ(1, d.response_started_count()); |
| 255 // We should not have followed the redirect. | 257 // We should not have followed the redirect. |
| 256 EXPECT_EQ(0, d.received_redirect_count()); | 258 EXPECT_EQ(0, d.received_redirect_count()); |
| 257 | 259 |
| 258 EXPECT_EQ(1, network_delegate.error_count()); | 260 EXPECT_EQ(1, network_delegate.error_count()); |
| 259 EXPECT_EQ(net::ERR_TUNNEL_CONNECTION_FAILED, | 261 EXPECT_EQ(ERR_TUNNEL_CONNECTION_FAILED, |
| 260 network_delegate.last_os_error()); | 262 network_delegate.last_os_error()); |
| 261 } | 263 } |
| 262 } | 264 } |
| 263 | 265 |
| 264 // In this unit test, we're using the HTTPTestServer as a proxy server and | 266 // In this unit test, we're using the HTTPTestServer as a proxy server and |
| 265 // issuing a CONNECT request with the magic host name "www.server-auth.com". | 267 // issuing a CONNECT request with the magic host name "www.server-auth.com". |
| 266 // The HTTPTestServer will return a 401 response, which we should balk at. | 268 // The HTTPTestServer will return a 401 response, which we should balk at. |
| 267 TEST_F(URLRequestTestHTTP, UnexpectedServerAuthTest) { | 269 TEST_F(URLRequestTestHTTP, UnexpectedServerAuthTest) { |
| 268 ASSERT_TRUE(test_server_.Start()); | 270 ASSERT_TRUE(test_server_.Start()); |
| 269 | 271 |
| 270 TestDelegate d; | 272 TestDelegate d; |
| 271 { | 273 { |
| 272 net::URLRequest r(GURL("https://www.server-auth.com/"), &d); | 274 URLRequest r(GURL("https://www.server-auth.com/"), &d); |
| 273 r.set_context( | 275 r.set_context( |
| 274 new TestURLRequestContext(test_server_.host_port_pair().ToString())); | 276 new TestURLRequestContext(test_server_.host_port_pair().ToString())); |
| 275 | 277 |
| 276 r.Start(); | 278 r.Start(); |
| 277 EXPECT_TRUE(r.is_pending()); | 279 EXPECT_TRUE(r.is_pending()); |
| 278 | 280 |
| 279 MessageLoop::current()->Run(); | 281 MessageLoop::current()->Run(); |
| 280 | 282 |
| 281 EXPECT_EQ(net::URLRequestStatus::FAILED, r.status().status()); | 283 EXPECT_EQ(URLRequestStatus::FAILED, r.status().status()); |
| 282 EXPECT_EQ(net::ERR_TUNNEL_CONNECTION_FAILED, r.status().os_error()); | 284 EXPECT_EQ(ERR_TUNNEL_CONNECTION_FAILED, r.status().os_error()); |
| 283 } | 285 } |
| 284 } | 286 } |
| 285 | 287 |
| 286 TEST_F(URLRequestTestHTTP, GetTest_NoCache) { | 288 TEST_F(URLRequestTestHTTP, GetTest_NoCache) { |
| 287 ASSERT_TRUE(test_server_.Start()); | 289 ASSERT_TRUE(test_server_.Start()); |
| 288 | 290 |
| 289 TestDelegate d; | 291 TestDelegate d; |
| 290 { | 292 { |
| 291 TestURLRequest r(test_server_.GetURL(""), &d); | 293 TestURLRequest r(test_server_.GetURL(""), &d); |
| 292 | 294 |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 325 EXPECT_EQ(test_server_.host_port_pair().host(), | 327 EXPECT_EQ(test_server_.host_port_pair().host(), |
| 326 r.GetSocketAddress().host()); | 328 r.GetSocketAddress().host()); |
| 327 EXPECT_EQ(test_server_.host_port_pair().port(), | 329 EXPECT_EQ(test_server_.host_port_pair().port(), |
| 328 r.GetSocketAddress().port()); | 330 r.GetSocketAddress().port()); |
| 329 } | 331 } |
| 330 } | 332 } |
| 331 | 333 |
| 332 TEST_F(URLRequestTestHTTP, HTTPSToHTTPRedirectNoRefererTest) { | 334 TEST_F(URLRequestTestHTTP, HTTPSToHTTPRedirectNoRefererTest) { |
| 333 ASSERT_TRUE(test_server_.Start()); | 335 ASSERT_TRUE(test_server_.Start()); |
| 334 | 336 |
| 335 net::TestServer https_test_server( | 337 TestServer https_test_server( |
| 336 net::TestServer::TYPE_HTTPS, FilePath(FILE_PATH_LITERAL("net/data/ssl"))); | 338 TestServer::TYPE_HTTPS, FilePath(FILE_PATH_LITERAL("net/data/ssl"))); |
| 337 ASSERT_TRUE(https_test_server.Start()); | 339 ASSERT_TRUE(https_test_server.Start()); |
| 338 | 340 |
| 339 // An https server is sent a request with an https referer, | 341 // An https server is sent a request with an https referer, |
| 340 // and responds with a redirect to an http url. The http | 342 // and responds with a redirect to an http url. The http |
| 341 // server should not be sent the referer. | 343 // server should not be sent the referer. |
| 342 GURL http_destination = test_server_.GetURL(""); | 344 GURL http_destination = test_server_.GetURL(""); |
| 343 TestDelegate d; | 345 TestDelegate d; |
| 344 TestURLRequest req(https_test_server.GetURL( | 346 TestURLRequest req(https_test_server.GetURL( |
| 345 "server-redirect?" + http_destination.spec()), &d); | 347 "server-redirect?" + http_destination.spec()), &d); |
| 346 req.set_referrer("https://www.referrer.com/"); | 348 req.set_referrer("https://www.referrer.com/"); |
| 347 req.Start(); | 349 req.Start(); |
| 348 MessageLoop::current()->Run(); | 350 MessageLoop::current()->Run(); |
| 349 | 351 |
| 350 EXPECT_EQ(1, d.response_started_count()); | 352 EXPECT_EQ(1, d.response_started_count()); |
| 351 EXPECT_EQ(1, d.received_redirect_count()); | 353 EXPECT_EQ(1, d.received_redirect_count()); |
| 352 EXPECT_EQ(http_destination, req.url()); | 354 EXPECT_EQ(http_destination, req.url()); |
| 353 EXPECT_EQ(std::string(), req.referrer()); | 355 EXPECT_EQ(std::string(), req.referrer()); |
| 354 } | 356 } |
| 355 | 357 |
| 356 class HTTPSRequestTest : public testing::Test { | 358 class HTTPSRequestTest : public testing::Test { |
| 357 }; | 359 }; |
| 358 | 360 |
| 359 TEST_F(HTTPSRequestTest, HTTPSGetTest) { | 361 TEST_F(HTTPSRequestTest, HTTPSGetTest) { |
| 360 net::TestServer test_server(net::TestServer::TYPE_HTTPS, | 362 TestServer test_server(TestServer::TYPE_HTTPS, |
| 361 FilePath(FILE_PATH_LITERAL("net/data/ssl"))); | 363 FilePath(FILE_PATH_LITERAL("net/data/ssl"))); |
| 362 ASSERT_TRUE(test_server.Start()); | 364 ASSERT_TRUE(test_server.Start()); |
| 363 | 365 |
| 364 TestDelegate d; | 366 TestDelegate d; |
| 365 { | 367 { |
| 366 TestURLRequest r(test_server.GetURL(""), &d); | 368 TestURLRequest r(test_server.GetURL(""), &d); |
| 367 | 369 |
| 368 r.Start(); | 370 r.Start(); |
| 369 EXPECT_TRUE(r.is_pending()); | 371 EXPECT_TRUE(r.is_pending()); |
| 370 | 372 |
| 371 MessageLoop::current()->Run(); | 373 MessageLoop::current()->Run(); |
| 372 | 374 |
| 373 EXPECT_EQ(1, d.response_started_count()); | 375 EXPECT_EQ(1, d.response_started_count()); |
| 374 EXPECT_FALSE(d.received_data_before_response()); | 376 EXPECT_FALSE(d.received_data_before_response()); |
| 375 EXPECT_NE(0, d.bytes_received()); | 377 EXPECT_NE(0, d.bytes_received()); |
| 376 CheckSSLInfo(r.ssl_info()); | 378 CheckSSLInfo(r.ssl_info()); |
| 377 EXPECT_EQ(test_server.host_port_pair().host(), | 379 EXPECT_EQ(test_server.host_port_pair().host(), |
| 378 r.GetSocketAddress().host()); | 380 r.GetSocketAddress().host()); |
| 379 EXPECT_EQ(test_server.host_port_pair().port(), | 381 EXPECT_EQ(test_server.host_port_pair().port(), |
| 380 r.GetSocketAddress().port()); | 382 r.GetSocketAddress().port()); |
| 381 } | 383 } |
| 382 } | 384 } |
| 383 | 385 |
| 384 TEST_F(HTTPSRequestTest, HTTPSMismatchedTest) { | 386 TEST_F(HTTPSRequestTest, HTTPSMismatchedTest) { |
| 385 net::TestServer::HTTPSOptions https_options( | 387 TestServer::HTTPSOptions https_options( |
| 386 net::TestServer::HTTPSOptions::CERT_MISMATCHED_NAME); | 388 TestServer::HTTPSOptions::CERT_MISMATCHED_NAME); |
| 387 net::TestServer test_server(https_options, | 389 TestServer test_server(https_options, |
| 388 FilePath(FILE_PATH_LITERAL("net/data/ssl"))); | 390 FilePath(FILE_PATH_LITERAL("net/data/ssl"))); |
| 389 ASSERT_TRUE(test_server.Start()); | 391 ASSERT_TRUE(test_server.Start()); |
| 390 | 392 |
| 391 bool err_allowed = true; | 393 bool err_allowed = true; |
| 392 for (int i = 0; i < 2 ; i++, err_allowed = !err_allowed) { | 394 for (int i = 0; i < 2 ; i++, err_allowed = !err_allowed) { |
| 393 TestDelegate d; | 395 TestDelegate d; |
| 394 { | 396 { |
| 395 d.set_allow_certificate_errors(err_allowed); | 397 d.set_allow_certificate_errors(err_allowed); |
| 396 TestURLRequest r(test_server.GetURL(""), &d); | 398 TestURLRequest r(test_server.GetURL(""), &d); |
| 397 | 399 |
| 398 r.Start(); | 400 r.Start(); |
| 399 EXPECT_TRUE(r.is_pending()); | 401 EXPECT_TRUE(r.is_pending()); |
| 400 | 402 |
| 401 MessageLoop::current()->Run(); | 403 MessageLoop::current()->Run(); |
| 402 | 404 |
| 403 EXPECT_EQ(1, d.response_started_count()); | 405 EXPECT_EQ(1, d.response_started_count()); |
| 404 EXPECT_FALSE(d.received_data_before_response()); | 406 EXPECT_FALSE(d.received_data_before_response()); |
| 405 EXPECT_TRUE(d.have_certificate_errors()); | 407 EXPECT_TRUE(d.have_certificate_errors()); |
| 406 if (err_allowed) { | 408 if (err_allowed) { |
| 407 EXPECT_NE(0, d.bytes_received()); | 409 EXPECT_NE(0, d.bytes_received()); |
| 408 CheckSSLInfo(r.ssl_info()); | 410 CheckSSLInfo(r.ssl_info()); |
| 409 } else { | 411 } else { |
| 410 EXPECT_EQ(0, d.bytes_received()); | 412 EXPECT_EQ(0, d.bytes_received()); |
| 411 } | 413 } |
| 412 } | 414 } |
| 413 } | 415 } |
| 414 } | 416 } |
| 415 | 417 |
| 416 TEST_F(HTTPSRequestTest, HTTPSExpiredTest) { | 418 TEST_F(HTTPSRequestTest, HTTPSExpiredTest) { |
| 417 net::TestServer::HTTPSOptions https_options( | 419 TestServer::HTTPSOptions https_options( |
| 418 net::TestServer::HTTPSOptions::CERT_EXPIRED); | 420 TestServer::HTTPSOptions::CERT_EXPIRED); |
| 419 net::TestServer test_server(https_options, | 421 TestServer test_server(https_options, |
| 420 FilePath(FILE_PATH_LITERAL("net/data/ssl"))); | 422 FilePath(FILE_PATH_LITERAL("net/data/ssl"))); |
| 421 ASSERT_TRUE(test_server.Start()); | 423 ASSERT_TRUE(test_server.Start()); |
| 422 | 424 |
| 423 // Iterate from false to true, just so that we do the opposite of the | 425 // Iterate from false to true, just so that we do the opposite of the |
| 424 // previous test in order to increase test coverage. | 426 // previous test in order to increase test coverage. |
| 425 bool err_allowed = false; | 427 bool err_allowed = false; |
| 426 for (int i = 0; i < 2 ; i++, err_allowed = !err_allowed) { | 428 for (int i = 0; i < 2 ; i++, err_allowed = !err_allowed) { |
| 427 TestDelegate d; | 429 TestDelegate d; |
| 428 { | 430 { |
| 429 d.set_allow_certificate_errors(err_allowed); | 431 d.set_allow_certificate_errors(err_allowed); |
| (...skipping 17 matching lines...) Expand all Loading... |
| 447 } | 449 } |
| 448 } | 450 } |
| 449 | 451 |
| 450 namespace { | 452 namespace { |
| 451 | 453 |
| 452 class SSLClientAuthTestDelegate : public TestDelegate { | 454 class SSLClientAuthTestDelegate : public TestDelegate { |
| 453 public: | 455 public: |
| 454 SSLClientAuthTestDelegate() : on_certificate_requested_count_(0) { | 456 SSLClientAuthTestDelegate() : on_certificate_requested_count_(0) { |
| 455 } | 457 } |
| 456 virtual void OnCertificateRequested( | 458 virtual void OnCertificateRequested( |
| 457 net::URLRequest* request, | 459 URLRequest* request, |
| 458 net::SSLCertRequestInfo* cert_request_info) { | 460 SSLCertRequestInfo* cert_request_info) { |
| 459 on_certificate_requested_count_++; | 461 on_certificate_requested_count_++; |
| 460 MessageLoop::current()->Quit(); | 462 MessageLoop::current()->Quit(); |
| 461 } | 463 } |
| 462 int on_certificate_requested_count() { | 464 int on_certificate_requested_count() { |
| 463 return on_certificate_requested_count_; | 465 return on_certificate_requested_count_; |
| 464 } | 466 } |
| 465 private: | 467 private: |
| 466 int on_certificate_requested_count_; | 468 int on_certificate_requested_count_; |
| 467 }; | 469 }; |
| 468 | 470 |
| 469 } // namespace | 471 } // namespace |
| 470 | 472 |
| 471 // TODO(davidben): Test the rest of the code. Specifically, | 473 // TODO(davidben): Test the rest of the code. Specifically, |
| 472 // - Filtering which certificates to select. | 474 // - Filtering which certificates to select. |
| 473 // - Sending a certificate back. | 475 // - Sending a certificate back. |
| 474 // - Getting a certificate request in an SSL renegotiation sending the | 476 // - Getting a certificate request in an SSL renegotiation sending the |
| 475 // HTTP request. | 477 // HTTP request. |
| 476 TEST_F(HTTPSRequestTest, ClientAuthTest) { | 478 TEST_F(HTTPSRequestTest, ClientAuthTest) { |
| 477 net::TestServer::HTTPSOptions https_options; | 479 TestServer::HTTPSOptions https_options; |
| 478 https_options.request_client_certificate = true; | 480 https_options.request_client_certificate = true; |
| 479 net::TestServer test_server(https_options, | 481 TestServer test_server(https_options, |
| 480 FilePath(FILE_PATH_LITERAL("net/data/ssl"))); | 482 FilePath(FILE_PATH_LITERAL("net/data/ssl"))); |
| 481 ASSERT_TRUE(test_server.Start()); | 483 ASSERT_TRUE(test_server.Start()); |
| 482 | 484 |
| 483 SSLClientAuthTestDelegate d; | 485 SSLClientAuthTestDelegate d; |
| 484 { | 486 { |
| 485 TestURLRequest r(test_server.GetURL(""), &d); | 487 TestURLRequest r(test_server.GetURL(""), &d); |
| 486 | 488 |
| 487 r.Start(); | 489 r.Start(); |
| 488 EXPECT_TRUE(r.is_pending()); | 490 EXPECT_TRUE(r.is_pending()); |
| 489 | 491 |
| (...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 536 d.set_cancel_in_response_started(true); | 538 d.set_cancel_in_response_started(true); |
| 537 | 539 |
| 538 r.Start(); | 540 r.Start(); |
| 539 EXPECT_TRUE(r.is_pending()); | 541 EXPECT_TRUE(r.is_pending()); |
| 540 | 542 |
| 541 MessageLoop::current()->Run(); | 543 MessageLoop::current()->Run(); |
| 542 | 544 |
| 543 EXPECT_EQ(1, d.response_started_count()); | 545 EXPECT_EQ(1, d.response_started_count()); |
| 544 EXPECT_EQ(0, d.bytes_received()); | 546 EXPECT_EQ(0, d.bytes_received()); |
| 545 EXPECT_FALSE(d.received_data_before_response()); | 547 EXPECT_FALSE(d.received_data_before_response()); |
| 546 EXPECT_EQ(net::URLRequestStatus::CANCELED, r.status().status()); | 548 EXPECT_EQ(URLRequestStatus::CANCELED, r.status().status()); |
| 547 } | 549 } |
| 548 } | 550 } |
| 549 | 551 |
| 550 TEST_F(URLRequestTestHTTP, CancelTest3) { | 552 TEST_F(URLRequestTestHTTP, CancelTest3) { |
| 551 ASSERT_TRUE(test_server_.Start()); | 553 ASSERT_TRUE(test_server_.Start()); |
| 552 | 554 |
| 553 TestDelegate d; | 555 TestDelegate d; |
| 554 { | 556 { |
| 555 TestURLRequest r(test_server_.GetURL(""), &d); | 557 TestURLRequest r(test_server_.GetURL(""), &d); |
| 556 | 558 |
| 557 d.set_cancel_in_received_data(true); | 559 d.set_cancel_in_received_data(true); |
| 558 | 560 |
| 559 r.Start(); | 561 r.Start(); |
| 560 EXPECT_TRUE(r.is_pending()); | 562 EXPECT_TRUE(r.is_pending()); |
| 561 | 563 |
| 562 MessageLoop::current()->Run(); | 564 MessageLoop::current()->Run(); |
| 563 | 565 |
| 564 EXPECT_EQ(1, d.response_started_count()); | 566 EXPECT_EQ(1, d.response_started_count()); |
| 565 // There is no guarantee about how much data was received | 567 // There is no guarantee about how much data was received |
| 566 // before the cancel was issued. It could have been 0 bytes, | 568 // before the cancel was issued. It could have been 0 bytes, |
| 567 // or it could have been all the bytes. | 569 // or it could have been all the bytes. |
| 568 // EXPECT_EQ(0, d.bytes_received()); | 570 // EXPECT_EQ(0, d.bytes_received()); |
| 569 EXPECT_FALSE(d.received_data_before_response()); | 571 EXPECT_FALSE(d.received_data_before_response()); |
| 570 EXPECT_EQ(net::URLRequestStatus::CANCELED, r.status().status()); | 572 EXPECT_EQ(URLRequestStatus::CANCELED, r.status().status()); |
| 571 } | 573 } |
| 572 } | 574 } |
| 573 | 575 |
| 574 TEST_F(URLRequestTestHTTP, CancelTest4) { | 576 TEST_F(URLRequestTestHTTP, CancelTest4) { |
| 575 ASSERT_TRUE(test_server_.Start()); | 577 ASSERT_TRUE(test_server_.Start()); |
| 576 | 578 |
| 577 TestDelegate d; | 579 TestDelegate d; |
| 578 { | 580 { |
| 579 TestURLRequest r(test_server_.GetURL(""), &d); | 581 TestURLRequest r(test_server_.GetURL(""), &d); |
| 580 | 582 |
| (...skipping 11 matching lines...) Expand all Loading... |
| 592 | 594 |
| 593 // we won't actually get a received reponse here because we've never run the | 595 // we won't actually get a received reponse here because we've never run the |
| 594 // message loop | 596 // message loop |
| 595 EXPECT_FALSE(d.received_data_before_response()); | 597 EXPECT_FALSE(d.received_data_before_response()); |
| 596 EXPECT_EQ(0, d.bytes_received()); | 598 EXPECT_EQ(0, d.bytes_received()); |
| 597 } | 599 } |
| 598 | 600 |
| 599 TEST_F(URLRequestTestHTTP, CancelTest5) { | 601 TEST_F(URLRequestTestHTTP, CancelTest5) { |
| 600 ASSERT_TRUE(test_server_.Start()); | 602 ASSERT_TRUE(test_server_.Start()); |
| 601 | 603 |
| 602 scoped_refptr<net::URLRequestContext> context(new TestURLRequestContext()); | 604 scoped_refptr<URLRequestContext> context(new TestURLRequestContext()); |
| 603 | 605 |
| 604 // populate cache | 606 // populate cache |
| 605 { | 607 { |
| 606 TestDelegate d; | 608 TestDelegate d; |
| 607 net::URLRequest r(test_server_.GetURL("cachetime"), &d); | 609 URLRequest r(test_server_.GetURL("cachetime"), &d); |
| 608 r.set_context(context); | 610 r.set_context(context); |
| 609 r.Start(); | 611 r.Start(); |
| 610 MessageLoop::current()->Run(); | 612 MessageLoop::current()->Run(); |
| 611 EXPECT_EQ(net::URLRequestStatus::SUCCESS, r.status().status()); | 613 EXPECT_EQ(URLRequestStatus::SUCCESS, r.status().status()); |
| 612 } | 614 } |
| 613 | 615 |
| 614 // cancel read from cache (see bug 990242) | 616 // cancel read from cache (see bug 990242) |
| 615 { | 617 { |
| 616 TestDelegate d; | 618 TestDelegate d; |
| 617 net::URLRequest r(test_server_.GetURL("cachetime"), &d); | 619 URLRequest r(test_server_.GetURL("cachetime"), &d); |
| 618 r.set_context(context); | 620 r.set_context(context); |
| 619 r.Start(); | 621 r.Start(); |
| 620 r.Cancel(); | 622 r.Cancel(); |
| 621 MessageLoop::current()->Run(); | 623 MessageLoop::current()->Run(); |
| 622 | 624 |
| 623 EXPECT_EQ(net::URLRequestStatus::CANCELED, r.status().status()); | 625 EXPECT_EQ(URLRequestStatus::CANCELED, r.status().status()); |
| 624 EXPECT_EQ(1, d.response_started_count()); | 626 EXPECT_EQ(1, d.response_started_count()); |
| 625 EXPECT_EQ(0, d.bytes_received()); | 627 EXPECT_EQ(0, d.bytes_received()); |
| 626 EXPECT_FALSE(d.received_data_before_response()); | 628 EXPECT_FALSE(d.received_data_before_response()); |
| 627 } | 629 } |
| 628 } | 630 } |
| 629 | 631 |
| 630 TEST_F(URLRequestTestHTTP, PostTest) { | 632 TEST_F(URLRequestTestHTTP, PostTest) { |
| 631 ASSERT_TRUE(test_server_.Start()); | 633 ASSERT_TRUE(test_server_.Start()); |
| 632 HTTPUploadDataOperationTest("POST"); | 634 HTTPUploadDataOperationTest("POST"); |
| 633 } | 635 } |
| (...skipping 162 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 796 EXPECT_FALSE(d.received_data_before_response()); | 798 EXPECT_FALSE(d.received_data_before_response()); |
| 797 EXPECT_EQ(d.bytes_received(), 911); | 799 EXPECT_EQ(d.bytes_received(), 911); |
| 798 EXPECT_EQ("", r.GetSocketAddress().host()); | 800 EXPECT_EQ("", r.GetSocketAddress().host()); |
| 799 EXPECT_EQ(0, r.GetSocketAddress().port()); | 801 EXPECT_EQ(0, r.GetSocketAddress().port()); |
| 800 } | 802 } |
| 801 } | 803 } |
| 802 | 804 |
| 803 TEST_F(URLRequestTest, FileTest) { | 805 TEST_F(URLRequestTest, FileTest) { |
| 804 FilePath app_path; | 806 FilePath app_path; |
| 805 PathService::Get(base::FILE_EXE, &app_path); | 807 PathService::Get(base::FILE_EXE, &app_path); |
| 806 GURL app_url = net::FilePathToFileURL(app_path); | 808 GURL app_url = FilePathToFileURL(app_path); |
| 807 | 809 |
| 808 TestDelegate d; | 810 TestDelegate d; |
| 809 { | 811 { |
| 810 TestURLRequest r(app_url, &d); | 812 TestURLRequest r(app_url, &d); |
| 811 | 813 |
| 812 r.Start(); | 814 r.Start(); |
| 813 EXPECT_TRUE(r.is_pending()); | 815 EXPECT_TRUE(r.is_pending()); |
| 814 | 816 |
| 815 MessageLoop::current()->Run(); | 817 MessageLoop::current()->Run(); |
| 816 | 818 |
| 817 int64 file_size = -1; | 819 int64 file_size = -1; |
| 818 EXPECT_TRUE(file_util::GetFileSize(app_path, &file_size)); | 820 EXPECT_TRUE(file_util::GetFileSize(app_path, &file_size)); |
| 819 | 821 |
| 820 EXPECT_TRUE(!r.is_pending()); | 822 EXPECT_TRUE(!r.is_pending()); |
| 821 EXPECT_EQ(1, d.response_started_count()); | 823 EXPECT_EQ(1, d.response_started_count()); |
| 822 EXPECT_FALSE(d.received_data_before_response()); | 824 EXPECT_FALSE(d.received_data_before_response()); |
| 823 EXPECT_EQ(d.bytes_received(), static_cast<int>(file_size)); | 825 EXPECT_EQ(d.bytes_received(), static_cast<int>(file_size)); |
| 824 EXPECT_EQ("", r.GetSocketAddress().host()); | 826 EXPECT_EQ("", r.GetSocketAddress().host()); |
| 825 EXPECT_EQ(0, r.GetSocketAddress().port()); | 827 EXPECT_EQ(0, r.GetSocketAddress().port()); |
| 826 } | 828 } |
| 827 } | 829 } |
| 828 | 830 |
| 829 TEST_F(URLRequestTest, FileTestFullSpecifiedRange) { | 831 TEST_F(URLRequestTest, FileTestFullSpecifiedRange) { |
| 830 const size_t buffer_size = 4000; | 832 const size_t buffer_size = 4000; |
| 831 scoped_array<char> buffer(new char[buffer_size]); | 833 scoped_array<char> buffer(new char[buffer_size]); |
| 832 FillBuffer(buffer.get(), buffer_size); | 834 FillBuffer(buffer.get(), buffer_size); |
| 833 | 835 |
| 834 FilePath temp_path; | 836 FilePath temp_path; |
| 835 EXPECT_TRUE(file_util::CreateTemporaryFile(&temp_path)); | 837 EXPECT_TRUE(file_util::CreateTemporaryFile(&temp_path)); |
| 836 GURL temp_url = net::FilePathToFileURL(temp_path); | 838 GURL temp_url = FilePathToFileURL(temp_path); |
| 837 EXPECT_TRUE(file_util::WriteFile(temp_path, buffer.get(), buffer_size)); | 839 EXPECT_TRUE(file_util::WriteFile(temp_path, buffer.get(), buffer_size)); |
| 838 | 840 |
| 839 int64 file_size; | 841 int64 file_size; |
| 840 EXPECT_TRUE(file_util::GetFileSize(temp_path, &file_size)); | 842 EXPECT_TRUE(file_util::GetFileSize(temp_path, &file_size)); |
| 841 | 843 |
| 842 const size_t first_byte_position = 500; | 844 const size_t first_byte_position = 500; |
| 843 const size_t last_byte_position = buffer_size - first_byte_position; | 845 const size_t last_byte_position = buffer_size - first_byte_position; |
| 844 const size_t content_length = last_byte_position - first_byte_position + 1; | 846 const size_t content_length = last_byte_position - first_byte_position + 1; |
| 845 std::string partial_buffer_string(buffer.get() + first_byte_position, | 847 std::string partial_buffer_string(buffer.get() + first_byte_position, |
| 846 buffer.get() + last_byte_position + 1); | 848 buffer.get() + last_byte_position + 1); |
| 847 | 849 |
| 848 TestDelegate d; | 850 TestDelegate d; |
| 849 { | 851 { |
| 850 TestURLRequest r(temp_url, &d); | 852 TestURLRequest r(temp_url, &d); |
| 851 | 853 |
| 852 net::HttpRequestHeaders headers; | 854 HttpRequestHeaders headers; |
| 853 headers.SetHeader(net::HttpRequestHeaders::kRange, | 855 headers.SetHeader(HttpRequestHeaders::kRange, |
| 854 base::StringPrintf( | 856 base::StringPrintf( |
| 855 "bytes=%" PRIuS "-%" PRIuS, | 857 "bytes=%" PRIuS "-%" PRIuS, |
| 856 first_byte_position, last_byte_position)); | 858 first_byte_position, last_byte_position)); |
| 857 r.SetExtraRequestHeaders(headers); | 859 r.SetExtraRequestHeaders(headers); |
| 858 r.Start(); | 860 r.Start(); |
| 859 EXPECT_TRUE(r.is_pending()); | 861 EXPECT_TRUE(r.is_pending()); |
| 860 | 862 |
| 861 MessageLoop::current()->Run(); | 863 MessageLoop::current()->Run(); |
| 862 EXPECT_TRUE(!r.is_pending()); | 864 EXPECT_TRUE(!r.is_pending()); |
| 863 EXPECT_EQ(1, d.response_started_count()); | 865 EXPECT_EQ(1, d.response_started_count()); |
| 864 EXPECT_FALSE(d.received_data_before_response()); | 866 EXPECT_FALSE(d.received_data_before_response()); |
| 865 EXPECT_EQ(static_cast<int>(content_length), d.bytes_received()); | 867 EXPECT_EQ(static_cast<int>(content_length), d.bytes_received()); |
| 866 // Don't use EXPECT_EQ, it will print out a lot of garbage if check failed. | 868 // Don't use EXPECT_EQ, it will print out a lot of garbage if check failed. |
| 867 EXPECT_TRUE(partial_buffer_string == d.data_received()); | 869 EXPECT_TRUE(partial_buffer_string == d.data_received()); |
| 868 } | 870 } |
| 869 | 871 |
| 870 EXPECT_TRUE(file_util::Delete(temp_path, false)); | 872 EXPECT_TRUE(file_util::Delete(temp_path, false)); |
| 871 } | 873 } |
| 872 | 874 |
| 873 TEST_F(URLRequestTest, FileTestHalfSpecifiedRange) { | 875 TEST_F(URLRequestTest, FileTestHalfSpecifiedRange) { |
| 874 const size_t buffer_size = 4000; | 876 const size_t buffer_size = 4000; |
| 875 scoped_array<char> buffer(new char[buffer_size]); | 877 scoped_array<char> buffer(new char[buffer_size]); |
| 876 FillBuffer(buffer.get(), buffer_size); | 878 FillBuffer(buffer.get(), buffer_size); |
| 877 | 879 |
| 878 FilePath temp_path; | 880 FilePath temp_path; |
| 879 EXPECT_TRUE(file_util::CreateTemporaryFile(&temp_path)); | 881 EXPECT_TRUE(file_util::CreateTemporaryFile(&temp_path)); |
| 880 GURL temp_url = net::FilePathToFileURL(temp_path); | 882 GURL temp_url = FilePathToFileURL(temp_path); |
| 881 EXPECT_TRUE(file_util::WriteFile(temp_path, buffer.get(), buffer_size)); | 883 EXPECT_TRUE(file_util::WriteFile(temp_path, buffer.get(), buffer_size)); |
| 882 | 884 |
| 883 int64 file_size; | 885 int64 file_size; |
| 884 EXPECT_TRUE(file_util::GetFileSize(temp_path, &file_size)); | 886 EXPECT_TRUE(file_util::GetFileSize(temp_path, &file_size)); |
| 885 | 887 |
| 886 const size_t first_byte_position = 500; | 888 const size_t first_byte_position = 500; |
| 887 const size_t last_byte_position = buffer_size - 1; | 889 const size_t last_byte_position = buffer_size - 1; |
| 888 const size_t content_length = last_byte_position - first_byte_position + 1; | 890 const size_t content_length = last_byte_position - first_byte_position + 1; |
| 889 std::string partial_buffer_string(buffer.get() + first_byte_position, | 891 std::string partial_buffer_string(buffer.get() + first_byte_position, |
| 890 buffer.get() + last_byte_position + 1); | 892 buffer.get() + last_byte_position + 1); |
| 891 | 893 |
| 892 TestDelegate d; | 894 TestDelegate d; |
| 893 { | 895 { |
| 894 TestURLRequest r(temp_url, &d); | 896 TestURLRequest r(temp_url, &d); |
| 895 | 897 |
| 896 net::HttpRequestHeaders headers; | 898 HttpRequestHeaders headers; |
| 897 headers.SetHeader(net::HttpRequestHeaders::kRange, | 899 headers.SetHeader(HttpRequestHeaders::kRange, |
| 898 base::StringPrintf("bytes=%" PRIuS "-", | 900 base::StringPrintf("bytes=%" PRIuS "-", |
| 899 first_byte_position)); | 901 first_byte_position)); |
| 900 r.SetExtraRequestHeaders(headers); | 902 r.SetExtraRequestHeaders(headers); |
| 901 r.Start(); | 903 r.Start(); |
| 902 EXPECT_TRUE(r.is_pending()); | 904 EXPECT_TRUE(r.is_pending()); |
| 903 | 905 |
| 904 MessageLoop::current()->Run(); | 906 MessageLoop::current()->Run(); |
| 905 EXPECT_TRUE(!r.is_pending()); | 907 EXPECT_TRUE(!r.is_pending()); |
| 906 EXPECT_EQ(1, d.response_started_count()); | 908 EXPECT_EQ(1, d.response_started_count()); |
| 907 EXPECT_FALSE(d.received_data_before_response()); | 909 EXPECT_FALSE(d.received_data_before_response()); |
| 908 EXPECT_EQ(static_cast<int>(content_length), d.bytes_received()); | 910 EXPECT_EQ(static_cast<int>(content_length), d.bytes_received()); |
| 909 // Don't use EXPECT_EQ, it will print out a lot of garbage if check failed. | 911 // Don't use EXPECT_EQ, it will print out a lot of garbage if check failed. |
| 910 EXPECT_TRUE(partial_buffer_string == d.data_received()); | 912 EXPECT_TRUE(partial_buffer_string == d.data_received()); |
| 911 } | 913 } |
| 912 | 914 |
| 913 EXPECT_TRUE(file_util::Delete(temp_path, false)); | 915 EXPECT_TRUE(file_util::Delete(temp_path, false)); |
| 914 } | 916 } |
| 915 | 917 |
| 916 TEST_F(URLRequestTest, FileTestMultipleRanges) { | 918 TEST_F(URLRequestTest, FileTestMultipleRanges) { |
| 917 const size_t buffer_size = 400000; | 919 const size_t buffer_size = 400000; |
| 918 scoped_array<char> buffer(new char[buffer_size]); | 920 scoped_array<char> buffer(new char[buffer_size]); |
| 919 FillBuffer(buffer.get(), buffer_size); | 921 FillBuffer(buffer.get(), buffer_size); |
| 920 | 922 |
| 921 FilePath temp_path; | 923 FilePath temp_path; |
| 922 EXPECT_TRUE(file_util::CreateTemporaryFile(&temp_path)); | 924 EXPECT_TRUE(file_util::CreateTemporaryFile(&temp_path)); |
| 923 GURL temp_url = net::FilePathToFileURL(temp_path); | 925 GURL temp_url = FilePathToFileURL(temp_path); |
| 924 EXPECT_TRUE(file_util::WriteFile(temp_path, buffer.get(), buffer_size)); | 926 EXPECT_TRUE(file_util::WriteFile(temp_path, buffer.get(), buffer_size)); |
| 925 | 927 |
| 926 int64 file_size; | 928 int64 file_size; |
| 927 EXPECT_TRUE(file_util::GetFileSize(temp_path, &file_size)); | 929 EXPECT_TRUE(file_util::GetFileSize(temp_path, &file_size)); |
| 928 | 930 |
| 929 TestDelegate d; | 931 TestDelegate d; |
| 930 { | 932 { |
| 931 TestURLRequest r(temp_url, &d); | 933 TestURLRequest r(temp_url, &d); |
| 932 | 934 |
| 933 net::HttpRequestHeaders headers; | 935 HttpRequestHeaders headers; |
| 934 headers.SetHeader(net::HttpRequestHeaders::kRange, | 936 headers.SetHeader(HttpRequestHeaders::kRange, |
| 935 "bytes=0-0,10-200,200-300"); | 937 "bytes=0-0,10-200,200-300"); |
| 936 r.SetExtraRequestHeaders(headers); | 938 r.SetExtraRequestHeaders(headers); |
| 937 r.Start(); | 939 r.Start(); |
| 938 EXPECT_TRUE(r.is_pending()); | 940 EXPECT_TRUE(r.is_pending()); |
| 939 | 941 |
| 940 MessageLoop::current()->Run(); | 942 MessageLoop::current()->Run(); |
| 941 EXPECT_TRUE(d.request_failed()); | 943 EXPECT_TRUE(d.request_failed()); |
| 942 } | 944 } |
| 943 | 945 |
| 944 EXPECT_TRUE(file_util::Delete(temp_path, false)); | 946 EXPECT_TRUE(file_util::Delete(temp_path, false)); |
| (...skipping 13 matching lines...) Expand all Loading... |
| 958 } | 960 } |
| 959 | 961 |
| 960 TEST_F(URLRequestTestHTTP, ResponseHeadersTest) { | 962 TEST_F(URLRequestTestHTTP, ResponseHeadersTest) { |
| 961 ASSERT_TRUE(test_server_.Start()); | 963 ASSERT_TRUE(test_server_.Start()); |
| 962 | 964 |
| 963 TestDelegate d; | 965 TestDelegate d; |
| 964 TestURLRequest req(test_server_.GetURL("files/with-headers.html"), &d); | 966 TestURLRequest req(test_server_.GetURL("files/with-headers.html"), &d); |
| 965 req.Start(); | 967 req.Start(); |
| 966 MessageLoop::current()->Run(); | 968 MessageLoop::current()->Run(); |
| 967 | 969 |
| 968 const net::HttpResponseHeaders* headers = req.response_headers(); | 970 const HttpResponseHeaders* headers = req.response_headers(); |
| 969 | 971 |
| 970 // Simple sanity check that response_info() accesses the same data. | 972 // Simple sanity check that response_info() accesses the same data. |
| 971 EXPECT_EQ(headers, req.response_info().headers.get()); | 973 EXPECT_EQ(headers, req.response_info().headers.get()); |
| 972 | 974 |
| 973 std::string header; | 975 std::string header; |
| 974 EXPECT_TRUE(headers->GetNormalizedHeader("cache-control", &header)); | 976 EXPECT_TRUE(headers->GetNormalizedHeader("cache-control", &header)); |
| 975 EXPECT_EQ("private", header); | 977 EXPECT_EQ("private", header); |
| 976 | 978 |
| 977 header.clear(); | 979 header.clear(); |
| 978 EXPECT_TRUE(headers->GetNormalizedHeader("content-type", &header)); | 980 EXPECT_TRUE(headers->GetNormalizedHeader("content-type", &header)); |
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1015 EXPECT_TRUE(SUCCEEDED(result)); | 1017 EXPECT_TRUE(SUCCEEDED(result)); |
| 1016 result = persist->Save(lnk_path.c_str(), TRUE); | 1018 result = persist->Save(lnk_path.c_str(), TRUE); |
| 1017 EXPECT_TRUE(SUCCEEDED(result)); | 1019 EXPECT_TRUE(SUCCEEDED(result)); |
| 1018 if (persist) | 1020 if (persist) |
| 1019 persist->Release(); | 1021 persist->Release(); |
| 1020 if (shell) | 1022 if (shell) |
| 1021 shell->Release(); | 1023 shell->Release(); |
| 1022 | 1024 |
| 1023 TestDelegate d; | 1025 TestDelegate d; |
| 1024 { | 1026 { |
| 1025 TestURLRequest r(net::FilePathToFileURL(FilePath(lnk_path)), &d); | 1027 TestURLRequest r(FilePathToFileURL(FilePath(lnk_path)), &d); |
| 1026 | 1028 |
| 1027 r.Start(); | 1029 r.Start(); |
| 1028 EXPECT_TRUE(r.is_pending()); | 1030 EXPECT_TRUE(r.is_pending()); |
| 1029 | 1031 |
| 1030 MessageLoop::current()->Run(); | 1032 MessageLoop::current()->Run(); |
| 1031 | 1033 |
| 1032 WIN32_FILE_ATTRIBUTE_DATA data; | 1034 WIN32_FILE_ATTRIBUTE_DATA data; |
| 1033 GetFileAttributesEx(app_path.value().c_str(), | 1035 GetFileAttributesEx(app_path.value().c_str(), |
| 1034 GetFileExInfoStandard, &data); | 1036 GetFileExInfoStandard, &data); |
| 1035 HANDLE file = CreateFile(app_path.value().c_str(), GENERIC_READ, | 1037 HANDLE file = CreateFile(app_path.value().c_str(), GENERIC_READ, |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1069 EXPECT_EQ("text/html", mime_type); | 1071 EXPECT_EQ("text/html", mime_type); |
| 1070 | 1072 |
| 1071 std::string charset; | 1073 std::string charset; |
| 1072 req.GetCharset(&charset); | 1074 req.GetCharset(&charset); |
| 1073 EXPECT_EQ("utf-8", charset); | 1075 EXPECT_EQ("utf-8", charset); |
| 1074 req.Cancel(); | 1076 req.Cancel(); |
| 1075 } | 1077 } |
| 1076 | 1078 |
| 1077 TEST_F(URLRequestTest, FileDirCancelTest) { | 1079 TEST_F(URLRequestTest, FileDirCancelTest) { |
| 1078 // Put in mock resource provider. | 1080 // Put in mock resource provider. |
| 1079 net::NetModule::SetResourceProvider(TestNetResourceProvider); | 1081 NetModule::SetResourceProvider(TestNetResourceProvider); |
| 1080 | 1082 |
| 1081 TestDelegate d; | 1083 TestDelegate d; |
| 1082 { | 1084 { |
| 1083 FilePath file_path; | 1085 FilePath file_path; |
| 1084 PathService::Get(base::DIR_SOURCE_ROOT, &file_path); | 1086 PathService::Get(base::DIR_SOURCE_ROOT, &file_path); |
| 1085 file_path = file_path.Append(FILE_PATH_LITERAL("net")); | 1087 file_path = file_path.Append(FILE_PATH_LITERAL("net")); |
| 1086 file_path = file_path.Append(FILE_PATH_LITERAL("data")); | 1088 file_path = file_path.Append(FILE_PATH_LITERAL("data")); |
| 1087 | 1089 |
| 1088 TestURLRequest req(net::FilePathToFileURL(file_path), &d); | 1090 TestURLRequest req(FilePathToFileURL(file_path), &d); |
| 1089 req.Start(); | 1091 req.Start(); |
| 1090 EXPECT_TRUE(req.is_pending()); | 1092 EXPECT_TRUE(req.is_pending()); |
| 1091 | 1093 |
| 1092 d.set_cancel_in_received_data_pending(true); | 1094 d.set_cancel_in_received_data_pending(true); |
| 1093 | 1095 |
| 1094 MessageLoop::current()->Run(); | 1096 MessageLoop::current()->Run(); |
| 1095 } | 1097 } |
| 1096 | 1098 |
| 1097 // Take out mock resource provider. | 1099 // Take out mock resource provider. |
| 1098 net::NetModule::SetResourceProvider(NULL); | 1100 NetModule::SetResourceProvider(NULL); |
| 1099 } | 1101 } |
| 1100 | 1102 |
| 1101 TEST_F(URLRequestTest, FileDirRedirectNoCrash) { | 1103 TEST_F(URLRequestTest, FileDirRedirectNoCrash) { |
| 1102 // There is an implicit redirect when loading a file path that matches a | 1104 // There is an implicit redirect when loading a file path that matches a |
| 1103 // directory and does not end with a slash. Ensure that following such | 1105 // directory and does not end with a slash. Ensure that following such |
| 1104 // redirects does not crash. See http://crbug.com/18686. | 1106 // redirects does not crash. See http://crbug.com/18686. |
| 1105 | 1107 |
| 1106 FilePath path; | 1108 FilePath path; |
| 1107 PathService::Get(base::DIR_SOURCE_ROOT, &path); | 1109 PathService::Get(base::DIR_SOURCE_ROOT, &path); |
| 1108 path = path.Append(FILE_PATH_LITERAL("net")); | 1110 path = path.Append(FILE_PATH_LITERAL("net")); |
| 1109 path = path.Append(FILE_PATH_LITERAL("data")); | 1111 path = path.Append(FILE_PATH_LITERAL("data")); |
| 1110 path = path.Append(FILE_PATH_LITERAL("url_request_unittest")); | 1112 path = path.Append(FILE_PATH_LITERAL("url_request_unittest")); |
| 1111 | 1113 |
| 1112 TestDelegate d; | 1114 TestDelegate d; |
| 1113 TestURLRequest req(net::FilePathToFileURL(path), &d); | 1115 TestURLRequest req(FilePathToFileURL(path), &d); |
| 1114 req.Start(); | 1116 req.Start(); |
| 1115 MessageLoop::current()->Run(); | 1117 MessageLoop::current()->Run(); |
| 1116 | 1118 |
| 1117 ASSERT_EQ(1, d.received_redirect_count()); | 1119 ASSERT_EQ(1, d.received_redirect_count()); |
| 1118 ASSERT_LT(0, d.bytes_received()); | 1120 ASSERT_LT(0, d.bytes_received()); |
| 1119 ASSERT_FALSE(d.request_failed()); | 1121 ASSERT_FALSE(d.request_failed()); |
| 1120 ASSERT_TRUE(req.status().is_success()); | 1122 ASSERT_TRUE(req.status().is_success()); |
| 1121 } | 1123 } |
| 1122 | 1124 |
| 1123 #if defined(OS_WIN) | 1125 #if defined(OS_WIN) |
| (...skipping 11 matching lines...) Expand all Loading... |
| 1135 | 1137 |
| 1136 TEST_F(URLRequestTestHTTP, RestrictRedirects) { | 1138 TEST_F(URLRequestTestHTTP, RestrictRedirects) { |
| 1137 ASSERT_TRUE(test_server_.Start()); | 1139 ASSERT_TRUE(test_server_.Start()); |
| 1138 | 1140 |
| 1139 TestDelegate d; | 1141 TestDelegate d; |
| 1140 TestURLRequest req(test_server_.GetURL( | 1142 TestURLRequest req(test_server_.GetURL( |
| 1141 "files/redirect-to-file.html"), &d); | 1143 "files/redirect-to-file.html"), &d); |
| 1142 req.Start(); | 1144 req.Start(); |
| 1143 MessageLoop::current()->Run(); | 1145 MessageLoop::current()->Run(); |
| 1144 | 1146 |
| 1145 EXPECT_EQ(net::URLRequestStatus::FAILED, req.status().status()); | 1147 EXPECT_EQ(URLRequestStatus::FAILED, req.status().status()); |
| 1146 EXPECT_EQ(net::ERR_UNSAFE_REDIRECT, req.status().os_error()); | 1148 EXPECT_EQ(ERR_UNSAFE_REDIRECT, req.status().os_error()); |
| 1147 } | 1149 } |
| 1148 | 1150 |
| 1149 TEST_F(URLRequestTestHTTP, RedirectToInvalidURL) { | 1151 TEST_F(URLRequestTestHTTP, RedirectToInvalidURL) { |
| 1150 ASSERT_TRUE(test_server_.Start()); | 1152 ASSERT_TRUE(test_server_.Start()); |
| 1151 | 1153 |
| 1152 TestDelegate d; | 1154 TestDelegate d; |
| 1153 TestURLRequest req(test_server_.GetURL( | 1155 TestURLRequest req(test_server_.GetURL( |
| 1154 "files/redirect-to-invalid-url.html"), &d); | 1156 "files/redirect-to-invalid-url.html"), &d); |
| 1155 req.Start(); | 1157 req.Start(); |
| 1156 MessageLoop::current()->Run(); | 1158 MessageLoop::current()->Run(); |
| 1157 | 1159 |
| 1158 EXPECT_EQ(net::URLRequestStatus::FAILED, req.status().status()); | 1160 EXPECT_EQ(URLRequestStatus::FAILED, req.status().status()); |
| 1159 EXPECT_EQ(net::ERR_INVALID_URL, req.status().os_error()); | 1161 EXPECT_EQ(ERR_INVALID_URL, req.status().os_error()); |
| 1160 } | 1162 } |
| 1161 | 1163 |
| 1162 TEST_F(URLRequestTestHTTP, NoUserPassInReferrer) { | 1164 TEST_F(URLRequestTestHTTP, NoUserPassInReferrer) { |
| 1163 ASSERT_TRUE(test_server_.Start()); | 1165 ASSERT_TRUE(test_server_.Start()); |
| 1164 | 1166 |
| 1165 TestDelegate d; | 1167 TestDelegate d; |
| 1166 TestURLRequest req(test_server_.GetURL( | 1168 TestURLRequest req(test_server_.GetURL( |
| 1167 "echoheader?Referer"), &d); | 1169 "echoheader?Referer"), &d); |
| 1168 req.set_referrer("http://user:pass@foo.com/"); | 1170 req.set_referrer("http://user:pass@foo.com/"); |
| 1169 req.Start(); | 1171 req.Start(); |
| 1170 MessageLoop::current()->Run(); | 1172 MessageLoop::current()->Run(); |
| 1171 | 1173 |
| 1172 EXPECT_EQ(std::string("http://foo.com/"), d.data_received()); | 1174 EXPECT_EQ(std::string("http://foo.com/"), d.data_received()); |
| 1173 } | 1175 } |
| 1174 | 1176 |
| 1175 TEST_F(URLRequestTestHTTP, CancelRedirect) { | 1177 TEST_F(URLRequestTestHTTP, CancelRedirect) { |
| 1176 ASSERT_TRUE(test_server_.Start()); | 1178 ASSERT_TRUE(test_server_.Start()); |
| 1177 | 1179 |
| 1178 TestDelegate d; | 1180 TestDelegate d; |
| 1179 { | 1181 { |
| 1180 d.set_cancel_in_received_redirect(true); | 1182 d.set_cancel_in_received_redirect(true); |
| 1181 TestURLRequest req(test_server_.GetURL( | 1183 TestURLRequest req(test_server_.GetURL( |
| 1182 "files/redirect-test.html"), &d); | 1184 "files/redirect-test.html"), &d); |
| 1183 req.Start(); | 1185 req.Start(); |
| 1184 MessageLoop::current()->Run(); | 1186 MessageLoop::current()->Run(); |
| 1185 | 1187 |
| 1186 EXPECT_EQ(1, d.response_started_count()); | 1188 EXPECT_EQ(1, d.response_started_count()); |
| 1187 EXPECT_EQ(0, d.bytes_received()); | 1189 EXPECT_EQ(0, d.bytes_received()); |
| 1188 EXPECT_FALSE(d.received_data_before_response()); | 1190 EXPECT_FALSE(d.received_data_before_response()); |
| 1189 EXPECT_EQ(net::URLRequestStatus::CANCELED, req.status().status()); | 1191 EXPECT_EQ(URLRequestStatus::CANCELED, req.status().status()); |
| 1190 } | 1192 } |
| 1191 } | 1193 } |
| 1192 | 1194 |
| 1193 TEST_F(URLRequestTestHTTP, DeferredRedirect) { | 1195 TEST_F(URLRequestTestHTTP, DeferredRedirect) { |
| 1194 ASSERT_TRUE(test_server_.Start()); | 1196 ASSERT_TRUE(test_server_.Start()); |
| 1195 | 1197 |
| 1196 TestDelegate d; | 1198 TestDelegate d; |
| 1197 { | 1199 { |
| 1198 d.set_quit_on_redirect(true); | 1200 d.set_quit_on_redirect(true); |
| 1199 TestURLRequest req(test_server_.GetURL( | 1201 TestURLRequest req(test_server_.GetURL( |
| 1200 "files/redirect-test.html"), &d); | 1202 "files/redirect-test.html"), &d); |
| 1201 req.Start(); | 1203 req.Start(); |
| 1202 MessageLoop::current()->Run(); | 1204 MessageLoop::current()->Run(); |
| 1203 | 1205 |
| 1204 EXPECT_EQ(1, d.received_redirect_count()); | 1206 EXPECT_EQ(1, d.received_redirect_count()); |
| 1205 | 1207 |
| 1206 req.FollowDeferredRedirect(); | 1208 req.FollowDeferredRedirect(); |
| 1207 MessageLoop::current()->Run(); | 1209 MessageLoop::current()->Run(); |
| 1208 | 1210 |
| 1209 EXPECT_EQ(1, d.response_started_count()); | 1211 EXPECT_EQ(1, d.response_started_count()); |
| 1210 EXPECT_FALSE(d.received_data_before_response()); | 1212 EXPECT_FALSE(d.received_data_before_response()); |
| 1211 EXPECT_EQ(net::URLRequestStatus::SUCCESS, req.status().status()); | 1213 EXPECT_EQ(URLRequestStatus::SUCCESS, req.status().status()); |
| 1212 | 1214 |
| 1213 FilePath path; | 1215 FilePath path; |
| 1214 PathService::Get(base::DIR_SOURCE_ROOT, &path); | 1216 PathService::Get(base::DIR_SOURCE_ROOT, &path); |
| 1215 path = path.Append(FILE_PATH_LITERAL("net")); | 1217 path = path.Append(FILE_PATH_LITERAL("net")); |
| 1216 path = path.Append(FILE_PATH_LITERAL("data")); | 1218 path = path.Append(FILE_PATH_LITERAL("data")); |
| 1217 path = path.Append(FILE_PATH_LITERAL("url_request_unittest")); | 1219 path = path.Append(FILE_PATH_LITERAL("url_request_unittest")); |
| 1218 path = path.Append(FILE_PATH_LITERAL("with-headers.html")); | 1220 path = path.Append(FILE_PATH_LITERAL("with-headers.html")); |
| 1219 | 1221 |
| 1220 std::string contents; | 1222 std::string contents; |
| 1221 EXPECT_TRUE(file_util::ReadFileToString(path, &contents)); | 1223 EXPECT_TRUE(file_util::ReadFileToString(path, &contents)); |
| (...skipping 13 matching lines...) Expand all Loading... |
| 1235 MessageLoop::current()->Run(); | 1237 MessageLoop::current()->Run(); |
| 1236 | 1238 |
| 1237 EXPECT_EQ(1, d.received_redirect_count()); | 1239 EXPECT_EQ(1, d.received_redirect_count()); |
| 1238 | 1240 |
| 1239 req.Cancel(); | 1241 req.Cancel(); |
| 1240 MessageLoop::current()->Run(); | 1242 MessageLoop::current()->Run(); |
| 1241 | 1243 |
| 1242 EXPECT_EQ(1, d.response_started_count()); | 1244 EXPECT_EQ(1, d.response_started_count()); |
| 1243 EXPECT_EQ(0, d.bytes_received()); | 1245 EXPECT_EQ(0, d.bytes_received()); |
| 1244 EXPECT_FALSE(d.received_data_before_response()); | 1246 EXPECT_FALSE(d.received_data_before_response()); |
| 1245 EXPECT_EQ(net::URLRequestStatus::CANCELED, req.status().status()); | 1247 EXPECT_EQ(URLRequestStatus::CANCELED, req.status().status()); |
| 1246 } | 1248 } |
| 1247 } | 1249 } |
| 1248 | 1250 |
| 1249 TEST_F(URLRequestTestHTTP, VaryHeader) { | 1251 TEST_F(URLRequestTestHTTP, VaryHeader) { |
| 1250 ASSERT_TRUE(test_server_.Start()); | 1252 ASSERT_TRUE(test_server_.Start()); |
| 1251 | 1253 |
| 1252 scoped_refptr<net::URLRequestContext> context(new TestURLRequestContext()); | 1254 scoped_refptr<URLRequestContext> context(new TestURLRequestContext()); |
| 1253 | 1255 |
| 1254 // populate the cache | 1256 // populate the cache |
| 1255 { | 1257 { |
| 1256 TestDelegate d; | 1258 TestDelegate d; |
| 1257 net::URLRequest req(test_server_.GetURL("echoheader?foo"), &d); | 1259 URLRequest req(test_server_.GetURL("echoheader?foo"), &d); |
| 1258 req.set_context(context); | 1260 req.set_context(context); |
| 1259 net::HttpRequestHeaders headers; | 1261 HttpRequestHeaders headers; |
| 1260 headers.SetHeader("foo", "1"); | 1262 headers.SetHeader("foo", "1"); |
| 1261 req.SetExtraRequestHeaders(headers); | 1263 req.SetExtraRequestHeaders(headers); |
| 1262 req.Start(); | 1264 req.Start(); |
| 1263 MessageLoop::current()->Run(); | 1265 MessageLoop::current()->Run(); |
| 1264 } | 1266 } |
| 1265 | 1267 |
| 1266 // expect a cache hit | 1268 // expect a cache hit |
| 1267 { | 1269 { |
| 1268 TestDelegate d; | 1270 TestDelegate d; |
| 1269 net::URLRequest req(test_server_.GetURL("echoheader?foo"), &d); | 1271 URLRequest req(test_server_.GetURL("echoheader?foo"), &d); |
| 1270 req.set_context(context); | 1272 req.set_context(context); |
| 1271 net::HttpRequestHeaders headers; | 1273 HttpRequestHeaders headers; |
| 1272 headers.SetHeader("foo", "1"); | 1274 headers.SetHeader("foo", "1"); |
| 1273 req.SetExtraRequestHeaders(headers); | 1275 req.SetExtraRequestHeaders(headers); |
| 1274 req.Start(); | 1276 req.Start(); |
| 1275 MessageLoop::current()->Run(); | 1277 MessageLoop::current()->Run(); |
| 1276 | 1278 |
| 1277 EXPECT_TRUE(req.was_cached()); | 1279 EXPECT_TRUE(req.was_cached()); |
| 1278 } | 1280 } |
| 1279 | 1281 |
| 1280 // expect a cache miss | 1282 // expect a cache miss |
| 1281 { | 1283 { |
| 1282 TestDelegate d; | 1284 TestDelegate d; |
| 1283 net::URLRequest req(test_server_.GetURL("echoheader?foo"), &d); | 1285 URLRequest req(test_server_.GetURL("echoheader?foo"), &d); |
| 1284 req.set_context(context); | 1286 req.set_context(context); |
| 1285 net::HttpRequestHeaders headers; | 1287 HttpRequestHeaders headers; |
| 1286 headers.SetHeader("foo", "2"); | 1288 headers.SetHeader("foo", "2"); |
| 1287 req.SetExtraRequestHeaders(headers); | 1289 req.SetExtraRequestHeaders(headers); |
| 1288 req.Start(); | 1290 req.Start(); |
| 1289 MessageLoop::current()->Run(); | 1291 MessageLoop::current()->Run(); |
| 1290 | 1292 |
| 1291 EXPECT_FALSE(req.was_cached()); | 1293 EXPECT_FALSE(req.was_cached()); |
| 1292 } | 1294 } |
| 1293 } | 1295 } |
| 1294 | 1296 |
| 1295 TEST_F(URLRequestTestHTTP, BasicAuth) { | 1297 TEST_F(URLRequestTestHTTP, BasicAuth) { |
| 1296 ASSERT_TRUE(test_server_.Start()); | 1298 ASSERT_TRUE(test_server_.Start()); |
| 1297 | 1299 |
| 1298 scoped_refptr<net::URLRequestContext> context(new TestURLRequestContext()); | 1300 scoped_refptr<URLRequestContext> context(new TestURLRequestContext()); |
| 1299 | 1301 |
| 1300 // populate the cache | 1302 // populate the cache |
| 1301 { | 1303 { |
| 1302 TestDelegate d; | 1304 TestDelegate d; |
| 1303 d.set_username(kUser); | 1305 d.set_username(kUser); |
| 1304 d.set_password(kSecret); | 1306 d.set_password(kSecret); |
| 1305 | 1307 |
| 1306 net::URLRequest r(test_server_.GetURL("auth-basic"), &d); | 1308 URLRequest r(test_server_.GetURL("auth-basic"), &d); |
| 1307 r.set_context(context); | 1309 r.set_context(context); |
| 1308 r.Start(); | 1310 r.Start(); |
| 1309 | 1311 |
| 1310 MessageLoop::current()->Run(); | 1312 MessageLoop::current()->Run(); |
| 1311 | 1313 |
| 1312 EXPECT_TRUE(d.data_received().find("user/secret") != std::string::npos); | 1314 EXPECT_TRUE(d.data_received().find("user/secret") != std::string::npos); |
| 1313 } | 1315 } |
| 1314 | 1316 |
| 1315 // repeat request with end-to-end validation. since auth-basic results in a | 1317 // repeat request with end-to-end validation. since auth-basic results in a |
| 1316 // cachable page, we expect this test to result in a 304. in which case, the | 1318 // cachable page, we expect this test to result in a 304. in which case, the |
| 1317 // response should be fetched from the cache. | 1319 // response should be fetched from the cache. |
| 1318 { | 1320 { |
| 1319 TestDelegate d; | 1321 TestDelegate d; |
| 1320 d.set_username(kUser); | 1322 d.set_username(kUser); |
| 1321 d.set_password(kSecret); | 1323 d.set_password(kSecret); |
| 1322 | 1324 |
| 1323 net::URLRequest r(test_server_.GetURL("auth-basic"), &d); | 1325 URLRequest r(test_server_.GetURL("auth-basic"), &d); |
| 1324 r.set_context(context); | 1326 r.set_context(context); |
| 1325 r.set_load_flags(net::LOAD_VALIDATE_CACHE); | 1327 r.set_load_flags(LOAD_VALIDATE_CACHE); |
| 1326 r.Start(); | 1328 r.Start(); |
| 1327 | 1329 |
| 1328 MessageLoop::current()->Run(); | 1330 MessageLoop::current()->Run(); |
| 1329 | 1331 |
| 1330 EXPECT_TRUE(d.data_received().find("user/secret") != std::string::npos); | 1332 EXPECT_TRUE(d.data_received().find("user/secret") != std::string::npos); |
| 1331 | 1333 |
| 1332 // Should be the same cached document. | 1334 // Should be the same cached document. |
| 1333 EXPECT_TRUE(r.was_cached()); | 1335 EXPECT_TRUE(r.was_cached()); |
| 1334 } | 1336 } |
| 1335 } | 1337 } |
| 1336 | 1338 |
| 1337 // Check that Set-Cookie headers in 401 responses are respected. | 1339 // Check that Set-Cookie headers in 401 responses are respected. |
| 1338 // http://crbug.com/6450 | 1340 // http://crbug.com/6450 |
| 1339 TEST_F(URLRequestTestHTTP, BasicAuthWithCookies) { | 1341 TEST_F(URLRequestTestHTTP, BasicAuthWithCookies) { |
| 1340 ASSERT_TRUE(test_server_.Start()); | 1342 ASSERT_TRUE(test_server_.Start()); |
| 1341 | 1343 |
| 1342 GURL url_requiring_auth = | 1344 GURL url_requiring_auth = |
| 1343 test_server_.GetURL("auth-basic?set-cookie-if-challenged"); | 1345 test_server_.GetURL("auth-basic?set-cookie-if-challenged"); |
| 1344 | 1346 |
| 1345 // Request a page that will give a 401 containing a Set-Cookie header. | 1347 // Request a page that will give a 401 containing a Set-Cookie header. |
| 1346 // Verify that when the transaction is restarted, it includes the new cookie. | 1348 // Verify that when the transaction is restarted, it includes the new cookie. |
| 1347 { | 1349 { |
| 1348 scoped_refptr<net::URLRequestContext> context(new TestURLRequestContext()); | 1350 scoped_refptr<URLRequestContext> context(new TestURLRequestContext()); |
| 1349 TestDelegate d; | 1351 TestDelegate d; |
| 1350 d.set_username(kUser); | 1352 d.set_username(kUser); |
| 1351 d.set_password(kSecret); | 1353 d.set_password(kSecret); |
| 1352 | 1354 |
| 1353 net::URLRequest r(url_requiring_auth, &d); | 1355 URLRequest r(url_requiring_auth, &d); |
| 1354 r.set_context(context); | 1356 r.set_context(context); |
| 1355 r.Start(); | 1357 r.Start(); |
| 1356 | 1358 |
| 1357 MessageLoop::current()->Run(); | 1359 MessageLoop::current()->Run(); |
| 1358 | 1360 |
| 1359 EXPECT_TRUE(d.data_received().find("user/secret") != std::string::npos); | 1361 EXPECT_TRUE(d.data_received().find("user/secret") != std::string::npos); |
| 1360 | 1362 |
| 1361 // Make sure we sent the cookie in the restarted transaction. | 1363 // Make sure we sent the cookie in the restarted transaction. |
| 1362 EXPECT_TRUE(d.data_received().find("Cookie: got_challenged=true") | 1364 EXPECT_TRUE(d.data_received().find("Cookie: got_challenged=true") |
| 1363 != std::string::npos); | 1365 != std::string::npos); |
| 1364 } | 1366 } |
| 1365 | 1367 |
| 1366 // Same test as above, except this time the restart is initiated earlier | 1368 // Same test as above, except this time the restart is initiated earlier |
| 1367 // (without user intervention since identity is embedded in the URL). | 1369 // (without user intervention since identity is embedded in the URL). |
| 1368 { | 1370 { |
| 1369 scoped_refptr<net::URLRequestContext> context(new TestURLRequestContext()); | 1371 scoped_refptr<URLRequestContext> context(new TestURLRequestContext()); |
| 1370 TestDelegate d; | 1372 TestDelegate d; |
| 1371 | 1373 |
| 1372 GURL::Replacements replacements; | 1374 GURL::Replacements replacements; |
| 1373 std::string username("user2"); | 1375 std::string username("user2"); |
| 1374 std::string password("secret"); | 1376 std::string password("secret"); |
| 1375 replacements.SetUsernameStr(username); | 1377 replacements.SetUsernameStr(username); |
| 1376 replacements.SetPasswordStr(password); | 1378 replacements.SetPasswordStr(password); |
| 1377 GURL url_with_identity = url_requiring_auth.ReplaceComponents(replacements); | 1379 GURL url_with_identity = url_requiring_auth.ReplaceComponents(replacements); |
| 1378 | 1380 |
| 1379 net::URLRequest r(url_with_identity, &d); | 1381 URLRequest r(url_with_identity, &d); |
| 1380 r.set_context(context); | 1382 r.set_context(context); |
| 1381 r.Start(); | 1383 r.Start(); |
| 1382 | 1384 |
| 1383 MessageLoop::current()->Run(); | 1385 MessageLoop::current()->Run(); |
| 1384 | 1386 |
| 1385 EXPECT_TRUE(d.data_received().find("user2/secret") != std::string::npos); | 1387 EXPECT_TRUE(d.data_received().find("user2/secret") != std::string::npos); |
| 1386 | 1388 |
| 1387 // Make sure we sent the cookie in the restarted transaction. | 1389 // Make sure we sent the cookie in the restarted transaction. |
| 1388 EXPECT_TRUE(d.data_received().find("Cookie: got_challenged=true") | 1390 EXPECT_TRUE(d.data_received().find("Cookie: got_challenged=true") |
| 1389 != std::string::npos); | 1391 != std::string::npos); |
| 1390 } | 1392 } |
| 1391 } | 1393 } |
| 1392 | 1394 |
| 1393 TEST_F(URLRequestTest, DoNotSendCookies) { | 1395 TEST_F(URLRequestTest, DoNotSendCookies) { |
| 1394 net::TestServer test_server(net::TestServer::TYPE_HTTP, FilePath()); | 1396 TestServer test_server(TestServer::TYPE_HTTP, FilePath()); |
| 1395 ASSERT_TRUE(test_server.Start()); | 1397 ASSERT_TRUE(test_server.Start()); |
| 1396 | 1398 |
| 1397 scoped_refptr<net::URLRequestContext> context(new TestURLRequestContext()); | 1399 scoped_refptr<URLRequestContext> context(new TestURLRequestContext()); |
| 1398 | 1400 |
| 1399 // Set up a cookie. | 1401 // Set up a cookie. |
| 1400 { | 1402 { |
| 1401 TestDelegate d; | 1403 TestDelegate d; |
| 1402 net::URLRequest req(test_server.GetURL("set-cookie?CookieToNotSend=1"), &d); | 1404 URLRequest req(test_server.GetURL("set-cookie?CookieToNotSend=1"), &d); |
| 1403 req.set_context(context); | 1405 req.set_context(context); |
| 1404 req.Start(); | 1406 req.Start(); |
| 1405 MessageLoop::current()->Run(); | 1407 MessageLoop::current()->Run(); |
| 1406 EXPECT_EQ(0, d.blocked_get_cookies_count()); | 1408 EXPECT_EQ(0, d.blocked_get_cookies_count()); |
| 1407 EXPECT_EQ(0, d.blocked_set_cookie_count()); | 1409 EXPECT_EQ(0, d.blocked_set_cookie_count()); |
| 1408 } | 1410 } |
| 1409 | 1411 |
| 1410 // Verify that the cookie is set. | 1412 // Verify that the cookie is set. |
| 1411 { | 1413 { |
| 1412 TestDelegate d; | 1414 TestDelegate d; |
| 1413 TestURLRequest req(test_server.GetURL("echoheader?Cookie"), &d); | 1415 TestURLRequest req(test_server.GetURL("echoheader?Cookie"), &d); |
| 1414 req.set_context(context); | 1416 req.set_context(context); |
| 1415 req.Start(); | 1417 req.Start(); |
| 1416 MessageLoop::current()->Run(); | 1418 MessageLoop::current()->Run(); |
| 1417 | 1419 |
| 1418 EXPECT_TRUE(d.data_received().find("CookieToNotSend=1") | 1420 EXPECT_TRUE(d.data_received().find("CookieToNotSend=1") |
| 1419 != std::string::npos); | 1421 != std::string::npos); |
| 1420 EXPECT_EQ(0, d.blocked_get_cookies_count()); | 1422 EXPECT_EQ(0, d.blocked_get_cookies_count()); |
| 1421 EXPECT_EQ(0, d.blocked_set_cookie_count()); | 1423 EXPECT_EQ(0, d.blocked_set_cookie_count()); |
| 1422 } | 1424 } |
| 1423 | 1425 |
| 1424 // Verify that the cookie isn't sent when LOAD_DO_NOT_SEND_COOKIES is set. | 1426 // Verify that the cookie isn't sent when LOAD_DO_NOT_SEND_COOKIES is set. |
| 1425 { | 1427 { |
| 1426 TestDelegate d; | 1428 TestDelegate d; |
| 1427 TestURLRequest req(test_server.GetURL("echoheader?Cookie"), &d); | 1429 TestURLRequest req(test_server.GetURL("echoheader?Cookie"), &d); |
| 1428 req.set_load_flags(net::LOAD_DO_NOT_SEND_COOKIES); | 1430 req.set_load_flags(LOAD_DO_NOT_SEND_COOKIES); |
| 1429 req.set_context(context); | 1431 req.set_context(context); |
| 1430 req.Start(); | 1432 req.Start(); |
| 1431 MessageLoop::current()->Run(); | 1433 MessageLoop::current()->Run(); |
| 1432 | 1434 |
| 1433 EXPECT_TRUE(d.data_received().find("Cookie: CookieToNotSend=1") | 1435 EXPECT_TRUE(d.data_received().find("Cookie: CookieToNotSend=1") |
| 1434 == std::string::npos); | 1436 == std::string::npos); |
| 1435 | 1437 |
| 1436 // LOAD_DO_NOT_SEND_COOKIES does not trigger OnGetCookies. | 1438 // LOAD_DO_NOT_SEND_COOKIES does not trigger OnGetCookies. |
| 1437 EXPECT_EQ(0, d.blocked_get_cookies_count()); | 1439 EXPECT_EQ(0, d.blocked_get_cookies_count()); |
| 1438 EXPECT_EQ(0, d.blocked_set_cookie_count()); | 1440 EXPECT_EQ(0, d.blocked_set_cookie_count()); |
| 1439 } | 1441 } |
| 1440 } | 1442 } |
| 1441 | 1443 |
| 1442 TEST_F(URLRequestTest, DoNotSaveCookies) { | 1444 TEST_F(URLRequestTest, DoNotSaveCookies) { |
| 1443 net::TestServer test_server(net::TestServer::TYPE_HTTP, FilePath()); | 1445 TestServer test_server(TestServer::TYPE_HTTP, FilePath()); |
| 1444 ASSERT_TRUE(test_server.Start()); | 1446 ASSERT_TRUE(test_server.Start()); |
| 1445 | 1447 |
| 1446 scoped_refptr<net::URLRequestContext> context(new TestURLRequestContext()); | 1448 scoped_refptr<URLRequestContext> context(new TestURLRequestContext()); |
| 1447 | 1449 |
| 1448 // Set up a cookie. | 1450 // Set up a cookie. |
| 1449 { | 1451 { |
| 1450 TestDelegate d; | 1452 TestDelegate d; |
| 1451 net::URLRequest req(test_server.GetURL("set-cookie?CookieToNotUpdate=2"), | 1453 URLRequest req(test_server.GetURL("set-cookie?CookieToNotUpdate=2"), |
| 1452 &d); | 1454 &d); |
| 1453 req.set_context(context); | 1455 req.set_context(context); |
| 1454 req.Start(); | 1456 req.Start(); |
| 1455 MessageLoop::current()->Run(); | 1457 MessageLoop::current()->Run(); |
| 1456 | 1458 |
| 1457 EXPECT_EQ(0, d.blocked_get_cookies_count()); | 1459 EXPECT_EQ(0, d.blocked_get_cookies_count()); |
| 1458 EXPECT_EQ(0, d.blocked_set_cookie_count()); | 1460 EXPECT_EQ(0, d.blocked_set_cookie_count()); |
| 1459 EXPECT_EQ(1, d.set_cookie_count()); | 1461 EXPECT_EQ(1, d.set_cookie_count()); |
| 1460 } | 1462 } |
| 1461 | 1463 |
| 1462 // Try to set-up another cookie and update the previous cookie. | 1464 // Try to set-up another cookie and update the previous cookie. |
| 1463 { | 1465 { |
| 1464 TestDelegate d; | 1466 TestDelegate d; |
| 1465 net::URLRequest req(test_server.GetURL( | 1467 URLRequest req(test_server.GetURL( |
| 1466 "set-cookie?CookieToNotSave=1&CookieToNotUpdate=1"), &d); | 1468 "set-cookie?CookieToNotSave=1&CookieToNotUpdate=1"), &d); |
| 1467 req.set_load_flags(net::LOAD_DO_NOT_SAVE_COOKIES); | 1469 req.set_load_flags(LOAD_DO_NOT_SAVE_COOKIES); |
| 1468 req.set_context(context); | 1470 req.set_context(context); |
| 1469 req.Start(); | 1471 req.Start(); |
| 1470 | 1472 |
| 1471 MessageLoop::current()->Run(); | 1473 MessageLoop::current()->Run(); |
| 1472 | 1474 |
| 1473 // LOAD_DO_NOT_SAVE_COOKIES does not trigger OnSetCookie. | 1475 // LOAD_DO_NOT_SAVE_COOKIES does not trigger OnSetCookie. |
| 1474 EXPECT_EQ(0, d.blocked_get_cookies_count()); | 1476 EXPECT_EQ(0, d.blocked_get_cookies_count()); |
| 1475 EXPECT_EQ(0, d.blocked_set_cookie_count()); | 1477 EXPECT_EQ(0, d.blocked_set_cookie_count()); |
| 1476 EXPECT_EQ(0, d.set_cookie_count()); | 1478 EXPECT_EQ(0, d.set_cookie_count()); |
| 1477 } | 1479 } |
| (...skipping 11 matching lines...) Expand all Loading... |
| 1489 EXPECT_TRUE(d.data_received().find("CookieToNotUpdate=2") | 1491 EXPECT_TRUE(d.data_received().find("CookieToNotUpdate=2") |
| 1490 != std::string::npos); | 1492 != std::string::npos); |
| 1491 | 1493 |
| 1492 EXPECT_EQ(0, d.blocked_get_cookies_count()); | 1494 EXPECT_EQ(0, d.blocked_get_cookies_count()); |
| 1493 EXPECT_EQ(0, d.blocked_set_cookie_count()); | 1495 EXPECT_EQ(0, d.blocked_set_cookie_count()); |
| 1494 EXPECT_EQ(0, d.set_cookie_count()); | 1496 EXPECT_EQ(0, d.set_cookie_count()); |
| 1495 } | 1497 } |
| 1496 } | 1498 } |
| 1497 | 1499 |
| 1498 TEST_F(URLRequestTest, DoNotSendCookies_ViaPolicy) { | 1500 TEST_F(URLRequestTest, DoNotSendCookies_ViaPolicy) { |
| 1499 net::TestServer test_server(net::TestServer::TYPE_HTTP, FilePath()); | 1501 TestServer test_server(TestServer::TYPE_HTTP, FilePath()); |
| 1500 ASSERT_TRUE(test_server.Start()); | 1502 ASSERT_TRUE(test_server.Start()); |
| 1501 | 1503 |
| 1502 scoped_refptr<TestURLRequestContext> context(new TestURLRequestContext()); | 1504 scoped_refptr<TestURLRequestContext> context(new TestURLRequestContext()); |
| 1503 | 1505 |
| 1504 // Set up a cookie. | 1506 // Set up a cookie. |
| 1505 { | 1507 { |
| 1506 TestDelegate d; | 1508 TestDelegate d; |
| 1507 net::URLRequest req(test_server.GetURL("set-cookie?CookieToNotSend=1"), &d); | 1509 URLRequest req(test_server.GetURL("set-cookie?CookieToNotSend=1"), &d); |
| 1508 req.set_context(context); | 1510 req.set_context(context); |
| 1509 req.Start(); | 1511 req.Start(); |
| 1510 MessageLoop::current()->Run(); | 1512 MessageLoop::current()->Run(); |
| 1511 | 1513 |
| 1512 EXPECT_EQ(0, d.blocked_get_cookies_count()); | 1514 EXPECT_EQ(0, d.blocked_get_cookies_count()); |
| 1513 EXPECT_EQ(0, d.blocked_set_cookie_count()); | 1515 EXPECT_EQ(0, d.blocked_set_cookie_count()); |
| 1514 } | 1516 } |
| 1515 | 1517 |
| 1516 // Verify that the cookie is set. | 1518 // Verify that the cookie is set. |
| 1517 { | 1519 { |
| (...skipping 25 matching lines...) Expand all Loading... |
| 1543 == std::string::npos); | 1545 == std::string::npos); |
| 1544 | 1546 |
| 1545 context->set_cookie_policy(NULL); | 1547 context->set_cookie_policy(NULL); |
| 1546 | 1548 |
| 1547 EXPECT_EQ(1, d.blocked_get_cookies_count()); | 1549 EXPECT_EQ(1, d.blocked_get_cookies_count()); |
| 1548 EXPECT_EQ(0, d.blocked_set_cookie_count()); | 1550 EXPECT_EQ(0, d.blocked_set_cookie_count()); |
| 1549 } | 1551 } |
| 1550 } | 1552 } |
| 1551 | 1553 |
| 1552 TEST_F(URLRequestTest, DoNotSaveCookies_ViaPolicy) { | 1554 TEST_F(URLRequestTest, DoNotSaveCookies_ViaPolicy) { |
| 1553 net::TestServer test_server(net::TestServer::TYPE_HTTP, FilePath()); | 1555 TestServer test_server(TestServer::TYPE_HTTP, FilePath()); |
| 1554 ASSERT_TRUE(test_server.Start()); | 1556 ASSERT_TRUE(test_server.Start()); |
| 1555 | 1557 |
| 1556 scoped_refptr<TestURLRequestContext> context(new TestURLRequestContext()); | 1558 scoped_refptr<TestURLRequestContext> context(new TestURLRequestContext()); |
| 1557 | 1559 |
| 1558 // Set up a cookie. | 1560 // Set up a cookie. |
| 1559 { | 1561 { |
| 1560 TestDelegate d; | 1562 TestDelegate d; |
| 1561 net::URLRequest req(test_server.GetURL("set-cookie?CookieToNotUpdate=2"), | 1563 URLRequest req(test_server.GetURL("set-cookie?CookieToNotUpdate=2"), |
| 1562 &d); | 1564 &d); |
| 1563 req.set_context(context); | 1565 req.set_context(context); |
| 1564 req.Start(); | 1566 req.Start(); |
| 1565 MessageLoop::current()->Run(); | 1567 MessageLoop::current()->Run(); |
| 1566 | 1568 |
| 1567 EXPECT_EQ(0, d.blocked_get_cookies_count()); | 1569 EXPECT_EQ(0, d.blocked_get_cookies_count()); |
| 1568 EXPECT_EQ(0, d.blocked_set_cookie_count()); | 1570 EXPECT_EQ(0, d.blocked_set_cookie_count()); |
| 1569 } | 1571 } |
| 1570 | 1572 |
| 1571 // Try to set-up another cookie and update the previous cookie. | 1573 // Try to set-up another cookie and update the previous cookie. |
| 1572 { | 1574 { |
| 1573 TestCookiePolicy cookie_policy(TestCookiePolicy::NO_SET_COOKIE); | 1575 TestCookiePolicy cookie_policy(TestCookiePolicy::NO_SET_COOKIE); |
| 1574 context->set_cookie_policy(&cookie_policy); | 1576 context->set_cookie_policy(&cookie_policy); |
| 1575 | 1577 |
| 1576 TestDelegate d; | 1578 TestDelegate d; |
| 1577 net::URLRequest req(test_server.GetURL( | 1579 URLRequest req(test_server.GetURL( |
| 1578 "set-cookie?CookieToNotSave=1&CookieToNotUpdate=1"), &d); | 1580 "set-cookie?CookieToNotSave=1&CookieToNotUpdate=1"), &d); |
| 1579 req.set_context(context); | 1581 req.set_context(context); |
| 1580 req.Start(); | 1582 req.Start(); |
| 1581 | 1583 |
| 1582 MessageLoop::current()->Run(); | 1584 MessageLoop::current()->Run(); |
| 1583 | 1585 |
| 1584 context->set_cookie_policy(NULL); | 1586 context->set_cookie_policy(NULL); |
| 1585 | 1587 |
| 1586 EXPECT_EQ(0, d.blocked_get_cookies_count()); | 1588 EXPECT_EQ(0, d.blocked_get_cookies_count()); |
| 1587 EXPECT_EQ(2, d.blocked_set_cookie_count()); | 1589 EXPECT_EQ(2, d.blocked_set_cookie_count()); |
| (...skipping 12 matching lines...) Expand all Loading... |
| 1600 == std::string::npos); | 1602 == std::string::npos); |
| 1601 EXPECT_TRUE(d.data_received().find("CookieToNotUpdate=2") | 1603 EXPECT_TRUE(d.data_received().find("CookieToNotUpdate=2") |
| 1602 != std::string::npos); | 1604 != std::string::npos); |
| 1603 | 1605 |
| 1604 EXPECT_EQ(0, d.blocked_get_cookies_count()); | 1606 EXPECT_EQ(0, d.blocked_get_cookies_count()); |
| 1605 EXPECT_EQ(0, d.blocked_set_cookie_count()); | 1607 EXPECT_EQ(0, d.blocked_set_cookie_count()); |
| 1606 } | 1608 } |
| 1607 } | 1609 } |
| 1608 | 1610 |
| 1609 TEST_F(URLRequestTest, DoNotSaveEmptyCookies) { | 1611 TEST_F(URLRequestTest, DoNotSaveEmptyCookies) { |
| 1610 net::TestServer test_server(net::TestServer::TYPE_HTTP, FilePath()); | 1612 TestServer test_server(TestServer::TYPE_HTTP, FilePath()); |
| 1611 ASSERT_TRUE(test_server.Start()); | 1613 ASSERT_TRUE(test_server.Start()); |
| 1612 | 1614 |
| 1613 scoped_refptr<TestURLRequestContext> context(new TestURLRequestContext()); | 1615 scoped_refptr<TestURLRequestContext> context(new TestURLRequestContext()); |
| 1614 | 1616 |
| 1615 // Set up an empty cookie. | 1617 // Set up an empty cookie. |
| 1616 { | 1618 { |
| 1617 TestDelegate d; | 1619 TestDelegate d; |
| 1618 net::URLRequest req(test_server.GetURL("set-cookie"), &d); | 1620 URLRequest req(test_server.GetURL("set-cookie"), &d); |
| 1619 req.set_context(context); | 1621 req.set_context(context); |
| 1620 req.Start(); | 1622 req.Start(); |
| 1621 MessageLoop::current()->Run(); | 1623 MessageLoop::current()->Run(); |
| 1622 | 1624 |
| 1623 EXPECT_EQ(0, d.blocked_get_cookies_count()); | 1625 EXPECT_EQ(0, d.blocked_get_cookies_count()); |
| 1624 EXPECT_EQ(0, d.blocked_set_cookie_count()); | 1626 EXPECT_EQ(0, d.blocked_set_cookie_count()); |
| 1625 EXPECT_EQ(0, d.set_cookie_count()); | 1627 EXPECT_EQ(0, d.set_cookie_count()); |
| 1626 } | 1628 } |
| 1627 } | 1629 } |
| 1628 | 1630 |
| 1629 TEST_F(URLRequestTest, DoNotSendCookies_ViaPolicy_Async) { | 1631 TEST_F(URLRequestTest, DoNotSendCookies_ViaPolicy_Async) { |
| 1630 net::TestServer test_server(net::TestServer::TYPE_HTTP, FilePath()); | 1632 TestServer test_server(TestServer::TYPE_HTTP, FilePath()); |
| 1631 ASSERT_TRUE(test_server.Start()); | 1633 ASSERT_TRUE(test_server.Start()); |
| 1632 | 1634 |
| 1633 scoped_refptr<TestURLRequestContext> context(new TestURLRequestContext()); | 1635 scoped_refptr<TestURLRequestContext> context(new TestURLRequestContext()); |
| 1634 | 1636 |
| 1635 // Set up a cookie. | 1637 // Set up a cookie. |
| 1636 { | 1638 { |
| 1637 TestDelegate d; | 1639 TestDelegate d; |
| 1638 net::URLRequest req(test_server.GetURL("set-cookie?CookieToNotSend=1"), &d); | 1640 URLRequest req(test_server.GetURL("set-cookie?CookieToNotSend=1"), &d); |
| 1639 req.set_context(context); | 1641 req.set_context(context); |
| 1640 req.Start(); | 1642 req.Start(); |
| 1641 MessageLoop::current()->Run(); | 1643 MessageLoop::current()->Run(); |
| 1642 | 1644 |
| 1643 EXPECT_EQ(0, d.blocked_get_cookies_count()); | 1645 EXPECT_EQ(0, d.blocked_get_cookies_count()); |
| 1644 EXPECT_EQ(0, d.blocked_set_cookie_count()); | 1646 EXPECT_EQ(0, d.blocked_set_cookie_count()); |
| 1645 } | 1647 } |
| 1646 | 1648 |
| 1647 // Verify that the cookie is set. | 1649 // Verify that the cookie is set. |
| 1648 { | 1650 { |
| (...skipping 26 matching lines...) Expand all Loading... |
| 1675 == std::string::npos); | 1677 == std::string::npos); |
| 1676 | 1678 |
| 1677 context->set_cookie_policy(NULL); | 1679 context->set_cookie_policy(NULL); |
| 1678 | 1680 |
| 1679 EXPECT_EQ(1, d.blocked_get_cookies_count()); | 1681 EXPECT_EQ(1, d.blocked_get_cookies_count()); |
| 1680 EXPECT_EQ(0, d.blocked_set_cookie_count()); | 1682 EXPECT_EQ(0, d.blocked_set_cookie_count()); |
| 1681 } | 1683 } |
| 1682 } | 1684 } |
| 1683 | 1685 |
| 1684 TEST_F(URLRequestTest, DoNotSaveCookies_ViaPolicy_Async) { | 1686 TEST_F(URLRequestTest, DoNotSaveCookies_ViaPolicy_Async) { |
| 1685 net::TestServer test_server(net::TestServer::TYPE_HTTP, FilePath()); | 1687 TestServer test_server(TestServer::TYPE_HTTP, FilePath()); |
| 1686 ASSERT_TRUE(test_server.Start()); | 1688 ASSERT_TRUE(test_server.Start()); |
| 1687 | 1689 |
| 1688 scoped_refptr<TestURLRequestContext> context(new TestURLRequestContext()); | 1690 scoped_refptr<TestURLRequestContext> context(new TestURLRequestContext()); |
| 1689 | 1691 |
| 1690 // Set up a cookie. | 1692 // Set up a cookie. |
| 1691 { | 1693 { |
| 1692 TestDelegate d; | 1694 TestDelegate d; |
| 1693 net::URLRequest req(test_server.GetURL("set-cookie?CookieToNotUpdate=2"), | 1695 URLRequest req(test_server.GetURL("set-cookie?CookieToNotUpdate=2"), |
| 1694 &d); | 1696 &d); |
| 1695 req.set_context(context); | 1697 req.set_context(context); |
| 1696 req.Start(); | 1698 req.Start(); |
| 1697 MessageLoop::current()->Run(); | 1699 MessageLoop::current()->Run(); |
| 1698 | 1700 |
| 1699 EXPECT_EQ(0, d.blocked_get_cookies_count()); | 1701 EXPECT_EQ(0, d.blocked_get_cookies_count()); |
| 1700 EXPECT_EQ(0, d.blocked_set_cookie_count()); | 1702 EXPECT_EQ(0, d.blocked_set_cookie_count()); |
| 1701 } | 1703 } |
| 1702 | 1704 |
| 1703 // Try to set-up another cookie and update the previous cookie. | 1705 // Try to set-up another cookie and update the previous cookie. |
| 1704 { | 1706 { |
| 1705 TestCookiePolicy cookie_policy(TestCookiePolicy::NO_SET_COOKIE | | 1707 TestCookiePolicy cookie_policy(TestCookiePolicy::NO_SET_COOKIE | |
| 1706 TestCookiePolicy::ASYNC); | 1708 TestCookiePolicy::ASYNC); |
| 1707 context->set_cookie_policy(&cookie_policy); | 1709 context->set_cookie_policy(&cookie_policy); |
| 1708 | 1710 |
| 1709 TestDelegate d; | 1711 TestDelegate d; |
| 1710 net::URLRequest req(test_server.GetURL( | 1712 URLRequest req(test_server.GetURL( |
| 1711 "set-cookie?CookieToNotSave=1&CookieToNotUpdate=1"), &d); | 1713 "set-cookie?CookieToNotSave=1&CookieToNotUpdate=1"), &d); |
| 1712 req.set_context(context); | 1714 req.set_context(context); |
| 1713 req.Start(); | 1715 req.Start(); |
| 1714 | 1716 |
| 1715 MessageLoop::current()->Run(); | 1717 MessageLoop::current()->Run(); |
| 1716 | 1718 |
| 1717 context->set_cookie_policy(NULL); | 1719 context->set_cookie_policy(NULL); |
| 1718 | 1720 |
| 1719 EXPECT_EQ(0, d.blocked_get_cookies_count()); | 1721 EXPECT_EQ(0, d.blocked_get_cookies_count()); |
| 1720 EXPECT_EQ(2, d.blocked_set_cookie_count()); | 1722 EXPECT_EQ(2, d.blocked_set_cookie_count()); |
| (...skipping 11 matching lines...) Expand all Loading... |
| 1732 == std::string::npos); | 1734 == std::string::npos); |
| 1733 EXPECT_TRUE(d.data_received().find("CookieToNotUpdate=2") | 1735 EXPECT_TRUE(d.data_received().find("CookieToNotUpdate=2") |
| 1734 != std::string::npos); | 1736 != std::string::npos); |
| 1735 | 1737 |
| 1736 EXPECT_EQ(0, d.blocked_get_cookies_count()); | 1738 EXPECT_EQ(0, d.blocked_get_cookies_count()); |
| 1737 EXPECT_EQ(0, d.blocked_set_cookie_count()); | 1739 EXPECT_EQ(0, d.blocked_set_cookie_count()); |
| 1738 } | 1740 } |
| 1739 } | 1741 } |
| 1740 | 1742 |
| 1741 TEST_F(URLRequestTest, CancelTest_During_CookiePolicy) { | 1743 TEST_F(URLRequestTest, CancelTest_During_CookiePolicy) { |
| 1742 net::TestServer test_server(net::TestServer::TYPE_HTTP, FilePath()); | 1744 TestServer test_server(TestServer::TYPE_HTTP, FilePath()); |
| 1743 ASSERT_TRUE(test_server.Start()); | 1745 ASSERT_TRUE(test_server.Start()); |
| 1744 | 1746 |
| 1745 scoped_refptr<TestURLRequestContext> context(new TestURLRequestContext()); | 1747 scoped_refptr<TestURLRequestContext> context(new TestURLRequestContext()); |
| 1746 | 1748 |
| 1747 TestCookiePolicy cookie_policy(TestCookiePolicy::ASYNC); | 1749 TestCookiePolicy cookie_policy(TestCookiePolicy::ASYNC); |
| 1748 context->set_cookie_policy(&cookie_policy); | 1750 context->set_cookie_policy(&cookie_policy); |
| 1749 | 1751 |
| 1750 // Set up a cookie. | 1752 // Set up a cookie. |
| 1751 { | 1753 { |
| 1752 TestDelegate d; | 1754 TestDelegate d; |
| 1753 net::URLRequest req(test_server.GetURL("set-cookie?A=1&B=2&C=3"), | 1755 URLRequest req(test_server.GetURL("set-cookie?A=1&B=2&C=3"), |
| 1754 &d); | 1756 &d); |
| 1755 req.set_context(context); | 1757 req.set_context(context); |
| 1756 req.Start(); // Triggers an asynchronous cookie policy check. | 1758 req.Start(); // Triggers an asynchronous cookie policy check. |
| 1757 | 1759 |
| 1758 // But, now we cancel the request by letting it go out of scope. This | 1760 // But, now we cancel the request by letting it go out of scope. This |
| 1759 // should not cause a crash. | 1761 // should not cause a crash. |
| 1760 | 1762 |
| 1761 EXPECT_EQ(0, d.blocked_get_cookies_count()); | 1763 EXPECT_EQ(0, d.blocked_get_cookies_count()); |
| 1762 EXPECT_EQ(0, d.blocked_set_cookie_count()); | 1764 EXPECT_EQ(0, d.blocked_set_cookie_count()); |
| 1763 } | 1765 } |
| 1764 | 1766 |
| 1765 context->set_cookie_policy(NULL); | 1767 context->set_cookie_policy(NULL); |
| 1766 | 1768 |
| 1767 // Let the cookie policy complete. Make sure it handles the destruction of | 1769 // Let the cookie policy complete. Make sure it handles the destruction of |
| 1768 // the net::URLRequest properly. | 1770 // the URLRequest properly. |
| 1769 MessageLoop::current()->RunAllPending(); | 1771 MessageLoop::current()->RunAllPending(); |
| 1770 } | 1772 } |
| 1771 | 1773 |
| 1772 TEST_F(URLRequestTest, CancelTest_During_OnGetCookies) { | 1774 TEST_F(URLRequestTest, CancelTest_During_OnGetCookies) { |
| 1773 net::TestServer test_server(net::TestServer::TYPE_HTTP, FilePath()); | 1775 TestServer test_server(TestServer::TYPE_HTTP, FilePath()); |
| 1774 ASSERT_TRUE(test_server.Start()); | 1776 ASSERT_TRUE(test_server.Start()); |
| 1775 | 1777 |
| 1776 scoped_refptr<TestURLRequestContext> context(new TestURLRequestContext()); | 1778 scoped_refptr<TestURLRequestContext> context(new TestURLRequestContext()); |
| 1777 | 1779 |
| 1778 TestCookiePolicy cookie_policy(TestCookiePolicy::NO_GET_COOKIES); | 1780 TestCookiePolicy cookie_policy(TestCookiePolicy::NO_GET_COOKIES); |
| 1779 context->set_cookie_policy(&cookie_policy); | 1781 context->set_cookie_policy(&cookie_policy); |
| 1780 | 1782 |
| 1781 // Set up a cookie. | 1783 // Set up a cookie. |
| 1782 { | 1784 { |
| 1783 TestDelegate d; | 1785 TestDelegate d; |
| 1784 d.set_cancel_in_get_cookies_blocked(true); | 1786 d.set_cancel_in_get_cookies_blocked(true); |
| 1785 net::URLRequest req(test_server.GetURL("set-cookie?A=1&B=2&C=3"), | 1787 URLRequest req(test_server.GetURL("set-cookie?A=1&B=2&C=3"), |
| 1786 &d); | 1788 &d); |
| 1787 req.set_context(context); | 1789 req.set_context(context); |
| 1788 req.Start(); // Triggers an asynchronous cookie policy check. | 1790 req.Start(); // Triggers an asynchronous cookie policy check. |
| 1789 | 1791 |
| 1790 MessageLoop::current()->Run(); | 1792 MessageLoop::current()->Run(); |
| 1791 | 1793 |
| 1792 EXPECT_EQ(net::URLRequestStatus::CANCELED, req.status().status()); | 1794 EXPECT_EQ(URLRequestStatus::CANCELED, req.status().status()); |
| 1793 | 1795 |
| 1794 EXPECT_EQ(1, d.blocked_get_cookies_count()); | 1796 EXPECT_EQ(1, d.blocked_get_cookies_count()); |
| 1795 EXPECT_EQ(0, d.blocked_set_cookie_count()); | 1797 EXPECT_EQ(0, d.blocked_set_cookie_count()); |
| 1796 } | 1798 } |
| 1797 | 1799 |
| 1798 context->set_cookie_policy(NULL); | 1800 context->set_cookie_policy(NULL); |
| 1799 } | 1801 } |
| 1800 | 1802 |
| 1801 TEST_F(URLRequestTest, CancelTest_During_OnSetCookie) { | 1803 TEST_F(URLRequestTest, CancelTest_During_OnSetCookie) { |
| 1802 net::TestServer test_server(net::TestServer::TYPE_HTTP, FilePath()); | 1804 TestServer test_server(TestServer::TYPE_HTTP, FilePath()); |
| 1803 ASSERT_TRUE(test_server.Start()); | 1805 ASSERT_TRUE(test_server.Start()); |
| 1804 | 1806 |
| 1805 scoped_refptr<TestURLRequestContext> context(new TestURLRequestContext()); | 1807 scoped_refptr<TestURLRequestContext> context(new TestURLRequestContext()); |
| 1806 | 1808 |
| 1807 TestCookiePolicy cookie_policy(TestCookiePolicy::NO_SET_COOKIE); | 1809 TestCookiePolicy cookie_policy(TestCookiePolicy::NO_SET_COOKIE); |
| 1808 context->set_cookie_policy(&cookie_policy); | 1810 context->set_cookie_policy(&cookie_policy); |
| 1809 | 1811 |
| 1810 // Set up a cookie. | 1812 // Set up a cookie. |
| 1811 { | 1813 { |
| 1812 TestDelegate d; | 1814 TestDelegate d; |
| 1813 d.set_cancel_in_set_cookie_blocked(true); | 1815 d.set_cancel_in_set_cookie_blocked(true); |
| 1814 net::URLRequest req(test_server.GetURL("set-cookie?A=1&B=2&C=3"), | 1816 URLRequest req(test_server.GetURL("set-cookie?A=1&B=2&C=3"), |
| 1815 &d); | 1817 &d); |
| 1816 req.set_context(context); | 1818 req.set_context(context); |
| 1817 req.Start(); // Triggers an asynchronous cookie policy check. | 1819 req.Start(); // Triggers an asynchronous cookie policy check. |
| 1818 | 1820 |
| 1819 MessageLoop::current()->Run(); | 1821 MessageLoop::current()->Run(); |
| 1820 | 1822 |
| 1821 EXPECT_EQ(net::URLRequestStatus::CANCELED, req.status().status()); | 1823 EXPECT_EQ(URLRequestStatus::CANCELED, req.status().status()); |
| 1822 | 1824 |
| 1823 // Even though the response will contain 3 set-cookie headers, we expect | 1825 // Even though the response will contain 3 set-cookie headers, we expect |
| 1824 // only one to be blocked as that first one will cause OnSetCookie to be | 1826 // only one to be blocked as that first one will cause OnSetCookie to be |
| 1825 // called, which will cancel the request. Once canceled, it should not | 1827 // called, which will cancel the request. Once canceled, it should not |
| 1826 // attempt to set further cookies. | 1828 // attempt to set further cookies. |
| 1827 | 1829 |
| 1828 EXPECT_EQ(0, d.blocked_get_cookies_count()); | 1830 EXPECT_EQ(0, d.blocked_get_cookies_count()); |
| 1829 EXPECT_EQ(1, d.blocked_set_cookie_count()); | 1831 EXPECT_EQ(1, d.blocked_set_cookie_count()); |
| 1830 } | 1832 } |
| 1831 | 1833 |
| 1832 context->set_cookie_policy(NULL); | 1834 context->set_cookie_policy(NULL); |
| 1833 } | 1835 } |
| 1834 | 1836 |
| 1835 TEST_F(URLRequestTest, CookiePolicy_ForceSession) { | 1837 TEST_F(URLRequestTest, CookiePolicy_ForceSession) { |
| 1836 net::TestServer test_server(net::TestServer::TYPE_HTTP, FilePath()); | 1838 TestServer test_server(TestServer::TYPE_HTTP, FilePath()); |
| 1837 ASSERT_TRUE(test_server.Start()); | 1839 ASSERT_TRUE(test_server.Start()); |
| 1838 | 1840 |
| 1839 scoped_refptr<TestURLRequestContext> context(new TestURLRequestContext()); | 1841 scoped_refptr<TestURLRequestContext> context(new TestURLRequestContext()); |
| 1840 | 1842 |
| 1841 TestCookiePolicy cookie_policy(TestCookiePolicy::FORCE_SESSION); | 1843 TestCookiePolicy cookie_policy(TestCookiePolicy::FORCE_SESSION); |
| 1842 context->set_cookie_policy(&cookie_policy); | 1844 context->set_cookie_policy(&cookie_policy); |
| 1843 | 1845 |
| 1844 // Set up a cookie. | 1846 // Set up a cookie. |
| 1845 { | 1847 { |
| 1846 TestDelegate d; | 1848 TestDelegate d; |
| 1847 net::URLRequest req(test_server.GetURL( | 1849 URLRequest req(test_server.GetURL( |
| 1848 "set-cookie?A=1;expires=\"Fri, 05 Feb 2010 23:42:01 GMT\""), &d); | 1850 "set-cookie?A=1;expires=\"Fri, 05 Feb 2010 23:42:01 GMT\""), &d); |
| 1849 req.set_context(context); | 1851 req.set_context(context); |
| 1850 req.Start(); // Triggers an asynchronous cookie policy check. | 1852 req.Start(); // Triggers an asynchronous cookie policy check. |
| 1851 | 1853 |
| 1852 MessageLoop::current()->Run(); | 1854 MessageLoop::current()->Run(); |
| 1853 | 1855 |
| 1854 EXPECT_EQ(0, d.blocked_get_cookies_count()); | 1856 EXPECT_EQ(0, d.blocked_get_cookies_count()); |
| 1855 EXPECT_EQ(0, d.blocked_set_cookie_count()); | 1857 EXPECT_EQ(0, d.blocked_set_cookie_count()); |
| 1856 } | 1858 } |
| 1857 | 1859 |
| 1858 // Now, check the cookie store. | 1860 // Now, check the cookie store. |
| 1859 net::CookieList cookies = | 1861 CookieList cookies = |
| 1860 context->cookie_store()->GetCookieMonster()->GetAllCookies(); | 1862 context->cookie_store()->GetCookieMonster()->GetAllCookies(); |
| 1861 EXPECT_EQ(1U, cookies.size()); | 1863 EXPECT_EQ(1U, cookies.size()); |
| 1862 EXPECT_FALSE(cookies[0].IsPersistent()); | 1864 EXPECT_FALSE(cookies[0].IsPersistent()); |
| 1863 | 1865 |
| 1864 context->set_cookie_policy(NULL); | 1866 context->set_cookie_policy(NULL); |
| 1865 } | 1867 } |
| 1866 | 1868 |
| 1867 // In this test, we do a POST which the server will 302 redirect. | 1869 // In this test, we do a POST which the server will 302 redirect. |
| 1868 // The subsequent transaction should use GET, and should not send the | 1870 // The subsequent transaction should use GET, and should not send the |
| 1869 // Content-Type header. | 1871 // Content-Type header. |
| 1870 // http://code.google.com/p/chromium/issues/detail?id=843 | 1872 // http://code.google.com/p/chromium/issues/detail?id=843 |
| 1871 TEST_F(URLRequestTestHTTP, Post302RedirectGet) { | 1873 TEST_F(URLRequestTestHTTP, Post302RedirectGet) { |
| 1872 ASSERT_TRUE(test_server_.Start()); | 1874 ASSERT_TRUE(test_server_.Start()); |
| 1873 | 1875 |
| 1874 const char kData[] = "hello world"; | 1876 const char kData[] = "hello world"; |
| 1875 | 1877 |
| 1876 TestDelegate d; | 1878 TestDelegate d; |
| 1877 TestURLRequest req(test_server_.GetURL("files/redirect-to-echoall"), &d); | 1879 TestURLRequest req(test_server_.GetURL("files/redirect-to-echoall"), &d); |
| 1878 req.set_method("POST"); | 1880 req.set_method("POST"); |
| 1879 req.set_upload(CreateSimpleUploadData(kData)); | 1881 req.set_upload(CreateSimpleUploadData(kData)); |
| 1880 | 1882 |
| 1881 // Set headers (some of which are specific to the POST). | 1883 // Set headers (some of which are specific to the POST). |
| 1882 net::HttpRequestHeaders headers; | 1884 HttpRequestHeaders headers; |
| 1883 headers.AddHeadersFromString( | 1885 headers.AddHeadersFromString( |
| 1884 "Content-Type: multipart/form-data; " | 1886 "Content-Type: multipart/form-data; " |
| 1885 "boundary=----WebKitFormBoundaryAADeAA+NAAWMAAwZ\r\n" | 1887 "boundary=----WebKitFormBoundaryAADeAA+NAAWMAAwZ\r\n" |
| 1886 "Accept: text/xml,application/xml,application/xhtml+xml,text/html;q=0.9," | 1888 "Accept: text/xml,application/xml,application/xhtml+xml,text/html;q=0.9," |
| 1887 "text/plain;q=0.8,image/png,*/*;q=0.5\r\n" | 1889 "text/plain;q=0.8,image/png,*/*;q=0.5\r\n" |
| 1888 "Accept-Language: en-US,en\r\n" | 1890 "Accept-Language: en-US,en\r\n" |
| 1889 "Accept-Charset: ISO-8859-1,*,utf-8\r\n" | 1891 "Accept-Charset: ISO-8859-1,*,utf-8\r\n" |
| 1890 "Content-Length: 11\r\n" | 1892 "Content-Length: 11\r\n" |
| 1891 "Origin: http://localhost:1337/"); | 1893 "Origin: http://localhost:1337/"); |
| 1892 req.SetExtraRequestHeaders(headers); | 1894 req.SetExtraRequestHeaders(headers); |
| (...skipping 20 matching lines...) Expand all Loading... |
| 1913 TEST_F(URLRequestTestHTTP, Post307RedirectPost) { | 1915 TEST_F(URLRequestTestHTTP, Post307RedirectPost) { |
| 1914 ASSERT_TRUE(test_server_.Start()); | 1916 ASSERT_TRUE(test_server_.Start()); |
| 1915 | 1917 |
| 1916 const char kData[] = "hello world"; | 1918 const char kData[] = "hello world"; |
| 1917 | 1919 |
| 1918 TestDelegate d; | 1920 TestDelegate d; |
| 1919 TestURLRequest req(test_server_.GetURL("files/redirect307-to-echo"), | 1921 TestURLRequest req(test_server_.GetURL("files/redirect307-to-echo"), |
| 1920 &d); | 1922 &d); |
| 1921 req.set_method("POST"); | 1923 req.set_method("POST"); |
| 1922 req.set_upload(CreateSimpleUploadData(kData).get()); | 1924 req.set_upload(CreateSimpleUploadData(kData).get()); |
| 1923 net::HttpRequestHeaders headers; | 1925 HttpRequestHeaders headers; |
| 1924 headers.SetHeader(net::HttpRequestHeaders::kContentLength, | 1926 headers.SetHeader(HttpRequestHeaders::kContentLength, |
| 1925 base::UintToString(arraysize(kData) - 1)); | 1927 base::UintToString(arraysize(kData) - 1)); |
| 1926 req.SetExtraRequestHeaders(headers); | 1928 req.SetExtraRequestHeaders(headers); |
| 1927 req.Start(); | 1929 req.Start(); |
| 1928 MessageLoop::current()->Run(); | 1930 MessageLoop::current()->Run(); |
| 1929 EXPECT_EQ("POST", req.method()); | 1931 EXPECT_EQ("POST", req.method()); |
| 1930 EXPECT_EQ(kData, d.data_received()); | 1932 EXPECT_EQ(kData, d.data_received()); |
| 1931 } | 1933 } |
| 1932 | 1934 |
| 1933 // Custom URLRequestJobs for use with interceptor tests | 1935 // Custom URLRequestJobs for use with interceptor tests |
| 1934 class RestartTestJob : public net::URLRequestTestJob { | 1936 class RestartTestJob : public URLRequestTestJob { |
| 1935 public: | 1937 public: |
| 1936 explicit RestartTestJob(net::URLRequest* request) | 1938 explicit RestartTestJob(URLRequest* request) |
| 1937 : net::URLRequestTestJob(request, true) {} | 1939 : URLRequestTestJob(request, true) {} |
| 1938 protected: | 1940 protected: |
| 1939 virtual void StartAsync() { | 1941 virtual void StartAsync() { |
| 1940 this->NotifyRestartRequired(); | 1942 this->NotifyRestartRequired(); |
| 1941 } | 1943 } |
| 1942 private: | 1944 private: |
| 1943 ~RestartTestJob() {} | 1945 ~RestartTestJob() {} |
| 1944 }; | 1946 }; |
| 1945 | 1947 |
| 1946 class CancelTestJob : public net::URLRequestTestJob { | 1948 class CancelTestJob : public URLRequestTestJob { |
| 1947 public: | 1949 public: |
| 1948 explicit CancelTestJob(net::URLRequest* request) | 1950 explicit CancelTestJob(URLRequest* request) |
| 1949 : net::URLRequestTestJob(request, true) {} | 1951 : URLRequestTestJob(request, true) {} |
| 1950 protected: | 1952 protected: |
| 1951 virtual void StartAsync() { | 1953 virtual void StartAsync() { |
| 1952 request_->Cancel(); | 1954 request_->Cancel(); |
| 1953 } | 1955 } |
| 1954 private: | 1956 private: |
| 1955 ~CancelTestJob() {} | 1957 ~CancelTestJob() {} |
| 1956 }; | 1958 }; |
| 1957 | 1959 |
| 1958 class CancelThenRestartTestJob : public net::URLRequestTestJob { | 1960 class CancelThenRestartTestJob : public URLRequestTestJob { |
| 1959 public: | 1961 public: |
| 1960 explicit CancelThenRestartTestJob(net::URLRequest* request) | 1962 explicit CancelThenRestartTestJob(URLRequest* request) |
| 1961 : net::URLRequestTestJob(request, true) { | 1963 : URLRequestTestJob(request, true) { |
| 1962 } | 1964 } |
| 1963 protected: | 1965 protected: |
| 1964 virtual void StartAsync() { | 1966 virtual void StartAsync() { |
| 1965 request_->Cancel(); | 1967 request_->Cancel(); |
| 1966 this->NotifyRestartRequired(); | 1968 this->NotifyRestartRequired(); |
| 1967 } | 1969 } |
| 1968 private: | 1970 private: |
| 1969 ~CancelThenRestartTestJob() {} | 1971 ~CancelThenRestartTestJob() {} |
| 1970 }; | 1972 }; |
| 1971 | 1973 |
| 1972 // An Interceptor for use with interceptor tests | 1974 // An Interceptor for use with interceptor tests |
| 1973 class TestInterceptor : net::URLRequest::Interceptor { | 1975 class TestInterceptor : URLRequest::Interceptor { |
| 1974 public: | 1976 public: |
| 1975 TestInterceptor() | 1977 TestInterceptor() |
| 1976 : intercept_main_request_(false), restart_main_request_(false), | 1978 : intercept_main_request_(false), restart_main_request_(false), |
| 1977 cancel_main_request_(false), cancel_then_restart_main_request_(false), | 1979 cancel_main_request_(false), cancel_then_restart_main_request_(false), |
| 1978 simulate_main_network_error_(false), | 1980 simulate_main_network_error_(false), |
| 1979 intercept_redirect_(false), cancel_redirect_request_(false), | 1981 intercept_redirect_(false), cancel_redirect_request_(false), |
| 1980 intercept_final_response_(false), cancel_final_request_(false), | 1982 intercept_final_response_(false), cancel_final_request_(false), |
| 1981 did_intercept_main_(false), did_restart_main_(false), | 1983 did_intercept_main_(false), did_restart_main_(false), |
| 1982 did_cancel_main_(false), did_cancel_then_restart_main_(false), | 1984 did_cancel_main_(false), did_cancel_then_restart_main_(false), |
| 1983 did_simulate_error_main_(false), | 1985 did_simulate_error_main_(false), |
| 1984 did_intercept_redirect_(false), did_cancel_redirect_(false), | 1986 did_intercept_redirect_(false), did_cancel_redirect_(false), |
| 1985 did_intercept_final_(false), did_cancel_final_(false) { | 1987 did_intercept_final_(false), did_cancel_final_(false) { |
| 1986 net::URLRequest::RegisterRequestInterceptor(this); | 1988 URLRequest::RegisterRequestInterceptor(this); |
| 1987 } | 1989 } |
| 1988 | 1990 |
| 1989 ~TestInterceptor() { | 1991 ~TestInterceptor() { |
| 1990 net::URLRequest::UnregisterRequestInterceptor(this); | 1992 URLRequest::UnregisterRequestInterceptor(this); |
| 1991 } | 1993 } |
| 1992 | 1994 |
| 1993 virtual net::URLRequestJob* MaybeIntercept(net::URLRequest* request) { | 1995 virtual URLRequestJob* MaybeIntercept(URLRequest* request) { |
| 1994 if (restart_main_request_) { | 1996 if (restart_main_request_) { |
| 1995 restart_main_request_ = false; | 1997 restart_main_request_ = false; |
| 1996 did_restart_main_ = true; | 1998 did_restart_main_ = true; |
| 1997 return new RestartTestJob(request); | 1999 return new RestartTestJob(request); |
| 1998 } | 2000 } |
| 1999 if (cancel_main_request_) { | 2001 if (cancel_main_request_) { |
| 2000 cancel_main_request_ = false; | 2002 cancel_main_request_ = false; |
| 2001 did_cancel_main_ = true; | 2003 did_cancel_main_ = true; |
| 2002 return new CancelTestJob(request); | 2004 return new CancelTestJob(request); |
| 2003 } | 2005 } |
| 2004 if (cancel_then_restart_main_request_) { | 2006 if (cancel_then_restart_main_request_) { |
| 2005 cancel_then_restart_main_request_ = false; | 2007 cancel_then_restart_main_request_ = false; |
| 2006 did_cancel_then_restart_main_ = true; | 2008 did_cancel_then_restart_main_ = true; |
| 2007 return new CancelThenRestartTestJob(request); | 2009 return new CancelThenRestartTestJob(request); |
| 2008 } | 2010 } |
| 2009 if (simulate_main_network_error_) { | 2011 if (simulate_main_network_error_) { |
| 2010 simulate_main_network_error_ = false; | 2012 simulate_main_network_error_ = false; |
| 2011 did_simulate_error_main_ = true; | 2013 did_simulate_error_main_ = true; |
| 2012 // will error since the requeted url is not one of its canned urls | 2014 // will error since the requeted url is not one of its canned urls |
| 2013 return new net::URLRequestTestJob(request, true); | 2015 return new URLRequestTestJob(request, true); |
| 2014 } | 2016 } |
| 2015 if (!intercept_main_request_) | 2017 if (!intercept_main_request_) |
| 2016 return NULL; | 2018 return NULL; |
| 2017 intercept_main_request_ = false; | 2019 intercept_main_request_ = false; |
| 2018 did_intercept_main_ = true; | 2020 did_intercept_main_ = true; |
| 2019 return new net::URLRequestTestJob(request, | 2021 return new URLRequestTestJob(request, |
| 2020 main_headers_, | 2022 main_headers_, |
| 2021 main_data_, | 2023 main_data_, |
| 2022 true); | 2024 true); |
| 2023 } | 2025 } |
| 2024 | 2026 |
| 2025 virtual net::URLRequestJob* MaybeInterceptRedirect(net::URLRequest* request, | 2027 virtual URLRequestJob* MaybeInterceptRedirect(URLRequest* request, |
| 2026 const GURL& location) { | 2028 const GURL& location) { |
| 2027 if (cancel_redirect_request_) { | 2029 if (cancel_redirect_request_) { |
| 2028 cancel_redirect_request_ = false; | 2030 cancel_redirect_request_ = false; |
| 2029 did_cancel_redirect_ = true; | 2031 did_cancel_redirect_ = true; |
| 2030 return new CancelTestJob(request); | 2032 return new CancelTestJob(request); |
| 2031 } | 2033 } |
| 2032 if (!intercept_redirect_) | 2034 if (!intercept_redirect_) |
| 2033 return NULL; | 2035 return NULL; |
| 2034 intercept_redirect_ = false; | 2036 intercept_redirect_ = false; |
| 2035 did_intercept_redirect_ = true; | 2037 did_intercept_redirect_ = true; |
| 2036 return new net::URLRequestTestJob(request, | 2038 return new URLRequestTestJob(request, |
| 2037 redirect_headers_, | 2039 redirect_headers_, |
| 2038 redirect_data_, | 2040 redirect_data_, |
| 2039 true); | 2041 true); |
| 2040 } | 2042 } |
| 2041 | 2043 |
| 2042 virtual net::URLRequestJob* MaybeInterceptResponse(net::URLRequest* request) { | 2044 virtual URLRequestJob* MaybeInterceptResponse(URLRequest* request) { |
| 2043 if (cancel_final_request_) { | 2045 if (cancel_final_request_) { |
| 2044 cancel_final_request_ = false; | 2046 cancel_final_request_ = false; |
| 2045 did_cancel_final_ = true; | 2047 did_cancel_final_ = true; |
| 2046 return new CancelTestJob(request); | 2048 return new CancelTestJob(request); |
| 2047 } | 2049 } |
| 2048 if (!intercept_final_response_) | 2050 if (!intercept_final_response_) |
| 2049 return NULL; | 2051 return NULL; |
| 2050 intercept_final_response_ = false; | 2052 intercept_final_response_ = false; |
| 2051 did_intercept_final_ = true; | 2053 did_intercept_final_ = true; |
| 2052 return new net::URLRequestTestJob(request, | 2054 return new URLRequestTestJob(request, |
| 2053 final_headers_, | 2055 final_headers_, |
| 2054 final_data_, | 2056 final_data_, |
| 2055 true); | 2057 true); |
| 2056 } | 2058 } |
| 2057 | 2059 |
| 2058 // Whether to intercept the main request, and if so the response to return. | 2060 // Whether to intercept the main request, and if so the response to return. |
| 2059 bool intercept_main_request_; | 2061 bool intercept_main_request_; |
| 2060 std::string main_headers_; | 2062 std::string main_headers_; |
| 2061 std::string main_data_; | 2063 std::string main_data_; |
| 2062 | 2064 |
| (...skipping 26 matching lines...) Expand all Loading... |
| 2089 bool did_cancel_then_restart_main_; | 2091 bool did_cancel_then_restart_main_; |
| 2090 bool did_simulate_error_main_; | 2092 bool did_simulate_error_main_; |
| 2091 bool did_intercept_redirect_; | 2093 bool did_intercept_redirect_; |
| 2092 bool did_cancel_redirect_; | 2094 bool did_cancel_redirect_; |
| 2093 bool did_intercept_final_; | 2095 bool did_intercept_final_; |
| 2094 bool did_cancel_final_; | 2096 bool did_cancel_final_; |
| 2095 | 2097 |
| 2096 // Static getters for canned response header and data strings | 2098 // Static getters for canned response header and data strings |
| 2097 | 2099 |
| 2098 static std::string ok_data() { | 2100 static std::string ok_data() { |
| 2099 return net::URLRequestTestJob::test_data_1(); | 2101 return URLRequestTestJob::test_data_1(); |
| 2100 } | 2102 } |
| 2101 | 2103 |
| 2102 static std::string ok_headers() { | 2104 static std::string ok_headers() { |
| 2103 return net::URLRequestTestJob::test_headers(); | 2105 return URLRequestTestJob::test_headers(); |
| 2104 } | 2106 } |
| 2105 | 2107 |
| 2106 static std::string redirect_data() { | 2108 static std::string redirect_data() { |
| 2107 return std::string(); | 2109 return std::string(); |
| 2108 } | 2110 } |
| 2109 | 2111 |
| 2110 static std::string redirect_headers() { | 2112 static std::string redirect_headers() { |
| 2111 return net::URLRequestTestJob::test_redirect_headers(); | 2113 return URLRequestTestJob::test_redirect_headers(); |
| 2112 } | 2114 } |
| 2113 | 2115 |
| 2114 static std::string error_data() { | 2116 static std::string error_data() { |
| 2115 return std::string("ohhh nooooo mr. bill!"); | 2117 return std::string("ohhh nooooo mr. bill!"); |
| 2116 } | 2118 } |
| 2117 | 2119 |
| 2118 static std::string error_headers() { | 2120 static std::string error_headers() { |
| 2119 return net::URLRequestTestJob::test_error_headers(); | 2121 return URLRequestTestJob::test_error_headers(); |
| 2120 } | 2122 } |
| 2121 }; | 2123 }; |
| 2122 | 2124 |
| 2123 TEST_F(URLRequestTest, Intercept) { | 2125 TEST_F(URLRequestTest, Intercept) { |
| 2124 TestInterceptor interceptor; | 2126 TestInterceptor interceptor; |
| 2125 | 2127 |
| 2126 // intercept the main request and respond with a simple response | 2128 // intercept the main request and respond with a simple response |
| 2127 interceptor.intercept_main_request_ = true; | 2129 interceptor.intercept_main_request_ = true; |
| 2128 interceptor.main_headers_ = TestInterceptor::ok_headers(); | 2130 interceptor.main_headers_ = TestInterceptor::ok_headers(); |
| 2129 interceptor.main_data_ = TestInterceptor::ok_data(); | 2131 interceptor.main_data_ = TestInterceptor::ok_data(); |
| 2130 | 2132 |
| 2131 TestDelegate d; | 2133 TestDelegate d; |
| 2132 TestURLRequest req(GURL("http://test_intercept/foo"), &d); | 2134 TestURLRequest req(GURL("http://test_intercept/foo"), &d); |
| 2133 net::URLRequest::UserData* user_data0 = new net::URLRequest::UserData(); | 2135 URLRequest::UserData* user_data0 = new URLRequest::UserData(); |
| 2134 net::URLRequest::UserData* user_data1 = new net::URLRequest::UserData(); | 2136 URLRequest::UserData* user_data1 = new URLRequest::UserData(); |
| 2135 net::URLRequest::UserData* user_data2 = new net::URLRequest::UserData(); | 2137 URLRequest::UserData* user_data2 = new URLRequest::UserData(); |
| 2136 req.SetUserData(NULL, user_data0); | 2138 req.SetUserData(NULL, user_data0); |
| 2137 req.SetUserData(&user_data1, user_data1); | 2139 req.SetUserData(&user_data1, user_data1); |
| 2138 req.SetUserData(&user_data2, user_data2); | 2140 req.SetUserData(&user_data2, user_data2); |
| 2139 req.set_method("GET"); | 2141 req.set_method("GET"); |
| 2140 req.Start(); | 2142 req.Start(); |
| 2141 MessageLoop::current()->Run(); | 2143 MessageLoop::current()->Run(); |
| 2142 | 2144 |
| 2143 // Make sure we can retrieve our specific user data | 2145 // Make sure we can retrieve our specific user data |
| 2144 EXPECT_EQ(user_data0, req.GetUserData(NULL)); | 2146 EXPECT_EQ(user_data0, req.GetUserData(NULL)); |
| 2145 EXPECT_EQ(user_data1, req.GetUserData(&user_data1)); | 2147 EXPECT_EQ(user_data1, req.GetUserData(&user_data1)); |
| (...skipping 150 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2296 req.set_method("GET"); | 2298 req.set_method("GET"); |
| 2297 req.Start(); | 2299 req.Start(); |
| 2298 MessageLoop::current()->Run(); | 2300 MessageLoop::current()->Run(); |
| 2299 | 2301 |
| 2300 // Check the interceptor got called as expected | 2302 // Check the interceptor got called as expected |
| 2301 EXPECT_TRUE(interceptor.did_cancel_main_); | 2303 EXPECT_TRUE(interceptor.did_cancel_main_); |
| 2302 EXPECT_FALSE(interceptor.did_intercept_final_); | 2304 EXPECT_FALSE(interceptor.did_intercept_final_); |
| 2303 | 2305 |
| 2304 // Check we see a canceled request | 2306 // Check we see a canceled request |
| 2305 EXPECT_FALSE(req.status().is_success()); | 2307 EXPECT_FALSE(req.status().is_success()); |
| 2306 EXPECT_EQ(net::URLRequestStatus::CANCELED, req.status().status()); | 2308 EXPECT_EQ(URLRequestStatus::CANCELED, req.status().status()); |
| 2307 } | 2309 } |
| 2308 | 2310 |
| 2309 TEST_F(URLRequestTest, InterceptRespectsCancelRedirect) { | 2311 TEST_F(URLRequestTest, InterceptRespectsCancelRedirect) { |
| 2310 TestInterceptor interceptor; | 2312 TestInterceptor interceptor; |
| 2311 | 2313 |
| 2312 // intercept the main request and respond with a redirect | 2314 // intercept the main request and respond with a redirect |
| 2313 interceptor.intercept_main_request_ = true; | 2315 interceptor.intercept_main_request_ = true; |
| 2314 interceptor.main_headers_ = TestInterceptor::redirect_headers(); | 2316 interceptor.main_headers_ = TestInterceptor::redirect_headers(); |
| 2315 interceptor.main_data_ = TestInterceptor::redirect_data(); | 2317 interceptor.main_data_ = TestInterceptor::redirect_data(); |
| 2316 | 2318 |
| (...skipping 11 matching lines...) Expand all Loading... |
| 2328 req.Start(); | 2330 req.Start(); |
| 2329 MessageLoop::current()->Run(); | 2331 MessageLoop::current()->Run(); |
| 2330 | 2332 |
| 2331 // Check the interceptor got called as expected | 2333 // Check the interceptor got called as expected |
| 2332 EXPECT_TRUE(interceptor.did_intercept_main_); | 2334 EXPECT_TRUE(interceptor.did_intercept_main_); |
| 2333 EXPECT_TRUE(interceptor.did_cancel_redirect_); | 2335 EXPECT_TRUE(interceptor.did_cancel_redirect_); |
| 2334 EXPECT_FALSE(interceptor.did_intercept_final_); | 2336 EXPECT_FALSE(interceptor.did_intercept_final_); |
| 2335 | 2337 |
| 2336 // Check we see a canceled request | 2338 // Check we see a canceled request |
| 2337 EXPECT_FALSE(req.status().is_success()); | 2339 EXPECT_FALSE(req.status().is_success()); |
| 2338 EXPECT_EQ(net::URLRequestStatus::CANCELED, req.status().status()); | 2340 EXPECT_EQ(URLRequestStatus::CANCELED, req.status().status()); |
| 2339 } | 2341 } |
| 2340 | 2342 |
| 2341 TEST_F(URLRequestTest, InterceptRespectsCancelFinal) { | 2343 TEST_F(URLRequestTest, InterceptRespectsCancelFinal) { |
| 2342 TestInterceptor interceptor; | 2344 TestInterceptor interceptor; |
| 2343 | 2345 |
| 2344 // intercept the main request to simulate a network error | 2346 // intercept the main request to simulate a network error |
| 2345 interceptor.simulate_main_network_error_ = true; | 2347 interceptor.simulate_main_network_error_ = true; |
| 2346 | 2348 |
| 2347 // setup to intercept final response and cancel from within that job | 2349 // setup to intercept final response and cancel from within that job |
| 2348 interceptor.cancel_final_request_ = true; | 2350 interceptor.cancel_final_request_ = true; |
| 2349 | 2351 |
| 2350 TestDelegate d; | 2352 TestDelegate d; |
| 2351 TestURLRequest req(GURL("http://test_intercept/foo"), &d); | 2353 TestURLRequest req(GURL("http://test_intercept/foo"), &d); |
| 2352 req.set_method("GET"); | 2354 req.set_method("GET"); |
| 2353 req.Start(); | 2355 req.Start(); |
| 2354 MessageLoop::current()->Run(); | 2356 MessageLoop::current()->Run(); |
| 2355 | 2357 |
| 2356 // Check the interceptor got called as expected | 2358 // Check the interceptor got called as expected |
| 2357 EXPECT_TRUE(interceptor.did_simulate_error_main_); | 2359 EXPECT_TRUE(interceptor.did_simulate_error_main_); |
| 2358 EXPECT_TRUE(interceptor.did_cancel_final_); | 2360 EXPECT_TRUE(interceptor.did_cancel_final_); |
| 2359 | 2361 |
| 2360 // Check we see a canceled request | 2362 // Check we see a canceled request |
| 2361 EXPECT_FALSE(req.status().is_success()); | 2363 EXPECT_FALSE(req.status().is_success()); |
| 2362 EXPECT_EQ(net::URLRequestStatus::CANCELED, req.status().status()); | 2364 EXPECT_EQ(URLRequestStatus::CANCELED, req.status().status()); |
| 2363 } | 2365 } |
| 2364 | 2366 |
| 2365 TEST_F(URLRequestTest, InterceptRespectsCancelInRestart) { | 2367 TEST_F(URLRequestTest, InterceptRespectsCancelInRestart) { |
| 2366 TestInterceptor interceptor; | 2368 TestInterceptor interceptor; |
| 2367 | 2369 |
| 2368 // intercept the main request and cancel then restart from within that job | 2370 // intercept the main request and cancel then restart from within that job |
| 2369 interceptor.cancel_then_restart_main_request_ = true; | 2371 interceptor.cancel_then_restart_main_request_ = true; |
| 2370 | 2372 |
| 2371 // setup to intercept final response and override it with an OK response | 2373 // setup to intercept final response and override it with an OK response |
| 2372 interceptor.intercept_final_response_ = true; | 2374 interceptor.intercept_final_response_ = true; |
| 2373 interceptor.final_headers_ = TestInterceptor::ok_headers(); | 2375 interceptor.final_headers_ = TestInterceptor::ok_headers(); |
| 2374 interceptor.final_data_ = TestInterceptor::ok_data(); | 2376 interceptor.final_data_ = TestInterceptor::ok_data(); |
| 2375 | 2377 |
| 2376 TestDelegate d; | 2378 TestDelegate d; |
| 2377 TestURLRequest req(GURL("http://test_intercept/foo"), &d); | 2379 TestURLRequest req(GURL("http://test_intercept/foo"), &d); |
| 2378 req.set_method("GET"); | 2380 req.set_method("GET"); |
| 2379 req.Start(); | 2381 req.Start(); |
| 2380 MessageLoop::current()->Run(); | 2382 MessageLoop::current()->Run(); |
| 2381 | 2383 |
| 2382 // Check the interceptor got called as expected | 2384 // Check the interceptor got called as expected |
| 2383 EXPECT_TRUE(interceptor.did_cancel_then_restart_main_); | 2385 EXPECT_TRUE(interceptor.did_cancel_then_restart_main_); |
| 2384 EXPECT_FALSE(interceptor.did_intercept_final_); | 2386 EXPECT_FALSE(interceptor.did_intercept_final_); |
| 2385 | 2387 |
| 2386 // Check we see a canceled request | 2388 // Check we see a canceled request |
| 2387 EXPECT_FALSE(req.status().is_success()); | 2389 EXPECT_FALSE(req.status().is_success()); |
| 2388 EXPECT_EQ(net::URLRequestStatus::CANCELED, req.status().status()); | 2390 EXPECT_EQ(URLRequestStatus::CANCELED, req.status().status()); |
| 2389 } | 2391 } |
| 2390 | 2392 |
| 2391 // Check that two different URL requests have different identifiers. | 2393 // Check that two different URL requests have different identifiers. |
| 2392 TEST_F(URLRequestTest, Identifiers) { | 2394 TEST_F(URLRequestTest, Identifiers) { |
| 2393 TestDelegate d; | 2395 TestDelegate d; |
| 2394 TestURLRequest req(GURL("http://example.com"), &d); | 2396 TestURLRequest req(GURL("http://example.com"), &d); |
| 2395 TestURLRequest other_req(GURL("http://example.com"), &d); | 2397 TestURLRequest other_req(GURL("http://example.com"), &d); |
| 2396 | 2398 |
| 2397 ASSERT_NE(req.identifier(), other_req.identifier()); | 2399 ASSERT_NE(req.identifier(), other_req.identifier()); |
| 2398 } | 2400 } |
| 2399 | 2401 |
| 2400 // Check that a failure to connect to the proxy is reported to the network | 2402 // Check that a failure to connect to the proxy is reported to the network |
| 2401 // delegate. | 2403 // delegate. |
| 2402 TEST_F(URLRequestTest, NetworkDelegateProxyError) { | 2404 TEST_F(URLRequestTest, NetworkDelegateProxyError) { |
| 2403 TestDelegate d; | 2405 TestDelegate d; |
| 2404 TestURLRequest req(GURL("http://example.com"), &d); | 2406 TestURLRequest req(GURL("http://example.com"), &d); |
| 2405 req.set_method("GET"); | 2407 req.set_method("GET"); |
| 2406 | 2408 |
| 2407 scoped_ptr<net::MockHostResolverBase> host_resolver( | 2409 scoped_ptr<MockHostResolverBase> host_resolver( |
| 2408 new net::MockHostResolver); | 2410 new MockHostResolver); |
| 2409 host_resolver->rules()->AddSimulatedFailure("*"); | 2411 host_resolver->rules()->AddSimulatedFailure("*"); |
| 2410 TestNetworkDelegate network_delegate; | 2412 TestNetworkDelegate network_delegate; |
| 2411 scoped_refptr<TestURLRequestContext> context( | 2413 scoped_refptr<TestURLRequestContext> context( |
| 2412 new TestURLRequestContext("myproxy:70", host_resolver.release())); | 2414 new TestURLRequestContext("myproxy:70", host_resolver.release())); |
| 2413 context->set_network_delegate(&network_delegate); | 2415 context->set_network_delegate(&network_delegate); |
| 2414 req.set_context(context); | 2416 req.set_context(context); |
| 2415 | 2417 |
| 2416 req.Start(); | 2418 req.Start(); |
| 2417 MessageLoop::current()->Run(); | 2419 MessageLoop::current()->Run(); |
| 2418 | 2420 |
| 2419 // Check we see a failed request. | 2421 // Check we see a failed request. |
| 2420 EXPECT_FALSE(req.status().is_success()); | 2422 EXPECT_FALSE(req.status().is_success()); |
| 2421 EXPECT_EQ(net::URLRequestStatus::FAILED, req.status().status()); | 2423 EXPECT_EQ(URLRequestStatus::FAILED, req.status().status()); |
| 2422 EXPECT_EQ(net::ERR_PROXY_CONNECTION_FAILED, req.status().os_error()); | 2424 EXPECT_EQ(ERR_PROXY_CONNECTION_FAILED, req.status().os_error()); |
| 2423 | 2425 |
| 2424 EXPECT_EQ(1, network_delegate.error_count()); | 2426 EXPECT_EQ(1, network_delegate.error_count()); |
| 2425 EXPECT_EQ(net::ERR_PROXY_CONNECTION_FAILED, network_delegate.last_os_error()); | 2427 EXPECT_EQ(ERR_PROXY_CONNECTION_FAILED, network_delegate.last_os_error()); |
| 2426 } | 2428 } |
| 2427 | 2429 |
| 2428 class URLRequestTestFTP : public URLRequestTest { | 2430 class URLRequestTestFTP : public URLRequestTest { |
| 2429 public: | 2431 public: |
| 2430 URLRequestTestFTP() : test_server_(net::TestServer::TYPE_FTP, FilePath()) { | 2432 URLRequestTestFTP() : test_server_(TestServer::TYPE_FTP, FilePath()) { |
| 2431 } | 2433 } |
| 2432 | 2434 |
| 2433 protected: | 2435 protected: |
| 2434 net::TestServer test_server_; | 2436 TestServer test_server_; |
| 2435 }; | 2437 }; |
| 2436 | 2438 |
| 2437 // Flaky, see http://crbug.com/25045. | 2439 // Flaky, see http://crbug.com/25045. |
| 2438 TEST_F(URLRequestTestFTP, FLAKY_FTPDirectoryListing) { | 2440 TEST_F(URLRequestTestFTP, FLAKY_FTPDirectoryListing) { |
| 2439 ASSERT_TRUE(test_server_.Start()); | 2441 ASSERT_TRUE(test_server_.Start()); |
| 2440 | 2442 |
| 2441 TestDelegate d; | 2443 TestDelegate d; |
| 2442 { | 2444 { |
| 2443 TestURLRequest r(test_server_.GetURL("/"), &d); | 2445 TestURLRequest r(test_server_.GetURL("/"), &d); |
| 2444 r.Start(); | 2446 r.Start(); |
| (...skipping 314 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2759 | 2761 |
| 2760 // Check that if request overrides the A-L header, the default is not appended. | 2762 // Check that if request overrides the A-L header, the default is not appended. |
| 2761 // See http://crbug.com/20894 | 2763 // See http://crbug.com/20894 |
| 2762 TEST_F(URLRequestTestHTTP, OverrideAcceptLanguage) { | 2764 TEST_F(URLRequestTestHTTP, OverrideAcceptLanguage) { |
| 2763 ASSERT_TRUE(test_server_.Start()); | 2765 ASSERT_TRUE(test_server_.Start()); |
| 2764 | 2766 |
| 2765 TestDelegate d; | 2767 TestDelegate d; |
| 2766 TestURLRequest | 2768 TestURLRequest |
| 2767 req(test_server_.GetURL("echoheaderoverride?Accept-Language"), &d); | 2769 req(test_server_.GetURL("echoheaderoverride?Accept-Language"), &d); |
| 2768 req.set_context(new TestURLRequestContext()); | 2770 req.set_context(new TestURLRequestContext()); |
| 2769 net::HttpRequestHeaders headers; | 2771 HttpRequestHeaders headers; |
| 2770 headers.SetHeader(net::HttpRequestHeaders::kAcceptLanguage, "ru"); | 2772 headers.SetHeader(HttpRequestHeaders::kAcceptLanguage, "ru"); |
| 2771 req.SetExtraRequestHeaders(headers); | 2773 req.SetExtraRequestHeaders(headers); |
| 2772 req.Start(); | 2774 req.Start(); |
| 2773 MessageLoop::current()->Run(); | 2775 MessageLoop::current()->Run(); |
| 2774 EXPECT_EQ(std::string("ru"), d.data_received()); | 2776 EXPECT_EQ(std::string("ru"), d.data_received()); |
| 2775 } | 2777 } |
| 2776 | 2778 |
| 2777 // Check that default A-C header is sent. | 2779 // Check that default A-C header is sent. |
| 2778 TEST_F(URLRequestTestHTTP, DefaultAcceptCharset) { | 2780 TEST_F(URLRequestTestHTTP, DefaultAcceptCharset) { |
| 2779 ASSERT_TRUE(test_server_.Start()); | 2781 ASSERT_TRUE(test_server_.Start()); |
| 2780 | 2782 |
| 2781 TestDelegate d; | 2783 TestDelegate d; |
| 2782 TestURLRequest req(test_server_.GetURL("echoheader?Accept-Charset"), &d); | 2784 TestURLRequest req(test_server_.GetURL("echoheader?Accept-Charset"), &d); |
| 2783 req.set_context(new TestURLRequestContext()); | 2785 req.set_context(new TestURLRequestContext()); |
| 2784 req.Start(); | 2786 req.Start(); |
| 2785 MessageLoop::current()->Run(); | 2787 MessageLoop::current()->Run(); |
| 2786 EXPECT_EQ(req.context()->accept_charset(), d.data_received()); | 2788 EXPECT_EQ(req.context()->accept_charset(), d.data_received()); |
| 2787 } | 2789 } |
| 2788 | 2790 |
| 2789 // Check that if request overrides the A-C header, the default is not appended. | 2791 // Check that if request overrides the A-C header, the default is not appended. |
| 2790 // See http://crbug.com/20894 | 2792 // See http://crbug.com/20894 |
| 2791 TEST_F(URLRequestTestHTTP, OverrideAcceptCharset) { | 2793 TEST_F(URLRequestTestHTTP, OverrideAcceptCharset) { |
| 2792 ASSERT_TRUE(test_server_.Start()); | 2794 ASSERT_TRUE(test_server_.Start()); |
| 2793 | 2795 |
| 2794 TestDelegate d; | 2796 TestDelegate d; |
| 2795 TestURLRequest | 2797 TestURLRequest |
| 2796 req(test_server_.GetURL("echoheaderoverride?Accept-Charset"), &d); | 2798 req(test_server_.GetURL("echoheaderoverride?Accept-Charset"), &d); |
| 2797 req.set_context(new TestURLRequestContext()); | 2799 req.set_context(new TestURLRequestContext()); |
| 2798 net::HttpRequestHeaders headers; | 2800 HttpRequestHeaders headers; |
| 2799 headers.SetHeader(net::HttpRequestHeaders::kAcceptCharset, "koi-8r"); | 2801 headers.SetHeader(HttpRequestHeaders::kAcceptCharset, "koi-8r"); |
| 2800 req.SetExtraRequestHeaders(headers); | 2802 req.SetExtraRequestHeaders(headers); |
| 2801 req.Start(); | 2803 req.Start(); |
| 2802 MessageLoop::current()->Run(); | 2804 MessageLoop::current()->Run(); |
| 2803 EXPECT_EQ(std::string("koi-8r"), d.data_received()); | 2805 EXPECT_EQ(std::string("koi-8r"), d.data_received()); |
| 2804 } | 2806 } |
| 2805 | 2807 |
| 2806 // Check that default User-Agent header is sent. | 2808 // Check that default User-Agent header is sent. |
| 2807 TEST_F(URLRequestTestHTTP, DefaultUserAgent) { | 2809 TEST_F(URLRequestTestHTTP, DefaultUserAgent) { |
| 2808 ASSERT_TRUE(test_server_.Start()); | 2810 ASSERT_TRUE(test_server_.Start()); |
| 2809 | 2811 |
| 2810 TestDelegate d; | 2812 TestDelegate d; |
| 2811 TestURLRequest req(test_server_.GetURL("echoheader?User-Agent"), &d); | 2813 TestURLRequest req(test_server_.GetURL("echoheader?User-Agent"), &d); |
| 2812 req.set_context(new TestURLRequestContext()); | 2814 req.set_context(new TestURLRequestContext()); |
| 2813 req.Start(); | 2815 req.Start(); |
| 2814 MessageLoop::current()->Run(); | 2816 MessageLoop::current()->Run(); |
| 2815 EXPECT_EQ(req.context()->GetUserAgent(req.url()), d.data_received()); | 2817 EXPECT_EQ(req.context()->GetUserAgent(req.url()), d.data_received()); |
| 2816 } | 2818 } |
| 2817 | 2819 |
| 2818 // Check that if request overrides the User-Agent header, | 2820 // Check that if request overrides the User-Agent header, |
| 2819 // the default is not appended. | 2821 // the default is not appended. |
| 2820 TEST_F(URLRequestTestHTTP, OverrideUserAgent) { | 2822 TEST_F(URLRequestTestHTTP, OverrideUserAgent) { |
| 2821 ASSERT_TRUE(test_server_.Start()); | 2823 ASSERT_TRUE(test_server_.Start()); |
| 2822 | 2824 |
| 2823 TestDelegate d; | 2825 TestDelegate d; |
| 2824 TestURLRequest | 2826 TestURLRequest |
| 2825 req(test_server_.GetURL("echoheaderoverride?User-Agent"), &d); | 2827 req(test_server_.GetURL("echoheaderoverride?User-Agent"), &d); |
| 2826 req.set_context(new TestURLRequestContext()); | 2828 req.set_context(new TestURLRequestContext()); |
| 2827 net::HttpRequestHeaders headers; | 2829 HttpRequestHeaders headers; |
| 2828 headers.SetHeader(net::HttpRequestHeaders::kUserAgent, "Lynx (textmode)"); | 2830 headers.SetHeader(HttpRequestHeaders::kUserAgent, "Lynx (textmode)"); |
| 2829 req.SetExtraRequestHeaders(headers); | 2831 req.SetExtraRequestHeaders(headers); |
| 2830 req.Start(); | 2832 req.Start(); |
| 2831 MessageLoop::current()->Run(); | 2833 MessageLoop::current()->Run(); |
| 2832 // If the net tests are being run with ChromeFrame then we need to allow for | 2834 // If the net tests are being run with ChromeFrame then we need to allow for |
| 2833 // the 'chromeframe' suffix which is added to the user agent before the | 2835 // the 'chromeframe' suffix which is added to the user agent before the |
| 2834 // closing parentheses. | 2836 // closing parentheses. |
| 2835 EXPECT_TRUE(StartsWithASCII(d.data_received(), "Lynx (textmode", true)); | 2837 EXPECT_TRUE(StartsWithASCII(d.data_received(), "Lynx (textmode", true)); |
| 2836 } | 2838 } |
| 2839 |
| 2840 } // namespace net |
| OLD | NEW |