| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #ifndef CHROME_FRAME_TEST_TEST_SERVER_H_ | 5 #ifndef CHROME_FRAME_TEST_TEST_SERVER_H_ |
| 6 #define CHROME_FRAME_TEST_TEST_SERVER_H_ | 6 #define CHROME_FRAME_TEST_TEST_SERVER_H_ |
| 7 | 7 |
| 8 // Implementation of an HTTP server for tests. | 8 // Implementation of an HTTP server for tests. |
| 9 // To instantiate the server, make sure you have a message loop on the | 9 // To instantiate the server, make sure you have a message loop on the |
| 10 // current thread and then create an instance of the SimpleWebServer class. | 10 // current thread and then create an instance of the SimpleWebServer class. |
| (...skipping 223 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 234 private: | 234 private: |
| 235 DISALLOW_COPY_AND_ASSIGN(SimpleResponse); | 235 DISALLOW_COPY_AND_ASSIGN(SimpleResponse); |
| 236 }; | 236 }; |
| 237 | 237 |
| 238 // To serve up files from the web server, create an instance of FileResponse | 238 // To serve up files from the web server, create an instance of FileResponse |
| 239 // and add it to the server's list of responses. The content type of the | 239 // and add it to the server's list of responses. The content type of the |
| 240 // file will be determined by calling FindMimeFromData which examines the | 240 // file will be determined by calling FindMimeFromData which examines the |
| 241 // contents of the file and performs registry lookups. | 241 // contents of the file and performs registry lookups. |
| 242 class FileResponse : public ResponseForPath { | 242 class FileResponse : public ResponseForPath { |
| 243 public: | 243 public: |
| 244 FileResponse(const char* request_path, const FilePath& file_path) | 244 FileResponse(const char* request_path, const base::FilePath& file_path) |
| 245 : ResponseForPath(request_path), file_path_(file_path) { | 245 : ResponseForPath(request_path), file_path_(file_path) { |
| 246 } | 246 } |
| 247 | 247 |
| 248 virtual bool GetContentType(std::string* content_type) const; | 248 virtual bool GetContentType(std::string* content_type) const; |
| 249 virtual void WriteContents(net::StreamListenSocket* socket) const; | 249 virtual void WriteContents(net::StreamListenSocket* socket) const; |
| 250 virtual size_t ContentLength() const; | 250 virtual size_t ContentLength() const; |
| 251 | 251 |
| 252 protected: | 252 protected: |
| 253 FilePath file_path_; | 253 base::FilePath file_path_; |
| 254 mutable scoped_ptr<file_util::MemoryMappedFile> file_; | 254 mutable scoped_ptr<file_util::MemoryMappedFile> file_; |
| 255 | 255 |
| 256 private: | 256 private: |
| 257 DISALLOW_COPY_AND_ASSIGN(FileResponse); | 257 DISALLOW_COPY_AND_ASSIGN(FileResponse); |
| 258 }; | 258 }; |
| 259 | 259 |
| 260 // Returns a 302 (temporary redirect) to redirect the client from a path | 260 // Returns a 302 (temporary redirect) to redirect the client from a path |
| 261 // on the test server to a different URL. | 261 // on the test server to a different URL. |
| 262 class RedirectResponse : public ResponseForPath { | 262 class RedirectResponse : public ResponseForPath { |
| 263 public: | 263 public: |
| (...skipping 127 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 391 int cur_pos_; | 391 int cur_pos_; |
| 392 | 392 |
| 393 DISALLOW_COPY_AND_ASSIGN(ConfigurableConnection); | 393 DISALLOW_COPY_AND_ASSIGN(ConfigurableConnection); |
| 394 }; | 394 }; |
| 395 | 395 |
| 396 // Simple class used as a base class for mock webserver. | 396 // Simple class used as a base class for mock webserver. |
| 397 // Override virtual functions Get and Post and use passed ConfigurableConnection | 397 // Override virtual functions Get and Post and use passed ConfigurableConnection |
| 398 // instance to send the response. | 398 // instance to send the response. |
| 399 class HTTPTestServer : public net::StreamListenSocket::Delegate { | 399 class HTTPTestServer : public net::StreamListenSocket::Delegate { |
| 400 public: | 400 public: |
| 401 HTTPTestServer(int port, const std::wstring& address, FilePath root_dir); | 401 HTTPTestServer(int port, const std::wstring& address, |
| 402 base::FilePath root_dir); |
| 402 virtual ~HTTPTestServer(); | 403 virtual ~HTTPTestServer(); |
| 403 | 404 |
| 404 // HTTP GET request is received. Override in derived classes. | 405 // HTTP GET request is received. Override in derived classes. |
| 405 // |connection| can be used to send the response. | 406 // |connection| can be used to send the response. |
| 406 virtual void Get(ConfigurableConnection* connection, | 407 virtual void Get(ConfigurableConnection* connection, |
| 407 const std::wstring& path, const Request& r) = 0; | 408 const std::wstring& path, const Request& r) = 0; |
| 408 | 409 |
| 409 // HTTP POST request is received. Override in derived classes. | 410 // HTTP POST request is received. Override in derived classes. |
| 410 // |connection| can be used to send the response | 411 // |connection| can be used to send the response |
| 411 virtual void Post(ConfigurableConnection* connection, | 412 virtual void Post(ConfigurableConnection* connection, |
| 412 const std::wstring& path, const Request& r) = 0; | 413 const std::wstring& path, const Request& r) = 0; |
| 413 | 414 |
| 414 // Return the appropriate url with the specified path for this server. | 415 // Return the appropriate url with the specified path for this server. |
| 415 std::wstring Resolve(const std::wstring& path); | 416 std::wstring Resolve(const std::wstring& path); |
| 416 | 417 |
| 417 FilePath root_dir() { return root_dir_; } | 418 base::FilePath root_dir() { return root_dir_; } |
| 418 | 419 |
| 419 protected: | 420 protected: |
| 420 int port_; | 421 int port_; |
| 421 std::wstring address_; | 422 std::wstring address_; |
| 422 FilePath root_dir_; | 423 base::FilePath root_dir_; |
| 423 | 424 |
| 424 private: | 425 private: |
| 425 typedef std::list<scoped_refptr<ConfigurableConnection> > ConnectionList; | 426 typedef std::list<scoped_refptr<ConfigurableConnection> > ConnectionList; |
| 426 ConnectionList::iterator FindConnection( | 427 ConnectionList::iterator FindConnection( |
| 427 const net::StreamListenSocket* socket); | 428 const net::StreamListenSocket* socket); |
| 428 scoped_refptr<ConfigurableConnection> ConnectionFromSocket( | 429 scoped_refptr<ConfigurableConnection> ConnectionFromSocket( |
| 429 const net::StreamListenSocket* socket); | 430 const net::StreamListenSocket* socket); |
| 430 | 431 |
| 431 // StreamListenSocket::Delegate overrides. | 432 // StreamListenSocket::Delegate overrides. |
| 432 virtual void DidAccept(net::StreamListenSocket* server, | 433 virtual void DidAccept(net::StreamListenSocket* server, |
| 433 net::StreamListenSocket* socket); | 434 net::StreamListenSocket* socket); |
| 434 virtual void DidRead(net::StreamListenSocket* socket, | 435 virtual void DidRead(net::StreamListenSocket* socket, |
| 435 const char* data, int len); | 436 const char* data, int len); |
| 436 virtual void DidClose(net::StreamListenSocket* socket); | 437 virtual void DidClose(net::StreamListenSocket* socket); |
| 437 | 438 |
| 438 scoped_refptr<net::StreamListenSocket> server_; | 439 scoped_refptr<net::StreamListenSocket> server_; |
| 439 ConnectionList connection_list_; | 440 ConnectionList connection_list_; |
| 440 | 441 |
| 441 DISALLOW_COPY_AND_ASSIGN(HTTPTestServer); | 442 DISALLOW_COPY_AND_ASSIGN(HTTPTestServer); |
| 442 }; | 443 }; |
| 443 | 444 |
| 444 } // namespace test_server | 445 } // namespace test_server |
| 445 | 446 |
| 446 #endif // CHROME_FRAME_TEST_TEST_SERVER_H_ | 447 #endif // CHROME_FRAME_TEST_TEST_SERVER_H_ |
| OLD | NEW |