| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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.content.Context; | 7 import android.content.Context; |
| 8 import android.content.ContextWrapper; | 8 import android.content.ContextWrapper; |
| 9 import android.os.ConditionVariable; | 9 import android.os.ConditionVariable; |
| 10 import android.os.Handler; | 10 import android.os.Handler; |
| (...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 72 | 72 |
| 73 @Override | 73 @Override |
| 74 public void onFailed(UrlRequest request, | 74 public void onFailed(UrlRequest request, |
| 75 ResponseInfo info, | 75 ResponseInfo info, |
| 76 UrlRequestException error) { | 76 UrlRequestException error) { |
| 77 super.onFailed(request, info, error); | 77 super.onFailed(request, info, error); |
| 78 mActivity.mUrlRequestContext.shutdown(); | 78 mActivity.mUrlRequestContext.shutdown(); |
| 79 } | 79 } |
| 80 } | 80 } |
| 81 | 81 |
| 82 static class TestNetworkQualityObserver |
| 83 implements NetworkQualityRTTObserver, NetworkQualityThroughputObserv
er { |
| 84 int mRTTObservationCount; |
| 85 int mThroughputObservationCount; |
| 86 |
| 87 public void onRTTObservation(int rttMs, int when, int source) { |
| 88 mRTTObservationCount++; |
| 89 } |
| 90 |
| 91 public void onThroughputObservation(int throughputKbps, int when, int so
urce) { |
| 92 mThroughputObservationCount++; |
| 93 } |
| 94 |
| 95 public int rttObservationCount() { |
| 96 return mRTTObservationCount; |
| 97 } |
| 98 |
| 99 public int throughputObservationCount() { |
| 100 return mThroughputObservationCount; |
| 101 } |
| 102 } |
| 103 |
| 82 @SmallTest | 104 @SmallTest |
| 83 @Feature({"Cronet"}) | 105 @Feature({"Cronet"}) |
| 84 public void testConfigUserAgent() throws Exception { | 106 public void testConfigUserAgent() throws Exception { |
| 85 String userAgentName = "User-Agent"; | 107 String userAgentName = "User-Agent"; |
| 86 String userAgentValue = "User-Agent-Value"; | 108 String userAgentValue = "User-Agent-Value"; |
| 87 UrlRequestContextConfig config = new UrlRequestContextConfig(); | 109 UrlRequestContextConfig config = new UrlRequestContextConfig(); |
| 88 config.setUserAgent(userAgentValue); | 110 config.setUserAgent(userAgentValue); |
| 89 config.setLibraryName("cronet_tests"); | 111 config.setLibraryName("cronet_tests"); |
| 90 String[] commandLineArgs = { | 112 String[] commandLineArgs = { |
| 91 CronetTestActivity.CONFIG_KEY, config.toString() | 113 CronetTestActivity.CONFIG_KEY, config.toString() |
| (...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 147 // Proxy logic configured to use the test server as its proxy. | 169 // Proxy logic configured to use the test server as its proxy. |
| 148 assertEquals(200, listener.mResponseInfo.getHttpStatusCode()); | 170 assertEquals(200, listener.mResponseInfo.getHttpStatusCode()); |
| 149 assertEquals(serverHostPort, listener.mResponseInfo.getProxyServer()); | 171 assertEquals(serverHostPort, listener.mResponseInfo.getProxyServer()); |
| 150 assertEquals( | 172 assertEquals( |
| 151 "http://DomainThatDoesnt.Resolve/datareductionproxysuccess.txt", | 173 "http://DomainThatDoesnt.Resolve/datareductionproxysuccess.txt", |
| 152 listener.mResponseInfo.getUrl()); | 174 listener.mResponseInfo.getUrl()); |
| 153 } | 175 } |
| 154 | 176 |
| 155 @SmallTest | 177 @SmallTest |
| 156 @Feature({"Cronet"}) | 178 @Feature({"Cronet"}) |
| 179 public void testRealTimeNetworkQualityObservations() throws Exception { |
| 180 mActivity = launchCronetTestApp(); |
| 181 TestNetworkQualityObserver networkQualityObserver = new TestNetworkQuali
tyObserver(); |
| 182 mActivity.mUrlRequestContext.enableNetworkQualityEstimator(true, true); |
| 183 mActivity.mUrlRequestContext.addRTTObserver(networkQualityObserver); |
| 184 mActivity.mUrlRequestContext.addThroughputObserver(networkQualityObserve
r); |
| 185 TestUrlRequestListener listener = new TestUrlRequestListener(); |
| 186 UrlRequest urlRequest = mActivity.mUrlRequestContext.createRequest( |
| 187 TEST_URL, listener, listener.getExecutor()); |
| 188 urlRequest.start(); |
| 189 listener.blockForDone(); |
| 190 assertTrue(networkQualityObserver.rttObservationCount() > 0); |
| 191 assertTrue(networkQualityObserver.throughputObservationCount() > 0); |
| 192 } |
| 193 |
| 194 @SmallTest |
| 195 @Feature({"Cronet"}) |
| 157 public void testShutdown() throws Exception { | 196 public void testShutdown() throws Exception { |
| 158 mActivity = launchCronetTestApp(); | 197 mActivity = launchCronetTestApp(); |
| 159 TestUrlRequestListener listener = new ShutdownTestUrlRequestListener(); | 198 TestUrlRequestListener listener = new ShutdownTestUrlRequestListener(); |
| 160 // Block listener when response starts to verify that shutdown fails | 199 // Block listener when response starts to verify that shutdown fails |
| 161 // if there are active requests. | 200 // if there are active requests. |
| 162 listener.setAutoAdvance(false); | 201 listener.setAutoAdvance(false); |
| 163 UrlRequest urlRequest = mActivity.mUrlRequestContext.createRequest( | 202 UrlRequest urlRequest = mActivity.mUrlRequestContext.createRequest( |
| 164 TEST_URL, listener, listener.getExecutor()); | 203 TEST_URL, listener, listener.getExecutor()); |
| 165 urlRequest.start(); | 204 urlRequest.start(); |
| 166 try { | 205 try { |
| (...skipping 501 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 668 new CronetUrlRequestContext(mActivity, mActivity.getContextConfi
g()); | 707 new CronetUrlRequestContext(mActivity, mActivity.getContextConfi
g()); |
| 669 CronetUrlRequestContext secondContext = new CronetUrlRequestContext( | 708 CronetUrlRequestContext secondContext = new CronetUrlRequestContext( |
| 670 mActivity.getApplicationContext(), mActivity.getContextConfig())
; | 709 mActivity.getApplicationContext(), mActivity.getContextConfig())
; |
| 671 CronetUrlRequestContext thirdContext = new CronetUrlRequestContext( | 710 CronetUrlRequestContext thirdContext = new CronetUrlRequestContext( |
| 672 new ContextWrapper(mActivity), mActivity.getContextConfig()); | 711 new ContextWrapper(mActivity), mActivity.getContextConfig()); |
| 673 firstContext.shutdown(); | 712 firstContext.shutdown(); |
| 674 secondContext.shutdown(); | 713 secondContext.shutdown(); |
| 675 thirdContext.shutdown(); | 714 thirdContext.shutdown(); |
| 676 } | 715 } |
| 677 } | 716 } |
| OLD | NEW |