OLD | NEW |
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 static android.net.NetworkCapabilities.NET_CAPABILITY_INTERNET; | 7 import static android.net.NetworkCapabilities.NET_CAPABILITY_INTERNET; |
8 import static android.net.NetworkCapabilities.TRANSPORT_CELLULAR; | 8 import static android.net.NetworkCapabilities.TRANSPORT_CELLULAR; |
9 import static android.net.NetworkCapabilities.TRANSPORT_VPN; | 9 import static android.net.NetworkCapabilities.TRANSPORT_VPN; |
10 import static android.net.NetworkCapabilities.TRANSPORT_WIFI; | 10 import static android.net.NetworkCapabilities.TRANSPORT_WIFI; |
(...skipping 574 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
585 | 585 |
586 /** | 586 /** |
587 * Tests that when Chrome gets an intent indicating a change in network conn
ectivity, it sends a | 587 * Tests that when Chrome gets an intent indicating a change in network conn
ectivity, it sends a |
588 * notification to Java observers. | 588 * notification to Java observers. |
589 */ | 589 */ |
590 @Test | 590 @Test |
591 @UiThreadTest | 591 @UiThreadTest |
592 @MediumTest | 592 @MediumTest |
593 @Feature({"Android-AppBase"}) | 593 @Feature({"Android-AppBase"}) |
594 public void testNetworkChangeNotifierJavaObservers() { | 594 public void testNetworkChangeNotifierJavaObservers() { |
| 595 mReceiver.register(); |
595 // Initialize the NetworkChangeNotifier with a connection. | 596 // Initialize the NetworkChangeNotifier with a connection. |
596 Intent connectivityIntent = new Intent(ConnectivityManager.CONNECTIVITY_
ACTION); | 597 Intent connectivityIntent = new Intent(ConnectivityManager.CONNECTIVITY_
ACTION); |
597 mReceiver.onReceive(InstrumentationRegistry.getInstrumentation().getTarg
etContext(), | 598 mReceiver.onReceive(InstrumentationRegistry.getInstrumentation().getTarg
etContext(), |
598 connectivityIntent); | 599 connectivityIntent); |
599 | 600 |
600 // We shouldn't be re-notified if the connection hasn't actually changed
. | 601 // We shouldn't be re-notified if the connection hasn't actually changed
. |
601 NetworkChangeNotifierTestObserver observer = new NetworkChangeNotifierTe
stObserver(); | 602 NetworkChangeNotifierTestObserver observer = new NetworkChangeNotifierTe
stObserver(); |
602 NetworkChangeNotifier.addConnectionTypeObserver(observer); | 603 NetworkChangeNotifier.addConnectionTypeObserver(observer); |
603 mReceiver.onReceive(InstrumentationRegistry.getInstrumentation().getTarg
etContext(), | 604 mReceiver.onReceive(InstrumentationRegistry.getInstrumentation().getTarg
etContext(), |
604 connectivityIntent); | 605 connectivityIntent); |
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
650 | 651 |
651 /** | 652 /** |
652 * Tests that when Chrome gets an intent indicating a change in max bandwidt
h, it sends a | 653 * Tests that when Chrome gets an intent indicating a change in max bandwidt
h, it sends a |
653 * notification to Java observers. | 654 * notification to Java observers. |
654 */ | 655 */ |
655 @Test | 656 @Test |
656 @UiThreadTest | 657 @UiThreadTest |
657 @MediumTest | 658 @MediumTest |
658 @Feature({"Android-AppBase"}) | 659 @Feature({"Android-AppBase"}) |
659 public void testNetworkChangeNotifierMaxBandwidthNotifications() { | 660 public void testNetworkChangeNotifierMaxBandwidthNotifications() { |
| 661 mReceiver.register(); |
660 // Initialize the NetworkChangeNotifier with a connection. | 662 // Initialize the NetworkChangeNotifier with a connection. |
661 mConnectivityDelegate.setActiveNetworkExists(true); | 663 mConnectivityDelegate.setActiveNetworkExists(true); |
662 mConnectivityDelegate.setNetworkType(ConnectivityManager.TYPE_WIFI); | 664 mConnectivityDelegate.setNetworkType(ConnectivityManager.TYPE_WIFI); |
663 Intent connectivityIntent = new Intent(ConnectivityManager.CONNECTIVITY_
ACTION); | 665 Intent connectivityIntent = new Intent(ConnectivityManager.CONNECTIVITY_
ACTION); |
664 mReceiver.onReceive(InstrumentationRegistry.getInstrumentation().getTarg
etContext(), | 666 mReceiver.onReceive(InstrumentationRegistry.getInstrumentation().getTarg
etContext(), |
665 connectivityIntent); | 667 connectivityIntent); |
666 Assert.assertTrue(mNotifier.hasReceivedMaxBandwidthNotification()); | 668 Assert.assertTrue(mNotifier.hasReceivedMaxBandwidthNotification()); |
667 mNotifier.resetHasReceivedMaxBandwidthNotification(); | 669 mNotifier.resetHasReceivedMaxBandwidthNotification(); |
668 | 670 |
669 // We shouldn't be re-notified if the connection hasn't actually changed
. | 671 // We shouldn't be re-notified if the connection hasn't actually changed
. |
(...skipping 276 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
946 } | 948 } |
947 | 949 |
948 /** | 950 /** |
949 * Tests that isOnline() returns the correct result. | 951 * Tests that isOnline() returns the correct result. |
950 */ | 952 */ |
951 @Test | 953 @Test |
952 @UiThreadTest | 954 @UiThreadTest |
953 @MediumTest | 955 @MediumTest |
954 @Feature({"Android-AppBase"}) | 956 @Feature({"Android-AppBase"}) |
955 public void testNetworkChangeNotifierIsOnline() { | 957 public void testNetworkChangeNotifierIsOnline() { |
| 958 mReceiver.register(); |
956 Intent intent = new Intent(ConnectivityManager.CONNECTIVITY_ACTION); | 959 Intent intent = new Intent(ConnectivityManager.CONNECTIVITY_ACTION); |
957 // For any connection type it should return true. | 960 // For any connection type it should return true. |
958 for (int i = ConnectivityManager.TYPE_MOBILE; i < ConnectivityManager.TY
PE_VPN; i++) { | 961 for (int i = ConnectivityManager.TYPE_MOBILE; i < ConnectivityManager.TY
PE_VPN; i++) { |
959 mConnectivityDelegate.setActiveNetworkExists(true); | 962 mConnectivityDelegate.setActiveNetworkExists(true); |
960 mConnectivityDelegate.setNetworkType(i); | 963 mConnectivityDelegate.setNetworkType(i); |
961 mReceiver.onReceive( | 964 mReceiver.onReceive( |
962 InstrumentationRegistry.getInstrumentation().getTargetContex
t(), intent); | 965 InstrumentationRegistry.getInstrumentation().getTargetContex
t(), intent); |
963 Assert.assertTrue(NetworkChangeNotifier.isOnline()); | 966 Assert.assertTrue(NetworkChangeNotifier.isOnline()); |
964 } | 967 } |
965 mConnectivityDelegate.setActiveNetworkExists(false); | 968 mConnectivityDelegate.setActiveNetworkExists(false); |
966 mReceiver.onReceive( | 969 mReceiver.onReceive( |
967 InstrumentationRegistry.getInstrumentation().getTargetContext(),
intent); | 970 InstrumentationRegistry.getInstrumentation().getTargetContext(),
intent); |
968 Assert.assertFalse(NetworkChangeNotifier.isOnline()); | 971 Assert.assertFalse(NetworkChangeNotifier.isOnline()); |
969 } | 972 } |
970 } | 973 } |
OLD | NEW |