OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 "native_test_server.h" | 5 #include "native_test_server.h" |
6 | 6 |
7 #include <string> | 7 #include <string> |
8 | 8 |
9 #include "base/android/jni_android.h" | 9 #include "base/android/jni_android.h" |
10 #include "base/android/jni_string.h" | 10 #include "base/android/jni_string.h" |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
47 const char kFakeQuicDomain[] = "test.example.com"; | 47 const char kFakeQuicDomain[] = "test.example.com"; |
48 // Path that advertises the dictionary passed in query params if client | 48 // Path that advertises the dictionary passed in query params if client |
49 // supports Sdch encoding. E.g. /sdch/index?q=LeQxM80O will make the server | 49 // supports Sdch encoding. E.g. /sdch/index?q=LeQxM80O will make the server |
50 // responds with "Get-Dictionary: /sdch/dict/LeQxM80O". | 50 // responds with "Get-Dictionary: /sdch/dict/LeQxM80O". |
51 const char kSdchPath[] = "/sdch/index"; | 51 const char kSdchPath[] = "/sdch/index"; |
52 // Path that returns encoded response if client has the right dictionary. | 52 // Path that returns encoded response if client has the right dictionary. |
53 const char kSdchTestPath[] = "/sdch/test"; | 53 const char kSdchTestPath[] = "/sdch/test"; |
54 // Path where dictionaries are stored. | 54 // Path where dictionaries are stored. |
55 const char kSdchDictPath[] = "/sdch/dict/"; | 55 const char kSdchDictPath[] = "/sdch/dict/"; |
56 | 56 |
57 net::test_server::EmbeddedTestServer* g_test_server = nullptr; | 57 net::EmbeddedTestServer* g_test_server = nullptr; |
58 | 58 |
59 scoped_ptr<net::test_server::RawHttpResponse> ConstructResponseBasedOnFile( | 59 scoped_ptr<net::test_server::RawHttpResponse> ConstructResponseBasedOnFile( |
60 const base::FilePath& file_path) { | 60 const base::FilePath& file_path) { |
61 std::string file_contents; | 61 std::string file_contents; |
62 bool read_file = base::ReadFileToString(file_path, &file_contents); | 62 bool read_file = base::ReadFileToString(file_path, &file_contents); |
63 DCHECK(read_file); | 63 DCHECK(read_file); |
64 base::FilePath headers_path( | 64 base::FilePath headers_path( |
65 file_path.AddExtension(FILE_PATH_LITERAL("mock-http-headers"))); | 65 file_path.AddExtension(FILE_PATH_LITERAL("mock-http-headers"))); |
66 std::string headers_contents; | 66 std::string headers_contents; |
67 bool read_headers = base::ReadFileToString(headers_path, &headers_contents); | 67 bool read_headers = base::ReadFileToString(headers_path, &headers_contents); |
(...skipping 126 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
194 } | 194 } |
195 | 195 |
196 } // namespace | 196 } // namespace |
197 | 197 |
198 jboolean StartNativeTestServer(JNIEnv* env, | 198 jboolean StartNativeTestServer(JNIEnv* env, |
199 const JavaParamRef<jclass>& jcaller, | 199 const JavaParamRef<jclass>& jcaller, |
200 const JavaParamRef<jstring>& jtest_files_root) { | 200 const JavaParamRef<jstring>& jtest_files_root) { |
201 // Shouldn't happen. | 201 // Shouldn't happen. |
202 if (g_test_server) | 202 if (g_test_server) |
203 return false; | 203 return false; |
204 g_test_server = new net::test_server::EmbeddedTestServer(); | 204 g_test_server = new net::EmbeddedTestServer(); |
205 g_test_server->RegisterRequestHandler( | 205 g_test_server->RegisterRequestHandler( |
206 base::Bind(&NativeTestServerRequestHandler)); | 206 base::Bind(&NativeTestServerRequestHandler)); |
207 g_test_server->RegisterRequestHandler(base::Bind(&SdchRequestHandler)); | 207 g_test_server->RegisterRequestHandler(base::Bind(&SdchRequestHandler)); |
208 base::FilePath test_files_root( | 208 base::FilePath test_files_root( |
209 base::android::ConvertJavaStringToUTF8(env, jtest_files_root)); | 209 base::android::ConvertJavaStringToUTF8(env, jtest_files_root)); |
210 | 210 |
211 // Add a third handler for paths that NativeTestServerRequestHandler does not | 211 // Add a third handler for paths that NativeTestServerRequestHandler does not |
212 // handle. | 212 // handle. |
213 g_test_server->ServeFilesFromDirectory(test_files_root); | 213 g_test_server->ServeFilesFromDirectory(test_files_root); |
214 return g_test_server->InitializeAndWaitUntilReady(); | 214 return g_test_server->Start(); |
215 } | 215 } |
216 | 216 |
217 void RegisterHostResolverProc(JNIEnv* env, | 217 void RegisterHostResolverProc(JNIEnv* env, |
218 const JavaParamRef<jclass>& jcaller, | 218 const JavaParamRef<jclass>& jcaller, |
219 jlong jadapter, | 219 jlong jadapter, |
220 jboolean jlegacy_api) { | 220 jboolean jlegacy_api) { |
221 if (jlegacy_api == JNI_TRUE) { | 221 if (jlegacy_api == JNI_TRUE) { |
222 URLRequestContextAdapter* context_adapter = | 222 URLRequestContextAdapter* context_adapter = |
223 reinterpret_cast<URLRequestContextAdapter*>(jadapter); | 223 reinterpret_cast<URLRequestContextAdapter*>(jadapter); |
224 context_adapter->PostTaskToNetworkThread( | 224 context_adapter->PostTaskToNetworkThread( |
(...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
319 #else | 319 #else |
320 return JNI_FALSE; | 320 return JNI_FALSE; |
321 #endif | 321 #endif |
322 } | 322 } |
323 | 323 |
324 bool RegisterNativeTestServer(JNIEnv* env) { | 324 bool RegisterNativeTestServer(JNIEnv* env) { |
325 return RegisterNativesImpl(env); | 325 return RegisterNativesImpl(env); |
326 } | 326 } |
327 | 327 |
328 } // namespace cronet | 328 } // namespace cronet |
OLD | NEW |