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

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

Issue 586143002: Initial implementation of Cronet Async API. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Sync Created 6 years, 1 month 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 "mock_url_request_job_util.h" 5 #include "mock_url_request_job_util.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/files/file_path.h" 9 #include "base/files/file_path.h"
9 #include "base/path_service.h" 10 #include "base/path_service.h"
10 #include "base/threading/sequenced_worker_pool.h" 11 #include "base/threading/sequenced_worker_pool.h"
11 #include "jni/MockUrlRequestJobUtil_jni.h" 12 #include "jni/MockUrlRequestJobUtil_jni.h"
12 #include "net/test/url_request/url_request_failed_job.h" 13 #include "net/test/url_request/url_request_failed_job.h"
13 #include "net/test/url_request/url_request_mock_http_job.h" 14 #include "net/test/url_request/url_request_mock_http_job.h"
14 15
15 namespace cronet { 16 namespace cronet {
16 17
17 void AddUrlInterceptors(JNIEnv* env, jclass jcaller) { 18 void AddUrlInterceptors(JNIEnv* env, jclass jcaller) {
18 base::FilePath test_files_root; 19 base::FilePath test_files_root;
19 PathService::Get(base::DIR_ANDROID_APP_DATA, &test_files_root); 20 PathService::Get(base::DIR_ANDROID_APP_DATA, &test_files_root);
20 net::URLRequestMockHTTPJob::AddUrlHandler( 21 net::URLRequestMockHTTPJob::AddUrlHandler(
21 test_files_root, new base::SequencedWorkerPool(1, "Worker")); 22 test_files_root, new base::SequencedWorkerPool(1, "Worker"));
22 net::URLRequestFailedJob::AddUrlHandler(); 23 net::URLRequestFailedJob::AddUrlHandler();
23 } 24 }
24 25
26 jstring GetMockUrl(JNIEnv* jenv, jclass jcaller, jstring jpath) {
27 base::FilePath path(base::android::ConvertJavaStringToUTF8(jenv, jpath));
28 GURL url(net::URLRequestMockHTTPJob::GetMockUrl(path));
29 return base::android::ConvertUTF8ToJavaString(jenv, url.spec()).Release();
30 }
31
32 jstring GetMockUrlWithFailure(JNIEnv* jenv,
33 jclass jcaller,
34 jstring jpath,
35 jint jphase,
36 jint jnet_error) {
37 base::FilePath path(base::android::ConvertJavaStringToUTF8(jenv, jpath));
38 GURL url(net::URLRequestMockHTTPJob::GetMockUrlWithFailure(
39 path,
40 static_cast<net::URLRequestMockHTTPJob::FailurePhase>(jphase),
41 static_cast<int>(jnet_error)));
42 return base::android::ConvertUTF8ToJavaString(jenv, url.spec()).Release();
43 }
44
25 bool RegisterMockUrlRequestJobUtil(JNIEnv* env) { 45 bool RegisterMockUrlRequestJobUtil(JNIEnv* env) {
26 return RegisterNativesImpl(env); 46 return RegisterNativesImpl(env);
27 } 47 }
28 48
29 } // namespace cronet 49 } // namespace cronet
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698