NetworkChangeNotifierTest.java 文件源码

java
阅读 28 收藏 0 点赞 0 评论 0

项目:chromium-net-for-android 作者:
@UiThreadTest
@MediumTest
@Feature({"Android-AppBase"})
public void testNetworkChangeNotifierMaxBandwidthNotifications() throws InterruptedException {
    // Initialize the NetworkChangeNotifier with a connection.
    mConnectivityDelegate.setActiveNetworkExists(true);
    mConnectivityDelegate.setNetworkType(ConnectivityManager.TYPE_WIFI);
    mWifiDelegate.setLinkSpeedInMbps(1);
    Intent connectivityIntent = new Intent(ConnectivityManager.CONNECTIVITY_ACTION);
    mReceiver.onReceive(getInstrumentation().getTargetContext(), connectivityIntent);
    assertTrue(mNotifier.hasReceivedMaxBandwidthNotification());
    mNotifier.resetHasReceivedMaxBandwidthNotification();

    // We shouldn't be re-notified if the connection hasn't actually changed.
    NetworkChangeNotifierTestObserver observer = new NetworkChangeNotifierTestObserver();
    NetworkChangeNotifier.addConnectionTypeObserver(observer);
    mReceiver.onReceive(getInstrumentation().getTargetContext(), connectivityIntent);
    assertFalse(mNotifier.hasReceivedMaxBandwidthNotification());

    // We should be notified if the bandwidth changed but not the connection type.
    mWifiDelegate.setLinkSpeedInMbps(2);
    mReceiver.onReceive(getInstrumentation().getTargetContext(), connectivityIntent);
    assertTrue(mNotifier.hasReceivedMaxBandwidthNotification());
    mNotifier.resetHasReceivedMaxBandwidthNotification();

    // We should be notified if bandwidth and connection type changed.
    mConnectivityDelegate.setNetworkType(ConnectivityManager.TYPE_ETHERNET);
    mReceiver.onReceive(getInstrumentation().getTargetContext(), connectivityIntent);
    assertTrue(mNotifier.hasReceivedMaxBandwidthNotification());
    mNotifier.resetHasReceivedMaxBandwidthNotification();

    // We should be notified if the connection type changed, but not the bandwidth.
    // Note that TYPE_ETHERNET and TYPE_BLUETOOTH have the same +INFINITY max bandwidth.
    // This test will fail if that changes.
    mConnectivityDelegate.setNetworkType(ConnectivityManager.TYPE_BLUETOOTH);
    mReceiver.onReceive(getInstrumentation().getTargetContext(), connectivityIntent);
    assertTrue(mNotifier.hasReceivedMaxBandwidthNotification());
}
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号