SurfaceControlViewHostTest: Deflake resize test

Currently we are using WidgetTestUtils.runOnMainAndDrawSync
however this only waits for the onDraw callback, which doesn't
even ensure the request has been queued to HWUI much less rendered.
If we use frame commit callback we are guaranteed the request has
been queued and so our ordering should work out since we perform
a sync transaction before injecting input.

Bug: 172061197
Test: SurfaceControlViewHostTests
Change-Id: Ib2d8c08082b846fe180a6af6eddf097b02042cf3
diff --git a/tests/framework/base/windowmanager/src/android/server/wm/SurfaceControlViewHostTests.java b/tests/framework/base/windowmanager/src/android/server/wm/SurfaceControlViewHostTests.java
index 6644990..c26ccb1 100644
--- a/tests/framework/base/windowmanager/src/android/server/wm/SurfaceControlViewHostTests.java
+++ b/tests/framework/base/windowmanager/src/android/server/wm/SurfaceControlViewHostTests.java
@@ -258,12 +258,17 @@
         mActivityRule.runOnUiThread(() -> {
                 mVr.relayout(bigEdgeLength, bigEdgeLength);
         });
-        WidgetTestUtils.runOnMainAndDrawSync(mActivityRule,
-            mEmbeddedView, null);
-        // We need to draw twice to make sure the first buffer actually
-        // arrives.
-        WidgetTestUtils.runOnMainAndDrawSync(mActivityRule,
-            mEmbeddedView, null);
+        mInstrumentation.waitForIdleSync();
+
+        // We use frameCommitCallback because we need to ensure HWUI
+        // has actually queued the frame.
+        final CountDownLatch latch = new CountDownLatch(1);
+        mActivityRule.runOnUiThread(() -> {
+            mEmbeddedView.getViewTreeObserver().registerFrameCommitCallback(
+                latch::countDown);
+            mEmbeddedView.invalidate();
+        });
+        assertTrue(latch.await(1, TimeUnit.SECONDS));
 
         // But after the click should hit.
         CtsTouchUtils.emulateTapOnViewCenter(mInstrumentation, mActivityRule, mSurfaceView);