| Index: chrome_frame/test/test_server.h
|
| ===================================================================
|
| --- chrome_frame/test/test_server.h (revision 48838)
|
| +++ chrome_frame/test/test_server.h (working copy)
|
| @@ -321,6 +321,83 @@
|
| 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_
|
|
|