Skip to content

Add failing reproducer for show-taps overlay misplacement#4

Draft
takahirom wants to merge 1 commit into
saket:trunkfrom
takahirom:show-taps-overlay-position-repro
Draft

Add failing reproducer for show-taps overlay misplacement#4
takahirom wants to merge 1 commit into
saket:trunkfrom
takahirom:show-taps-overlay-position-repro

Conversation

@takahirom

Copy link
Copy Markdown

Reproducer for #3, as requested (a runnable feedback loop for the show-taps overlay misplacement).

What this adds

  • A Robolectric unit test, ShowTapsOverlayPositionTest, in touchrobot-core.
  • Robolectric test infra for touchrobot-core (JUnit4, Robolectric 4.14.1, androidx.test.ext:junit, androidx.compose.ui:ui-test-junit4, and ui-test-manifest as debugImplementation), plus testOptions.unitTests.isIncludeAndroidResources = true. Versions go through the existing version catalog and match the Compose version the repo already uses (1.8.1).

The Robolectric gotcha

rememberTouchRobot(showTaps = true) draws taps in a separate window added via WindowManager.addView(). MatchParentSizePopup sizes that window to the host view but leaves WindowManager.LayoutParams.gravity at its default (0), so WindowManager centers the window on screen. An overlay smaller than the screen is therefore drawn offset from the host view (and from the touches, which are injected at the host's top-left).

Robolectric does not run WindowManager's window-placement math, so View.getLocationOnScreen() reports (0, 0) for the overlay and hides the bug. The test instead reconstructs the on-screen rect with the exact call WindowManager makes to place a window — Gravity.apply(...) — and asserts the overlay lands at the host view's position.

Current failure (on trunk)

java.lang.AssertionError: Show-taps overlay window is not anchored to the host view. Overlay window at (15, 174) size 450x450, but host view is at (0, 0) size 450x450 on a 480x799 screen. The overlay LayoutParams gravity is 0 (0 = centered by WindowManager). expected:<(0, 0)> but was:<(15, 174)>

This test fails intentionally on trunk (that's the point — it's the red half of the feedback loop). The fix is stacked in the follow-up PR.

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.

1 participant