Commit 323bf3a2 authored by Clemens Arbesser's avatar Clemens Arbesser Committed by Commit Bot

[Autofill Assistant] Test refactoring and cleanup.

Bug: b/133725664
Change-Id: Ifc03bfc11dec8f6cc24456a4fca71b89d8471acc
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1687398
Commit-Queue: Clemens Arbesser <arbesser@google.com>
Reviewed-by: default avatarStephane Zermatten <szermatt@chromium.org>
Cr-Commit-Position: refs/heads/master@{#676030}
parent dce57dae
...@@ -16,12 +16,9 @@ import static org.hamcrest.CoreMatchers.is; ...@@ -16,12 +16,9 @@ import static org.hamcrest.CoreMatchers.is;
import static org.hamcrest.MatcherAssert.assertThat; import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.allOf; import static org.hamcrest.Matchers.allOf;
import android.support.design.widget.CoordinatorLayout;
import android.support.test.InstrumentationRegistry; import android.support.test.InstrumentationRegistry;
import android.support.test.filters.MediumTest; import android.support.test.filters.MediumTest;
import android.support.v7.widget.DefaultItemAnimator; import android.support.v7.widget.DefaultItemAnimator;
import android.view.Gravity;
import android.view.ViewGroup;
import android.widget.LinearLayout; import android.widget.LinearLayout;
import org.junit.Before; import org.junit.Before;
...@@ -29,86 +26,71 @@ import org.junit.Rule; ...@@ -29,86 +26,71 @@ import org.junit.Rule;
import org.junit.Test; import org.junit.Test;
import org.junit.runner.RunWith; import org.junit.runner.RunWith;
import org.chromium.base.ThreadUtils;
import org.chromium.base.test.util.CommandLineFlags; import org.chromium.base.test.util.CommandLineFlags;
import org.chromium.chrome.browser.ChromeSwitches; import org.chromium.chrome.browser.ChromeSwitches;
import org.chromium.chrome.browser.autofill_assistant.carousel.AssistantActionsCarouselCoordinator; import org.chromium.chrome.browser.autofill_assistant.carousel.AssistantActionsCarouselCoordinator;
import org.chromium.chrome.browser.autofill_assistant.carousel.AssistantCarouselModel; import org.chromium.chrome.browser.autofill_assistant.carousel.AssistantCarouselModel;
import org.chromium.chrome.browser.autofill_assistant.carousel.AssistantChip; import org.chromium.chrome.browser.autofill_assistant.carousel.AssistantChip;
import org.chromium.chrome.browser.customtabs.CustomTabActivity;
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.test.ChromeJUnit4ClassRunner; import org.chromium.chrome.test.ChromeJUnit4ClassRunner;
import org.chromium.content_public.browser.test.util.TestThreadUtils; import org.chromium.content_public.browser.test.util.TestThreadUtils;
import java.util.concurrent.ExecutionException;
/** /**
* Tests for the autofill assistant actions carousel. * Tests for the autofill assistant actions carousel.
*/ */
@RunWith(ChromeJUnit4ClassRunner.class)
@CommandLineFlags.Add({ChromeSwitches.DISABLE_FIRST_RUN_EXPERIENCE}) @CommandLineFlags.Add({ChromeSwitches.DISABLE_FIRST_RUN_EXPERIENCE})
@RunWith(ChromeJUnit4ClassRunner.class)
public class AutofillAssistantActionsCarouselUiTest { public class AutofillAssistantActionsCarouselUiTest {
@Rule @Rule
public CustomTabActivityTestRule mCustomTabActivityTestRule = new CustomTabActivityTestRule(); public CustomTabActivityTestRule mTestRule = new CustomTabActivityTestRule();
@Before
public void setUp() throws Exception {
mCustomTabActivityTestRule.startCustomTabActivityWithIntent(
CustomTabsTestUtils.createMinimalCustomTabIntent(
InstrumentationRegistry.getTargetContext(), "about:blank"));
}
private CustomTabActivity getActivity() {
return mCustomTabActivityTestRule.getActivity();
}
/** Creates a coordinator for use in UI tests, and adds it to the global view hierarchy. */ /** Creates a coordinator for use in UI tests, and adds it to the global view hierarchy. */
private AssistantActionsCarouselCoordinator createCoordinator(AssistantCarouselModel model) { private AssistantActionsCarouselCoordinator createCoordinator(AssistantCarouselModel model)
ThreadUtils.assertOnUiThread(); throws Exception {
AssistantActionsCarouselCoordinator coordinator = new AssistantActionsCarouselCoordinator( AssistantActionsCarouselCoordinator coordinator = TestThreadUtils.runOnUiThreadBlocking(
InstrumentationRegistry.getTargetContext(), model); ()
-> new AssistantActionsCarouselCoordinator(
// Note: apparently, we need an intermediate container for this coordinator's view, InstrumentationRegistry.getTargetContext(), model));
// otherwise the view will be invisible.
// @TODO(crbug.com/806868) figure out why this is the case.
LinearLayout container = new LinearLayout(InstrumentationRegistry.getTargetContext());
container.addView(coordinator.getView());
CoordinatorLayout.LayoutParams lp = new CoordinatorLayout.LayoutParams(
ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT);
lp.gravity = Gravity.BOTTOM;
ViewGroup chromeCoordinatorView = TestThreadUtils.runOnUiThreadBlocking(() -> {
getActivity().findViewById(org.chromium.chrome.autofill_assistant.R.id.coordinator); // Note: apparently, we need an intermediate container for this coordinator's view,
chromeCoordinatorView.addView(container, lp); // otherwise the view will be invisible.
// @TODO(crbug.com/806868) figure out why this is the case.
LinearLayout container = new LinearLayout(InstrumentationRegistry.getTargetContext());
container.addView(coordinator.getView());
AutofillAssistantUiTestUtil.attachToCoordinator(mTestRule.getActivity(), container);
});
return coordinator; return coordinator;
} }
@Before
public void setUp() throws Exception {
AutofillAssistantUiTestUtil.startOnBlankPage(mTestRule);
}
/** Tests assumptions about the initial state of the carousel. */ /** Tests assumptions about the initial state of the carousel. */
@Test @Test
@MediumTest @MediumTest
public void testInitialState() { public void testInitialState() throws Exception {
TestThreadUtils.runOnUiThreadBlocking(() -> { AssistantCarouselModel model = new AssistantCarouselModel();
AssistantCarouselModel model = new AssistantCarouselModel(); AssistantActionsCarouselCoordinator coordinator = createCoordinator(model);
AssistantActionsCarouselCoordinator coordinator = createCoordinator(model);
TestThreadUtils.runOnUiThreadBlocking(() -> {
assertThat(((DefaultItemAnimator) coordinator.getView().getItemAnimator()) assertThat(((DefaultItemAnimator) coordinator.getView().getItemAnimator())
.getSupportsChangeAnimations(), .getSupportsChangeAnimations(),
is(false)); is(false));
assertThat(model.getChipsModel().size(), is(0));
assertThat(coordinator.getView().getAdapter().getItemCount(), is(0));
}); });
assertThat(model.getChipsModel().size(), is(0));
assertThat(coordinator.getView().getAdapter().getItemCount(), is(0));
} }
/** Adds a single chip and tests assumptions about the view state after the change. */ /** Adds a single chip and tests assumptions about the view state after the change. */
@Test @Test
@MediumTest @MediumTest
public void testAddSingleChip() throws ExecutionException { public void testAddSingleChip() throws Exception {
AssistantCarouselModel model = new AssistantCarouselModel(); AssistantCarouselModel model = new AssistantCarouselModel();
AssistantActionsCarouselCoordinator coordinator = AssistantActionsCarouselCoordinator coordinator = createCoordinator(model);
TestThreadUtils.runOnUiThreadBlocking(() -> createCoordinator(model));
TestThreadUtils.runOnUiThreadBlocking( TestThreadUtils.runOnUiThreadBlocking(
() ()
...@@ -126,10 +108,9 @@ public class AutofillAssistantActionsCarouselUiTest { ...@@ -126,10 +108,9 @@ public class AutofillAssistantActionsCarouselUiTest {
/** Adds multiple chips and tests assumptions about the view state after the change. */ /** Adds multiple chips and tests assumptions about the view state after the change. */
@Test @Test
@MediumTest @MediumTest
public void testAddMultipleChips() throws ExecutionException { public void testAddMultipleChips() throws Exception {
AssistantCarouselModel model = new AssistantCarouselModel(); AssistantCarouselModel model = new AssistantCarouselModel();
AssistantActionsCarouselCoordinator coordinator = AssistantActionsCarouselCoordinator coordinator = createCoordinator(model);
TestThreadUtils.runOnUiThreadBlocking(() -> createCoordinator(model));
// Note: this should be a small number that fits on screen without scrolling. // Note: this should be a small number that fits on screen without scrolling.
int numChips = 3; int numChips = 3;
...@@ -154,10 +135,9 @@ public class AutofillAssistantActionsCarouselUiTest { ...@@ -154,10 +135,9 @@ public class AutofillAssistantActionsCarouselUiTest {
/** Adds many chips and tests that the cancel chip is always visible. */ /** Adds many chips and tests that the cancel chip is always visible. */
@Test @Test
@MediumTest @MediumTest
public void testCancelChipAlwaysVisible() throws ExecutionException { public void testCancelChipAlwaysVisible() throws Exception {
AssistantCarouselModel model = new AssistantCarouselModel(); AssistantCarouselModel model = new AssistantCarouselModel();
AssistantActionsCarouselCoordinator coordinator = AssistantActionsCarouselCoordinator coordinator = createCoordinator(model);
TestThreadUtils.runOnUiThreadBlocking(() -> createCoordinator(model));
// Note: this should be a large number that does not fit on screen without scrolling. // Note: this should be a large number that does not fit on screen without scrolling.
int numChips = 30; int numChips = 30;
......
...@@ -21,12 +21,9 @@ import static org.chromium.content_public.browser.test.util.TestThreadUtils.runO ...@@ -21,12 +21,9 @@ import static org.chromium.content_public.browser.test.util.TestThreadUtils.runO
import android.graphics.Bitmap; import android.graphics.Bitmap;
import android.graphics.BitmapFactory; import android.graphics.BitmapFactory;
import android.support.design.widget.CoordinatorLayout;
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.Gravity;
import android.view.View; import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView; import android.widget.ImageView;
import android.widget.TextView; import android.widget.TextView;
...@@ -42,18 +39,19 @@ import org.chromium.chrome.browser.ChromeSwitches; ...@@ -42,18 +39,19 @@ import org.chromium.chrome.browser.ChromeSwitches;
import org.chromium.chrome.browser.autofill_assistant.details.AssistantDetails; import org.chromium.chrome.browser.autofill_assistant.details.AssistantDetails;
import org.chromium.chrome.browser.autofill_assistant.details.AssistantDetailsCoordinator; import org.chromium.chrome.browser.autofill_assistant.details.AssistantDetailsCoordinator;
import org.chromium.chrome.browser.autofill_assistant.details.AssistantDetailsModel; import org.chromium.chrome.browser.autofill_assistant.details.AssistantDetailsModel;
import org.chromium.chrome.browser.customtabs.CustomTabActivity;
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.test.ChromeJUnit4ClassRunner; import org.chromium.chrome.test.ChromeJUnit4ClassRunner;
import java.util.Calendar; import java.util.Calendar;
import java.util.Locale; import java.util.Locale;
/** Tests for the Autofill Assistant details. */ /** Tests for the Autofill Assistant details. */
@RunWith(ChromeJUnit4ClassRunner.class)
@CommandLineFlags.Add({ChromeSwitches.DISABLE_FIRST_RUN_EXPERIENCE}) @CommandLineFlags.Add({ChromeSwitches.DISABLE_FIRST_RUN_EXPERIENCE})
@RunWith(ChromeJUnit4ClassRunner.class)
public class AutofillAssistantDetailsUiTest { public class AutofillAssistantDetailsUiTest {
@Rule
public CustomTabActivityTestRule mTestRule = new CustomTabActivityTestRule();
private static class ViewHolder { private static class ViewHolder {
final ImageView mImageView; final ImageView mImageView;
final TextView mTitleView; final TextView mTitleView;
...@@ -78,20 +76,6 @@ public class AutofillAssistantDetailsUiTest { ...@@ -78,20 +76,6 @@ public class AutofillAssistantDetailsUiTest {
} }
} }
@Rule
public CustomTabActivityTestRule mCustomTabActivityTestRule = new CustomTabActivityTestRule();
@Before
public void setUp() throws Exception {
mCustomTabActivityTestRule.startCustomTabActivityWithIntent(
CustomTabsTestUtils.createMinimalCustomTabIntent(
InstrumentationRegistry.getTargetContext(), "about:blank"));
}
private CustomTabActivity getActivity() {
return mCustomTabActivityTestRule.getActivity();
}
private AssistantDetailsCoordinator createCoordinator(AssistantDetailsModel model) private AssistantDetailsCoordinator createCoordinator(AssistantDetailsModel model)
throws Exception { throws Exception {
return createCoordinator(model, Locale.getDefault()); return createCoordinator(model, Locale.getDefault());
...@@ -102,25 +86,24 @@ public class AutofillAssistantDetailsUiTest { ...@@ -102,25 +86,24 @@ public class AutofillAssistantDetailsUiTest {
AssistantDetailsModel model, Locale locale) throws Exception { AssistantDetailsModel model, Locale locale) throws Exception {
AssistantDetailsCoordinator coordinator = runOnUiThreadBlocking(() -> { AssistantDetailsCoordinator coordinator = runOnUiThreadBlocking(() -> {
Bitmap testImage = BitmapFactory.decodeResource( Bitmap testImage = BitmapFactory.decodeResource(
getActivity().getResources(), R.drawable.btn_close); mTestRule.getActivity().getResources(), R.drawable.btn_close);
return new AssistantDetailsCoordinator(InstrumentationRegistry.getTargetContext(), return new AssistantDetailsCoordinator(InstrumentationRegistry.getTargetContext(),
locale, model, locale, model,
new AutofillAssistantUiTestUtil.MockImageFetcher(testImage, null)); new AutofillAssistantUiTestUtil.MockImageFetcher(testImage, null));
}); });
runOnUiThreadBlocking(() -> { runOnUiThreadBlocking(()
CoordinatorLayout.LayoutParams lp = new CoordinatorLayout.LayoutParams( -> AutofillAssistantUiTestUtil.attachToCoordinator(
ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT); mTestRule.getActivity(), coordinator.getView()));
lp.gravity = Gravity.BOTTOM;
ViewGroup chromeCoordinatorView = getActivity().findViewById(R.id.coordinator);
chromeCoordinatorView.addView(coordinator.getView(), lp);
});
return coordinator; return coordinator;
} }
@Before
public void setUp() throws Exception {
AutofillAssistantUiTestUtil.startOnBlankPage(mTestRule);
}
/** Tests assumptions about the initial state of the details. */ /** Tests assumptions about the initial state of the details. */
@Test @Test
@MediumTest @MediumTest
......
...@@ -4,19 +4,20 @@ ...@@ -4,19 +4,20 @@
package org.chromium.chrome.browser.autofill_assistant; package org.chromium.chrome.browser.autofill_assistant;
import static org.junit.Assert.assertEquals; import static android.support.test.espresso.Espresso.onView;
import static org.junit.Assert.assertFalse; import static android.support.test.espresso.assertion.ViewAssertions.matches;
import static org.junit.Assert.assertNotNull; import static android.support.test.espresso.matcher.ViewMatchers.isDisplayed;
import static org.junit.Assert.assertNull; import static android.support.test.espresso.matcher.ViewMatchers.withText;
import static org.junit.Assert.assertTrue;
import static org.hamcrest.CoreMatchers.is;
import static org.hamcrest.CoreMatchers.not;
import static org.hamcrest.CoreMatchers.nullValue;
import static org.junit.Assert.assertThat;
import android.graphics.Bitmap; import android.graphics.Bitmap;
import android.graphics.BitmapFactory; import android.graphics.BitmapFactory;
import android.support.design.widget.CoordinatorLayout;
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.Gravity;
import android.view.ViewGroup;
import android.widget.TextView; import android.widget.TextView;
import org.junit.Before; import org.junit.Before;
...@@ -24,126 +25,108 @@ import org.junit.Rule; ...@@ -24,126 +25,108 @@ import org.junit.Rule;
import org.junit.Test; import org.junit.Test;
import org.junit.runner.RunWith; import org.junit.runner.RunWith;
import org.chromium.base.ThreadUtils;
import org.chromium.base.test.util.CommandLineFlags; import org.chromium.base.test.util.CommandLineFlags;
import org.chromium.chrome.autofill_assistant.R; 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.infobox.AssistantInfoBox; import org.chromium.chrome.browser.autofill_assistant.infobox.AssistantInfoBox;
import org.chromium.chrome.browser.autofill_assistant.infobox.AssistantInfoBoxCoordinator; import org.chromium.chrome.browser.autofill_assistant.infobox.AssistantInfoBoxCoordinator;
import org.chromium.chrome.browser.autofill_assistant.infobox.AssistantInfoBoxModel; import org.chromium.chrome.browser.autofill_assistant.infobox.AssistantInfoBoxModel;
import org.chromium.chrome.browser.customtabs.CustomTabActivity;
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.test.ChromeJUnit4ClassRunner; import org.chromium.chrome.test.ChromeJUnit4ClassRunner;
import org.chromium.content_public.browser.test.util.TestThreadUtils; import org.chromium.content_public.browser.test.util.TestThreadUtils;
/** /**
* Tests for the Autofill Assistant infobox. * Tests for the Autofill Assistant infobox.
*/ */
@RunWith(ChromeJUnit4ClassRunner.class)
@CommandLineFlags.Add({ChromeSwitches.DISABLE_FIRST_RUN_EXPERIENCE}) @CommandLineFlags.Add({ChromeSwitches.DISABLE_FIRST_RUN_EXPERIENCE})
@RunWith(ChromeJUnit4ClassRunner.class)
public class AutofillAssistantInfoBoxUiTest { public class AutofillAssistantInfoBoxUiTest {
@Rule @Rule
public CustomTabActivityTestRule mCustomTabActivityTestRule = new CustomTabActivityTestRule(); public CustomTabActivityTestRule mTestRule = new CustomTabActivityTestRule();
@Before
public void setUp() throws Exception {
mCustomTabActivityTestRule.startCustomTabActivityWithIntent(
CustomTabsTestUtils.createMinimalCustomTabIntent(
InstrumentationRegistry.getTargetContext(), "about:blank"));
}
private CustomTabActivity getActivity() {
return mCustomTabActivityTestRule.getActivity();
}
private TextView getExplanationView(AssistantInfoBoxCoordinator coordinator) { private TextView getExplanationView(AssistantInfoBoxCoordinator coordinator) {
return coordinator.getView().findViewById(R.id.info_box_explanation); return coordinator.getView().findViewById(R.id.info_box_explanation);
} }
/** Creates a coordinator for use in UI tests, and adds it to the global view hierarchy. */ /** Creates a coordinator for use in UI tests, and adds it to the global view hierarchy. */
private AssistantInfoBoxCoordinator createCoordinator(AssistantInfoBoxModel model) { private AssistantInfoBoxCoordinator createCoordinator(AssistantInfoBoxModel model)
ThreadUtils.assertOnUiThread(); throws Exception {
AssistantInfoBoxCoordinator coordinator = TestThreadUtils.runOnUiThreadBlocking(() -> {
Bitmap testImage = Bitmap testImage = BitmapFactory.decodeResource(
BitmapFactory.decodeResource(getActivity().getResources(), R.drawable.btn_close); mTestRule.getActivity().getResources(), R.drawable.btn_close);
AssistantInfoBoxCoordinator coordinator = return new AssistantInfoBoxCoordinator(InstrumentationRegistry.getTargetContext(),
new AssistantInfoBoxCoordinator(InstrumentationRegistry.getTargetContext(), model, model, new AutofillAssistantUiTestUtil.MockImageFetcher(testImage, null));
new AutofillAssistantUiTestUtil.MockImageFetcher(testImage, null)); });
CoordinatorLayout.LayoutParams lp = new CoordinatorLayout.LayoutParams(
ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT);
lp.gravity = Gravity.BOTTOM;
ViewGroup chromeCoordinatorView = getActivity().findViewById(R.id.coordinator);
chromeCoordinatorView.addView(coordinator.getView(), lp);
TestThreadUtils.runOnUiThreadBlocking(
()
-> AutofillAssistantUiTestUtil.attachToCoordinator(
mTestRule.getActivity(), coordinator.getView()));
return coordinator; return coordinator;
} }
@Before
public void setUp() throws Exception {
AutofillAssistantUiTestUtil.startOnBlankPage(mTestRule);
}
/** Tests assumptions about the initial state of the infobox. */ /** Tests assumptions about the initial state of the infobox. */
@Test @Test
@MediumTest @MediumTest
public void testInitialState() { public void testInitialState() throws Exception {
TestThreadUtils.runOnUiThreadBlocking(() -> { AssistantInfoBoxModel model = new AssistantInfoBoxModel();
AssistantInfoBoxModel model = new AssistantInfoBoxModel(); AssistantInfoBoxCoordinator coordinator = createCoordinator(model);
AssistantInfoBoxCoordinator coordinator = createCoordinator(model);
assertNull(model.get(AssistantInfoBoxModel.INFO_BOX)); assertThat(model.get(AssistantInfoBoxModel.INFO_BOX), nullValue());
assertFalse(coordinator.getView().isShown()); onView(is(coordinator.getView())).check(matches(not(isDisplayed())));
});
} }
/** Tests for an infobox with a message, but without an image. */ /** Tests for an infobox with a message, but without an image. */
@Test @Test
@MediumTest @MediumTest
public void testMessageNoImage() { public void testMessageNoImage() throws Exception {
TestThreadUtils.runOnUiThreadBlocking(() -> { AssistantInfoBoxModel model = new AssistantInfoBoxModel();
AssistantInfoBoxModel model = new AssistantInfoBoxModel(); AssistantInfoBoxCoordinator coordinator = createCoordinator(model);
AssistantInfoBoxCoordinator coordinator = createCoordinator(model); AssistantInfoBox infoBox = new AssistantInfoBox("", "Message");
AssistantInfoBox infoBox = new AssistantInfoBox("", "Message"); TestThreadUtils.runOnUiThreadBlocking(
model.set(AssistantInfoBoxModel.INFO_BOX, infoBox); () -> model.set(AssistantInfoBoxModel.INFO_BOX, infoBox));
onView(is(coordinator.getView())).check(matches(isDisplayed()));
assertTrue(getExplanationView(coordinator).isShown()); // Image should not be set.
assertNull("Image should not be set", assertThat(getExplanationView(coordinator).getCompoundDrawables()[1], nullValue());
getExplanationView(coordinator).getCompoundDrawables()[1]); onView(is(getExplanationView(coordinator))).check(matches(withText("Message")));
assertEquals(infoBox.getExplanation(), getExplanationView(coordinator).getText());
});
} }
/** Tests for an infobox with message and image. */ /** Tests for an infobox with message and image. */
@Test @Test
@MediumTest @MediumTest
public void testImage() { public void testImage() throws Exception {
TestThreadUtils.runOnUiThreadBlocking(() -> { AssistantInfoBoxModel model = new AssistantInfoBoxModel();
AssistantInfoBoxModel model = new AssistantInfoBoxModel(); AssistantInfoBoxCoordinator coordinator = createCoordinator(model);
AssistantInfoBoxCoordinator coordinator = createCoordinator(model); AssistantInfoBox infoBox = new AssistantInfoBox("x", "Message");
AssistantInfoBox infoBox = new AssistantInfoBox("x", "Message"); TestThreadUtils.runOnUiThreadBlocking(
model.set(AssistantInfoBoxModel.INFO_BOX, infoBox); () -> model.set(AssistantInfoBoxModel.INFO_BOX, infoBox));
onView(is(getExplanationView(coordinator))).check(matches(isDisplayed()));
assertTrue(getExplanationView(coordinator).isShown()); // Image should be set.
assertNotNull("Image should be set", assertThat(getExplanationView(coordinator).getCompoundDrawables()[1], not(nullValue()));
getExplanationView(coordinator).getCompoundDrawables()[1]); onView(is(getExplanationView(coordinator))).check(matches(withText("Message")));
assertEquals(infoBox.getExplanation(), getExplanationView(coordinator).getText());
});
} }
@Test @Test
@MediumTest @MediumTest
public void testVisibility() { public void testVisibility() throws Exception {
TestThreadUtils.runOnUiThreadBlocking(() -> { AssistantInfoBoxModel model = new AssistantInfoBoxModel();
AssistantInfoBoxModel model = new AssistantInfoBoxModel(); AssistantInfoBoxCoordinator coordinator = createCoordinator(model);
AssistantInfoBoxCoordinator coordinator = createCoordinator(model); AssistantInfoBox infoBox = new AssistantInfoBox("", "");
AssistantInfoBox infoBox = new AssistantInfoBox("", ""); TestThreadUtils.runOnUiThreadBlocking(
model.set(AssistantInfoBoxModel.INFO_BOX, infoBox); () -> model.set(AssistantInfoBoxModel.INFO_BOX, infoBox));
assertTrue(coordinator.getView().isShown()); onView(is(coordinator.getView())).check(matches(isDisplayed()));
model.set(AssistantInfoBoxModel.INFO_BOX, null); TestThreadUtils.runOnUiThreadBlocking(
assertFalse(coordinator.getView().isShown()); () -> model.set(AssistantInfoBoxModel.INFO_BOX, null));
}); onView(is(coordinator.getView())).check(matches(not(isDisplayed())));
} }
} }
...@@ -22,7 +22,6 @@ import android.support.test.filters.MediumTest; ...@@ -22,7 +22,6 @@ import android.support.test.filters.MediumTest;
import android.util.DisplayMetrics; import android.util.DisplayMetrics;
import org.json.JSONArray; import org.json.JSONArray;
import org.junit.After;
import org.junit.Before; import org.junit.Before;
import org.junit.Rule; import org.junit.Rule;
import org.junit.Test; import org.junit.Test;
...@@ -33,14 +32,12 @@ import org.chromium.chrome.browser.ChromeSwitches; ...@@ -33,14 +32,12 @@ import org.chromium.chrome.browser.ChromeSwitches;
import org.chromium.chrome.browser.autofill_assistant.overlay.AssistantOverlayCoordinator; import org.chromium.chrome.browser.autofill_assistant.overlay.AssistantOverlayCoordinator;
import org.chromium.chrome.browser.autofill_assistant.overlay.AssistantOverlayModel; import org.chromium.chrome.browser.autofill_assistant.overlay.AssistantOverlayModel;
import org.chromium.chrome.browser.autofill_assistant.overlay.AssistantOverlayState; import org.chromium.chrome.browser.autofill_assistant.overlay.AssistantOverlayState;
import org.chromium.chrome.browser.customtabs.CustomTabActivity;
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.WebContents; import org.chromium.content_public.browser.WebContents;
import org.chromium.content_public.browser.test.util.TestCallbackHelperContainer; import org.chromium.content_public.browser.test.util.TestCallbackHelperContainer;
import org.chromium.content_public.browser.test.util.TestTouchUtils; import org.chromium.content_public.browser.test.util.TestTouchUtils;
import org.chromium.net.test.EmbeddedTestServer;
import java.util.Collections; import java.util.Collections;
import java.util.concurrent.ExecutionException; import java.util.concurrent.ExecutionException;
...@@ -48,46 +45,33 @@ import java.util.concurrent.ExecutionException; ...@@ -48,46 +45,33 @@ import java.util.concurrent.ExecutionException;
/** /**
* Tests for the Autofill Assistant overlay. * Tests for the Autofill Assistant overlay.
*/ */
@RunWith(ChromeJUnit4ClassRunner.class)
@CommandLineFlags.Add({ChromeSwitches.DISABLE_FIRST_RUN_EXPERIENCE}) @CommandLineFlags.Add({ChromeSwitches.DISABLE_FIRST_RUN_EXPERIENCE})
@RunWith(ChromeJUnit4ClassRunner.class)
public class AutofillAssistantOverlayUiTest { public class AutofillAssistantOverlayUiTest {
@Rule
public CustomTabActivityTestRule mTestRule = new CustomTabActivityTestRule();
// TODO(crbug.com/806868): Create a more specific test site for overlay testing. // TODO(crbug.com/806868): Create a more specific test site for overlay testing.
private static final String TEST_PAGE = private static final String TEST_PAGE =
"/components/test/data/autofill_assistant/autofill_assistant_target_website.html"; "/components/test/data/autofill_assistant/autofill_assistant_target_website.html";
private EmbeddedTestServer mTestServer;
@Rule
public CustomTabActivityTestRule mCustomTabActivityTestRule = new CustomTabActivityTestRule();
@Before @Before
public void setUp() throws Exception { public void setUp() throws Exception {
mTestServer = EmbeddedTestServer.createAndStartServer( mTestRule.startCustomTabActivityWithIntent(CustomTabsTestUtils.createMinimalCustomTabIntent(
InstrumentationRegistry.getTargetContext().getApplicationContext()); InstrumentationRegistry.getTargetContext(),
String testPage = mTestServer.getURL(TEST_PAGE); mTestRule.getTestServer().getURL(TEST_PAGE)));
mCustomTabActivityTestRule.startCustomTabActivityWithIntent( mTestRule.getActivity().getScrim().disableAnimationForTesting(true);
CustomTabsTestUtils.createMinimalCustomTabIntent(
InstrumentationRegistry.getTargetContext(), testPage));
mCustomTabActivityTestRule.getActivity().getScrim().disableAnimationForTesting(true);
}
@After
public void tearDown() throws Exception {
mTestServer.stopAndDestroyServer();
}
private CustomTabActivity getActivity() {
return mCustomTabActivityTestRule.getActivity();
} }
private WebContents getWebContents() { private WebContents getWebContents() {
return mCustomTabActivityTestRule.getWebContents(); return mTestRule.getWebContents();
} }
/** Creates a coordinator for use in UI tests. */ /** Creates a coordinator for use in UI tests. */
private AssistantOverlayCoordinator createCoordinator(AssistantOverlayModel model) private AssistantOverlayCoordinator createCoordinator(AssistantOverlayModel model)
throws ExecutionException { throws ExecutionException {
return runOnUiThreadBlocking(() -> new AssistantOverlayCoordinator(getActivity(), model)); return runOnUiThreadBlocking(
() -> new AssistantOverlayCoordinator(mTestRule.getActivity(), model));
} }
/** Tests assumptions about the initial state of the infobox. */ /** Tests assumptions about the initial state of the infobox. */
...@@ -190,15 +174,15 @@ public class AutofillAssistantOverlayUiTest { ...@@ -190,15 +174,15 @@ public class AutofillAssistantOverlayUiTest {
// The scrim view is only attached to the view hierarchy when needed, preventing us from // The scrim view is only attached to the view hierarchy when needed, preventing us from
// using regular espresso facilities. // using regular espresso facilities.
boolean scrimInHierarchy = boolean scrimInHierarchy =
runOnUiThreadBlocking(() -> getActivity().getScrim().getParent() != null); runOnUiThreadBlocking(() -> mTestRule.getActivity().getScrim().getParent() != null);
if (expected && !scrimInHierarchy) { if (expected && !scrimInHierarchy) {
throw new Exception("Expected scrim view visible, but scrim was not in view hierarchy"); throw new Exception("Expected scrim view visible, but scrim was not in view hierarchy");
} }
if (scrimInHierarchy) { if (scrimInHierarchy) {
if (expected) { if (expected) {
onView(is(getActivity().getScrim())).check(matches(isDisplayed())); onView(is(mTestRule.getActivity().getScrim())).check(matches(isDisplayed()));
} else { } else {
onView(is(getActivity().getScrim())).check(matches(not(isDisplayed()))); onView(is(mTestRule.getActivity().getScrim())).check(matches(not(isDisplayed())));
} }
} }
} }
...@@ -210,7 +194,7 @@ public class AutofillAssistantOverlayUiTest { ...@@ -210,7 +194,7 @@ public class AutofillAssistantOverlayUiTest {
float y = coords.top + 0.5f * (coords.bottom - coords.top); float y = coords.top + 0.5f * (coords.bottom - coords.top);
// Sanity check, can only click on coordinates on screen. // Sanity check, can only click on coordinates on screen.
DisplayMetrics displayMetrics = getActivity().getResources().getDisplayMetrics(); DisplayMetrics displayMetrics = mTestRule.getActivity().getResources().getDisplayMetrics();
if (x < 0 || x > displayMetrics.widthPixels || y < 0 || y > displayMetrics.heightPixels) { if (x < 0 || x > displayMetrics.widthPixels || y < 0 || y > displayMetrics.heightPixels) {
throw new IllegalArgumentException(elementId + " not on screen: tried to tap x=" + x throw new IllegalArgumentException(elementId + " not on screen: tried to tap x=" + x
+ ", y=" + y + ", which is outside of display with w=" + ", y=" + y + ", which is outside of display with w="
...@@ -230,13 +214,14 @@ public class AutofillAssistantOverlayUiTest { ...@@ -230,13 +214,14 @@ public class AutofillAssistantOverlayUiTest {
* - Then, convert compositor space to screen space (add content offset). * - Then, convert compositor space to screen space (add content offset).
*/ */
Rect viewport = getViewport(); Rect viewport = getViewport();
float cssToPysicalPixels = (((float) getActivity().getCompositorViewHolder().getWidth() float cssToPysicalPixels =
/ (float) viewport.width())); (((float) mTestRule.getActivity().getCompositorViewHolder().getWidth()
/ (float) viewport.width()));
int[] compositorLocation = new int[2]; int[] compositorLocation = new int[2];
getActivity().getCompositorViewHolder().getLocationOnScreen(compositorLocation); mTestRule.getActivity().getCompositorViewHolder().getLocationOnScreen(compositorLocation);
int offsetY = int offsetY = compositorLocation[1]
compositorLocation[1] + getActivity().getFullscreenManager().getContentOffset(); + mTestRule.getActivity().getFullscreenManager().getContentOffset();
return new Rect((int) ((elementRect.left - viewport.left) * cssToPysicalPixels), return new Rect((int) ((elementRect.left - viewport.left) * cssToPysicalPixels),
(int) ((elementRect.top - viewport.top) * cssToPysicalPixels + offsetY), (int) ((elementRect.top - viewport.top) * cssToPysicalPixels + offsetY),
(int) ((elementRect.right - viewport.left) * cssToPysicalPixels), (int) ((elementRect.right - viewport.left) * cssToPysicalPixels),
......
...@@ -24,19 +24,14 @@ import static org.junit.Assert.assertThat; ...@@ -24,19 +24,14 @@ import static org.junit.Assert.assertThat;
import static org.chromium.chrome.browser.autofill_assistant.AssistantTagsForTesting.VERTICAL_EXPANDER_CHEVRON; import static org.chromium.chrome.browser.autofill_assistant.AssistantTagsForTesting.VERTICAL_EXPANDER_CHEVRON;
import android.support.design.widget.CoordinatorLayout;
import android.support.test.InstrumentationRegistry;
import android.support.test.filters.MediumTest; import android.support.test.filters.MediumTest;
import android.view.Gravity;
import android.view.View; import android.view.View;
import android.view.ViewGroup;
import org.junit.Before; import org.junit.Before;
import org.junit.Rule; import org.junit.Rule;
import org.junit.Test; import org.junit.Test;
import org.junit.runner.RunWith; import org.junit.runner.RunWith;
import org.chromium.base.ThreadUtils;
import org.chromium.base.test.util.CommandLineFlags; import org.chromium.base.test.util.CommandLineFlags;
import org.chromium.chrome.autofill_assistant.R; import org.chromium.chrome.autofill_assistant.R;
import org.chromium.chrome.browser.ChromeSwitches; import org.chromium.chrome.browser.ChromeSwitches;
...@@ -46,54 +41,37 @@ import org.chromium.chrome.browser.autofill_assistant.payment.AssistantChoiceLis ...@@ -46,54 +41,37 @@ import org.chromium.chrome.browser.autofill_assistant.payment.AssistantChoiceLis
import org.chromium.chrome.browser.autofill_assistant.payment.AssistantPaymentRequestCoordinator; import org.chromium.chrome.browser.autofill_assistant.payment.AssistantPaymentRequestCoordinator;
import org.chromium.chrome.browser.autofill_assistant.payment.AssistantPaymentRequestModel; import org.chromium.chrome.browser.autofill_assistant.payment.AssistantPaymentRequestModel;
import org.chromium.chrome.browser.autofill_assistant.payment.AssistantTermsAndConditionsState; import org.chromium.chrome.browser.autofill_assistant.payment.AssistantTermsAndConditionsState;
import org.chromium.chrome.browser.customtabs.CustomTabActivity;
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.test.ChromeJUnit4ClassRunner; import org.chromium.chrome.test.ChromeJUnit4ClassRunner;
import org.chromium.content_public.browser.WebContents;
import org.chromium.content_public.browser.test.util.TestThreadUtils; import org.chromium.content_public.browser.test.util.TestThreadUtils;
/** /**
* Tests for the Autofill Assistant payment request UI. * Tests for the Autofill Assistant payment request UI.
*/ */
@RunWith(ChromeJUnit4ClassRunner.class)
@CommandLineFlags.Add({ChromeSwitches.DISABLE_FIRST_RUN_EXPERIENCE}) @CommandLineFlags.Add({ChromeSwitches.DISABLE_FIRST_RUN_EXPERIENCE})
@RunWith(ChromeJUnit4ClassRunner.class)
public class AutofillAssistantPaymentRequestUiTest { public class AutofillAssistantPaymentRequestUiTest {
private AutofillAssistantPaymentRequestTestHelper mHelper;
@Rule @Rule
public CustomTabActivityTestRule mCustomTabActivityTestRule = new CustomTabActivityTestRule(); public CustomTabActivityTestRule mTestRule = new CustomTabActivityTestRule();
private AutofillAssistantPaymentRequestTestHelper mHelper;
@Before @Before
public void setUp() throws Exception { public void setUp() throws Exception {
mCustomTabActivityTestRule.startCustomTabActivityWithIntent( AutofillAssistantUiTestUtil.startOnBlankPage(mTestRule);
CustomTabsTestUtils.createMinimalCustomTabIntent(
InstrumentationRegistry.getTargetContext(), "about:blank"));
mHelper = new AutofillAssistantPaymentRequestTestHelper(); mHelper = new AutofillAssistantPaymentRequestTestHelper();
} }
private CustomTabActivity getActivity() {
return mCustomTabActivityTestRule.getActivity();
}
private WebContents getWebContents() {
return mCustomTabActivityTestRule.getWebContents();
}
/** Creates a coordinator for use in UI tests, and adds it to the global view hierarchy. */ /** Creates a coordinator for use in UI tests, and adds it to the global view hierarchy. */
private AssistantPaymentRequestCoordinator createPaymentRequestCoordinator( private AssistantPaymentRequestCoordinator createPaymentRequestCoordinator(
AssistantPaymentRequestModel model) { AssistantPaymentRequestModel model) throws Exception {
ThreadUtils.assertOnUiThread(); AssistantPaymentRequestCoordinator coordinator = TestThreadUtils.runOnUiThreadBlocking(
AssistantPaymentRequestCoordinator coordinator = () -> new AssistantPaymentRequestCoordinator(mTestRule.getActivity(), model));
new AssistantPaymentRequestCoordinator(getActivity(), model);
CoordinatorLayout.LayoutParams lp = new CoordinatorLayout.LayoutParams(
ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT);
lp.gravity = Gravity.BOTTOM;
ViewGroup chromeCoordinatorView = getActivity().findViewById(R.id.coordinator);
chromeCoordinatorView.addView(coordinator.getView(), lp);
TestThreadUtils.runOnUiThreadBlocking(
()
-> AutofillAssistantUiTestUtil.attachToCoordinator(
mTestRule.getActivity(), coordinator.getView()));
return coordinator; return coordinator;
} }
...@@ -104,8 +82,7 @@ public class AutofillAssistantPaymentRequestUiTest { ...@@ -104,8 +82,7 @@ public class AutofillAssistantPaymentRequestUiTest {
@MediumTest @MediumTest
public void testInitialState() throws Exception { public void testInitialState() throws Exception {
AssistantPaymentRequestModel model = new AssistantPaymentRequestModel(); AssistantPaymentRequestModel model = new AssistantPaymentRequestModel();
AssistantPaymentRequestCoordinator coordinator = AssistantPaymentRequestCoordinator coordinator = createPaymentRequestCoordinator(model);
TestThreadUtils.runOnUiThreadBlocking(() -> createPaymentRequestCoordinator(model));
/* Test initial model state. */ /* Test initial model state. */
assertThat(model.get(AssistantPaymentRequestModel.VISIBLE), is(false)); assertThat(model.get(AssistantPaymentRequestModel.VISIBLE), is(false));
...@@ -153,8 +130,7 @@ public class AutofillAssistantPaymentRequestUiTest { ...@@ -153,8 +130,7 @@ public class AutofillAssistantPaymentRequestUiTest {
@MediumTest @MediumTest
public void testSectionVisibility() throws Exception { public void testSectionVisibility() throws Exception {
AssistantPaymentRequestModel model = new AssistantPaymentRequestModel(); AssistantPaymentRequestModel model = new AssistantPaymentRequestModel();
AssistantPaymentRequestCoordinator coordinator = AssistantPaymentRequestCoordinator coordinator = createPaymentRequestCoordinator(model);
TestThreadUtils.runOnUiThreadBlocking(() -> createPaymentRequestCoordinator(model));
AutofillAssistantPaymentRequestTestHelper AutofillAssistantPaymentRequestTestHelper
.ViewHolder viewHolder = TestThreadUtils.runOnUiThreadBlocking( .ViewHolder viewHolder = TestThreadUtils.runOnUiThreadBlocking(
() -> new AutofillAssistantPaymentRequestTestHelper.ViewHolder(coordinator)); () -> new AutofillAssistantPaymentRequestTestHelper.ViewHolder(coordinator));
...@@ -221,8 +197,7 @@ public class AutofillAssistantPaymentRequestUiTest { ...@@ -221,8 +197,7 @@ public class AutofillAssistantPaymentRequestUiTest {
@MediumTest @MediumTest
public void testEmptyPaymentRequest() throws Exception { public void testEmptyPaymentRequest() throws Exception {
AssistantPaymentRequestModel model = new AssistantPaymentRequestModel(); AssistantPaymentRequestModel model = new AssistantPaymentRequestModel();
AssistantPaymentRequestCoordinator coordinator = AssistantPaymentRequestCoordinator coordinator = createPaymentRequestCoordinator(model);
TestThreadUtils.runOnUiThreadBlocking(() -> createPaymentRequestCoordinator(model));
AutofillAssistantPaymentRequestTestHelper.MockDelegate delegate = AutofillAssistantPaymentRequestTestHelper.MockDelegate delegate =
new AutofillAssistantPaymentRequestTestHelper.MockDelegate(); new AutofillAssistantPaymentRequestTestHelper.MockDelegate();
AutofillAssistantPaymentRequestTestHelper AutofillAssistantPaymentRequestTestHelper
...@@ -301,15 +276,14 @@ public class AutofillAssistantPaymentRequestUiTest { ...@@ -301,15 +276,14 @@ public class AutofillAssistantPaymentRequestUiTest {
@MediumTest @MediumTest
public void testContactDetailsLiveUpdate() throws Exception { public void testContactDetailsLiveUpdate() throws Exception {
AssistantPaymentRequestModel model = new AssistantPaymentRequestModel(); AssistantPaymentRequestModel model = new AssistantPaymentRequestModel();
AssistantPaymentRequestCoordinator coordinator = AssistantPaymentRequestCoordinator coordinator = createPaymentRequestCoordinator(model);
TestThreadUtils.runOnUiThreadBlocking(() -> createPaymentRequestCoordinator(model));
AutofillAssistantPaymentRequestTestHelper AutofillAssistantPaymentRequestTestHelper
.ViewHolder viewHolder = TestThreadUtils.runOnUiThreadBlocking( .ViewHolder viewHolder = TestThreadUtils.runOnUiThreadBlocking(
() -> new AutofillAssistantPaymentRequestTestHelper.ViewHolder(coordinator)); () -> new AutofillAssistantPaymentRequestTestHelper.ViewHolder(coordinator));
TestThreadUtils.runOnUiThreadBlocking(() -> { TestThreadUtils.runOnUiThreadBlocking(() -> {
// WEB_CONTENTS are necessary for the creation of the editors. // WEB_CONTENTS are necessary for the creation of the editors.
model.set(AssistantPaymentRequestModel.WEB_CONTENTS, getWebContents()); model.set(AssistantPaymentRequestModel.WEB_CONTENTS, mTestRule.getWebContents());
model.set(AssistantPaymentRequestModel.REQUEST_NAME, true); model.set(AssistantPaymentRequestModel.REQUEST_NAME, true);
model.set(AssistantPaymentRequestModel.REQUEST_EMAIL, true); model.set(AssistantPaymentRequestModel.REQUEST_EMAIL, true);
model.set(AssistantPaymentRequestModel.VISIBLE, true); model.set(AssistantPaymentRequestModel.VISIBLE, true);
...@@ -357,15 +331,14 @@ public class AutofillAssistantPaymentRequestUiTest { ...@@ -357,15 +331,14 @@ public class AutofillAssistantPaymentRequestUiTest {
@MediumTest @MediumTest
public void testPaymentMethodsLiveUpdate() throws Exception { public void testPaymentMethodsLiveUpdate() throws Exception {
AssistantPaymentRequestModel model = new AssistantPaymentRequestModel(); AssistantPaymentRequestModel model = new AssistantPaymentRequestModel();
AssistantPaymentRequestCoordinator coordinator = AssistantPaymentRequestCoordinator coordinator = createPaymentRequestCoordinator(model);
TestThreadUtils.runOnUiThreadBlocking(() -> createPaymentRequestCoordinator(model));
AutofillAssistantPaymentRequestTestHelper AutofillAssistantPaymentRequestTestHelper
.ViewHolder viewHolder = TestThreadUtils.runOnUiThreadBlocking( .ViewHolder viewHolder = TestThreadUtils.runOnUiThreadBlocking(
() -> new AutofillAssistantPaymentRequestTestHelper.ViewHolder(coordinator)); () -> new AutofillAssistantPaymentRequestTestHelper.ViewHolder(coordinator));
TestThreadUtils.runOnUiThreadBlocking(() -> { TestThreadUtils.runOnUiThreadBlocking(() -> {
// WEB_CONTENTS are necessary for the creation of the editors. // WEB_CONTENTS are necessary for the creation of the editors.
model.set(AssistantPaymentRequestModel.WEB_CONTENTS, getWebContents()); model.set(AssistantPaymentRequestModel.WEB_CONTENTS, mTestRule.getWebContents());
model.set(AssistantPaymentRequestModel.REQUEST_PAYMENT, true); model.set(AssistantPaymentRequestModel.REQUEST_PAYMENT, true);
model.set(AssistantPaymentRequestModel.VISIBLE, true); model.set(AssistantPaymentRequestModel.VISIBLE, true);
}); });
...@@ -424,8 +397,7 @@ public class AutofillAssistantPaymentRequestUiTest { ...@@ -424,8 +397,7 @@ public class AutofillAssistantPaymentRequestUiTest {
mHelper.setCreditCard(creditCard); mHelper.setCreditCard(creditCard);
AssistantPaymentRequestModel model = new AssistantPaymentRequestModel(); AssistantPaymentRequestModel model = new AssistantPaymentRequestModel();
AssistantPaymentRequestCoordinator coordinator = AssistantPaymentRequestCoordinator coordinator = createPaymentRequestCoordinator(model);
TestThreadUtils.runOnUiThreadBlocking(() -> createPaymentRequestCoordinator(model));
AutofillAssistantPaymentRequestTestHelper.MockDelegate delegate = AutofillAssistantPaymentRequestTestHelper.MockDelegate delegate =
new AutofillAssistantPaymentRequestTestHelper.MockDelegate(); new AutofillAssistantPaymentRequestTestHelper.MockDelegate();
AutofillAssistantPaymentRequestTestHelper AutofillAssistantPaymentRequestTestHelper
...@@ -513,8 +485,7 @@ public class AutofillAssistantPaymentRequestUiTest { ...@@ -513,8 +485,7 @@ public class AutofillAssistantPaymentRequestUiTest {
@MediumTest @MediumTest
public void testRemoveLastItemImplicitSelection() throws Exception { public void testRemoveLastItemImplicitSelection() throws Exception {
AssistantPaymentRequestModel model = new AssistantPaymentRequestModel(); AssistantPaymentRequestModel model = new AssistantPaymentRequestModel();
AssistantPaymentRequestCoordinator coordinator = AssistantPaymentRequestCoordinator coordinator = createPaymentRequestCoordinator(model);
TestThreadUtils.runOnUiThreadBlocking(() -> createPaymentRequestCoordinator(model));
AutofillAssistantPaymentRequestTestHelper.MockDelegate delegate = AutofillAssistantPaymentRequestTestHelper.MockDelegate delegate =
new AutofillAssistantPaymentRequestTestHelper.MockDelegate(); new AutofillAssistantPaymentRequestTestHelper.MockDelegate();
AutofillAssistantPaymentRequestTestHelper AutofillAssistantPaymentRequestTestHelper
......
...@@ -6,13 +6,21 @@ package org.chromium.chrome.browser.autofill_assistant; ...@@ -6,13 +6,21 @@ package org.chromium.chrome.browser.autofill_assistant;
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.test.InstrumentationRegistry;
import android.view.Gravity;
import android.view.View; import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView; import android.widget.TextView;
import org.hamcrest.Description; import org.hamcrest.Description;
import org.hamcrest.TypeSafeMatcher; import org.hamcrest.TypeSafeMatcher;
import org.chromium.base.Callback; import org.chromium.base.Callback;
import org.chromium.base.ThreadUtils;
import org.chromium.chrome.browser.customtabs.CustomTabActivity;
import org.chromium.chrome.browser.customtabs.CustomTabActivityTestRule;
import org.chromium.chrome.browser.customtabs.CustomTabsTestUtils;
import org.chromium.chrome.browser.image_fetcher.ImageFetcher; import org.chromium.chrome.browser.image_fetcher.ImageFetcher;
import org.chromium.chrome.browser.image_fetcher.ImageFetcherConfig; import org.chromium.chrome.browser.image_fetcher.ImageFetcherConfig;
...@@ -69,4 +77,26 @@ class AutofillAssistantUiTestUtil { ...@@ -69,4 +77,26 @@ class AutofillAssistantUiTestUtil {
} }
}; };
} }
/**
* Attaches the specified view to the Chrome coordinator. Must be called from the UI thread.
*/
public static void attachToCoordinator(CustomTabActivity activity, View view) {
ThreadUtils.assertOnUiThread();
ViewGroup chromeCoordinatorView =
activity.findViewById(org.chromium.chrome.autofill_assistant.R.id.coordinator);
CoordinatorLayout.LayoutParams lp = new CoordinatorLayout.LayoutParams(
ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT);
lp.gravity = Gravity.BOTTOM;
chromeCoordinatorView.addView(view, lp);
}
/**
* Starts the CCT test rule on a blank page.
*/
public static void startOnBlankPage(CustomTabActivityTestRule testRule)
throws InterruptedException {
testRule.startCustomTabActivityWithIntent(CustomTabsTestUtils.createMinimalCustomTabIntent(
InstrumentationRegistry.getTargetContext(), "about:blank"));
}
} }
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