Commit 704f090f authored by Clemens Arbesser's avatar Clemens Arbesser Committed by Commit Bot

[Autofill Assistant] Fixed flaky test.

Before this patch, we would wait for AA to be shown before invoking the espresso check. This would sometimes fail on slower devices, because asynchronous events on the native side might not have finished processing at that point.

This CL instead continuously polls the UI thread until the specified condition is matched or the default timeout is reached.

Bug: b/986026
Change-Id: I311f94dd8fd4383dfcce35656299bddce366b7bc
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1712564
Commit-Queue: Clemens Arbesser <arbesser@google.com>
Reviewed-by: default avatarStephane Zermatten <szermatt@chromium.org>
Cr-Commit-Position: refs/heads/master@{#680362}
parent 52f45a7b
...@@ -4,14 +4,13 @@ ...@@ -4,14 +4,13 @@
package org.chromium.chrome.browser.autofill_assistant; package org.chromium.chrome.browser.autofill_assistant;
import static android.support.test.espresso.Espresso.onView;
import static android.support.test.espresso.assertion.ViewAssertions.matches;
import static android.support.test.espresso.matcher.ViewMatchers.isDisplayed; import static android.support.test.espresso.matcher.ViewMatchers.isDisplayed;
import static android.support.test.espresso.matcher.ViewMatchers.withText; import static android.support.test.espresso.matcher.ViewMatchers.withText;
import static org.chromium.chrome.browser.autofill_assistant.AutofillAssistantUiTestUtil.waitUntilViewMatchesCondition;
import android.support.test.InstrumentationRegistry; import android.support.test.InstrumentationRegistry;
import android.support.test.filters.MediumTest; import android.support.test.filters.MediumTest;
import android.view.View;
import org.junit.Before; import org.junit.Before;
import org.junit.Rule; import org.junit.Rule;
...@@ -19,8 +18,6 @@ import org.junit.Test; ...@@ -19,8 +18,6 @@ import org.junit.Test;
import org.junit.runner.RunWith; import org.junit.runner.RunWith;
import org.chromium.base.test.util.CommandLineFlags; import org.chromium.base.test.util.CommandLineFlags;
import org.chromium.base.test.util.FlakyTest;
import org.chromium.chrome.autofill_assistant.R;
import org.chromium.chrome.browser.ChromeSwitches; import org.chromium.chrome.browser.ChromeSwitches;
import org.chromium.chrome.browser.autofill_assistant.proto.ActionProto; import org.chromium.chrome.browser.autofill_assistant.proto.ActionProto;
import org.chromium.chrome.browser.autofill_assistant.proto.ChipProto; import org.chromium.chrome.browser.autofill_assistant.proto.ChipProto;
...@@ -31,8 +28,6 @@ import org.chromium.chrome.browser.autofill_assistant.proto.SupportedScriptProto ...@@ -31,8 +28,6 @@ import org.chromium.chrome.browser.autofill_assistant.proto.SupportedScriptProto
import org.chromium.chrome.browser.customtabs.CustomTabActivityTestRule; import org.chromium.chrome.browser.customtabs.CustomTabActivityTestRule;
import org.chromium.chrome.browser.customtabs.CustomTabsTestUtils; import org.chromium.chrome.browser.customtabs.CustomTabsTestUtils;
import org.chromium.chrome.test.ChromeJUnit4ClassRunner; import org.chromium.chrome.test.ChromeJUnit4ClassRunner;
import org.chromium.content_public.browser.test.util.Criteria;
import org.chromium.content_public.browser.test.util.CriteriaHelper;
import java.util.Collections; import java.util.Collections;
...@@ -55,7 +50,6 @@ public class AutofillAssistantAutostartTest { ...@@ -55,7 +50,6 @@ public class AutofillAssistantAutostartTest {
*/ */
@Test @Test
@MediumTest @MediumTest
@FlakyTest(message = "crbug.com/986026")
public void testAutostart() throws Exception { public void testAutostart() throws Exception {
AutofillAssistantTestScript script = new AutofillAssistantTestScript( AutofillAssistantTestScript script = new AutofillAssistantTestScript(
SupportedScriptProto.newBuilder() SupportedScriptProto.newBuilder()
...@@ -85,15 +79,6 @@ public class AutofillAssistantAutostartTest { ...@@ -85,15 +79,6 @@ public class AutofillAssistantAutostartTest {
"http://www.example.com") "http://www.example.com")
.putExtra("org.chromium.chrome.browser.autofill_assistant.ENABLED", true)); .putExtra("org.chromium.chrome.browser.autofill_assistant.ENABLED", true));
// Wait until autofill assistant is visible on screen. waitUntilViewMatchesCondition(withText("Hello World!"), isDisplayed());
CriteriaHelper.pollUiThread(new Criteria("Autofill Assistant never started.") {
@Override
public boolean isSatisfied() {
View view = mTestRule.getActivity().findViewById(R.id.autofill_assistant);
return view != null && view.getHeight() > 0 && view.isShown();
}
});
onView(withText("Hello World!")).check(matches(isDisplayed()));
} }
} }
...@@ -4,10 +4,14 @@ ...@@ -4,10 +4,14 @@
package org.chromium.chrome.browser.autofill_assistant; package org.chromium.chrome.browser.autofill_assistant;
import static android.support.test.espresso.Espresso.onView;
import static android.support.test.espresso.assertion.ViewAssertions.matches;
import android.graphics.Bitmap; import android.graphics.Bitmap;
import android.support.annotation.Nullable; import android.support.annotation.Nullable;
import android.support.design.widget.CoordinatorLayout; import android.support.design.widget.CoordinatorLayout;
import android.support.test.InstrumentationRegistry; import android.support.test.InstrumentationRegistry;
import android.support.test.espresso.NoMatchingViewException;
import android.view.Gravity; import android.view.Gravity;
import android.view.LayoutInflater; import android.view.LayoutInflater;
import android.view.View; import android.view.View;
...@@ -15,6 +19,7 @@ import android.view.ViewGroup; ...@@ -15,6 +19,7 @@ import android.view.ViewGroup;
import android.widget.TextView; import android.widget.TextView;
import org.hamcrest.Description; import org.hamcrest.Description;
import org.hamcrest.Matcher;
import org.hamcrest.TypeSafeMatcher; import org.hamcrest.TypeSafeMatcher;
import org.chromium.base.Callback; import org.chromium.base.Callback;
...@@ -29,6 +34,8 @@ import org.chromium.chrome.browser.image_fetcher.ImageFetcherConfig; ...@@ -29,6 +34,8 @@ import org.chromium.chrome.browser.image_fetcher.ImageFetcherConfig;
import org.chromium.chrome.browser.snackbar.BottomContainer; import org.chromium.chrome.browser.snackbar.BottomContainer;
import org.chromium.chrome.browser.widget.bottomsheet.BottomSheet; import org.chromium.chrome.browser.widget.bottomsheet.BottomSheet;
import org.chromium.chrome.browser.widget.bottomsheet.BottomSheetController; import org.chromium.chrome.browser.widget.bottomsheet.BottomSheetController;
import org.chromium.content_public.browser.test.util.Criteria;
import org.chromium.content_public.browser.test.util.CriteriaHelper;
import jp.tomorrowkey.android.gifplayer.BaseGifImage; import jp.tomorrowkey.android.gifplayer.BaseGifImage;
...@@ -84,6 +91,28 @@ class AutofillAssistantUiTestUtil { ...@@ -84,6 +91,28 @@ class AutofillAssistantUiTestUtil {
}; };
} }
/**
* Waits until {@code matcher} matches {@code condition}. Will automatically fail after a
* default timeout.
*/
public static void waitUntilViewMatchesCondition(
Matcher<View> matcher, Matcher<View> condition) {
CriteriaHelper.pollInstrumentationThread(
new Criteria("Timeout while waiting for " + matcher + " to satisfy " + condition) {
@Override
public boolean isSatisfied() {
try {
onView(matcher).check(matches(condition));
return true;
} catch (NoMatchingViewException e) {
// Note: all other exceptions are let through, in particular
// AmbiguousViewMatcherException.
return false;
}
}
});
}
/** /**
* Creates a {@link BottomSheetController} for the activity, suitable for testing. * Creates a {@link BottomSheetController} for the activity, suitable for testing.
* *
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment