Commit 6b4b065f authored by Clemens Arbesser's avatar Clemens Arbesser Committed by Commit Bot

[Autofill Assistant] Fix/workaround test failure.

This hopefully fixes/workarounds a test failure. The fix is to avoid
using the bottom sheet in the UI test directly. I was not able to repro
the originally reported test failure, so this is only a best guess
effort for now. We will have to monitor if this has indeed fixed the
problem.

I have created b/172639096 to track the root cause of the test failure.

Bug: 1146084
Change-Id: I6ef0cb4f05717805f4ba7dd36b6c0c682b89ef3a
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2521817
Commit-Queue: Clemens Arbesser <arbesser@google.com>
Commit-Queue: Mathias Carlen <mcarlen@chromium.org>
Auto-Submit: Clemens Arbesser <arbesser@google.com>
Reviewed-by: default avatarMathias Carlen <mcarlen@chromium.org>
Cr-Commit-Position: refs/heads/master@{#824849}
parent 9131a10e
......@@ -147,6 +147,10 @@ public class AssistantTriggerScript {
public List<AssistantChip> getRightAlignedChipsForTest() {
return mRightAlignedChips;
}
@VisibleForTesting
public AssistantBottomSheetContent getBottomSheetContentForTest() {
return mContent;
}
private void addChipsToContainer(LinearLayout container, List<AssistantChip> chips) {
for (int i = 0; i < chips.size(); ++i) {
......@@ -164,13 +168,17 @@ public class AssistantTriggerScript {
// TODO(b/171776026): before calling this method, native needs to send the necessary
// information to populate and update the views.
public void show() {
@VisibleForTesting
public void update() {
mChipsContainer.removeAllViews();
addChipsToContainer(mChipsContainer, mLeftAlignedChips);
mChipsContainer.addView(new Space(mContext),
new LinearLayout.LayoutParams(0, ViewGroup.LayoutParams.MATCH_PARENT, 1.0f));
addChipsToContainer(mChipsContainer, mRightAlignedChips);
}
public void show() {
update();
mBottomSheetController.removeObserver(mBottomSheetObserver);
mBottomSheetController.addObserver(mBottomSheetObserver);
BottomSheetUtils.showContentAndMaybeExpand(mBottomSheetController, mContent,
......
......@@ -5,7 +5,6 @@
package org.chromium.chrome.browser.autofill_assistant;
import static androidx.test.espresso.Espresso.onView;
import static androidx.test.espresso.assertion.ViewAssertions.doesNotExist;
import static androidx.test.espresso.assertion.ViewAssertions.matches;
import static androidx.test.espresso.matcher.ViewMatchers.isDisplayed;
import static androidx.test.espresso.matcher.ViewMatchers.withContentDescription;
......@@ -13,7 +12,11 @@ import static androidx.test.espresso.matcher.ViewMatchers.withId;
import static androidx.test.espresso.matcher.ViewMatchers.withText;
import android.support.test.InstrumentationRegistry;
import android.view.Gravity;
import android.view.ViewGroup;
import android.widget.LinearLayout;
import androidx.coordinatorlayout.widget.CoordinatorLayout;
import androidx.test.filters.MediumTest;
import org.junit.Before;
......@@ -59,6 +62,23 @@ public class AutofillAssistantTriggerScriptTest {
return AutofillAssistantUiTestUtil.getBottomSheetController(mTestRule.getActivity());
}
/**
* Creates a linear layout at the bottom of the screen for use in tests. Showing content
* directly in the bottom sheet has been flaky in the past (see e.g., crbug.com/1146084).
*/
private LinearLayout createViewContainerForTest() {
CoordinatorLayout.LayoutParams lp = new CoordinatorLayout.LayoutParams(
ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT);
lp.gravity = Gravity.BOTTOM;
LinearLayout container = new LinearLayout(mTestRule.getActivity());
container.setOrientation(LinearLayout.VERTICAL);
ViewGroup chromeCoordinatorView = mTestRule.getActivity().findViewById(R.id.coordinator);
chromeCoordinatorView.addView(container, lp);
return container;
}
@Test
@MediumTest
public void testTriggerScript() throws Exception {
......@@ -106,7 +126,11 @@ public class AutofillAssistantTriggerScriptTest {
});
triggerScript.disableBottomSheetAnimationsForTesting(true);
TestThreadUtils.runOnUiThreadBlocking(triggerScript::show);
TestThreadUtils.runOnUiThreadBlocking(() -> {
triggerScript.update();
createViewContainerForTest().addView(
triggerScript.getBottomSheetContentForTest().getContentView());
});
onView(withId(R.id.autofill_assistant)).check(matches(isDisplayed()));
onView(withId(R.id.header)).check(matches(isDisplayed()));
onView(withId(R.id.poodle_wrapper)).check(matches(isDisplayed()));
......@@ -117,9 +141,5 @@ public class AutofillAssistantTriggerScriptTest {
.check(matches(isDisplayed()));
onView(withText("Not now")).check(matches(isDisplayed()));
onView(withText("Fast checkout")).check(matches(isDisplayed()));
TestThreadUtils.runOnUiThreadBlocking(triggerScript::hide);
onView(withId(R.id.autofill_assistant)).check(doesNotExist());
TestThreadUtils.runOnUiThreadBlocking(triggerScript::destroy);
}
}
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