-
-
Notifications
You must be signed in to change notification settings - Fork 8.5k
[dotnet] [bidi] Support WebExtension module #15850
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
Open
nvborisenko
wants to merge
11
commits into
SeleniumHQ:trunk
Choose a base branch
from
nvborisenko:bidi-webextension
base: trunk
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+304
−0
Open
Changes from all commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
b8cb6c2
Install
nvborisenko 9bb7c20
Install coommand
nvborisenko 3bb1ab6
Install command
nvborisenko 3a78096
Tests
nvborisenko 80801a5
Uninstall
nvborisenko 73e12f5
Ignore tests
nvborisenko a1d3998
Merge remote-tracking branch 'upstream/trunk' into bidi-webextension
nvborisenko 2548b02
Merge remote-tracking branch 'upstream/trunk' into bidi-webextension
nvborisenko c0c27d3
Test data in bazel
nvborisenko 393e414
Works on remote?
nvborisenko d040dae
Support test data in bazel
nvborisenko File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
47 changes: 47 additions & 0 deletions
47
dotnet/src/webdriver/BiDi/Communication/Json/Converters/WebExtensionConverter.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
// <copyright file="WebExtensionConverter.cs" company="Selenium Committers"> | ||
// 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. | ||
// </copyright> | ||
|
||
using OpenQA.Selenium.BiDi.WebExtension; | ||
using System; | ||
using System.Text.Json; | ||
using System.Text.Json.Serialization; | ||
|
||
namespace OpenQA.Selenium.BiDi.Communication.Json.Converters; | ||
|
||
internal class WebExtensionConverter : JsonConverter<Extension> | ||
{ | ||
private readonly BiDi _bidi; | ||
|
||
public WebExtensionConverter(BiDi bidi) | ||
{ | ||
_bidi = bidi; | ||
} | ||
|
||
public override Extension? Read(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options) | ||
{ | ||
var id = reader.GetString(); | ||
|
||
return new Extension(_bidi, id!); | ||
} | ||
|
||
public override void Write(Utf8JsonWriter writer, Extension value, JsonSerializerOptions options) | ||
{ | ||
writer.WriteStringValue(value.Id); | ||
} | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
// <copyright file="Extension.cs" company="Selenium Committers"> | ||
// 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. | ||
// </copyright> | ||
|
||
using System.Threading.Tasks; | ||
|
||
namespace OpenQA.Selenium.BiDi.WebExtension; | ||
|
||
public class Extension | ||
{ | ||
private readonly BiDi _bidi; | ||
|
||
public Extension(BiDi bidi, string id) | ||
{ | ||
_bidi = bidi; | ||
Id = id; | ||
} | ||
|
||
internal string Id { get; } | ||
|
||
public Task UninstallAsync(UninstallOptions? options = null) | ||
{ | ||
return _bidi.WebExtension.UninstallAsync(this, options); | ||
} | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
// <copyright file="InstallCommand.cs" company="Selenium Committers"> | ||
// 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. | ||
// </copyright> | ||
|
||
using OpenQA.Selenium.BiDi.Communication; | ||
using System.Text.Json.Serialization; | ||
|
||
namespace OpenQA.Selenium.BiDi.WebExtension; | ||
|
||
internal class InstallCommand(InstallCommandParameters @params) | ||
: Command<InstallCommandParameters, InstallResult>(@params, "webExtension.install"); | ||
|
||
internal record InstallCommandParameters(ExtensionData ExtensionData) : CommandParameters; | ||
|
||
[JsonPolymorphic(TypeDiscriminatorPropertyName = "type")] | ||
[JsonDerivedType(typeof(ExtensionArchivePath), "archivePath")] | ||
[JsonDerivedType(typeof(ExtensionBase64Encoded), "base64")] | ||
[JsonDerivedType(typeof(ExtensionPath), "path")] | ||
public abstract record ExtensionData; | ||
|
||
public record ExtensionArchivePath(string Path) : ExtensionData; | ||
|
||
public record ExtensionBase64Encoded(string Value) : ExtensionData; | ||
|
||
public record ExtensionPath(string Path) : ExtensionData; | ||
|
||
public record InstallOptions : CommandOptions; | ||
|
||
public record InstallResult(Extension Extension) : EmptyResult; |
29 changes: 29 additions & 0 deletions
29
dotnet/src/webdriver/BiDi/WebExtension/UninstallCommand.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
// <copyright file="UninstallCommand.cs" company="Selenium Committers"> | ||
// 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. | ||
// </copyright> | ||
|
||
using OpenQA.Selenium.BiDi.Communication; | ||
|
||
namespace OpenQA.Selenium.BiDi.WebExtension; | ||
|
||
internal class UninstallCommand(UninstallCommandParameters @params) | ||
: Command<UninstallCommandParameters, EmptyResult>(@params, "webExtension.uninstall"); | ||
|
||
internal record UninstallCommandParameters(Extension Extension) : CommandParameters; | ||
|
||
public record UninstallOptions : CommandOptions; |
40 changes: 40 additions & 0 deletions
40
dotnet/src/webdriver/BiDi/WebExtension/WebExtensionModule.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
// <copyright file="WebExtensionModule.cs" company="Selenium Committers"> | ||
// 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. | ||
// </copyright> | ||
|
||
using OpenQA.Selenium.BiDi.Communication; | ||
using System.Threading.Tasks; | ||
|
||
namespace OpenQA.Selenium.BiDi.WebExtension; | ||
|
||
public sealed class WebExtensionModule(Broker broker) : Module(broker) | ||
{ | ||
public async Task<InstallResult> InstallAsync(ExtensionData extensionData, InstallOptions? options = null) | ||
{ | ||
var @params = new InstallCommandParameters(extensionData); | ||
|
||
return await Broker.ExecuteCommandAsync<InstallCommand, InstallResult>(new InstallCommand(@params), options).ConfigureAwait(false); | ||
} | ||
|
||
internal async Task UninstallAsync(Extension extension, UninstallOptions? options = null) | ||
{ | ||
var @params = new UninstallCommandParameters(extension); | ||
|
||
await Broker.ExecuteCommandAsync(new UninstallCommand(@params), options).ConfigureAwait(false); | ||
} | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,90 @@ | ||
// <copyright file="WebExtensionTest.cs" company="Selenium Committers"> | ||
// 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. | ||
// </copyright> | ||
|
||
using NUnit.Framework; | ||
using System; | ||
using System.IO; | ||
using System.Threading.Tasks; | ||
|
||
namespace OpenQA.Selenium.BiDi.WebExtension; | ||
|
||
class WebExtensionTest : BiDiTestFixture | ||
{ | ||
[Test] | ||
[IgnoreBrowser(Selenium.Browser.Chrome, "Web extensions are not supported yet?")] | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Try to support it according #15850 (comment) |
||
[IgnoreBrowser(Selenium.Browser.Edge, "Web extensions are not supported yet?")] | ||
public async Task CanInstallPathWebExtension() | ||
{ | ||
string path = Path.GetFullPath("common/extensions/webextensions-selenium-example"); | ||
|
||
var result = await bidi.WebExtension.InstallAsync(new ExtensionPath(path)); | ||
|
||
Assert.That(result, Is.Not.Null); | ||
} | ||
|
||
[Test] | ||
[IgnoreBrowser(Selenium.Browser.Chrome, "Web extensions are not supported yet?")] | ||
[IgnoreBrowser(Selenium.Browser.Edge, "Web extensions are not supported yet?")] | ||
public async Task CanInstallArchiveWebExtension() | ||
{ | ||
string path = LocateRelativePath("common/extensions/webextensions-selenium-example.zip"); | ||
|
||
var result = await bidi.WebExtension.InstallAsync(new ExtensionArchivePath(path)); | ||
|
||
Assert.That(result, Is.Not.Null); | ||
} | ||
|
||
[Test] | ||
[IgnoreBrowser(Selenium.Browser.Chrome, "Web extensions are not supported yet?")] | ||
[IgnoreBrowser(Selenium.Browser.Edge, "Web extensions are not supported yet?")] | ||
public async Task CanInstallBase64WebExtension() | ||
{ | ||
var path = LocateRelativePath("common/extensions/webextensions-selenium-example.zip"); | ||
|
||
string base64 = Convert.ToBase64String(File.ReadAllBytes(path)); | ||
|
||
var result = await bidi.WebExtension.InstallAsync(new ExtensionBase64Encoded(base64)); | ||
|
||
Assert.That(result, Is.Not.Null); | ||
} | ||
|
||
[Test] | ||
[IgnoreBrowser(Selenium.Browser.Chrome, "Web extensions are not supported yet?")] | ||
[IgnoreBrowser(Selenium.Browser.Edge, "Web extensions are not supported yet?")] | ||
public async Task CanUninstallExtension() | ||
{ | ||
string path = LocateRelativePath("common/extensions/webextensions-selenium-example"); | ||
|
||
var result = await bidi.WebExtension.InstallAsync(new ExtensionPath(path)); | ||
|
||
await result.Extension.UninstallAsync(); | ||
} | ||
|
||
private string LocateRelativePath(string path) | ||
{ | ||
try | ||
{ | ||
return Bazel.Runfiles.Create().Rlocation($"_main/{path}"); | ||
} | ||
catch (FileNotFoundException) | ||
{ | ||
return Path.GetFullPath(path); | ||
} | ||
} | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Don't forget to seal everything.