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

Side by Side Diff: components/cronet/android/test/native_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 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 "components/cronet/android/test/native_test_server.h" 5 #include "components/cronet/android/test/native_test_server.h"
6 6
7 #include <memory> 7 #include <memory>
8 #include <string> 8 #include <string>
9 #include <utility> 9 #include <utility>
10 10
11 #include "base/android/jni_android.h" 11 #include "base/android/jni_android.h"
12 #include "base/android/jni_string.h" 12 #include "base/android/jni_string.h"
13 #include "base/android/path_utils.h" 13 #include "base/android/path_utils.h"
14 #include "base/bind.h" 14 #include "base/bind.h"
15 #include "base/files/file_path.h" 15 #include "base/files/file_path.h"
16 #include "base/files/file_util.h" 16 #include "base/files/file_util.h"
17 #include "base/macros.h" 17 #include "base/macros.h"
18 #include "base/path_service.h" 18 #include "base/path_service.h"
19 #include "base/strings/string_util.h" 19 #include "base/strings/string_util.h"
20 #include "base/strings/stringprintf.h" 20 #include "base/strings/stringprintf.h"
21 #include "base/test/test_support_android.h"
21 #include "components/cronet/android/test/cronet_test_util.h" 22 #include "components/cronet/android/test/cronet_test_util.h"
22 #include "jni/NativeTestServer_jni.h" 23 #include "jni/NativeTestServer_jni.h"
23 #include "net/base/host_port_pair.h" 24 #include "net/base/host_port_pair.h"
24 #include "net/base/url_util.h" 25 #include "net/base/url_util.h"
25 #include "net/http/http_status_code.h" 26 #include "net/http/http_status_code.h"
26 #include "net/test/embedded_test_server/embedded_test_server.h" 27 #include "net/test/embedded_test_server/embedded_test_server.h"
27 #include "net/test/embedded_test_server/http_request.h" 28 #include "net/test/embedded_test_server/http_request.h"
28 #include "net/test/embedded_test_server/http_response.h" 29 #include "net/test/embedded_test_server/http_response.h"
29 #include "url/gurl.h" 30 #include "url/gurl.h"
30 31
(...skipping 126 matching lines...) Expand 10 before | Expand all | Expand 10 after
157 } 158 }
158 159
159 // Unhandled requests result in the Embedded test server sending a 404. 160 // Unhandled requests result in the Embedded test server sending a 404.
160 return std::unique_ptr<net::test_server::BasicHttpResponse>(); 161 return std::unique_ptr<net::test_server::BasicHttpResponse>();
161 } 162 }
162 163
163 } // namespace 164 } // namespace
164 165
165 jboolean StartNativeTestServer(JNIEnv* env, 166 jboolean StartNativeTestServer(JNIEnv* env,
166 const JavaParamRef<jclass>& jcaller, 167 const JavaParamRef<jclass>& jcaller,
167 const JavaParamRef<jstring>& jtest_files_root) { 168 const JavaParamRef<jstring>& jtest_files_root,
169 const JavaParamRef<jstring>& jtest_data_dir) {
168 // Shouldn't happen. 170 // Shouldn't happen.
169 if (g_test_server) 171 if (g_test_server)
170 return false; 172 return false;
173
174 base::FilePath test_data_dir(
175 base::android::ConvertJavaStringToUTF8(env, jtest_data_dir));
176 base::InitAndroidTestPaths(test_data_dir);
177
171 g_test_server = new net::EmbeddedTestServer(); 178 g_test_server = new net::EmbeddedTestServer();
172 g_test_server->RegisterRequestHandler( 179 g_test_server->RegisterRequestHandler(
173 base::Bind(&NativeTestServerRequestHandler)); 180 base::Bind(&NativeTestServerRequestHandler));
174 g_test_server->RegisterRequestHandler(base::Bind(&SdchRequestHandler)); 181 g_test_server->RegisterRequestHandler(base::Bind(&SdchRequestHandler));
175 base::FilePath test_files_root( 182 base::FilePath test_files_root(
176 base::android::ConvertJavaStringToUTF8(env, jtest_files_root)); 183 base::android::ConvertJavaStringToUTF8(env, jtest_files_root));
177 184
178 // Add a third handler for paths that NativeTestServerRequestHandler does not 185 // Add a third handler for paths that NativeTestServerRequestHandler does not
179 // handle. 186 // handle.
180 g_test_server->ServeFilesFromDirectory(test_files_root); 187 g_test_server->ServeFilesFromDirectory(test_files_root);
(...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after
267 #else 274 #else
268 return JNI_FALSE; 275 return JNI_FALSE;
269 #endif 276 #endif
270 } 277 }
271 278
272 bool RegisterNativeTestServer(JNIEnv* env) { 279 bool RegisterNativeTestServer(JNIEnv* env) {
273 return RegisterNativesImpl(env); 280 return RegisterNativesImpl(env);
274 } 281 }
275 282
276 } // namespace cronet 283 } // namespace cronet
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698