summaryrefslogtreecommitdiffstats
path: root/chrome_frame/test/test_with_web_server.h
diff options
context:
space:
mode:
authorkkania@chromium.org <kkania@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-07-12 22:07:03 +0000
committerkkania@chromium.org <kkania@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-07-12 22:07:03 +0000
commit6448b3abcfa035eaf65b7c0c15bb728513f228fe (patch)
tree3d8ee0bf2f528e93616a1d7721bc721ef6726189 /chrome_frame/test/test_with_web_server.h
parentbb2eb35a70fcbc47be253bf50c8648c65271a19e (diff)
downloadchromium_src-6448b3abcfa035eaf65b7c0c15bb728513f228fe.zip
chromium_src-6448b3abcfa035eaf65b7c0c15bb728513f228fe.tar.gz
chromium_src-6448b3abcfa035eaf65b7c0c15bb728513f228fe.tar.bz2
[chrome_frame] Refactor/merge IE no interference tests with other mock event sink tests. Have the test mock contain, not inherit the IE event sink. Use the new test server to verify the right requests are being sent.
BUG=none TEST=none Review URL: http://codereview.chromium.org/2822016 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@52137 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome_frame/test/test_with_web_server.h')
-rw-r--r--chrome_frame/test/test_with_web_server.h119
1 files changed, 94 insertions, 25 deletions
diff --git a/chrome_frame/test/test_with_web_server.h b/chrome_frame/test/test_with_web_server.h
index 30466b9b..18e7086 100644
--- a/chrome_frame/test/test_with_web_server.h
+++ b/chrome_frame/test/test_with_web_server.h
@@ -177,6 +177,66 @@ class SimpleWebServerTest {
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 +256,47 @@ class SimpleWebServerTest {
// "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);
-}
-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);
-}
+ // 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);
+
+ // Same as above except do not include the no-cache header.
+ void ExpectAndServeRequestAllowCache(CFInvocation invocation,
+ const std::wstring& url);
+
+ // 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"");
+ }
-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);
-}
+ // 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_