Commit 59775686 authored by Alice Wang's avatar Alice Wang Committed by Commit Bot

[Android][Test] Destroy mSetActivity in ChromeActivityTestRule

This CL destroys mSetActivity in ChromeActivityTestRule. Prior to this
CL, the teardown of ChromeActivityTestRule only ends the tasks in
ActivityManager. As mSetActivity.finish() is not called before the
teardown, no Activity.finish() task is submitted to ActivityManager.
Thus we still have the ChromeActivity unfinished after the teardown.

Bug: 1083138
Change-Id: If0ee66770d66ef451fcb0188907ba759d501291f
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2234517
Commit-Queue: Alice Wang <aliceywang@chromium.org>
Reviewed-by: default avatarTed Choc <tedchoc@chromium.org>
Cr-Commit-Position: refs/heads/master@{#777920}
parent c5ec0665
...@@ -150,12 +150,24 @@ public class ChromeActivityTestRule<T extends ChromeActivity> extends ActivityTe ...@@ -150,12 +150,24 @@ public class ChromeActivityTestRule<T extends ChromeActivity> extends ActivityTe
private void ruleTearDown() { private void ruleTearDown() {
try { try {
ApplicationTestUtils.tearDown(InstrumentationRegistry.getTargetContext()); ApplicationTestUtils.tearDown(InstrumentationRegistry.getTargetContext());
waitForActivityFinished();
Thread.setDefaultUncaughtExceptionHandler(mDefaultUncaughtExceptionHandler); Thread.setDefaultUncaughtExceptionHandler(mDefaultUncaughtExceptionHandler);
} catch (Exception e) { } catch (Exception e) {
throw new RuntimeException("Failed to tearDown", e); throw new RuntimeException("Failed to tearDown", e);
} }
} }
private void waitForActivityFinished() {
if (mSetActivity == null) return;
try {
ApplicationTestUtils.waitForActivityState(mSetActivity, ActivityState.DESTROYED);
} catch (Exception e) {
Log.e(TAG, "Cannot finish activity, exception:" + e);
} finally {
mSetActivity = null;
}
}
// TODO(yolandyan): remove this once startActivityCompletely is refactored out of // TODO(yolandyan): remove this once startActivityCompletely is refactored out of
// ChromeActivityTestRule // ChromeActivityTestRule
@Override @Override
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment