summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
author Chavi Weingarten <chaviw@google.com> 2023-09-18 18:20:16 +0000
committer Chavi Weingarten <chaviw@google.com> 2023-09-18 18:49:06 +0000
commitae13571f09dee996a0c858d2690cd7671e51d15c (patch)
treeb8a0ed3c989361471a518a46f99de2784ccbaa0a
parent1f5b85230ab1d9ac886d29ccff8dc440242bf986 (diff)
Dump state if TrustedPresentationCallback test fails
Test: TrustedPresentationCallbackTest Bug: 300720417 Change-Id: I30902ff957915db5bc3ab06afb73c79850f3f81b
-rw-r--r--services/tests/wmtests/src/com/android/server/wm/TrustedPresentationCallbackTest.java79
1 files changed, 46 insertions, 33 deletions
diff --git a/services/tests/wmtests/src/com/android/server/wm/TrustedPresentationCallbackTest.java b/services/tests/wmtests/src/com/android/server/wm/TrustedPresentationCallbackTest.java
index f173d661c0a4..c5dd447b5b0c 100644
--- a/services/tests/wmtests/src/com/android/server/wm/TrustedPresentationCallbackTest.java
+++ b/services/tests/wmtests/src/com/android/server/wm/TrustedPresentationCallbackTest.java
@@ -18,16 +18,16 @@ package com.android.server.wm;
import static android.server.wm.ActivityManagerTestBase.createFullscreenActivityScenarioRule;
import static android.server.wm.BuildUtils.HW_TIMEOUT_MULTIPLIER;
-
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;
import android.app.Activity;
import android.platform.test.annotations.Presubmit;
-import android.util.Log;
+import android.server.wm.CtsWindowInfoUtils;
import android.view.SurfaceControl;
import android.view.SurfaceControl.TrustedPresentationThresholds;
+import androidx.annotation.GuardedBy;
import androidx.test.ext.junit.rules.ActivityScenarioRule;
import com.android.server.wm.utils.CommonUtils;
@@ -36,9 +36,8 @@ import org.junit.After;
import org.junit.Before;
import org.junit.Rule;
import org.junit.Test;
+import org.junit.rules.TestName;
-import java.util.concurrent.CountDownLatch;
-import java.util.concurrent.TimeUnit;
import java.util.function.Consumer;
/**
@@ -53,6 +52,15 @@ public class TrustedPresentationCallbackTest {
private static final float FRACTION_VISIBLE = 0.1f;
+ private final Object mResultsLock = new Object();
+ @GuardedBy("mResultsLock")
+ private boolean mResult;
+ @GuardedBy("mResultsLock")
+ private boolean mReceivedResults;
+
+ @Rule
+ public TestName mName = new TestName();
+
@Rule
public ActivityScenarioRule<TestActivity> mActivityRule = createFullscreenActivityScenarioRule(
TestActivity.class);
@@ -71,36 +79,32 @@ public class TrustedPresentationCallbackTest {
@Test
public void testAddTrustedPresentationListenerOnWindow() throws InterruptedException {
- boolean[] results = new boolean[1];
- CountDownLatch receivedResults = new CountDownLatch(1);
TrustedPresentationThresholds thresholds = new TrustedPresentationThresholds(
1 /* minAlpha */, FRACTION_VISIBLE, STABILITY_REQUIREMENT_MS);
SurfaceControl.Transaction t = new SurfaceControl.Transaction();
mActivity.getWindow().getRootSurfaceControl().addTrustedPresentationCallback(t, thresholds,
Runnable::run, inTrustedPresentationState -> {
- Log.d(TAG, "onTrustedPresentationChanged " + inTrustedPresentationState);
- results[0] = inTrustedPresentationState;
- receivedResults.countDown();
+ synchronized (mResultsLock) {
+ mResult = inTrustedPresentationState;
+ mReceivedResults = true;
+ mResultsLock.notify();
+ }
});
t.apply();
-
- assertTrue("Timed out waiting for results",
- receivedResults.await(WAIT_TIME_MS, TimeUnit.MILLISECONDS));
- assertTrue(results[0]);
+ synchronized (mResultsLock) {
+ assertResults();
+ }
}
@Test
public void testRemoveTrustedPresentationListenerOnWindow() throws InterruptedException {
- final Object resultsLock = new Object();
- boolean[] results = new boolean[1];
- boolean[] receivedResults = new boolean[1];
TrustedPresentationThresholds thresholds = new TrustedPresentationThresholds(
1 /* minAlpha */, FRACTION_VISIBLE, STABILITY_REQUIREMENT_MS);
Consumer<Boolean> trustedPresentationCallback = inTrustedPresentationState -> {
- synchronized (resultsLock) {
- results[0] = inTrustedPresentationState;
- receivedResults[0] = true;
- resultsLock.notify();
+ synchronized (mResultsLock) {
+ mResult = inTrustedPresentationState;
+ mReceivedResults = true;
+ mResultsLock.notify();
}
};
SurfaceControl.Transaction t = new SurfaceControl.Transaction();
@@ -108,32 +112,41 @@ public class TrustedPresentationCallbackTest {
Runnable::run, trustedPresentationCallback);
t.apply();
- synchronized (resultsLock) {
- if (!receivedResults[0]) {
- resultsLock.wait(WAIT_TIME_MS);
+ synchronized (mResultsLock) {
+ if (!mReceivedResults) {
+ mResultsLock.wait(WAIT_TIME_MS);
}
- // Make sure we received the results and not just timed out
- assertTrue("Timed out waiting for results", receivedResults[0]);
- assertTrue(results[0]);
-
+ assertResults();
// reset the state
- receivedResults[0] = false;
+ mReceivedResults = false;
}
mActivity.getWindow().getRootSurfaceControl().removeTrustedPresentationCallback(t,
trustedPresentationCallback);
t.apply();
- synchronized (resultsLock) {
- if (!receivedResults[0]) {
- resultsLock.wait(WAIT_TIME_MS);
+ synchronized (mResultsLock) {
+ if (!mReceivedResults) {
+ mResultsLock.wait(WAIT_TIME_MS);
}
// Ensure we waited the full time and never received a notify on the result from the
// callback.
- assertFalse("Should never have received a callback", receivedResults[0]);
+ assertFalse("Should never have received a callback", mReceivedResults);
// results shouldn't have changed.
- assertTrue(results[0]);
+ assertTrue(mResult);
+ }
+ }
+
+ @GuardedBy("mResultsLock")
+ private void assertResults() throws InterruptedException {
+ mResultsLock.wait(WAIT_TIME_MS);
+
+ if (!mReceivedResults) {
+ CtsWindowInfoUtils.dumpWindowsOnScreen(TAG, "test " + mName.getMethodName());
}
+ // Make sure we received the results and not just timed out
+ assertTrue("Timed out waiting for results", mReceivedResults);
+ assertTrue(mResult);
}
public static class TestActivity extends Activity {