Skip to content

Commit a470cbc

Browse files
committed
SetScriptingEnabled
1 parent 1af3dcb commit a470cbc

File tree

4 files changed

+51
-0
lines changed

4 files changed

+51
-0
lines changed

dotnet/src/webdriver/BiDi/Communication/Json/BiDiJsonSerializerContext.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -176,5 +176,6 @@ namespace OpenQA.Selenium.BiDi.Communication.Json;
176176
[JsonSerializable(typeof(Emulation.SetUserAgentOverrideCommand))]
177177
[JsonSerializable(typeof(Emulation.SetLocaleOverrideCommand))]
178178
[JsonSerializable(typeof(Emulation.SetForcedColorsModeThemeOverrideCommand))]
179+
[JsonSerializable(typeof(Emulation.SetScriptingEnabledCommand))]
179180

180181
internal partial class BiDiJsonSerializerContext : JsonSerializerContext;

dotnet/src/webdriver/BiDi/Emulation/EmulationModule.cs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,4 +51,11 @@ public async Task<EmptyResult> SetForcedColorsModeThemeOverrideAsync(ForcedColor
5151

5252
return await Broker.ExecuteCommandAsync<SetForcedColorsModeThemeOverrideCommand, EmptyResult>(new SetForcedColorsModeThemeOverrideCommand(@params), options).ConfigureAwait(false);
5353
}
54+
55+
public async Task<EmptyResult> SetScriptingEnabledAsync(bool? enabled, SetScriptingEnabledOptions? options = null)
56+
{
57+
var @params = new SetScriptingEnabledParameters(enabled, options?.Contexts, options?.UserContexts);
58+
59+
return await Broker.ExecuteCommandAsync<SetScriptingEnabledCommand, EmptyResult>(new SetScriptingEnabledCommand(@params), options).ConfigureAwait(false);
60+
}
5461
}
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
// <copyright file="SetScriptingEnabledCommand.cs" company="Selenium Committers">
2+
// Licensed to the Software Freedom Conservancy (SFC) under one
3+
// or more contributor license agreements. See the NOTICE file
4+
// distributed with this work for additional information
5+
// regarding copyright ownership. The SFC licenses this file
6+
// to you under the Apache License, Version 2.0 (the
7+
// "License"); you may not use this file except in compliance
8+
// with the License. You may obtain a copy of the License at
9+
//
10+
// http://www.apache.org/licenses/LICENSE-2.0
11+
//
12+
// Unless required by applicable law or agreed to in writing,
13+
// software distributed under the License is distributed on an
14+
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15+
// KIND, either express or implied. See the License for the
16+
// specific language governing permissions and limitations
17+
// under the License.
18+
// </copyright>
19+
20+
using System.Collections.Generic;
21+
using System.Text.Json.Serialization;
22+
using OpenQA.Selenium.BiDi.Communication;
23+
24+
namespace OpenQA.Selenium.BiDi.Emulation;
25+
26+
internal sealed class SetScriptingEnabledCommand(SetScriptingEnabledParameters @params)
27+
: Command<SetScriptingEnabledParameters, EmptyResult>(@params, "emulation.setScriptingEnabled");
28+
29+
internal sealed record SetScriptingEnabledParameters([property: JsonIgnore(Condition = JsonIgnoreCondition.Never)] bool? Enabled, IEnumerable<BrowsingContext.BrowsingContext>? Contexts, IEnumerable<Browser.UserContext>? UserContexts) : Parameters;
30+
31+
public sealed class SetScriptingEnabledOptions : CommandOptions
32+
{
33+
public IEnumerable<BrowsingContext.BrowsingContext>? Contexts { get; set; }
34+
35+
public IEnumerable<Browser.UserContext>? UserContexts { get; set; }
36+
}

dotnet/test/common/BiDi/Emulation/EmulationTest.cs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,4 +50,11 @@ public void CanSetForcedColorsModeThemeOverride()
5050
Assert.That(async () => await bidi.Emulation.SetForcedColorsModeThemeOverrideAsync(ForcedColorsModeTheme.Light, new () { Contexts = [context] }), Throws.Nothing);
5151
Assert.That(async () => await bidi.Emulation.SetForcedColorsModeThemeOverrideAsync(null, new () { Contexts = [context] }), Throws.Nothing);
5252
}
53+
54+
[Test]
55+
public void CanSetScriptingEnabled()
56+
{
57+
Assert.That(async () => await bidi.Emulation.SetScriptingEnabledAsync(false, new () { Contexts = [context] }), Throws.Nothing);
58+
Assert.That(async () => await bidi.Emulation.SetScriptingEnabledAsync(null, new () { Contexts = [context] }), Throws.Nothing);
59+
}
5360
}

0 commit comments

Comments
 (0)