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

Side by Side Diff: net/test/embedded_test_server/embedded_test_server.h

Issue 1905873002: Add content_browsertests for testing cache control flags (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: reload.html wasn't there Created 4 years, 7 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
OLDNEW
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 NET_TEST_EMBEDDED_TEST_SERVER_EMBEDDED_TEST_SERVER_H_ 5 #ifndef NET_TEST_EMBEDDED_TEST_SERVER_EMBEDDED_TEST_SERVER_H_
6 #define NET_TEST_EMBEDDED_TEST_SERVER_EMBEDDED_TEST_SERVER_H_ 6 #define NET_TEST_EMBEDDED_TEST_SERVER_EMBEDDED_TEST_SERVER_H_
7 7
8 #include <stdint.h> 8 #include <stdint.h>
9 9
10 #include <map> 10 #include <map>
(...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after
110 CERT_CHAIN_WRONG_ROOT, 110 CERT_CHAIN_WRONG_ROOT,
111 111
112 // Causes the testserver to use a hostname that is a domain 112 // Causes the testserver to use a hostname that is a domain
113 // instead of an IP. 113 // instead of an IP.
114 CERT_COMMON_NAME_IS_DOMAIN, 114 CERT_COMMON_NAME_IS_DOMAIN,
115 }; 115 };
116 116
117 typedef base::Callback<std::unique_ptr<HttpResponse>( 117 typedef base::Callback<std::unique_ptr<HttpResponse>(
118 const HttpRequest& request)> 118 const HttpRequest& request)>
119 HandleRequestCallback; 119 HandleRequestCallback;
120 typedef base::Callback<void(const HttpRequest& request)>
121 MonitorRequestCallback;
120 122
121 // Creates a http test server. Start() must be called to start the server. 123 // Creates a http test server. Start() must be called to start the server.
122 // |type| indicates the protocol type of the server (HTTP/HTTPS). 124 // |type| indicates the protocol type of the server (HTTP/HTTPS).
123 EmbeddedTestServer(); 125 EmbeddedTestServer();
124 explicit EmbeddedTestServer(Type type); 126 explicit EmbeddedTestServer(Type type);
125 ~EmbeddedTestServer(); 127 ~EmbeddedTestServer();
126 128
127 // Sets a connection listener, that would be notified when various connection 129 // Sets a connection listener, that would be notified when various connection
128 // events happen. May only be called before the server is started. Caller 130 // events happen. May only be called before the server is started. Caller
129 // maintains ownership of the listener. 131 // maintains ownership of the listener.
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after
200 202
201 // Registers the default handlers and serve additional files from the 203 // Registers the default handlers and serve additional files from the
202 // |directory| directory, relative to DIR_SOURCE_ROOT. 204 // |directory| directory, relative to DIR_SOURCE_ROOT.
203 void AddDefaultHandlers(const base::FilePath& directory); 205 void AddDefaultHandlers(const base::FilePath& directory);
204 206
205 // The most general purpose method. Any request processing can be added using 207 // The most general purpose method. Any request processing can be added using
206 // this method. Takes ownership of the object. The |callback| is called 208 // this method. Takes ownership of the object. The |callback| is called
207 // on UI thread. 209 // on UI thread.
208 void RegisterRequestHandler(const HandleRequestCallback& callback); 210 void RegisterRequestHandler(const HandleRequestCallback& callback);
209 211
212 // Adds request monitor. The |callback| is called before any other handler is
kinuko 2016/05/12 08:45:05 nit: 'a request monitor' or 'request monitors' 'an
Takashi Toyoshima 2016/05/13 05:27:13 Done.
213 // called, but can not respond it. This is useful to monitor requests that
214 // will be handled by other request handlers.
215 void RegisterRequestMonitor(const MonitorRequestCallback& callback);
216
210 // Adds default handlers, including those added by AddDefaultHandlers, to be 217 // Adds default handlers, including those added by AddDefaultHandlers, to be
211 // tried after all other user-specified handlers have been tried. 218 // tried after all other user-specified handlers have been tried.
212 void RegisterDefaultHandler(const HandleRequestCallback& callback); 219 void RegisterDefaultHandler(const HandleRequestCallback& callback);
213 220
214 private: 221 private:
215 // Shuts down the server. 222 // Shuts down the server.
216 void ShutdownOnIOThread(); 223 void ShutdownOnIOThread();
217 224
218 // Upgrade the TCP connection to one over SSL. 225 // Upgrade the TCP connection to one over SSL.
219 std::unique_ptr<StreamSocket> DoSSLUpgrade( 226 std::unique_ptr<StreamSocket> DoSSLUpgrade(
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after
264 std::unique_ptr<StreamSocket> accepted_socket_; 271 std::unique_ptr<StreamSocket> accepted_socket_;
265 272
266 EmbeddedTestServerConnectionListener* connection_listener_; 273 EmbeddedTestServerConnectionListener* connection_listener_;
267 uint16_t port_; 274 uint16_t port_;
268 GURL base_url_; 275 GURL base_url_;
269 IPEndPoint local_endpoint_; 276 IPEndPoint local_endpoint_;
270 277
271 // Owns the HttpConnection objects. 278 // Owns the HttpConnection objects.
272 std::map<StreamSocket*, HttpConnection*> connections_; 279 std::map<StreamSocket*, HttpConnection*> connections_;
273 280
274 // Vector of registered and default request handlers. 281 // Vector of registered and default request handlers and monitors.
275 std::vector<HandleRequestCallback> request_handlers_; 282 std::vector<HandleRequestCallback> request_handlers_;
283 std::vector<MonitorRequestCallback> request_monitors_;
276 std::vector<HandleRequestCallback> default_request_handlers_; 284 std::vector<HandleRequestCallback> default_request_handlers_;
277 285
278 base::ThreadChecker thread_checker_; 286 base::ThreadChecker thread_checker_;
279 287
280 net::SSLServerConfig ssl_config_; 288 net::SSLServerConfig ssl_config_;
281 ServerCertificate cert_; 289 ServerCertificate cert_;
282 std::unique_ptr<SSLServerContext> context_; 290 std::unique_ptr<SSLServerContext> context_;
283 291
284 base::WeakPtrFactory<EmbeddedTestServer> weak_factory_; 292 base::WeakPtrFactory<EmbeddedTestServer> weak_factory_;
285 293
286 DISALLOW_COPY_AND_ASSIGN(EmbeddedTestServer); 294 DISALLOW_COPY_AND_ASSIGN(EmbeddedTestServer);
287 }; 295 };
288 296
289 } // namespace test_server 297 } // namespace test_server
290 298
291 // TODO(svaldez): Refactor EmbeddedTestServer to be in the net namespace. 299 // TODO(svaldez): Refactor EmbeddedTestServer to be in the net namespace.
292 using test_server::EmbeddedTestServer; 300 using test_server::EmbeddedTestServer;
293 301
294 } // namespace net 302 } // namespace net
295 303
296 #endif // NET_TEST_EMBEDDED_TEST_SERVER_EMBEDDED_TEST_SERVER_H_ 304 #endif // NET_TEST_EMBEDDED_TEST_SERVER_EMBEDDED_TEST_SERVER_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698