tests: Fix flaky OwnedWidgetShutdownTest.SyntheticOwnedWindow

The owned menu window could be created before the main window was
activated. When the main window became active later, the menu was
dismissed (e.g. Wayland popups), so owned_window_ was null by the
time CloseMainWindow ran. This happened reliably on repeat
iterations, where cached loads make OnLoadEnd fire sooner.

Forward CefWindowDelegate::OnWindowActivationChanged from
TestWindowDelegate to a new TestHandler::OnWindowActivationChanged
hook, and wait until the load has ended and the main window is
active before creating the owned window.
This commit is contained in:
Marshall Greenblatt committed 2026-10-07 12:25:37 -04:00
1 parent 3baba7c8db
commit bfb444b334
3 files changed
+25

No files matched your search

@@ -312,6 +312,23 @@ class SyntheticOwnedWindowTestHandler : public TestHandler,
CefGetChromeBrowserOwnedWidgetCountForTests(browser);
ASSERT_GE(initial_owned_widget_count_, 0);
load_ended_ = true;
MaybeCreateOwnedWindow();
}
void OnWindowActivationChanged(int browser_id, bool active) override {
main_window_active_ = active;
MaybeCreateOwnedWindow();
}
// Wait for the main window to become active before creating the owned menu
// window. Otherwise, later activation of the main window may dismiss the
// menu (e.g. Wayland popups) before the test closes the main window.
void MaybeCreateOwnedWindow() {
if (!load_ended_ || !main_window_active_ || owned_window_delegate_) {
return;
}
owned_window_delegate_ = new OwnedWindowDelegate(main_window_, this);
CefWindow::CreateTopLevelWindow(owned_window_delegate_);
}
@@ -380,6 +397,8 @@ class SyntheticOwnedWindowTestHandler : public TestHandler,
CefRefPtr<OwnedWindowDelegate> owned_window_delegate_;
int initial_owned_widget_count_ = -1;
int pending_browser_id_ = 0;
bool load_ended_ = false;
bool main_window_active_ = false;
IMPLEMENT_REFCOUNTING(SyntheticOwnedWindowTestHandler);
};
+5
View File
@@ -72,6 +72,11 @@ class TestWindowDelegate : public CefWindowDelegate {
handler_->OnWindowDestroyed(browser_id_);
}
void OnWindowActivationChanged(CefRefPtr<CefWindow> window,
bool active) override {
handler_->OnWindowActivationChanged(browser_id_, active);
}
bool CanClose(CefRefPtr<CefWindow> window) override {
// Allow the window to close if the browser says it's OK.
CefRefPtr<CefBrowser> browser = browser_view_->GetBrowser();
+1
View File
@@ -215,6 +215,7 @@ class TestHandler : public CefClient,
// Called from TestWindowDelegate when Views is enabled.
void OnWindowCreated(int browser_id);
virtual void OnWindowDestroyed(int browser_id);
virtual void OnWindowActivationChanged(int browser_id, bool active) {}
// Returns the count of TestHandlers the currently exist.
static size_t GetTestHandlerCount() {