summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorWei Wang <weiwa@google.com>2017-08-18 13:55:33 -0700
committerWei Wang <weiwa@google.com>2017-08-18 16:13:36 -0700
commitbd8bc092b6e2edfae44629390ac653c49047c235 (patch)
tree702d6978c328246208f6f860500114b6831afd0a /tests
parent529bed806618e5232cad35492307796cf1165dac (diff)
Fix Rtt unit tests failures due to permission checks.
Bug: 64819280 Test: wifi unit tests. Change-Id: Ia52b1516f6e09c609bb26709715c7977d07119a1
Diffstat (limited to 'tests')
-rw-r--r--tests/wifitests/src/com/android/server/wifi/RttServiceTest.java22
1 files changed, 22 insertions, 0 deletions
diff --git a/tests/wifitests/src/com/android/server/wifi/RttServiceTest.java b/tests/wifitests/src/com/android/server/wifi/RttServiceTest.java
index b2b40e226..7300cb256 100644
--- a/tests/wifitests/src/com/android/server/wifi/RttServiceTest.java
+++ b/tests/wifitests/src/com/android/server/wifi/RttServiceTest.java
@@ -41,6 +41,7 @@ import android.os.test.TestLooper;
import android.test.suitebuilder.annotation.SmallTest;
import com.android.internal.util.test.BidirectionalAsyncChannel;
+import com.android.server.wifi.util.WifiPermissionsUtil;
import org.junit.After;
import org.junit.Before;
@@ -69,6 +70,8 @@ public class RttServiceTest {
WifiInjector mWifiInjector;
@Mock
IWificond mWificond;
+ @Mock
+ WifiPermissionsUtil mWifiPermissionsUtil;
RttService.RttServiceImpl mRttServiceImpl;
ArgumentCaptor<BroadcastReceiver> mBroadcastReceiverCaptor = ArgumentCaptor
@@ -80,6 +83,9 @@ public class RttServiceTest {
mLooper = new TestLooper();
when(mWifiInjector.makeWificond()).thenReturn(mWificond);
when(mWifiInjector.getWifiNative()).thenReturn(mWifiNative);
+ when(mWifiInjector.getWifiPermissionsUtil()).thenReturn(mWifiPermissionsUtil);
+ when(mWifiPermissionsUtil.checkCallersLocationPermission(any(), anyInt()))
+ .thenReturn(true);
mRttServiceImpl = new RttService.RttServiceImpl(mContext, mLooper.getLooper(),
mWifiInjector);
mRttServiceImpl.startService();
@@ -271,6 +277,22 @@ public class RttServiceTest {
}
/**
+ * Test RTT fails without proper location permission
+ */
+ @Test
+ public void testEnableResponderFailureNoPermission() throws Exception {
+ when(mWifiPermissionsUtil.checkCallersLocationPermission(any(), anyInt()))
+ .thenReturn(false);
+ startWifi();
+ Handler handler = mock(Handler.class);
+ BidirectionalAsyncChannel channel = connectChannel(handler);
+ Message message = sendEnableResponder(channel, handler, CLIENT_KEY1, null);
+ // RTT operations failed without proper permission.
+ assertEquals("expected permission denied, but got " + message.what,
+ RttManager.REASON_PERMISSION_DENIED, message.arg1);
+ }
+
+ /**
* Test RTT ranging with empty RttParams.
*/
@Test