Skip to content

Commit c97e8fc

Browse files
committed
SetUserAgent
1 parent 1c957e6 commit c97e8fc

File tree

4 files changed

+49
-2
lines changed

4 files changed

+49
-2
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -172,7 +172,7 @@ namespace OpenQA.Selenium.BiDi.Communication.Json;
172172
[JsonSerializable(typeof(WebExtension.InstallCommand))]
173173
[JsonSerializable(typeof(WebExtension.InstallResult))]
174174
[JsonSerializable(typeof(WebExtension.UninstallCommand))]
175-
176175
[JsonSerializable(typeof(Emulation.SetTimezoneOverrideCommand))]
176+
[JsonSerializable(typeof(Emulation.SetUserAgentOverrideCommand))]
177177

178178
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
@@ -30,4 +30,11 @@ public async Task<EmptyResult> SetTimezoneOverrideAsync(string? timezone, SetTim
3030

3131
return await Broker.ExecuteCommandAsync<SetTimezoneOverrideCommand, EmptyResult>(new SetTimezoneOverrideCommand(@params), options).ConfigureAwait(false);
3232
}
33+
34+
public async Task<EmptyResult> SetUserAgentOverrideAsync(string? userAgent, SetUserAgentOverrideOptions? options = null)
35+
{
36+
var @params = new SetUserAgentOverrideParameters(userAgent, options?.Contexts, options?.UserContexts);
37+
38+
return await Broker.ExecuteCommandAsync<SetUserAgentOverrideCommand, EmptyResult>(new SetUserAgentOverrideCommand(@params), options).ConfigureAwait(false);
39+
}
3340
}
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
// <copyright file="SetUserAgentOverrideCommand.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 OpenQA.Selenium.BiDi.Communication;
22+
23+
namespace OpenQA.Selenium.BiDi.Emulation;
24+
25+
internal sealed class SetUserAgentOverrideCommand(SetUserAgentOverrideParameters @params)
26+
: Command<SetUserAgentOverrideParameters, EmptyResult>(@params, "emulation.setUserAgentOverride");
27+
28+
internal sealed record SetUserAgentOverrideParameters(string? UserAgent, IEnumerable<BrowsingContext.BrowsingContext>? Contexts, IEnumerable<Browser.UserContext>? UserContexts) : Parameters;
29+
30+
public sealed class SetUserAgentOverrideOptions : CommandOptions
31+
{
32+
public IEnumerable<BrowsingContext.BrowsingContext>? Contexts { get; set; }
33+
34+
public IEnumerable<Browser.UserContext>? UserContexts { get; set; }
35+
}

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

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,9 +24,14 @@ namespace OpenQA.Selenium.BiDi.Emulation;
2424
class EmulationTest : BiDiTestFixture
2525
{
2626
[Test]
27-
[IgnoreBrowser(Selenium.Browser.Firefox, "Not supported yet")]
2827
public void CanSetTimezoneOverride()
2928
{
3029
Assert.That(async () => await bidi.Emulation.SetTimezoneOverrideAsync("UTC", new () { Contexts = [context] }), Throws.Nothing);
3130
}
31+
32+
[Test]
33+
public void CanSetUserAgentOverride()
34+
{
35+
Assert.That(async () => await bidi.Emulation.SetUserAgentOverrideAsync("MyUserAgent/1.0", new () { Contexts = [context] }), Throws.Nothing);
36+
}
3237
}

0 commit comments

Comments
 (0)