Skip to content

test: Verify Button exits Pressed state during async Click handler - #23009

Merged
MartinZikmund merged 2 commits into
masterfrom
dev/mazi/repro/12028
Jun 24, 2026
Merged

MartinZikmund merged 2 commits into
masterfrom
dev/mazi/repro/12028

Conversation

@MartinZikmund

Copy link
Copy Markdown
Member

Closes #12028

Summary

  • The issue reports that a Button with OutlinedButtonStyle from Uno.Material remains visually "selected" (in Pressed visual state) while a long-running async Click handler (Task.Delay(2000)) is running on Android, iOS, and Windows.
  • A runtime test verifies that after a mouse press+release, the Button's CommonStates group transitions out of Pressed immediately, regardless of the Click handler's async duration.

The reported issue appears to be potentially fixed — the test passes on current master (Skia target).

Test(s) added

  • src/Uno.UI.RuntimeTests/Tests/Windows_UI_Xaml_Controls/Given_Button.cs → When_Button_Does_Not_Stay_Pressed_During_Async_Click_Handler

Notes

The issue was reported on Android, iOS, and Windows, with Uno.Material's OutlinedButtonStyle. The runtime test uses the default Button style. If the root cause is in Material's custom visual states or touch-specific pointer capture, the issue may still reproduce on native targets. The test should also be verified on Android/iOS native targets.

Copilot AI review requested due to automatic review settings April 10, 2026 08:56

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

Adds a new Uno.UI runtime test to ensure Button exits the Pressed visual state immediately after pointer release, even if the Click handler starts a long-running async operation—addressing the behavior reported in #12028.

Changes:

  • Introduce a runtime test that injects mouse press/release and inspects the CommonStates visual state after release.
  • Validate that CommonStates.CurrentState is not Pressed while the async click handler is still running.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@unodevops

Copy link
Copy Markdown
Contributor

@unodevops

Copy link
Copy Markdown
Contributor

⚠️⚠️ The build 206553 has failed on Uno.UI - CI.

@github-actions

Copy link
Copy Markdown
Contributor

This PR is stale because it has been open 60 days with no activity. Remove stale label or comment or it will be closed in 10 days.

@github-actions github-actions Bot added the stale This item has been marked as stale and will be closed if there is no activity. label Jun 10, 2026
@github-actions

Copy link
Copy Markdown
Contributor

This PR was closed because it has been stalled for 10 days with no activity.

@github-actions github-actions Bot closed this Jun 21, 2026
@MartinZikmund MartinZikmund removed the stale This item has been marked as stale and will be closed if there is no activity. label Jun 22, 2026
@MartinZikmund MartinZikmund reopened this Jun 22, 2026
@github-actions

github-actions Bot commented Jun 22, 2026 •

Copy link
Copy Markdown
Contributor

Claude finished @MartinZikmund's task in 2m 2s —— View job


Code Review

  • Gather context and read changed files
  • Review test code for correctness, robustness, and style
  • Post inline comments for specific findings
  • Update summary comment

Overall verdict: needs changes before merge. The test intent is correct and the [GitHubWorkItem] / #if !HAS_INPUT_INJECTOR guard / [Ignore] pattern is spot-on. However there are 4 issues that need to be addressed — 1 crash risk, 1 reliability bug, and 2 correctness gaps that can produce false positives:

Severity Count Summary
🔴 Crash risk 1 GetVisualStateGroups return value can be null; .FirstOrDefault() on null throws
🟠 Reliability 2 SetResult on TCS can throw if Click fires twice; 500 ms gate is fragile under CI load
🟡 Correctness 1 No assertion that button entered Pressed — test passes trivially if state never engaged

Cross-cutting note: [RunsOnUIThread] is already on the class (Given_Button line 33), so the new test inherits it correctly — no change needed there.

The Copilot reviewer's suggestion to poll GetChildrenCount > 0 before calling GetChild is reasonable hardening, but in practice UITestHelper.Load + WaitForIdle makes it very unlikely to be needed. The more critical issues are the four listed above.

