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.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; |
| 12 import org.chromium.net.impl.JavaCronetEngine; |
| 13 import org.chromium.net.impl.UserAgent; |
11 | 14 |
12 import java.lang.annotation.ElementType; | 15 import java.lang.annotation.ElementType; |
13 import java.lang.annotation.Retention; | 16 import java.lang.annotation.Retention; |
14 import java.lang.annotation.RetentionPolicy; | 17 import java.lang.annotation.RetentionPolicy; |
15 import java.lang.annotation.Target; | 18 import java.lang.annotation.Target; |
16 import java.lang.reflect.AnnotatedElement; | 19 import java.lang.reflect.AnnotatedElement; |
17 import java.net.URL; | 20 import java.net.URL; |
18 | 21 |
19 /** | 22 /** |
20 * Base test class for all CronetTest based tests. | 23 * Base test class for all CronetTest based tests. |
(...skipping 28 matching lines...) Expand all Loading... |
49 */ | 52 */ |
50 protected CronetTestFramework startCronetTestFrameworkWithUrl(String url) { | 53 protected CronetTestFramework startCronetTestFrameworkWithUrl(String url) { |
51 return startCronetTestFrameworkWithUrlAndCronetEngineBuilder(url, null); | 54 return startCronetTestFrameworkWithUrlAndCronetEngineBuilder(url, null); |
52 } | 55 } |
53 | 56 |
54 /** | 57 /** |
55 * Starts the CronetTest framework using the provided CronetEngine.Builder | 58 * Starts the CronetTest framework using the provided CronetEngine.Builder |
56 * and loads the given URL. The URL can be null. | 59 * and loads the given URL. The URL can be null. |
57 */ | 60 */ |
58 protected CronetTestFramework startCronetTestFrameworkWithUrlAndCronetEngine
Builder( | 61 protected CronetTestFramework startCronetTestFrameworkWithUrlAndCronetEngine
Builder( |
59 String url, CronetEngine.Builder builder) { | 62 String url, ExperimentalCronetEngine.Builder builder) { |
60 mCronetTestFramework = new CronetTestFramework(url, null, getContext(),
builder); | 63 mCronetTestFramework = new CronetTestFramework(url, null, getContext(),
builder); |
61 return mCronetTestFramework; | 64 return mCronetTestFramework; |
62 } | 65 } |
63 | 66 |
64 /** | 67 /** |
65 * Starts the CronetTest framework appending the provided command line | 68 * Starts the CronetTest framework appending the provided command line |
66 * arguments and loads the given URL. The URL can be null. | 69 * arguments and loads the given URL. The URL can be null. |
67 */ | 70 */ |
68 protected CronetTestFramework startCronetTestFrameworkWithUrlAndCommandLineA
rgs( | 71 protected CronetTestFramework startCronetTestFrameworkWithUrlAndCommandLineA
rgs( |
69 String url, String[] commandLineArgs) { | 72 String url, String[] commandLineArgs) { |
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
120 } | 123 } |
121 } catch (Throwable e) { | 124 } catch (Throwable e) { |
122 throw new Throwable("CronetTestBase#runTest failed.", e); | 125 throw new Throwable("CronetTestBase#runTest failed.", e); |
123 } | 126 } |
124 } else if (packageName.equals("org.chromium.net")) { | 127 } else if (packageName.equals("org.chromium.net")) { |
125 try { | 128 try { |
126 AnnotatedElement method = getClass().getMethod(getName(), (Class
[]) null); | 129 AnnotatedElement method = getClass().getMethod(getName(), (Class
[]) null); |
127 super.runTest(); | 130 super.runTest(); |
128 if (!method.isAnnotationPresent(OnlyRunNativeCronet.class)) { | 131 if (!method.isAnnotationPresent(OnlyRunNativeCronet.class)) { |
129 if (mCronetTestFramework != null) { | 132 if (mCronetTestFramework != null) { |
130 mCronetTestFramework.mCronetEngine = | 133 ExperimentalCronetEngine.Builder builder = |
131 new JavaCronetEngine(UserAgent.from(getContext()
)); | 134 new ExperimentalCronetEngine.Builder(getContext(
)); |
| 135 builder.setUserAgent(UserAgent.from(getContext())); |
| 136 builder.enableLegacyMode(true); |
| 137 mCronetTestFramework.mCronetEngine = (CronetEngineBase)
builder.build(); |
| 138 // Make sure that the instantiated engine is JavaCronetE
ngine. |
| 139 assert mCronetTestFramework.mCronetEngine.getClass() |
| 140 == JavaCronetEngine.class; |
132 } | 141 } |
133 mTestingJavaImpl = true; | 142 mTestingJavaImpl = true; |
134 super.runTest(); | 143 super.runTest(); |
135 } | 144 } |
136 } catch (Throwable e) { | 145 } catch (Throwable e) { |
137 throw new Throwable("CronetTestBase#runTest failed.", e); | 146 throw new Throwable("CronetTestBase#runTest failed.", e); |
138 } | 147 } |
139 } else { | 148 } else { |
140 super.runTest(); | 149 super.runTest(); |
141 } | 150 } |
(...skipping 22 matching lines...) Expand all Loading... |
164 | 173 |
165 @Target(ElementType.METHOD) | 174 @Target(ElementType.METHOD) |
166 @Retention(RetentionPolicy.RUNTIME) | 175 @Retention(RetentionPolicy.RUNTIME) |
167 public @interface OnlyRunCronetHttpURLConnection { | 176 public @interface OnlyRunCronetHttpURLConnection { |
168 } | 177 } |
169 | 178 |
170 @Target(ElementType.METHOD) | 179 @Target(ElementType.METHOD) |
171 @Retention(RetentionPolicy.RUNTIME) | 180 @Retention(RetentionPolicy.RUNTIME) |
172 public @interface OnlyRunNativeCronet {} | 181 public @interface OnlyRunNativeCronet {} |
173 } | 182 } |
OLD | NEW |