Skip to content

Commit a5f0038

Browse files
committed
[bidi][java] Add Permissions Module commands
1 parent 04f9e9f commit a5f0038

File tree

8 files changed

+445
-0
lines changed

8 files changed

+445
-0
lines changed

java/src/org/openqa/selenium/bidi/module/BUILD.bazel

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ java_library(
2121
"//java/src/org/openqa/selenium/bidi/browsingcontext",
2222
"//java/src/org/openqa/selenium/bidi/log",
2323
"//java/src/org/openqa/selenium/bidi/network",
24+
"//java/src/org/openqa/selenium/bidi/permissions",
2425
"//java/src/org/openqa/selenium/bidi/script",
2526
"//java/src/org/openqa/selenium/bidi/storage",
2627
"//java/src/org/openqa/selenium/json",
Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
// Licensed to the Software Freedom Conservancy (SFC) under one
2+
// or more contributor license agreements. See the NOTICE file
3+
// distributed with this work for additional information
4+
// regarding copyright ownership. The SFC licenses this file
5+
// to you under the Apache License, Version 2.0 (the
6+
// "License"); you may not use this file except in compliance
7+
// with the License. You may obtain a copy of the License at
8+
//
9+
// http://www.apache.org/licenses/LICENSE-2.0
10+
//
11+
// Unless required by applicable law or agreed to in writing,
12+
// software distributed under the License is distributed on an
13+
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14+
// KIND, either express or implied. See the License for the
15+
// specific language governing permissions and limitations
16+
// under the License.
17+
18+
package org.openqa.selenium.bidi.module;
19+
20+
import org.openqa.selenium.WebDriver;
21+
import org.openqa.selenium.bidi.BiDi;
22+
import org.openqa.selenium.bidi.Command;
23+
import org.openqa.selenium.bidi.HasBiDi;
24+
import org.openqa.selenium.bidi.permissions.PermissionState;
25+
import org.openqa.selenium.internal.Require;
26+
27+
import java.util.HashMap;
28+
import java.util.Map;
29+
30+
public class Permission {
31+
32+
private final BiDi bidi;
33+
34+
public Permission(WebDriver driver) {
35+
Require.nonNull("WebDriver", driver);
36+
37+
if (!(driver instanceof HasBiDi)) {
38+
throw new IllegalArgumentException("WebDriver instance must support BiDi protocol");
39+
}
40+
41+
this.bidi = ((HasBiDi) driver).getBiDi();
42+
}
43+
44+
public void setPermission(Map<String, String> permissionDescriptor, PermissionState state, String origin) {
45+
this.setPermission(permissionDescriptor, state, origin, null);
46+
}
47+
48+
public void setPermission(
49+
Map<String, String> permissionDescriptor, PermissionState state, String origin, String userContext) {
50+
Require.nonNull("Permission descriptor", permissionDescriptor);
51+
Require.nonNull("Permission state", state);
52+
Require.nonNull("Origin", origin);
53+
54+
Map<String, Object> params =
55+
new HashMap<>(
56+
Map.of(
57+
"descriptor", permissionDescriptor,
58+
"state", state.toString(),
59+
"origin", origin));
60+
61+
if (userContext != null) {
62+
params.put("userContext", userContext);
63+
}
64+
65+
this.bidi.send(new Command<>("permissions.setPermission", params));
66+
}
67+
}
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
load("@rules_jvm_external//:defs.bzl", "artifact")
2+
load("//java:defs.bzl", "java_library")
3+
4+
java_library(
5+
name = "permissions",
6+
srcs = glob(
7+
[
8+
"*.java",
9+
],
10+
),
11+
visibility = [
12+
"//java/src/org/openqa/selenium/bidi:__subpackages__",
13+
"//java/src/org/openqa/selenium/firefox:__subpackages__",
14+
"//java/src/org/openqa/selenium/remote:__pkg__",
15+
"//java/test/org/openqa/selenium/bidi:__subpackages__",
16+
"//java/test/org/openqa/selenium/grid:__subpackages__",
17+
],
18+
)
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
// Licensed to the Software Freedom Conservancy (SFC) under one
2+
// or more contributor license agreements. See the NOTICE file
3+
// distributed with this work for additional information
4+
// regarding copyright ownership. The SFC licenses this file
5+
// to you under the Apache License, Version 2.0 (the
6+
// "License"); you may not use this file except in compliance
7+
// with the License. You may obtain a copy of the License at
8+
//
9+
// http://www.apache.org/licenses/LICENSE-2.0
10+
//
11+
// Unless required by applicable law or agreed to in writing,
12+
// software distributed under the License is distributed on an
13+
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14+
// KIND, either express or implied. See the License for the
15+
// specific language governing permissions and limitations
16+
// under the License.
17+
18+
package org.openqa.selenium.bidi.permissions;
19+
20+
public enum PermissionState {
21+
22+
GRANTED("granted"),
23+
DENIED("denied"),
24+
PROMPT("prompt");
25+
26+
private final String state;
27+
28+
PermissionState(String state) {
29+
this.state = state;
30+
}
31+
32+
@Override
33+
public String toString() {
34+
return state;
35+
}
36+
37+
public static PermissionState findByName(String name) {
38+
PermissionState result = null;
39+
for (PermissionState state : values()) {
40+
if (state.toString().equalsIgnoreCase(name)) {
41+
result = state;
42+
break;
43+
}
44+
}
45+
return result;
46+
}
47+
}

java/src/org/openqa/selenium/remote/BUILD.bazel

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ java_export(
3131
"//java/src/org/openqa/selenium/bidi/log",
3232
"//java/src/org/openqa/selenium/bidi/module",
3333
"//java/src/org/openqa/selenium/bidi/network",
34+
"//java/src/org/openqa/selenium/bidi/permissions",
3435
"//java/src/org/openqa/selenium/bidi/script",
3536
"//java/src/org/openqa/selenium/bidi/storage",
3637
"//java/src/org/openqa/selenium/devtools",

java/test/org/openqa/selenium/bidi/input/BUILD.bazel

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ java_selenium_test_suite(
2222
"//java/src/org/openqa/selenium/bidi/log",
2323
"//java/src/org/openqa/selenium/bidi/module",
2424
"//java/src/org/openqa/selenium/bidi/network",
25+
"//java/src/org/openqa/selenium/bidi/permissions",
2526
"//java/src/org/openqa/selenium/bidi/script",
2627
"//java/src/org/openqa/selenium/chrome",
2728
"//java/src/org/openqa/selenium/firefox",
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
load("@rules_jvm_external//:defs.bzl", "artifact")
2+
load("//java:defs.bzl", "JUNIT5_DEPS", "java_selenium_test_suite")
3+
4+
java_selenium_test_suite(
5+
name = "large-tests",
6+
size = "large",
7+
srcs = glob(["*Test.java"]),
8+
browsers = [
9+
"chrome",
10+
"edge",
11+
"firefox",
12+
],
13+
data = [
14+
"//third_party/chrome_ext:backspace.crx",
15+
],
16+
tags = [
17+
"selenium-remote",
18+
],
19+
deps = [
20+
"//java/src/org/openqa/selenium/bidi",
21+
"//java/src/org/openqa/selenium/bidi/browsingcontext",
22+
"//java/src/org/openqa/selenium/bidi/log",
23+
"//java/src/org/openqa/selenium/bidi/module",
24+
"//java/src/org/openqa/selenium/bidi/network",
25+
"//java/src/org/openqa/selenium/bidi/script",
26+
"//java/src/org/openqa/selenium/chrome",
27+
"//java/src/org/openqa/selenium/firefox",
28+
"//java/src/org/openqa/selenium/json",
29+
"//java/src/org/openqa/selenium/remote",
30+
"//java/src/org/openqa/selenium/support",
31+
"//java/test/org/openqa/selenium:helpers",
32+
"//java/test/org/openqa/selenium/build",
33+
"//java/test/org/openqa/selenium/environment",
34+
"//java/test/org/openqa/selenium/testing:annotations",
35+
"//java/test/org/openqa/selenium/testing:test-base",
36+
"//java/test/org/openqa/selenium/testing/drivers",
37+
artifact("org.junit.jupiter:junit-jupiter-api"),
38+
artifact("org.assertj:assertj-core"),
39+
artifact("org.mockito:mockito-core"),
40+
] + JUNIT5_DEPS,
41+
)

0 commit comments

Comments
 (0)