committed by
GitHub
26 changed files with 369 additions and 140 deletions
@ -0,0 +1,30 @@ |
|||
using System; |
|||
using Avalonia.Input; |
|||
|
|||
namespace Avalonia.Platform |
|||
{ |
|||
/// <summary>
|
|||
/// A default implementation of <see cref="IPlatformSettings"/> for platforms which don't have
|
|||
/// an OS-specific implementation.
|
|||
/// </summary>
|
|||
public class DefaultPlatformSettings : IPlatformSettings |
|||
{ |
|||
public Size GetTapSize(PointerType type) |
|||
{ |
|||
return type switch |
|||
{ |
|||
PointerType.Touch => new(10, 10), |
|||
_ => new(4, 4), |
|||
}; |
|||
} |
|||
public Size GetDoubleTapSize(PointerType type) |
|||
{ |
|||
return type switch |
|||
{ |
|||
PointerType.Touch => new(16, 16), |
|||
_ => new(4, 4), |
|||
}; |
|||
} |
|||
public TimeSpan GetDoubleTapTime(PointerType type) => TimeSpan.FromMilliseconds(500); |
|||
} |
|||
} |
|||
@ -1,17 +0,0 @@ |
|||
using System; |
|||
using Avalonia.Platform; |
|||
|
|||
namespace Avalonia.X11 |
|||
{ |
|||
class PlatformSettingsStub : IPlatformSettings |
|||
{ |
|||
public Size DoubleClickSize { get; } = new Size(2, 2); |
|||
public TimeSpan DoubleClickTime { get; } = TimeSpan.FromMilliseconds(500); |
|||
|
|||
/// <inheritdoc cref="IPlatformSettings.TouchDoubleClickSize"/>
|
|||
public Size TouchDoubleClickSize => new Size(16, 16); |
|||
|
|||
/// <inheritdoc cref="IPlatformSettings.TouchDoubleClickTime"/>
|
|||
public TimeSpan TouchDoubleClickTime => DoubleClickTime; |
|||
} |
|||
} |
|||
@ -0,0 +1,175 @@ |
|||
using System; |
|||
using System.Threading; |
|||
using OpenQA.Selenium.Appium; |
|||
using OpenQA.Selenium.Interactions; |
|||
using Xunit; |
|||
|
|||
namespace Avalonia.IntegrationTests.Appium |
|||
{ |
|||
[Collection("Default")] |
|||
public class GestureTests |
|||
{ |
|||
private readonly AppiumDriver<AppiumWebElement> _session; |
|||
|
|||
public GestureTests(TestAppFixture fixture) |
|||
{ |
|||
_session = fixture.Session; |
|||
|
|||
var tabs = _session.FindElementByAccessibilityId("MainTabs"); |
|||
var tab = tabs.FindElementByName("Gestures"); |
|||
tab.Click(); |
|||
var clear = _session.FindElementByAccessibilityId("ResetGestures"); |
|||
clear.Click(); |
|||
} |
|||
|
|||
[Fact] |
|||
public void Tapped_Is_Raised() |
|||
{ |
|||
var border = _session.FindElementByAccessibilityId("GestureBorder"); |
|||
var lastGesture = _session.FindElementByAccessibilityId("LastGesture"); |
|||
|
|||
new Actions(_session).Click(border).Perform(); |
|||
|
|||
Assert.Equal("Tapped", lastGesture.Text); |
|||
} |
|||
|
|||
[Fact] |
|||
public void Tapped_Is_Raised_Slow() |
|||
{ |
|||
var border = _session.FindElementByAccessibilityId("GestureBorder"); |
|||
var lastGesture = _session.FindElementByAccessibilityId("LastGesture"); |
|||
|
|||
new Actions(_session).ClickAndHold(border).Perform(); |
|||
|
|||
Thread.Sleep(2000); |
|||
|
|||
new Actions(_session).Release(border).Perform(); |
|||
|
|||
Assert.Equal("Tapped", lastGesture.Text); |
|||
} |
|||
|
|||
[Fact] |
|||
public void Tapped_Is_Not_Raised_For_Drag() |
|||
{ |
|||
var border = _session.FindElementByAccessibilityId("GestureBorder"); |
|||
var lastGesture = _session.FindElementByAccessibilityId("LastGesture"); |
|||
|
|||
new Actions(_session) |
|||
.ClickAndHold(border) |
|||
.MoveByOffset(50, 50) |
|||
.Release() |
|||
.Perform(); |
|||
|
|||
Assert.Equal(string.Empty, lastGesture.Text); |
|||
} |
|||
|
|||
[Fact] |
|||
public void DoubleTapped_Is_Raised() |
|||
{ |
|||
var border = _session.FindElementByAccessibilityId("GestureBorder"); |
|||
var lastGesture = _session.FindElementByAccessibilityId("LastGesture"); |
|||
|
|||
new Actions(_session).DoubleClick(border).Perform(); |
|||
|
|||
Assert.Equal("DoubleTapped", lastGesture.Text); |
|||
} |
|||
|
|||
[Fact] |
|||
public void DoubleTapped_Is_Raised_2() |
|||
{ |
|||
var border = _session.FindElementByAccessibilityId("GestureBorder"); |
|||
var lastGesture = _session.FindElementByAccessibilityId("LastGesture"); |
|||
|
|||
new Actions(_session).ClickAndHold(border).Release().Perform(); |
|||
|
|||
Thread.Sleep(100); |
|||
|
|||
// DoubleTapped is raised on second pointer press, not release.
|
|||
new Actions(_session).ClickAndHold(border).Perform(); |
|||
|
|||
try |
|||
{ |
|||
Assert.Equal("DoubleTapped", lastGesture.Text); |
|||
} |
|||
finally |
|||
{ |
|||
new Actions(_session).Release(border).Perform(); |
|||
} |
|||
} |
|||
|
|||
[Fact] |
|||
public void DoubleTapped_Is_Raised_Not_Raised_If_Too_Slow() |
|||
{ |
|||
var border = _session.FindElementByAccessibilityId("GestureBorder"); |
|||
var lastGesture = _session.FindElementByAccessibilityId("LastGesture"); |
|||
|
|||
new Actions(_session).ClickAndHold(border).Release().Perform(); |
|||
|
|||
Thread.Sleep(2000); |
|||
|
|||
new Actions(_session).ClickAndHold(border).Release().Perform(); |
|||
|
|||
Assert.Equal("Tapped", lastGesture.Text); |
|||
} |
|||
|
|||
[Fact] |
|||
public void DoubleTapped_Is_Raised_After_Control_Changes() |
|||
{ |
|||
// #8733
|
|||
var border = _session.FindElementByAccessibilityId("GestureBorder"); |
|||
var lastGesture = _session.FindElementByAccessibilityId("LastGesture"); |
|||
|
|||
new Actions(_session) |
|||
.MoveToElement(border) |
|||
.DoubleClick() |
|||
.DoubleClick() |
|||
.Perform(); |
|||
|
|||
Assert.Equal("DoubleTapped2", lastGesture.Text); |
|||
} |
|||
|
|||
[Fact] |
|||
public void RightTapped_Is_Raised() |
|||
{ |
|||
var border = _session.FindElementByAccessibilityId("GestureBorder"); |
|||
var lastGesture = _session.FindElementByAccessibilityId("LastGesture"); |
|||
|
|||
new Actions(_session).ContextClick(border).Perform(); |
|||
|
|||
Assert.Equal("RightTapped", lastGesture.Text); |
|||
} |
|||
|
|||
[PlatformFact(TestPlatforms.MacOS)] |
|||
public void RightTapped_Is_Raised_2() |
|||
{ |
|||
var border = _session.FindElementByAccessibilityId("GestureBorder"); |
|||
var lastGesture = _session.FindElementByAccessibilityId("LastGesture"); |
|||
var device = new PointerInputDevice(PointerKind.Mouse); |
|||
var b = new ActionBuilder(); |
|||
|
|||
b.AddAction(device.CreatePointerMove(border, 50, 50, TimeSpan.FromMilliseconds(100))); |
|||
b.AddAction(device.CreatePointerDown(MouseButton.Right)); |
|||
b.AddAction(device.CreatePointerMove(border, 2, 2, TimeSpan.FromMilliseconds(100))); |
|||
b.AddAction(device.CreatePointerUp(MouseButton.Right)); |
|||
_session.PerformActions(b.ToActionSequenceList()); |
|||
|
|||
Assert.Equal("RightTapped", lastGesture.Text); |
|||
} |
|||
|
|||
[PlatformFact(TestPlatforms.MacOS)] |
|||
public void RightTapped_Is_Not_Raised_For_Drag() |
|||
{ |
|||
var border = _session.FindElementByAccessibilityId("GestureBorder"); |
|||
var lastGesture = _session.FindElementByAccessibilityId("LastGesture"); |
|||
var device = new PointerInputDevice(PointerKind.Mouse); |
|||
var b = new ActionBuilder(); |
|||
|
|||
b.AddAction(device.CreatePointerMove(border, 50, 50, TimeSpan.FromMilliseconds(100))); |
|||
b.AddAction(device.CreatePointerDown(MouseButton.Right)); |
|||
b.AddAction(device.CreatePointerMove(CoordinateOrigin.Pointer, 50, 50, TimeSpan.FromMilliseconds(100))); |
|||
b.AddAction(device.CreatePointerUp(MouseButton.Right)); |
|||
|
|||
Assert.Equal(string.Empty, lastGesture.Text); |
|||
} |
|||
} |
|||
} |
|||
Loading…
Reference in new issue