@unodevops

Copy link
Copy Markdown
Contributor

MartinZikmund and others added 2 commits June 24, 2026 09:38
Addresses the WinAppSDK compile break and the PR review feedback on the
When_Button_Does_Not_Stay_Pressed_During_Async_Click_Handler test:

- Replace buttonRect.GetCenter() with inline Point math. GetCenter is a
  Uno.UWP extension (Uno.Extensions.RectExtensions) that is absent on the
  native WinAppSDK target, which broke the Windows build with CS1061.
- Use TrySetResult so a second injected Click can't throw.
- Poll for template children and null-check GetVisualStateGroups before
  querying CommonStates, so the test can't NRE/throw if the template is
  not ready yet.
- Assert the button is in the Pressed state while held, so a button that
  never engages Pressed fails loudly instead of passing trivially.
- Replace the brittle Task.Delay(500) with a gate TaskCompletionSource:
  the Click handler blocks until the post-release assertion has run, so
  there is no wall-clock window for the assertion to race. Released in a
  finally to avoid leaving the handler awaiting forever on failure.

Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
Claude-Session: https://claude.ai/code/session_015DYGmMmEsscuswdkmjSNrZ
@MartinZikmund
MartinZikmund force-pushed the dev/mazi/repro/12028 branch from 73954af to 1f1bf0f Compare June 24, 2026 07:54
@github-actions

github-actions Bot commented Jun 24, 2026 •

Copy link
Copy Markdown
Contributor

Claude finished @MartinZikmund's task in 2m 31s —— View job


Code Review

  • Load tools
  • Read changed file and diff
  • Check all four previously flagged issues
  • Check for new issues
  • Post inline comments (none needed — no blocking findings)
  • Update summary

Overall verdict: LGTM. All four issues flagged in the prior review have been resolved in this revision. No new findings.

Prior Issue Status
🔴 GetVisualStateGroups null crash ✅ Fixed — ?.FirstOrDefault(...) + Assert.IsNotNull guard
🟠 SetResult crash on double-fire ✅ Fixed — changed to TrySetResult
🟠 500 ms wall-clock timing race ✅ Fixed — asyncHandlerGate TCS gates the handler deterministically; no delay to tune
🟡 No assertion button entered Pressed ✅ Fixed — Assert.AreEqual("Pressed", ...) added before mouse.Release()

Cross-cutting checks (all pass):

  • [RunsOnUIThread] inherited from class-level attribute ✅
  • #if !HAS_INPUT_INJECTOR wraps only [Ignore], not [TestMethod] — test discovery preserved ✅
  • try/finally releases the gate on assertion failure — no handler left hanging ✅
  • using var mouse ensures InputInjector cleanup ✅
  • Conventional Commit on PR title (test:) and commits ✅
  • No event Action / event Action<T> usage ✅

Validation note (Code review): Assessment is by diff inspection. Runtime validation on Skia Desktop requires /runtime-tests When_Button_Does_Not_Stay_Pressed_During_Async_Click_Handler. Native Android/iOS/Windows targets should also be verified given the original issue was reported there with Uno.Material's OutlinedButtonStyle.

@unodevops

Copy link
Copy Markdown
Contributor

@MartinZikmund

Copy link
Copy Markdown
Member Author

C:/Program Files/Git/azp run

@unodevops

Copy link
Copy Markdown
Contributor

⚠️⚠️ The build 219569 has failed on Uno.UI - CI.

@MartinZikmund
MartinZikmund enabled auto-merge June 24, 2026 13:47
@MartinZikmund
MartinZikmund merged commit 728f7e7 into master Jun 24, 2026
47 checks passed
@MartinZikmund
MartinZikmund deleted the dev/mazi/repro/12028 branch June 24, 2026 14:02
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.

Button with OutlinedButtonStyle or MaterialOutlinedButtonStyle style stay selected if we execute a task

4 participants