Index: chrome/browser/component_updater/test/url_request_post_interceptor.h |
diff --git a/chrome/browser/component_updater/test/url_request_post_interceptor.h b/chrome/browser/component_updater/test/url_request_post_interceptor.h |
index 3d0af2b50a16666f5c6a1f31eb5cbf07748eb361..32b8246637e47dd702256222982c3b274cebb3c9 100644 |
--- a/chrome/browser/component_updater/test/url_request_post_interceptor.h |
+++ b/chrome/browser/component_updater/test/url_request_post_interceptor.h |
@@ -5,68 +5,53 @@ |
#ifndef CHROME_BROWSER_COMPONENT_UPDATER_TEST_URL_REQUEST_POST_INTERCEPTOR_H_ |
#define CHROME_BROWSER_COMPONENT_UPDATER_TEST_URL_REQUEST_POST_INTERCEPTOR_H_ |
+#include <string> |
+#include <vector> |
#include "base/basictypes.h" |
-#include "net/url_request/url_request_job_factory.h" |
-#include "net/url_request/url_request_simple_job.h" |
+ |
+namespace base { |
+class FilePath; |
+} |
namespace net { |
-class NetworkDelegate; |
class URLRequest; |
} |
-class RequestCounter { |
- public: |
- virtual void Trial(net::URLRequest* request) = 0; |
-}; |
- |
+// Intercepts POST requests, counts them, and captures the body of the requests. |
+// Optionally, for each request, it can return a canned response from a |
+// given file. The class maintains a queue of paths to serve responses from, |
+// and returns one and only one response for each request that it intercepts. |
class URLRequestPostInterceptor { |
public: |
- explicit URLRequestPostInterceptor(RequestCounter* counter); |
- virtual ~URLRequestPostInterceptor(); |
+ URLRequestPostInterceptor(const std::string& scheme, |
+ const std::string& hostname); |
+ ~URLRequestPostInterceptor(); |
- private: |
- class Delegate; |
+ // Returns how many requests have been intercepted. |
+ int GetHitCount() const; |
- // After creation, |delegate_| lives on the IO thread, and a task to delete it |
- // is posted from ~URLRequestPostInterceptor(). |
- Delegate* delegate_; |
+ // Returns the requests that have been intercepted. |
+ std::vector<std::string> GetRequests() const; |
- DISALLOW_COPY_AND_ASSIGN(URLRequestPostInterceptor); |
-}; |
+ // Returns all requests as a string for debugging purposes. |
+ std::string GetRequestsAsString() const; |
-class URLRequestPostInterceptor::Delegate |
- : public net::URLRequestJobFactory::ProtocolHandler { |
- public: |
- explicit Delegate(RequestCounter* counter); |
- virtual ~Delegate() {} |
- |
- void Register(); |
- |
- void Unregister(); |
+ // Adds a response to its queue of responses to serve. |
+ // TODO(sorin): implement this. |
+ void AddResponse(const base::FilePath& path); |
private: |
- RequestCounter* counter_; |
- |
- virtual net::URLRequestJob* MaybeCreateJob( |
- net::URLRequest* request, |
- net::NetworkDelegate* network_delegate) const OVERRIDE; |
-}; |
- |
-class URLRequestPingMockJob : public net::URLRequestSimpleJob { |
- public: |
- URLRequestPingMockJob(net::URLRequest* request, |
- net::NetworkDelegate* network_delegate); |
+ class Delegate; |
- protected: |
- virtual int GetData(std::string* mime_type, |
- std::string* charset, |
- std::string* data, |
- const net::CompletionCallback& callback) const OVERRIDE; |
+ const std::string scheme_; |
+ const std::string hostname_; |
- private: |
- virtual ~URLRequestPingMockJob() {} |
+ // After creation, |delegate_| lives on the IO thread and it is owned by |
+ // a URLRequestFilter after registration. A task to unregister it and |
+ // implicitly destroy it is posted from ~URLRequestPostInterceptor(). |
+ Delegate* delegate_; |
- DISALLOW_COPY_AND_ASSIGN(URLRequestPingMockJob); |
+ DISALLOW_COPY_AND_ASSIGN(URLRequestPostInterceptor); |
}; |
#endif // CHROME_BROWSER_COMPONENT_UPDATER_TEST_URL_REQUEST_POST_INTERCEPTOR_H_ |