Skip to content

FIX: UITK UI input tests and re-enable test on CI#2367

Open
MorganHoarau wants to merge 5 commits intofix/uum-100125/inactive-touch-drive-phantom-click-on-state-resetfrom
fix/uitkinputmodule-tests
Open

FIX: UITK UI input tests and re-enable test on CI#2367
MorganHoarau wants to merge 5 commits intofix/uum-100125/inactive-touch-drive-phantom-click-on-state-resetfrom
fix/uitkinputmodule-tests

Conversation

@MorganHoarau
Copy link
Collaborator

Description

While testing #2349 locally, I noticed that UI_CanOperateUIToolkitInterface_UsingInputSystemUIInputModule was failing. Turns out the test have always been failing and was ignore on most platform (including linux - which run our CI).

UI_CanOperateUIToolkitInterface_UsingInputSystemUIInputModule was a long integration scenario that was doing:

  • mouse press/capture/release
  • scroll
  • gamepad submit with uiButton.Focus()
  • mouse device removal (pointer purge path)
  • then multi-touch checks (both event and visual state based)

I was able to get the failing scenario (the UI element :active pseudo-state inconsistent behaviour) - by gradually disabling the integrated scenario. So my assumption is that the the pointer/event-data being reused across pointers and phases was causing touch pointers to inherit subtle stale event state after mouse/gamepad + purge transitions.

I then splitted the monolithic method into multiple focused UnityTests:

  • mouse click
  • mouse scroll
  • gamepad submit
  • multi-touch pointer ownership
  • multi-touch visual active-state

...and added stronger assertions (including pointerId ownership checks), and clearer assertion messages.

Note that the original scenarios have been preserved, simply isolated to avoid the complexity of handling multiple devices properly in a test.

My hope is to re-enable those tests on CI and mobile platform.

Testing status & QA

Please describe the testing already done by you and what testing you request/recommend QA to execute. If you used or created any testing project please link them here too for QA.

Overall Product Risks

Please rate the potential complexity and halo effect from low to high for the reviewers. Note down potential risks to specific Editor branches if any.

  • Complexity:
  • Halo Effect:

Comments to reviewers

Please describe any additional information such as what to focus on, or historical info for the reviewers.

Checklist

Before review:

  • Changelog entry added.
    • Explains the change in Changed, Fixed, Added sections.
    • For API change contains an example snippet and/or migration example.
    • JIRA ticket linked, example (case %%). If it is a private issue, just add the case ID without a link.
    • Jira port for the next release set as "Resolved".
  • Tests added/changed, if applicable.
    • Functional tests Area_CanDoX, Area_CanDoX_EvenIfYIsTheCase, Area_WhenIDoX_AndYHappens_ThisIsTheResult.
    • Performance tests.
    • Integration tests.
  • Docs for new/changed API's.
    • Xmldoc cross references are set correctly.
    • Added explanation how the API works.
    • Usage code examples added.
    • The manual is updated, if needed.

During merge:

  • Commit message for squash-merge is prefixed with one of the list:
    • NEW: ___.
    • FIX: ___.
    • DOCS: ___.
    • CHANGE: ___.
    • RELEASE: 1.1.0-preview.3.

Split monolithic UITests method into multiple focused UnityTests (mouse click, mouse scroll, gamepad submit, multi-touch pointer ownership, and multi-touch visual active-state).

Added stronger assertions (including pointerId ownership checks), and clearer assertion messages.
@u-pr
Copy link
Contributor

u-pr bot commented Mar 5, 2026

PR Reviewer Guide 🔍

(Review updated until commit 91a0007)

Here are some key observations to aid the review process:

⏱️ Estimated effort to review: 3 🔵🔵🔵⚪⚪

The changes are mostly test refactoring but introduce several new UnityTests whose correctness and stability (especially across platforms/CI) need validation.

🏅 Score: 87

The refactor significantly improves test focus and assertions, but there are a couple of correctness/stability risks in the new helper/cleanup patterns that could cause flaky or misleading results.

🧪 PR contains tests
🔒 No security concerns identified
⚡ Recommended focus areas for review

Possible Issue

IsActiveVisualElement checks active state via visualElement.Query<VisualElement>().Active().ToList().Contains(visualElement), which may never include visualElement itself (depending on whether Query() includes the root), and it allocates; consider validating the semantics or using a direct pseudo-state check (e.g., visualElement.pseudoStates / PseudoStates.Active) to avoid false positives/negatives and reduce flakiness.

