Search in sources :

Example 1 with PermissionState

use of com.getcapacitor.PermissionState in project capacitor-radar by radarlabs.

the class PermissionsTest method data.

@Parameters(name = "{index}: " + "gpsLocationPermission? {0}. " + "wifiLocationPermission? {1}. " + "backgroundLocationPermission? {2}")
public static Iterable<Object[]> data() {
    PermissionState[] states = PermissionState.values();
    Object[][] data = new Object[states.length * states.length * states.length][3];
    int i = 0;
    for (PermissionState gpsLocationPermission : states) {
        for (PermissionState wifiLocationPermission : states) {
            for (PermissionState backgroundLocationPermission : states) {
                data[i] = new Object[] { gpsLocationPermission, wifiLocationPermission, backgroundLocationPermission };
                i++;
            }
        }
    }
    return Arrays.asList(data);
}
Also used : PermissionState(com.getcapacitor.PermissionState) JSObject(com.getcapacitor.JSObject) Parameters(org.robolectric.ParameterizedRobolectricTestRunner.Parameters)

Example 2 with PermissionState

use of com.getcapacitor.PermissionState in project capacitor-radar by radarlabs.

the class PermissionsTest method testGetLocationPermissionsStatus.

@Test
public void testGetLocationPermissionsStatus() {
    PluginCall pluginCall = mock(PluginCall.class);
    Map<String, PermissionState> states = new HashMap<>();
    states.put(Manifest.permission.ACCESS_FINE_LOCATION, mGpsLocationPermission);
    states.put(Manifest.permission.ACCESS_COARSE_LOCATION, mWifiLocationPermission);
    states.put(Manifest.permission.ACCESS_BACKGROUND_LOCATION, mBackgroundLocationPermission);
    when(mBridge.getPermissionStates(eq(mPlugin))).thenReturn(states);
    mPlugin.getLocationPermissionsStatus(pluginCall);
    String expectedStatus;
    if (isGranted(mGpsLocationPermission) || isGranted(mWifiLocationPermission)) {
        if (isGranted(mBackgroundLocationPermission)) {
            expectedStatus = "GRANTED_BACKGROUND";
        } else {
            expectedStatus = "GRANTED_FOREGROUND";
        }
    } else if (isDenied(mGpsLocationPermission) || isDenied(mWifiLocationPermission)) {
        expectedStatus = "DENIED";
    } else {
        expectedStatus = "NOT_DETERMINED";
    }
    ArgumentCaptor<JSObject> captor = ArgumentCaptor.forClass(JSObject.class);
    verify(pluginCall).resolve(captor.capture());
    JSObject json = captor.getValue();
    assertNotNull(json);
    String actualStatus = json.getString("status");
    assertEquals(expectedStatus, actualStatus);
}
Also used : PermissionState(com.getcapacitor.PermissionState) HashMap(java.util.HashMap) PluginCall(com.getcapacitor.PluginCall) JSObject(com.getcapacitor.JSObject) Test(org.junit.Test)

Aggregations

JSObject (com.getcapacitor.JSObject)2 PermissionState (com.getcapacitor.PermissionState)2 PluginCall (com.getcapacitor.PluginCall)1 HashMap (java.util.HashMap)1 Test (org.junit.Test)1 Parameters (org.robolectric.ParameterizedRobolectricTestRunner.Parameters)1