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
3 // found in the LICENSE file.
5 #include "mock_url_request_job_factory.h"
7 #include "base/android/jni_android.h"
8 #include "base/android/jni_string.h"
9 #include "base/files/file_path.h"
10 #include "base/path_service.h"
11 #include "base/threading/sequenced_worker_pool.h"
12 #include "jni/MockUrlRequestJobFactory_jni.h"
13 #include "net/test/url_request/url_request_failed_job.h"
14 #include "net/test/url_request/url_request_mock_http_job.h"
18 void AddUrlInterceptors(JNIEnv
* env
, jclass jcaller
) {
19 base::FilePath test_files_root
;
20 PathService::Get(base::DIR_ANDROID_APP_DATA
, &test_files_root
);
21 net::URLRequestMockHTTPJob::AddUrlHandler(
22 test_files_root
, new base::SequencedWorkerPool(1, "Worker"));
23 net::URLRequestFailedJob::AddUrlHandler();
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();
32 jstring
GetMockUrlWithFailure(JNIEnv
* jenv
,
37 base::FilePath
path(base::android::ConvertJavaStringToUTF8(jenv
, jpath
));
38 GURL
url(net::URLRequestMockHTTPJob::GetMockUrlWithFailure(
40 static_cast<net::URLRequestMockHTTPJob::FailurePhase
>(jphase
),
41 static_cast<int>(jnet_error
)));
42 return base::android::ConvertUTF8ToJavaString(jenv
, url
.spec()).Release();
45 bool RegisterMockUrlRequestJobFactory(JNIEnv
* env
) {
46 return RegisterNativesImpl(env
);