Added new Autofill test.
Test: LoginActivityTest.testPopupGoesAwayWhenServiceIsChanged()
Bug: 62836529
Change-Id: Ic5216764d2ad9b38565b5e04c8869f7bd0452d16
diff --git a/tests/autofillservice/AndroidManifest.xml b/tests/autofillservice/AndroidManifest.xml
index 173f122..4bb8fa6 100644
--- a/tests/autofillservice/AndroidManifest.xml
+++ b/tests/autofillservice/AndroidManifest.xml
@@ -74,6 +74,14 @@
<action android:name="android.service.autofill.AutofillService" />
</intent-filter>
</service>
+ <service
+ android:name=".NoOpAutofillService"
+ android:label="NoOpAutofillService"
+ android:permission="android.permission.BIND_AUTOFILL_SERVICE" >
+ <intent-filter>
+ <action android:name="android.service.autofill.AutofillService" />
+ </intent-filter>
+ </service>
</application>
<instrumentation
diff --git a/tests/autofillservice/src/android/autofillservice/cts/LoginActivityTest.java b/tests/autofillservice/src/android/autofillservice/cts/LoginActivityTest.java
index 3ff26db..ae61bb3 100644
--- a/tests/autofillservice/src/android/autofillservice/cts/LoginActivityTest.java
+++ b/tests/autofillservice/src/android/autofillservice/cts/LoginActivityTest.java
@@ -99,8 +99,8 @@
public class LoginActivityTest extends AutoFillServiceTestCase {
@Rule
- public final ActivityTestRule<LoginActivity> mActivityRule = new ActivityTestRule<LoginActivity>(
- LoginActivity.class);
+ public final ActivityTestRule<LoginActivity> mActivityRule =
+ new ActivityTestRule<LoginActivity>(LoginActivity.class);
private LoginActivity mActivity;
@@ -2961,4 +2961,29 @@
setUserComplete(getContext(), true);
}
}
+
+ @Test
+ public void testPopupGoesAwayWhenServiceIsChanged() throws Exception {
+ // Set service.
+ enableService();
+
+ // Set expectations.
+ sReplier.addResponse(new CannedDataset.Builder()
+ .setField(ID_USERNAME, "dude")
+ .setField(ID_PASSWORD, "sweet")
+ .setPresentation(createPresentation("The Dude"))
+ .build());
+ mActivity.expectAutoFill("dude", "sweet");
+
+ // Trigger auto-fill.
+ mActivity.onUsername(View::requestFocus);
+ sReplier.getNextFillRequest();
+ sUiBot.assertDatasets("The Dude");
+
+ // Now disable service by setting another service
+ Helper.enableAutofillService(getContext(), NoOpAutofillService.SERVICE_NAME);
+
+ // ...and make sure popup's gone
+ sUiBot.assertNoDatasets();
+ }
}
diff --git a/tests/autofillservice/src/android/autofillservice/cts/NoOpAutofillService.java b/tests/autofillservice/src/android/autofillservice/cts/NoOpAutofillService.java
new file mode 100644
index 0000000..4255b6d
--- /dev/null
+++ b/tests/autofillservice/src/android/autofillservice/cts/NoOpAutofillService.java
@@ -0,0 +1,41 @@
+/*
+ * Copyright (C) 2017 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package android.autofillservice.cts;
+
+import android.os.CancellationSignal;
+import android.service.autofill.AutofillService;
+import android.service.autofill.FillCallback;
+import android.service.autofill.FillRequest;
+import android.service.autofill.SaveCallback;
+import android.service.autofill.SaveRequest;
+
+/**
+ * {@link AutofillService} implementation that does not do anything...
+ */
+public class NoOpAutofillService extends AutofillService {
+
+ static final String SERVICE_NAME = NoOpAutofillService.class.getPackage().getName()
+ + "/." + NoOpAutofillService.class.getSimpleName();
+
+ @Override
+ public void onFillRequest(FillRequest request, CancellationSignal cancellationSignal,
+ FillCallback callback) {
+ }
+
+ @Override
+ public void onSaveRequest(SaveRequest request, SaveCallback callback) {
+ }
+}