Fix flaky EmailAliasesBrowserTest.ContextMenuAuthorizedManage (#36306)

The test intermittently fails with "deepQuery is not defined" because
InjectHelpers injects the helper function into the bubble's WebContents
before the WebUI navigation has committed. WaitForLoadStop returns
immediately when no navigation is pending (e.g., the WebContents is
still at about:blank), so deepQuery is injected into the pre-navigation
context, then lost when chrome://email-aliases.panel/ loads.

Wait for the WebContents to commit a non-empty, non-about:blank URL
before calling WaitForLoadStop and injecting JavaScript.

Fix brave/brave-browser#55000
This commit is contained in:
Netzenbot
2026-05-12 14:06:07 -04:00
committed by GitHub
parent 8472556270
commit 51176a84e1
@@ -178,6 +178,10 @@ class EmailAliasesBrowserTestBase : public InProcessBrowserTest {
}
void InjectHelpers(content::WebContents* contents) {
ASSERT_TRUE(base::test::RunUntil([&]() {
return !contents->GetLastCommittedURL().is_empty() &&
!contents->GetLastCommittedURL().IsAboutBlank();
}));
ASSERT_TRUE(content::WaitForLoadStop(contents));
constexpr char kDeepQuery[] = R"js(
function deepQuery(selector) {