diff --git a/tests/ceftests/views/test_window_delegate.cc b/tests/ceftests/views/test_window_delegate.cc index 7f6f5aeaf..ff0e47677 100644 --- a/tests/ceftests/views/test_window_delegate.cc +++ b/tests/ceftests/views/test_window_delegate.cc @@ -193,8 +193,15 @@ void TestWindowDelegate::OnWindowFullscreenTransition( fullscreen_transition_callback_count_++; #if defined(OS_MAC) - // Two callbacks on MacOS. - EXPECT_EQ(is_completed ? 2U : 1U, fullscreen_transition_callback_count_); + // Only one callback when window is initially shown fullscreen on MacOS. + if (config_->initial_show_state == CEF_SHOW_STATE_FULLSCREEN && + fullscreen_transition_complete_count_ == 0) { + EXPECT_TRUE(is_completed); + EXPECT_EQ(1U, fullscreen_transition_callback_count_); + } else { + // Two callbacks otherwise. + EXPECT_EQ(is_completed ? 2U : 1U, fullscreen_transition_callback_count_); + } #else // Single callback on other platforms. EXPECT_TRUE(is_completed); diff --git a/tests/ceftests/views/window_unittest.cc b/tests/ceftests/views/window_unittest.cc index d2dbac857..b95e9c863 100644 --- a/tests/ceftests/views/window_unittest.cc +++ b/tests/ceftests/views/window_unittest.cc @@ -145,11 +145,36 @@ void WindowCreateMaximizedImpl(CefRefPtr event) { TestWindowDelegate::RunTest(event, std::move(config)); } +#if defined(OS_MAC) +void WindowFullscreenCreationComplete(CefRefPtr window, + size_t count) { + EXPECT_FALSE(window->IsMinimized()); + EXPECT_EQ(window->IsFullscreen(), window->IsMaximized()); + + if (window->IsFullscreen()) { + EXPECT_EQ(1U, count); + window->SetFullscreen(false); + } else { + EXPECT_EQ(2U, count); + // End the test by closing the Window. + window->Close(); + } +} +#endif + void WindowCreateFullscreenImpl(CefRefPtr event) { auto config = std::make_unique(); config->initial_show_state = CEF_SHOW_STATE_FULLSCREEN; config->on_window_created = base::BindOnce(RunWindowShow, config->initial_show_state); +#if defined(OS_MAC) + // On macOS, destroying a fullscreen window can take a long time. + // To prevent the next test from starting before the window is fully closed, + // we need to exit fullscreen mode before closing the window. + config->on_window_fullscreen_transition_complete = + base::BindRepeating(WindowFullscreenCreationComplete); + config->close_window = false; +#endif TestWindowDelegate::RunTest(event, std::move(config)); }