Commit a546cdf4 authored by Ian Struiksma's avatar Ian Struiksma Committed by Commit Bot

Ensure ContentAutofillDriver exists before getting AutofillManager

During Autofill captured sites tests, when there is a new popup,
it appears the RenderFrameHost is not always owned by the current WebContents.
This may be a further issue with the way current_main_rfh_ but this change
just ensures that the pointer exists before attempting to retrieve
it's autofill_manager instance.

This fixes 2 existing Autofill captured sites tests.

Bug: 988532
Change-Id: I0b60679843900c8313fc18f71e00cd64faf78528
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1724494
Commit-Queue: Ian Struiksma <ianstruiksma@google.com>
Reviewed-by: default avatarDominic Battré <battre@chromium.org>
Cr-Commit-Position: refs/heads/master@{#683283}
parent 18c94525
......@@ -91,7 +91,9 @@ void AutofillUiTest::SetUpOnMainThread() {
void AutofillUiTest::TearDownOnMainThread() {
// Make sure to close any showing popups prior to tearing down the UI.
GetAutofillManager()->client()->HideAutofillPopup();
AutofillManager* autofill_manager = GetAutofillManager();
if (autofill_manager)
autofill_manager->client()->HideAutofillPopup();
test::ReenableSystemServices();
}
......@@ -222,9 +224,15 @@ content::RenderViewHost* AutofillUiTest::GetRenderViewHost() {
}
AutofillManager* AutofillUiTest::GetAutofillManager() {
return ContentAutofillDriverFactory::FromWebContents(GetWebContents())
->DriverForFrame(current_main_rfh_)
->autofill_manager();
ContentAutofillDriver* driver =
ContentAutofillDriverFactory::FromWebContents(GetWebContents())
->DriverForFrame(current_main_rfh_);
// ContentAutofillDriver will be null if the current RenderFrameHost
// is not owned by the current WebContents. This state appears to occur
// when there is a web page popup during teardown
if (!driver)
return nullptr;
return driver->autofill_manager();
}
void AutofillUiTest::RenderFrameHostChanged(
......@@ -233,7 +241,9 @@ void AutofillUiTest::RenderFrameHostChanged(
if (current_main_rfh_ != old_frame)
return;
current_main_rfh_ = new_frame;
GetAutofillManager()->SetTestDelegate(test_delegate());
AutofillManager* autofill_manager = GetAutofillManager();
if (autofill_manager)
autofill_manager->SetTestDelegate(test_delegate());
}
} // namespace autofill
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