OLD | NEW |
1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2013 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 "chrome/browser/policy/cloud/test_request_interceptor.h" | 5 #include "chrome/browser/policy/cloud/test_request_interceptor.h" |
6 | 6 |
7 #include <limits> | 7 #include <limits> |
8 #include <queue> | 8 #include <queue> |
9 | 9 |
10 #include "base/bind.h" | 10 #include "base/bind.h" |
11 #include "base/bind_helpers.h" | 11 #include "base/bind_helpers.h" |
12 #include "base/memory/scoped_ptr.h" | 12 #include "base/memory/scoped_ptr.h" |
13 #include "content/public/browser/browser_thread.h" | 13 #include "content/public/browser/browser_thread.h" |
14 #include "content/public/test/test_utils.h" | 14 #include "content/public/test/test_utils.h" |
| 15 #include "content/test/net/url_request_mock_http_job.h" |
15 #include "googleurl/src/gurl.h" | 16 #include "googleurl/src/gurl.h" |
16 #include "net/base/net_errors.h" | 17 #include "net/base/net_errors.h" |
17 #include "net/base/upload_bytes_element_reader.h" | 18 #include "net/base/upload_bytes_element_reader.h" |
18 #include "net/base/upload_data_stream.h" | 19 #include "net/base/upload_data_stream.h" |
19 #include "net/base/upload_element_reader.h" | 20 #include "net/base/upload_element_reader.h" |
20 #include "net/url_request/url_request_error_job.h" | 21 #include "net/url_request/url_request_error_job.h" |
21 #include "net/url_request/url_request_filter.h" | 22 #include "net/url_request/url_request_filter.h" |
22 #include "net/url_request/url_request_job_factory.h" | 23 #include "net/url_request/url_request_job_factory.h" |
23 #include "net/url_request/url_request_test_job.h" | 24 #include "net/url_request/url_request_test_job.h" |
24 | 25 |
(...skipping 22 matching lines...) Expand all Loading... |
47 net::NetworkDelegate* network_delegate) { | 48 net::NetworkDelegate* network_delegate) { |
48 static const char kBadHeaders[] = | 49 static const char kBadHeaders[] = |
49 "HTTP/1.1 400 Bad request\0" | 50 "HTTP/1.1 400 Bad request\0" |
50 "Content-type: application/protobuf\0" | 51 "Content-type: application/protobuf\0" |
51 "\0"; | 52 "\0"; |
52 std::string headers(kBadHeaders, arraysize(kBadHeaders)); | 53 std::string headers(kBadHeaders, arraysize(kBadHeaders)); |
53 return new net::URLRequestTestJob( | 54 return new net::URLRequestTestJob( |
54 request, network_delegate, headers, std::string(), true); | 55 request, network_delegate, headers, std::string(), true); |
55 } | 56 } |
56 | 57 |
| 58 net::URLRequestJob* FileJobCallback(const base::FilePath& file_path, |
| 59 net::URLRequest* request, |
| 60 net::NetworkDelegate* network_delegate) { |
| 61 return new content::URLRequestMockHTTPJob( |
| 62 request, |
| 63 network_delegate, |
| 64 file_path); |
| 65 } |
| 66 |
57 // Parses the upload data in |request| into |request_msg|, and validates the | 67 // Parses the upload data in |request| into |request_msg|, and validates the |
58 // request. The query string in the URL must contain the |expected_type| for | 68 // request. The query string in the URL must contain the |expected_type| for |
59 // the "request" parameter. Returns true if all checks succeeded, and the | 69 // the "request" parameter. Returns true if all checks succeeded, and the |
60 // request data has been parsed into |request_msg|. | 70 // request data has been parsed into |request_msg|. |
61 bool ValidRequest(net::URLRequest* request, | 71 bool ValidRequest(net::URLRequest* request, |
62 const std::string& expected_type, | 72 const std::string& expected_type, |
63 em::DeviceManagementRequest* request_msg) { | 73 em::DeviceManagementRequest* request_msg) { |
64 if (request->method() != "POST") | 74 if (request->method() != "POST") |
65 return false; | 75 return false; |
66 std::string spec = request->url().spec(); | 76 std::string spec = request->url().spec(); |
(...skipping 180 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
247 return base::Bind(&BadRequestJobCallback); | 257 return base::Bind(&BadRequestJobCallback); |
248 } | 258 } |
249 | 259 |
250 // static | 260 // static |
251 TestRequestInterceptor::JobCallback TestRequestInterceptor::RegisterJob( | 261 TestRequestInterceptor::JobCallback TestRequestInterceptor::RegisterJob( |
252 em::DeviceRegisterRequest::Type expected_type, | 262 em::DeviceRegisterRequest::Type expected_type, |
253 bool expect_reregister) { | 263 bool expect_reregister) { |
254 return base::Bind(&RegisterJobCallback, expected_type, expect_reregister); | 264 return base::Bind(&RegisterJobCallback, expected_type, expect_reregister); |
255 } | 265 } |
256 | 266 |
| 267 // static |
| 268 TestRequestInterceptor::JobCallback TestRequestInterceptor::FileJob( |
| 269 const base::FilePath& file_path) { |
| 270 return base::Bind(&FileJobCallback, file_path); |
| 271 } |
| 272 |
257 } // namespace policy | 273 } // namespace policy |
OLD | NEW |