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

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

Issue 2416473004: Add functionality for embedders to configure NQE (Closed)
Patch Set: rebased Created 3 years, 7 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 2017 The Chromium Authors. All rights reserved. 1 // Copyright 2017 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.os.ConditionVariable;
8 import android.os.StrictMode; 8 import android.os.StrictMode;
9 import android.support.test.filters.SmallTest; 9 import android.support.test.filters.SmallTest;
10 10
11 import org.json.JSONObject;
12
11 import org.chromium.base.Log; 13 import org.chromium.base.Log;
12 import org.chromium.base.annotations.JNINamespace; 14 import org.chromium.base.annotations.JNINamespace;
13 import org.chromium.base.annotations.SuppressFBWarnings; 15 import org.chromium.base.annotations.SuppressFBWarnings;
14 import org.chromium.base.test.util.DisabledTest; 16 import org.chromium.base.test.util.DisabledTest;
15 import org.chromium.base.test.util.Feature; 17 import org.chromium.base.test.util.Feature;
16 import org.chromium.base.test.util.MetricsUtils.HistogramDelta; 18 import org.chromium.base.test.util.MetricsUtils.HistogramDelta;
17 import org.chromium.net.MetricsTestUtil.TestExecutor; 19 import org.chromium.net.MetricsTestUtil.TestExecutor;
18 import org.chromium.net.test.EmbeddedTestServer; 20 import org.chromium.net.test.EmbeddedTestServer;
19 21
20 import java.io.File; 22 import java.io.File;
(...skipping 202 matching lines...) Expand 10 before | Expand all | Expand 10 after
223 } catch (FileNotFoundException e) { 225 } catch (FileNotFoundException e) {
224 // Ignored this exception since the file will only be created wh en updates are 226 // Ignored this exception since the file will only be created wh en updates are
225 // flushed to the disk. 227 // flushed to the disk.
226 } 228 }
227 } 229 }
228 assertTrue(fileContainsString("local_prefs.json", "network_qualities")); 230 assertTrue(fileContainsString("local_prefs.json", "network_qualities"));
229 231
230 testFramework.mCronetEngine.shutdown(); 232 testFramework.mCronetEngine.shutdown();
231 assertTrue(writeCountHistogram.getDelta() > 0); 233 assertTrue(writeCountHistogram.getDelta() > 0);
232 } 234 }
235
236 @SmallTest
237 @Feature({"Cronet"})
238 public void testQuicDisabledWithParams() throws Exception {
239 ExperimentalCronetEngine.Builder mCronetEngineBuilder =
240 new ExperimentalCronetEngine.Builder(getContext());
241 Executor listenersExecutor = Executors.newSingleThreadExecutor(new Execu torThreadFactory());
242 ConditionVariable waitForThroughput = new ConditionVariable();
243 TestNetworkQualityRttListener rttListener =
244 new TestNetworkQualityRttListener(listenersExecutor);
245 TestNetworkQualityThroughputListener throughputListener =
246 new TestNetworkQualityThroughputListener(listenersExecutor, wait ForThroughput);
247
248 // Force the effective connection type to "2G".
249 JSONObject nqeOptions = new JSONObject().put("force_effective_connection _type", "2G");
250 // Add one more extra param two times to ensure robustness.
251 nqeOptions.put("some_other_param_1", "value1");
252 nqeOptions.put("some_other_param_2", "value2");
253 JSONObject experimentalOptions =
254 new JSONObject().put("NetworkQualityEstimator", nqeOptions);
255 experimentalOptions.put("SomeOtherFieldTrialName", new JSONObject());
256
257 mCronetEngineBuilder.enableHttp2(true).enableQuic(false).enableNetworkQu alityEstimator(
258 true);
259 mCronetEngineBuilder.setExperimentalOptions(experimentalOptions.toString ());
260 final CronetTestFramework testFramework =
261 startCronetTestFrameworkWithUrlAndCronetEngineBuilder(null, mCro netEngineBuilder);
262 testFramework.mCronetEngine.configureNetworkQualityEstimatorForTesting(t rue, true, false);
263
264 testFramework.mCronetEngine.addRttListener(rttListener);
265 testFramework.mCronetEngine.addThroughputListener(throughputListener);
266
267 TestUrlRequestCallback callback = new TestUrlRequestCallback();
268 UrlRequest.Builder builder = testFramework.mCronetEngine.newUrlRequestBu ilder(
269 mUrl, callback, callback.getExecutor());
270
271 UrlRequest urlRequest = builder.build();
272 urlRequest.start();
273 callback.blockForDone();
274
275 // Throughput observation is posted to the network quality estimator on the network thread
276 // after the UrlRequest is completed. The observations are then eventual ly posted to
277 // throughput listeners on the executor provided to network quality.
278 waitForThroughput.block();
279 assertTrue(throughputListener.throughputObservationCount() > 0);
280
281 // Check RTT observation count after throughput observation has been rec eived. This ensures
282 // that executor has finished posting the RTT observation to the RTT lis teners.
283 assertTrue(rttListener.rttObservationCount() > 0);
284
285 // NETWORK_QUALITY_OBSERVATION_SOURCE_URL_REQUEST
286 assertTrue(rttListener.rttObservationCount(0) > 0);
287
288 // NETWORK_QUALITY_OBSERVATION_SOURCE_TCP
289 assertTrue(rttListener.rttObservationCount(1) > 0);
290
291 // NETWORK_QUALITY_OBSERVATION_SOURCE_QUIC
292 assertEquals(0, rttListener.rttObservationCount(2));
293
294 // Verify that the listeners were notified on the expected thread.
295 assertEquals(mNetworkQualityThread, rttListener.getThread());
296 assertEquals(mNetworkQualityThread, throughputListener.getThread());
297
298 // Verify that effective connection type callback is received and effect ive connection type
299 // is correctly set to the forced value. This also verifies that the con figuration params
300 // from Cronet embedders were correctly read by NetworkQualityEstimator.
301 assertEquals(EffectiveConnectionType.TYPE_2G,
302 testFramework.mCronetEngine.getEffectiveConnectionType());
303
304 testFramework.mCronetEngine.shutdown();
305 }
233 } 306 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698