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

Unified Diff: components/cronet/android/test/mock_url_request_job.cc

Issue 525613002: Set up initial MockURLRequestJob tests for Cronet (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Addressed comments Created 6 years, 3 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 side-by-side diff with in-line comments
Download patch
Index: components/cronet/android/test/mock_url_request_job.cc
diff --git a/components/cronet/android/test/mock_url_request_job.cc b/components/cronet/android/test/mock_url_request_job.cc
new file mode 100644
index 0000000000000000000000000000000000000000..923b89bb14eb27cddcce4556e745163465570729
--- /dev/null
+++ b/components/cronet/android/test/mock_url_request_job.cc
@@ -0,0 +1,42 @@
+// Copyright 2014 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "base/android/jni_android.h"
+#include "base/android/jni_registrar.h"
+#include "base/android/jni_string.h"
+#include "base/macros.h"
+#include "jni/URLRequestJobUtil_jni.h"
+#include "net/base/net_errors.h"
+#include "net/test/url_request_failed_job.h"
+#include "net/url_request/url_request_filter.h"
+#include "url/gurl.h"
+
+using base::android::ConvertJavaStringToUTF8;
+
+namespace cronet {
+namespace {
+// Fails requests using ERR_CONNECTION_RESET.
+net::URLRequestJob* FailedJobFactory(
+ net::URLRequest* request,
+ net::NetworkDelegate* network_delegate,
+ const std::string& scheme) {
+ return new net::URLRequestFailedJob(
+ request, network_delegate, net::ERR_CONNECTION_RESET);
+}
+
+} // namespace
+
+static void FailURLRequestJob(JNIEnv* env, jclass jcaller, jstring jurl) {
+ net::URLRequestFilter* filter = net::URLRequestFilter::GetInstance();
+ filter->AddUrlHandler(
+ GURL(ConvertJavaStringToUTF8(env, jurl)), &FailedJobFactory);
mmenke 2014/09/03 18:02:35 Suggest just using URLRequestFailedJob::AddUrlHand
+}
+
+// Explicitly register static JNI functions.
+bool MockURLRequestJobRegisterJni(JNIEnv* env) {
+ return RegisterNativesImpl(env);
+}
+
+} // namespace cronet
+

Powered by Google App Engine
This is Rietveld 408576698