コード例 #1
0
 @SmallTest
 @Feature({"Cronet"})
 public void testRealTimeNetworkQualityObservations() throws Exception {
   mActivity = launchCronetTestApp();
   TestExecutor testExecutor = new TestExecutor();
   TestNetworkQualityListener networkQualityListener = new TestNetworkQualityListener();
   mActivity.mCronetEngine.enableNetworkQualityEstimatorForTesting(true, true, testExecutor);
   mActivity.mCronetEngine.addRttListener(networkQualityListener);
   mActivity.mCronetEngine.addThroughputListener(networkQualityListener);
   TestUrlRequestListener listener = new TestUrlRequestListener();
   UrlRequest urlRequest =
       mActivity.mCronetEngine.createRequest(TEST_URL, listener, listener.getExecutor());
   urlRequest.start();
   listener.blockForDone();
   testExecutor.runAllTasks();
   assertTrue(networkQualityListener.rttObservationCount() > 0);
   assertTrue(networkQualityListener.throughputObservationCount() > 0);
   mActivity.mCronetEngine.shutdown();
 }
コード例 #2
0
 @SmallTest
 @Feature({"Cronet"})
 public void testRealTimeNetworkQualityObservationsNotEnabled() throws Exception {
   mActivity = launchCronetTestApp();
   TestNetworkQualityListener networkQualityListener = new TestNetworkQualityListener();
   try {
     mActivity.mCronetEngine.addRttListener(networkQualityListener);
     fail("Should throw an exception.");
   } catch (IllegalStateException e) {
   }
   try {
     mActivity.mCronetEngine.addThroughputListener(networkQualityListener);
     fail("Should throw an exception.");
   } catch (IllegalStateException e) {
   }
   TestUrlRequestListener listener = new TestUrlRequestListener();
   UrlRequest urlRequest =
       mActivity.mCronetEngine.createRequest(TEST_URL, listener, listener.getExecutor());
   urlRequest.start();
   listener.blockForDone();
   assertEquals(0, networkQualityListener.rttObservationCount());
   assertEquals(0, networkQualityListener.throughputObservationCount());
   mActivity.mCronetEngine.shutdown();
 }