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

Side by Side 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: Fix tests Created 5 years 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 unified diff | Download patch
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 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 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 package org.chromium.net; 5 package org.chromium.net;
6 6
7 import android.test.AndroidTestCase; 7 import android.test.AndroidTestCase;
8 8
9 import org.chromium.base.PathUtils; 9 import org.chromium.base.PathUtils;
10 10
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after
68 protected CronetTestFramework startCronetTestFrameworkAndSkipFactoryInit() { 68 protected CronetTestFramework startCronetTestFrameworkAndSkipFactoryInit() {
69 String[] commandLineArgs = { 69 String[] commandLineArgs = {
70 CronetTestFramework.LIBRARY_INIT_KEY, CronetTestFramework.LIBRAR Y_INIT_SKIP}; 70 CronetTestFramework.LIBRARY_INIT_KEY, CronetTestFramework.LIBRAR Y_INIT_SKIP};
71 mCronetTestFramework = 71 mCronetTestFramework =
72 startCronetTestFrameworkWithUrlAndCommandLineArgs(null, commandL ineArgs); 72 startCronetTestFrameworkWithUrlAndCommandLineArgs(null, commandL ineArgs);
73 return mCronetTestFramework; 73 return mCronetTestFramework;
74 } 74 }
75 75
76 @Override 76 @Override
77 protected void runTest() throws Throwable { 77 protected void runTest() throws Throwable {
78 if (!getClass().getPackage().getName().equals( 78 String packageName = getClass().getPackage().getName();
79 "org.chromium.net.urlconnection")) { 79 if (packageName.equals("org.chromium.net.urlconnection")) {
80 try {
81 Method method = getClass().getMethod(getName(), (Class[]) null);
82 if (method.isAnnotationPresent(CompareDefaultWithCronet.class)) {
83 // Run with the default HttpURLConnection implementation fir st.
84 super.runTest();
85 // Use Cronet's implementation, and run the same test.
86 URL.setURLStreamHandlerFactory(mCronetTestFramework.mStreamH andlerFactory);
87 super.runTest();
88 } else if (method.isAnnotationPresent(OnlyRunCronetHttpURLConnec tion.class)) {
89 // Run only with Cronet's implementation.
90 URL.setURLStreamHandlerFactory(mCronetTestFramework.mStreamH andlerFactory);
91 super.runTest();
92 } else {
93 // For all other tests.
94 super.runTest();
95 }
96 } catch (Throwable e) {
97 throw new Throwable("CronetTestBase#runTest failed.", e);
98 }
99 } else if (packageName.equals("org.chromium.net")) {
100 try {
101 Method method = getClass().getMethod(getName(), (Class[]) null);
102 super.runTest();
103 if (!method.isAnnotationPresent(OnlyRunNativeCronet.class)) {
104 if (mCronetTestFramework != null) {
105 mCronetTestFramework.mCronetEngine =
106 new JavaCronetEngine(UserAgent.from(getContext() ));
107 }
108 super.runTest();
109 }
110 } catch (Throwable e) {
111 throw new Throwable("CronetTestBase#runTest failed.", e);
112 }
113 return;
114 } else {
80 super.runTest(); 115 super.runTest();
81 return;
82 }
83 try {
84 Method method = getClass().getMethod(getName(), (Class[]) null);
85 if (method.isAnnotationPresent(CompareDefaultWithCronet.class)) {
86 // Run with the default HttpURLConnection implementation first.
87 super.runTest();
88 // Use Cronet's implementation, and run the same test.
89 URL.setURLStreamHandlerFactory(mCronetTestFramework.mStreamHandl erFactory);
90 super.runTest();
91 } else if (method.isAnnotationPresent(
92 OnlyRunCronetHttpURLConnection.class)) {
93 // Run only with Cronet's implementation.
94 URL.setURLStreamHandlerFactory(mCronetTestFramework.mStreamHandl erFactory);
95 super.runTest();
96 } else {
97 // For all other tests.
98 super.runTest();
99 }
100 } catch (Throwable e) {
101 throw new Throwable("CronetTestBase#runTest failed.", e);
102 } 116 }
103 } 117 }
104 118
105 @Target(ElementType.METHOD) 119 @Target(ElementType.METHOD)
106 @Retention(RetentionPolicy.RUNTIME) 120 @Retention(RetentionPolicy.RUNTIME)
107 public @interface CompareDefaultWithCronet { 121 public @interface CompareDefaultWithCronet {
108 } 122 }
109 123
110 @Target(ElementType.METHOD) 124 @Target(ElementType.METHOD)
111 @Retention(RetentionPolicy.RUNTIME) 125 @Retention(RetentionPolicy.RUNTIME)
112 public @interface OnlyRunCronetHttpURLConnection { 126 public @interface OnlyRunCronetHttpURLConnection {
113 } 127 }
114 128
129 @Target(ElementType.METHOD)
130 @Retention(RetentionPolicy.RUNTIME)
131 public @interface OnlyRunNativeCronet {}
115 } 132 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698