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

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

Issue 2003503003: Add a null check in ConnectivityManagerDelegate.getNetworkState (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Added test Created 4 years, 7 months 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
« no previous file with comments | « net/android/java/src/org/chromium/net/NetworkChangeNotifierAutoDetect.java ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 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
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;
pauljensen 2016/05/21 00:33:03 nit: instead of null, maybe you could use netIdToN
xunjieli 2016/05/23 13:05:54 Done.
697 NetworkState invalidNetworkState = delegate.getNetworkState(invalidNetwo rk);
698 assertFalse(invalidNetworkState.isConnected());
699 assertEquals(-1, invalidNetworkState.getNetworkType());
700 assertEquals(-1, invalidNetworkState.getNetworkSubType());
701
694 if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { 702 if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
695 Network[] networks = delegate.getAllNetworksUnfiltered(); 703 Network[] networks = delegate.getAllNetworksUnfiltered();
696 if (networks.length >= 1) { 704 if (networks.length >= 1) {
697 delegate.getNetworkState(networks[0]); 705 delegate.getNetworkState(networks[0]);
698 } 706 }
699 delegate.getDefaultNetId(); 707 delegate.getDefaultNetId();
700 NetworkCallback networkCallback = new NetworkCallback(); 708 NetworkCallback networkCallback = new NetworkCallback();
701 NetworkRequest networkRequest = new NetworkRequest.Builder().build() ; 709 NetworkRequest networkRequest = new NetworkRequest.Builder().build() ;
702 delegate.registerNetworkCallback(networkRequest, networkCallback); 710 delegate.registerNetworkCallback(networkRequest, networkCallback);
703 delegate.unregisterNetworkCallback(networkCallback); 711 delegate.unregisterNetworkCallback(networkCallback);
(...skipping 216 matching lines...) Expand 10 before | Expand all | Expand 10 after
920 mConnectivityDelegate.setActiveNetworkExists(true); 928 mConnectivityDelegate.setActiveNetworkExists(true);
921 mConnectivityDelegate.setNetworkType(i); 929 mConnectivityDelegate.setNetworkType(i);
922 mReceiver.onReceive(getInstrumentation().getTargetContext(), intent) ; 930 mReceiver.onReceive(getInstrumentation().getTargetContext(), intent) ;
923 assertTrue(NetworkChangeNotifier.isOnline()); 931 assertTrue(NetworkChangeNotifier.isOnline());
924 } 932 }
925 mConnectivityDelegate.setActiveNetworkExists(false); 933 mConnectivityDelegate.setActiveNetworkExists(false);
926 mReceiver.onReceive(getInstrumentation().getTargetContext(), intent); 934 mReceiver.onReceive(getInstrumentation().getTargetContext(), intent);
927 assertFalse(NetworkChangeNotifier.isOnline()); 935 assertFalse(NetworkChangeNotifier.isOnline());
928 } 936 }
929 } 937 }
OLDNEW
« no previous file with comments | « net/android/java/src/org/chromium/net/NetworkChangeNotifierAutoDetect.java ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698