From 23d79bf144c272b9c11cb044082ef85c88834bfd Mon Sep 17 00:00:00 2001 From: Rebecca Silberstein Date: Tue, 2 May 2017 11:22:45 -0700 Subject: [PATCH] WifiManagerTest: test for startLOHS return code Add a test checking the return code value for startLocalOnlyHotspot. This test verifies that the error code supplied by WifiServiceImpl is passed to the caller via the onFailed(reason) callback. Bug: 36760523 Test: frameworks/base/wifi/tests/runtests.sh Change-Id: I37eb788d62df89e0b2a133be4368a375e29e39e3 --- .../src/android/net/wifi/WifiManagerTest.java | 22 ++++++++++++++++--- 1 file changed, 19 insertions(+), 3 deletions(-) diff --git a/wifi/tests/src/android/net/wifi/WifiManagerTest.java b/wifi/tests/src/android/net/wifi/WifiManagerTest.java index 03ef319fa1e03..b34fcdce1b9ac 100644 --- a/wifi/tests/src/android/net/wifi/WifiManagerTest.java +++ b/wifi/tests/src/android/net/wifi/WifiManagerTest.java @@ -22,6 +22,7 @@ import static android.net.wifi.WifiManager.HOTSPOT_STOPPED; import static android.net.wifi.WifiManager.LocalOnlyHotspotCallback.ERROR_GENERIC; import static android.net.wifi.WifiManager.LocalOnlyHotspotCallback.ERROR_INCOMPATIBLE_MODE; import static android.net.wifi.WifiManager.LocalOnlyHotspotCallback.ERROR_NO_CHANNEL; +import static android.net.wifi.WifiManager.LocalOnlyHotspotCallback.ERROR_TETHERING_DISALLOWED; import static android.net.wifi.WifiManager.LocalOnlyHotspotCallback.REQUEST_REGISTERED; import static org.junit.Assert.assertEquals; @@ -464,11 +465,10 @@ public class WifiManagerTest { } /** - * Verify the handler passed in to startLocalOnlyHotspot is correctly used for callbacks when a - * null WifiConfig is returned. + * Verify callback triggered from startLocalOnlyHotspot with an incompatible mode failure. */ @Test - public void testLocalOnlyHotspotCallbackFullOnNullConfig() throws Exception { + public void testLocalOnlyHotspotCallbackFullOnIncompatibleMode() throws Exception { TestLocalOnlyHotspotCallback callback = new TestLocalOnlyHotspotCallback(); when(mWifiService.startLocalOnlyHotspot(any(Messenger.class), any(IBinder.class))) .thenReturn(ERROR_INCOMPATIBLE_MODE); @@ -480,6 +480,22 @@ public class WifiManagerTest { assertEquals(null, callback.mRes); } + /** + * Verify callback triggered from startLocalOnlyHotspot with a tethering disallowed failure. + */ + @Test + public void testLocalOnlyHotspotCallbackFullOnTetheringDisallowed() throws Exception { + TestLocalOnlyHotspotCallback callback = new TestLocalOnlyHotspotCallback(); + when(mWifiService.startLocalOnlyHotspot(any(Messenger.class), any(IBinder.class))) + .thenReturn(ERROR_TETHERING_DISALLOWED); + mWifiManager.startLocalOnlyHotspot(callback, mHandler); + mLooper.dispatchAll(); + assertEquals(ERROR_TETHERING_DISALLOWED, callback.mFailureReason); + assertFalse(callback.mOnStartedCalled); + assertFalse(callback.mOnStoppedCalled); + assertEquals(null, callback.mRes); + } + /** * Verify a SecurityException resulting from an application without necessary permissions will * bubble up through the call to start LocalOnlyHotspot and will not trigger other callbacks.