private static bool IsActiveVisualElement(VisualElement visualElement)
{
    return visualElement.Query<VisualElement>().Active().ToList().Contains(visualElement);
}
Test Stability

Scene unloading is triggered via SceneManager.UnloadSceneAsync(scene) but the tests only yield return null afterward, which may not guarantee unload completion before the next test starts; consider yielding the AsyncOperation (or otherwise ensuring completion) to reduce cross-test interference in CI.

    finally
    {
        if (mouse.added)
            InputSystem.RemoveDevice(mouse);
        SceneManager.UnloadSceneAsync(scene);
    }

    yield return null;
}
Cleanup/Noise

Several tests fetch uiModule but don’t use it, which can introduce warnings or obscure intent; either remove the unused variable or use it consistently (e.g., explicitly set/verify pointerBehavior or relevant module settings in the tests that rely on defaults).

        var objects = scene.GetRootGameObjects();
        var uiModule = objects.First(x => x.name == "EventSystem").GetComponent<InputSystemUIInputModule>();
        var uiDocument = objects.First(x => x.name == "UIDocument").GetComponent<UIDocument>();
        var uiButton = uiDocument.rootVisualElement.Query<UnityEngine.UIElements.Button>("Button").First();

        var clickReceived = false;
        uiButton.clicked += () => clickReceived = true;

        yield return null;

        var buttonCenter = new Vector2(uiButton.worldBound.center.x, Screen.height - uiButton.worldBound.center.y);
        Set(mouse.position, buttonCenter, queueEventOnly: true);
        Press(mouse.leftButton, queueEventOnly: true);
        yield return null;
        Assert.That(uiButton.HasMouseCapture(), Is.True, "Expected uiButton to have mouse capture");

        Release(mouse.leftButton, queueEventOnly: true);
        yield return null;
        Assert.That(uiButton.HasMouseCapture(), Is.False, "Expected uiButton to no longer have mouse capture");
        Assert.That(clickReceived, Is.True, "Expected mouse click callback on UITK button");
    }
    finally
    {
        if (mouse.added)
            InputSystem.RemoveDevice(mouse);
        SceneManager.UnloadSceneAsync(scene);
    }

    yield return null;
}

[UnityTest]
[Category("UI")]
[PrebuildSetup(typeof(UI_CanOperateUIToolkitInterface_UsingInputSystemUIInputModule_Setup))]
public IEnumerator UI_UIToolkitInputModule_MouseScroll_MovesScrollView()
{
    var mouse = InputSystem.AddDevice<Mouse>();
    var scene = SceneManager.LoadScene("UITKTestScene", new LoadSceneParameters(LoadSceneMode.Additive));
    yield return null;
    Assert.That(scene.isLoaded, Is.True, "UITKTestScene did not load as expected");

    try
    {
        var objects = scene.GetRootGameObjects();
        var uiModule = objects.First(x => x.name == "EventSystem").GetComponent<InputSystemUIInputModule>();
        var uiDocument = objects.First(x => x.name == "UIDocument").GetComponent<UIDocument>();
        var scrollView = uiDocument.rootVisualElement.Query<ScrollView>("ScrollView").First();

        yield return null;

        var scrollViewCenter = new Vector2(scrollView.worldBound.center.x, Screen.height - scrollView.worldBound.center.y);
        Assert.That(scrollView.verticalScroller.value, Is.Zero, "Expected verticalScroller to be all the way up");
        Set(mouse.position, scrollViewCenter, queueEventOnly: true);
        yield return null;
        Set(mouse.scroll, new Vector2(0, -100), queueEventOnly: true);
        yield return null;
        Assert.That(scrollView.verticalScroller.value, Is.GreaterThan(0));
    }
    finally
    {
        if (mouse.added)
            InputSystem.RemoveDevice(mouse);
        SceneManager.UnloadSceneAsync(scene);
    }

    yield return null;
}

