| Index: chrome_frame/test/test_with_web_server.h
|
| ===================================================================
|
| --- chrome_frame/test/test_with_web_server.h (revision 51968)
|
| +++ chrome_frame/test/test_with_web_server.h (working copy)
|
| @@ -8,6 +8,7 @@
|
| #include <windows.h>
|
| #include <string>
|
|
|
| +#include "chrome_frame/test/chrome_frame_test_utils.h"
|
| #include "chrome_frame/test/http_server.h"
|
| #include "chrome_frame/test/test_server.h"
|
| #include "testing/gtest/include/gtest/gtest.h"
|
| @@ -177,6 +178,66 @@
|
| int port_;
|
| };
|
|
|
| +// Specifies the invocation method for CF.
|
| +class CFInvocation {
|
| + public:
|
| + enum Type {
|
| + NONE = 0,
|
| + META_TAG,
|
| + HTTP_HEADER
|
| + };
|
| +
|
| + CFInvocation(): method_(NONE) {}
|
| + explicit CFInvocation(Type method): method_(method) {}
|
| +
|
| + // Convience methods for creating this class.
|
| + static CFInvocation None() { return CFInvocation(NONE); }
|
| + static CFInvocation MetaTag() { return CFInvocation(META_TAG); }
|
| + static CFInvocation HttpHeader() { return CFInvocation(HTTP_HEADER); }
|
| +
|
| + // Returns whether this page does invoke CF.
|
| + bool invokes_cf() const {
|
| + return method_ != NONE;
|
| + }
|
| +
|
| + Type type() const { return method_; }
|
| +
|
| + private:
|
| + Type method_;
|
| +};
|
| +
|
| +ACTION_P2(SendFast, headers, content) {
|
| + arg0->Send(headers, content);
|
| +}
|
| +
|
| +ACTION_P4(Send, headers, content, chunk, timeout) {
|
| + test_server::ConfigurableConnection::SendOptions options(
|
| + test_server::ConfigurableConnection::SendOptions::
|
| + IMMEDIATE_HEADERS_DELAYED_CONTENT, chunk, timeout);
|
| + arg0->SendWithOptions(std::string(headers),
|
| + std::string(content),
|
| + options);
|
| +}
|
| +
|
| +ACTION_P4(SendSlow, headers, content, chunk, timeout) {
|
| + test_server::ConfigurableConnection::SendOptions options(
|
| + test_server::ConfigurableConnection::SendOptions::DELAYED, chunk, timeout);
|
| + arg0->SendWithOptions(std::string(headers),
|
| + std::string(content),
|
| + options);
|
| +}
|
| +
|
| +// Sends a response with the file data for the given path, if the file exists,
|
| +// or a 404 if the file does not. This response includes a no-cache header.
|
| +ACTION_P2(SendResponse, server, invocation) {
|
| + server->SendResponseHelper(arg0, arg1, invocation, true);
|
| +}
|
| +
|
| +// Same as above except that the response does not include the no-cache header.
|
| +ACTION_P2(SendAllowCacheResponse, server, invocation) {
|
| + server->SendResponseHelper(arg0, arg1, invocation, false);
|
| +}
|
| +
|
| // Simple Gmock friendly web server. Sample usage:
|
| // MockWebServer mock(9999, "0.0.0.0");
|
| // EXPECT_CALL(mock, Get(_, StrEq("/favicon.ico"), _)).WillRepeatedly(SendFast(
|
| @@ -196,38 +257,47 @@
|
| // "Content-Type: text/html\r\n",
|
| // "<html><meta http-equiv=\"X-UA-Compatible\" content=\"chrome=1\" />"
|
| // "<body>Rendered in CF.</body></html>", 4, 1000));
|
| -
|
| class MockWebServer : public test_server::HTTPTestServer {
|
| public:
|
| - MockWebServer(int port, const char* address = "127.0.0.1")
|
| - : test_server::HTTPTestServer(port, address) {}
|
| + MockWebServer(int port, const std::wstring& address, FilePath root_dir)
|
| + : test_server::HTTPTestServer(port, address, root_dir) {}
|
| +
|
| + // Overriden from test_server::HTTPTestServer.
|
| MOCK_METHOD3(Get, void(test_server::ConfigurableConnection* connection,
|
| - const std::string& path,
|
| + const std::wstring& path,
|
| const test_server::Request&r));
|
| MOCK_METHOD3(Post, void(test_server::ConfigurableConnection* connection,
|
| - const std::string& path,
|
| + const std::wstring& path,
|
| const test_server::Request&r));
|
| -};
|
|
|
| -ACTION_P2(SendFast, headers, content) {
|
| - arg0->Send(headers, content);
|
| -}
|
| + // Expect a GET request for |url|. Respond with the file appropriate for
|
| + // the given |url|. Modify the file to follow the given CFInvocation method.
|
| + // The response includes a no-cache header. |allow_meta_tag_double_req|
|
| + // specifies whether to allow the request to happen twice if the invocation
|
| + // is using the CF meta tag.
|
| + void ExpectAndServeRequest(CFInvocation invocation, const std::wstring& url);
|
|
|
| -ACTION_P4(Send, headers, content, chunk, timeout) {
|
| - test_server::ConfigurableConnection::SendOptions options(
|
| - test_server::ConfigurableConnection::SendOptions::
|
| - IMMEDIATE_HEADERS_DELAYED_CONTENT, chunk, timeout);
|
| - arg0->SendWithOptions(std::string(headers),
|
| - std::string(content),
|
| - options);
|
| -}
|
| + // Same as above except do not include the no-cache header.
|
| + void ExpectAndServeRequestAllowCache(CFInvocation invocation,
|
| + const std::wstring& url);
|
|
|
| -ACTION_P4(SendSlow, headers, content, chunk, timeout) {
|
| - test_server::ConfigurableConnection::SendOptions options(
|
| - test_server::ConfigurableConnection::SendOptions::DELAYED, chunk, timeout);
|
| - arg0->SendWithOptions(std::string(headers),
|
| - std::string(content),
|
| - options);
|
| -}
|
| + // Expect any number of GETs for the given resource path (e.g, /favicon.ico)
|
| + // and respond with the file, if it exists, or a 404 if it does not.
|
| + void ExpectAndServeRequestAnyNumberTimes(CFInvocation invocation,
|
| + const std::wstring& path_prefix);
|
|
|
| + // Expect and serve all incoming GET requests.
|
| + void ExpectAndServeAnyRequests(CFInvocation invocation) {
|
| + ExpectAndServeRequestAnyNumberTimes(invocation, L"");
|
| + }
|
| +
|
| + // Send a response on the given connection appropriate for |resource_uri|.
|
| + // If the file referred to by |path| exists, send the file data, otherwise
|
| + // send 404. Modify the file data according to the given invocation method.
|
| + void SendResponseHelper(test_server::ConfigurableConnection* connection,
|
| + const std::wstring& resource_uri,
|
| + CFInvocation invocation,
|
| + bool add_no_cache_header);
|
| +};
|
| +
|
| #endif // CHROME_FRAME_TEST_TEST_WITH_WEB_SERVER_H_
|
|
|