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 |
11 | 11 |
12 #include <algorithm> | 12 #include <algorithm> |
13 | 13 |
14 #include "base/basictypes.h" | 14 #include "base/basictypes.h" |
15 #include "base/bind.h" | 15 #include "base/bind.h" |
16 #include "base/compiler_specific.h" | 16 #include "base/compiler_specific.h" |
17 #include "base/files/file_util.h" | 17 #include "base/files/file_util.h" |
18 #include "base/files/scoped_temp_dir.h" | 18 #include "base/files/scoped_temp_dir.h" |
19 #include "base/format_macros.h" | 19 #include "base/format_macros.h" |
20 #include "base/memory/scoped_ptr.h" | 20 #include "base/memory/scoped_ptr.h" |
21 #include "base/memory/weak_ptr.h" | 21 #include "base/memory/weak_ptr.h" |
22 #include "base/message_loop/message_loop.h" | 22 #include "base/message_loop/message_loop.h" |
23 #include "base/message_loop/message_loop_proxy.h" | |
24 #include "base/path_service.h" | 23 #include "base/path_service.h" |
25 #include "base/run_loop.h" | 24 #include "base/run_loop.h" |
26 #include "base/strings/string_number_conversions.h" | 25 #include "base/strings/string_number_conversions.h" |
27 #include "base/strings/string_piece.h" | 26 #include "base/strings/string_piece.h" |
28 #include "base/strings/string_split.h" | 27 #include "base/strings/string_split.h" |
29 #include "base/strings/string_util.h" | 28 #include "base/strings/string_util.h" |
30 #include "base/strings/stringprintf.h" | 29 #include "base/strings/stringprintf.h" |
31 #include "base/strings/utf_string_conversions.h" | 30 #include "base/strings/utf_string_conversions.h" |
| 31 #include "base/thread_task_runner_handle.h" |
32 #include "net/base/chunked_upload_data_stream.h" | 32 #include "net/base/chunked_upload_data_stream.h" |
33 #include "net/base/elements_upload_data_stream.h" | 33 #include "net/base/elements_upload_data_stream.h" |
34 #include "net/base/load_flags.h" | 34 #include "net/base/load_flags.h" |
35 #include "net/base/load_timing_info.h" | 35 #include "net/base/load_timing_info.h" |
36 #include "net/base/load_timing_info_test_util.h" | 36 #include "net/base/load_timing_info_test_util.h" |
37 #include "net/base/net_errors.h" | 37 #include "net/base/net_errors.h" |
38 #include "net/base/net_module.h" | 38 #include "net/base/net_module.h" |
39 #include "net/base/net_util.h" | 39 #include "net/base/net_util.h" |
40 #include "net/base/request_priority.h" | 40 #include "net/base/request_priority.h" |
41 #include "net/base/test_data_directory.h" | 41 #include "net/base/test_data_directory.h" |
(...skipping 193 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
235 EXPECT_TRUE(load_timing_info.proxy_resolve_start.is_null()); | 235 EXPECT_TRUE(load_timing_info.proxy_resolve_start.is_null()); |
236 EXPECT_TRUE(load_timing_info.proxy_resolve_end.is_null()); | 236 EXPECT_TRUE(load_timing_info.proxy_resolve_end.is_null()); |
237 EXPECT_TRUE(load_timing_info.send_start.is_null()); | 237 EXPECT_TRUE(load_timing_info.send_start.is_null()); |
238 EXPECT_TRUE(load_timing_info.send_end.is_null()); | 238 EXPECT_TRUE(load_timing_info.send_end.is_null()); |
239 EXPECT_TRUE(load_timing_info.receive_headers_end.is_null()); | 239 EXPECT_TRUE(load_timing_info.receive_headers_end.is_null()); |
240 } | 240 } |
241 #endif | 241 #endif |
242 | 242 |
243 // Do a case-insensitive search through |haystack| for |needle|. | 243 // Do a case-insensitive search through |haystack| for |needle|. |
244 bool ContainsString(const std::string& haystack, const char* needle) { | 244 bool ContainsString(const std::string& haystack, const char* needle) { |
245 std::string::const_iterator it = | 245 std::string::const_iterator it = std::search( |
246 std::search(haystack.begin(), | 246 haystack.begin(), haystack.end(), needle, needle + strlen(needle), |
247 haystack.end(), | 247 base::CaseInsensitiveCompareASCII<char>()); |
248 needle, | |
249 needle + strlen(needle), | |
250 base::CaseInsensitiveCompare<char>()); | |
251 return it != haystack.end(); | 248 return it != haystack.end(); |
252 } | 249 } |
253 | 250 |
254 scoped_ptr<UploadDataStream> CreateSimpleUploadData(const char* data) { | 251 scoped_ptr<UploadDataStream> CreateSimpleUploadData(const char* data) { |
255 scoped_ptr<UploadElementReader> reader( | 252 scoped_ptr<UploadElementReader> reader( |
256 new UploadBytesElementReader(data, strlen(data))); | 253 new UploadBytesElementReader(data, strlen(data))); |
257 return ElementsUploadDataStream::CreateWithReader(reader.Pass(), 0); | 254 return ElementsUploadDataStream::CreateWithReader(reader.Pass(), 0); |
258 } | 255 } |
259 | 256 |
260 // Verify that the SSLInfo of a successful SSL connection has valid values. | 257 // Verify that the SSLInfo of a successful SSL connection has valid values. |
(...skipping 366 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
627 SetUpFactory(); | 624 SetUpFactory(); |
628 default_context_.set_job_factory(job_factory_.get()); | 625 default_context_.set_job_factory(job_factory_.get()); |
629 default_context_.Init(); | 626 default_context_.Init(); |
630 PlatformTest::SetUp(); | 627 PlatformTest::SetUp(); |
631 } | 628 } |
632 | 629 |
633 virtual void SetUpFactory() { | 630 virtual void SetUpFactory() { |
634 job_factory_impl_->SetProtocolHandler("data", new DataProtocolHandler); | 631 job_factory_impl_->SetProtocolHandler("data", new DataProtocolHandler); |
635 #if !defined(DISABLE_FILE_SUPPORT) | 632 #if !defined(DISABLE_FILE_SUPPORT) |
636 job_factory_impl_->SetProtocolHandler( | 633 job_factory_impl_->SetProtocolHandler( |
637 "file", new FileProtocolHandler(base::MessageLoopProxy::current())); | 634 "file", new FileProtocolHandler(base::ThreadTaskRunnerHandle::Get())); |
638 #endif | 635 #endif |
639 } | 636 } |
640 | 637 |
641 TestNetworkDelegate* default_network_delegate() { | 638 TestNetworkDelegate* default_network_delegate() { |
642 return &default_network_delegate_; | 639 return &default_network_delegate_; |
643 } | 640 } |
644 | 641 |
645 const TestURLRequestContext& default_context() const { | 642 const TestURLRequestContext& default_context() const { |
646 return default_context_; | 643 return default_context_; |
647 } | 644 } |
(...skipping 4455 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
5103 | 5100 |
5104 ScopedVector<UploadElementReader> element_readers; | 5101 ScopedVector<UploadElementReader> element_readers; |
5105 | 5102 |
5106 base::FilePath path; | 5103 base::FilePath path; |
5107 PathService::Get(base::DIR_SOURCE_ROOT, &path); | 5104 PathService::Get(base::DIR_SOURCE_ROOT, &path); |
5108 path = path.Append(FILE_PATH_LITERAL("net")); | 5105 path = path.Append(FILE_PATH_LITERAL("net")); |
5109 path = path.Append(FILE_PATH_LITERAL("data")); | 5106 path = path.Append(FILE_PATH_LITERAL("data")); |
5110 path = path.Append(FILE_PATH_LITERAL("url_request_unittest")); | 5107 path = path.Append(FILE_PATH_LITERAL("url_request_unittest")); |
5111 path = path.Append(FILE_PATH_LITERAL("with-headers.html")); | 5108 path = path.Append(FILE_PATH_LITERAL("with-headers.html")); |
5112 element_readers.push_back( | 5109 element_readers.push_back( |
5113 new UploadFileElementReader(base::MessageLoopProxy::current().get(), | 5110 new UploadFileElementReader(base::ThreadTaskRunnerHandle::Get().get(), |
5114 path, | 5111 path, 0, kuint64max, base::Time())); |
5115 0, | |
5116 kuint64max, | |
5117 base::Time())); | |
5118 r->set_upload(make_scoped_ptr<UploadDataStream>( | 5112 r->set_upload(make_scoped_ptr<UploadDataStream>( |
5119 new ElementsUploadDataStream(element_readers.Pass(), 0))); | 5113 new ElementsUploadDataStream(element_readers.Pass(), 0))); |
5120 | 5114 |
5121 r->Start(); | 5115 r->Start(); |
5122 EXPECT_TRUE(r->is_pending()); | 5116 EXPECT_TRUE(r->is_pending()); |
5123 | 5117 |
5124 base::RunLoop().Run(); | 5118 base::RunLoop().Run(); |
5125 | 5119 |
5126 int64 size64 = 0; | 5120 int64 size64 = 0; |
5127 ASSERT_EQ(true, base::GetFileSize(path, &size64)); | 5121 ASSERT_EQ(true, base::GetFileSize(path, &size64)); |
(...skipping 19 matching lines...) Expand all Loading... |
5147 | 5141 |
5148 TestDelegate d; | 5142 TestDelegate d; |
5149 { | 5143 { |
5150 scoped_ptr<URLRequest> r(default_context_.CreateRequest( | 5144 scoped_ptr<URLRequest> r(default_context_.CreateRequest( |
5151 test_server_.GetURL("echo"), DEFAULT_PRIORITY, &d)); | 5145 test_server_.GetURL("echo"), DEFAULT_PRIORITY, &d)); |
5152 r->set_method("POST"); | 5146 r->set_method("POST"); |
5153 | 5147 |
5154 ScopedVector<UploadElementReader> element_readers; | 5148 ScopedVector<UploadElementReader> element_readers; |
5155 | 5149 |
5156 element_readers.push_back(new UploadFileElementReader( | 5150 element_readers.push_back(new UploadFileElementReader( |
5157 base::MessageLoopProxy::current().get(), | 5151 base::ThreadTaskRunnerHandle::Get().get(), |
5158 base::FilePath(FILE_PATH_LITERAL( | 5152 base::FilePath(FILE_PATH_LITERAL( |
5159 "c:\\path\\to\\non\\existant\\file.randomness.12345")), | 5153 "c:\\path\\to\\non\\existant\\file.randomness.12345")), |
5160 0, | 5154 0, kuint64max, base::Time())); |
5161 kuint64max, | |
5162 base::Time())); | |
5163 r->set_upload(make_scoped_ptr<UploadDataStream>( | 5155 r->set_upload(make_scoped_ptr<UploadDataStream>( |
5164 new ElementsUploadDataStream(element_readers.Pass(), 0))); | 5156 new ElementsUploadDataStream(element_readers.Pass(), 0))); |
5165 | 5157 |
5166 r->Start(); | 5158 r->Start(); |
5167 EXPECT_TRUE(r->is_pending()); | 5159 EXPECT_TRUE(r->is_pending()); |
5168 | 5160 |
5169 base::RunLoop().Run(); | 5161 base::RunLoop().Run(); |
5170 | 5162 |
5171 EXPECT_TRUE(d.request_failed()); | 5163 EXPECT_TRUE(d.request_failed()); |
5172 EXPECT_FALSE(d.received_data_before_response()); | 5164 EXPECT_FALSE(d.received_data_before_response()); |
(...skipping 348 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
5521 EXPECT_FALSE(data_protocol_handler.IsSafeRedirectTarget(data_url)); | 5513 EXPECT_FALSE(data_protocol_handler.IsSafeRedirectTarget(data_url)); |
5522 | 5514 |
5523 // Test URLRequestJobFactoryImpl::IsSafeRedirectTarget(). | 5515 // Test URLRequestJobFactoryImpl::IsSafeRedirectTarget(). |
5524 EXPECT_FALSE(job_factory_->IsSafeRedirectTarget(data_url)); | 5516 EXPECT_FALSE(job_factory_->IsSafeRedirectTarget(data_url)); |
5525 } | 5517 } |
5526 | 5518 |
5527 #if !defined(DISABLE_FILE_SUPPORT) | 5519 #if !defined(DISABLE_FILE_SUPPORT) |
5528 TEST_F(URLRequestTestHTTP, ProtocolHandlerAndFactoryRestrictFileRedirects) { | 5520 TEST_F(URLRequestTestHTTP, ProtocolHandlerAndFactoryRestrictFileRedirects) { |
5529 // Test URLRequestJobFactory::ProtocolHandler::IsSafeRedirectTarget(). | 5521 // Test URLRequestJobFactory::ProtocolHandler::IsSafeRedirectTarget(). |
5530 GURL file_url("file:///foo.txt"); | 5522 GURL file_url("file:///foo.txt"); |
5531 FileProtocolHandler file_protocol_handler(base::MessageLoopProxy::current()); | 5523 FileProtocolHandler file_protocol_handler( |
| 5524 base::ThreadTaskRunnerHandle::Get()); |
5532 EXPECT_FALSE(file_protocol_handler.IsSafeRedirectTarget(file_url)); | 5525 EXPECT_FALSE(file_protocol_handler.IsSafeRedirectTarget(file_url)); |
5533 | 5526 |
5534 // Test URLRequestJobFactoryImpl::IsSafeRedirectTarget(). | 5527 // Test URLRequestJobFactoryImpl::IsSafeRedirectTarget(). |
5535 EXPECT_FALSE(job_factory_->IsSafeRedirectTarget(file_url)); | 5528 EXPECT_FALSE(job_factory_->IsSafeRedirectTarget(file_url)); |
5536 } | 5529 } |
5537 | 5530 |
5538 TEST_F(URLRequestTestHTTP, RestrictFileRedirects) { | 5531 TEST_F(URLRequestTestHTTP, RestrictFileRedirects) { |
5539 ASSERT_TRUE(test_server_.Start()); | 5532 ASSERT_TRUE(test_server_.Start()); |
5540 | 5533 |
5541 TestDelegate d; | 5534 TestDelegate d; |
(...skipping 3647 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
9189 GURL("http://test_intercept/foo"), DEFAULT_PRIORITY, &d)); | 9182 GURL("http://test_intercept/foo"), DEFAULT_PRIORITY, &d)); |
9190 | 9183 |
9191 EXPECT_FALSE(req->response_info().network_accessed); | 9184 EXPECT_FALSE(req->response_info().network_accessed); |
9192 | 9185 |
9193 req->Start(); | 9186 req->Start(); |
9194 base::RunLoop().Run(); | 9187 base::RunLoop().Run(); |
9195 EXPECT_TRUE(req->response_info().network_accessed); | 9188 EXPECT_TRUE(req->response_info().network_accessed); |
9196 } | 9189 } |
9197 | 9190 |
9198 } // namespace net | 9191 } // namespace net |
OLD | NEW |