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

Side by Side Diff: net/android/javatests/src/org/chromium/net/NetworkChangeNotifierTest.java

Issue 816543004: Update from https://crrev.com/308996 (Closed) Base URL: git@github.com:domokit/mojo.git@master
Patch Set: Created 6 years 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 2012 The Chromium Authors. All rights reserved. 1 // Copyright 2012 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.Intent; 8 import android.content.Intent;
9 import android.net.ConnectivityManager; 9 import android.net.ConnectivityManager;
10 import android.net.wifi.WifiManager;
10 import android.telephony.TelephonyManager; 11 import android.telephony.TelephonyManager;
11 import android.test.InstrumentationTestCase; 12 import android.test.InstrumentationTestCase;
12 import android.test.UiThreadTest; 13 import android.test.UiThreadTest;
13 import android.test.suitebuilder.annotation.MediumTest; 14 import android.test.suitebuilder.annotation.MediumTest;
14 15
15 import org.chromium.base.ApplicationState; 16 import org.chromium.base.ApplicationState;
16 import org.chromium.base.library_loader.LibraryLoader; 17 import org.chromium.base.library_loader.LibraryLoader;
17 import org.chromium.base.test.util.Feature; 18 import org.chromium.base.test.util.Feature;
18 import org.chromium.net.NetworkChangeNotifierAutoDetect.NetworkState; 19 import org.chromium.net.NetworkChangeNotifierAutoDetect.NetworkState;
19 20
(...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after
118 mConnectivityDelegate = 119 mConnectivityDelegate =
119 new MockConnectivityManagerDelegate(); 120 new MockConnectivityManagerDelegate();
120 mConnectivityDelegate.setActiveNetworkExists(true); 121 mConnectivityDelegate.setActiveNetworkExists(true);
121 mReceiver.setConnectivityManagerDelegateForTests(mConnectivityDelegate); 122 mReceiver.setConnectivityManagerDelegateForTests(mConnectivityDelegate);
122 123
123 mWifiDelegate = new MockWifiManagerDelegate(); 124 mWifiDelegate = new MockWifiManagerDelegate();
124 mReceiver.setWifiManagerDelegateForTests(mWifiDelegate); 125 mReceiver.setWifiManagerDelegateForTests(mWifiDelegate);
125 mWifiDelegate.setWifiSSID("foo"); 126 mWifiDelegate.setWifiSSID("foo");
126 } 127 }
127 128
129 private double getCurrentMaxBandwidthInMbps() {
130 final NetworkChangeNotifierAutoDetect.NetworkState networkState =
131 mReceiver.getCurrentNetworkState();
132 return mReceiver.getCurrentMaxBandwidthInMbps(networkState);
133 }
134
135 private int getCurrentConnectionType() {
136 final NetworkChangeNotifierAutoDetect.NetworkState networkState =
137 mReceiver.getCurrentNetworkState();
138 return mReceiver.getCurrentConnectionType(networkState);
139 }
140
141 /**
142 * Tests that changing the RSSI_CHANGED_ACTION intent updates MaxBandwidth.
143 */
144 @UiThreadTest
145 @MediumTest
146 @Feature({"Android-AppBase"})
147 public void testNetworkChangeNotifierRSSIEventUpdatesMaxBandwidthForWiFi()
148 throws InterruptedException {
149 NetworkChangeNotifier notifier = NetworkChangeNotifier.getInstance();
150 mConnectivityDelegate.setNetworkType(ConnectivityManager.TYPE_WIFI);
151 mWifiDelegate.setLinkSpeedInMbps(42);
152 Intent intent = new Intent(WifiManager.RSSI_CHANGED_ACTION);
153 mReceiver.onReceive(getInstrumentation().getTargetContext(), intent);
154
155 assertEquals(42.0, notifier.getCurrentMaxBandwidthInMbps());
156
157 // Changing the link speed has no effect until the intent fires.
158 mWifiDelegate.setLinkSpeedInMbps(80);
159 assertEquals(42.0, notifier.getCurrentMaxBandwidthInMbps());
160
161 // Fire the intent.
162 mReceiver.onReceive(getInstrumentation().getTargetContext(), intent);
163 assertEquals(80.0, notifier.getCurrentMaxBandwidthInMbps());
164
165 // Firing a network type change intent also causes max bandwidth to upda te.
166 mWifiDelegate.setLinkSpeedInMbps(20);
167 intent = new Intent(ConnectivityManager.CONNECTIVITY_ACTION);
168 mReceiver.onReceive(getInstrumentation().getTargetContext(), intent);
169 assertEquals(20.0, notifier.getCurrentMaxBandwidthInMbps());
170 }
171
128 /** 172 /**
129 * Tests that changing the network type changes the maxBandwidth. 173 * Tests that changing the network type changes the maxBandwidth.
130 */ 174 */
131 @UiThreadTest 175 @UiThreadTest
132 @MediumTest 176 @MediumTest
133 @Feature({"Android-AppBase"}) 177 @Feature({"Android-AppBase"})
134 public void testNetworkChangeNotifierMaxBandwidthEthernet() throws Interrupt edException { 178 public void testNetworkChangeNotifierMaxBandwidthEthernet() throws Interrupt edException {
135 // Show that for Ethernet the link speed is unknown (+Infinity). 179 // Show that for Ethernet the link speed is unknown (+Infinity).
136 mConnectivityDelegate.setNetworkType(ConnectivityManager.TYPE_ETHERNET); 180 mConnectivityDelegate.setNetworkType(ConnectivityManager.TYPE_ETHERNET);
137 assertEquals(ConnectionType.CONNECTION_ETHERNET, 181 assertEquals(ConnectionType.CONNECTION_ETHERNET, getCurrentConnectionTyp e());
138 mReceiver.getCurrentConnectionType()); 182 assertEquals(Double.POSITIVE_INFINITY, getCurrentMaxBandwidthInMbps());
139 assertEquals(Double.POSITIVE_INFINITY, mReceiver.getCurrentMaxBandwidthI nMbps());
140 } 183 }
141 184
142 @UiThreadTest 185 @UiThreadTest
143 @MediumTest 186 @MediumTest
144 @Feature({"Android-AppBase"}) 187 @Feature({"Android-AppBase"})
145 public void testNetworkChangeNotifierMaxBandwidthWifi() throws InterruptedEx ception { 188 public void testNetworkChangeNotifierMaxBandwidthWifi() throws InterruptedEx ception {
146 // Test that for wifi types the link speed is read from the WifiManager. 189 // Test that for wifi types the link speed is read from the WifiManager.
147 mWifiDelegate.setLinkSpeedInMbps(42); 190 mWifiDelegate.setLinkSpeedInMbps(42);
148 mConnectivityDelegate.setNetworkType(ConnectivityManager.TYPE_WIFI); 191 mConnectivityDelegate.setNetworkType(ConnectivityManager.TYPE_WIFI);
149 assertEquals(ConnectionType.CONNECTION_WIFI, mReceiver.getCurrentConnect ionType()); 192 assertEquals(ConnectionType.CONNECTION_WIFI, getCurrentConnectionType()) ;
150 assertEquals(42.0, mReceiver.getCurrentMaxBandwidthInMbps()); 193 assertEquals(42.0, getCurrentMaxBandwidthInMbps());
151 } 194 }
152 195
153 @UiThreadTest 196 @UiThreadTest
154 @MediumTest 197 @MediumTest
155 @Feature({"Android-AppBase"}) 198 @Feature({"Android-AppBase"})
156 public void testNetworkChangeNotifierMaxBandwidthWiMax() throws InterruptedE xception { 199 public void testNetworkChangeNotifierMaxBandwidthWiMax() throws InterruptedE xception {
157 // Show that for WiMax the link speed is unknown (+Infinity), although t he type is 4g. 200 // Show that for WiMax the link speed is unknown (+Infinity), although t he type is 4g.
158 // TODO(jkarlin): Add support for CONNECTION_WIMAX as specified in 201 // TODO(jkarlin): Add support for CONNECTION_WIMAX as specified in
159 // http://w3c.github.io/netinfo/. 202 // http://w3c.github.io/netinfo/.
160 mConnectivityDelegate.setNetworkType(ConnectivityManager.TYPE_WIMAX); 203 mConnectivityDelegate.setNetworkType(ConnectivityManager.TYPE_WIMAX);
161 assertEquals(ConnectionType.CONNECTION_4G, 204 assertEquals(ConnectionType.CONNECTION_4G, getCurrentConnectionType());
162 mReceiver.getCurrentConnectionType()); 205 assertEquals(Double.POSITIVE_INFINITY, getCurrentMaxBandwidthInMbps());
163 assertEquals(Double.POSITIVE_INFINITY, mReceiver.getCurrentMaxBandwidthI nMbps());
164 } 206 }
165 207
166 @UiThreadTest 208 @UiThreadTest
167 @MediumTest 209 @MediumTest
168 @Feature({"Android-AppBase"}) 210 @Feature({"Android-AppBase"})
169 public void testNetworkChangeNotifierMaxBandwidthBluetooth() throws Interrup tedException { 211 public void testNetworkChangeNotifierMaxBandwidthBluetooth() throws Interrup tedException {
170 // Show that for bluetooth the link speed is unknown (+Infinity). 212 // Show that for bluetooth the link speed is unknown (+Infinity).
171 mConnectivityDelegate.setNetworkType(ConnectivityManager.TYPE_BLUETOOTH) ; 213 mConnectivityDelegate.setNetworkType(ConnectivityManager.TYPE_BLUETOOTH) ;
172 assertEquals(ConnectionType.CONNECTION_BLUETOOTH, 214 assertEquals(ConnectionType.CONNECTION_BLUETOOTH, getCurrentConnectionTy pe());
173 mReceiver.getCurrentConnectionType()); 215 assertEquals(Double.POSITIVE_INFINITY, getCurrentMaxBandwidthInMbps());
174 assertEquals(Double.POSITIVE_INFINITY, mReceiver.getCurrentMaxBandwidthI nMbps());
175 } 216 }
176 217
177 @UiThreadTest 218 @UiThreadTest
178 @MediumTest 219 @MediumTest
179 @Feature({"Android-AppBase"}) 220 @Feature({"Android-AppBase"})
180 public void testNetworkChangeNotifierMaxBandwidthMobile() throws Interrupted Exception { 221 public void testNetworkChangeNotifierMaxBandwidthMobile() throws Interrupted Exception {
181 // Test that for mobile types the subtype is used to determine the maxBa ndwidth. 222 // Test that for mobile types the subtype is used to determine the maxBa ndwidth.
182 mConnectivityDelegate.setNetworkType(ConnectivityManager.TYPE_MOBILE); 223 mConnectivityDelegate.setNetworkType(ConnectivityManager.TYPE_MOBILE);
183 mConnectivityDelegate.setNetworkSubtype(TelephonyManager.NETWORK_TYPE_LT E); 224 mConnectivityDelegate.setNetworkSubtype(TelephonyManager.NETWORK_TYPE_LT E);
184 assertEquals(ConnectionType.CONNECTION_4G, mReceiver.getCurrentConnectio nType()); 225 assertEquals(ConnectionType.CONNECTION_4G, getCurrentConnectionType());
185 assertEquals(100.0, mReceiver.getCurrentMaxBandwidthInMbps()); 226 assertEquals(100.0, getCurrentMaxBandwidthInMbps());
186 } 227 }
187 228
188 /** 229 /**
189 * Tests that when Chrome gets an intent indicating a change in network conn ectivity, it sends a 230 * Tests that when Chrome gets an intent indicating a change in network conn ectivity, it sends a
190 * notification to Java observers. 231 * notification to Java observers.
191 */ 232 */
192 @UiThreadTest 233 @UiThreadTest
193 @MediumTest 234 @MediumTest
194 @Feature({"Android-AppBase"}) 235 @Feature({"Android-AppBase"})
195 public void testNetworkChangeNotifierJavaObservers() throws InterruptedExcep tion { 236 public void testNetworkChangeNotifierJavaObservers() throws InterruptedExcep tion {
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
233 // Change the state. 274 // Change the state.
234 mConnectivityDelegate.setActiveNetworkExists(true); 275 mConnectivityDelegate.setActiveNetworkExists(true);
235 mConnectivityDelegate.setNetworkType(ConnectivityManager.TYPE_WIFI); 276 mConnectivityDelegate.setNetworkType(ConnectivityManager.TYPE_WIFI);
236 // The NetworkChangeNotifierAutoDetect doesn't receive any notification while we are in the 277 // The NetworkChangeNotifierAutoDetect doesn't receive any notification while we are in the
237 // background, but when we get back to the foreground the state changed should be detected 278 // background, but when we get back to the foreground the state changed should be detected
238 // and a notification sent. 279 // and a notification sent.
239 mReceiver.onApplicationStateChange(ApplicationState.HAS_RUNNING_ACTIVITI ES); 280 mReceiver.onApplicationStateChange(ApplicationState.HAS_RUNNING_ACTIVITI ES);
240 assertTrue(observer.hasReceivedNotification()); 281 assertTrue(observer.hasReceivedNotification());
241 } 282 }
242 } 283 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698