77
88#if defined(_WIN32) || defined(_WIN64)
99 #include < windows.h>
10+ // clang-format off
11+ // build fails if shellapi.h is included before windows.h
12+ #include < shellapi.h>
13+ // clang-format on
1014 #define TRAY_WINAPI 1
1115#elif defined(__linux__) || defined(linux) || defined(__linux)
1216 #define TRAY_APPINDICATOR 1
@@ -278,6 +282,14 @@ TEST_F(TrayTest, TestNotificationDisplay) {
278282 GTEST_SKIP () << " Notifications only supported on desktop platforms" ;
279283#endif
280284
285+ #if defined(_WIN32)
286+ QUERY_USER_NOTIFICATION_STATE notification_state;
287+ HRESULT ns = SHQueryUserNotificationState (¬ification_state);
288+ if (ns != S_OK || notification_state != QUNS_ACCEPTS_NOTIFICATIONS ) {
289+ GTEST_SKIP () << " Notifications not accepted in this environment" ;
290+ }
291+ #endif
292+
281293 int initResult = tray_init (&testTray);
282294 trayRunning = (initResult == 0 );
283295 ASSERT_EQ (initResult, 0 );
@@ -290,6 +302,8 @@ TEST_F(TrayTest, TestNotificationDisplay) {
290302 tray_update (&testTray);
291303 tray_loop (1 );
292304
305+ std::this_thread::sleep_for (std::chrono::milliseconds (5000 ));
306+
293307 EXPECT_TRUE (captureScreenshot (" tray_notification_displayed" ));
294308
295309 // Clear notification
@@ -304,6 +318,14 @@ TEST_F(TrayTest, TestNotificationCallback) {
304318 GTEST_SKIP () << " Notifications only supported on desktop platforms" ;
305319#endif
306320
321+ #if defined(_WIN32)
322+ QUERY_USER_NOTIFICATION_STATE notification_state;
323+ HRESULT ns = SHQueryUserNotificationState (¬ification_state);
324+ if (ns != S_OK || notification_state != QUNS_ACCEPTS_NOTIFICATIONS ) {
325+ GTEST_SKIP () << " Notifications not accepted in this environment" ;
326+ }
327+ #endif
328+
307329 static bool callbackInvoked = false ;
308330 auto notification_callback = []() {
309331 callbackInvoked = true ;
@@ -322,6 +344,8 @@ TEST_F(TrayTest, TestNotificationCallback) {
322344 tray_update (&testTray);
323345 tray_loop (1 );
324346
347+ std::this_thread::sleep_for (std::chrono::milliseconds (5000 ));
348+
325349 EXPECT_TRUE (captureScreenshot (" tray_notification_with_callback" ));
326350
327351 // Note: callback would be invoked by user interaction in real scenario
0 commit comments