Skip to content

Commit 300896c

Browse files
committed
Add Input Action tests to validate the change
It's tested against all background behavior settings.
1 parent 6157498 commit 300896c

File tree

1 file changed

+49
-0
lines changed

1 file changed

+49
-0
lines changed

Assets/Tests/InputSystem/CoreTests_Actions.cs

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -642,6 +642,55 @@ public void Actions_DoNotGetTriggeredByEditorUpdates()
642642
}
643643
}
644644

645+
[Test]
646+
[Category("Actions")]
647+
[Description("Tests that that only the latest event after focus is regained is able to trigger the action." +
648+
"Depends on background behavior. ")]
649+
[TestCase(InputSettings.BackgroundBehavior.IgnoreFocus)]
650+
[TestCase(InputSettings.BackgroundBehavior.ResetAndDisableNonBackgroundDevices)]
651+
[TestCase(InputSettings.BackgroundBehavior.ResetAndDisableAllDevices)]
652+
public void Actions_DoNotGetTriggeredByOutOfFocusEventInEditor(InputSettings.BackgroundBehavior backgroundBehavior)
653+
{
654+
InputSystem.settings.backgroundBehavior = backgroundBehavior;
655+
656+
var mouse = InputSystem.AddDevice<Mouse>();
657+
var mousePointAction = new InputAction(binding: "<Mouse>/position", type: InputActionType.PassThrough);
658+
mousePointAction.Enable();
659+
660+
using (var trace = new InputActionTrace(mousePointAction))
661+
{
662+
currentTime += 1.0f;
663+
runtime.PlayerFocusLost();
664+
currentTime += 1.0f;
665+
// Queuing an event like it would be in the editor when the GameView is out of focus.
666+
Set(mouse.position, new Vector2(0.234f, 0.345f) , queueEventOnly: true);
667+
currentTime += 1.0f;
668+
// Gaining focus like it would happen in the editor when the GameView regains focus.
669+
runtime.PlayerFocusGained();
670+
currentTime += 1.0f;
671+
// This emulates a device sync that happens when the player regains focus through an IOCTL command.
672+
// That's why it also has it's time incremented.
673+
Set(mouse.position, new Vector2(1.0f, 2.0f), queueEventOnly: true);
674+
currentTime += 1.0f;
675+
// This update should not trigger any ction as it's an editor update.
676+
InputSystem.Update(InputUpdateType.Editor);
677+
currentTime += 1.0f;
678+
679+
var actions = trace.ToArray();
680+
Assert.That(actions, Has.Length.EqualTo(0));
681+
// This update should trigger an action with regards to the event queued after focus was regained.
682+
// The one queued while out of focus should have been ignored and we should expect only one action triggered.
683+
// Unless background behavior is set to IgnoreFocus in which case both events should trigger the action.
684+
InputSystem.Update(InputUpdateType.Dynamic);
685+
686+
actions = trace.ToArray();
687+
Assert.That(actions, Has.Length.EqualTo(backgroundBehavior == InputSettings.BackgroundBehavior.IgnoreFocus ? 2 : 1));
688+
Assert.That(actions[0].phase, Is.EqualTo(InputActionPhase.Performed));
689+
Vector2Control control = (Vector2Control)actions[0].control;
690+
Assert.That(control.value, Is.EqualTo(new Vector2(1.0f, 2.0f)).Using(Vector2EqualityComparer.Instance));
691+
}
692+
}
693+
645694
[Test]
646695
[Category("Actions")]
647696
public void Actions_TimeoutsDoNotGetTriggeredInEditorUpdates()

0 commit comments

Comments
 (0)