Skip to content

Commit

Permalink
CHANGE: Re-enable temporarily disabled tests due to ProjectWide actio…
Browse files Browse the repository at this point in the history
…ns (ISX-1455) (Unity-Technologies#1745)

* re-enable UI testts as they are no longer failing

* remove null entries in the projects preloaded assets

* Update comment on disabling actions in Test after investigation

* Fix assert during binding resolution when binding is active

* Re-enable tests failing due to rebinding issue

* Add a comment for every case we disable project-wide actions in tests

* ProjectWide actions don't require EditorBuildSettings for storage
  • Loading branch information
jamesmcgill authored Sep 11, 2023
1 parent 3a482de commit baec637
Show file tree
Hide file tree
Showing 11 changed files with 87 additions and 75 deletions.
91 changes: 69 additions & 22 deletions Assets/Tests/InputSystem/CoreTests_Actions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -529,7 +529,7 @@ public void Actions_CanTargetSameControlWithMultipleActions()
{
#if UNITY_INPUT_SYSTEM_PROJECT_WIDE_ACTIONS
// Exclude project-wide actions from this test
InputSystem.actions?.Disable();
InputSystem.actions?.Disable(); // Prevent these actions appearing in the `InputActionTrace`
#endif

var gamepad = InputSystem.AddDevice<Gamepad>();
Expand Down Expand Up @@ -1337,6 +1337,59 @@ public unsafe void Actions_CanTriggerBindingResolutionOnAction_FromCallback(bool
Assert.That(action.controls, Is.EquivalentTo(new InputControl[] {gamepad.leftStick, mouse.delta}));
}

// ReSharper disable once ClassNeverInstantiated.Local
private class ConstantFloatTestProcessor : InputProcessor<float>
{
public const float EXPECTED_VALUE = 0.5f;
public override float Process(float value, InputControl control)
{
return EXPECTED_VALUE;
}
}

[Test]
[Category("Actions")]
public void Actions_ActiveBindingsHaveCorrectBindingIndicesAfterBindingResolution()
{
// Attaching a processor to a particular binding is how
// we test that we are correctly referencing the same binding
// from before and after the binding resolution.
// This is a tricky issue to tease out. Testing with just ReadValue(),
// with the control (i.e. mouse.leftButton) or with action callbacks
// could all appear correct because those don't actually use bindingIndex.
// This issue originally manifested itself as an assert in another place in the code.
InputSystem.RegisterProcessor<ConstantFloatTestProcessor>();

// This test is sensitive to binding order.
// It's important that the active binding is not in the first
// position of the action (i.e. not at the default index).
var map = new InputActionMap("map");
var action = map.AddAction("action1", binding: "<Gamepad>/buttonSouth");
action.AddBinding("<Mouse>/leftButton").WithProcessor<ConstantFloatTestProcessor>(); // binding in 2nd position.
map.Enable();

var mouse = InputSystem.AddDevice<Mouse>();
Assert.That(action.activeControl, Is.Null);
Assert.That(action.ReadValue<float>(), Is.EqualTo(0));

// Put the action into an active state using the 2nd binding.
Press(mouse.leftButton);
Assert.That(action.activeControl, Is.SameAs(mouse.leftButton));
Assert.That(action.ReadValue<float>(), Is.EqualTo(ConstantFloatTestProcessor.EXPECTED_VALUE));

// Perform binding resolution while the action is active.
var gamepad = InputSystem.AddDevice<Gamepad>();
Assert.That(action.activeControl, Is.SameAs(mouse.leftButton));

// Check the active control is still triggered by the 2nd binding (with the processor attached).
Assert.That(action.ReadValue<float>(), Is.EqualTo(ConstantFloatTestProcessor.EXPECTED_VALUE));

// Perform binding resolution again.
// This would cause an assert if the binding indices were incorrect
// as the binding resolver would choke on the bad data at this point.
InputSystem.RemoveDevice(gamepad);
}

[Test]
[Category("Actions")]
public void Actions_CanDisableAndEnableOtherAction_FromCallback()
Expand Down Expand Up @@ -2049,7 +2102,7 @@ public void Actions_CanCreateActionAssetWithMultipleActionMaps()
{
#if UNITY_INPUT_SYSTEM_PROJECT_WIDE_ACTIONS
// Exclude project-wide actions from this test
InputSystem.actions?.Disable();
InputSystem.actions?.Disable(); // Prevent these actions appearing in the `InputActionTrace`
#endif

var asset = ScriptableObject.CreateInstance<InputActionAsset>();
Expand Down Expand Up @@ -2303,7 +2356,7 @@ public void Actions_WithMultipleBoundControls_DriveInteractionsFromControlWithGr
{
#if UNITY_INPUT_SYSTEM_PROJECT_WIDE_ACTIONS
// Exclude project-wide actions from this test
InputSystem.actions?.Disable();
InputSystem.actions?.Disable(); // Prevent these actions appearing in the `InputActionTrace`
#endif

var gamepad = InputSystem.AddDevice<Gamepad>();
Expand Down Expand Up @@ -2595,7 +2648,7 @@ public void Actions_WithMultipleBoundControls_CanHandleInteractionsThatTriggerOn
{
#if UNITY_INPUT_SYSTEM_PROJECT_WIDE_ACTIONS
// Exclude project-wide actions from this test
InputSystem.actions?.Disable();
InputSystem.actions?.Disable(); // Prevent these actions appearing in the `InputActionTrace`
#endif

var keyboard = InputSystem.AddDevice<Keyboard>();
Expand Down Expand Up @@ -3120,7 +3173,7 @@ public void Actions_CanRecordAllActionsInTheSystem()
{
#if UNITY_INPUT_SYSTEM_PROJECT_WIDE_ACTIONS
// Exclude project-wide actions from this test
InputSystem.actions?.Disable();
InputSystem.actions?.Disable(); // Prevent these actions appearing in the `InputActionTrace`
#endif

var gamepad = InputSystem.AddDevice<Gamepad>();
Expand Down Expand Up @@ -3568,7 +3621,7 @@ public void Actions_CanQueryAllEnabledActions()
{
#if UNITY_INPUT_SYSTEM_PROJECT_WIDE_ACTIONS
// Exclude project-wide actions from this test
InputSystem.actions?.Disable();
InputSystem.actions?.Disable(); // Remove from `ListEnabledActions`
#endif

var action = new InputAction(binding: "<Gamepad>/leftStick");
Expand Down Expand Up @@ -3816,7 +3869,7 @@ public void Actions_CanHandleModification(Modification modification, IInputActio
#if UNITY_INPUT_SYSTEM_PROJECT_WIDE_ACTIONS
// Exclude project-wide actions from this test
InputSystem.actions?.Disable();
InputActionState.DestroyAllActionMapStates(); // Also remove controls so the changed control count is accurate
InputActionState.DestroyAllActionMapStates(); // Required for `onActionChange` to report correct number of changes
#endif

var gamepad = InputSystem.AddDevice<Gamepad>();
Expand Down Expand Up @@ -4708,7 +4761,7 @@ public void Actions_WhenDeviceIsRemoved_DeviceIsRemovedFromDeviceMask()
#if UNITY_INPUT_SYSTEM_PROJECT_WIDE_ACTIONS
// Exclude project-wide actions from this test
InputSystem.actions?.Disable();
InputActionState.DestroyAllActionMapStates(); // Also remove controls so the changed control count is accurate
InputActionState.DestroyAllActionMapStates(); // Required for `onActionChange` to report correct number of changes
#endif

var gamepad = InputSystem.AddDevice<Gamepad>();
Expand Down Expand Up @@ -4856,8 +4909,8 @@ public void Actions_WhenControlsUpdate_NotificationIsTriggered_ButOnlyAfterBindi
#if UNITY_INPUT_SYSTEM_PROJECT_WIDE_ACTIONS
// Exclude project-wide actions from this test
InputSystem.actions?.Disable();
InputActionState.DestroyAllActionMapStates(); // Also remove controls so the changed control count is accurate
#endif
InputActionState.DestroyAllActionMapStates(); // Required for `onActionChange` to report correct number of changes
#endif

var enabledAction = new InputAction("enabledAction", binding: "<Gamepad>/leftTrigger");

Expand Down Expand Up @@ -4918,7 +4971,7 @@ public void Actions_WhenControlsUpdateInActionMap_NotificationIsTriggered()
#if UNITY_INPUT_SYSTEM_PROJECT_WIDE_ACTIONS
// Exclude project-wide actions from this test
InputSystem.actions?.Disable();
InputActionState.DestroyAllActionMapStates(); // Also remove controls so the changed control count is accurate
InputActionState.DestroyAllActionMapStates(); // Required for `onActionChange` to report correct number of changes
#endif

var actionMap = new InputActionMap("map");
Expand Down Expand Up @@ -4949,8 +5002,8 @@ public void Actions_WhenControlsUpdateInActionAsset_NotificationIsTriggered()
{
#if UNITY_INPUT_SYSTEM_PROJECT_WIDE_ACTIONS
// Exclude project-wide actions from this test
InputSystem.actions?.Disable(); // Worked in Standalone
InputActionState.DestroyAllActionMapStates(); // Also remove controls so the changed control count is accurate
InputSystem.actions?.Disable();
InputActionState.DestroyAllActionMapStates(); // Required for `onActionChange` to report correct number of changes
#endif

var asset = ScriptableObject.CreateInstance<InputActionAsset>();
Expand Down Expand Up @@ -5020,12 +5073,6 @@ public void Actions_WhenControlsUpdate_TimeoutsAreCarriedOver()
[Category("Actions")]
public void Actions_WhenControlsUpdate_InProgressActionsKeepGoing()
{
#if UNITY_INPUT_SYSTEM_PROJECT_WIDE_ACTIONS
// @TODO: This should not need disabled for this test (https://jira.unity3d.com/browse/ISX-1455)
// Causes: "[Assert] Could not find active control after binding resolution"
// when RemoveDevice() called
InputSystem.actions.Disable();
#endif
currentTime = 0;
var gamepad = InputSystem.AddDevice<Gamepad>();

Expand Down Expand Up @@ -5145,7 +5192,7 @@ public void Actions_CanFindEnabledActions()
{
#if UNITY_INPUT_SYSTEM_PROJECT_WIDE_ACTIONS
// Exclude project-wide actions from this test
InputSystem.actions?.Disable();
InputSystem.actions?.Disable(); // Remove from `ListEnabledActions`
#endif

var action1 = new InputAction(name: "a");
Expand Down Expand Up @@ -9789,7 +9836,7 @@ public void Actions_CanUseTouchWithActions()
{
#if UNITY_INPUT_SYSTEM_PROJECT_WIDE_ACTIONS
// Exclude project-wide actions from this test
InputSystem.actions?.Disable();
InputSystem.actions?.Disable(); // Prevent these actions appearing in the `InputActionTrace`
#endif

var touchscreen = InputSystem.AddDevice<Touchscreen>();
Expand Down Expand Up @@ -9864,7 +9911,7 @@ public void Actions_CanDrivePointerInputFromTouchPenAndMouse()
{
#if UNITY_INPUT_SYSTEM_PROJECT_WIDE_ACTIONS
// Exclude project-wide actions from this test
InputSystem.actions?.Disable();
InputSystem.actions?.Disable(); // Prevent these actions appearing in the `InputActionTrace`
#endif

// Give us known parameters for tap detection.
Expand Down
2 changes: 1 addition & 1 deletion Assets/Tests/InputSystem/CoreTests_Actions_Interactions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -753,7 +753,7 @@ public void Actions_CanCustomizeButtonPressPointsOfInteractions()
{
#if UNITY_INPUT_SYSTEM_PROJECT_WIDE_ACTIONS
// Exclude project-wide actions from this test
InputSystem.actions.Disable();
InputSystem.actions?.Disable(); // Prevent these actions appearing in the `InputActionTrace`
#endif

var gamepad = InputSystem.AddDevice<Gamepad>();
Expand Down
10 changes: 7 additions & 3 deletions Assets/Tests/InputSystem/CoreTests_Controls.cs
Original file line number Diff line number Diff line change
Expand Up @@ -478,10 +478,14 @@ public unsafe void Controls_ValueIsReadFromStateMemoryOnlyWhenControlHasBeenMark
[Category("Controls")]
public void Controls_ValueCachingWorksAcrossEntireDeviceMemoryRange()
{
// @TODO: This should not need disabled for this test (https://jira.unity3d.com/browse/ISX-1455)
// Somehow the presence of action controls prevents those controls being marked as stale
#if UNITY_INPUT_SYSTEM_PROJECT_WIDE_ACTIONS
InputSystem.actions.Disable();
// Exclude project-wide actions from this test
// The presence of any enabled actions means we have installed StateChangeMonitors
// which interferes with this test. Essentially when we update the device state
// and invalidate the cache (make it stale), immediately afterwards we
// call NotifyControlStateChanged for each of the actions which _may_ cause a Read()
// on the control and make it immediately cached (non-stale) again.
InputSystem.actions?.Disable();
#endif

var keyboard = InputSystem.AddDevice<Keyboard>();
Expand Down
18 changes: 1 addition & 17 deletions Assets/Tests/InputSystem/CoreTests_Devices.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4100,7 +4100,7 @@ public void Devices_RemovingAndReaddingDevice_DoesNotAllocateMemory()
#if UNITY_INPUT_SYSTEM_PROJECT_WIDE_ACTIONS
// Exclude project-wide actions from this test
// Prevent GC Allocations happening later in test
InputSystem.actions.Disable();
InputSystem.actions?.Disable();
InputActionState.DestroyAllActionMapStates();
#endif

Expand Down Expand Up @@ -4390,12 +4390,6 @@ public void TODO_Devices_CanHijackEventStreamOfDevice()
[TestCase(false, InputSettings.BackgroundBehavior.ResetAndDisableNonBackgroundDevices, InputSettings.EditorInputBehaviorInPlayMode.AllDeviceInputAlwaysGoesToGameView)]
public unsafe void Devices_CanHandleFocusChanges(bool appRunInBackground, InputSettings.BackgroundBehavior backgroundBehavior, InputSettings.EditorInputBehaviorInPlayMode editorInputBehaviorInPlayMode)
{
#if UNITY_INPUT_SYSTEM_PROJECT_WIDE_ACTIONS
// @TODO: This should not need disabled for this test (https://jira.unity3d.com/browse/ISX-1455)
// Causes: "[Assert] Could not find active control after binding resolution"
// due to: mouse3 = InputSystem.AddDevice<Mouse>();
InputSystem.actions.Disable();
#endif
// The constant leads to "Unreachable code detected" warnings.
#pragma warning disable CS0162

Expand Down Expand Up @@ -5363,16 +5357,6 @@ public void Devices_RemovingKeyboardMakesNextKeyboardCurrent()
[Category("Devices")]
public void Devices_RemovingDevice_MakesNextDeviceOfTypeCurrent()
{
#if UNITY_INPUT_SYSTEM_PROJECT_WIDE_ACTIONS
// @TODO: This should not need disabled for this test (https://jira.unity3d.com/browse/ISX-1455)
// Causes: "[Assert] Could not find active control after binding resolution"
// during point where Pointer is removed
// - InputActionState.OnDeviceChange(device, InputDeviceChange.Removed);
// - LazyResolveBindings(bool fullResolve)
// - ResolveBindings()
// - RestoreActionStatesAfterReResolvingBindings(UnmanagedMemory oldState, InputControlList<InputControl> activeControls, bool isFullResolve)
InputSystem.actions.Disable();
#endif
var mouse = InputSystem.AddDevice<Mouse>();
Press(mouse.leftButton);
Assert.That(Pointer.current, Is.EqualTo(mouse));
Expand Down
5 changes: 3 additions & 2 deletions Assets/Tests/InputSystem/CoreTests_Editor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2838,10 +2838,11 @@ public void Editor_WhenRunUpdatesInEditModeIsEnabled_InputActionsTriggerInEditMo
public void Editor_LeavingPlayMode_DestroysAllActionStates()
{
#if UNITY_INPUT_SYSTEM_PROJECT_WIDE_ACTIONS
// With Project-wide Actions `InputSystem.actions`, we begin with some initial ActionState
// Exclude project-wide actions from this test
// With Project-wide Actions `InputSystem.actions`, we begin with some initial ActionState
// Disabling Project-wide actions so that we begin from zero.
Assert.That(InputActionState.s_GlobalState.globalList.length, Is.EqualTo(1));
InputSystem.actions.Disable();
InputSystem.actions?.Disable();
InputActionState.DestroyAllActionMapStates();
#endif

Expand Down
2 changes: 1 addition & 1 deletion Assets/Tests/InputSystem/CoreTests_ProjectWideActions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,7 @@ public void ProjectWideActions_AppearInEnabledActions()
Assert.That(enabledActions, Has.Exactly(1).SameAs(action));

// Disabling works
InputSystem.actions.Disable();
InputSystem.actions?.Disable();
enabledActions = InputSystem.ListEnabledActions();
Assert.That(enabledActions, Has.Count.EqualTo(1));
Assert.That(enabledActions, Has.Exactly(1).SameAs(action));
Expand Down
8 changes: 0 additions & 8 deletions Assets/Tests/InputSystem/Plugins/UITests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3231,8 +3231,6 @@ public IEnumerator UI_CanPreventAutomaticDeselectionOfGameObjects()
Assert.That(scene.eventSystem.currentSelectedGameObject, Is.SameAs(scene.leftGameObject));
}

// @TODO: This should not need disabled for this test (https://jira.unity3d.com/browse/ISX-1455)
#if !UNITY_INPUT_SYSTEM_PROJECT_WIDE_ACTIONS || UNITY_EDITOR
[UnityTest]
[Category("UI")]
public IEnumerator UI_WhenBindingsAreReResolved_PointerStatesAreKeptInSync()
Expand Down Expand Up @@ -3283,8 +3281,6 @@ public IEnumerator UI_WhenBindingsAreReResolved_PointerStatesAreKeptInSync()
Assert.That(EventSystem.current.IsPointerOverGameObject(), Is.True);
}

#endif

////REVIEW: While `deselectOnBackgroundClick` does solve the problem of breaking keyboard and gamepad navigation, the question
//// IMO is whether navigation should even be affected that way by not having a current selection. Seems to me that the
//// the system should remember the last selected object and start up navigation from there when nothing is selected.
Expand Down Expand Up @@ -3800,8 +3796,6 @@ public IEnumerator UI_WhenAppLosesAndRegainsFocus_WhileUIButtonIsPressed_UIButto
Assert.That(clicked, Is.True);
}

// @TODO: This should not need disabled for this test (https://jira.unity3d.com/browse/ISX-1455)
#if !UNITY_INPUT_SYSTEM_PROJECT_WIDE_ACTIONS || UNITY_EDITOR
[UnityTest]
[Category("UI")]
public IEnumerator UI_WhenCursorIsLockedToScreenCenter_PointerEnterAndExitEventsFire()
Expand Down Expand Up @@ -3834,8 +3828,6 @@ public IEnumerator UI_WhenCursorIsLockedToScreenCenter_PointerEnterAndExitEvents
Assert.That(callbackReceiver.events.Any(e => e.type == EventType.PointerExit), Is.True);
}

#endif

#region Multi Display Tests
#if UNITY_2022_3_OR_NEWER // displayIndex is only available from 2022.3 onwards

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -551,6 +551,7 @@ private void RestoreActionStatesAfterReResolvingBindings(UnmanagedMemory oldStat
newActionState.pressedInUpdate = oldActionState.pressedInUpdate;
newActionState.releasedInUpdate = oldActionState.releasedInUpdate;
newActionState.startTime = oldActionState.startTime;
newActionState.bindingIndex = oldActionState.bindingIndex;

if (oldActionState.phase != InputActionPhase.Disabled)
{
Expand Down Expand Up @@ -628,6 +629,7 @@ private void RestoreActionStatesAfterReResolvingBindings(UnmanagedMemory oldStat
// so we can simply look on the binding for where the control is now.
var newControlIndex = FindControlIndexOnBinding(bindingIndex, control);

// This assert is used by test: Actions_ActiveBindingsHaveCorrectBindingIndicesAfterBindingResolution
Debug.Assert(newControlIndex != kInvalidIndex, "Could not find active control after binding resolution");
if (newControlIndex != kInvalidIndex)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,12 @@ public void OnPreprocessBuild(BuildReport report)
var preloadedAssets = PlayerSettings.GetPreloadedAssets();

#if UNITY_INPUT_SYSTEM_PROJECT_WIDE_ACTIONS
EditorBuildSettings.TryGetConfigObject(InputSettingsProvider.kEditorBuildSettingsActionsConfigKey,
out m_ProjectWideActions);

m_ProjectWideActions = Editor.ProjectWideActionsAsset.GetOrCreate();
if (m_ProjectWideActions != null)
{
if (!preloadedAssets.Contains(InputSystem.actions))
if (!preloadedAssets.Contains(m_ProjectWideActions))
{
ArrayHelpers.Append(ref preloadedAssets, InputSystem.actions);
ArrayHelpers.Append(ref preloadedAssets, m_ProjectWideActions);
PlayerSettings.SetPreloadedAssets(preloadedAssets);
}
}
Expand Down
Loading

0 comments on commit baec637

Please sign in to comment.