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

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

Issue 2045703003: Enable NQE when Cronet Engine is built (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Addressed mef comments Created 4 years, 6 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 2015 The Chromium Authors. All rights reserved. 1 // Copyright 2015 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.os.ConditionVariable;
7 import android.test.suitebuilder.annotation.LargeTest; 8 import android.test.suitebuilder.annotation.LargeTest;
8 import android.test.suitebuilder.annotation.SmallTest; 9 import android.test.suitebuilder.annotation.SmallTest;
9 10
10 import org.chromium.base.Log; 11 import org.chromium.base.Log;
11 import org.chromium.base.annotations.SuppressFBWarnings; 12 import org.chromium.base.annotations.SuppressFBWarnings;
12 import org.chromium.base.test.util.Feature; 13 import org.chromium.base.test.util.Feature;
13 import org.chromium.net.CronetTestBase.OnlyRunNativeCronet; 14 import org.chromium.net.CronetTestBase.OnlyRunNativeCronet;
14 import org.json.JSONObject; 15 import org.json.JSONObject;
15 16
16 import java.io.File; 17 import java.io.File;
17 import java.io.FileInputStream; 18 import java.io.FileInputStream;
18 import java.io.FileNotFoundException; 19 import java.io.FileNotFoundException;
19 import java.io.IOException; 20 import java.io.IOException;
20 import java.util.HashMap; 21 import java.util.HashMap;
22 import java.util.concurrent.Executors;
21 23
22 /** 24 /**
23 * Tests making requests using QUIC. 25 * Tests making requests using QUIC.
24 */ 26 */
25 public class QuicTest extends CronetTestBase { 27 public class QuicTest extends CronetTestBase {
26 private static final String TAG = "cr.QuicTest"; 28 private static final String TAG = "cr.QuicTest";
27 private CronetTestFramework mTestFramework; 29 private CronetTestFramework mTestFramework;
28 private CronetEngine.Builder mBuilder; 30 private CronetEngine.Builder mBuilder;
29 31
30 @Override 32 @Override
31 protected void setUp() throws Exception { 33 protected void setUp() throws Exception {
32 super.setUp(); 34 super.setUp();
33 // Load library first, since we need the Quic test server's URL. 35 // Load library first, since we need the Quic test server's URL.
34 System.loadLibrary("cronet_tests"); 36 System.loadLibrary("cronet_tests");
35 QuicTestServer.startQuicTestServer(getContext()); 37 QuicTestServer.startQuicTestServer(getContext());
36 38
37 mBuilder = new CronetEngine.Builder(getContext()); 39 mBuilder = new CronetEngine.Builder(getContext());
38 mBuilder.enableQUIC(true); 40 mBuilder.enableQUIC(true).enableNetworkQualityEstimator(true);
39 mBuilder.addQuicHint(QuicTestServer.getServerHost(), QuicTestServer.getS erverPort(), 41 mBuilder.addQuicHint(QuicTestServer.getServerHost(), QuicTestServer.getS erverPort(),
40 QuicTestServer.getServerPort()); 42 QuicTestServer.getServerPort());
41 43
42 JSONObject quicParams = new JSONObject() 44 JSONObject quicParams = new JSONObject()
43 .put("connection_options", "PACE,IW10,FO O,DEADBEEF") 45 .put("connection_options", "PACE,IW10,FO O,DEADBEEF")
44 .put("host_whitelist", "test.example.com ") 46 .put("host_whitelist", "test.example.com ")
45 .put("max_server_configs_stored_in_prope rties", 2) 47 .put("max_server_configs_stored_in_prope rties", 2)
46 .put("delay_tcp_race", true) 48 .put("delay_tcp_race", true)
47 .put("max_number_of_lossy_connections", 10) 49 .put("max_number_of_lossy_connections", 10)
48 .put("packet_loss_threshold", 0.5) 50 .put("packet_loss_threshold", 0.5)
(...skipping 114 matching lines...) Expand 10 before | Expand all | Expand 10 after
163 @SuppressFBWarnings("OBL_UNSATISFIED_OBLIGATION_EXCEPTION_EDGE") 165 @SuppressFBWarnings("OBL_UNSATISFIED_OBLIGATION_EXCEPTION_EDGE")
164 private boolean fileContainsString(String filename, String content) throws I OException { 166 private boolean fileContainsString(String filename, String content) throws I OException {
165 File file = 167 File file =
166 new File(CronetTestFramework.getTestStorage(getContext()) + "/pr efs/" + filename); 168 new File(CronetTestFramework.getTestStorage(getContext()) + "/pr efs/" + filename);
167 FileInputStream fileInputStream = new FileInputStream(file); 169 FileInputStream fileInputStream = new FileInputStream(file);
168 byte[] data = new byte[(int) file.length()]; 170 byte[] data = new byte[(int) file.length()];
169 fileInputStream.read(data); 171 fileInputStream.read(data);
170 fileInputStream.close(); 172 fileInputStream.close();
171 return new String(data, "UTF-8").contains(content); 173 return new String(data, "UTF-8").contains(content);
172 } 174 }
175
176 @LargeTest
177 @Feature({"Cronet"})
178 @OnlyRunNativeCronet
179 @SuppressWarnings("deprecation")
180 public void testRealTimeNetworkQualityObservationsWithQuic() throws Exceptio n {
181 mTestFramework = startCronetTestFrameworkWithUrlAndCronetEngineBuilder(n ull, mBuilder);
182 registerHostResolver(mTestFramework);
183 String quicURL = QuicTestServer.getServerURL() + "/simple.txt";
184 ConditionVariable waitForThroughput = new ConditionVariable();
185
186 TestNetworkQualityRttListener rttListener =
187 new TestNetworkQualityRttListener(Executors.newSingleThreadExecu tor());
188 TestNetworkQualityThroughputListener throughputListener =
189 new TestNetworkQualityThroughputListener(
190 Executors.newSingleThreadExecutor(), waitForThroughput);
191
192 mTestFramework.mCronetEngine.addRttListener(rttListener);
193 mTestFramework.mCronetEngine.addThroughputListener(throughputListener);
194
195 mTestFramework.mCronetEngine.configureNetworkQualityEstimatorForTesting( true, true);
196 TestUrlRequestCallback callback = new TestUrlRequestCallback();
197
198 // Although the native stack races QUIC and SPDY for the first request,
199 // since there is no http server running on the corresponding TCP port,
200 // QUIC will always succeed with a 200 (see
201 // net::HttpStreamFactoryImpl::Request::OnStreamFailed).
202 UrlRequest.Builder requestBuilder = new UrlRequest.Builder(
203 quicURL, callback, callback.getExecutor(), mTestFramework.mCrone tEngine);
204 requestBuilder.build().start();
205 callback.blockForDone();
206
207 assertEquals(200, callback.mResponseInfo.getHttpStatusCode());
208 String expectedContent = "This is a simple text file served by QUIC.\n";
209 assertEquals(expectedContent, callback.mResponseAsString);
210 assertEquals("quic/1+spdy/3", callback.mResponseInfo.getNegotiatedProtoc ol());
211
212 // Throughput observation is posted to the network quality estimator on the network thread
213 // after the UrlRequest is completed. The observations are then eventual ly posted to
214 // throughput listeners on the executor provided to network quality.
215 waitForThroughput.block();
216 assertTrue(throughputListener.throughputObservationCount() > 0);
217
218 // Check RTT observation count after throughput observation has been rec eived. This ensures
219 // that executor has finished posting the RTT observation to the RTT lis teners.
220 // NETWORK_QUALITY_OBSERVATION_SOURCE_URL_REQUEST
221 assertTrue(rttListener.rttObservationCount(0) > 0);
222
223 // NETWORK_QUALITY_OBSERVATION_SOURCE_QUIC
224 assertTrue(rttListener.rttObservationCount(2) > 0);
225
226 mTestFramework.mCronetEngine.shutdown();
227 }
173 } 228 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698