Skip to content

Replace ViewHelpers with explicit measure/layout; childCountTest uses view.post polling#113

Open
EmilioBejasa wants to merge 1 commit into
mainfrom
assert-child-count
Open

Replace ViewHelpers with explicit measure/layout; childCountTest uses view.post polling#113
EmilioBejasa wants to merge 1 commit into
mainfrom
assert-child-count

Conversation

@EmilioBejasa
Copy link
Copy Markdown
Collaborator

Summary

  • Remove ViewHelpers from IsolatedTest.kt (constructViewTest, childCountTest) and ScreenshotTest.kt (testSimpleTextView); replace with explicit view.measure() / view.layout() calls
  • Replace 30s poll loop in childCountTest with a self-rescheduling Runnable posted via view.post(). WindowAttachment.dispatchAttach injects a real Handler (bound to the main Looper) into AttachInfo, so view.post() routes to the main MessageQueue. The Runnable checks childCount every 50ms on the main thread and completes a CompletableFuture<Int> when children appear; the test thread blocks on future.get(5s).
  • Remove childCountScreenshotTest — it was a duplicate of childCountTest plus a screenshot; the screenshot half will live in a follow-up PR
  • Capture startTask return value and assertGoodTask it before waiting on the future, so the bg executor is fully drained before polling begins

Why view.post works here

WindowAttachment.dispatchAttach (screenshot-tests-for-android) doesn't add the view to a real window — it uses reflection to inject a fake AttachInfo. That AttachInfo is constructed with new Handler() on the main thread, so view.post(r) calls attachInfo.mHandler.post(r), which posts to the main Looper. OnGlobalLayoutListener does not work here because there's no real ViewRootImpl driving layout traversals.

Test plan

  • simpleTest passes
  • constructViewTest passes
  • childCountTest passes (no sleep, no CountDownLatch, one setup runOnMainSync)
  • recordDebugAndroidTestScreenshotTest succeeds; addViewHookTest screenshot shows "Hello" (not blank)
  • verifyDebugAndroidTestScreenshotTest passes

🤖 Generated with Claude Code

…ith view.post check

- Remove ViewHelpers from constructViewTest and childCountTest (IsolatedTest.kt)
  and testSimpleTextView (ScreenshotTest.kt); use explicit measure()/layout() calls
- Replace 30s poll loop in childCountTest with a self-rescheduling Runnable posted
  via view.post(), driven by the main-thread Handler that WindowAttachment.dispatchAttach
  installs in AttachInfo; block test thread on CompletableFuture.get(5s)
- Remove childCountScreenshotTest (duplicate of childCountTest + screenshot)
- assertGoodTask now captures and awaits startTask so the bg executor is drained
  before the future is polled

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
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