[Autofill] Prepared AutofillPopupController for filling across frames.

In the upcoming CL http://crrev.com/c/2531999, events like
ContentAutofillRouter::SendAutofillTypePredictionsToRenderer() will
DCHECK that there is a last-queried ContentAutofillDriver. Moreover,
this upcoming CL will forward
ContentAutofillDriver::{Register,Remove}KeyPressHandler() to this
last-queried ContentAutofillDriver.

This CL skips this forwarding of {Register,Remove}KeyPressHandler()
for password forms: AutofillPopupControllerImpl now calls
{Register,Remove}KeyPressHandlerImpl() (as opposed to the non-Impl())
directly. This is necessary ContentAutofillDriver does not handle
password forms and therefore the last-queried ContentAutofillDriver
may be incorrect (in particular, it may be nullptr) for password forms.

Currently as well as with autofill::features::kAutofillAcrossIframes
disabled, this change is a no-op.

In addition, this CL fixes the last-queried ContentAutofillDriver in
the tests of AutofillPopupController:

For AutofillPopupControllerBrowserTest, this CL triggers the events to
create an Autofill popup already at the ContentAutofillDriver-level,
instead of calling into AutofillExternalDelegate directly.

For AutofillPopupControllerUnit tests, this CL sets the
ContentAutofillRouter::last_queried_source() directly.

Bug: 1187842, 1218890
Change-Id: Ie6f4f581ebe684619da947ff2d8aadceb229f6d6
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2988651
Reviewed-by: Evan Stade <[email protected]>
Reviewed-by: Dominic Battré <[email protected]>
Commit-Queue: Christoph Schwering <[email protected]>
Cr-Commit-Position: refs/heads/master@{#898076}
diff --git a/chrome/browser/autofill/autofill_uitest_util.h b/chrome/browser/autofill/autofill_uitest_util.h
index a6bcd32..30f3ead4 100644
--- a/chrome/browser/autofill/autofill_uitest_util.h
+++ b/chrome/browser/autofill/autofill_uitest_util.h
@@ -11,6 +11,7 @@
 
 namespace autofill {
 
+class AutofillExternalDelegate;
 class AutofillProfile;
 class CreditCard;
 
@@ -26,6 +27,16 @@
 void WaitForPersonalDataChange(Profile* base_profile);
 void WaitForPersonalDataManagerToBeLoaded(Profile* base_profile);
 
+// Displays an Autofill popup with a dummy suggestion.
+// Unlike autofill::test::GenerateTestAutofillPopup(), this function triggers
+// the popup through the `autofill_external_delegate->GetAutofillDriver()`'s
+// QueryFormFieldAutofill(), instead of the |autofill_external_delegate|'s
+// OnQuery() event. This initializes the form's meta data and prepares
+// ContentAutofillDriver's and ContentAutofillRouter's state to process events
+// such as AutofillDriver::PopupHidden() triggered by the popup.
+void GenerateTestAutofillPopup(
+    AutofillExternalDelegate* autofill_external_delegate);
+
 }  // namespace autofill
 
 #endif  // CHROME_BROWSER_AUTOFILL_AUTOFILL_UITEST_UTIL_H_