summaryrefslogtreecommitdiffstats
path: root/chrome_frame/test/test_with_web_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_with_web_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_with_web_server.h')
-rw-r--r--chrome_frame/test/test_with_web_server.h54
1 files changed, 54 insertions, 0 deletions
diff --git a/chrome_frame/test/test_with_web_server.h b/chrome_frame/test/test_with_web_server.h
index 16b03bc..30466b9b 100644
--- a/chrome_frame/test/test_with_web_server.h
+++ b/chrome_frame/test/test_with_web_server.h
@@ -11,6 +11,7 @@
#include "chrome_frame/test/http_server.h"
#include "chrome_frame/test/test_server.h"
#include "testing/gtest/include/gtest/gtest.h"
+#include "testing/gmock/include/gmock/gmock.h"
// Include without path to make GYP build see it.
#include "chrome_tab.h" // NOLINT
@@ -176,4 +177,57 @@ class SimpleWebServerTest {
int port_;
};
+// Simple Gmock friendly web server. Sample usage:
+// MockWebServer mock(9999, "0.0.0.0");
+// EXPECT_CALL(mock, Get(_, StrEq("/favicon.ico"), _)).WillRepeatedly(SendFast(
+// "HTTP/1.1 404 Not Found"
+// "text/html; charset=UTF-8", EmptyString()));
+//
+// EXPECT_CALL(mock, Get(_, StrEq("/book"), _)).WillRepeatedly(Send(
+// "HTTP/1.1 302 Found\r\n"
+// "Connection: close\r\n"
+// "Content-Type: text/html\r\n"
+// "Location: library\r\n",
+// "<html>Lalalala</html>", 3, 1000));
+//
+// EXPECT_CALL(mock, Get(_, StrEq("/library"), _)).WillRepeatedly(Send(
+// "HTTP/1.1 200 OK\r\n"
+// "Connection: close\r\n"
+// "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) {}
+ MOCK_METHOD3(Get, void(test_server::ConfigurableConnection* connection,
+ const std::string& path,
+ const test_server::Request&r));
+ MOCK_METHOD3(Post, void(test_server::ConfigurableConnection* connection,
+ const std::string& 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);
+}
+
+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);
+}
+
#endif // CHROME_FRAME_TEST_TEST_WITH_WEB_SERVER_H_