Index: components/cronet/android/test/javatests/src/org/chromium/net/NQETest.java |
diff --git a/components/cronet/android/test/javatests/src/org/chromium/net/NQETest.java b/components/cronet/android/test/javatests/src/org/chromium/net/NQETest.java |
index 4bf2631d5e9c845980ca4b7d0be57cc8aeba9dc5..5ae8c0aa35f845292b46236e26f2fcf879cb13a8 100644 |
--- a/components/cronet/android/test/javatests/src/org/chromium/net/NQETest.java |
+++ b/components/cronet/android/test/javatests/src/org/chromium/net/NQETest.java |
@@ -8,6 +8,8 @@ import android.os.ConditionVariable; |
import android.os.StrictMode; |
import android.support.test.filters.SmallTest; |
+import org.json.JSONObject; |
+ |
import org.chromium.base.Log; |
import org.chromium.base.annotations.JNINamespace; |
import org.chromium.base.annotations.SuppressFBWarnings; |
@@ -230,4 +232,75 @@ public class NQETest extends CronetTestBase { |
testFramework.mCronetEngine.shutdown(); |
assertTrue(writeCountHistogram.getDelta() > 0); |
} |
+ |
+ @SmallTest |
+ @Feature({"Cronet"}) |
+ public void testQuicDisabledWithParams() throws Exception { |
+ ExperimentalCronetEngine.Builder mCronetEngineBuilder = |
+ new ExperimentalCronetEngine.Builder(getContext()); |
+ Executor listenersExecutor = Executors.newSingleThreadExecutor(new ExecutorThreadFactory()); |
+ ConditionVariable waitForThroughput = new ConditionVariable(); |
+ TestNetworkQualityRttListener rttListener = |
+ new TestNetworkQualityRttListener(listenersExecutor); |
+ TestNetworkQualityThroughputListener throughputListener = |
+ new TestNetworkQualityThroughputListener(listenersExecutor, waitForThroughput); |
+ |
+ // Force the effective connection type to "2G". |
+ JSONObject nqeOptions = new JSONObject().put("force_effective_connection_type", "2G"); |
+ // Add one more extra param two times to ensure robustness. |
+ nqeOptions.put("some_other_param_1", "value1"); |
+ nqeOptions.put("some_other_param_2", "value2"); |
+ JSONObject experimentalOptions = |
+ new JSONObject().put("NetworkQualityEstimator", nqeOptions); |
+ experimentalOptions.put("SomeOtherFieldTrialName", new JSONObject()); |
+ |
+ mCronetEngineBuilder.enableHttp2(true).enableQuic(false).enableNetworkQualityEstimator( |
+ true); |
+ mCronetEngineBuilder.setExperimentalOptions(experimentalOptions.toString()); |
+ final CronetTestFramework testFramework = |
+ startCronetTestFrameworkWithUrlAndCronetEngineBuilder(null, mCronetEngineBuilder); |
+ testFramework.mCronetEngine.configureNetworkQualityEstimatorForTesting(true, true, false); |
+ |
+ testFramework.mCronetEngine.addRttListener(rttListener); |
+ testFramework.mCronetEngine.addThroughputListener(throughputListener); |
+ |
+ TestUrlRequestCallback callback = new TestUrlRequestCallback(); |
+ UrlRequest.Builder builder = testFramework.mCronetEngine.newUrlRequestBuilder( |
+ mUrl, callback, callback.getExecutor()); |
+ |
+ UrlRequest urlRequest = builder.build(); |
+ urlRequest.start(); |
+ callback.blockForDone(); |
+ |
+ // Throughput observation is posted to the network quality estimator on the network thread |
+ // after the UrlRequest is completed. The observations are then eventually posted to |
+ // throughput listeners on the executor provided to network quality. |
+ waitForThroughput.block(); |
+ assertTrue(throughputListener.throughputObservationCount() > 0); |
+ |
+ // Check RTT observation count after throughput observation has been received. This ensures |
+ // that executor has finished posting the RTT observation to the RTT listeners. |
+ assertTrue(rttListener.rttObservationCount() > 0); |
+ |
+ // NETWORK_QUALITY_OBSERVATION_SOURCE_URL_REQUEST |
+ assertTrue(rttListener.rttObservationCount(0) > 0); |
+ |
+ // NETWORK_QUALITY_OBSERVATION_SOURCE_TCP |
+ assertTrue(rttListener.rttObservationCount(1) > 0); |
+ |
+ // NETWORK_QUALITY_OBSERVATION_SOURCE_QUIC |
+ assertEquals(0, rttListener.rttObservationCount(2)); |
+ |
+ // Verify that the listeners were notified on the expected thread. |
+ assertEquals(mNetworkQualityThread, rttListener.getThread()); |
+ assertEquals(mNetworkQualityThread, throughputListener.getThread()); |
+ |
+ // Verify that effective connection type callback is received and effective connection type |
+ // is correctly set to the forced value. This also verifies that the configuration params |
+ // from Cronet embedders were correctly read by NetworkQualityEstimator. |
+ assertEquals(EffectiveConnectionType.TYPE_2G, |
+ testFramework.mCronetEngine.getEffectiveConnectionType()); |
+ |
+ testFramework.mCronetEngine.shutdown(); |
+ } |
} |