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

Unified Diff: components/cronet/android/test/src/org/chromium/net/MockUrlRequestJobFactory.java

Issue 2406273002: [Cronet] Test the libcronet that's shipped, not libcronet_test (Closed)
Patch Set: fix perf test Created 4 years, 2 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/src/org/chromium/net/MockUrlRequestJobFactory.java
diff --git a/components/cronet/android/test/src/org/chromium/net/MockUrlRequestJobFactory.java b/components/cronet/android/test/src/org/chromium/net/MockUrlRequestJobFactory.java
index 96750028ea374fcdf297bbdc0fd113dffd9af363..89e863756d72b302172f23615af2327aefe97087 100644
--- a/components/cronet/android/test/src/org/chromium/net/MockUrlRequestJobFactory.java
+++ b/components/cronet/android/test/src/org/chromium/net/MockUrlRequestJobFactory.java
@@ -6,7 +6,10 @@ package org.chromium.net;
import static junit.framework.Assert.assertTrue;
+import android.os.ConditionVariable;
+
import org.chromium.base.annotations.JNINamespace;
+import org.chromium.net.impl.CronetUrlRequestContext;
import org.chromium.net.test.FailurePhase;
/**
@@ -14,11 +17,46 @@ import org.chromium.net.test.FailurePhase;
*/
@JNINamespace("cronet")
public final class MockUrlRequestJobFactory {
+ private static CronetEngine sCronetEngine;
+
/**
* Sets up URL interceptors.
*/
- public static void setUp() {
- nativeAddUrlInterceptors();
+ public static void setUp(final CronetEngine cronetEngine) {
+ sCronetEngine = cronetEngine;
+ CronetTestUtil.prepareNetworkThreadForTesting(cronetEngine);
+
+ // Hop over to network thread and install URL interceptors at the native level.
+ final ConditionVariable done = new ConditionVariable();
+ CronetTestUtil.postToNetworkThread(cronetEngine, new Runnable() {
+ @Override
+ public void run() {
+ long requestContext =
+ ((CronetUrlRequestContext) cronetEngine).getUrlRequestContextForTesting();
+ nativeAddUrlInterceptors();
+ nativeAddUrlInterceptorJobFactory(requestContext);
+ done.open();
+ }
+ });
+ done.block();
+ }
+
+ /**
+ * Remove URL Interceptors.
+ */
+ public static void shutdown() {
+ // Hop over to network thread and remove URL interceptors at the native level.
+ final long requestContext =
+ ((CronetUrlRequestContext) sCronetEngine).getUrlRequestContextForTesting();
+ CronetTestUtil.postToNetworkThread(sCronetEngine, new Runnable() {
+ @Override
+ public void run() {
+ nativeRemoveUrlInterceptorJobFactory(requestContext);
+ }
+ });
+
+ CronetTestUtil.cleanupNetorkThreadForTesting();
+ sCronetEngine = null;
}
/**
@@ -77,6 +115,10 @@ public final class MockUrlRequestJobFactory {
private static native void nativeAddUrlInterceptors();
+ private static native void nativeAddUrlInterceptorJobFactory(long requestContext);
+
+ private static native void nativeRemoveUrlInterceptorJobFactory(long requestContext);
+
private static native String nativeGetMockUrlWithFailure(int phase, int netError);
private static native String nativeGetMockUrlForData(String data,

Powered by Google App Engine
This is Rietveld 408576698