Chromium Code Reviews| 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 673 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 684 * active network connections so it cannot usefully check results, but it ca n at least check | 684 * active network connections so it cannot usefully check results, but it ca n at least check |
| 685 * that the functions don't crash. | 685 * that the functions don't crash. |
| 686 */ | 686 */ |
| 687 @UiThreadTest | 687 @UiThreadTest |
| 688 @MediumTest | 688 @MediumTest |
| 689 @Feature({"Android-AppBase"}) | 689 @Feature({"Android-AppBase"}) |
| 690 public void testConnectivityManagerDelegateDoesNotCrash() { | 690 public void testConnectivityManagerDelegateDoesNotCrash() { |
| 691 ConnectivityManagerDelegate delegate = | 691 ConnectivityManagerDelegate delegate = |
| 692 new ConnectivityManagerDelegate(getInstrumentation().getTargetCo ntext()); | 692 new ConnectivityManagerDelegate(getInstrumentation().getTargetCo ntext()); |
| 693 delegate.getNetworkState(); | 693 delegate.getNetworkState(); |
| 694 | |
| 695 // getNetworkState doesn't crash upon invalid Network argument. | |
| 696 Network invalidNetwork = null; | |
| 697 if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { | |
| 698 invalidNetwork = netIdToNetwork(NetId.INVALID); | |
|
xunjieli
2016/05/23 16:45:03
Paul, netIdToNetwork uses mNetworkConstructor whic
pauljensen
2016/05/23 17:19:40
is delegate.getNetworkState(Network) callable on p
xunjieli
2016/05/23 17:27:01
Done.
| |
| 699 } | |
| 700 NetworkState invalidNetworkState = delegate.getNetworkState(invalidNetwo rk); | |
| 701 assertFalse(invalidNetworkState.isConnected()); | |
| 702 assertEquals(-1, invalidNetworkState.getNetworkType()); | |
| 703 assertEquals(-1, invalidNetworkState.getNetworkSubType()); | |
| 704 | |
| 694 if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { | 705 if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { |
| 695 Network[] networks = delegate.getAllNetworksUnfiltered(); | 706 Network[] networks = delegate.getAllNetworksUnfiltered(); |
| 696 if (networks.length >= 1) { | 707 if (networks.length >= 1) { |
| 697 delegate.getNetworkState(networks[0]); | 708 delegate.getNetworkState(networks[0]); |
| 698 } | 709 } |
| 699 delegate.getDefaultNetId(); | 710 delegate.getDefaultNetId(); |
| 700 NetworkCallback networkCallback = new NetworkCallback(); | 711 NetworkCallback networkCallback = new NetworkCallback(); |
| 701 NetworkRequest networkRequest = new NetworkRequest.Builder().build() ; | 712 NetworkRequest networkRequest = new NetworkRequest.Builder().build() ; |
| 702 delegate.registerNetworkCallback(networkRequest, networkCallback); | 713 delegate.registerNetworkCallback(networkRequest, networkCallback); |
| 703 delegate.unregisterNetworkCallback(networkCallback); | 714 delegate.unregisterNetworkCallback(networkCallback); |
| (...skipping 216 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 920 mConnectivityDelegate.setActiveNetworkExists(true); | 931 mConnectivityDelegate.setActiveNetworkExists(true); |
| 921 mConnectivityDelegate.setNetworkType(i); | 932 mConnectivityDelegate.setNetworkType(i); |
| 922 mReceiver.onReceive(getInstrumentation().getTargetContext(), intent) ; | 933 mReceiver.onReceive(getInstrumentation().getTargetContext(), intent) ; |
| 923 assertTrue(NetworkChangeNotifier.isOnline()); | 934 assertTrue(NetworkChangeNotifier.isOnline()); |
| 924 } | 935 } |
| 925 mConnectivityDelegate.setActiveNetworkExists(false); | 936 mConnectivityDelegate.setActiveNetworkExists(false); |
| 926 mReceiver.onReceive(getInstrumentation().getTargetContext(), intent); | 937 mReceiver.onReceive(getInstrumentation().getTargetContext(), intent); |
| 927 assertFalse(NetworkChangeNotifier.isOnline()); | 938 assertFalse(NetworkChangeNotifier.isOnline()); |
| 928 } | 939 } |
| 929 } | 940 } |
| OLD | NEW |