test: remove ambient timing from double-click contracts
This commit is contained in:
parent
3684e7b5e7
commit
c8c764a40e
5 changed files with 151 additions and 40 deletions
|
|
@ -1,6 +1,5 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Threading;
|
||||
using AcDream.UI.Abstractions.Input;
|
||||
using Silk.NET.Input;
|
||||
|
||||
|
|
@ -19,7 +18,7 @@ public class InputDispatcherDoubleClickTests
|
|||
/// Build a dispatcher wired with LMB Press → SelectLeft,
|
||||
/// LMB DoubleClick → SelectDblLeft, and RMB Press → SelectRight.
|
||||
/// </summary>
|
||||
private static (InputDispatcher dispatcher, FakeMouseSource mouse, List<(InputAction, ActivationType)> fired)
|
||||
private static (InputDispatcher dispatcher, FakeMouseSource mouse, ManualTickClock clock, List<(InputAction, ActivationType)> fired)
|
||||
Build()
|
||||
{
|
||||
var kb = new FakeKeyboardSource();
|
||||
|
|
@ -33,11 +32,12 @@ public class InputDispatcherDoubleClickTests
|
|||
bindings.Add(new Binding(lmbChord, InputAction.SelectDblLeft, ActivationType.DoubleClick));
|
||||
bindings.Add(new Binding(rmbChord, InputAction.SelectRight));
|
||||
|
||||
var dispatcher = InputDispatcher.CreateDetached(kb, mouse, bindings);
|
||||
var clock = new ManualTickClock();
|
||||
var dispatcher = InputDispatcher.CreateDetached(kb, mouse, bindings, clock.Read);
|
||||
dispatcher.Attach();
|
||||
var fired = new List<(InputAction, ActivationType)>();
|
||||
dispatcher.Fired += (a, t) => fired.Add((a, t));
|
||||
return (dispatcher, mouse, fired);
|
||||
return (dispatcher, mouse, clock, fired);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
|
@ -47,10 +47,10 @@ public class InputDispatcherDoubleClickTests
|
|||
[Fact]
|
||||
public void SecondClick_WithinThreshold_FiresDoubleClick()
|
||||
{
|
||||
var (_, mouse, fired) = Build();
|
||||
var (_, mouse, clock, fired) = Build();
|
||||
|
||||
mouse.EmitMouseDown(MouseButton.Left, ModifierMask.None);
|
||||
Thread.Sleep(10);
|
||||
clock.Advance(10);
|
||||
mouse.EmitMouseDown(MouseButton.Left, ModifierMask.None);
|
||||
|
||||
// Two SelectLeft Press events (one per click).
|
||||
|
|
@ -67,10 +67,10 @@ public class InputDispatcherDoubleClickTests
|
|||
[Fact]
|
||||
public void SecondClick_BeyondThreshold_DoesNotFireDoubleClick()
|
||||
{
|
||||
var (_, mouse, fired) = Build();
|
||||
var (_, mouse, clock, fired) = Build();
|
||||
|
||||
mouse.EmitMouseDown(MouseButton.Left, ModifierMask.None);
|
||||
Thread.Sleep(600);
|
||||
clock.Advance(600);
|
||||
mouse.EmitMouseDown(MouseButton.Left, ModifierMask.None);
|
||||
|
||||
Assert.Equal(2, fired.FindAll(e => e == (InputAction.SelectLeft, ActivationType.Press)).Count);
|
||||
|
|
@ -83,10 +83,10 @@ public class InputDispatcherDoubleClickTests
|
|||
[Fact]
|
||||
public void DifferentButtons_DoNotFireDoubleClick()
|
||||
{
|
||||
var (_, mouse, fired) = Build();
|
||||
var (_, mouse, clock, fired) = Build();
|
||||
|
||||
mouse.EmitMouseDown(MouseButton.Left, ModifierMask.None);
|
||||
Thread.Sleep(10);
|
||||
clock.Advance(10);
|
||||
mouse.EmitMouseDown(MouseButton.Right, ModifierMask.None);
|
||||
|
||||
Assert.Empty(fired.FindAll(e => e.Item2 == ActivationType.DoubleClick));
|
||||
|
|
@ -100,12 +100,12 @@ public class InputDispatcherDoubleClickTests
|
|||
[Fact]
|
||||
public void ThirdClick_AfterDoubleClick_RequiresFreshPair()
|
||||
{
|
||||
var (_, mouse, fired) = Build();
|
||||
var (_, mouse, clock, fired) = Build();
|
||||
|
||||
mouse.EmitMouseDown(MouseButton.Left, ModifierMask.None); // click 1
|
||||
Thread.Sleep(10);
|
||||
clock.Advance(10);
|
||||
mouse.EmitMouseDown(MouseButton.Left, ModifierMask.None); // click 2 → DoubleClick fires, state reset
|
||||
Thread.Sleep(10);
|
||||
clock.Advance(10);
|
||||
mouse.EmitMouseDown(MouseButton.Left, ModifierMask.None); // click 3 → no DoubleClick (fresh pair started)
|
||||
|
||||
// Three Press events total.
|
||||
|
|
@ -114,4 +114,14 @@ public class InputDispatcherDoubleClickTests
|
|||
// Exactly one DoubleClick (between clicks 1 and 2).
|
||||
Assert.Single(fired.FindAll(e => e == (InputAction.SelectDblLeft, ActivationType.DoubleClick)));
|
||||
}
|
||||
|
||||
private sealed class ManualTickClock
|
||||
{
|
||||
private long _tickCount64;
|
||||
|
||||
public long Read() => _tickCount64;
|
||||
|
||||
public void Advance(long milliseconds) =>
|
||||
_tickCount64 = checked(_tickCount64 + milliseconds);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue