summaryrefslogtreecommitdiffstats
path: root/chrome_frame/test/test_server.h
diff options
context:
space:
mode:
authorstoyan@chromium.org <stoyan@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-06-09 16:54:42 +0000
committerstoyan@chromium.org <stoyan@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-06-09 16:54:42 +0000
commit0f53f5628ec01d743afade7de5e8ae350ca6880b (patch)
tree0c664dfb70e4c30b60719a4c24290aec44ca9dc1 /chrome_frame/test/test_server.h
parentce2b9f923c23700d24658b5118ab9c1d2f330d8b (diff)
downloadchromium_src-0f53f5628ec01d743afade7de5e8ae350ca6880b.zip
chromium_src-0f53f5628ec01d743afade7de5e8ae350ca6880b.tar.gz
chromium_src-0f53f5628ec01d743afade7de5e8ae350ca6880b.tar.bz2
Yet another test web server. Supports speed throttle and dump of the traffic.
Allows binding on 0.0.0.0 to allow connections from a VM (for example). Simple GMock class and Actions. Review URL: http://codereview.chromium.org/2620006 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@49266 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome_frame/test/test_server.h')
-rw-r--r--chrome_frame/test/test_server.h77
1 files changed, 77 insertions, 0 deletions
diff --git a/chrome_frame/test/test_server.h b/chrome_frame/test/test_server.h
index 58fd160..b827ceb 100644
--- a/chrome_frame/test/test_server.h
+++ b/chrome_frame/test/test_server.h
@@ -321,6 +321,83 @@ class SimpleWebServer : public ListenSocket::ListenSocketDelegate {
DISALLOW_COPY_AND_ASSIGN(SimpleWebServer);
};
+// Simple class holding incoming HTTP request. Can send the HTTP response
+// at different rate - small chunks, on regular interval.
+class ConfigurableConnection : public base::RefCounted<ConfigurableConnection> {
+ public:
+ struct SendOptions {
+ enum Speed { IMMEDIATE, DELAYED, IMMEDIATE_HEADERS_DELAYED_CONTENT };
+ SendOptions() : speed_(IMMEDIATE), chunk_size_(0), timeout_(0) { }
+ SendOptions(Speed speed, int chunk_size, int64 timeout)
+ : speed_(speed), chunk_size_(chunk_size), timeout_(timeout) {
+ }
+
+ Speed speed_;
+ int chunk_size_;
+ int64 timeout_;
+ };
+
+ explicit ConfigurableConnection(ListenSocket* sock)
+ : socket_(sock), cur_pos_(0) { }
+
+ // Send HTTP response with provided |headers| and |content|. Appends
+ // "Context-Length:" header if the |content| is not empty.
+ void Send(const std::string& headers, const std::string& content);
+
+ // Send HTTP response with provided |headers| and |content|. Appends
+ // "Context-Length:" header if the |content| is not empty.
+ // Use the |options| to tweak the network speed behaviour.
+ void SendWithOptions(const std::string& headers, const std::string& content,
+ const SendOptions& options);
+
+ private:
+ friend class HTTPTestServer;
+ // Sends a chunk of the response and queues itself as a task for sending
+ // next chunk of |data_|.
+ void SendChunk();
+
+ scoped_refptr<ListenSocket> socket_;
+ Request r_;
+ SendOptions options_;
+ std::string data_;
+ int cur_pos_;
+
+ DISALLOW_COPY_AND_ASSIGN(ConfigurableConnection);
+};
+
+// Simple class used as a base class for mock webserver.
+// Override virtual functions Get and Post and use passed ConfigurableConnection
+// instance to send the response.
+class HTTPTestServer : public ListenSocket::ListenSocketDelegate {
+ public:
+ explicit HTTPTestServer(int port, const char* address);
+ virtual ~HTTPTestServer();
+ // HTTP GET request is received. Override in derived classes.
+ // |connection| can be used to send the response.
+ virtual void Get(ConfigurableConnection* connection,
+ const std::string& path, const Request& r) = 0;
+ // HTTP POST request is received. Override in derived classes.
+ // |connection| can be used to send the response
+ virtual void Post(ConfigurableConnection* connection,
+ const std::string& path, const Request& r) = 0;
+
+private:
+ typedef std::list<scoped_refptr<ConfigurableConnection> > ConnectionList;
+ ConnectionList::iterator FindConnection(const ListenSocket* socket);
+ scoped_refptr<ConfigurableConnection> ConnectionFromSocket(
+ const ListenSocket* socket);
+
+ // ListenSocketDelegate overrides.
+ virtual void DidAccept(ListenSocket* server, ListenSocket* socket);
+ virtual void DidRead(ListenSocket* socket, const std::string& data);
+ virtual void DidClose(ListenSocket* socket);
+
+ scoped_refptr<ListenSocket> server_;
+ ConnectionList connection_list_;
+ DISALLOW_COPY_AND_ASSIGN(HTTPTestServer);
+};
+
+
} // namespace test_server
#endif // CHROME_FRAME_TEST_TEST_SERVER_H_