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" |
29 #include "base/run_loop.h" | 31 #include "base/run_loop.h" |
30 #include "base/single_thread_task_runner.h" | 32 #include "base/single_thread_task_runner.h" |
31 #include "base/strings/string_number_conversions.h" | 33 #include "base/strings/string_number_conversions.h" |
32 #include "base/strings/string_piece.h" | 34 #include "base/strings/string_piece.h" |
33 #include "base/strings/string_split.h" | 35 #include "base/strings/string_split.h" |
34 #include "base/strings/string_util.h" | 36 #include "base/strings/string_util.h" |
35 #include "base/strings/stringprintf.h" | 37 #include "base/strings/stringprintf.h" |
36 #include "base/strings/utf_string_conversions.h" | 38 #include "base/strings/utf_string_conversions.h" |
37 #include "base/test/histogram_tester.h" | 39 #include "base/test/histogram_tester.h" |
38 #include "base/thread_task_runner_handle.h" | 40 #include "base/thread_task_runner_handle.h" |
(...skipping 212 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
251 ExpectConnectTimingHasNoTimes(load_timing_info.connect_timing); | 253 ExpectConnectTimingHasNoTimes(load_timing_info.connect_timing); |
252 | 254 |
253 EXPECT_TRUE(load_timing_info.proxy_resolve_start.is_null()); | 255 EXPECT_TRUE(load_timing_info.proxy_resolve_start.is_null()); |
254 EXPECT_TRUE(load_timing_info.proxy_resolve_end.is_null()); | 256 EXPECT_TRUE(load_timing_info.proxy_resolve_end.is_null()); |
255 EXPECT_TRUE(load_timing_info.send_start.is_null()); | 257 EXPECT_TRUE(load_timing_info.send_start.is_null()); |
256 EXPECT_TRUE(load_timing_info.send_end.is_null()); | 258 EXPECT_TRUE(load_timing_info.send_end.is_null()); |
257 EXPECT_TRUE(load_timing_info.receive_headers_end.is_null()); | 259 EXPECT_TRUE(load_timing_info.receive_headers_end.is_null()); |
258 } | 260 } |
259 #endif | 261 #endif |
260 | 262 |
| 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 |
261 // Do a case-insensitive search through |haystack| for |needle|. | 278 // Do a case-insensitive search through |haystack| for |needle|. |
262 bool ContainsString(const std::string& haystack, const char* needle) { | 279 bool ContainsString(const std::string& haystack, const char* needle) { |
263 std::string::const_iterator it = std::search( | 280 std::string::const_iterator it = std::search( |
264 haystack.begin(), haystack.end(), needle, needle + strlen(needle), | 281 haystack.begin(), haystack.end(), needle, needle + strlen(needle), |
265 base::CaseInsensitiveCompareASCII<char>()); | 282 base::CaseInsensitiveCompareASCII<char>()); |
266 return it != haystack.end(); | 283 return it != haystack.end(); |
267 } | 284 } |
268 | 285 |
269 scoped_ptr<UploadDataStream> CreateSimpleUploadData(const char* data) { | 286 scoped_ptr<UploadDataStream> CreateSimpleUploadData(const char* data) { |
270 scoped_ptr<UploadElementReader> reader( | 287 scoped_ptr<UploadElementReader> reader( |
(...skipping 3619 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3890 | 3907 |
3891 base::RunLoop().Run(); | 3908 base::RunLoop().Run(); |
3892 | 3909 |
3893 EXPECT_EQ(URLRequestStatus::FAILED, r->status().status()); | 3910 EXPECT_EQ(URLRequestStatus::FAILED, r->status().status()); |
3894 // The proxy server is not set before failure. | 3911 // The proxy server is not set before failure. |
3895 EXPECT_TRUE(r->proxy_server().IsEmpty()); | 3912 EXPECT_TRUE(r->proxy_server().IsEmpty()); |
3896 EXPECT_EQ(ERR_TUNNEL_CONNECTION_FAILED, r->status().error()); | 3913 EXPECT_EQ(ERR_TUNNEL_CONNECTION_FAILED, r->status().error()); |
3897 } | 3914 } |
3898 } | 3915 } |
3899 | 3916 |
| 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 |
3900 TEST_F(URLRequestTestHTTP, GetTest_NoCache) { | 3938 TEST_F(URLRequestTestHTTP, GetTest_NoCache) { |
3901 ASSERT_TRUE(test_server_.Start()); | 3939 ASSERT_TRUE(test_server_.Start()); |
3902 | 3940 |
3903 TestDelegate d; | 3941 TestDelegate d; |
3904 { | 3942 { |
3905 scoped_ptr<URLRequest> r(default_context_.CreateRequest( | 3943 scoped_ptr<URLRequest> r(default_context_.CreateRequest( |
3906 test_server_.GetURL(std::string()), DEFAULT_PRIORITY, &d)); | 3944 test_server_.GetURL(std::string()), DEFAULT_PRIORITY, &d)); |
3907 | 3945 |
3908 r->Start(); | 3946 r->Start(); |
3909 EXPECT_TRUE(r->is_pending()); | 3947 EXPECT_TRUE(r->is_pending()); |
(...skipping 5563 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
9473 | 9511 |
9474 req->Start(); | 9512 req->Start(); |
9475 req->Cancel(); | 9513 req->Cancel(); |
9476 job->DetachRequest(); | 9514 job->DetachRequest(); |
9477 base::RunLoop().RunUntilIdle(); | 9515 base::RunLoop().RunUntilIdle(); |
9478 EXPECT_EQ(URLRequestStatus::CANCELED, req->status().status()); | 9516 EXPECT_EQ(URLRequestStatus::CANCELED, req->status().status()); |
9479 EXPECT_EQ(0, d.received_redirect_count()); | 9517 EXPECT_EQ(0, d.received_redirect_count()); |
9480 } | 9518 } |
9481 | 9519 |
9482 } // namespace net | 9520 } // namespace net |
OLD | NEW |