| 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 <stdint.h> | 12 #include <stdint.h> |
| 13 | 13 |
| 14 #include <algorithm> | 14 #include <algorithm> |
| 15 | 15 |
| 16 #include "base/basictypes.h" | 16 #include "base/basictypes.h" |
| 17 #include "base/bind.h" | 17 #include "base/bind.h" |
| 18 #include "base/compiler_specific.h" | 18 #include "base/compiler_specific.h" |
| 19 #include "base/files/file_path.h" | 19 #include "base/files/file_path.h" |
| 20 #include "base/files/file_util.h" | 20 #include "base/files/file_util.h" |
| 21 #include "base/files/scoped_temp_dir.h" | 21 #include "base/files/scoped_temp_dir.h" |
| 22 #include "base/format_macros.h" | 22 #include "base/format_macros.h" |
| 23 #include "base/json/json_reader.h" | 23 #include "base/json/json_reader.h" |
| 24 #include "base/location.h" | 24 #include "base/location.h" |
| 25 #include "base/memory/scoped_ptr.h" | 25 #include "base/memory/scoped_ptr.h" |
| 26 #include "base/memory/weak_ptr.h" | 26 #include "base/memory/weak_ptr.h" |
| 27 #include "base/message_loop/message_loop.h" | 27 #include "base/message_loop/message_loop.h" |
| 28 #include "base/path_service.h" | 28 #include "base/path_service.h" |
| 29 #include "base/power_monitor/power_monitor.h" | |
| 30 #include "base/power_monitor/power_monitor_source.h" | |
| 31 #include "base/run_loop.h" | 29 #include "base/run_loop.h" |
| 32 #include "base/single_thread_task_runner.h" | 30 #include "base/single_thread_task_runner.h" |
| 33 #include "base/strings/string_number_conversions.h" | 31 #include "base/strings/string_number_conversions.h" |
| 34 #include "base/strings/string_piece.h" | 32 #include "base/strings/string_piece.h" |
| 35 #include "base/strings/string_split.h" | 33 #include "base/strings/string_split.h" |
| 36 #include "base/strings/string_util.h" | 34 #include "base/strings/string_util.h" |
| 37 #include "base/strings/stringprintf.h" | 35 #include "base/strings/stringprintf.h" |
| 38 #include "base/strings/utf_string_conversions.h" | 36 #include "base/strings/utf_string_conversions.h" |
| 39 #include "base/test/histogram_tester.h" | 37 #include "base/test/histogram_tester.h" |
| 40 #include "base/thread_task_runner_handle.h" | 38 #include "base/thread_task_runner_handle.h" |
| (...skipping 212 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 253 ExpectConnectTimingHasNoTimes(load_timing_info.connect_timing); | 251 ExpectConnectTimingHasNoTimes(load_timing_info.connect_timing); |
| 254 | 252 |
| 255 EXPECT_TRUE(load_timing_info.proxy_resolve_start.is_null()); | 253 EXPECT_TRUE(load_timing_info.proxy_resolve_start.is_null()); |
| 256 EXPECT_TRUE(load_timing_info.proxy_resolve_end.is_null()); | 254 EXPECT_TRUE(load_timing_info.proxy_resolve_end.is_null()); |
| 257 EXPECT_TRUE(load_timing_info.send_start.is_null()); | 255 EXPECT_TRUE(load_timing_info.send_start.is_null()); |
| 258 EXPECT_TRUE(load_timing_info.send_end.is_null()); | 256 EXPECT_TRUE(load_timing_info.send_end.is_null()); |
| 259 EXPECT_TRUE(load_timing_info.receive_headers_end.is_null()); | 257 EXPECT_TRUE(load_timing_info.receive_headers_end.is_null()); |
| 260 } | 258 } |
| 261 #endif | 259 #endif |
| 262 | 260 |
| 263 // Test power monitor source that can simulate entering suspend mode. Can't use | |
| 264 // the one in base/ because it insists on bringing its own MessageLoop. | |
| 265 class TestPowerMonitorSource : public base::PowerMonitorSource { | |
| 266 public: | |
| 267 TestPowerMonitorSource() {} | |
| 268 ~TestPowerMonitorSource() override {} | |
| 269 | |
| 270 void Suspend() { ProcessPowerEvent(SUSPEND_EVENT); } | |
| 271 | |
| 272 bool IsOnBatteryPowerImpl() override { return false; } | |
| 273 | |
| 274 private: | |
| 275 DISALLOW_COPY_AND_ASSIGN(TestPowerMonitorSource); | |
| 276 }; | |
| 277 | |
| 278 // Do a case-insensitive search through |haystack| for |needle|. | 261 // Do a case-insensitive search through |haystack| for |needle|. |
| 279 bool ContainsString(const std::string& haystack, const char* needle) { | 262 bool ContainsString(const std::string& haystack, const char* needle) { |
| 280 std::string::const_iterator it = std::search( | 263 std::string::const_iterator it = std::search( |
| 281 haystack.begin(), haystack.end(), needle, needle + strlen(needle), | 264 haystack.begin(), haystack.end(), needle, needle + strlen(needle), |
| 282 base::CaseInsensitiveCompareASCII<char>()); | 265 base::CaseInsensitiveCompareASCII<char>()); |
| 283 return it != haystack.end(); | 266 return it != haystack.end(); |
| 284 } | 267 } |
| 285 | 268 |
| 286 scoped_ptr<UploadDataStream> CreateSimpleUploadData(const char* data) { | 269 scoped_ptr<UploadDataStream> CreateSimpleUploadData(const char* data) { |
| 287 scoped_ptr<UploadElementReader> reader( | 270 scoped_ptr<UploadElementReader> reader( |
| (...skipping 3619 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3907 | 3890 |
| 3908 base::RunLoop().Run(); | 3891 base::RunLoop().Run(); |
| 3909 | 3892 |
| 3910 EXPECT_EQ(URLRequestStatus::FAILED, r->status().status()); | 3893 EXPECT_EQ(URLRequestStatus::FAILED, r->status().status()); |
| 3911 // The proxy server is not set before failure. | 3894 // The proxy server is not set before failure. |
| 3912 EXPECT_TRUE(r->proxy_server().IsEmpty()); | 3895 EXPECT_TRUE(r->proxy_server().IsEmpty()); |
| 3913 EXPECT_EQ(ERR_TUNNEL_CONNECTION_FAILED, r->status().error()); | 3896 EXPECT_EQ(ERR_TUNNEL_CONNECTION_FAILED, r->status().error()); |
| 3914 } | 3897 } |
| 3915 } | 3898 } |
| 3916 | 3899 |
| 3917 // Tests that a request is cancelled while entering suspend mode. | |
| 3918 TEST_F(URLRequestTestHTTP, CancelOnSuspend) { | |
| 3919 TestPowerMonitorSource* power_monitor_source = new TestPowerMonitorSource(); | |
| 3920 base::PowerMonitor power_monitor(make_scoped_ptr(power_monitor_source)); | |
| 3921 ASSERT_TRUE(test_server_.Start()); | |
| 3922 | |
| 3923 TestDelegate d; | |
| 3924 // Request that won't complete any time soon. | |
| 3925 GURL url(test_server_.GetURL("slow?600")); | |
| 3926 scoped_ptr<URLRequest> r( | |
| 3927 default_context_.CreateRequest(url, DEFAULT_PRIORITY, &d)); | |
| 3928 r->Start(); | |
| 3929 | |
| 3930 power_monitor_source->Suspend(); | |
| 3931 // Wait for the suspend notification to cause the request to fail. | |
| 3932 base::RunLoop().Run(); | |
| 3933 EXPECT_EQ(URLRequestStatus::CANCELED, r->status().status()); | |
| 3934 EXPECT_TRUE(d.request_failed()); | |
| 3935 EXPECT_EQ(1, default_network_delegate_.completed_requests()); | |
| 3936 } | |
| 3937 | |
| 3938 TEST_F(URLRequestTestHTTP, GetTest_NoCache) { | 3900 TEST_F(URLRequestTestHTTP, GetTest_NoCache) { |
| 3939 ASSERT_TRUE(test_server_.Start()); | 3901 ASSERT_TRUE(test_server_.Start()); |
| 3940 | 3902 |
| 3941 TestDelegate d; | 3903 TestDelegate d; |
| 3942 { | 3904 { |
| 3943 scoped_ptr<URLRequest> r(default_context_.CreateRequest( | 3905 scoped_ptr<URLRequest> r(default_context_.CreateRequest( |
| 3944 test_server_.GetURL(std::string()), DEFAULT_PRIORITY, &d)); | 3906 test_server_.GetURL(std::string()), DEFAULT_PRIORITY, &d)); |
| 3945 | 3907 |
| 3946 r->Start(); | 3908 r->Start(); |
| 3947 EXPECT_TRUE(r->is_pending()); | 3909 EXPECT_TRUE(r->is_pending()); |
| (...skipping 5563 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 9511 | 9473 |
| 9512 req->Start(); | 9474 req->Start(); |
| 9513 req->Cancel(); | 9475 req->Cancel(); |
| 9514 job->DetachRequest(); | 9476 job->DetachRequest(); |
| 9515 base::RunLoop().RunUntilIdle(); | 9477 base::RunLoop().RunUntilIdle(); |
| 9516 EXPECT_EQ(URLRequestStatus::CANCELED, req->status().status()); | 9478 EXPECT_EQ(URLRequestStatus::CANCELED, req->status().status()); |
| 9517 EXPECT_EQ(0, d.received_redirect_count()); | 9479 EXPECT_EQ(0, d.received_redirect_count()); |
| 9518 } | 9480 } |
| 9519 | 9481 |
| 9520 } // namespace net | 9482 } // namespace net |
| OLD | NEW |