Commit 20c9db4a authored by Boris Sazonov's avatar Boris Sazonov Committed by Commit Bot

[Android] Fix ChromeLauncherActivity capturing in testAbortFirstRun

This CL fixes FirstRunIntegrationTest.testAbortFirstRun flakiness on
Android M+. testAbortFirstRun has been setting up ActivityMonitor for
ChromeLauncherActivity after starting FRE and checked that the activity
was finishing. But ChromeLauncherActivity is actually started before
FirstRunActivity, so waitForMonitorWithTimeout was returning null in
some runs on Android M+.
This CL captures ChromeLauncherActivity before starting FRE and checks
that both FirstRunActivity and ChromeLauncherActivity are finishing
after FRE is aborted.

Bug: 758751
Change-Id: I03fe5b973faf02d63eb528e90ba1e6efb839f0f8
Reviewed-on: https://chromium-review.googlesource.com/956182Reviewed-by: default avatarDavid Trainor <dtrainor@chromium.org>
Commit-Queue: Boris Sazonov <bsazonov@chromium.org>
Cr-Commit-Position: refs/heads/master@{#542878}
parent 48d1ecaf
......@@ -186,9 +186,12 @@ public class FirstRunIntegrationTest {
@Test
@SmallTest
public void testAbortFirstRun() throws Exception {
Instrumentation instrumentation = InstrumentationRegistry.getInstrumentation();
final ActivityMonitor launcherActivityMonitor =
new ActivityMonitor(ChromeLauncherActivity.class.getName(), null, false);
instrumentation.addMonitor(launcherActivityMonitor);
final ActivityMonitor freMonitor =
new ActivityMonitor(FirstRunActivity.class.getName(), null, false);
Instrumentation instrumentation = InstrumentationRegistry.getInstrumentation();
instrumentation.addMonitor(freMonitor);
final Context context = instrumentation.getTargetContext();
......@@ -197,31 +200,37 @@ public class FirstRunIntegrationTest {
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
context.startActivity(intent);
// Because the AsyncInitializationActivity notices that the FRE hasn't been run yet, it
// redirects to it. Once the user closes the FRE, the user should be kicked back into the
// startup flow where they were interrupted.
final Activity chromeLauncherActivity = instrumentation.waitForMonitorWithTimeout(
launcherActivityMonitor, CriteriaHelper.DEFAULT_MAX_TIME_TO_POLL);
Assert.assertNotNull(chromeLauncherActivity);
// Because the ChromeLauncherActivity notices that the FRE hasn't been run yet, it
// redirects to it.
mActivity = instrumentation.waitForMonitorWithTimeout(
freMonitor, CriteriaHelper.DEFAULT_MAX_TIME_TO_POLL);
Assert.assertNotNull(mActivity);
ActivityMonitor activityMonitor =
new ActivityMonitor(ChromeLauncherActivity.class.getName(), null, false);
instrumentation.addMonitor(activityMonitor);
// Once the user closes the FRE, the user should be kicked back into the
// startup flow where they were interrupted.
Assert.assertEquals(0, mTestObserver.abortFirstRunExperienceCallback.getCallCount());
mActivity.onBackPressed();
mTestObserver.abortFirstRunExperienceCallback.waitForCallback(
"FirstRunActivity didn't abort", 0);
mActivity = instrumentation.waitForMonitorWithTimeout(
activityMonitor, CriteriaHelper.DEFAULT_MAX_TIME_TO_POLL);
Assert.assertNotNull(mActivity);
CriteriaHelper.pollInstrumentationThread(new Criteria() {
@Override
public boolean isSatisfied() {
return mActivity.isFinishing();
}
});
// ChromeLauncherActivity should finish if FRE was aborted.
CriteriaHelper.pollInstrumentationThread(new Criteria() {
@Override
public boolean isSatisfied() {
return chromeLauncherActivity.isFinishing();
}
});
}
@Test
......
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