| 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 | 23 |
| 24 private CronetTestFramework mCronetTestFramework; | 24 private CronetTestFramework mCronetTestFramework; |
| 25 | 25 |
| 26 @Override | 26 @Override |
| 27 protected void setUp() throws Exception { | 27 protected void setUp() throws Exception { |
| 28 super.setUp(); | 28 super.setUp(); |
| 29 PathUtils.setPrivateDataDirectorySuffix(PRIVATE_DATA_DIRECTORY_SUFFIX, g
etContext()); | 29 PathUtils.setPrivateDataDirectorySuffix(PRIVATE_DATA_DIRECTORY_SUFFIX, g
etContext()); |
| 30 CronetTestFramework.prepareTestStorage(getContext()); |
| 30 } | 31 } |
| 31 | 32 |
| 32 /** | 33 /** |
| 33 * Starts the CronetTest framework. | 34 * Starts the CronetTest framework. |
| 34 */ | 35 */ |
| 35 protected CronetTestFramework startCronetTestFramework() { | 36 protected CronetTestFramework startCronetTestFramework() { |
| 36 return startCronetTestFrameworkWithUrlAndCronetEngineBuilder(null, null)
; | 37 return startCronetTestFrameworkWithUrlAndCronetEngineBuilder(null, null)
; |
| 37 } | 38 } |
| 38 | 39 |
| 39 /** | 40 /** |
| (...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 107 super.runTest(); | 108 super.runTest(); |
| 108 } else { | 109 } else { |
| 109 // For all other tests. | 110 // For all other tests. |
| 110 super.runTest(); | 111 super.runTest(); |
| 111 } | 112 } |
| 112 } catch (Throwable e) { | 113 } catch (Throwable e) { |
| 113 throw new Throwable("CronetTestBase#runTest failed.", e); | 114 throw new Throwable("CronetTestBase#runTest failed.", e); |
| 114 } | 115 } |
| 115 } | 116 } |
| 116 | 117 |
| 118 /** |
| 119 * Registers test host resolver for testing with the new API. |
| 120 */ |
| 121 protected void registerHostResolver(CronetTestFramework framework) { |
| 122 registerHostResolver(framework, false); |
| 123 } |
| 124 |
| 125 /** |
| 126 * Registers test host resolver. |
| 127 * |
| 128 * @param isLegacyAPI true if the test should use the legacy API. |
| 129 */ |
| 130 protected void registerHostResolver(CronetTestFramework framework, boolean i
sLegacyAPI) { |
| 131 long urlRequestContextAdapter; |
| 132 if (isLegacyAPI) { |
| 133 urlRequestContextAdapter = ((ChromiumUrlRequestFactory) framework.mR
equestFactory) |
| 134 .getRequestContext() |
| 135 .getUrlRequestContextAdapter(); |
| 136 } else { |
| 137 urlRequestContextAdapter = ((CronetUrlRequestContext) framework.mCro
netEngine) |
| 138 .getUrlRequestContextAdapter(); |
| 139 } |
| 140 NativeTestServer.registerHostResolverProc(urlRequestContextAdapter, isLe
gacyAPI); |
| 141 } |
| 142 |
| 117 @Target(ElementType.METHOD) | 143 @Target(ElementType.METHOD) |
| 118 @Retention(RetentionPolicy.RUNTIME) | 144 @Retention(RetentionPolicy.RUNTIME) |
| 119 public @interface CompareDefaultWithCronet { | 145 public @interface CompareDefaultWithCronet { |
| 120 } | 146 } |
| 121 | 147 |
| 122 @Target(ElementType.METHOD) | 148 @Target(ElementType.METHOD) |
| 123 @Retention(RetentionPolicy.RUNTIME) | 149 @Retention(RetentionPolicy.RUNTIME) |
| 124 public @interface OnlyRunCronetHttpURLConnection { | 150 public @interface OnlyRunCronetHttpURLConnection { |
| 125 } | 151 } |
| 126 | 152 |
| 127 } | 153 } |
| OLD | NEW |