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

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

Issue 2043803003: 👔 Reland #2: Move side-loaded test data /sdcard -> /sdcard/gtestdata (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: rebase atop https://codereview.chromium.org/2041723006 Created 4 years, 6 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/android/path_utils.h"
10 #include "base/bind.h" 10 #include "base/bind.h"
11 #include "base/files/file_path.h" 11 #include "base/files/file_path.h"
12 #include "base/files/file_util.h" 12 #include "base/files/file_util.h"
13 #include "base/test/test_support_android.h"
13 #include "base/threading/thread.h" 14 #include "base/threading/thread.h"
14 #include "components/cronet/android/test/cronet_test_util.h" 15 #include "components/cronet/android/test/cronet_test_util.h"
15 #include "jni/QuicTestServer_jni.h" 16 #include "jni/QuicTestServer_jni.h"
16 #include "net/base/ip_address.h" 17 #include "net/base/ip_address.h"
17 #include "net/base/ip_endpoint.h" 18 #include "net/base/ip_endpoint.h"
18 #include "net/base/test_data_directory.h" 19 #include "net/base/test_data_directory.h"
19 #include "net/quic/crypto/proof_source_chromium.h" 20 #include "net/quic/crypto/proof_source_chromium.h"
20 #include "net/tools/quic/quic_in_memory_cache.h" 21 #include "net/tools/quic/quic_in_memory_cache.h"
21 #include "net/tools/quic/quic_simple_server.h" 22 #include "net/tools/quic/quic_simple_server.h"
22 23
23 namespace cronet { 24 namespace cronet {
24 25
25 namespace { 26 namespace {
26 27
27 static const int kServerPort = 6121; 28 static const int kServerPort = 6121;
28 29
29 base::Thread* g_quic_server_thread = nullptr; 30 base::Thread* g_quic_server_thread = nullptr;
30 net::QuicSimpleServer* g_quic_server = nullptr; 31 net::QuicSimpleServer* g_quic_server = nullptr;
31 32
32 void StartOnServerThread(const base::FilePath& test_files_root) { 33 void StartOnServerThread(const base::FilePath& test_files_root,
34 const base::FilePath& test_data_dir) {
33 DCHECK(g_quic_server_thread->task_runner()->BelongsToCurrentThread()); 35 DCHECK(g_quic_server_thread->task_runner()->BelongsToCurrentThread());
34 DCHECK(!g_quic_server); 36 DCHECK(!g_quic_server);
35 37
36 // Set up in-memory cache. 38 // Set up in-memory cache.
37 base::FilePath file_dir = test_files_root.Append("quic_data"); 39 base::FilePath file_dir = test_files_root.Append("quic_data");
38 CHECK(base::PathExists(file_dir)) << "Quic data does not exist"; 40 CHECK(base::PathExists(file_dir)) << "Quic data does not exist";
39 net::QuicInMemoryCache::GetInstance()->InitializeFromDirectory( 41 net::QuicInMemoryCache::GetInstance()->InitializeFromDirectory(
40 file_dir.value()); 42 file_dir.value());
41 net::QuicConfig config; 43 net::QuicConfig config;
42 44
43 // Set up server certs. 45 // Set up server certs.
44 base::FilePath directory; 46 base::FilePath directory = test_data_dir.Append("net/data/ssl/certificates");
45 CHECK(base::android::GetExternalStorageDirectory(&directory));
46 directory = directory.Append("net/data/ssl/certificates");
47 // TODO(xunjieli): Use scoped_ptr when crbug.com/545474 is fixed. 47 // TODO(xunjieli): Use scoped_ptr when crbug.com/545474 is fixed.
48 net::ProofSourceChromium* proof_source = new net::ProofSourceChromium(); 48 net::ProofSourceChromium* proof_source = new net::ProofSourceChromium();
49 CHECK(proof_source->Initialize( 49 CHECK(proof_source->Initialize(
50 directory.Append("quic_test.example.com.crt"), 50 directory.Append("quic_test.example.com.crt"),
51 directory.Append("quic_test.example.com.key.pkcs8"), 51 directory.Append("quic_test.example.com.key.pkcs8"),
52 directory.Append("quic_test.example.com.key.sct"))); 52 directory.Append("quic_test.example.com.key.sct")));
53 g_quic_server = new net::QuicSimpleServer(proof_source, config, 53 g_quic_server = new net::QuicSimpleServer(proof_source, config,
54 net::QuicSupportedVersions()); 54 net::QuicSupportedVersions());
55 55
56 // Start listening. 56 // Start listening.
57 int rv = g_quic_server->Listen( 57 int rv = g_quic_server->Listen(
58 net::IPEndPoint(net::IPAddress::IPv4AllZeros(), kServerPort)); 58 net::IPEndPoint(net::IPAddress::IPv4AllZeros(), kServerPort));
59 CHECK_GE(rv, 0) << "Quic server fails to start"; 59 CHECK_GE(rv, 0) << "Quic server fails to start";
60 JNIEnv* env = base::android::AttachCurrentThread(); 60 JNIEnv* env = base::android::AttachCurrentThread();
61 Java_QuicTestServer_onServerStarted(env); 61 Java_QuicTestServer_onServerStarted(env);
62 } 62 }
63 63
64 void ShutdownOnServerThread() { 64 void ShutdownOnServerThread() {
65 DCHECK(g_quic_server_thread->task_runner()->BelongsToCurrentThread()); 65 DCHECK(g_quic_server_thread->task_runner()->BelongsToCurrentThread());
66 g_quic_server->Shutdown(); 66 g_quic_server->Shutdown();
67 delete g_quic_server; 67 delete g_quic_server;
68 } 68 }
69 69
70 } // namespace 70 } // namespace
71 71
72 // Quic server is currently hardcoded to run on port 6121 of the localhost on 72 // Quic server is currently hardcoded to run on port 6121 of the localhost on
73 // the device. 73 // the device.
74 void StartQuicTestServer(JNIEnv* env, 74 void StartQuicTestServer(JNIEnv* env,
75 const JavaParamRef<jclass>& /*jcaller*/, 75 const JavaParamRef<jclass>& /*jcaller*/,
76 const JavaParamRef<jstring>& jtest_files_root) { 76 const JavaParamRef<jstring>& jtest_files_root,
77 const JavaParamRef<jstring>& jtest_data_dir) {
77 DCHECK(!g_quic_server_thread); 78 DCHECK(!g_quic_server_thread);
79 base::FilePath test_data_dir(
80 base::android::ConvertJavaStringToUTF8(env, jtest_data_dir));
81 base::InitAndroidTestPaths(test_data_dir);
82
78 g_quic_server_thread = new base::Thread("quic server thread"); 83 g_quic_server_thread = new base::Thread("quic server thread");
79 base::Thread::Options thread_options; 84 base::Thread::Options thread_options;
80 thread_options.message_loop_type = base::MessageLoop::TYPE_IO; 85 thread_options.message_loop_type = base::MessageLoop::TYPE_IO;
81 bool started = g_quic_server_thread->StartWithOptions(thread_options); 86 bool started = g_quic_server_thread->StartWithOptions(thread_options);
82 DCHECK(started); 87 DCHECK(started);
83 base::FilePath test_files_root( 88 base::FilePath test_files_root(
84 base::android::ConvertJavaStringToUTF8(env, jtest_files_root)); 89 base::android::ConvertJavaStringToUTF8(env, jtest_files_root));
85 g_quic_server_thread->task_runner()->PostTask( 90 g_quic_server_thread->task_runner()->PostTask(
86 FROM_HERE, base::Bind(&StartOnServerThread, test_files_root)); 91 FROM_HERE,
92 base::Bind(&StartOnServerThread, test_files_root, test_data_dir));
87 } 93 }
88 94
89 void ShutdownQuicTestServer(JNIEnv* env, 95 void ShutdownQuicTestServer(JNIEnv* env,
90 const JavaParamRef<jclass>& /*jcaller*/) { 96 const JavaParamRef<jclass>& /*jcaller*/) {
91 DCHECK(!g_quic_server_thread->task_runner()->BelongsToCurrentThread()); 97 DCHECK(!g_quic_server_thread->task_runner()->BelongsToCurrentThread());
92 g_quic_server_thread->task_runner()->PostTask( 98 g_quic_server_thread->task_runner()->PostTask(
93 FROM_HERE, base::Bind(&ShutdownOnServerThread)); 99 FROM_HERE, base::Bind(&ShutdownOnServerThread));
94 delete g_quic_server_thread; 100 delete g_quic_server_thread;
95 } 101 }
96 102
97 ScopedJavaLocalRef<jstring> GetServerHost( 103 ScopedJavaLocalRef<jstring> GetServerHost(
98 JNIEnv* env, 104 JNIEnv* env,
99 const JavaParamRef<jclass>& /*jcaller*/) { 105 const JavaParamRef<jclass>& /*jcaller*/) {
100 return base::android::ConvertUTF8ToJavaString(env, kFakeQuicDomain); 106 return base::android::ConvertUTF8ToJavaString(env, kFakeQuicDomain);
101 } 107 }
102 108
103 int GetServerPort(JNIEnv* env, const JavaParamRef<jclass>& /*jcaller*/) { 109 int GetServerPort(JNIEnv* env, const JavaParamRef<jclass>& /*jcaller*/) {
104 return kServerPort; 110 return kServerPort;
105 } 111 }
106 112
107 bool RegisterQuicTestServer(JNIEnv* env) { 113 bool RegisterQuicTestServer(JNIEnv* env) {
108 return RegisterNativesImpl(env); 114 return RegisterNativesImpl(env);
109 } 115 }
110 116
111 } // namespace cronet 117 } // namespace cronet
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698