This is the cherry pick merge for the M73 branch which was approved here: http://crbug.com/927215

[Autofill Assistant] Fix delayed prompt state issue.

Before this patch, the controller would stay in the running state
between the end of a script and the time runnable scripts were found.

In practice, for users, this meant that the website could be available,
but keyboard could be unavailable until a runnable script is found.
During that time the progress bar should have been pulsing but wasn't.

After this patch, the controller enters the prompt state immediately
after running a script, starting the pulsing and making the keyboard
available right away.

The cost of this is that in some corner case, the state can switch to
the prompt state then quickly enter an error case.

Bug: 122825639
Change-Id: Id4927a750370ec59e5c1216ebac01d54e377b2f3
Reviewed-on: https://chromium-review.googlesource.com/c/1442711
Commit-Queue: Stephane Zermatten <szermatt@chromium.org>
Reviewed-by: Mathias Carlen <mcarlen@chromium.org>
Cr-Original-Commit-Position: refs/heads/master@{#626996}(cherry picked from commit ba1715e2e1d192e2564252c91186fd1e4e184df2)
Reviewed-on: https://chromium-review.googlesource.com/c/1449651
Reviewed-by: Stephane Zermatten <szermatt@chromium.org>
Cr-Commit-Position: refs/branch-heads/3683@{#112}
Cr-Branched-From: e51029943e0a38dd794b73caaf6373d5496ae783-refs/heads/master@{#625896}
diff --git a/components/autofill_assistant/browser/controller.cc b/components/autofill_assistant/browser/controller.cc
index 7509aa7..cae0a4c 100644
--- a/components/autofill_assistant/browser/controller.cc
+++ b/components/autofill_assistant/browser/controller.cc
@@ -318,6 +318,7 @@
       DLOG(ERROR) << "Unexpected value for at_end: " << result.at_end;
       break;
   }
+  EnterState(AutofillAssistantState::PROMPT);
   GetOrCheckScripts(web_contents()->GetLastCommittedURL());
 }
 
diff --git a/components/autofill_assistant/browser/controller_unittest.cc b/components/autofill_assistant/browser/controller_unittest.cc
index aea610c1..689e163 100644
--- a/components/autofill_assistant/browser/controller_unittest.cc
+++ b/components/autofill_assistant/browser/controller_unittest.cc
@@ -513,6 +513,7 @@
 
   EXPECT_EQ(AutofillAssistantState::STOPPED, GetUiDelegate()->GetState());
   EXPECT_THAT(states_, ElementsAre(AutofillAssistantState::RUNNING,
+                                   AutofillAssistantState::PROMPT,
                                    AutofillAssistantState::STOPPED));
 }
 }  // namespace autofill_assistant