OLD | NEW |
(Empty) | |
| 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 |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #ifndef CHROME_BROWSER_POLICY_TEST_REQUEST_INTERCEPTOR_H_ |
| 6 #define CHROME_BROWSER_POLICY_TEST_REQUEST_INTERCEPTOR_H_ |
| 7 |
| 8 #include <string> |
| 9 |
| 10 #include "base/basictypes.h" |
| 11 #include "base/callback.h" |
| 12 #include "chrome/browser/policy/proto/device_management_backend.pb.h" |
| 13 |
| 14 namespace net { |
| 15 class NetworkDelegate; |
| 16 class URLRequest; |
| 17 class URLRequestJob; |
| 18 } |
| 19 |
| 20 namespace policy { |
| 21 |
| 22 // Intercepts all requests to the given hostname while in scope, and allows |
| 23 // queuing callbacks to handle expected requests. Must be created and destroyed |
| 24 // while the IO thread is valid. |
| 25 class TestRequestInterceptor { |
| 26 public: |
| 27 // A callback that returns a new URLRequestJob given a URLRequest. |
| 28 // This is used to queue callbacks that will handle expected requests. |
| 29 typedef base::Callback< |
| 30 net::URLRequestJob*(net::URLRequest*, net::NetworkDelegate*)> JobCallback; |
| 31 |
| 32 // Will intercept request to |hostname| made over HTTP. |
| 33 explicit TestRequestInterceptor(const std::string& hostname); |
| 34 virtual ~TestRequestInterceptor(); |
| 35 |
| 36 // Returns the number of pending callback jobs that haven't been used yet. |
| 37 size_t GetPendingSize() const; |
| 38 |
| 39 // Queues |callback| to handle a request to |hostname_|. Each callback is |
| 40 // used only once, and in the order that they're pushed. |
| 41 void PushJobCallback(const JobCallback& callback); |
| 42 |
| 43 // Returns a JobCallback that will fail with the given network |error|. |
| 44 static JobCallback ErrorJob(int error); |
| 45 |
| 46 // Returns a JobCallback that will fail with HTTP 400 Bad Request. |
| 47 static JobCallback BadRequestJob(); |
| 48 |
| 49 // Returns a JobCallback that will process a policy register request that |
| 50 // should succeed. The request parameters are validated, and an appropriate |
| 51 // response is sent back. |
| 52 // |expected_type| is the expected type in the register request. |
| 53 // If |expect_reregister| is true then the request must have the reregister |
| 54 // flag set; otherwise the flag must be not set. |
| 55 static JobCallback RegisterJob( |
| 56 enterprise_management::DeviceRegisterRequest::Type expected_type, |
| 57 bool expect_reregister); |
| 58 |
| 59 private: |
| 60 class Delegate; |
| 61 |
| 62 const std::string hostname_; |
| 63 |
| 64 // Owned by URLRequestFilter. This handle is valid on IO and only while the |
| 65 // interceptor is valid. |
| 66 Delegate* delegate_; |
| 67 |
| 68 DISALLOW_COPY_AND_ASSIGN(TestRequestInterceptor); |
| 69 }; |
| 70 |
| 71 } // namespace policy |
| 72 |
| 73 #endif // CHROME_BROWSER_POLICY_TEST_REQUEST_INTERCEPTOR_H_ |
OLD | NEW |