Skip to content

test: Verify TextBox KeyDown event fires when key is pressed - #23083

Merged
MartinZikmund merged 2 commits into
masterfrom
dev/mazi/repro/13983
Jul 15, 2026
Merged

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

Conversation

@MartinZikmund

Copy link
Copy Markdown
Member

Closes #13983

Summary

Issue #13983 reports that TextBox.KeyDown event is not triggered on Android (Google Pixel 6) when pressing virtual keyboard keys.

Two runtime tests added in Given_TextBox.cs that verify TextBox.KeyDown fires when pressing a regular key (A) and the Enter key on a focused TextBox.

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

Test(s) added

  • src/Uno.UI.RuntimeTests/Tests/Windows_UI_Xaml_Controls/Given_TextBox.cs → When_TextBox_Focused_And_Key_Pressed_Then_KeyDown_Fires
  • src/Uno.UI.RuntimeTests/Tests/Windows_UI_Xaml_Controls/Given_TextBox.cs → When_TextBox_Focused_And_Enter_Pressed_Then_KeyDown_Fires

Notes

The issue was reported on Android (Google Pixel 6, Uno 4.10). Runtime tests run on Skia only — the fix should be verified on native Android as well. The tests use OnKeyTestingOnly which bypasses the virtual keyboard layer, so they serve as regression coverage for the Xaml event routing pipeline, but do not exercise the Android input method (IME) path that may be the actual source of the bug.

Copilot AI review requested due to automatic review settings April 20, 2026 12:27

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 Skia runtime regression coverage for issue #13983 by validating that TextBox.KeyDown is raised when a focused TextBox receives keyboard input (regular key and Enter).

Changes:

  • Add a Skia-only runtime test that injects an A key press and asserts TextBox.KeyDown fires.
  • Add a Skia-only runtime test that injects an Enter key press and asserts TextBox.KeyDown fires.

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

@unodevops

Copy link
Copy Markdown
Contributor

⚠️⚠️ The build 208101 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 21, 2026
@github-actions

github-actions Bot commented Jul 1, 2026

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 Jul 1, 2026
@MartinZikmund MartinZikmund removed the stale This item has been marked as stale and will be closed if there is no activity. label Jul 2, 2026
@MartinZikmund MartinZikmund reopened this Jul 2, 2026
@github-actions

github-actions Bot commented Jul 2, 2026 •

Copy link
Copy Markdown
Contributor

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


Review: 4 findings (1 blocking, 3 advisory)

  • Read changed file and understand the PR
  • Review against AGENTS.md rules and coding standards
  • Post inline comments for specific findings
  • Update summary

Overall: The intent is good — regression coverage for issue #13983 is worthwhile, and the test logic is correct. One rule violation must be fixed before merge; three others are advisory.

Findings: 1 blocking, 3 advisory

# Severity Summary
1 Blocking #if __SKIA__ wrapping [TestMethod] declarations breaks test discovery on non-Skia platforms — the tests become invisible rather than properly skipped. Replace with [PlatformCondition(ConditionMode.Include, RuntimeTestPlatforms.Skia)] on each method. (Runtime-tests rule: "Skip per platform with attributes, not #if on the method.")
2 Advisory After tb.Focus(FocusState.Programmatic), there is no assertion that focus was actually transferred. A silent focus failure causes a misleading "KeyDown never fired" failure. Add Assert.AreEqual(tb, FocusManager.GetFocusedElement(WindowHelper.XamlRoot)) before key injection.
3 Advisory All type references are fully qualified (Windows.System.VirtualKey, Windows.UI.Core.KeyEventArgs, etc.), making the lines unnecessarily long. Add using directives and use the shorter names, matching the style of surrounding tests.
4 Advisory The four-line keyboard-press sequence (key-down + wait + key-up + wait) is duplicated verbatim in both tests. A small local helper function would reduce duplication and make future additions easy.

