summaryrefslogtreecommitdiffstats
path: root/tests/src/com
diff options
context:
space:
mode:
authorvadimt <vadimt@google.com>2018-12-11 17:59:36 -0800
committervadimt <vadimt@google.com>2018-12-17 14:41:20 -0800
commit00d42552725a215e4b98c84e1238a0039582286b (patch)
tree7a34b2b829bc7e96fec8b1c9fd6a00b182d198fb /tests/src/com
parent381a75c19497342c1ffe62aa6553425231eb3da5 (diff)
downloadandroid_packages_apps_Trebuchet-00d42552725a215e4b98c84e1238a0039582286b.tar.gz
android_packages_apps_Trebuchet-00d42552725a215e4b98c84e1238a0039582286b.tar.bz2
android_packages_apps_Trebuchet-00d42552725a215e4b98c84e1238a0039582286b.zip
Adding tests that would reliably reproduce shifted search.
This would guaranteed to repro b/118441555 before it was fixed. The test doesn't use the most powerful feature of race condition reproducer, which is enumerating all possible event sequences. Instead, it uses explicit repro sequences, which makes the test much faster. Bug: 120628042 Test: The added test Change-Id: I89a7a9964f160a8a20ba3d9dda2f248237713014
Diffstat (limited to 'tests/src/com')
-rw-r--r--tests/src/com/android/launcher3/ui/AbstractLauncherUiTest.java22
-rw-r--r--tests/src/com/android/launcher3/util/RaceConditionReproducer.java9
2 files changed, 31 insertions, 0 deletions
diff --git a/tests/src/com/android/launcher3/ui/AbstractLauncherUiTest.java b/tests/src/com/android/launcher3/ui/AbstractLauncherUiTest.java
index bc5aaeeb7..338fd853e 100644
--- a/tests/src/com/android/launcher3/ui/AbstractLauncherUiTest.java
+++ b/tests/src/com/android/launcher3/ui/AbstractLauncherUiTest.java
@@ -17,6 +17,7 @@ package com.android.launcher3.ui;
import static androidx.test.InstrumentationRegistry.getInstrumentation;
+import static org.junit.Assert.assertTrue;
import static org.junit.Assert.fail;
import android.app.Instrumentation;
@@ -25,11 +26,13 @@ import android.content.Context;
import android.content.Intent;
import android.content.IntentFilter;
import android.content.pm.LauncherActivityInfo;
+import android.content.pm.PackageManager;
import android.os.Process;
import android.os.RemoteException;
import android.view.Surface;
import androidx.test.InstrumentationRegistry;
+import androidx.test.uiautomator.By;
import androidx.test.uiautomator.BySelector;
import androidx.test.uiautomator.Direction;
import androidx.test.uiautomator.UiDevice;
@@ -77,6 +80,7 @@ public abstract class AbstractLauncherUiTest {
public static final long SHORT_UI_TIMEOUT= 300;
public static final long DEFAULT_UI_TIMEOUT = 10000;
+ protected static final int LONG_WAIT_TIME_MS = 60000;
protected MainThreadExecutor mMainThreadExecutor = new MainThreadExecutor();
protected final UiDevice mDevice;
@@ -325,4 +329,22 @@ public abstract class AbstractLauncherUiTest {
return intent == null ? null : (Intent) intent.getParcelableExtra(Intent.EXTRA_INTENT);
}
}
+
+ protected void startAppFast(String packageName) {
+ final Instrumentation instrumentation = getInstrumentation();
+ final Intent intent = instrumentation.getContext().getPackageManager().
+ getLaunchIntentForPackage(packageName);
+ intent.addCategory(Intent.CATEGORY_LAUNCHER);
+ intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
+ instrumentation.getTargetContext().startActivity(intent);
+ assertTrue(packageName + " didn't start",
+ mDevice.wait(Until.hasObject(By.pkg(packageName).depth(0)), LONG_WAIT_TIME_MS));
+ }
+
+ protected String resolveSystemApp(String category) {
+ return getInstrumentation().getContext().getPackageManager().resolveActivity(
+ new Intent(Intent.ACTION_MAIN).addCategory(category),
+ PackageManager.MATCH_SYSTEM_ONLY).
+ activityInfo.packageName;
+ }
}
diff --git a/tests/src/com/android/launcher3/util/RaceConditionReproducer.java b/tests/src/com/android/launcher3/util/RaceConditionReproducer.java
index c4350de0b..316e40d82 100644
--- a/tests/src/com/android/launcher3/util/RaceConditionReproducer.java
+++ b/tests/src/com/android/launcher3/util/RaceConditionReproducer.java
@@ -43,6 +43,11 @@ import java.util.concurrent.TimeUnit;
* executing events in previously unseen order. It does it by postponing execution of threads that
* would lead to an already seen sequence.
*
+ * If an event A occurs before event B in the sequence, this is how execution order looks like:
+ * Events: ... A ... B ...
+ * Events and instructions, guaranteed order:
+ * (instructions executed prior to A) A ... B (instructions executed after B)
+ *
* Each iteration has 3 parts (phases).
* Phase 1. Picking a previously seen event subsequence that we believe can have previously unseen
* continuations. Reproducing this sequence by pausing threads that would lead to other sequences.
@@ -178,6 +183,10 @@ public class RaceConditionReproducer implements RaceConditionTracker.EventProces
mReproString = reproString;
}
+ public RaceConditionReproducer(String... reproSequence) {
+ this(String.join("|", reproSequence));
+ }
+
public synchronized String getCurrentSequenceString() {
return mCurrentSequence.toString();
}