| OLD | NEW |
| 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; | |
| 8 import android.os.StrictMode; | 7 import android.os.StrictMode; |
| 9 import android.support.test.filters.SmallTest; | 8 import android.support.test.filters.SmallTest; |
| 10 | 9 |
| 11 import org.chromium.base.Log; | 10 import org.chromium.base.Log; |
| 12 import org.chromium.base.annotations.JNINamespace; | 11 import org.chromium.base.annotations.JNINamespace; |
| 13 import org.chromium.base.annotations.SuppressFBWarnings; | 12 import org.chromium.base.annotations.SuppressFBWarnings; |
| 14 import org.chromium.base.test.util.DisabledTest; | 13 import org.chromium.base.test.util.DisabledTest; |
| 15 import org.chromium.base.test.util.Feature; | 14 import org.chromium.base.test.util.Feature; |
| 16 import org.chromium.base.test.util.MetricsUtils.HistogramDelta; | 15 import org.chromium.base.test.util.MetricsUtils.HistogramDelta; |
| 17 import org.chromium.net.MetricsTestUtil.TestExecutor; | 16 import org.chromium.net.MetricsTestUtil.TestExecutor; |
| (...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 71 @Feature({"Cronet"}) | 70 @Feature({"Cronet"}) |
| 72 public void testNotEnabled() throws Exception { | 71 public void testNotEnabled() throws Exception { |
| 73 ExperimentalCronetEngine.Builder mCronetEngineBuilder = | 72 ExperimentalCronetEngine.Builder mCronetEngineBuilder = |
| 74 new ExperimentalCronetEngine.Builder(getContext()); | 73 new ExperimentalCronetEngine.Builder(getContext()); |
| 75 final CronetTestFramework testFramework = | 74 final CronetTestFramework testFramework = |
| 76 startCronetTestFrameworkWithUrlAndCronetEngineBuilder(null, mCro
netEngineBuilder); | 75 startCronetTestFrameworkWithUrlAndCronetEngineBuilder(null, mCro
netEngineBuilder); |
| 77 Executor networkQualityExecutor = Executors.newSingleThreadExecutor(); | 76 Executor networkQualityExecutor = Executors.newSingleThreadExecutor(); |
| 78 TestNetworkQualityRttListener rttListener = | 77 TestNetworkQualityRttListener rttListener = |
| 79 new TestNetworkQualityRttListener(networkQualityExecutor); | 78 new TestNetworkQualityRttListener(networkQualityExecutor); |
| 80 TestNetworkQualityThroughputListener throughputListener = | 79 TestNetworkQualityThroughputListener throughputListener = |
| 81 new TestNetworkQualityThroughputListener(networkQualityExecutor,
null); | 80 new TestNetworkQualityThroughputListener(networkQualityExecutor)
; |
| 82 try { | 81 try { |
| 83 testFramework.mCronetEngine.addRttListener(rttListener); | 82 testFramework.mCronetEngine.addRttListener(rttListener); |
| 84 fail("Should throw an exception."); | 83 fail("Should throw an exception."); |
| 85 } catch (IllegalStateException e) { | 84 } catch (IllegalStateException e) { |
| 86 } | 85 } |
| 87 try { | 86 try { |
| 88 testFramework.mCronetEngine.addThroughputListener(throughputListener
); | 87 testFramework.mCronetEngine.addThroughputListener(throughputListener
); |
| 89 fail("Should throw an exception."); | 88 fail("Should throw an exception."); |
| 90 } catch (IllegalStateException e) { | 89 } catch (IllegalStateException e) { |
| 91 } | 90 } |
| (...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 140 } | 139 } |
| 141 | 140 |
| 142 @SmallTest | 141 @SmallTest |
| 143 @Feature({"Cronet"}) | 142 @Feature({"Cronet"}) |
| 144 @DisabledTest(message = "Disabled due to flaky assert. See crbug.com/710626"
) | 143 @DisabledTest(message = "Disabled due to flaky assert. See crbug.com/710626"
) |
| 145 public void testQuicDisabled() throws Exception { | 144 public void testQuicDisabled() throws Exception { |
| 146 ExperimentalCronetEngine.Builder mCronetEngineBuilder = | 145 ExperimentalCronetEngine.Builder mCronetEngineBuilder = |
| 147 new ExperimentalCronetEngine.Builder(getContext()); | 146 new ExperimentalCronetEngine.Builder(getContext()); |
| 148 assert RttThroughputValues.INVALID_RTT_THROUGHPUT < 0; | 147 assert RttThroughputValues.INVALID_RTT_THROUGHPUT < 0; |
| 149 Executor listenersExecutor = Executors.newSingleThreadExecutor(new Execu
torThreadFactory()); | 148 Executor listenersExecutor = Executors.newSingleThreadExecutor(new Execu
torThreadFactory()); |
| 150 ConditionVariable waitForThroughput = new ConditionVariable(); | |
| 151 TestNetworkQualityRttListener rttListener = | 149 TestNetworkQualityRttListener rttListener = |
| 152 new TestNetworkQualityRttListener(listenersExecutor); | 150 new TestNetworkQualityRttListener(listenersExecutor); |
| 153 TestNetworkQualityThroughputListener throughputListener = | 151 TestNetworkQualityThroughputListener throughputListener = |
| 154 new TestNetworkQualityThroughputListener(listenersExecutor, wait
ForThroughput); | 152 new TestNetworkQualityThroughputListener(listenersExecutor); |
| 155 mCronetEngineBuilder.enableNetworkQualityEstimator(true).enableHttp2(tru
e).enableQuic( | 153 mCronetEngineBuilder.enableNetworkQualityEstimator(true).enableHttp2(tru
e).enableQuic( |
| 156 false); | 154 false); |
| 157 mCronetEngineBuilder.setStoragePath(CronetTestFramework.getTestStorage(g
etContext())); | 155 mCronetEngineBuilder.setStoragePath(CronetTestFramework.getTestStorage(g
etContext())); |
| 158 final CronetTestFramework testFramework = | 156 final CronetTestFramework testFramework = |
| 159 startCronetTestFrameworkWithUrlAndCronetEngineBuilder(null, mCro
netEngineBuilder); | 157 startCronetTestFrameworkWithUrlAndCronetEngineBuilder(null, mCro
netEngineBuilder); |
| 160 testFramework.mCronetEngine.configureNetworkQualityEstimatorForTesting(t
rue, true, true); | 158 testFramework.mCronetEngine.configureNetworkQualityEstimatorForTesting(t
rue, true, true); |
| 161 | 159 |
| 162 testFramework.mCronetEngine.addRttListener(rttListener); | 160 testFramework.mCronetEngine.addRttListener(rttListener); |
| 163 testFramework.mCronetEngine.addThroughputListener(throughputListener); | 161 testFramework.mCronetEngine.addThroughputListener(throughputListener); |
| 164 | 162 |
| 165 HistogramDelta writeCountHistogram = new HistogramDelta("NQE.Prefs.Write
Count", 1); | 163 HistogramDelta writeCountHistogram = new HistogramDelta("NQE.Prefs.Write
Count", 1); |
| 166 assertEquals(0, writeCountHistogram.getDelta()); // Sanity check. | 164 assertEquals(0, writeCountHistogram.getDelta()); // Sanity check. |
| 167 | 165 |
| 168 HistogramDelta readCountHistogram = new HistogramDelta("NQE.Prefs.ReadCo
unt", 1); | 166 HistogramDelta readCountHistogram = new HistogramDelta("NQE.Prefs.ReadCo
unt", 1); |
| 169 assertEquals(0, readCountHistogram.getDelta()); // Sanity check. | 167 assertEquals(0, readCountHistogram.getDelta()); // Sanity check. |
| 170 | 168 |
| 171 TestUrlRequestCallback callback = new TestUrlRequestCallback(); | 169 TestUrlRequestCallback callback = new TestUrlRequestCallback(); |
| 172 UrlRequest.Builder builder = testFramework.mCronetEngine.newUrlRequestBu
ilder( | 170 UrlRequest.Builder builder = testFramework.mCronetEngine.newUrlRequestBu
ilder( |
| 173 mUrl, callback, callback.getExecutor()); | 171 mUrl, callback, callback.getExecutor()); |
| 174 UrlRequest urlRequest = builder.build(); | 172 UrlRequest urlRequest = builder.build(); |
| 175 urlRequest.start(); | 173 urlRequest.start(); |
| 176 callback.blockForDone(); | 174 callback.blockForDone(); |
| 177 | 175 |
| 178 // Throughput observation is posted to the network quality estimator on
the network thread | 176 // Throughput observation is posted to the network quality estimator on
the network thread |
| 179 // after the UrlRequest is completed. The observations are then eventual
ly posted to | 177 // after the UrlRequest is completed. The observations are then eventual
ly posted to |
| 180 // throughput listeners on the executor provided to network quality. | 178 // throughput listeners on the executor provided to network quality. |
| 181 waitForThroughput.block(); | 179 throughputListener.waitUntilFirstThroughputObservationReceived(); |
| 180 |
| 181 // Wait for RTT observation (at the URL request layer) to be posted. |
| 182 rttListener.waitUntilFirstUrlRequestRTTReceived(); |
| 183 |
| 182 assertTrue(throughputListener.throughputObservationCount() > 0); | 184 assertTrue(throughputListener.throughputObservationCount() > 0); |
| 183 | 185 |
| 184 // Prefs must be read at startup. | 186 // Prefs must be read at startup. |
| 185 assertTrue(readCountHistogram.getDelta() > 0); | 187 assertTrue(readCountHistogram.getDelta() > 0); |
| 186 | 188 |
| 187 // Check RTT observation count after throughput observation has been rec
eived. This ensures | 189 // Check RTT observation count after throughput observation has been rec
eived. This ensures |
| 188 // that executor has finished posting the RTT observation to the RTT lis
teners. | 190 // that executor has finished posting the RTT observation to the RTT lis
teners. |
| 189 assertTrue(rttListener.rttObservationCount() > 0); | 191 assertTrue(rttListener.rttObservationCount() > 0); |
| 190 | 192 |
| 191 // NETWORK_QUALITY_OBSERVATION_SOURCE_URL_REQUEST | 193 // NETWORK_QUALITY_OBSERVATION_SOURCE_URL_REQUEST |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 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 } |
| 233 } | 235 } |
| OLD | NEW |