Fix test window leaks in FullScreenWinApplicationHandlerTest Track all created test windows in FullScreenWinApplicationHandlerTest and destroy them in TearDown. Bug: chromium:409473386 Change-Id: I6161f09203a039829c24f20b0e8a4dac8d6287fb Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/484660 Commit-Queue: Palak Agarwal <agpalak@google.com> Reviewed-by: Ilya Nikolaevskiy <ilnik@webrtc.org> Cr-Commit-Position: refs/heads/main@{#48063}
diff --git a/modules/desktop_capture/win/full_screen_win_application_handler_unittest.cc b/modules/desktop_capture/win/full_screen_win_application_handler_unittest.cc index 5a56bbf..5361c15 100644 --- a/modules/desktop_capture/win/full_screen_win_application_handler_unittest.cc +++ b/modules/desktop_capture/win/full_screen_win_application_handler_unittest.cc
@@ -19,14 +19,17 @@ namespace webrtc { -WindowInfo CreateTestWindow(const WCHAR* window_title, - const WCHAR* window_class) { - return CreateTestWindow(window_title, /*height=*/240, /*width=*/320, - /*extended_styles=*/0, window_class); -} - class FullScreenWinApplicationHandlerTest : public ::testing::Test { public: + WindowInfo CreateTestWindow(const WCHAR* window_title, + const WCHAR* window_class) { + WindowInfo info = webrtc::CreateTestWindow( + window_title, /*height=*/240, /*width=*/320, + /*extended_styles=*/0, window_class); + created_windows_.push_back(info); + return info; + } + void CreateEditorWindow( const WCHAR* title, const WCHAR* window_class = L"PPTFrameClass", @@ -69,11 +72,13 @@ } void TearDown() override { - DestroyTestWindow(editor_window_info_); - DestroyTestWindow(slide_show_window_info_); + for (const auto& window : created_windows_) { + DestroyTestWindow(window); + } } protected: + std::vector<WindowInfo> created_windows_; WindowInfo editor_window_info_; WindowInfo slide_show_window_info_; std::unique_ptr<FullScreenPowerPointHandler> full_screen_ppt_handler_; @@ -272,7 +277,6 @@ EXPECT_EQ(FindFullScreenWindow(), correct_slide_show); } -// TODO(crbug.com/409473386): Add DestroyTestWindow to clean the tests. TEST_F(FullScreenWinApplicationHandlerTest, FullScreenWindowsFoundWhenMultipleEditorsAndSlideShowsExist) { std::vector<WindowInfo> editors = { @@ -321,8 +325,6 @@ EXPECT_NE(FindFullScreenWindow(), slide_show); EXPECT_EQ(FindFullScreenWindow(), reinterpret_cast<HWND>(0)); - - DestroyTestWindow(second_editor_window_info); } TEST_F(FullScreenWinApplicationHandlerTest,