[PATCH v2 1/2] user32/tests: Test that ShowWindow(SW_SHOWMINIMIZED) shouldn't make a window visible.

Zhiyi Zhang zzhang at codeweavers.com
Tue Feb 22 01:31:04 CST 2022


This bug can be triggered on Mutter because it unminimizes windows when handling map requests.

Also see https://gitlab.gnome.org/GNOME/mutter/-/blob/main/src/x11/events.c#L1525 for how map
requests are handled.

Signed-off-by: Zhiyi Zhang <zzhang at codeweavers.com>
---
 dlls/user32/tests/win.c | 30 ++++++++++++++++++++++++++++--
 1 file changed, 28 insertions(+), 2 deletions(-)

diff --git a/dlls/user32/tests/win.c b/dlls/user32/tests/win.c
index d6087873f21..dcd84d0202d 100644
--- a/dlls/user32/tests/win.c
+++ b/dlls/user32/tests/win.c
@@ -7413,7 +7413,7 @@ static void test_set_window_style(void)
     UnregisterClassA(cls.lpszClassName, cls.hInstance);
 }
 
-static void test_ShowWindow(void)
+static void test_ShowWindow(HWND hwnd_main)
 {
     HWND hwnd;
     DWORD style;
@@ -7421,6 +7421,9 @@ static void test_ShowWindow(void)
     LPARAM ret;
     MONITORINFO mon_info;
     unsigned int i;
+    int timeout = 0;
+    COLORREF color;
+    HDC hdc;
 
     DWORD test_style[] =
     {
@@ -7693,6 +7696,29 @@ static void test_ShowWindow(void)
 
     flush_events(TRUE);
 
+    /* Test SW_SHOWMINIMIZED shouldn't restore windows from minimized state */
+    hwnd = CreateWindowA("static", "test", WS_POPUP, 100, 100, 200, 200, NULL, NULL, NULL, NULL);
+    ok(hwnd != NULL, "CreateWindowA failed, error %d.\n", GetLastError());
+    ShowWindow(hwnd, SW_SHOWMINIMIZED);
+    flush_events(TRUE);
+
+    hdc = GetDC(0);
+    color = GetPixel(hdc, 150, 150);
+    /* Desktop pixels may take a while to update */
+    while (color != 0xffffff && timeout < 1000)
+    {
+        Sleep(100);
+        timeout += 100;
+        color = GetPixel(hdc, 150, 150);
+    }
+    /* The window rectangle of hwndMain is (100, 100, 200, 200). If the window manager unminimizes
+     * hwnd, hwnd will end up obscuring hwndMain. Mutter is such a window manager that unminimizes
+     * windows when handling map requests and thus can demonstrate this bug */
+    todo_wine_if(color != 0xffffff)
+    ok(color == 0xffffff, "Expected color %#x, got %#x.\n", 0xffffff, color);
+    ReleaseDC(0, hdc);
+    DestroyWindow(hwnd);
+
     /* test maximize and restore windows without setting WS_CAPTION */
 
     for (i = 0; i < ARRAY_SIZE(test_style); ++i)
@@ -13132,7 +13158,7 @@ START_TEST(win)
     test_csparentdc();
     test_SetWindowLong();
     test_set_window_style();
-    test_ShowWindow();
+    test_ShowWindow(hwndMain);
     test_ShowWindow_owned(hwndMain);
     test_ShowWindow_child(hwndMain);
     test_ShowWindow_mdichild(hwndMain);
-- 
2.32.0




More information about the wine-devel mailing list