| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "build/build_config.h" | 5 #include "build/build_config.h" |
| 6 | 6 |
| 7 #if defined(OS_WIN) | 7 #if defined(OS_WIN) |
| 8 #include <windows.h> | 8 #include <windows.h> |
| 9 #include <shlobj.h> | 9 #include <shlobj.h> |
| 10 #endif | 10 #endif |
| (...skipping 222 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 233 } | 233 } |
| 234 | 234 |
| 235 UploadDataStream* CreateSimpleUploadData(const char* data) { | 235 UploadDataStream* CreateSimpleUploadData(const char* data) { |
| 236 scoped_ptr<UploadElementReader> reader( | 236 scoped_ptr<UploadElementReader> reader( |
| 237 new UploadBytesElementReader(data, strlen(data))); | 237 new UploadBytesElementReader(data, strlen(data))); |
| 238 return UploadDataStream::CreateWithReader(reader.Pass(), 0); | 238 return UploadDataStream::CreateWithReader(reader.Pass(), 0); |
| 239 } | 239 } |
| 240 | 240 |
| 241 // Verify that the SSLInfo of a successful SSL connection has valid values. | 241 // Verify that the SSLInfo of a successful SSL connection has valid values. |
| 242 void CheckSSLInfo(const SSLInfo& ssl_info) { | 242 void CheckSSLInfo(const SSLInfo& ssl_info) { |
| 243 // Allow ChromeFrame fake SSLInfo to get through. | |
| 244 if (ssl_info.cert.get() && | |
| 245 ssl_info.cert.get()->issuer().GetDisplayName() == "Chrome Internal") { | |
| 246 // -1 means unknown. | |
| 247 EXPECT_EQ(ssl_info.security_bits, -1); | |
| 248 return; | |
| 249 } | |
| 250 | |
| 251 // -1 means unknown. 0 means no encryption. | 243 // -1 means unknown. 0 means no encryption. |
| 252 EXPECT_GT(ssl_info.security_bits, 0); | 244 EXPECT_GT(ssl_info.security_bits, 0); |
| 253 | 245 |
| 254 // The cipher suite TLS_NULL_WITH_NULL_NULL (0) must not be negotiated. | 246 // The cipher suite TLS_NULL_WITH_NULL_NULL (0) must not be negotiated. |
| 255 int cipher_suite = SSLConnectionStatusToCipherSuite( | 247 int cipher_suite = SSLConnectionStatusToCipherSuite( |
| 256 ssl_info.connection_status); | 248 ssl_info.connection_status); |
| 257 EXPECT_NE(0, cipher_suite); | 249 EXPECT_NE(0, cipher_suite); |
| 258 } | 250 } |
| 259 | 251 |
| 260 void CheckFullRequestHeaders(const HttpRequestHeaders& headers, | 252 void CheckFullRequestHeaders(const HttpRequestHeaders& headers, |
| (...skipping 1697 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1958 req.Start(); | 1950 req.Start(); |
| 1959 EXPECT_EQ(MAXIMUM_PRIORITY, req.priority()); | 1951 EXPECT_EQ(MAXIMUM_PRIORITY, req.priority()); |
| 1960 EXPECT_EQ(MAXIMUM_PRIORITY, job->priority()); | 1952 EXPECT_EQ(MAXIMUM_PRIORITY, job->priority()); |
| 1961 } | 1953 } |
| 1962 | 1954 |
| 1963 // TODO(droger): Support SpawnedTestServer on iOS (see http://crbug.com/148666). | 1955 // TODO(droger): Support SpawnedTestServer on iOS (see http://crbug.com/148666). |
| 1964 #if !defined(OS_IOS) | 1956 #if !defined(OS_IOS) |
| 1965 // A subclass of SpawnedTestServer that uses a statically-configured hostname. | 1957 // A subclass of SpawnedTestServer that uses a statically-configured hostname. |
| 1966 // This is to work around mysterious failures in chrome_frame_net_tests. See: | 1958 // This is to work around mysterious failures in chrome_frame_net_tests. See: |
| 1967 // http://crbug.com/114369 | 1959 // http://crbug.com/114369 |
| 1960 // TODO(erikwright): remove or update as needed; see http://crbug.com/334634. |
| 1968 class LocalHttpTestServer : public SpawnedTestServer { | 1961 class LocalHttpTestServer : public SpawnedTestServer { |
| 1969 public: | 1962 public: |
| 1970 explicit LocalHttpTestServer(const base::FilePath& document_root) | 1963 explicit LocalHttpTestServer(const base::FilePath& document_root) |
| 1971 : SpawnedTestServer(SpawnedTestServer::TYPE_HTTP, | 1964 : SpawnedTestServer(SpawnedTestServer::TYPE_HTTP, |
| 1972 ScopedCustomUrlRequestTestHttpHost::value(), | 1965 ScopedCustomUrlRequestTestHttpHost::value(), |
| 1973 document_root) {} | 1966 document_root) {} |
| 1974 LocalHttpTestServer() | 1967 LocalHttpTestServer() |
| 1975 : SpawnedTestServer(SpawnedTestServer::TYPE_HTTP, | 1968 : SpawnedTestServer(SpawnedTestServer::TYPE_HTTP, |
| 1976 ScopedCustomUrlRequestTestHttpHost::value(), | 1969 ScopedCustomUrlRequestTestHttpHost::value(), |
| 1977 base::FilePath()) {} | 1970 base::FilePath()) {} |
| (...skipping 705 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2683 &default_context_); | 2676 &default_context_); |
| 2684 | 2677 |
| 2685 r.Start(); | 2678 r.Start(); |
| 2686 EXPECT_TRUE(r.is_pending()); | 2679 EXPECT_TRUE(r.is_pending()); |
| 2687 | 2680 |
| 2688 base::RunLoop().Run(); | 2681 base::RunLoop().Run(); |
| 2689 | 2682 |
| 2690 bool is_success = r.status().is_success(); | 2683 bool is_success = r.status().is_success(); |
| 2691 | 2684 |
| 2692 if (!is_success) { | 2685 if (!is_success) { |
| 2693 // Requests handled by ChromeFrame send a less precise error message, | 2686 EXPECT_TRUE(r.status().error() == ERR_RESPONSE_HEADERS_TOO_BIG); |
| 2694 // ERR_CONNECTION_ABORTED. | |
| 2695 EXPECT_TRUE(r.status().error() == ERR_RESPONSE_HEADERS_TOO_BIG || | |
| 2696 r.status().error() == ERR_CONNECTION_ABORTED); | |
| 2697 // The test server appears to be unable to handle subsequent requests | 2687 // The test server appears to be unable to handle subsequent requests |
| 2698 // after this error is triggered. Force it to restart. | 2688 // after this error is triggered. Force it to restart. |
| 2699 EXPECT_TRUE(test_server_.Stop()); | 2689 EXPECT_TRUE(test_server_.Stop()); |
| 2700 EXPECT_TRUE(test_server_.Start()); | 2690 EXPECT_TRUE(test_server_.Start()); |
| 2701 } | 2691 } |
| 2702 | 2692 |
| 2703 return is_success; | 2693 return is_success; |
| 2704 } | 2694 } |
| 2705 | 2695 |
| 2706 LocalHttpTestServer test_server_; | 2696 LocalHttpTestServer test_server_; |
| (...skipping 2098 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 4805 kuint64max, | 4795 kuint64max, |
| 4806 base::Time())); | 4796 base::Time())); |
| 4807 r.set_upload(make_scoped_ptr( | 4797 r.set_upload(make_scoped_ptr( |
| 4808 new UploadDataStream(element_readers.Pass(), 0))); | 4798 new UploadDataStream(element_readers.Pass(), 0))); |
| 4809 | 4799 |
| 4810 r.Start(); | 4800 r.Start(); |
| 4811 EXPECT_TRUE(r.is_pending()); | 4801 EXPECT_TRUE(r.is_pending()); |
| 4812 | 4802 |
| 4813 base::RunLoop().Run(); | 4803 base::RunLoop().Run(); |
| 4814 | 4804 |
| 4815 // TODO(tzik): Remove this #if after we stop supporting Chrome Frame. | |
| 4816 // http://crbug.com/317432 | |
| 4817 #if defined(CHROME_FRAME_NET_TESTS) | |
| 4818 EXPECT_FALSE(d.request_failed()); | |
| 4819 EXPECT_FALSE(d.received_data_before_response()); | |
| 4820 EXPECT_EQ(0, d.bytes_received()); | |
| 4821 EXPECT_EQ(URLRequestStatus::SUCCESS, r.status().status()); | |
| 4822 EXPECT_EQ(OK, r.status().error()); | |
| 4823 #else | |
| 4824 EXPECT_TRUE(d.request_failed()); | 4805 EXPECT_TRUE(d.request_failed()); |
| 4825 EXPECT_FALSE(d.received_data_before_response()); | 4806 EXPECT_FALSE(d.received_data_before_response()); |
| 4826 EXPECT_EQ(0, d.bytes_received()); | 4807 EXPECT_EQ(0, d.bytes_received()); |
| 4827 EXPECT_EQ(URLRequestStatus::FAILED, r.status().status()); | 4808 EXPECT_EQ(URLRequestStatus::FAILED, r.status().status()); |
| 4828 EXPECT_EQ(ERR_FILE_NOT_FOUND, r.status().error()); | 4809 EXPECT_EQ(ERR_FILE_NOT_FOUND, r.status().error()); |
| 4829 #endif // defined(CHROME_FRAME_NET_TESTS) | |
| 4830 } | 4810 } |
| 4831 } | 4811 } |
| 4832 | 4812 |
| 4833 TEST_F(URLRequestTestHTTP, TestPostChunkedDataBeforeStart) { | 4813 TEST_F(URLRequestTestHTTP, TestPostChunkedDataBeforeStart) { |
| 4834 ASSERT_TRUE(test_server_.Start()); | 4814 ASSERT_TRUE(test_server_.Start()); |
| 4835 | 4815 |
| 4836 TestDelegate d; | 4816 TestDelegate d; |
| 4837 { | 4817 { |
| 4838 URLRequest r( | 4818 URLRequest r( |
| 4839 test_server_.GetURL("echo"), DEFAULT_PRIORITY, &d, &default_context_); | 4819 test_server_.GetURL("echo"), DEFAULT_PRIORITY, &d, &default_context_); |
| (...skipping 1115 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 5955 TestDelegate d; | 5935 TestDelegate d; |
| 5956 URLRequest req(test_server_.GetURL("echoheader?User-Agent"), | 5936 URLRequest req(test_server_.GetURL("echoheader?User-Agent"), |
| 5957 DEFAULT_PRIORITY, | 5937 DEFAULT_PRIORITY, |
| 5958 &d, | 5938 &d, |
| 5959 &default_context_); | 5939 &default_context_); |
| 5960 HttpRequestHeaders headers; | 5940 HttpRequestHeaders headers; |
| 5961 headers.SetHeader(HttpRequestHeaders::kUserAgent, "Lynx (textmode)"); | 5941 headers.SetHeader(HttpRequestHeaders::kUserAgent, "Lynx (textmode)"); |
| 5962 req.SetExtraRequestHeaders(headers); | 5942 req.SetExtraRequestHeaders(headers); |
| 5963 req.Start(); | 5943 req.Start(); |
| 5964 base::RunLoop().Run(); | 5944 base::RunLoop().Run(); |
| 5965 // If the net tests are being run with ChromeFrame then we need to allow for | 5945 EXPECT_EQ(std::string("Lynx (textmode)"), d.data_received()); |
| 5966 // the 'chromeframe' suffix which is added to the user agent before the | |
| 5967 // closing parentheses. | |
| 5968 EXPECT_TRUE(StartsWithASCII(d.data_received(), "Lynx (textmode", true)); | |
| 5969 } | 5946 } |
| 5970 | 5947 |
| 5971 // Check that a NULL HttpUserAgentSettings causes the corresponding empty | 5948 // Check that a NULL HttpUserAgentSettings causes the corresponding empty |
| 5972 // User-Agent header to be sent but does not send the Accept-Language and | 5949 // User-Agent header to be sent but does not send the Accept-Language and |
| 5973 // Accept-Charset headers. | 5950 // Accept-Charset headers. |
| 5974 TEST_F(URLRequestTestHTTP, EmptyHttpUserAgentSettings) { | 5951 TEST_F(URLRequestTestHTTP, EmptyHttpUserAgentSettings) { |
| 5975 ASSERT_TRUE(test_server_.Start()); | 5952 ASSERT_TRUE(test_server_.Start()); |
| 5976 | 5953 |
| 5977 TestNetworkDelegate network_delegate; // Must outlive URLRequests. | 5954 TestNetworkDelegate network_delegate; // Must outlive URLRequests. |
| 5978 TestURLRequestContext context(true); | 5955 TestURLRequestContext context(true); |
| (...skipping 1637 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 7616 | 7593 |
| 7617 EXPECT_FALSE(r.is_pending()); | 7594 EXPECT_FALSE(r.is_pending()); |
| 7618 EXPECT_EQ(1, d->response_started_count()); | 7595 EXPECT_EQ(1, d->response_started_count()); |
| 7619 EXPECT_FALSE(d->received_data_before_response()); | 7596 EXPECT_FALSE(d->received_data_before_response()); |
| 7620 EXPECT_EQ(d->bytes_received(), static_cast<int>(file_size)); | 7597 EXPECT_EQ(d->bytes_received(), static_cast<int>(file_size)); |
| 7621 } | 7598 } |
| 7622 } | 7599 } |
| 7623 #endif // !defined(DISABLE_FTP_SUPPORT) | 7600 #endif // !defined(DISABLE_FTP_SUPPORT) |
| 7624 | 7601 |
| 7625 } // namespace net | 7602 } // namespace net |
| OLD | NEW |