Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(876)

Side by Side Diff: components/cronet/android/test/javatests/src/org/chromium/net/CronetUrlTest.java

Issue 1039693003: [Cronet] Add support to run quic_simple_server (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Remove unused header Created 5 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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
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 HttpUrlRequestFactoryConfig config = new HttpUrlRequestFactoryConfig(); 138 HttpUrlRequestFactoryConfig config = new HttpUrlRequestFactoryConfig();
139 // TODO(mef): Test Quic end-to-end using local QUIC server. 139 String quicURL = QuicTestServer.SERVER_URL + "/simple.txt";
140 String quicURL = "https://www.google.com:443";
141 String quicNegotiatedProtocol = "quic/1+spdy/3";
142 config.enableQUIC(true); 140 config.enableQUIC(true);
143 config.addQuicHint("www.google.com", 443, 443); 141 config.setLibraryName("cronet_tests");
142 config.addQuicHint("127.0.0.1", 6121, 6121);
mef 2015/03/31 17:33:18 should those constants come from QuicTestServer?
xunjieli 2015/03/31 17:50:15 Done.
144 config.setExperimentalQuicConnectionOptions("PACE,IW10,FOO,DEADBEEF"); 143 config.setExperimentalQuicConnectionOptions("PACE,IW10,FOO,DEADBEEF");
145 144
146 String[] commandLineArgs = { 145 String[] commandLineArgs = {
147 CronetTestActivity.CONFIG_KEY, config.toString() }; 146 CronetTestActivity.CONFIG_KEY, config.toString() };
148 CronetTestActivity activity = 147 CronetTestActivity activity =
149 launchCronetTestAppWithUrlAndCommandLineArgs(null, 148 launchCronetTestAppWithUrlAndCommandLineArgs(null,
150 commandLineArgs); 149 commandLineArgs);
150 QuicTestServer.startQuicTestServer(activity.getApplicationContext());
151 activity.startNetLog(); 151 activity.startNetLog();
152 152
153 HashMap<String, String> headers = new HashMap<String, String>(); 153 HashMap<String, String> headers = new HashMap<String, String>();
154 TestHttpUrlRequestListener listener = new TestHttpUrlRequestListener(); 154 TestHttpUrlRequestListener listener = new TestHttpUrlRequestListener();
155 155
156 // Try several times as first request may not use QUIC. 156 HttpUrlRequest request =
157 // TODO(mef): Remove loop after adding http server properties manager. 157 activity.mRequestFactory.createRequest(
158 for (int i = 0; i < 10; ++i) { 158 quicURL,
159 HttpUrlRequest request = 159 HttpUrlRequest.REQUEST_PRIORITY_MEDIUM,
160 activity.mRequestFactory.createRequest( 160 headers,
161 quicURL, 161 listener);
162 HttpUrlRequest.REQUEST_PRIORITY_MEDIUM, 162 request.start();
163 headers, 163 listener.blockForComplete();
164 listener); 164 assertEquals(200, listener.mHttpStatusCode);
165 request.start(); 165 assertEquals(
166 listener.blockForComplete(); 166 "This is a simple text file served by QUIC.\n", listener.mRespon seAsString);
167 assertEquals(200, listener.mHttpStatusCode); 167 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(); 168 activity.stopNetLog();
169 QuicTestServer.shutdownQuicTestServer();
177 } 170 }
178 171
179 @SmallTest 172 @SmallTest
180 @Feature({"Cronet"}) 173 @Feature({"Cronet"})
181 public void testLegacyLoadUrl() throws Exception { 174 public void testLegacyLoadUrl() throws Exception {
182 HttpUrlRequestFactoryConfig config = new HttpUrlRequestFactoryConfig(); 175 HttpUrlRequestFactoryConfig config = new HttpUrlRequestFactoryConfig();
183 config.enableLegacyMode(true); 176 config.enableLegacyMode(true);
184 // TODO(mef) fix tests so that library isn't loaded for legacy stack 177 // TODO(mef) fix tests so that library isn't loaded for legacy stack
185 config.setLibraryName("cronet_tests"); 178 config.setLibraryName("cronet_tests");
186 179
(...skipping 21 matching lines...) Expand all
208 URL, HttpUrlRequest.REQUEST_PRIORITY_MEDIUM, headers, listener); 201 URL, HttpUrlRequest.REQUEST_PRIORITY_MEDIUM, headers, listener);
209 request.setHttpMethod("HEAD"); 202 request.setHttpMethod("HEAD");
210 request.start(); 203 request.start();
211 listener.blockForComplete(); 204 listener.blockForComplete();
212 assertEquals(200, listener.mHttpStatusCode); 205 assertEquals(200, listener.mHttpStatusCode);
213 // HEAD requests do not get any response data and Content-Length must be 206 // HEAD requests do not get any response data and Content-Length must be
214 // ignored. 207 // ignored.
215 assertEquals(0, listener.mResponseAsBytes.length); 208 assertEquals(0, listener.mResponseAsBytes.length);
216 } 209 }
217 } 210 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698