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 "jni/MockUrlRequestJobFactory_jni.h"
10 #include "net/test/url_request/ssl_certificate_error_job.h"
11 #include "net/test/url_request/url_request_failed_job.h"
12 #include "net/test/url_request/url_request_mock_data_job.h"
17 void AddUrlInterceptors(JNIEnv
* env
, const JavaParamRef
<jclass
>& jcaller
) {
18 net::URLRequestMockDataJob::AddUrlHandler();
19 net::URLRequestFailedJob::AddUrlHandler();
20 net::SSLCertificateErrorJob::AddUrlHandler();
23 ScopedJavaLocalRef
<jstring
> GetMockUrlWithFailure(
25 const JavaParamRef
<jclass
>& jcaller
,
28 GURL
url(net::URLRequestFailedJob::GetMockHttpUrlWithFailurePhase(
29 static_cast<net::URLRequestFailedJob::FailurePhase
>(jphase
),
30 static_cast<int>(jnet_error
)));
31 return base::android::ConvertUTF8ToJavaString(jenv
, url
.spec());
34 ScopedJavaLocalRef
<jstring
> GetMockUrlForData(
36 const JavaParamRef
<jclass
>& jcaller
,
37 const JavaParamRef
<jstring
>& jdata
,
38 jint jdata_repeat_count
) {
39 std::string
data(base::android::ConvertJavaStringToUTF8(jenv
, jdata
));
40 GURL
url(net::URLRequestMockDataJob::GetMockHttpUrl(data
,
42 return base::android::ConvertUTF8ToJavaString(jenv
, url
.spec());
45 ScopedJavaLocalRef
<jstring
> GetMockUrlForSSLCertificateError(
47 const JavaParamRef
<jclass
>& jcaller
) {
48 GURL
url(net::SSLCertificateErrorJob::GetMockUrl());
49 return base::android::ConvertUTF8ToJavaString(jenv
, url
.spec());
52 bool RegisterMockUrlRequestJobFactory(JNIEnv
* env
) {
53 return RegisterNativesImpl(env
);