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

Side by Side Diff: components/cronet/android/test/quic_test_server.cc

Issue 1389213003: [Cronet] Use Https for Quic Test Server (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@ryancl
Patch Set: Use mock verifier and fix tests Created 5 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 unified diff | Download patch
OLDNEW
1 // Copyright 2015 The Chromium Authors. All rights reserved. 1 // Copyright 2015 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 #include "quic_test_server.h" 5 #include "quic_test_server.h"
6 6
7 #include "base/android/jni_android.h" 7 #include "base/android/jni_android.h"
8 #include "base/android/jni_string.h" 8 #include "base/android/jni_string.h"
9 #include "base/android/path_utils.h"
9 #include "base/bind.h" 10 #include "base/bind.h"
10 #include "base/files/file_path.h" 11 #include "base/files/file_path.h"
11 #include "base/files/file_util.h" 12 #include "base/files/file_util.h"
12 #include "base/threading/thread.h" 13 #include "base/threading/thread.h"
13 #include "jni/QuicTestServer_jni.h" 14 #include "jni/QuicTestServer_jni.h"
14 #include "net/base/ip_endpoint.h" 15 #include "net/base/ip_endpoint.h"
15 #include "net/base/net_util.h" 16 #include "net/base/net_util.h"
17 #include "net/base/test_data_directory.h"
18 #include "net/quic/crypto/proof_source_chromium.h"
16 #include "net/tools/quic/quic_in_memory_cache.h" 19 #include "net/tools/quic/quic_in_memory_cache.h"
17 #include "net/tools/quic/quic_simple_server.h" 20 #include "net/tools/quic/quic_simple_server.h"
18 21
19 namespace cronet { 22 namespace cronet {
20 23
21 namespace { 24 namespace {
22 25
23 static const char kServerHost[] = "127.0.0.1"; 26 static const char kServerHost[] = "test.example.com";
24 static const int kServerPort = 6121; 27 static const int kServerPort = 6121;
25 28
26 base::Thread* g_quic_server_thread = nullptr; 29 base::Thread* g_quic_server_thread = nullptr;
27 net::tools::QuicSimpleServer* g_quic_server = nullptr; 30 net::tools::QuicSimpleServer* g_quic_server = nullptr;
28 31
29 void ServeFilesFromDirectory( 32 net::ProofSource* CreateProofSource(const base::FilePath& cert_path,
30 const base::FilePath& directory) { 33 const base::FilePath& key_path) {
pauljensen 2015/10/09 20:58:10 any particular reason you have a tiny function tha
xunjieli 2015/10/09 21:19:57 Done.
34 net::ProofSourceChromium* proof_source = new net::ProofSourceChromium();
35 CHECK(proof_source->Initialize(cert_path, key_path));
36 return proof_source;
37 }
38
39 void StartOnServerThread(const base::FilePath& test_files_root) {
31 DCHECK(g_quic_server_thread->task_runner()->BelongsToCurrentThread()); 40 DCHECK(g_quic_server_thread->task_runner()->BelongsToCurrentThread());
32 DCHECK(!g_quic_server); 41 DCHECK(!g_quic_server);
33 base::FilePath file_dir = directory.Append("quic_data"); 42
43 // Set up in-memory cache.
44 base::FilePath file_dir = test_files_root.Append("quic_data");
34 CHECK(base::PathExists(file_dir)) << "Quic data does not exist"; 45 CHECK(base::PathExists(file_dir)) << "Quic data does not exist";
35 net::tools::QuicInMemoryCache::GetInstance()->InitializeFromDirectory( 46 net::tools::QuicInMemoryCache::GetInstance()->InitializeFromDirectory(
36 file_dir.value()); 47 file_dir.value());
37 net::IPAddressNumber ip; 48 net::IPAddressNumber ip;
38 net::ParseIPLiteralToNumber(kServerHost, &ip); 49 net::ParseIPLiteralToNumber(kServerHost, &ip);
39 net::QuicConfig config; 50 net::QuicConfig config;
40 g_quic_server = 51 g_quic_server =
41 new net::tools::QuicSimpleServer(config, net::QuicSupportedVersions()); 52 new net::tools::QuicSimpleServer(config, net::QuicSupportedVersions());
53
54 // Set up server certs.
55 base::FilePath directory;
56 bool success = base::android::GetExternalStorageDirectory(&directory);
pauljensen 2015/10/09 20:58:10 can we combine this and the next line into CHECK(b
xunjieli 2015/10/09 21:19:57 Done.
57 CHECK(success);
58 directory = directory.Append("net/data/ssl/certificates");
59 g_quic_server->SetProofSource(
60 CreateProofSource(directory.Append("quic_test.example.com.crt"),
61 directory.Append("quic_test.example.com.key.pkcs8")));
62
63 // Start listening.
42 int rv = g_quic_server->Listen(net::IPEndPoint(ip, kServerPort)); 64 int rv = g_quic_server->Listen(net::IPEndPoint(ip, kServerPort));
43 CHECK_GE(rv, 0) << "Quic server fails to start"; 65 CHECK_GE(rv, 0) << "Quic server fails to start";
44 JNIEnv* env = base::android::AttachCurrentThread(); 66 JNIEnv* env = base::android::AttachCurrentThread();
45 Java_QuicTestServer_onServerStarted(env); 67 Java_QuicTestServer_onServerStarted(env);
46 } 68 }
47 69
48 void ShutdownOnServerThread() { 70 void ShutdownOnServerThread() {
49 DCHECK(g_quic_server_thread->task_runner()->BelongsToCurrentThread()); 71 DCHECK(g_quic_server_thread->task_runner()->BelongsToCurrentThread());
50 g_quic_server->Shutdown(); 72 g_quic_server->Shutdown();
51 delete g_quic_server; 73 delete g_quic_server;
52 } 74 }
53 75
54 } // namespace 76 } // namespace
55 77
56 // Quic server is currently hardcoded to run on port 6121 of the localhost on 78 // Quic server is currently hardcoded to run on port 6121 of the localhost on
57 // the device. 79 // the device.
58 void StartQuicTestServer(JNIEnv* env, 80 void StartQuicTestServer(JNIEnv* env,
59 const JavaParamRef<jclass>& /*jcaller*/, 81 const JavaParamRef<jclass>& /*jcaller*/,
60 const JavaParamRef<jstring>& jtest_files_root) { 82 const JavaParamRef<jstring>& jtest_files_root) {
61 DCHECK(!g_quic_server_thread); 83 DCHECK(!g_quic_server_thread);
62 g_quic_server_thread = new base::Thread("quic server thread"); 84 g_quic_server_thread = new base::Thread("quic server thread");
63 base::Thread::Options thread_options; 85 base::Thread::Options thread_options;
64 thread_options.message_loop_type = base::MessageLoop::TYPE_IO; 86 thread_options.message_loop_type = base::MessageLoop::TYPE_IO;
65 bool started = g_quic_server_thread->StartWithOptions(thread_options); 87 bool started = g_quic_server_thread->StartWithOptions(thread_options);
66 DCHECK(started); 88 DCHECK(started);
67 base::FilePath test_files_root( 89 base::FilePath test_files_root(
68 base::android::ConvertJavaStringToUTF8(env, jtest_files_root)); 90 base::android::ConvertJavaStringToUTF8(env, jtest_files_root));
69 g_quic_server_thread->task_runner()->PostTask( 91 g_quic_server_thread->task_runner()->PostTask(
70 FROM_HERE, base::Bind(&ServeFilesFromDirectory, test_files_root)); 92 FROM_HERE, base::Bind(&StartOnServerThread, test_files_root));
71 } 93 }
72 94
73 void ShutdownQuicTestServer(JNIEnv* env, 95 void ShutdownQuicTestServer(JNIEnv* env,
74 const JavaParamRef<jclass>& /*jcaller*/) { 96 const JavaParamRef<jclass>& /*jcaller*/) {
75 DCHECK(!g_quic_server_thread->task_runner()->BelongsToCurrentThread()); 97 DCHECK(!g_quic_server_thread->task_runner()->BelongsToCurrentThread());
76 g_quic_server_thread->task_runner()->PostTask( 98 g_quic_server_thread->task_runner()->PostTask(
77 FROM_HERE, base::Bind(&ShutdownOnServerThread)); 99 FROM_HERE, base::Bind(&ShutdownOnServerThread));
78 delete g_quic_server_thread; 100 delete g_quic_server_thread;
79 } 101 }
80 102
81 ScopedJavaLocalRef<jstring> GetServerHost( 103 ScopedJavaLocalRef<jstring> GetServerHost(
82 JNIEnv* env, 104 JNIEnv* env,
83 const JavaParamRef<jclass>& /*jcaller*/) { 105 const JavaParamRef<jclass>& /*jcaller*/) {
84 return base::android::ConvertUTF8ToJavaString(env, kServerHost); 106 return base::android::ConvertUTF8ToJavaString(env, kServerHost);
85 } 107 }
86 108
87 int GetServerPort(JNIEnv* env, const JavaParamRef<jclass>& /*jcaller*/) { 109 int GetServerPort(JNIEnv* env, const JavaParamRef<jclass>& /*jcaller*/) {
88 return kServerPort; 110 return kServerPort;
89 } 111 }
90 112
91 bool RegisterQuicTestServer(JNIEnv* env) { 113 bool RegisterQuicTestServer(JNIEnv* env) {
92 return RegisterNativesImpl(env); 114 return RegisterNativesImpl(env);
93 } 115 }
94 116
95 } // namespace cronet 117 } // namespace cronet
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698