Cross-cutting note: The PR description accurately flags the IME limitation — OnKeyTestingOnly bypasses the Android virtual keyboard layer, so the tests provide Xaml-event-routing coverage but do not reproduce the original Android IME bug path. This should be called out in a follow-up task or tracking comment if Android parity is still needed.

@unodevops

Copy link
Copy Markdown
Contributor

@unodevops

Copy link
Copy Markdown
Contributor

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

@MartinZikmund
MartinZikmund force-pushed the dev/mazi/repro/13983 branch from 9c27e06 to 374f071 Compare July 13, 2026 08:45
@github-actions

github-actions Bot commented Jul 13, 2026 •

Copy link
Copy Markdown
Contributor

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


Review: 5 findings (1 blocking, 4 advisory)

  • Read changed file and understand the PR
  • Review against AGENTS.md rules and coding standards
  • Post inline comments for specific findings
  • Update summary

Overall: The intent is sound — regression coverage for #13983 is valuable and the test logic itself is correct. One rule violation must be fixed before merge; four others are advisory improvements.

# Severity Line Summary
1 Blocking 1254 #if __SKIA__ wrapping [TestMethod] declarations breaks test discovery on non-Skia platforms — tests become silently absent rather than properly skipped. Replace the outer #if/#endif with [PlatformCondition(ConditionMode.Include, RuntimeTestPlatforms.Skia)] on each method (runtime-tests rule: "Skip per platform with attributes, not #if on the method").
2 Advisory 1272 No assertion that focus was actually acquired after tb.Focus(FocusState.Programmatic). A silent focus failure produces a misleading "KeyDown never fired" error instead of "focus was never set."
3 Advisory 1303 Same missing focus assertion in the second test.
4 Advisory 1276 Fully-qualified Windows.System.VirtualKey, Windows.System.VirtualKeyModifiers, Windows.UI.Core.KeyEventArgs, Windows.UI.Core.CorePhysicalKeyStatus throughout — the file already imports using Windows.System; inside `#if WINAPPSDK
5 Advisory 1274–1280 The four-line key-press sequence (key-down + wait + key-up + wait) is duplicated verbatim across both tests — a small local helper function would reduce duplication and make future additions easy.

Cross-cutting note: The PR description correctly flags the IME limitation — OnKeyTestingOnly bypasses the Android virtual keyboard path, so these tests cover XAML event-routing regression but do not reproduce the original Android IME bug. If native Android parity is still needed, a follow-up task or tracking comment should call that out.

@unodevops

Copy link
Copy Markdown
Contributor

Extract a shared TapKey helper, drop the fully-qualified type names in
favor of usings/aliases, and assert focus landed on the TextBox before
injecting keys so a focus failure is not reported as a routing failure.

Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
Claude-Session: https://claude.ai/code/session_01GKBgQoAmRmaFoXXZr93iLB
@github-actions

github-actions Bot commented Jul 14, 2026 •

Copy link
Copy Markdown
Contributor

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


Review: 1 blocking finding

  • Load tools
  • Read changed file
  • Post inline review comments
  • Update summary

Overall: The latest commit (884c587) has addressed all three advisory findings from the previous round — TapKey helper extracted, focus assertion added, and using aliases added for shorter type names. One blocking rule violation remains.

# Severity Line Summary
1 Blocking 1271 Both [TestMethod] declarations are still inside the outer #if __SKIA__ block — the test runner on Android/iOS/WASM never discovers them (silently absent, not properly skipped). Replace the outer #if/#endif with [PlatformCondition(ConditionMode.Include, RuntimeTestPlatforms.Skia)] on each method and guard the method bodies with #if __SKIA__. The TapKey helper can keep its own #if __SKIA__ wrapper.

Cross-cutting note: The PR description correctly flags the IME limitation — OnKeyTestingOnly bypasses the Android virtual keyboard path, so these tests cover XAML event-routing regression but do not reproduce the original Android IME bug. If native Android parity is still needed, a follow-up task or tracking comment should call that out.

@MartinZikmund

MartinZikmund commented Jul 14, 2026 •

Copy link
Copy Markdown
Member Author

🤖 Addressed PR comments up to this point

All review threads on this PR were reviewed individually against the current code on dev/mazi/repro/13983 (HEAD 884c5877ef). They collapse into 4 distinct concerns. Three of the four were already fixed in 884c5877ef; the fourth is a repo-convention decision that is deliberately escalated below.

Validation level: code inspection only. No build or test was run this pass — Azure Pipelines CI is the validation gate. No new commit was pushed this pass — the earlier fixes remain at 884c5877ef, and the one open concern is escalated rather than changed.

✅ Addressed in 884c5877ef (12 threads — resolved)

Concern file:line Reviewer point What changed
Noisy fully-qualified type names Given_TextBox.cs Windows.System.* / Windows.UI.Core.* are hard to scan (@copilot-pull-request-reviewer, @Xiaoy312, ultrareview) VirtualKey/VirtualKeyModifiers are now unqualified via the file's existing using Windows.System; (in scope inside #if __SKIA__); KeyEventArgs/CorePhysicalKeyStatus use Skia-gated aliases (as Given_UIElement.cs does) to avoid ambiguity a blanket using Windows.UI.Core; would introduce.
No focus assertion before key injection Given_TextBox.cs:1290, 1317 Focus(...) can silently fail → misleading "KeyDown never fired" (@copilot-pull-request-reviewer, ultrareview) Both tests now assert Assert.AreEqual(tb, FocusManager.GetFocusedElement(WindowHelper.XamlRoot), …) before injecting keys, matching When_Clicked_In_Popup in the same file.
Key-press sequence duplicated Given_TextBox.cs:1260 Extract a helper for the key-down/up sequence (@copilot-pull-request-reviewer, ultrareview) Extracted TapKey(VirtualKey key), mirroring the identically-named helper in Given_UIElement.cs; both tests now call await TapKey(...).

⏳ Needs @MartinZikmund input (3 threads — left unresolved)

#if __SKIA__ around [TestMethod] → [PlatformCondition(ConditionMode.Include, RuntimeTestPlatforms.Skia)] — Given_TextBox.cs:1259/1271, ultrareview, flagged [Blocking] (three separate threads raise this same concern).

The discovery argument is correct in principle — .claude/rules/runtime-tests.md does say "skip per platform with attributes, not #if on the method". But this is not a mechanical swap, and I will not guess it under an inspection-only pass:

  1. The body cannot compile off Skia — InputManager.Keyboard.OnKeyTestingOnly exists only in InputManager.Keyboard.skia.cs. [PlatformCondition] therefore still requires the body under #if __SKIA__ with a non-Skia #else arm to avoid CS1998 (async method with no await) — which is warnings-as-errors on CI.
  2. Precedent conflict: Given_UIElement.cs wraps six OnKeyTestingOnly-based [TestMethod]s in exactly this #if __SKIA__ pattern (verified: lines 395–853). Changing only this PR diverges the two conventions; changing it everywhere is a repo-wide call.
  3. The change spans five platform heads and needs a real build to trust — outside this inspection-only pass.

So this is escalated for your call, Martin: either accept the #if __SKIA__ precedent here (matching Given_UIElement.cs) and dismiss the finding, or greenlight a repo-wide migration to [PlatformCondition] + body-gating that I'll do with a proper build. Happy to do either — just say which.

@unodevops

Copy link
Copy Markdown
Contributor

@MartinZikmund
MartinZikmund merged commit 6cebf8d into master Jul 15, 2026
47 checks passed
@MartinZikmund
MartinZikmund deleted the dev/mazi/repro/13983 branch July 15, 2026 07:39
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.

[Android] TextBox.KeyDown event is not working

4 participants