summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
author Joanne Chung <joannechung@google.com> 2020-09-24 02:25:09 +0000
committer Android (Google) Code Review <android-gerrit@google.com> 2020-09-24 02:25:09 +0000
commit79fc5e06f03f8da7f71a2ebe6eaf38f18cca78cd (patch)
tree859b27e9cc7d606b9203c3e21969e0ab12691a46
parentdb4b7127a27b9ba47c4490d4777d6ea0ad73742c (diff)
parent92249244647b81485fe47f53c7730c723db486bd (diff)
Merge "Disable the services before each test"
-rw-r--r--apct-tests/perftests/autofill/src/android/view/autofill/AbstractAutofillPerfTestCase.java48
-rw-r--r--apct-tests/perftests/autofill/src/android/view/autofill/AutofillTestWatcher.java43
-rw-r--r--apct-tests/perftests/autofill/src/android/view/autofill/LoginTest.java18
-rw-r--r--apct-tests/perftests/autofill/src/android/view/autofill/MyAutofillService.java1
4 files changed, 74 insertions, 36 deletions
diff --git a/apct-tests/perftests/autofill/src/android/view/autofill/AbstractAutofillPerfTestCase.java b/apct-tests/perftests/autofill/src/android/view/autofill/AbstractAutofillPerfTestCase.java
index d97b5003b252..54e1860d3390 100644
--- a/apct-tests/perftests/autofill/src/android/view/autofill/AbstractAutofillPerfTestCase.java
+++ b/apct-tests/perftests/autofill/src/android/view/autofill/AbstractAutofillPerfTestCase.java
@@ -16,19 +16,23 @@
package android.view.autofill;
+import static com.android.compatibility.common.util.ShellUtils.runShellCommand;
+
import static org.junit.Assert.assertTrue;
import android.os.Looper;
import android.perftests.utils.PerfStatusReporter;
import android.perftests.utils.PerfTestActivity;
-import android.perftests.utils.SettingsHelper;
import android.perftests.utils.SettingsStateKeeperRule;
import android.provider.Settings;
+import android.util.Log;
import androidx.test.InstrumentationRegistry;
import androidx.test.rule.ActivityTestRule;
+import org.junit.AfterClass;
import org.junit.Before;
+import org.junit.BeforeClass;
import org.junit.ClassRule;
import org.junit.Rule;
import org.junit.rules.RuleChain;
@@ -38,6 +42,8 @@ import org.junit.rules.RuleChain;
*/
public abstract class AbstractAutofillPerfTestCase {
+ private static final String TAG = "AbstractAutofillPerfTestCase";
+
@ClassRule
public static final SettingsStateKeeperRule mServiceSettingsKeeper =
new SettingsStateKeeperRule(InstrumentationRegistry.getTargetContext(),
@@ -60,6 +66,27 @@ public abstract class AbstractAutofillPerfTestCase {
mLayoutId = layoutId;
}
+ @BeforeClass
+ public static void disableDefaultAugmentedService() {
+ Log.v(TAG, "@BeforeClass: disableDefaultAugmentedService()");
+ setDefaultAugmentedAutofillServiceEnabled(false);
+ }
+
+ @AfterClass
+ public static void enableDefaultAugmentedService() {
+ Log.v(TAG, "@AfterClass: enableDefaultAugmentedService()");
+ setDefaultAugmentedAutofillServiceEnabled(true);
+ }
+
+ /**
+ * Enables / disables the default augmented autofill service.
+ */
+ private static void setDefaultAugmentedAutofillServiceEnabled(boolean enabled) {
+ Log.d(TAG, "setDefaultAugmentedAutofillServiceEnabled(): " + enabled);
+ runShellCommand("cmd autofill set default-augmented-service-enabled 0 %s",
+ Boolean.toString(enabled));
+ }
+
/**
* Prepares the activity so that by the time the test is run it has reference to its fields.
*/
@@ -80,23 +107,4 @@ public abstract class AbstractAutofillPerfTestCase {
* Initializes the {@link PerfTestActivity} after it was launched.
*/
protected abstract void onCreate(PerfTestActivity activity);
-
- /**
- * Uses the {@code settings} binary to set the autofill service.
- */
- protected void setService() {
- SettingsHelper.syncSet(InstrumentationRegistry.getTargetContext(),
- SettingsHelper.NAMESPACE_SECURE,
- Settings.Secure.AUTOFILL_SERVICE,
- MyAutofillService.COMPONENT_NAME);
- }
-
- /**
- * Uses the {@code settings} binary to reset the autofill service.
- */
- protected void resetService() {
- SettingsHelper.syncDelete(InstrumentationRegistry.getTargetContext(),
- SettingsHelper.NAMESPACE_SECURE,
- Settings.Secure.AUTOFILL_SERVICE);
- }
}
diff --git a/apct-tests/perftests/autofill/src/android/view/autofill/AutofillTestWatcher.java b/apct-tests/perftests/autofill/src/android/view/autofill/AutofillTestWatcher.java
index f1f812ddf1c7..2475d988f107 100644
--- a/apct-tests/perftests/autofill/src/android/view/autofill/AutofillTestWatcher.java
+++ b/apct-tests/perftests/autofill/src/android/view/autofill/AutofillTestWatcher.java
@@ -18,10 +18,13 @@ package android.view.autofill;
import static com.android.compatibility.common.util.ShellUtils.runShellCommand;
+import android.perftests.utils.SettingsHelper;
+import android.provider.Settings;
import android.util.Log;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
+import androidx.test.InstrumentationRegistry;
import org.junit.rules.TestWatcher;
import org.junit.runner.Description;
@@ -44,19 +47,26 @@ final class AutofillTestWatcher extends TestWatcher {
@Override
protected void starting(Description description) {
super.starting(description);
+ final String testName = description.getDisplayName();
+ Log.i(TAG, "Starting " + testName);
enableVerboseLog();
- MyAutofillService.resetStaticState();
- MyAutofillService.setEnabled(true);
+ // Prepare the service before each test.
+ // Disable the current AutofillService.
+ resetAutofillService();
+ // Set MyAutofillService status enable, it can start to accept the calls.
+ enableMyAutofillService();
setServiceWatcher();
}
@Override
protected void finished(Description description) {
super.finished(description);
-
+ final String testName = description.getDisplayName();
+ Log.i(TAG, "Finished " + testName);
restoreLogLevel();
- disableService();
+ // Set MyAutofillService status disable, so the calls are ignored.
+ disableMyAutofillService();
clearServiceWatcher();
}
@@ -67,12 +77,31 @@ final class AutofillTestWatcher extends TestWatcher {
}
}
- private void enableService() {
+ /**
+ * Uses the {@code settings} binary to set the autofill service.
+ */
+ void setAutofillService() {
+ SettingsHelper.syncSet(InstrumentationRegistry.getTargetContext(),
+ SettingsHelper.NAMESPACE_SECURE,
+ Settings.Secure.AUTOFILL_SERVICE,
+ MyAutofillService.COMPONENT_NAME);
+ }
+
+ /**
+ * Uses the {@code settings} binary to reset the autofill service.
+ */
+ void resetAutofillService() {
+ SettingsHelper.syncDelete(InstrumentationRegistry.getTargetContext(),
+ SettingsHelper.NAMESPACE_SECURE,
+ Settings.Secure.AUTOFILL_SERVICE);
+ }
+
+ private void enableMyAutofillService() {
MyAutofillService.resetStaticState();
MyAutofillService.setEnabled(true);
}
- private void disableService() {
+ private void disableMyAutofillService() {
// Must disable service so calls are ignored in case of errors during the test case;
// otherwise, other tests will fail because these calls are made in the UI thread (as both
// the service, the tests, and the app run in the same process).
@@ -88,7 +117,7 @@ final class AutofillTestWatcher extends TestWatcher {
}
private void restoreLogLevel() {
- Log.w(TAG, "restoreLogLevel to " + mOriginalLogLevel);
+ Log.d(TAG, "restoreLogLevel to " + mOriginalLogLevel);
if (!mOriginalLogLevel.equals("verbose")) {
runShellCommand("cmd autofill set log_level %s", mOriginalLogLevel);
}
diff --git a/apct-tests/perftests/autofill/src/android/view/autofill/LoginTest.java b/apct-tests/perftests/autofill/src/android/view/autofill/LoginTest.java
index 99b2590e4049..37b4bde034df 100644
--- a/apct-tests/perftests/autofill/src/android/view/autofill/LoginTest.java
+++ b/apct-tests/perftests/autofill/src/android/view/autofill/LoginTest.java
@@ -55,7 +55,7 @@ public class LoginTest extends AbstractAutofillPerfTestCase {
*/
@Test
public void testFocus_noService() throws Throwable {
- resetService();
+ mTestWatcher.resetAutofillService();
BenchmarkState state = mPerfStatusReporter.getBenchmarkState();
while (state.keepRunning()) {
@@ -73,7 +73,7 @@ public class LoginTest extends AbstractAutofillPerfTestCase {
@Test
public void testFocus_serviceDoesNotAutofill() throws Throwable {
MyAutofillService.newCannedResponse().reply();
- setService();
+ mTestWatcher.setAutofillService();
// Must first focus in a field to trigger autofill and wait for service response
// outside the loop
@@ -102,7 +102,7 @@ public class LoginTest extends AbstractAutofillPerfTestCase {
.setUsername(mUsername.getAutofillId(), "user")
.setPassword(mPassword.getAutofillId(), "pass")
.reply();
- setService();
+ mTestWatcher.setAutofillService();
// Callback is used to slow down the calls made to the autofill server so the
// app is not crashed due to binder exhaustion. But the time spent waiting for the callbacks
@@ -157,7 +157,7 @@ public class LoginTest extends AbstractAutofillPerfTestCase {
.setUsername(mUsername.getAutofillId(), "user")
.setIgnored(mPassword.getAutofillId())
.reply();
- setService();
+ mTestWatcher.setAutofillService();
// Callback is used to slow down the calls made to the autofill server so the
// app is not crashed due to binder exhaustion. But the time spent waiting for the callbacks
@@ -201,7 +201,7 @@ public class LoginTest extends AbstractAutofillPerfTestCase {
*/
@Test
public void testChange_noService() throws Throwable {
- resetService();
+ mTestWatcher.resetAutofillService();
changeTest(false);
}
@@ -213,7 +213,7 @@ public class LoginTest extends AbstractAutofillPerfTestCase {
@Test
public void testChange_serviceDoesNotAutofill() throws Throwable {
MyAutofillService.newCannedResponse().reply();
- setService();
+ mTestWatcher.setAutofillService();
changeTest(true);
}
@@ -227,7 +227,7 @@ public class LoginTest extends AbstractAutofillPerfTestCase {
.setUsername(mUsername.getAutofillId(), "user")
.setPassword(mPassword.getAutofillId(), "pass")
.reply();
- setService();
+ mTestWatcher.setAutofillService();
changeTest(true);
}
@@ -242,7 +242,7 @@ public class LoginTest extends AbstractAutofillPerfTestCase {
.setUsername(mUsername.getAutofillId(), "user")
.setIgnored(mPassword.getAutofillId())
.reply();
- setService();
+ mTestWatcher.setAutofillService();
changeTest(true);
}
@@ -274,7 +274,7 @@ public class LoginTest extends AbstractAutofillPerfTestCase {
.setUsername(mUsername.getAutofillId(), "user")
.setPassword(mPassword.getAutofillId(), "pass")
.reply();
- setService();
+ mTestWatcher.setAutofillService();
MyAutofillCallback callback = new MyAutofillCallback();
mAfm.registerCallback(callback);
diff --git a/apct-tests/perftests/autofill/src/android/view/autofill/MyAutofillService.java b/apct-tests/perftests/autofill/src/android/view/autofill/MyAutofillService.java
index 77c1b85b10ab..ddac68b93ebd 100644
--- a/apct-tests/perftests/autofill/src/android/view/autofill/MyAutofillService.java
+++ b/apct-tests/perftests/autofill/src/android/view/autofill/MyAutofillService.java
@@ -126,6 +126,7 @@ public class MyAutofillService extends AutofillService {
onError("ignoring onFillRequest(): response not set", callback);
return;
}
+ // TODO(b/162216576): fix error FillResponse
Dataset.Builder dataset = new Dataset.Builder(newDatasetPresentation("dataset"));
boolean hasData = false;
if (response.mUsername != null) {