| OLD | NEW |
| 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 |
| 11 import java.lang.annotation.ElementType; | 11 import java.lang.annotation.ElementType; |
| 12 import java.lang.annotation.Retention; | 12 import java.lang.annotation.Retention; |
| 13 import java.lang.annotation.RetentionPolicy; | 13 import java.lang.annotation.RetentionPolicy; |
| 14 import java.lang.annotation.Target; | 14 import java.lang.annotation.Target; |
| 15 import java.lang.reflect.Method; | 15 import java.lang.reflect.Method; |
| 16 import java.net.URL; | 16 import java.net.URL; |
| 17 | 17 |
| 18 /** | 18 /** |
| 19 * Base test class for all CronetTest based tests. | 19 * Base test class for all CronetTest based tests. |
| 20 */ | 20 */ |
| 21 public class CronetTestBase extends AndroidTestCase { | 21 public class CronetTestBase extends AndroidTestCase { |
| 22 private static final String PRIVATE_DATA_DIRECTORY_SUFFIX = "cronet_test"; | 22 private static final String PRIVATE_DATA_DIRECTORY_SUFFIX = "cronet_test"; |
| 23 private static final String LOOPBACK_ADDRESS = "127.0.0.1"; | |
| 24 | 23 |
| 25 private CronetTestFramework mCronetTestFramework; | 24 private CronetTestFramework mCronetTestFramework; |
| 26 // {@code true} when test is being run against system HttpURLConnection impl
ementation. | 25 // {@code true} when test is being run against system HttpURLConnection impl
ementation. |
| 27 private boolean mTestingSystemHttpURLConnection; | 26 private boolean mTestingSystemHttpURLConnection; |
| 28 private boolean mTestingJavaImpl = false; | 27 private boolean mTestingJavaImpl = false; |
| 29 | 28 |
| 30 @Override | 29 @Override |
| 31 protected void setUp() throws Exception { | 30 protected void setUp() throws Exception { |
| 32 super.setUp(); | 31 super.setUp(); |
| 33 PathUtils.setPrivateDataDirectorySuffix(PRIVATE_DATA_DIRECTORY_SUFFIX, g
etContext()); | 32 PathUtils.setPrivateDataDirectorySuffix(PRIVATE_DATA_DIRECTORY_SUFFIX, g
etContext()); |
| (...skipping 123 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 157 protected void registerHostResolver(CronetTestFramework framework) { | 156 protected void registerHostResolver(CronetTestFramework framework) { |
| 158 registerHostResolver(framework, false); | 157 registerHostResolver(framework, false); |
| 159 } | 158 } |
| 160 | 159 |
| 161 /** | 160 /** |
| 162 * Registers test host resolver. | 161 * Registers test host resolver. |
| 163 * | 162 * |
| 164 * @param isLegacyAPI true if the test should use the legacy API. | 163 * @param isLegacyAPI true if the test should use the legacy API. |
| 165 */ | 164 */ |
| 166 protected void registerHostResolver(CronetTestFramework framework, boolean i
sLegacyAPI) { | 165 protected void registerHostResolver(CronetTestFramework framework, boolean i
sLegacyAPI) { |
| 166 long urlRequestContextAdapter; |
| 167 if (isLegacyAPI) { | 167 if (isLegacyAPI) { |
| 168 CronetTestUtil.registerHostResolverProc(framework.mRequestFactory, L
OOPBACK_ADDRESS); | 168 urlRequestContextAdapter = ((ChromiumUrlRequestFactory) framework.mR
equestFactory) |
| 169 .getRequestContext() |
| 170 .getUrlRequestContextAdapter(); |
| 169 } else { | 171 } else { |
| 170 CronetTestUtil.registerHostResolverProc(framework.mCronetEngine, LOO
PBACK_ADDRESS); | 172 urlRequestContextAdapter = ((CronetUrlRequestContext) framework.mCro
netEngine) |
| 173 .getUrlRequestContextAdapter(); |
| 171 } | 174 } |
| 175 NativeTestServer.registerHostResolverProc(urlRequestContextAdapter, isLe
gacyAPI); |
| 172 } | 176 } |
| 173 | 177 |
| 174 void assertResponseEquals(UrlResponseInfo expected, UrlResponseInfo actual)
{ | 178 void assertResponseEquals(UrlResponseInfo expected, UrlResponseInfo actual)
{ |
| 175 assertEquals(expected.getAllHeaders(), actual.getAllHeaders()); | 179 assertEquals(expected.getAllHeaders(), actual.getAllHeaders()); |
| 176 assertEquals(expected.getAllHeadersAsList(), actual.getAllHeadersAsList(
)); | 180 assertEquals(expected.getAllHeadersAsList(), actual.getAllHeadersAsList(
)); |
| 177 assertEquals(expected.getHttpStatusCode(), actual.getHttpStatusCode()); | 181 assertEquals(expected.getHttpStatusCode(), actual.getHttpStatusCode()); |
| 178 assertEquals(expected.getHttpStatusText(), actual.getHttpStatusText()); | 182 assertEquals(expected.getHttpStatusText(), actual.getHttpStatusText()); |
| 179 assertEquals(expected.getUrlChain(), actual.getUrlChain()); | 183 assertEquals(expected.getUrlChain(), actual.getUrlChain()); |
| 180 assertEquals(expected.getUrl(), actual.getUrl()); | 184 assertEquals(expected.getUrl(), actual.getUrl()); |
| 181 // Transferred bytes and proxy server are not supported in pure java | 185 // Transferred bytes and proxy server are not supported in pure java |
| (...skipping 12 matching lines...) Expand all Loading... |
| 194 | 198 |
| 195 @Target(ElementType.METHOD) | 199 @Target(ElementType.METHOD) |
| 196 @Retention(RetentionPolicy.RUNTIME) | 200 @Retention(RetentionPolicy.RUNTIME) |
| 197 public @interface OnlyRunCronetHttpURLConnection { | 201 public @interface OnlyRunCronetHttpURLConnection { |
| 198 } | 202 } |
| 199 | 203 |
| 200 @Target(ElementType.METHOD) | 204 @Target(ElementType.METHOD) |
| 201 @Retention(RetentionPolicy.RUNTIME) | 205 @Retention(RetentionPolicy.RUNTIME) |
| 202 public @interface OnlyRunNativeCronet {} | 206 public @interface OnlyRunNativeCronet {} |
| 203 } | 207 } |
| OLD | NEW |