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.content.Context; | 7 import android.content.Context; |
8 import android.test.suitebuilder.annotation.SmallTest; | 8 import android.test.suitebuilder.annotation.SmallTest; |
9 | 9 |
10 import org.chromium.base.PathUtils; | 10 import org.chromium.base.PathUtils; |
(...skipping 116 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
127 try { | 127 try { |
128 request.setUploadData(null, uploadData); | 128 request.setUploadData(null, uploadData); |
129 fail("setUploadData should throw on null content type"); | 129 fail("setUploadData should throw on null content type"); |
130 } catch (NullPointerException e) { | 130 } catch (NullPointerException e) { |
131 // Nothing to do here. | 131 // Nothing to do here. |
132 } | 132 } |
133 } | 133 } |
134 | 134 |
135 @SmallTest | 135 @SmallTest |
136 @Feature({"Cronet"}) | 136 @Feature({"Cronet"}) |
137 public void disabled_testQuicLoadUrl() throws Exception { | 137 public void testQuicLoadUrl() throws Exception { |
138 // Loads library first since native functions are used to retrieve | |
139 // QuicTestServer info before config is constructed. | |
140 System.loadLibrary("cronet_tests"); | |
mef
2015/04/06 20:30:56
Thanks for the comment!
That's annoying that we h
xunjieli
2015/04/06 21:23:50
Done. Makes sense, since we will be adding more te
| |
138 HttpUrlRequestFactoryConfig config = new HttpUrlRequestFactoryConfig(); | 141 HttpUrlRequestFactoryConfig config = new HttpUrlRequestFactoryConfig(); |
139 // TODO(mef): Test Quic end-to-end using local QUIC server. | 142 String quicURL = QuicTestServer.getServerURL() + "/simple.txt"; |
140 String quicURL = "https://www.google.com:443"; | |
141 String quicNegotiatedProtocol = "quic/1+spdy/3"; | |
142 config.enableQUIC(true); | 143 config.enableQUIC(true); |
143 config.addQuicHint("www.google.com", 443, 443); | 144 config.setLibraryName("cronet_tests"); |
145 config.addQuicHint(QuicTestServer.getServerHost(), | |
146 QuicTestServer.getServerPort(), QuicTestServer.getServerPort()); | |
144 config.setExperimentalQuicConnectionOptions("PACE,IW10,FOO,DEADBEEF"); | 147 config.setExperimentalQuicConnectionOptions("PACE,IW10,FOO,DEADBEEF"); |
145 | 148 |
146 String[] commandLineArgs = { | 149 String[] commandLineArgs = { |
147 CronetTestActivity.CONFIG_KEY, config.toString() }; | 150 CronetTestActivity.CONFIG_KEY, config.toString() }; |
148 CronetTestActivity activity = | 151 CronetTestActivity activity = |
149 launchCronetTestAppWithUrlAndCommandLineArgs(null, | 152 launchCronetTestAppWithUrlAndCommandLineArgs(null, |
150 commandLineArgs); | 153 commandLineArgs); |
154 QuicTestServer.startQuicTestServer(activity.getApplicationContext()); | |
151 activity.startNetLog(); | 155 activity.startNetLog(); |
152 | 156 |
153 HashMap<String, String> headers = new HashMap<String, String>(); | 157 HashMap<String, String> headers = new HashMap<String, String>(); |
154 TestHttpUrlRequestListener listener = new TestHttpUrlRequestListener(); | 158 TestHttpUrlRequestListener listener = new TestHttpUrlRequestListener(); |
155 | 159 |
156 // Try several times as first request may not use QUIC. | 160 HttpUrlRequest request = |
157 // TODO(mef): Remove loop after adding http server properties manager. | 161 activity.mRequestFactory.createRequest( |
158 for (int i = 0; i < 10; ++i) { | 162 quicURL, |
159 HttpUrlRequest request = | 163 HttpUrlRequest.REQUEST_PRIORITY_MEDIUM, |
160 activity.mRequestFactory.createRequest( | 164 headers, |
161 quicURL, | 165 listener); |
162 HttpUrlRequest.REQUEST_PRIORITY_MEDIUM, | 166 request.start(); |
163 headers, | 167 listener.blockForComplete(); |
164 listener); | 168 assertEquals(200, listener.mHttpStatusCode); |
165 request.start(); | 169 assertEquals( |
166 listener.blockForComplete(); | 170 "This is a simple text file served by QUIC.\n", listener.mRespon seAsString); |
167 assertEquals(200, listener.mHttpStatusCode); | 171 assertEquals("quic/1+spdy/3", listener.mNegotiatedProtocol); |
168 if (listener.mNegotiatedProtocol.equals(quicNegotiatedProtocol)) { | |
169 break; | |
170 } | |
171 Thread.sleep(1000); | |
172 listener.resetComplete(); | |
173 } | |
174 | |
175 assertEquals(quicNegotiatedProtocol, listener.mNegotiatedProtocol); | |
176 activity.stopNetLog(); | 172 activity.stopNetLog(); |
173 QuicTestServer.shutdownQuicTestServer(); | |
177 } | 174 } |
178 | 175 |
179 @SmallTest | 176 @SmallTest |
180 @Feature({"Cronet"}) | 177 @Feature({"Cronet"}) |
181 public void testLegacyLoadUrl() throws Exception { | 178 public void testLegacyLoadUrl() throws Exception { |
182 HttpUrlRequestFactoryConfig config = new HttpUrlRequestFactoryConfig(); | 179 HttpUrlRequestFactoryConfig config = new HttpUrlRequestFactoryConfig(); |
183 config.enableLegacyMode(true); | 180 config.enableLegacyMode(true); |
184 // TODO(mef) fix tests so that library isn't loaded for legacy stack | 181 // TODO(mef) fix tests so that library isn't loaded for legacy stack |
185 config.setLibraryName("cronet_tests"); | 182 config.setLibraryName("cronet_tests"); |
186 | 183 |
(...skipping 21 matching lines...) Expand all Loading... | |
208 URL, HttpUrlRequest.REQUEST_PRIORITY_MEDIUM, headers, listener); | 205 URL, HttpUrlRequest.REQUEST_PRIORITY_MEDIUM, headers, listener); |
209 request.setHttpMethod("HEAD"); | 206 request.setHttpMethod("HEAD"); |
210 request.start(); | 207 request.start(); |
211 listener.blockForComplete(); | 208 listener.blockForComplete(); |
212 assertEquals(200, listener.mHttpStatusCode); | 209 assertEquals(200, listener.mHttpStatusCode); |
213 // HEAD requests do not get any response data and Content-Length must be | 210 // HEAD requests do not get any response data and Content-Length must be |
214 // ignored. | 211 // ignored. |
215 assertEquals(0, listener.mResponseAsBytes.length); | 212 assertEquals(0, listener.mResponseAsBytes.length); |
216 } | 213 } |
217 } | 214 } |
OLD | NEW |