Check return values in WindowFinderTest.FindConsoleWindow on win

Bug: webrtc:373792116
Change-Id: I2213f12e11e469aa5b94eca82deaceff5785ce6c
Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/365802
Reviewed-by: Harald Alvestrand <hta@webrtc.org>
Reviewed-by: Mirko Bonadei <mbonadei@webrtc.org>
Commit-Queue: Björn Terelius <terelius@webrtc.org>
Cr-Commit-Position: refs/heads/main@{#43256}
This commit is contained in:
Björn Terelius 2024-10-17 13:23:40 +02:00 committed by WebRTC LUCI CQ
parent ecb3ed7a76
commit 27d3d74300

View File

@ -61,25 +61,35 @@ TEST(WindowFinderTest, FindConsoleWindow) {
// Ensures that current console window is visible.
ShowWindow(console_window, SW_MAXIMIZE);
// Moves the window to the top-left of the display.
MoveWindow(console_window, 0, 0, kMaxSize, kMaxSize, true);
if (!MoveWindow(console_window, 0, 0, kMaxSize, kMaxSize, true)) {
FAIL() << "Failed to move window. Error code: " << GetLastError();
}
bool should_restore_notopmost =
(GetWindowLong(console_window, GWL_EXSTYLE) & WS_EX_TOPMOST) == 0;
// Brings console window to top.
SetWindowPos(console_window, HWND_TOPMOST, 0, 0, 0, 0,
SWP_NOMOVE | SWP_NOSIZE);
BringWindowToTop(console_window);
if (!SetWindowPos(console_window, HWND_TOPMOST, 0, 0, 0, 0,
SWP_NOMOVE | SWP_NOSIZE)) {
FAIL() << "Failed to bring window to top. Error code: " << GetLastError();
}
if (!BringWindowToTop(console_window)) {
FAIL() << "Failed second attempt to bring window to top. Error code: "
<< GetLastError();
}
bool success = false;
WindowFinderWin finder;
for (int i = 0; i < kMaxSize; i++) {
const DesktopVector spot(i, i);
const HWND id = reinterpret_cast<HWND>(finder.GetWindowUnderPoint(spot));
if (id == console_window) {
success = true;
break;
}
RTC_LOG(LS_INFO) << "Expected window " << console_window
<< ". Found window " << id;
}
if (should_restore_notopmost)
SetWindowPos(console_window, HWND_NOTOPMOST, 0, 0, 0, 0,