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 |
(...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
91 /** | 91 /** |
92 * Returns {@code true} when test is being run against system HttpURLConnect
ion implementation. | 92 * Returns {@code true} when test is being run against system HttpURLConnect
ion implementation. |
93 */ | 93 */ |
94 protected boolean testingSystemHttpURLConnection() { | 94 protected boolean testingSystemHttpURLConnection() { |
95 return mTestingSystemHttpURLConnection; | 95 return mTestingSystemHttpURLConnection; |
96 } | 96 } |
97 | 97 |
98 @Override | 98 @Override |
99 protected void runTest() throws Throwable { | 99 protected void runTest() throws Throwable { |
100 mTestingSystemHttpURLConnection = false; | 100 mTestingSystemHttpURLConnection = false; |
101 if (!getClass().getPackage().getName().equals( | 101 String packageName = getClass().getPackage().getName(); |
102 "org.chromium.net.urlconnection")) { | 102 if (packageName.equals("org.chromium.net.urlconnection")) { |
| 103 try { |
| 104 Method method = getClass().getMethod(getName(), (Class[]) null); |
| 105 if (method.isAnnotationPresent(CompareDefaultWithCronet.class))
{ |
| 106 // Run with the default HttpURLConnection implementation fir
st. |
| 107 mTestingSystemHttpURLConnection = true; |
| 108 super.runTest(); |
| 109 // Use Cronet's implementation, and run the same test. |
| 110 mTestingSystemHttpURLConnection = false; |
| 111 URL.setURLStreamHandlerFactory(mCronetTestFramework.mStreamH
andlerFactory); |
| 112 super.runTest(); |
| 113 } else if (method.isAnnotationPresent(OnlyRunCronetHttpURLConnec
tion.class)) { |
| 114 // Run only with Cronet's implementation. |
| 115 URL.setURLStreamHandlerFactory(mCronetTestFramework.mStreamH
andlerFactory); |
| 116 super.runTest(); |
| 117 } else { |
| 118 // For all other tests. |
| 119 super.runTest(); |
| 120 } |
| 121 } catch (Throwable e) { |
| 122 throw new Throwable("CronetTestBase#runTest failed.", e); |
| 123 } |
| 124 } else if (packageName.equals("org.chromium.net")) { |
| 125 try { |
| 126 Method method = getClass().getMethod(getName(), (Class[]) null); |
| 127 super.runTest(); |
| 128 if (!method.isAnnotationPresent(OnlyRunNativeCronet.class)) { |
| 129 if (mCronetTestFramework != null) { |
| 130 mCronetTestFramework.mCronetEngine = |
| 131 new JavaCronetEngine(UserAgent.from(getContext()
)); |
| 132 } |
| 133 super.runTest(); |
| 134 } |
| 135 } catch (Throwable e) { |
| 136 throw new Throwable("CronetTestBase#runTest failed.", e); |
| 137 } |
| 138 return; |
| 139 } else { |
103 super.runTest(); | 140 super.runTest(); |
104 return; | |
105 } | |
106 try { | |
107 Method method = getClass().getMethod(getName(), (Class[]) null); | |
108 if (method.isAnnotationPresent(CompareDefaultWithCronet.class)) { | |
109 // Run with the default HttpURLConnection implementation first. | |
110 mTestingSystemHttpURLConnection = true; | |
111 super.runTest(); | |
112 // Use Cronet's implementation, and run the same test. | |
113 mTestingSystemHttpURLConnection = false; | |
114 URL.setURLStreamHandlerFactory(mCronetTestFramework.mStreamHandl
erFactory); | |
115 super.runTest(); | |
116 } else if (method.isAnnotationPresent( | |
117 OnlyRunCronetHttpURLConnection.class)) { | |
118 // Run only with Cronet's implementation. | |
119 URL.setURLStreamHandlerFactory(mCronetTestFramework.mStreamHandl
erFactory); | |
120 super.runTest(); | |
121 } else { | |
122 // For all other tests. | |
123 super.runTest(); | |
124 } | |
125 } catch (Throwable e) { | |
126 throw new Throwable("CronetTestBase#runTest failed.", e); | |
127 } | 141 } |
128 } | 142 } |
129 | 143 |
130 /** | 144 /** |
131 * Registers test host resolver for testing with the new API. | 145 * Registers test host resolver for testing with the new API. |
132 */ | 146 */ |
133 protected void registerHostResolver(CronetTestFramework framework) { | 147 protected void registerHostResolver(CronetTestFramework framework) { |
134 registerHostResolver(framework, false); | 148 registerHostResolver(framework, false); |
135 } | 149 } |
136 | 150 |
(...skipping 18 matching lines...) Expand all Loading... |
155 @Target(ElementType.METHOD) | 169 @Target(ElementType.METHOD) |
156 @Retention(RetentionPolicy.RUNTIME) | 170 @Retention(RetentionPolicy.RUNTIME) |
157 public @interface CompareDefaultWithCronet { | 171 public @interface CompareDefaultWithCronet { |
158 } | 172 } |
159 | 173 |
160 @Target(ElementType.METHOD) | 174 @Target(ElementType.METHOD) |
161 @Retention(RetentionPolicy.RUNTIME) | 175 @Retention(RetentionPolicy.RUNTIME) |
162 public @interface OnlyRunCronetHttpURLConnection { | 176 public @interface OnlyRunCronetHttpURLConnection { |
163 } | 177 } |
164 | 178 |
| 179 @Target(ElementType.METHOD) |
| 180 @Retention(RetentionPolicy.RUNTIME) |
| 181 public @interface OnlyRunNativeCronet {} |
165 } | 182 } |
OLD | NEW |