Chromium Code Reviews| 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* MockJobCallback(const base::FilePath& file_path, | |
| 59 net::URLRequest* request, | |
| 60 net::NetworkDelegate* network_delegate) { | |
| 61 LOG(ERROR) << file_path.value(); | |
|
Joao da Silva
2013/05/28 08:27:31
Remove this.
csorba
2013/05/28 12:00:39
Done.
| |
| 62 return new content::URLRequestMockHTTPJob( | |
| 63 request, | |
| 64 network_delegate, | |
| 65 file_path); | |
|
Joao da Silva
2013/05/28 08:27:31
it: indent (+4 spaces)
csorba
2013/05/28 12:00:39
Done.
| |
| 66 } | |
| 67 | |
| 57 // Parses the upload data in |request| into |request_msg|, and validates the | 68 // 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 | 69 // 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 | 70 // the "request" parameter. Returns true if all checks succeeded, and the |
| 60 // request data has been parsed into |request_msg|. | 71 // request data has been parsed into |request_msg|. |
| 61 bool ValidRequest(net::URLRequest* request, | 72 bool ValidRequest(net::URLRequest* request, |
| 62 const std::string& expected_type, | 73 const std::string& expected_type, |
| 63 em::DeviceManagementRequest* request_msg) { | 74 em::DeviceManagementRequest* request_msg) { |
| 64 if (request->method() != "POST") | 75 if (request->method() != "POST") |
| 65 return false; | 76 return false; |
| 66 std::string spec = request->url().spec(); | 77 std::string spec = request->url().spec(); |
| (...skipping 180 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 247 return base::Bind(&BadRequestJobCallback); | 258 return base::Bind(&BadRequestJobCallback); |
| 248 } | 259 } |
| 249 | 260 |
| 250 // static | 261 // static |
| 251 TestRequestInterceptor::JobCallback TestRequestInterceptor::RegisterJob( | 262 TestRequestInterceptor::JobCallback TestRequestInterceptor::RegisterJob( |
| 252 em::DeviceRegisterRequest::Type expected_type, | 263 em::DeviceRegisterRequest::Type expected_type, |
| 253 bool expect_reregister) { | 264 bool expect_reregister) { |
| 254 return base::Bind(&RegisterJobCallback, expected_type, expect_reregister); | 265 return base::Bind(&RegisterJobCallback, expected_type, expect_reregister); |
| 255 } | 266 } |
| 256 | 267 |
| 268 // static | |
| 269 TestRequestInterceptor::JobCallback TestRequestInterceptor::MockJob( | |
| 270 const base::FilePath& file_path) { | |
| 271 return base::Bind(&MockJobCallback, file_path); | |
| 272 } | |
| 273 | |
| 257 } // namespace policy | 274 } // namespace policy |
| OLD | NEW |