Commit 4a9173db authored by Luca Hunkeler's avatar Luca Hunkeler Committed by Commit Bot

[Autofill Assistant] Add util method to start Autofill Assistant with test service

After http://crrev/c/1808180 the bottom sheet is set up lazily.
This allows us to start autofill assistant after CCT startup has completed,
which makes our integration tests easier to setup and run.


Bug: b/141838297
Change-Id: I729fd5e453d883b6124beb3d357d146b7bb79531
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1837773
Commit-Queue: Luca Hunkeler <hluca@google.com>
Reviewed-by: default avatarClemens Arbesser <arbesser@google.com>
Cr-Commit-Position: refs/heads/master@{#702764}
parent 234703c6
...@@ -7,6 +7,7 @@ package org.chromium.chrome.browser.autofill_assistant; ...@@ -7,6 +7,7 @@ package org.chromium.chrome.browser.autofill_assistant;
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.startAutofillAssistant;
import static org.chromium.chrome.browser.autofill_assistant.AutofillAssistantUiTestUtil.waitUntilViewMatchesCondition; import static org.chromium.chrome.browser.autofill_assistant.AutofillAssistantUiTestUtil.waitUntilViewMatchesCondition;
import android.support.test.InstrumentationRegistry; import android.support.test.InstrumentationRegistry;
...@@ -51,6 +52,9 @@ public class AutofillAssistantAutostartTest { ...@@ -51,6 +52,9 @@ public class AutofillAssistantAutostartTest {
@Test @Test
@MediumTest @MediumTest
public void testAutostart() { public void testAutostart() {
mTestRule.startCustomTabActivityWithIntent(CustomTabsTestUtils.createMinimalCustomTabIntent(
InstrumentationRegistry.getTargetContext(), "http://www.example.com"));
AutofillAssistantTestScript script = new AutofillAssistantTestScript( AutofillAssistantTestScript script = new AutofillAssistantTestScript(
SupportedScriptProto.newBuilder() SupportedScriptProto.newBuilder()
.setPath("example.com/hello") .setPath("example.com/hello")
...@@ -68,16 +72,9 @@ public class AutofillAssistantAutostartTest { ...@@ -68,16 +72,9 @@ public class AutofillAssistantAutostartTest {
.setText("Done")))) .setText("Done"))))
.build())); .build()));
// Create test service before starting activity.
AutofillAssistantTestService testService = AutofillAssistantTestService testService =
new AutofillAssistantTestService(Collections.singletonList(script)); new AutofillAssistantTestService(Collections.singletonList(script));
testService.scheduleForInjection(); startAutofillAssistant(mTestRule.getActivity(), testService);
mTestRule.startCustomTabActivityWithIntent(
CustomTabsTestUtils
.createMinimalCustomTabIntent(InstrumentationRegistry.getTargetContext(),
"http://www.example.com")
.putExtra("org.chromium.chrome.browser.autofill_assistant.ENABLED", true));
waitUntilViewMatchesCondition(withText("Hello World!"), isDisplayed()); waitUntilViewMatchesCondition(withText("Hello World!"), isDisplayed());
} }
......
...@@ -38,6 +38,7 @@ import org.chromium.chrome.browser.widget.bottomsheet.BottomSheet; ...@@ -38,6 +38,7 @@ 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.Criteria;
import org.chromium.content_public.browser.test.util.CriteriaHelper; import org.chromium.content_public.browser.test.util.CriteriaHelper;
import org.chromium.content_public.browser.test.util.TestThreadUtils;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
...@@ -201,4 +202,13 @@ class AutofillAssistantUiTestUtil { ...@@ -201,4 +202,13 @@ class AutofillAssistantUiTestUtil {
testRule.startCustomTabActivityWithIntent(CustomTabsTestUtils.createMinimalCustomTabIntent( testRule.startCustomTabActivityWithIntent(CustomTabsTestUtils.createMinimalCustomTabIntent(
InstrumentationRegistry.getTargetContext(), "about:blank")); InstrumentationRegistry.getTargetContext(), "about:blank"));
} }
/**
* Starts Autofill Assistant on the given {@code activity} and injects the given {@code
* testService}.
*/
public static void startAutofillAssistant(
ChromeActivity activity, AutofillAssistantTestService testService) {
testService.scheduleForInjection();
TestThreadUtils.runOnUiThreadBlocking(() -> AutofillAssistantFacade.start(activity));
}
} }
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