Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(2395)

Unified Diff: chrome/browser/component_updater/test/url_request_post_interceptor.h

Issue 56023005: First changelist of a series to migrate the component updater protocol (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Fixed broken build due to DISALLOW_COPY_AND_ASSIGN. Created 7 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
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_

Powered by Google App Engine
This is Rietveld 408576698