-
- Notifications
You must be signed in to change notification settings - Fork 8.6k
[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
Merged
Merged
Changes from 15 commits
Commits
Show all changes
23 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 0c3ed57 Enable some tests
nvborisenko 69fdad9 Deeper asserts
nvborisenko 9443622 Sealed types
nvborisenko c1efb37 Merge remote-tracking branch 'upstream/trunk' into bidi-webextension
nvborisenko e3a623f Merge remote-tracking branch 'upstream/trunk' into bidi-webextension
nvborisenko 8c20eb7 From trunk
nvborisenko 95c3444 Merge branch 'trunk' into bidi-webextension
navin772 db2a825 Remove breaking driver global arguments
nvborisenko 931c3d1 Ignore tests temporaly
nvborisenko ba6bcf7 Clarify chromium
nvborisenko 513eda4 Merge remote-tracking branch 'upstream/trunk' into bidi-webextension
nvborisenko 288a627 Fix command parameters changes
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 sealed 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 sealed class InstallCommand(InstallCommandParameters @params) | ||
| : Command<InstallCommandParameters, InstallResult>(@params, "webExtension.install"); | ||
| | ||
| internal sealed 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 sealed record ExtensionArchivePath(string Path) : ExtensionData; | ||
| | ||
| public sealed record ExtensionBase64Encoded(string Value) : ExtensionData; | ||
| | ||
| public sealed record ExtensionPath(string Path) : ExtensionData; | ||
| | ||
| public sealed record InstallOptions : CommandOptions; | ||
| | ||
| public sealed 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 sealed class UninstallCommand(UninstallCommandParameters @params) | ||
| : Command<UninstallCommandParameters, EmptyResult>(@params, "webExtension.uninstall"); | ||
| | ||
| internal sealed record UninstallCommandParameters(Extension Extension) : CommandParameters; | ||
| | ||
| public sealed 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,89 @@ | ||
| // <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] | ||
| 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); | ||
| Assert.That(result.Extension, Is.Not.Null); | ||
| } | ||
| | ||
| [Test] | ||
| [IgnoreBrowser(Selenium.Browser.Chrome, "Archived and Base64 extensions are not supported?")] | ||
| [IgnoreBrowser(Selenium.Browser.Edge, "Archived and Base64 extensions are not supported?")] | ||
| 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); | ||
| Assert.That(result.Extension, Is.Not.Null); | ||
| } | ||
| | ||
| [Test] | ||
| [IgnoreBrowser(Selenium.Browser.Chrome, "Archived and Base64 extensions are not supported?")] | ||
| [IgnoreBrowser(Selenium.Browser.Edge, "Archived and Base64 extensions are not supported?")] | ||
| 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); | ||
| Assert.That(result.Extension, Is.Not.Null); | ||
| } | ||
| | ||
| [Test] | ||
| 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 static 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
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
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.