summaryrefslogtreecommitdiffstats
path: root/net/android/javatests/src/org
diff options
context:
space:
mode:
authorjkarlin <jkarlin@chromium.org>2014-12-16 11:59:47 -0800
committerCommit bot <commit-bot@chromium.org>2014-12-16 20:00:23 +0000
commit7b25e6c3b62270e30e92ff19a5fa915d5b6213f9 (patch)
treee2209a52feccf54df6b48e5d46a8de1078fb1c81 /net/android/javatests/src/org
parent2c719d3954743e3baa47ca02624dc43391f0bec5 (diff)
downloadchromium_src-7b25e6c3b62270e30e92ff19a5fa915d5b6213f9.zip
chromium_src-7b25e6c3b62270e30e92ff19a5fa915d5b6213f9.tar.gz
chromium_src-7b25e6c3b62270e30e92ff19a5fa915d5b6213f9.tar.bz2
[NetInfo] Add a MaxBandwidthChangeObserver and Android implementation
* Add a MaxBandwidthChangeObserver to NetworkChangeNotifier * Android notifies of max bandwidth changes at two points: 1. On connection type change (if the bandwidth changes) 2. On wifi signal strength change BUG=433370 Review URL: https://codereview.chromium.org/780293003 Cr-Commit-Position: refs/heads/master@{#308647}
Diffstat (limited to 'net/android/javatests/src/org')
-rw-r--r--net/android/javatests/src/org/chromium/net/NetworkChangeNotifierTest.java67
1 files changed, 54 insertions, 13 deletions
diff --git a/net/android/javatests/src/org/chromium/net/NetworkChangeNotifierTest.java b/net/android/javatests/src/org/chromium/net/NetworkChangeNotifierTest.java
index f4eafd9..d2229dc 100644
--- a/net/android/javatests/src/org/chromium/net/NetworkChangeNotifierTest.java
+++ b/net/android/javatests/src/org/chromium/net/NetworkChangeNotifierTest.java
@@ -7,6 +7,7 @@ package org.chromium.net;
import android.content.Context;
import android.content.Intent;
import android.net.ConnectivityManager;
+import android.net.wifi.WifiManager;
import android.telephony.TelephonyManager;
import android.test.InstrumentationTestCase;
import android.test.UiThreadTest;
@@ -125,6 +126,49 @@ public class NetworkChangeNotifierTest extends InstrumentationTestCase {
mWifiDelegate.setWifiSSID("foo");
}
+ private double getCurrentMaxBandwidthInMbps() {
+ final NetworkChangeNotifierAutoDetect.NetworkState networkState =
+ mReceiver.getCurrentNetworkState();
+ return mReceiver.getCurrentMaxBandwidthInMbps(networkState);
+ }
+
+ private int getCurrentConnectionType() {
+ final NetworkChangeNotifierAutoDetect.NetworkState networkState =
+ mReceiver.getCurrentNetworkState();
+ return mReceiver.getCurrentConnectionType(networkState);
+ }
+
+ /**
+ * Tests that changing the RSSI_CHANGED_ACTION intent updates MaxBandwidth.
+ */
+ @UiThreadTest
+ @MediumTest
+ @Feature({"Android-AppBase"})
+ public void testNetworkChangeNotifierRSSIEventUpdatesMaxBandwidthForWiFi()
+ throws InterruptedException {
+ NetworkChangeNotifier notifier = NetworkChangeNotifier.getInstance();
+ mConnectivityDelegate.setNetworkType(ConnectivityManager.TYPE_WIFI);
+ mWifiDelegate.setLinkSpeedInMbps(42);
+ Intent intent = new Intent(WifiManager.RSSI_CHANGED_ACTION);
+ mReceiver.onReceive(getInstrumentation().getTargetContext(), intent);
+
+ assertEquals(42.0, notifier.getCurrentMaxBandwidthInMbps());
+
+ // Changing the link speed has no effect until the intent fires.
+ mWifiDelegate.setLinkSpeedInMbps(80);
+ assertEquals(42.0, notifier.getCurrentMaxBandwidthInMbps());
+
+ // Fire the intent.
+ mReceiver.onReceive(getInstrumentation().getTargetContext(), intent);
+ assertEquals(80.0, notifier.getCurrentMaxBandwidthInMbps());
+
+ // Firing a network type change intent also causes max bandwidth to update.
+ mWifiDelegate.setLinkSpeedInMbps(20);
+ intent = new Intent(ConnectivityManager.CONNECTIVITY_ACTION);
+ mReceiver.onReceive(getInstrumentation().getTargetContext(), intent);
+ assertEquals(20.0, notifier.getCurrentMaxBandwidthInMbps());
+ }
+
/**
* Tests that changing the network type changes the maxBandwidth.
*/
@@ -134,9 +178,8 @@ public class NetworkChangeNotifierTest extends InstrumentationTestCase {
public void testNetworkChangeNotifierMaxBandwidthEthernet() throws InterruptedException {
// Show that for Ethernet the link speed is unknown (+Infinity).
mConnectivityDelegate.setNetworkType(ConnectivityManager.TYPE_ETHERNET);
- assertEquals(ConnectionType.CONNECTION_ETHERNET,
- mReceiver.getCurrentConnectionType());
- assertEquals(Double.POSITIVE_INFINITY, mReceiver.getCurrentMaxBandwidthInMbps());
+ assertEquals(ConnectionType.CONNECTION_ETHERNET, getCurrentConnectionType());
+ assertEquals(Double.POSITIVE_INFINITY, getCurrentMaxBandwidthInMbps());
}
@UiThreadTest
@@ -146,8 +189,8 @@ public class NetworkChangeNotifierTest extends InstrumentationTestCase {
// Test that for wifi types the link speed is read from the WifiManager.
mWifiDelegate.setLinkSpeedInMbps(42);
mConnectivityDelegate.setNetworkType(ConnectivityManager.TYPE_WIFI);
- assertEquals(ConnectionType.CONNECTION_WIFI, mReceiver.getCurrentConnectionType());
- assertEquals(42.0, mReceiver.getCurrentMaxBandwidthInMbps());
+ assertEquals(ConnectionType.CONNECTION_WIFI, getCurrentConnectionType());
+ assertEquals(42.0, getCurrentMaxBandwidthInMbps());
}
@UiThreadTest
@@ -158,9 +201,8 @@ public class NetworkChangeNotifierTest extends InstrumentationTestCase {
// TODO(jkarlin): Add support for CONNECTION_WIMAX as specified in
// http://w3c.github.io/netinfo/.
mConnectivityDelegate.setNetworkType(ConnectivityManager.TYPE_WIMAX);
- assertEquals(ConnectionType.CONNECTION_4G,
- mReceiver.getCurrentConnectionType());
- assertEquals(Double.POSITIVE_INFINITY, mReceiver.getCurrentMaxBandwidthInMbps());
+ assertEquals(ConnectionType.CONNECTION_4G, getCurrentConnectionType());
+ assertEquals(Double.POSITIVE_INFINITY, getCurrentMaxBandwidthInMbps());
}
@UiThreadTest
@@ -169,9 +211,8 @@ public class NetworkChangeNotifierTest extends InstrumentationTestCase {
public void testNetworkChangeNotifierMaxBandwidthBluetooth() throws InterruptedException {
// Show that for bluetooth the link speed is unknown (+Infinity).
mConnectivityDelegate.setNetworkType(ConnectivityManager.TYPE_BLUETOOTH);
- assertEquals(ConnectionType.CONNECTION_BLUETOOTH,
- mReceiver.getCurrentConnectionType());
- assertEquals(Double.POSITIVE_INFINITY, mReceiver.getCurrentMaxBandwidthInMbps());
+ assertEquals(ConnectionType.CONNECTION_BLUETOOTH, getCurrentConnectionType());
+ assertEquals(Double.POSITIVE_INFINITY, getCurrentMaxBandwidthInMbps());
}
@UiThreadTest
@@ -181,8 +222,8 @@ public class NetworkChangeNotifierTest extends InstrumentationTestCase {
// Test that for mobile types the subtype is used to determine the maxBandwidth.
mConnectivityDelegate.setNetworkType(ConnectivityManager.TYPE_MOBILE);
mConnectivityDelegate.setNetworkSubtype(TelephonyManager.NETWORK_TYPE_LTE);
- assertEquals(ConnectionType.CONNECTION_4G, mReceiver.getCurrentConnectionType());
- assertEquals(100.0, mReceiver.getCurrentMaxBandwidthInMbps());
+ assertEquals(ConnectionType.CONNECTION_4G, getCurrentConnectionType());
+ assertEquals(100.0, getCurrentMaxBandwidthInMbps());
}
/**