Allow custom buttons in autofill UI
Test: this is the test
bug:36871561
Change-Id: I157a577f22d591866b19e1d0189e23d3bb01547d
diff --git a/tests/autofillservice/AndroidManifest.xml b/tests/autofillservice/AndroidManifest.xml
index 663fe40..6e3d44992 100644
--- a/tests/autofillservice/AndroidManifest.xml
+++ b/tests/autofillservice/AndroidManifest.xml
@@ -51,6 +51,7 @@
</intent-filter>
</activity>
<activity android:name=".EmptyActivity"/>
+ <activity android:name=".DummyActivity"/>
<activity android:name=".OutOfProcessLoginActivity"
android:process="android.autofillservice.cts.outside"/>
diff --git a/tests/autofillservice/src/android/autofillservice/cts/DummyActivity.java b/tests/autofillservice/src/android/autofillservice/cts/DummyActivity.java
new file mode 100644
index 0000000..a1f5bd9
--- /dev/null
+++ b/tests/autofillservice/src/android/autofillservice/cts/DummyActivity.java
@@ -0,0 +1,31 @@
+/*
+ * 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.app.Activity;
+import android.os.Bundle;
+import android.widget.TextView;
+
+public class DummyActivity extends Activity {
+ @Override
+ protected void onCreate(Bundle savedInstanceState) {
+ super.onCreate(savedInstanceState);
+ TextView text = new TextView(this);
+ text.setText("foo");
+ setContentView(text);
+ }
+}
diff --git a/tests/autofillservice/src/android/autofillservice/cts/LoginActivityTest.java b/tests/autofillservice/src/android/autofillservice/cts/LoginActivityTest.java
index e294c33..d3899d1 100644
--- a/tests/autofillservice/src/android/autofillservice/cts/LoginActivityTest.java
+++ b/tests/autofillservice/src/android/autofillservice/cts/LoginActivityTest.java
@@ -65,6 +65,7 @@
import android.view.accessibility.AccessibilityNodeProvider;
import android.view.autofill.AutofillManager;
+import android.widget.RemoteViews;
import org.junit.After;
import org.junit.Before;
import org.junit.Rule;
@@ -1460,4 +1461,47 @@
setUserRestrictionForAutofill(false);
}
}
+
+ @Test
+ public void testClickCustomButton() throws Exception {
+ // Set service.
+ enableService();
+
+ Intent intent = new Intent(getContext(), EmptyActivity.class);
+ IntentSender sender = PendingIntent.getActivity(getContext(), 0, intent,
+ PendingIntent.FLAG_ONE_SHOT | PendingIntent.FLAG_CANCEL_CURRENT)
+ .getIntentSender();
+
+ RemoteViews presentation = new RemoteViews(getContext().getPackageName(),
+ R.layout.list_item);
+ presentation.setTextViewText(R.id.text1, "Poke");
+ Intent firstIntent = new Intent(getContext(), DummyActivity.class);
+ presentation.setOnClickPendingIntent(R.id.text1, PendingIntent.getActivity(
+ getContext(), 0, firstIntent, PendingIntent.FLAG_ONE_SHOT
+ | PendingIntent.FLAG_CANCEL_CURRENT));
+
+ // Set expectations.
+ sReplier.addResponse(new CannedFillResponse.Builder()
+ .setAuthentication(sender)
+ .setPresentation(presentation)
+ .build());
+
+ // Trigger auto-fill.
+ mActivity.onUsername(View::requestFocus);
+
+ // Wait for onFill() before proceeding.
+ sReplier.getNextFillRequest();
+
+ // Click on the custom button
+ sUiBot.selectByText("Poke");
+
+ // Make sure the click worked
+ sUiBot.selectByText("foo");
+
+ // Go back to the filled app.
+ sUiBot.pressBack();
+
+ // The session should be gone
+ assertNoDanglingSessions();
+ }
}
diff --git a/tests/autofillservice/src/android/autofillservice/cts/UiBot.java b/tests/autofillservice/src/android/autofillservice/cts/UiBot.java
index 1f98171..30dae0e 100644
--- a/tests/autofillservice/src/android/autofillservice/cts/UiBot.java
+++ b/tests/autofillservice/src/android/autofillservice/cts/UiBot.java
@@ -202,6 +202,13 @@
}
/**
+ * Presses the back button.
+ */
+ void pressBack() {
+ mDevice.pressBack();
+ }
+
+ /**
* Asserts the save snackbar is not showing and returns it.
*/
void assertSaveNotShowing(int type) {