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 "content/test/net/url_request_slow_http_job.h" | 5 #include "content/test/net/url_request_slow_http_job.h" |
6 | 6 |
7 #include "base/time.h" | 7 #include "base/time.h" |
8 #include "base/utf_string_conversions.h" | 8 #include "base/utf_string_conversions.h" |
9 #include "net/url_request/url_request_filter.h" | 9 #include "net/url_request/url_request_filter.h" |
10 | 10 |
11 static const char kMockHostname[] = "mock.slow.http"; | 11 static const char kMockHostname[] = "mock.slow.http"; |
12 | 12 |
13 namespace { | 13 namespace { |
14 | 14 |
15 // This is the file path leading to the root of the directory to use as the | 15 // This is the file path leading to the root of the directory to use as the |
16 // root of the http server. This returns a reference that can be assigned to. | 16 // root of the http server. This returns a reference that can be assigned to. |
17 FilePath& BasePath() { | 17 FilePath& BasePath() { |
18 CR_DEFINE_STATIC_LOCAL(FilePath, base_path, ()); | 18 CR_DEFINE_STATIC_LOCAL(FilePath, base_path, ()); |
19 return base_path; | 19 return base_path; |
20 } | 20 } |
21 | 21 |
22 } // namespace | 22 } // namespace |
23 | 23 |
24 // static | 24 // static |
25 const int URLRequestSlowHTTPJob::kDelayMs = 1000; | 25 const int URLRequestSlowHTTPJob::kDelayMs = 1000; |
26 | 26 |
27 using base::TimeDelta; | 27 using base::TimeDelta; |
28 | 28 |
29 // static | 29 // static |
30 net::URLRequestJob* URLRequestSlowHTTPJob::Factory(net::URLRequest* request, | 30 net::URLRequestJob* URLRequestSlowHTTPJob::Factory( |
31 const std::string& scheme) { | 31 net::URLRequest* request, |
32 return new URLRequestSlowHTTPJob(request, | 32 net::NetworkDelegate* network_delegate, |
| 33 const std::string& scheme) { |
| 34 return new URLRequestSlowHTTPJob(request, network_delegate, |
33 GetOnDiskPath(BasePath(), request, scheme)); | 35 GetOnDiskPath(BasePath(), request, scheme)); |
34 } | 36 } |
35 | 37 |
36 // static | 38 // static |
37 void URLRequestSlowHTTPJob::AddUrlHandler(const FilePath& base_path) { | 39 void URLRequestSlowHTTPJob::AddUrlHandler(const FilePath& base_path) { |
38 BasePath() = base_path; | 40 BasePath() = base_path; |
39 | 41 |
40 // Add kMockHostname to net::URLRequestFilter. | 42 // Add kMockHostname to net::URLRequestFilter. |
41 net::URLRequestFilter* filter = net::URLRequestFilter::GetInstance(); | 43 net::URLRequestFilter* filter = net::URLRequestFilter::GetInstance(); |
42 filter->AddHostnameHandler("http", kMockHostname, | 44 filter->AddHostnameHandler("http", kMockHostname, |
43 URLRequestSlowHTTPJob::Factory); | 45 URLRequestSlowHTTPJob::Factory); |
44 } | 46 } |
45 | 47 |
46 /* static */ | 48 /* static */ |
47 GURL URLRequestSlowHTTPJob::GetMockUrl(const FilePath& path) { | 49 GURL URLRequestSlowHTTPJob::GetMockUrl(const FilePath& path) { |
48 std::string url = "http://"; | 50 std::string url = "http://"; |
49 url.append(kMockHostname); | 51 url.append(kMockHostname); |
50 url.append("/"); | 52 url.append("/"); |
51 std::string path_str = path.MaybeAsASCII(); | 53 std::string path_str = path.MaybeAsASCII(); |
52 DCHECK(!path_str.empty()); // We only expect ASCII paths in tests. | 54 DCHECK(!path_str.empty()); // We only expect ASCII paths in tests. |
53 url.append(path_str); | 55 url.append(path_str); |
54 return GURL(url); | 56 return GURL(url); |
55 } | 57 } |
56 | 58 |
57 URLRequestSlowHTTPJob::URLRequestSlowHTTPJob(net::URLRequest* request, | 59 URLRequestSlowHTTPJob::URLRequestSlowHTTPJob( |
58 const FilePath& file_path) | 60 net::URLRequest* request, |
59 : URLRequestMockHTTPJob(request, file_path) { } | 61 net::NetworkDelegate* network_delegate, |
| 62 const FilePath& file_path) |
| 63 : URLRequestMockHTTPJob(request, network_delegate, file_path) { } |
60 | 64 |
61 void URLRequestSlowHTTPJob::Start() { | 65 void URLRequestSlowHTTPJob::Start() { |
62 delay_timer_.Start(FROM_HERE, TimeDelta::FromMilliseconds(kDelayMs), this, | 66 delay_timer_.Start(FROM_HERE, TimeDelta::FromMilliseconds(kDelayMs), this, |
63 &URLRequestSlowHTTPJob::RealStart); | 67 &URLRequestSlowHTTPJob::RealStart); |
64 } | 68 } |
65 | 69 |
66 URLRequestSlowHTTPJob::~URLRequestSlowHTTPJob() { | 70 URLRequestSlowHTTPJob::~URLRequestSlowHTTPJob() { |
67 } | 71 } |
68 | 72 |
69 void URLRequestSlowHTTPJob::RealStart() { | 73 void URLRequestSlowHTTPJob::RealStart() { |
70 URLRequestMockHTTPJob::Start(); | 74 URLRequestMockHTTPJob::Start(); |
71 } | 75 } |
OLD | NEW |