Skip to content

Commit 9160cb2

Browse files
authored
[dotnet] [bidi] SetTouchOverride command in Emulation module (#17045)
1 parent 01eb8f0 commit 9160cb2

3 files changed

Lines changed: 72 additions & 0 deletions

File tree

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

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,13 @@ public async Task<SetGeolocationOverrideResult> SetGeolocationPositionErrorOverr
101101
return await ExecuteCommandAsync(new SetGeolocationOverrideCommand(@params), options, _jsonContext.SetGeolocationOverrideCommand, _jsonContext.SetGeolocationOverrideResult, cancellationToken).ConfigureAwait(false);
102102
}
103103

104+
public async Task<SetTouchOverrideResult> SetTouchOverrideAsync(long? maxTouchPoints, SetTouchOverrideOptions? options = null, CancellationToken cancellationToken = default)
105+
{
106+
var @params = new SetTouchOverrideParameters(maxTouchPoints, options?.Contexts, options?.UserContexts);
107+
108+
return await ExecuteCommandAsync(new SetTouchOverrideCommand(@params), options, _jsonContext.SetTouchOverrideCommand, _jsonContext.SetTouchOverrideResult, cancellationToken).ConfigureAwait(false);
109+
}
110+
104111
protected override void Initialize(BiDi bidi, JsonSerializerOptions jsonSerializerOptions)
105112
{
106113
jsonSerializerOptions.Converters.Add(new BrowsingContextConverter(bidi));
@@ -126,5 +133,7 @@ protected override void Initialize(BiDi bidi, JsonSerializerOptions jsonSerializ
126133
[JsonSerializable(typeof(SetScreenSettingsOverrideResult))]
127134
[JsonSerializable(typeof(SetGeolocationOverrideCommand))]
128135
[JsonSerializable(typeof(SetGeolocationOverrideResult))]
136+
[JsonSerializable(typeof(SetTouchOverrideCommand))]
137+
[JsonSerializable(typeof(SetTouchOverrideResult))]
129138

130139
internal partial class EmulationJsonSerializerContext : JsonSerializerContext;
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
// <copyright file="SetTouchOverrideCommand.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+
23+
namespace OpenQA.Selenium.BiDi.Emulation;
24+
25+
internal sealed class SetTouchOverrideCommand(SetTouchOverrideParameters @params)
26+
: Command<SetTouchOverrideParameters, SetTouchOverrideResult>(@params, "emulation.setTouchOverride");
27+
28+
internal sealed record SetTouchOverrideParameters([property: JsonIgnore(Condition = JsonIgnoreCondition.Never)] long? MaxTouchPoints, IEnumerable<BrowsingContext.BrowsingContext>? Contexts, IEnumerable<Browser.UserContext>? UserContexts) : Parameters;
29+
30+
public sealed class SetTouchOverrideOptions : CommandOptions
31+
{
32+
public IEnumerable<BrowsingContext.BrowsingContext>? Contexts { get; set; }
33+
34+
public IEnumerable<Browser.UserContext>? UserContexts { get; set; }
35+
}
36+
37+
public sealed record SetTouchOverrideResult : EmptyResult;

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

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -197,4 +197,30 @@ public void CanSetGeolocationPositionErrorOverride()
197197
},
198198
Throws.Nothing);
199199
}
200+
201+
[Test]
202+
[IgnoreBrowser(Selenium.Browser.Chrome, "Not supported yet?")]
203+
[IgnoreBrowser(Selenium.Browser.Edge, "Not supported yet?")]
204+
[IgnoreBrowser(Selenium.Browser.Firefox, "Not supported yet?")]
205+
public void CanSetTouchOverride()
206+
{
207+
Assert.That(async () =>
208+
{
209+
await bidi.Emulation.SetTouchOverrideAsync(5, new() { Contexts = [context] });
210+
},
211+
Throws.Nothing);
212+
}
213+
214+
[Test]
215+
[IgnoreBrowser(Selenium.Browser.Chrome, "Not supported yet?")]
216+
[IgnoreBrowser(Selenium.Browser.Edge, "Not supported yet?")]
217+
[IgnoreBrowser(Selenium.Browser.Firefox, "Not supported yet?")]
218+
public void CanSetTouchOverrideToDefault()
219+
{
220+
Assert.That(async () =>
221+
{
222+
await bidi.Emulation.SetTouchOverrideAsync(null, new() { Contexts = [context] });
223+
},
224+
Throws.Nothing);
225+
}
200226
}

0 commit comments

Comments
 (0)