Remove obsolete entries from .gitignore.
[chromium-blink-merge.git] / components / cronet / android / test / mock_url_request_job_factory.cc
blob716faa82cdf5b569297447ec3de1f9df77319df4
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"
13 #include "url/gurl.h"
15 namespace cronet {
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(
24 JNIEnv* jenv,
25 const JavaParamRef<jclass>& jcaller,
26 jint jphase,
27 jint jnet_error) {
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(
35 JNIEnv* jenv,
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,
41 jdata_repeat_count));
42 return base::android::ConvertUTF8ToJavaString(jenv, url.spec());
45 ScopedJavaLocalRef<jstring> GetMockUrlForSSLCertificateError(
46 JNIEnv* jenv,
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);
56 } // namespace cronet