Commit 01a6c3bb authored by Michael Thiessen's avatar Michael Thiessen Committed by Chromium LUCI CQ

Return to Launcher after Settings workaround for Activity finish on L

We need to actually launch Settings for the workaround to work, so
to make sure later tests don't fail because the settings workaround was
already applied, we need to return to the launcher after launching
settings.

I'm not actually sure about anything I just said though, as these flakes
are like 1/100 and while I couldn't repro locally after this fix they
could still be present.

Example flake here on MainSettingsFragmentTest:
https://ci.chromium.org/p/chromium/builders/ci/Lollipop%20Phone%20Tester/28012

Bug: 1152413
Change-Id: I1dd77366c2eb9c422dbe75e3efecb3e29ed00920
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2566352
Commit-Queue: Michael Thiessen <mthiesse@chromium.org>
Reviewed-by: default avatarYaron Friedman <yfriedman@chromium.org>
Cr-Commit-Position: refs/heads/master@{#832490}
parent 3ecc5cc0
...@@ -5,6 +5,7 @@ ...@@ -5,6 +5,7 @@
package org.chromium.base.test.util; package org.chromium.base.test.util;
import android.app.Activity; import android.app.Activity;
import android.content.Context;
import android.content.Intent; import android.content.Intent;
import android.os.Build; import android.os.Build;
import android.provider.Settings; import android.provider.Settings;
...@@ -48,11 +49,10 @@ public class ApplicationTestUtils { ...@@ -48,11 +49,10 @@ public class ApplicationTestUtils {
activity.finish(); activity.finish();
} }
}); });
final String error = "Failed to finish the Activity. Did you start a second Activity and "
+ "not finish it?";
try { try {
waitForActivityState( waitForActivityState(error, activity, Stage.DESTROYED);
"Failed to finish the Activity. Did you start a second Activity and not finish"
+ " it?",
activity, Stage.DESTROYED);
} catch (Throwable e) { } catch (Throwable e) {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) throw e; if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) throw e;
...@@ -61,13 +61,22 @@ public class ApplicationTestUtils { ...@@ -61,13 +61,22 @@ public class ApplicationTestUtils {
Intent intent = new Intent(Settings.ACTION_SETTINGS); Intent intent = new Intent(Settings.ACTION_SETTINGS);
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
activity.startActivity(intent); activity.startActivity(intent);
waitForActivityState( try {
"Failed to finish the Activity. Did you start a second Activity and not finish" waitForActivityState(error, activity, Stage.DESTROYED);
+ " it?", } finally {
activity, Stage.DESTROYED); // We can't finish com.android.settings, so return to launcher instead.
fireHomescreenIntent(activity);
}
} }
} }
private static void fireHomescreenIntent(Context context) {
Intent intent = new Intent(Intent.ACTION_MAIN);
intent.addCategory(Intent.CATEGORY_HOME);
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
context.startActivity(intent);
}
/** /**
* Recreates the provided Activity, returning the newly created Activity once it's finished * Recreates the provided Activity, returning the newly created Activity once it's finished
* starting up. * starting up.
......
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