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

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

Issue 1492583002: Add HttpUrlConnection backed implementation of CronetEngine. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Enabled user agent test Created 4 years, 11 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/javatests/src/org/chromium/net/CronetTestBase.java
diff --git a/components/cronet/android/test/javatests/src/org/chromium/net/CronetTestBase.java b/components/cronet/android/test/javatests/src/org/chromium/net/CronetTestBase.java
index 59aad24329b928e7d5d1bf57ad6db0a2357413fc..30c485638c37b013e999e50c1f19e4d44f55ac85 100644
--- a/components/cronet/android/test/javatests/src/org/chromium/net/CronetTestBase.java
+++ b/components/cronet/android/test/javatests/src/org/chromium/net/CronetTestBase.java
@@ -24,6 +24,7 @@ public class CronetTestBase extends AndroidTestCase {
private CronetTestFramework mCronetTestFramework;
// {@code true} when test is being run against system HttpURLConnection implementation.
private boolean mTestingSystemHttpURLConnection;
+ private boolean mTestingJavaImpl = false;
@Override
protected void setUp() throws Exception {
@@ -95,35 +96,57 @@ public class CronetTestBase extends AndroidTestCase {
return mTestingSystemHttpURLConnection;
}
+ /**
+ * Returns {@code true} when test is being run against the java implementation of CronetEngine.
+ */
+ protected boolean testingJavaImpl() {
+ return mTestingJavaImpl;
+ }
+
@Override
protected void runTest() throws Throwable {
mTestingSystemHttpURLConnection = false;
- if (!getClass().getPackage().getName().equals(
- "org.chromium.net.urlconnection")) {
- super.runTest();
- return;
- }
- try {
- Method method = getClass().getMethod(getName(), (Class[]) null);
- if (method.isAnnotationPresent(CompareDefaultWithCronet.class)) {
- // Run with the default HttpURLConnection implementation first.
- mTestingSystemHttpURLConnection = true;
- super.runTest();
- // Use Cronet's implementation, and run the same test.
- mTestingSystemHttpURLConnection = false;
- URL.setURLStreamHandlerFactory(mCronetTestFramework.mStreamHandlerFactory);
- super.runTest();
- } else if (method.isAnnotationPresent(
- OnlyRunCronetHttpURLConnection.class)) {
- // Run only with Cronet's implementation.
- URL.setURLStreamHandlerFactory(mCronetTestFramework.mStreamHandlerFactory);
- super.runTest();
- } else {
- // For all other tests.
+ mTestingJavaImpl = false;
+ String packageName = getClass().getPackage().getName();
+ if (packageName.equals("org.chromium.net.urlconnection")) {
+ try {
+ Method method = getClass().getMethod(getName(), (Class[]) null);
+ if (method.isAnnotationPresent(CompareDefaultWithCronet.class)) {
+ // Run with the default HttpURLConnection implementation first.
+ mTestingSystemHttpURLConnection = true;
+ super.runTest();
+ // Use Cronet's implementation, and run the same test.
+ mTestingSystemHttpURLConnection = false;
+ URL.setURLStreamHandlerFactory(mCronetTestFramework.mStreamHandlerFactory);
+ super.runTest();
+ } else if (method.isAnnotationPresent(OnlyRunCronetHttpURLConnection.class)) {
+ // Run only with Cronet's implementation.
+ URL.setURLStreamHandlerFactory(mCronetTestFramework.mStreamHandlerFactory);
+ super.runTest();
+ } else {
+ // For all other tests.
+ super.runTest();
+ }
+ } catch (Throwable e) {
+ throw new Throwable("CronetTestBase#runTest failed.", e);
+ }
+ } else if (packageName.equals("org.chromium.net")) {
+ try {
+ Method method = getClass().getMethod(getName(), (Class[]) null);
super.runTest();
+ if (!method.isAnnotationPresent(OnlyRunNativeCronet.class)) {
+ if (mCronetTestFramework != null) {
+ mCronetTestFramework.mCronetEngine =
+ new JavaCronetEngine(UserAgent.from(getContext()));
+ }
+ mTestingJavaImpl = true;
+ super.runTest();
+ }
+ } catch (Throwable e) {
+ throw new Throwable("CronetTestBase#runTest failed.", e);
}
- } catch (Throwable e) {
- throw new Throwable("CronetTestBase#runTest failed.", e);
+ } else {
+ super.runTest();
}
}
@@ -162,4 +185,7 @@ public class CronetTestBase extends AndroidTestCase {
public @interface OnlyRunCronetHttpURLConnection {
}
+ @Target(ElementType.METHOD)
+ @Retention(RetentionPolicy.RUNTIME)
+ public @interface OnlyRunNativeCronet {}
pauljensen 2016/01/07 04:33:38 can you make these braces match those on lines 180
Charles 2016/01/07 16:10:02 Done.
}

Powered by Google App Engine
This is Rietveld 408576698