Skip to content

[java][BiDi] implement web extensions #15660

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 6 commits into
base: trunk
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions java/src/org/openqa/selenium/bidi/module/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ java_library(
"//java/src/org/openqa/selenium/bidi/permissions",
"//java/src/org/openqa/selenium/bidi/script",
"//java/src/org/openqa/selenium/bidi/storage",
"//java/src/org/openqa/selenium/bidi/webextension",
"//java/src/org/openqa/selenium/json",
"//java/src/org/openqa/selenium/remote/http",
artifact("com.google.auto.service:auto-service-annotations"),
Expand Down
25 changes: 25 additions & 0 deletions java/src/org/openqa/selenium/bidi/webextension/BUILD.bazel
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
load("@rules_jvm_external//:defs.bzl", "artifact")
load("//java:defs.bzl", "java_library")

java_library(
name = "webextension",
srcs = glob(
[
"*.java",
],
),
visibility = [
"//java/src/org/openqa/selenium/bidi:__subpackages__",
"//java/src/org/openqa/selenium/firefox:__subpackages__",
"//java/src/org/openqa/selenium/remote:__pkg__",
"//java/test/org/openqa/selenium/bidi:__subpackages__",
"//java/test/org/openqa/selenium/grid:__subpackages__",
],
deps = [
"//java/src/org/openqa/selenium:core",
"//java/src/org/openqa/selenium/bidi",
"//java/src/org/openqa/selenium/json",
"//java/src/org/openqa/selenium/remote/http",
artifact("com.google.auto.service:auto-service-annotations"),
],
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
// Licensed to the Software Freedom Conservancy (SFC) under one
// or more contributor license agreements. See the NOTICE file
// distributed with this work for additional information
// regarding copyright ownership. The SFC licenses this file
// to you under the Apache License, Version 2.0 (the
// "License"); you may not use this file except in compliance
// with the License. You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing,
// software distributed under the License is distributed on an
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
// KIND, either express or implied. See the License for the
// specific language governing permissions and limitations
// under the License.

package org.openqa.selenium.bidi.webextension;

import java.util.Map;

public class ExtensionArchivePath extends ExtensionData {
private final String path;

public ExtensionArchivePath(String path) {
this.path = path;
}

@Override
public Map<String, Object> toMap() {
String type = "archivePath";
return Map.of("extensionData", Map.of("type", type, "path", path));
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
// Licensed to the Software Freedom Conservancy (SFC) under one
// or more contributor license agreements. See the NOTICE file
// distributed with this work for additional information
// regarding copyright ownership. The SFC licenses this file
// to you under the Apache License, Version 2.0 (the
// "License"); you may not use this file except in compliance
// with the License. You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing,
// software distributed under the License is distributed on an
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
// KIND, either express or implied. See the License for the
// specific language governing permissions and limitations
// under the License.

package org.openqa.selenium.bidi.webextension;

import java.util.Map;

public class ExtensionBase64Encoded extends ExtensionData {
private final String value;

public ExtensionBase64Encoded(String value) {
this.value = value;
}

@Override
public Map<String, Object> toMap() {
String type = "base64";
return Map.of("extensionData", Map.of("type", type, "value", value));
}
}
24 changes: 24 additions & 0 deletions java/src/org/openqa/selenium/bidi/webextension/ExtensionData.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
// Licensed to the Software Freedom Conservancy (SFC) under one
// or more contributor license agreements. See the NOTICE file
// distributed with this work for additional information
// regarding copyright ownership. The SFC licenses this file
// to you under the Apache License, Version 2.0 (the
// "License"); you may not use this file except in compliance
// with the License. You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing,
// software distributed under the License is distributed on an
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
// KIND, either express or implied. See the License for the
// specific language governing permissions and limitations
// under the License.

package org.openqa.selenium.bidi.webextension;

import java.util.Map;

public abstract class ExtensionData {
public abstract Map<String, Object> toMap();
}
34 changes: 34 additions & 0 deletions java/src/org/openqa/selenium/bidi/webextension/ExtensionPath.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
// Licensed to the Software Freedom Conservancy (SFC) under one
// or more contributor license agreements. See the NOTICE file
// distributed with this work for additional information
// regarding copyright ownership. The SFC licenses this file
// to you under the Apache License, Version 2.0 (the
// "License"); you may not use this file except in compliance
// with the License. You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing,
// software distributed under the License is distributed on an
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
// KIND, either express or implied. See the License for the
// specific language governing permissions and limitations
// under the License.

package org.openqa.selenium.bidi.webextension;

import java.util.Map;

public class ExtensionPath extends ExtensionData {
private final String path;

public ExtensionPath(String path) {
this.path = path;
}

@Override
public Map<String, Object> toMap() {
String type = "path";
return Map.of("extensionData", Map.of("type", type, "path", path));
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
// Licensed to the Software Freedom Conservancy (SFC) under one
// or more contributor license agreements. See the NOTICE file
// distributed with this work for additional information
// regarding copyright ownership. The SFC licenses this file
// to you under the Apache License, Version 2.0 (the
// "License"); you may not use this file except in compliance
// with the License. You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing,
// software distributed under the License is distributed on an
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
// KIND, either express or implied. See the License for the
// specific language governing permissions and limitations
// under the License.

package org.openqa.selenium.bidi.webextension;

public class InstallExtensionParameters {

private final ExtensionData extensionData;

public InstallExtensionParameters(ExtensionData extensionData) {
this.extensionData = extensionData;
}

public ExtensionData getExtensionData() {
return extensionData;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
// Licensed to the Software Freedom Conservancy (SFC) under one
// or more contributor license agreements. See the NOTICE file
// distributed with this work for additional information
// regarding copyright ownership. The SFC licenses this file
// to you under the Apache License, Version 2.0 (the
// "License"); you may not use this file except in compliance
// with the License. You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing,
// software distributed under the License is distributed on an
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
// KIND, either express or implied. See the License for the
// specific language governing permissions and limitations
// under the License.

package org.openqa.selenium.bidi.webextension;

import java.util.Map;

public class UninstallExtensionParameters {

public final Map<String, Object> extension;

public UninstallExtensionParameters(Map<String, Object> extension) {
this.extension = extension;
}
}
50 changes: 50 additions & 0 deletions java/src/org/openqa/selenium/bidi/webextension/WebExtension.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
// Licensed to the Software Freedom Conservancy (SFC) under one
// or more contributor license agreements. See the NOTICE file
// distributed with this work for additional information
// regarding copyright ownership. The SFC licenses this file
// to you under the Apache License, Version 2.0 (the
// "License"); you may not use this file except in compliance
// with the License. You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing,
// software distributed under the License is distributed on an
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
// KIND, either express or implied. See the License for the
// specific language governing permissions and limitations
// under the License.

package org.openqa.selenium.bidi.webextension;

import java.util.Map;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.bidi.BiDi;
import org.openqa.selenium.bidi.Command;
import org.openqa.selenium.bidi.HasBiDi;
import org.openqa.selenium.internal.Require;

public class WebExtension {
private final BiDi bidi;

public WebExtension(WebDriver driver) {
Require.nonNull("WebDriver", driver);

if (!(driver instanceof HasBiDi)) {
throw new IllegalArgumentException("WebDriver instance must support BiDi protocol");
}

this.bidi = ((HasBiDi) driver).getBiDi();
}

public Map<String, Object> Install(InstallExtensionParameters parameters) {
Require.nonNull("Install parameters", parameters);
return bidi.send(
new Command<>("webExtension.install", parameters.getExtensionData().toMap(), Map.class));
}

public Map<String, Object> Uninstall(UninstallExtensionParameters parameters) {
Require.nonNull("Uninstall parameters", parameters);
return bidi.send(new Command<>("webExtension.uninstall", parameters.extension, Map.class));
}
}
1 change: 1 addition & 0 deletions java/src/org/openqa/selenium/remote/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ java_export(
"//java/src/org/openqa/selenium/bidi/permissions",
"//java/src/org/openqa/selenium/bidi/script",
"//java/src/org/openqa/selenium/bidi/storage",
"//java/src/org/openqa/selenium/bidi/webextension",
"//java/src/org/openqa/selenium/devtools",
"//java/src/org/openqa/selenium/devtools:augmenter",
"//java/src/org/openqa/selenium/os",
Expand Down
1 change: 1 addition & 0 deletions java/test/org/openqa/selenium/bidi/input/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ java_selenium_test_suite(
"//java/src/org/openqa/selenium/bidi/network",
"//java/src/org/openqa/selenium/bidi/permissions",
"//java/src/org/openqa/selenium/bidi/script",
"//java/src/org/openqa/selenium/bidi/webextension",
"//java/src/org/openqa/selenium/chrome",
"//java/src/org/openqa/selenium/firefox",
"//java/src/org/openqa/selenium/json",
Expand Down
37 changes: 37 additions & 0 deletions java/test/org/openqa/selenium/bidi/webextension/BUILD.bazel
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
load("@rules_jvm_external//:defs.bzl", "artifact")
load("//java:defs.bzl", "JUNIT5_DEPS", "java_selenium_test_suite")

java_selenium_test_suite(
name = "large-tests",
size = "large",
srcs = glob(["*Test.java"]),
browsers = [
"firefox",
],
tags = [
"selenium-remote",
],
deps = [
"//java/src/org/openqa/selenium/bidi",
"//java/src/org/openqa/selenium/bidi/browsingcontext",
"//java/src/org/openqa/selenium/bidi/log",
"//java/src/org/openqa/selenium/bidi/module",
"//java/src/org/openqa/selenium/bidi/network",
"//java/src/org/openqa/selenium/bidi/script",
"//java/src/org/openqa/selenium/bidi/webextension",
"//java/src/org/openqa/selenium/firefox",
"//java/src/org/openqa/selenium/grid/security",
"//java/src/org/openqa/selenium/json",
"//java/src/org/openqa/selenium/manager",
"//java/src/org/openqa/selenium/remote",
"//java/src/org/openqa/selenium/support",
"//java/test/org/openqa/selenium/build",
"//java/test/org/openqa/selenium/environment",
"//java/test/org/openqa/selenium/testing:annotations",
"//java/test/org/openqa/selenium/testing:test-base",
"//java/test/org/openqa/selenium/testing/drivers",
artifact("com.google.guava:guava"),
artifact("org.junit.jupiter:junit-jupiter-api"),
artifact("org.assertj:assertj-core"),
] + JUNIT5_DEPS,
)
Loading
Loading