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

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

Issue 1273173002: Added Network Quality Estimator Real-time interface to Cronet (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 4 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 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
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 implements RTTObserver,
83 BandwidthObserver {
84 int mRTTObservationCount;
85 int mBandwidthObservationCount;
86
87 public void onRTTObservation(int value, int when, int source) {
88 mRTTObservationCount++;
89 }
90
91 public void onBandwidthObservation(int value, int when, int source) {
92 mBandwidthObservationCount++;
93 }
94
95 public int rttObservationCount() {
96 return mRTTObservationCount;
97 }
98
99 public int bandwidthObservationCount() {
100 return mBandwidthObservationCount;
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
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 =
182 new TestNetworkQualityObserver();
183 mActivity.mUrlRequestContext.configureNetworkQualityEstimator(true,
mef 2015/08/11 17:16:27 What happens if you add observer without configuri
bengr 2015/08/25 23:43:34 Removed the configure method.
184 true);
185 mActivity.mUrlRequestContext.addRTTObserver(networkQualityObserver);
186 mActivity.mUrlRequestContext.addBandwidthObserver(
187 networkQualityObserver);
188 TestUrlRequestListener listener = new TestUrlRequestListener();
189 UrlRequest urlRequest = mActivity.mUrlRequestContext.createRequest(
190 TEST_URL, listener, listener.getExecutor());
191 urlRequest.start();
192 listener.blockForDone();
193 assertTrue(networkQualityObserver.rttObservationCount() > 0);
194 assertTrue(networkQualityObserver.bandwidthObservationCount() > 0);
195 }
196
197 @SmallTest
198 @Feature({"Cronet"})
157 public void testShutdown() throws Exception { 199 public void testShutdown() throws Exception {
158 mActivity = launchCronetTestApp(); 200 mActivity = launchCronetTestApp();
159 TestUrlRequestListener listener = new ShutdownTestUrlRequestListener(); 201 TestUrlRequestListener listener = new ShutdownTestUrlRequestListener();
160 // Block listener when response starts to verify that shutdown fails 202 // Block listener when response starts to verify that shutdown fails
161 // if there are active requests. 203 // if there are active requests.
162 listener.setAutoAdvance(false); 204 listener.setAutoAdvance(false);
163 UrlRequest urlRequest = mActivity.mUrlRequestContext.createRequest( 205 UrlRequest urlRequest = mActivity.mUrlRequestContext.createRequest(
164 TEST_URL, listener, listener.getExecutor()); 206 TEST_URL, listener, listener.getExecutor());
165 urlRequest.start(); 207 urlRequest.start();
166 try { 208 try {
(...skipping 502 matching lines...) Expand 10 before | Expand all | Expand 10 after
669 new CronetUrlRequestContext(mActivity, mActivity.getContextConfi g()); 711 new CronetUrlRequestContext(mActivity, mActivity.getContextConfi g());
670 CronetUrlRequestContext secondContext = new CronetUrlRequestContext( 712 CronetUrlRequestContext secondContext = new CronetUrlRequestContext(
671 mActivity.getApplicationContext(), mActivity.getContextConfig()) ; 713 mActivity.getApplicationContext(), mActivity.getContextConfig()) ;
672 CronetUrlRequestContext thirdContext = new CronetUrlRequestContext( 714 CronetUrlRequestContext thirdContext = new CronetUrlRequestContext(
673 new ContextWrapper(mActivity), mActivity.getContextConfig()); 715 new ContextWrapper(mActivity), mActivity.getContextConfig());
674 firstContext.shutdown(); 716 firstContext.shutdown();
675 secondContext.shutdown(); 717 secondContext.shutdown();
676 thirdContext.shutdown(); 718 thirdContext.shutdown();
677 } 719 }
678 } 720 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698