[UnityTest]
[Category("UI")]
[PrebuildSetup(typeof(UI_CanOperateUIToolkitInterface_UsingInputSystemUIInputModule_Setup))]
public IEnumerator UI_UIToolkitInputModule_GamepadSubmit_ClicksFocusedButton()
{
    var gamepad = InputSystem.AddDevice<Gamepad>();
    var scene = SceneManager.LoadScene("UITKTestScene", new LoadSceneParameters(LoadSceneMode.Additive));
    yield return null;
    Assert.That(scene.isLoaded, Is.True, "UITKTestScene did not load as expected");

    try
    {
        var objects = scene.GetRootGameObjects();
        var uiModule = objects.First(x => x.name == "EventSystem").GetComponent<InputSystemUIInputModule>();
        var uiDocument = objects.First(x => x.name == "UIDocument").GetComponent<UIDocument>();
        var uiButton = uiDocument.rootVisualElement.Query<UnityEngine.UIElements.Button>("Button").First();
  • Update review

🤖 Helpful? Please react with 👍/👎 | Questions❓Please reach out in Slack #ask-u-pr

@u-pr
Copy link
Contributor

u-pr bot commented Mar 5, 2026

PR Code Suggestions ✨

Explore these optional code suggestions:

CategorySuggestion                                                                                                                                    Impact
Possible issue
Check active state correctly

Query() does not include the element itself, so this check can return false even
when the element is actually active, making the new assertions unreliable. Use the
element’s pseudoStates to directly test the Active state without allocations.

Assets/Tests/InputSystem/Plugins/UITests.cs [4201-4204]

 private static bool IsActiveVisualElement(VisualElement visualElement)
 {
-    return visualElement.Query<VisualElement>().Active().ToList().Contains(visualElement);
+    return (visualElement.pseudoStates & UnityEngine.UIElements.PseudoStates.Active) != 0;
 }
Suggestion importance[1-10]: 7

__

Why: The IsActiveVisualElement check using Query is likely incorrect because Query on a VisualElement searches its descendants; thus Contains(visualElement) would return false. Using pseudoStates directly is more accurate and avoids unnecessary allocations.

Medium
Clean up created input devices

Devices created via InputSystem.AddDevice<...>() should be removed even when assertions
fail; otherwise later tests can see extra devices and behave differently. Remove the
created device(s) in the finally block so cleanup always runs.

Assets/Tests/InputSystem/Plugins/UITests.cs [4021-4050]

 public IEnumerator UI_UIToolkitInputModule_GamepadSubmit_ClicksFocusedButton()
 {
     var gamepad = InputSystem.AddDevice<Gamepad>();
     var scene = SceneManager.LoadScene("UITKTestScene", new LoadSceneParameters(LoadSceneMode.Additive));
     yield return null;
     Assert.That(scene.isLoaded, Is.True, "UITKTestScene did not load as expected");
 
     try
     {
         ...
     }
     finally
     {
+        if (gamepad.added)
+            InputSystem.RemoveDevice(gamepad);
         SceneManager.UnloadSceneAsync(scene);
     }
 
     yield return null;
 }
Suggestion importance[1-10]: 7

__

Why: Created input devices should be removed in a finally block to ensure test isolation, especially if an assertion fails. This ensures that the global InputSystem state is restored for subsequent tests.

Medium
Wait for scene unload completion

SceneManager.UnloadSceneAsync(scene) is asynchronous and a single yield return null
may not guarantee the scene is fully unloaded, which can cause cross-test
interference/flakiness on CI. Capture the unload operation and yield until it
completes.

Assets/Tests/InputSystem/Plugins/UITests.cs [3939-3968]

+UnityEngine.AsyncOperation unloadOp = null;
 try
 {
     ...
 }
 finally
 {
-    SceneManager.UnloadSceneAsync(scene);
+    unloadOp = SceneManager.UnloadSceneAsync(scene);
 }
 
-yield return null;
+while (unloadOp != null && !unloadOp.isDone)
+    yield return null;
Suggestion importance[1-10]: 6

__

Why: SceneManager.UnloadSceneAsync is an asynchronous operation. A single yield return null might not be sufficient to ensure the scene is fully unloaded, potentially leading to flakiness or cross-test interference.

Low
  • More suggestions

🤖 Helpful? Please react with 👍/👎 | Questions❓Please reach out in Slack #ask-u-pr

@codecov-github-com
Copy link

codecov-github-com bot commented Mar 5, 2026

Codecov Report

All modified and coverable lines are covered by tests ✅

@@                                         Coverage Diff                                          @@
##           fix/uum-100125/inactive-touch-drive-phantom-click-on-state-reset    #2367      +/-   ##
====================================================================================================
+ Coverage                                                             77.91%   77.93%   +0.02%     
====================================================================================================
  Files                                                                   481      481              
  Lines                                                                 97692    97792     +100     
====================================================================================================
+ Hits                                                                  76117    76218     +101     
+ Misses                                                                21575    21574       -1     
Flag Coverage Δ
inputsystem_MacOS_2022.3 5.50% <ø> (ø)
inputsystem_MacOS_2022.3_project 75.46% <100.00%> (+0.02%) ⬆️
inputsystem_MacOS_6000.0 5.28% <ø> (ø)
inputsystem_MacOS_6000.0_project 77.36% <100.00%> (+0.02%) ⬆️
inputsystem_MacOS_6000.3 5.28% <ø> (ø)
inputsystem_MacOS_6000.3_project 77.36% <100.00%> (+0.02%) ⬆️
inputsystem_MacOS_6000.4 5.28% <ø> (ø)
inputsystem_MacOS_6000.4_project 77.37% <100.00%> (+0.02%) ⬆️
inputsystem_MacOS_6000.5 5.28% <ø> (ø)
inputsystem_MacOS_6000.5_project 77.37% <100.00%> (+0.02%) ⬆️
inputsystem_MacOS_6000.6 5.28% <ø> (ø)
inputsystem_MacOS_6000.6_project 77.37% <100.00%> (+0.03%) ⬆️
inputsystem_Ubuntu_2022.3_project 75.36% <100.00%> (+0.12%) ⬆️
inputsystem_Ubuntu_6000.0 5.28% <ø> (ø)
inputsystem_Ubuntu_6000.0_project 77.27% <100.00%> (+0.13%) ⬆️
inputsystem_Ubuntu_6000.3 5.28% <ø> (ø)
inputsystem_Ubuntu_6000.3_project 77.26% <100.00%> (+0.12%) ⬆️
inputsystem_Ubuntu_6000.4 5.29% <ø> (ø)
inputsystem_Ubuntu_6000.4_project 77.28% <100.00%> (+0.12%) ⬆️
inputsystem_Ubuntu_6000.5 5.29% <ø> (ø)
inputsystem_Ubuntu_6000.5_project 77.27% <100.00%> (+0.12%) ⬆️
inputsystem_Ubuntu_6000.6 5.29% <ø> (ø)
inputsystem_Ubuntu_6000.6_project 77.27% <100.00%> (+0.12%) ⬆️
inputsystem_Windows_2022.3 5.50% <ø> (ø)
inputsystem_Windows_2022.3_project 75.59% <100.00%> (+0.02%) ⬆️
inputsystem_Windows_6000.0 5.28% <ø> (ø)
inputsystem_Windows_6000.0_project 77.49% <100.00%> (+0.02%) ⬆️
inputsystem_Windows_6000.3 5.28% <ø> (ø)
inputsystem_Windows_6000.3_project 77.49% <100.00%> (+0.02%) ⬆️
inputsystem_Windows_6000.4 5.28% <ø> (ø)
inputsystem_Windows_6000.4_project 77.49% <100.00%> (+0.02%) ⬆️
inputsystem_Windows_6000.5 5.28% <ø> (ø)
inputsystem_Windows_6000.5_project 77.49% <100.00%> (+0.02%) ⬆️
inputsystem_Windows_6000.6 5.28% <ø> (ø)
inputsystem_Windows_6000.6_project 77.49% <100.00%> (+0.02%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

Files with missing lines Coverage Δ
Assets/Tests/InputSystem/Plugins/UITests.cs 94.87% <100.00%> (+0.20%) ⬆️

... and 1 file with indirect coverage changes

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Skip Android/iOS on several 2 failing UI tests to address CI failures on Unity 2022.3.

+ Clean up created input devices
@u-pr
Copy link
Contributor

u-pr bot commented Mar 10, 2026

Persistent review updated to latest commit 91a0007

@MorganHoarau MorganHoarau changed the title Refactor UITK UI input tests and re-enable test on CI FIX: UITK UI input tests and re-enable test on CI Mar 11, 2026
Copy link
Collaborator

@ekcoh ekcoh left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for looking into this @MorganHoarau. It makes a lot of sense to break up that overly-complex test sequence.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants