Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(42)

Side by Side Diff: chrome_frame/test/test_with_web_server.h

Issue 2822016: [chrome_frame] Refactor/merge IE no interference tests with other mock event ... (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: '' Created 10 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « chrome_frame/test/test_server.cc ('k') | chrome_frame/test/test_with_web_server.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2010 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_WITH_WEB_SERVER_H_ 5 #ifndef CHROME_FRAME_TEST_TEST_WITH_WEB_SERVER_H_
6 #define CHROME_FRAME_TEST_TEST_WITH_WEB_SERVER_H_ 6 #define CHROME_FRAME_TEST_TEST_WITH_WEB_SERVER_H_
7 7
8 #include <windows.h> 8 #include <windows.h>
9 #include <string> 9 #include <string>
10 10
11 #include "chrome_frame/test/chrome_frame_test_utils.h"
11 #include "chrome_frame/test/http_server.h" 12 #include "chrome_frame/test/http_server.h"
12 #include "chrome_frame/test/test_server.h" 13 #include "chrome_frame/test/test_server.h"
13 #include "testing/gtest/include/gtest/gtest.h" 14 #include "testing/gtest/include/gtest/gtest.h"
14 #include "testing/gmock/include/gmock/gmock.h" 15 #include "testing/gmock/include/gmock/gmock.h"
15 16
16 // Include without path to make GYP build see it. 17 // Include without path to make GYP build see it.
17 #include "chrome_tab.h" // NOLINT 18 #include "chrome_tab.h" // NOLINT
18 19
19 // Class that: 20 // Class that:
20 // 1) Starts the local webserver, 21 // 1) Starts the local webserver,
(...skipping 149 matching lines...) Expand 10 before | Expand all | Expand 10 after
170 171
171 test_server::SimpleWebServer* web_server() { 172 test_server::SimpleWebServer* web_server() {
172 return &server_; 173 return &server_;
173 } 174 }
174 175
175 protected: 176 protected:
176 test_server::SimpleWebServer server_; 177 test_server::SimpleWebServer server_;
177 int port_; 178 int port_;
178 }; 179 };
179 180
181 // Specifies the invocation method for CF.
182 class CFInvocation {
183 public:
184 enum Type {
185 NONE = 0,
186 META_TAG,
187 HTTP_HEADER
188 };
189
190 CFInvocation(): method_(NONE) {}
191 explicit CFInvocation(Type method): method_(method) {}
192
193 // Convience methods for creating this class.
194 static CFInvocation None() { return CFInvocation(NONE); }
195 static CFInvocation MetaTag() { return CFInvocation(META_TAG); }
196 static CFInvocation HttpHeader() { return CFInvocation(HTTP_HEADER); }
197
198 // Returns whether this page does invoke CF.
199 bool invokes_cf() const {
200 return method_ != NONE;
201 }
202
203 Type type() const { return method_; }
204
205 private:
206 Type method_;
207 };
208
209 ACTION_P2(SendFast, headers, content) {
210 arg0->Send(headers, content);
211 }
212
213 ACTION_P4(Send, headers, content, chunk, timeout) {
214 test_server::ConfigurableConnection::SendOptions options(
215 test_server::ConfigurableConnection::SendOptions::
216 IMMEDIATE_HEADERS_DELAYED_CONTENT, chunk, timeout);
217 arg0->SendWithOptions(std::string(headers),
218 std::string(content),
219 options);
220 }
221
222 ACTION_P4(SendSlow, headers, content, chunk, timeout) {
223 test_server::ConfigurableConnection::SendOptions options(
224 test_server::ConfigurableConnection::SendOptions::DELAYED, chunk, timeout);
225 arg0->SendWithOptions(std::string(headers),
226 std::string(content),
227 options);
228 }
229
230 // Sends a response with the file data for the given path, if the file exists,
231 // or a 404 if the file does not. This response includes a no-cache header.
232 ACTION_P2(SendResponse, server, invocation) {
233 server->SendResponseHelper(arg0, arg1, invocation, true);
234 }
235
236 // Same as above except that the response does not include the no-cache header.
237 ACTION_P2(SendAllowCacheResponse, server, invocation) {
238 server->SendResponseHelper(arg0, arg1, invocation, false);
239 }
240
180 // Simple Gmock friendly web server. Sample usage: 241 // Simple Gmock friendly web server. Sample usage:
181 // MockWebServer mock(9999, "0.0.0.0"); 242 // MockWebServer mock(9999, "0.0.0.0");
182 // EXPECT_CALL(mock, Get(_, StrEq("/favicon.ico"), _)).WillRepeatedly(SendFast( 243 // EXPECT_CALL(mock, Get(_, StrEq("/favicon.ico"), _)).WillRepeatedly(SendFast(
183 // "HTTP/1.1 404 Not Found" 244 // "HTTP/1.1 404 Not Found"
184 // "text/html; charset=UTF-8", EmptyString())); 245 // "text/html; charset=UTF-8", EmptyString()));
185 // 246 //
186 // EXPECT_CALL(mock, Get(_, StrEq("/book"), _)).WillRepeatedly(Send( 247 // EXPECT_CALL(mock, Get(_, StrEq("/book"), _)).WillRepeatedly(Send(
187 // "HTTP/1.1 302 Found\r\n" 248 // "HTTP/1.1 302 Found\r\n"
188 // "Connection: close\r\n" 249 // "Connection: close\r\n"
189 // "Content-Type: text/html\r\n" 250 // "Content-Type: text/html\r\n"
190 // "Location: library\r\n", 251 // "Location: library\r\n",
191 // "<html>Lalalala</html>", 3, 1000)); 252 // "<html>Lalalala</html>", 3, 1000));
192 // 253 //
193 // EXPECT_CALL(mock, Get(_, StrEq("/library"), _)).WillRepeatedly(Send( 254 // EXPECT_CALL(mock, Get(_, StrEq("/library"), _)).WillRepeatedly(Send(
194 // "HTTP/1.1 200 OK\r\n" 255 // "HTTP/1.1 200 OK\r\n"
195 // "Connection: close\r\n" 256 // "Connection: close\r\n"
196 // "Content-Type: text/html\r\n", 257 // "Content-Type: text/html\r\n",
197 // "<html><meta http-equiv=\"X-UA-Compatible\" content=\"chrome=1\" />" 258 // "<html><meta http-equiv=\"X-UA-Compatible\" content=\"chrome=1\" />"
198 // "<body>Rendered in CF.</body></html>", 4, 1000)); 259 // "<body>Rendered in CF.</body></html>", 4, 1000));
199
200 class MockWebServer : public test_server::HTTPTestServer { 260 class MockWebServer : public test_server::HTTPTestServer {
201 public: 261 public:
202 MockWebServer(int port, const char* address = "127.0.0.1") 262 MockWebServer(int port, const std::wstring& address, FilePath root_dir)
203 : test_server::HTTPTestServer(port, address) {} 263 : test_server::HTTPTestServer(port, address, root_dir) {}
264
265 // Overriden from test_server::HTTPTestServer.
204 MOCK_METHOD3(Get, void(test_server::ConfigurableConnection* connection, 266 MOCK_METHOD3(Get, void(test_server::ConfigurableConnection* connection,
205 const std::string& path, 267 const std::wstring& path,
206 const test_server::Request&r)); 268 const test_server::Request&r));
207 MOCK_METHOD3(Post, void(test_server::ConfigurableConnection* connection, 269 MOCK_METHOD3(Post, void(test_server::ConfigurableConnection* connection,
208 const std::string& path, 270 const std::wstring& path,
209 const test_server::Request&r)); 271 const test_server::Request&r));
272
273 // Expect a GET request for |url|. Respond with the file appropriate for
274 // the given |url|. Modify the file to follow the given CFInvocation method.
275 // The response includes a no-cache header. |allow_meta_tag_double_req|
276 // specifies whether to allow the request to happen twice if the invocation
277 // is using the CF meta tag.
278 void ExpectAndServeRequest(CFInvocation invocation, const std::wstring& url);
279
280 // Same as above except do not include the no-cache header.
281 void ExpectAndServeRequestAllowCache(CFInvocation invocation,
282 const std::wstring& url);
283
284 // Expect any number of GETs for the given resource path (e.g, /favicon.ico)
285 // and respond with the file, if it exists, or a 404 if it does not.
286 void ExpectAndServeRequestAnyNumberTimes(CFInvocation invocation,
287 const std::wstring& path_prefix);
288
289 // Expect and serve all incoming GET requests.
290 void ExpectAndServeAnyRequests(CFInvocation invocation) {
291 ExpectAndServeRequestAnyNumberTimes(invocation, L"");
292 }
293
294 // Send a response on the given connection appropriate for |resource_uri|.
295 // If the file referred to by |path| exists, send the file data, otherwise
296 // send 404. Modify the file data according to the given invocation method.
297 void SendResponseHelper(test_server::ConfigurableConnection* connection,
298 const std::wstring& resource_uri,
299 CFInvocation invocation,
300 bool add_no_cache_header);
210 }; 301 };
211 302
212 ACTION_P2(SendFast, headers, content) {
213 arg0->Send(headers, content);
214 }
215
216 ACTION_P4(Send, headers, content, chunk, timeout) {
217 test_server::ConfigurableConnection::SendOptions options(
218 test_server::ConfigurableConnection::SendOptions::
219 IMMEDIATE_HEADERS_DELAYED_CONTENT, chunk, timeout);
220 arg0->SendWithOptions(std::string(headers),
221 std::string(content),
222 options);
223 }
224
225 ACTION_P4(SendSlow, headers, content, chunk, timeout) {
226 test_server::ConfigurableConnection::SendOptions options(
227 test_server::ConfigurableConnection::SendOptions::DELAYED, chunk, timeout);
228 arg0->SendWithOptions(std::string(headers),
229 std::string(content),
230 options);
231 }
232
233 #endif // CHROME_FRAME_TEST_TEST_WITH_WEB_SERVER_H_ 303 #endif // CHROME_FRAME_TEST_TEST_WITH_WEB_SERVER_H_
OLDNEW
« no previous file with comments | « chrome_frame/test/test_server.cc ('k') | chrome_frame/test/test_with_web_server.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698