Fix intermittent ContainersBrowserTest.MixedTabsPersistence (#34921)

Fix intermittent ContainersBrowserTest.MixedTabsPersistence failure

After session restore, background tabs use deferred loading and may not
have loaded their pages yet. The test was calling EvalJs to read
document.cookie on restored tabs without ensuring they were loaded,
causing a SecurityError on unloaded tabs with opaque origins.

Fix: Activate each tab and wait for load stop before accessing content,
following the standard Chromium session restore test pattern.

Resolves brave/brave-browser#53772
This commit is contained in:
Netzenbot
2026-03-25 08:45:30 -04:00
committed by GitHub
parent 789bb611b6
commit e38f0fc98c
@@ -1416,6 +1416,11 @@ IN_PROC_BROWSER_TEST_F(ContainersBrowserTest, MixedTabsPersistence) {
browser()->tab_strip_model()->GetWebContentsAt(i);
ASSERT_TRUE(tab);
// Restored background tabs may not have loaded yet. Activate each tab to
// trigger session restore's deferred loading, then wait for it to finish.
browser()->tab_strip_model()->ActivateTabAt(i);
ASSERT_TRUE(content::WaitForLoadStop(tab));
content::StoragePartition* partition =
tab->GetPrimaryMainFrame()->GetStoragePartition();
ASSERT_TRUE(partition);