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

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

Issue 2660963002: Cronet: a framework to provide alternative Cronet implementations (Closed)
Patch Set: Created 3 years, 10 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 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.ContextUtils; 9 import org.chromium.base.ContextUtils;
10 import org.chromium.base.PathUtils; 10 import org.chromium.base.PathUtils;
11 import org.chromium.net.impl.CronetEngineBase; 11 import org.chromium.net.impl.CronetEngineBase;
12 import org.chromium.net.impl.JavaCronetEngine; 12 import org.chromium.net.impl.JavaCronetEngine;
13 import org.chromium.net.impl.JavaCronetProvider;
13 import org.chromium.net.impl.UserAgent; 14 import org.chromium.net.impl.UserAgent;
14 15
15 import java.lang.annotation.ElementType; 16 import java.lang.annotation.ElementType;
16 import java.lang.annotation.Retention; 17 import java.lang.annotation.Retention;
17 import java.lang.annotation.RetentionPolicy; 18 import java.lang.annotation.RetentionPolicy;
18 import java.lang.annotation.Target; 19 import java.lang.annotation.Target;
19 import java.lang.reflect.AnnotatedElement; 20 import java.lang.reflect.AnnotatedElement;
20 import java.net.URL; 21 import java.net.URL;
21 22
22 /** 23 /**
(...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after
125 } 126 }
126 } catch (Throwable e) { 127 } catch (Throwable e) {
127 throw new Throwable("CronetTestBase#runTest failed.", e); 128 throw new Throwable("CronetTestBase#runTest failed.", e);
128 } 129 }
129 } else if (packageName.equals("org.chromium.net")) { 130 } else if (packageName.equals("org.chromium.net")) {
130 try { 131 try {
131 AnnotatedElement method = getClass().getMethod(getName(), (Class []) null); 132 AnnotatedElement method = getClass().getMethod(getName(), (Class []) null);
132 super.runTest(); 133 super.runTest();
133 if (!method.isAnnotationPresent(OnlyRunNativeCronet.class)) { 134 if (!method.isAnnotationPresent(OnlyRunNativeCronet.class)) {
134 if (mCronetTestFramework != null) { 135 if (mCronetTestFramework != null) {
135 ExperimentalCronetEngine.Builder builder = 136 ExperimentalCronetEngine.Builder builder = createJavaEng ineBuilder();
136 new ExperimentalCronetEngine.Builder(getContext( ));
137 builder.setUserAgent(UserAgent.from(getContext())); 137 builder.setUserAgent(UserAgent.from(getContext()));
138 builder.enableLegacyMode(true);
139 mCronetTestFramework.mCronetEngine = (CronetEngineBase) builder.build(); 138 mCronetTestFramework.mCronetEngine = (CronetEngineBase) builder.build();
140 // Make sure that the instantiated engine is JavaCronetE ngine. 139 // Make sure that the instantiated engine is JavaCronetE ngine.
141 assert mCronetTestFramework.mCronetEngine.getClass() 140 assert mCronetTestFramework.mCronetEngine.getClass()
142 == JavaCronetEngine.class; 141 == JavaCronetEngine.class;
143 } 142 }
144 mTestingJavaImpl = true; 143 mTestingJavaImpl = true;
145 super.runTest(); 144 super.runTest();
146 } 145 }
147 } catch (Throwable e) { 146 } catch (Throwable e) {
148 throw new Throwable("CronetTestBase#runTest failed.", e); 147 throw new Throwable("CronetTestBase#runTest failed.", e);
149 } 148 }
150 } else { 149 } else {
151 super.runTest(); 150 super.runTest();
152 } 151 }
153 } 152 }
154 153
154 /**
155 * Creates and returns {@link ExperimentalCronetEngine.Builder} that creates
156 * Java (platform) based {@link CronetEngine.Builder}.
157 *
158 * @return the {@code CronetEngine.Builder} that builds Java-based {@code Cr onet engine}.
159 */
160 ExperimentalCronetEngine.Builder createJavaEngineBuilder() {
161 return (ExperimentalCronetEngine.Builder) new JavaCronetProvider(mContex t).createBuilder();
162 }
163
155 public void assertResponseEquals(UrlResponseInfo expected, UrlResponseInfo a ctual) { 164 public void assertResponseEquals(UrlResponseInfo expected, UrlResponseInfo a ctual) {
156 assertEquals(expected.getAllHeaders(), actual.getAllHeaders()); 165 assertEquals(expected.getAllHeaders(), actual.getAllHeaders());
157 assertEquals(expected.getAllHeadersAsList(), actual.getAllHeadersAsList( )); 166 assertEquals(expected.getAllHeadersAsList(), actual.getAllHeadersAsList( ));
158 assertEquals(expected.getHttpStatusCode(), actual.getHttpStatusCode()); 167 assertEquals(expected.getHttpStatusCode(), actual.getHttpStatusCode());
159 assertEquals(expected.getHttpStatusText(), actual.getHttpStatusText()); 168 assertEquals(expected.getHttpStatusText(), actual.getHttpStatusText());
160 assertEquals(expected.getUrlChain(), actual.getUrlChain()); 169 assertEquals(expected.getUrlChain(), actual.getUrlChain());
161 assertEquals(expected.getUrl(), actual.getUrl()); 170 assertEquals(expected.getUrl(), actual.getUrl());
162 // Transferred bytes and proxy server are not supported in pure java 171 // Transferred bytes and proxy server are not supported in pure java
163 if (!(mCronetTestFramework.mCronetEngine instanceof JavaCronetEngine)) { 172 if (!(mCronetTestFramework.mCronetEngine instanceof JavaCronetEngine)) {
164 assertEquals(expected.getReceivedByteCount(), actual.getReceivedByte Count()); 173 assertEquals(expected.getReceivedByteCount(), actual.getReceivedByte Count());
(...skipping 18 matching lines...) Expand all
183 192
184 @Target(ElementType.METHOD) 193 @Target(ElementType.METHOD)
185 @Retention(RetentionPolicy.RUNTIME) 194 @Retention(RetentionPolicy.RUNTIME)
186 public @interface OnlyRunCronetHttpURLConnection { 195 public @interface OnlyRunCronetHttpURLConnection {
187 } 196 }
188 197
189 @Target(ElementType.METHOD) 198 @Target(ElementType.METHOD)
190 @Retention(RetentionPolicy.RUNTIME) 199 @Retention(RetentionPolicy.RUNTIME)
191 public @interface OnlyRunNativeCronet {} 200 public @interface OnlyRunNativeCronet {}
192 } 201 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698