From de4ff4c5ec71698fb4d2ff9ce4572929d70d477a Mon Sep 17 00:00:00 2001 From: tonihei Date: Mon, 19 Jun 2017 06:23:22 -0700 Subject: [PATCH] Extend HostActivity for reuse and silent timeout. Added option to fail on timeout. Also reset internals in all cases such that the activity can be used more than once. ------------- Created by MOE: https://github.com/google/moe MOE_MIGRATED_REVID=159419176 --- .../exoplayer2/testutil/HostActivity.java | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/testutils/src/main/java/com/google/android/exoplayer2/testutil/HostActivity.java b/testutils/src/main/java/com/google/android/exoplayer2/testutil/HostActivity.java index ecbe00b487..831344aa8b 100644 --- a/testutils/src/main/java/com/google/android/exoplayer2/testutil/HostActivity.java +++ b/testutils/src/main/java/com/google/android/exoplayer2/testutil/HostActivity.java @@ -101,6 +101,17 @@ public final class HostActivity extends Activity implements SurfaceHolder.Callba * is exceeded then the test will fail. */ public void runTest(final HostedTest hostedTest, long timeoutMs) { + runTest(hostedTest, timeoutMs, true); + } + + /** + * Executes a {@link HostedTest} inside the host. + * + * @param hostedTest The test to execute. + * @param timeoutMs The number of milliseconds to wait for the test to finish. + * @param failOnTimeout Whether the test fails when the timeout is exceeded. + */ + public void runTest(final HostedTest hostedTest, long timeoutMs, boolean failOnTimeout) { Assertions.checkArgument(timeoutMs > 0); Assertions.checkState(Thread.currentThread() != getMainLooper().getThread()); @@ -131,7 +142,11 @@ public final class HostActivity extends Activity implements SurfaceHolder.Callba } else { String message = "Test timed out after " + timeoutMs + " ms."; Log.e(TAG, message); - fail(message); + if (failOnTimeout) { + fail(message); + } + maybeStopHostedTest(); + hostedTestStoppedCondition.block(); } }