Fix flaky InlineSimpleSaveActivityTest#testAutofill_oneDatasetAndSave
In the test, we will change the EditText text and then call commit().
The test fails because we call commit() too early. Because the value
doesn't change yet, the saveui will not show.
To fix this issue, the test will wait the EditText value change then
call commit(). Without the fix, there are 40% to see this issue (not
fail test but pass on re-try). Local verify solution in 100 tries,
not see the problem again.
Bug: 195582566
Test: atest InlineSimpleSaveActivityTest --iterations 100
Change-Id: I6970e4114a1efacc36e25871b77c5350496a0b2a
diff --git a/tests/autofillservice/src/android/autofillservice/cts/activities/SimpleSaveActivity.java b/tests/autofillservice/src/android/autofillservice/cts/activities/SimpleSaveActivity.java
index 1ba0b07b..2866cbc 100644
--- a/tests/autofillservice/src/android/autofillservice/cts/activities/SimpleSaveActivity.java
+++ b/tests/autofillservice/src/android/autofillservice/cts/activities/SimpleSaveActivity.java
@@ -105,12 +105,16 @@
mClearFieldsOnSubmit = flag;
}
- public FillExpectation expectAutoFill(String input) {
+ public FillExpectation expectInputTextChange(String input) {
final FillExpectation expectation = new FillExpectation(input, null);
mInput.addTextChangedListener(expectation.mInputWatcher);
return expectation;
}
+ public FillExpectation expectAutoFill(String input) {
+ return expectInputTextChange(input);
+ }
+
public FillExpectation expectAutoFill(String input, String password) {
final FillExpectation expectation = new FillExpectation(input, password);
mInput.addTextChangedListener(expectation.mInputWatcher);
@@ -133,6 +137,10 @@
: new OneTimeTextWatcher("password", mPassword, password);
}
+ public void assertTextChange() throws Exception {
+ assertAutoFilled();
+ }
+
public void assertAutoFilled() throws Exception {
mInputWatcher.assertAutoFilled();
if (mPasswordWatcher != null) {
diff --git a/tests/autofillservice/src/android/autofillservice/cts/inline/InlineSimpleSaveActivityTest.java b/tests/autofillservice/src/android/autofillservice/cts/inline/InlineSimpleSaveActivityTest.java
index da84344..d07f95b 100644
--- a/tests/autofillservice/src/android/autofillservice/cts/inline/InlineSimpleSaveActivityTest.java
+++ b/tests/autofillservice/src/android/autofillservice/cts/inline/InlineSimpleSaveActivityTest.java
@@ -92,8 +92,10 @@
mUiBot.assertNoDatasetsEver();
// Change input
+ final SimpleSaveActivity.FillExpectation changeExpectation =
+ mActivity.expectInputTextChange("ID");
mActivity.syncRunOnUiThread(() -> mActivity.getInput().setText("ID"));
- mUiBot.waitForIdle();
+ changeExpectation.assertTextChange();
// Trigger save UI.
mUiBot.selectByRelativeId(ID_COMMIT);
@@ -136,15 +138,19 @@
mUiBot.assertDatasets("YO");
// Select suggestion
+ final SimpleSaveActivity.FillExpectation fillExpectation =
+ mActivity.expectAutoFill("id", "pass");
mUiBot.selectDataset("YO");
mUiBot.waitForIdle();
// Check the results.
- mActivity.expectAutoFill("id", "pass");
+ fillExpectation.assertAutoFilled();
// Change input
+ final SimpleSaveActivity.FillExpectation changeExpectation =
+ mActivity.expectInputTextChange("ID");
mActivity.syncRunOnUiThread(() -> mActivity.getInput().setText("ID"));
- mUiBot.waitForIdle();
+ changeExpectation.assertTextChange();
// Trigger save UI.
mUiBot.selectByRelativeId(ID_COMMIT);