forked from react-native-webview/react-native-webview
-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathRNCWebChromeClientTest.java
More file actions
68 lines (52 loc) · 2.23 KB
/
Copy pathRNCWebChromeClientTest.java
File metadata and controls
68 lines (52 loc) · 2.23 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
package com.reactnativecommunity.webview;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.never;
import static org.mockito.Mockito.times;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;
import android.webkit.PermissionRequest;
import org.junit.Test;
/**
* Unit tests for {@link RNCWebChromeClient#onPermissionRequest(PermissionRequest)} covering the
* Android enforcement of the {@code mediaCapturePermissionGrantType="deny"} prop.
*/
public class RNCWebChromeClientTest {
private RNCWebChromeClient createClient() {
RNCWebView webView = mock(RNCWebView.class);
return new RNCWebChromeClient(webView);
}
@Test
public void denyShortCircuitsPermissionRequest() {
RNCWebChromeClient client = createClient();
client.setMediaCapturePermissionGrantType("deny");
PermissionRequest request = mock(PermissionRequest.class);
client.onPermissionRequest(request);
// The request is denied immediately...
verify(request, times(1)).deny();
// ...and never reaches the resource-mapping / OS-permission / AlertDialog path,
// which always starts by reading the requested resources.
verify(request, never()).getResources();
verify(request, never()).grant(org.mockito.ArgumentMatchers.any());
}
@Test
public void nullGrantTypePreservesExistingPromptFlow() {
RNCWebChromeClient client = createClient();
// No grant type configured (default behavior).
PermissionRequest request = mock(PermissionRequest.class);
when(request.getResources()).thenReturn(new String[] {});
client.onPermissionRequest(request);
// It does NOT take the deny short-circuit: the existing flow always inspects
// the requested resources first.
verify(request, times(1)).getResources();
}
@Test
public void unknownGrantTypePreservesExistingPromptFlow() {
RNCWebChromeClient client = createClient();
// An unsupported value must preserve existing prompt behavior, not deny.
client.setMediaCapturePermissionGrantType("grant");
PermissionRequest request = mock(PermissionRequest.class);
when(request.getResources()).thenReturn(new String[] {});
client.onPermissionRequest(request);
verify(request, times(1)).getResources();
}
}