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

Unified Diff: components/cronet/ios/test/quic_test_server.cc

Issue 2146643002: [Cronet] Integrate CrNet functionality into Cronet on iOS. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Sync Created 4 years, 2 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « components/cronet/ios/test/quic_test_server.h ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: components/cronet/ios/test/quic_test_server.cc
diff --git a/components/cronet/ios/test/quic_test_server.cc b/components/cronet/ios/test/quic_test_server.cc
index 67b887e4ebc3a174fdcaff6b269cedd43553ad21..dec1b1cdb9183d4528b810d4264e3950dff7898a 100644
--- a/components/cronet/ios/test/quic_test_server.cc
+++ b/components/cronet/ios/test/quic_test_server.cc
@@ -16,6 +16,9 @@
#include "net/base/ip_endpoint.h"
#include "net/quic/chromium/crypto/proof_source_chromium.h"
#include "net/spdy/spdy_header_block.h"
+#include "net/test/embedded_test_server/embedded_test_server.h"
+#include "net/test/embedded_test_server/http_request.h"
+#include "net/test/embedded_test_server/http_response.h"
#include "net/test/test_data_directory.h"
#include "net/tools/quic/quic_in_memory_cache.h"
#include "net/tools/quic/quic_simple_server.h"
@@ -43,6 +46,7 @@ const char kHelloTrailerValue[] = "hello trailer value";
base::Thread* g_quic_server_thread = nullptr;
net::QuicSimpleServer* g_quic_server = nullptr;
+net::EmbeddedTestServer* g_test_server = nullptr;
void SetupQuicInMemoryCache() {
static bool setup_done = false;
@@ -59,6 +63,17 @@ void SetupQuicInMemoryCache() {
std::move(trailers));
}
+std::unique_ptr<net::test_server::HttpResponse> EchoUserAgentHeaderInRequest(
+ const net::test_server::HttpRequest& request) {
+ auto it = request.headers.find("User-Agent");
+ DCHECK(it != request.headers.end());
+
+ std::unique_ptr<net::test_server::BasicHttpResponse> http_response(
+ new net::test_server::BasicHttpResponse());
+ http_response->set_content(it->second);
+ return std::move(http_response);
+}
+
void StartQuicServerOnServerThread(const base::FilePath& test_files_root,
base::WaitableEvent* server_started_event) {
DCHECK(g_quic_server_thread->task_runner()->BelongsToCurrentThread());
@@ -85,14 +100,25 @@ void StartQuicServerOnServerThread(const base::FilePath& test_files_root,
int rv = g_quic_server->Listen(
net::IPEndPoint(net::IPAddress::IPv4AllZeros(), kTestServerPort));
CHECK_GE(rv, 0) << "Quic server fails to start";
+
+ g_test_server =
+ new net::EmbeddedTestServer(net::EmbeddedTestServer::TYPE_HTTPS);
+ g_test_server->RegisterRequestHandler(
+ base::Bind(&EchoUserAgentHeaderInRequest));
+ CHECK(g_test_server->Start());
server_started_event->Signal();
}
void ShutdownOnServerThread(base::WaitableEvent* server_stopped_event) {
+ // TODO(mef): Delete g_test_server without hanging.
+ // delete g_test_server;
+ g_test_server = nullptr;
+
DCHECK(g_quic_server_thread->task_runner()->BelongsToCurrentThread());
g_quic_server->Shutdown();
delete g_quic_server;
g_quic_server = nullptr;
+
server_stopped_event->Signal();
}
@@ -133,4 +159,9 @@ void ShutdownQuicTestServer() {
g_quic_server_thread = nullptr;
}
+std::string GetTestServerURL(const std::string& path) {
+ DCHECK(g_test_server);
+ return g_test_server->GetURL(path).spec();
+}
+
} // namespace cronet
« no previous file with comments | « components/cronet/ios/test/quic_test_server.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698