Commit 5b42777f authored by sandromaggi's avatar sandromaggi Committed by Commit Bot

[Autofill Assistant] Integration test for starting a new flow.

This tests what happens when a new flow gets started in a new tab.

It also fixes a bug where:
Flow A started on Tab A, Flow B started on Tab B, switching from B to A,
since B was attached, the |Attach| was not called and B was shown on
Tab A.

The CL also introduces some safety null checks.

Bug: b/152967053
Change-Id: I9789e823fb4b1c129db35504484215ea50e1b7ec
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2135746Reviewed-by: default avatarClemens Arbesser <arbesser@google.com>
Reviewed-by: default avatarMathias Carlen <mcarlen@chromium.org>
Commit-Queue: Sandro Maggi <sandromaggi@google.com>
Cr-Commit-Position: refs/heads/master@{#756671}
parent ba98eab7
...@@ -303,7 +303,7 @@ public class AutofillAssistantGenericUiTest { ...@@ -303,7 +303,7 @@ public class AutofillAssistantGenericUiTest {
.build()); .build());
AutofillAssistantTestScript script = new AutofillAssistantTestScript( AutofillAssistantTestScript script = new AutofillAssistantTestScript(
(SupportedScriptProto) SupportedScriptProto.newBuilder() (SupportedScriptProto) SupportedScriptProto.newBuilder()
.setPath("form_target_website.html") .setPath("autofill_assistant_target_website.html")
.setPresentation(PresentationProto.newBuilder().setAutostart(true).setChip( .setPresentation(PresentationProto.newBuilder().setAutostart(true).setChip(
ChipProto.newBuilder().setText("Autostart"))) ChipProto.newBuilder().setText("Autostart")))
.build(), .build(),
...@@ -427,7 +427,7 @@ public class AutofillAssistantGenericUiTest { ...@@ -427,7 +427,7 @@ public class AutofillAssistantGenericUiTest {
.build()); .build());
AutofillAssistantTestScript script = new AutofillAssistantTestScript( AutofillAssistantTestScript script = new AutofillAssistantTestScript(
(SupportedScriptProto) SupportedScriptProto.newBuilder() (SupportedScriptProto) SupportedScriptProto.newBuilder()
.setPath("form_target_website.html") .setPath("autofill_assistant_target_website.html")
.setPresentation(PresentationProto.newBuilder().setAutostart(true).setChip( .setPresentation(PresentationProto.newBuilder().setAutostart(true).setChip(
ChipProto.newBuilder().setText("Autostart"))) ChipProto.newBuilder().setText("Autostart")))
.build(), .build(),
...@@ -580,7 +580,7 @@ public class AutofillAssistantGenericUiTest { ...@@ -580,7 +580,7 @@ public class AutofillAssistantGenericUiTest {
.build()); .build());
AutofillAssistantTestScript script = new AutofillAssistantTestScript( AutofillAssistantTestScript script = new AutofillAssistantTestScript(
(SupportedScriptProto) SupportedScriptProto.newBuilder() (SupportedScriptProto) SupportedScriptProto.newBuilder()
.setPath("form_target_website.html") .setPath("autofill_assistant_target_website.html")
.setPresentation(PresentationProto.newBuilder().setAutostart(true).setChip( .setPresentation(PresentationProto.newBuilder().setAutostart(true).setChip(
ChipProto.newBuilder().setText("Autostart"))) ChipProto.newBuilder().setText("Autostart")))
.build(), .build(),
...@@ -685,7 +685,7 @@ public class AutofillAssistantGenericUiTest { ...@@ -685,7 +685,7 @@ public class AutofillAssistantGenericUiTest {
.build()); .build());
AutofillAssistantTestScript script = new AutofillAssistantTestScript( AutofillAssistantTestScript script = new AutofillAssistantTestScript(
(SupportedScriptProto) SupportedScriptProto.newBuilder() (SupportedScriptProto) SupportedScriptProto.newBuilder()
.setPath("form_target_website.html") .setPath("autofill_assistant_target_website.html")
.setPresentation(PresentationProto.newBuilder().setAutostart(true).setChip( .setPresentation(PresentationProto.newBuilder().setAutostart(true).setChip(
ChipProto.newBuilder().setText("Autostart"))) ChipProto.newBuilder().setText("Autostart")))
.build(), .build(),
...@@ -785,7 +785,7 @@ public class AutofillAssistantGenericUiTest { ...@@ -785,7 +785,7 @@ public class AutofillAssistantGenericUiTest {
.build()); .build());
AutofillAssistantTestScript script = new AutofillAssistantTestScript( AutofillAssistantTestScript script = new AutofillAssistantTestScript(
(SupportedScriptProto) SupportedScriptProto.newBuilder() (SupportedScriptProto) SupportedScriptProto.newBuilder()
.setPath("form_target_website.html") .setPath("autofill_assistant_target_website.html")
.setPresentation(PresentationProto.newBuilder().setAutostart(true).setChip( .setPresentation(PresentationProto.newBuilder().setAutostart(true).setChip(
ChipProto.newBuilder().setText("Autostart"))) ChipProto.newBuilder().setText("Autostart")))
.build(), .build(),
...@@ -945,7 +945,7 @@ public class AutofillAssistantGenericUiTest { ...@@ -945,7 +945,7 @@ public class AutofillAssistantGenericUiTest {
.build()); .build());
AutofillAssistantTestScript script = new AutofillAssistantTestScript( AutofillAssistantTestScript script = new AutofillAssistantTestScript(
(SupportedScriptProto) SupportedScriptProto.newBuilder() (SupportedScriptProto) SupportedScriptProto.newBuilder()
.setPath("form_target_website.html") .setPath("autofill_assistant_target_website.html")
.setPresentation(PresentationProto.newBuilder().setAutostart(true).setChip( .setPresentation(PresentationProto.newBuilder().setAutostart(true).setChip(
ChipProto.newBuilder().setText("Autostart"))) ChipProto.newBuilder().setText("Autostart")))
.build(), .build(),
...@@ -1027,7 +1027,7 @@ public class AutofillAssistantGenericUiTest { ...@@ -1027,7 +1027,7 @@ public class AutofillAssistantGenericUiTest {
.build()); .build());
AutofillAssistantTestScript script = new AutofillAssistantTestScript( AutofillAssistantTestScript script = new AutofillAssistantTestScript(
(SupportedScriptProto) SupportedScriptProto.newBuilder() (SupportedScriptProto) SupportedScriptProto.newBuilder()
.setPath("form_target_website.html") .setPath("autofill_assistant_target_website.html")
.setPresentation(PresentationProto.newBuilder().setAutostart(true).setChip( .setPresentation(PresentationProto.newBuilder().setAutostart(true).setChip(
ChipProto.newBuilder().setText("Autostart"))) ChipProto.newBuilder().setText("Autostart")))
.build(), .build(),
...@@ -1169,7 +1169,7 @@ public class AutofillAssistantGenericUiTest { ...@@ -1169,7 +1169,7 @@ public class AutofillAssistantGenericUiTest {
.build()); .build());
AutofillAssistantTestScript script = new AutofillAssistantTestScript( AutofillAssistantTestScript script = new AutofillAssistantTestScript(
(SupportedScriptProto) SupportedScriptProto.newBuilder() (SupportedScriptProto) SupportedScriptProto.newBuilder()
.setPath("form_target_website.html") .setPath("autofill_assistant_target_website.html")
.setPresentation(PresentationProto.newBuilder().setAutostart(true).setChip( .setPresentation(PresentationProto.newBuilder().setAutostart(true).setChip(
ChipProto.newBuilder().setText("Autostart"))) ChipProto.newBuilder().setText("Autostart")))
.build(), .build(),
...@@ -1263,7 +1263,7 @@ public class AutofillAssistantGenericUiTest { ...@@ -1263,7 +1263,7 @@ public class AutofillAssistantGenericUiTest {
.build()); .build());
AutofillAssistantTestScript script = new AutofillAssistantTestScript( AutofillAssistantTestScript script = new AutofillAssistantTestScript(
(SupportedScriptProto) SupportedScriptProto.newBuilder() (SupportedScriptProto) SupportedScriptProto.newBuilder()
.setPath("form_target_website.html") .setPath("autofill_assistant_target_website.html")
.setPresentation(PresentationProto.newBuilder().setAutostart(true).setChip( .setPresentation(PresentationProto.newBuilder().setAutostart(true).setChip(
ChipProto.newBuilder().setText("Autostart"))) ChipProto.newBuilder().setText("Autostart")))
.build(), .build(),
...@@ -1358,7 +1358,7 @@ public class AutofillAssistantGenericUiTest { ...@@ -1358,7 +1358,7 @@ public class AutofillAssistantGenericUiTest {
.build()); .build());
AutofillAssistantTestScript script = new AutofillAssistantTestScript( AutofillAssistantTestScript script = new AutofillAssistantTestScript(
(SupportedScriptProto) SupportedScriptProto.newBuilder() (SupportedScriptProto) SupportedScriptProto.newBuilder()
.setPath("form_target_website.html") .setPath("autofill_assistant_target_website.html")
.setPresentation(PresentationProto.newBuilder().setAutostart(true).setChip( .setPresentation(PresentationProto.newBuilder().setAutostart(true).setChip(
ChipProto.newBuilder().setText("Autostart"))) ChipProto.newBuilder().setText("Autostart")))
.build(), .build(),
...@@ -1459,7 +1459,7 @@ public class AutofillAssistantGenericUiTest { ...@@ -1459,7 +1459,7 @@ public class AutofillAssistantGenericUiTest {
.build()); .build());
AutofillAssistantTestScript script = new AutofillAssistantTestScript( AutofillAssistantTestScript script = new AutofillAssistantTestScript(
(SupportedScriptProto) SupportedScriptProto.newBuilder() (SupportedScriptProto) SupportedScriptProto.newBuilder()
.setPath("form_target_website.html") .setPath("autofill_assistant_target_website.html")
.setPresentation(PresentationProto.newBuilder().setAutostart(true).setChip( .setPresentation(PresentationProto.newBuilder().setAutostart(true).setChip(
ChipProto.newBuilder().setText("Autostart"))) ChipProto.newBuilder().setText("Autostart")))
.build(), .build(),
...@@ -1549,7 +1549,7 @@ public class AutofillAssistantGenericUiTest { ...@@ -1549,7 +1549,7 @@ public class AutofillAssistantGenericUiTest {
.build()); .build());
AutofillAssistantTestScript script = new AutofillAssistantTestScript( AutofillAssistantTestScript script = new AutofillAssistantTestScript(
(SupportedScriptProto) SupportedScriptProto.newBuilder() (SupportedScriptProto) SupportedScriptProto.newBuilder()
.setPath("form_target_website.html") .setPath("autofill_assistant_target_website.html")
.setPresentation(PresentationProto.newBuilder().setAutostart(true).setChip( .setPresentation(PresentationProto.newBuilder().setAutostart(true).setChip(
ChipProto.newBuilder().setText("Autostart"))) ChipProto.newBuilder().setText("Autostart")))
.build(), .build(),
...@@ -1636,7 +1636,7 @@ public class AutofillAssistantGenericUiTest { ...@@ -1636,7 +1636,7 @@ public class AutofillAssistantGenericUiTest {
.build()); .build());
AutofillAssistantTestScript script = new AutofillAssistantTestScript( AutofillAssistantTestScript script = new AutofillAssistantTestScript(
(SupportedScriptProto) SupportedScriptProto.newBuilder() (SupportedScriptProto) SupportedScriptProto.newBuilder()
.setPath("form_target_website.html") .setPath("autofill_assistant_target_website.html")
.setPresentation(PresentationProto.newBuilder().setAutostart(true).setChip( .setPresentation(PresentationProto.newBuilder().setAutostart(true).setChip(
ChipProto.newBuilder().setText("Autostart"))) ChipProto.newBuilder().setText("Autostart")))
.build(), .build(),
...@@ -1727,7 +1727,7 @@ public class AutofillAssistantGenericUiTest { ...@@ -1727,7 +1727,7 @@ public class AutofillAssistantGenericUiTest {
.build()); .build());
AutofillAssistantTestScript script = new AutofillAssistantTestScript( AutofillAssistantTestScript script = new AutofillAssistantTestScript(
(SupportedScriptProto) SupportedScriptProto.newBuilder() (SupportedScriptProto) SupportedScriptProto.newBuilder()
.setPath("form_target_website.html") .setPath("autofill_assistant_target_website.html")
.setPresentation(PresentationProto.newBuilder().setAutostart(true).setChip( .setPresentation(PresentationProto.newBuilder().setAutostart(true).setChip(
ChipProto.newBuilder().setText("Autostart"))) ChipProto.newBuilder().setText("Autostart")))
.build(), .build(),
...@@ -1838,7 +1838,7 @@ public class AutofillAssistantGenericUiTest { ...@@ -1838,7 +1838,7 @@ public class AutofillAssistantGenericUiTest {
.build()); .build());
AutofillAssistantTestScript script = new AutofillAssistantTestScript( AutofillAssistantTestScript script = new AutofillAssistantTestScript(
(SupportedScriptProto) SupportedScriptProto.newBuilder() (SupportedScriptProto) SupportedScriptProto.newBuilder()
.setPath("form_target_website.html") .setPath("autofill_assistant_target_website.html")
.setPresentation(PresentationProto.newBuilder().setAutostart(true).setChip( .setPresentation(PresentationProto.newBuilder().setAutostart(true).setChip(
ChipProto.newBuilder().setText("Autostart"))) ChipProto.newBuilder().setText("Autostart")))
.build(), .build(),
...@@ -1980,7 +1980,7 @@ public class AutofillAssistantGenericUiTest { ...@@ -1980,7 +1980,7 @@ public class AutofillAssistantGenericUiTest {
.build()); .build());
AutofillAssistantTestScript script = new AutofillAssistantTestScript( AutofillAssistantTestScript script = new AutofillAssistantTestScript(
(SupportedScriptProto) SupportedScriptProto.newBuilder() (SupportedScriptProto) SupportedScriptProto.newBuilder()
.setPath("form_target_website.html") .setPath("autofill_assistant_target_website.html")
.setPresentation(PresentationProto.newBuilder().setAutostart(true).setChip( .setPresentation(PresentationProto.newBuilder().setAutostart(true).setChip(
ChipProto.newBuilder().setText("Autostart"))) ChipProto.newBuilder().setText("Autostart")))
.build(), .build(),
......
...@@ -37,6 +37,7 @@ public class AutofillAssistantTestService ...@@ -37,6 +37,7 @@ public class AutofillAssistantTestService
/** The most recently received list of processed actions. */ /** The most recently received list of processed actions. */
private @Nullable List<ProcessedActionProto> mProcessedActions; private @Nullable List<ProcessedActionProto> mProcessedActions;
private int mNextActionsCounter; private int mNextActionsCounter;
private int mCurrentScriptIndex;
/** Default constructor which disables animations. */ /** Default constructor which disables animations. */
AutofillAssistantTestService(List<AutofillAssistantTestScript> scripts) { AutofillAssistantTestService(List<AutofillAssistantTestScript> scripts) {
...@@ -82,9 +83,11 @@ public class AutofillAssistantTestService ...@@ -82,9 +83,11 @@ public class AutofillAssistantTestService
/** @see AutofillAssistantService#getScriptsForUrl(String) */ /** @see AutofillAssistantService#getScriptsForUrl(String) */
@Override @Override
public SupportsScriptResponseProto getScriptsForUrl(String url) { public SupportsScriptResponseProto getScriptsForUrl(String url) {
// Return scripts one after the other. Note: Returning more than one script at once leads
// to a dropout with RENDER_PROCESS_GONE.
SupportsScriptResponseProto.Builder builder = SupportsScriptResponseProto.newBuilder(); SupportsScriptResponseProto.Builder builder = SupportsScriptResponseProto.newBuilder();
for (AutofillAssistantTestScript script : mScripts) { if (mCurrentScriptIndex < mScripts.size()) {
builder.addScripts(script.getSupportedScript()); builder.addScripts(mScripts.get(mCurrentScriptIndex++).getSupportedScript());
} }
builder.setClientSettings(mClientSettings); builder.setClientSettings(mClientSettings);
return builder.build(); return builder.build();
......
...@@ -97,8 +97,7 @@ ClientAndroid::ClientAndroid(content::WebContents* web_contents) ...@@ -97,8 +97,7 @@ ClientAndroid::ClientAndroid(content::WebContents* web_contents)
: web_contents_(web_contents), : web_contents_(web_contents),
java_object_(Java_AutofillAssistantClient_create( java_object_(Java_AutofillAssistantClient_create(
AttachCurrentThread(), AttachCurrentThread(),
reinterpret_cast<intptr_t>(this))) { reinterpret_cast<intptr_t>(this))) {}
}
ClientAndroid::~ClientAndroid() { ClientAndroid::~ClientAndroid() {
if (controller_ != nullptr && started_) { if (controller_ != nullptr && started_) {
...@@ -419,10 +418,11 @@ void ClientAndroid::AttachUI( ...@@ -419,10 +418,11 @@ void ClientAndroid::AttachUI(
} }
} }
if (!ui_controller_android_->IsAttached()) { if (!ui_controller_android_->IsAttached() ||
(controller_ != nullptr &&
!ui_controller_android_->IsAttachedTo(controller_.get()))) {
if (!controller_) if (!controller_)
CreateController(nullptr); CreateController(nullptr);
ui_controller_android_->Attach(web_contents_, this, controller_.get()); ui_controller_android_->Attach(web_contents_, this, controller_.get());
} }
......
...@@ -384,6 +384,8 @@ void UiControllerAndroid::OnStateChanged(AutofillAssistantState new_state) { ...@@ -384,6 +384,8 @@ void UiControllerAndroid::OnStateChanged(AutofillAssistantState new_state) {
} }
void UiControllerAndroid::SetupForState() { void UiControllerAndroid::SetupForState() {
DCHECK(ui_delegate_ != nullptr);
UpdateActions(ui_delegate_->GetUserActions()); UpdateActions(ui_delegate_->GetUserActions());
AutofillAssistantState state = ui_delegate_->GetState(); AutofillAssistantState state = ui_delegate_->GetState();
bool should_prompt_action_expand_sheet = bool should_prompt_action_expand_sheet =
......
...@@ -73,7 +73,12 @@ class UiControllerAndroid : public ControllerObserver { ...@@ -73,7 +73,12 @@ class UiControllerAndroid : public ControllerObserver {
void Detach(); void Detach();
// Returns true if the UI is attached to a delegate. // Returns true if the UI is attached to a delegate.
bool IsAttached() { return ui_delegate_; } bool IsAttached() { return ui_delegate_ != nullptr; }
// Returns whether the UI is currently attached to the given delegate or not.
bool IsAttachedTo(UiDelegate* ui_delegate) {
return ui_delegate_ == ui_delegate;
}
// Have the UI react as if a close or cancel button was pressed. // Have the UI react as if a close or cancel button was pressed.
// //
......
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