| OLD | NEW |
| 1 // Copyright (c) 2010 The Chromium OS Authors. All rights reserved. | 1 // Copyright (c) 2010 The Chromium OS Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include <algorithm> | 5 #include <algorithm> |
| 6 #include <cstdarg> | 6 #include <cstdarg> |
| 7 #include <set> | 7 #include <set> |
| 8 #include <tr1/memory> | 8 #include <tr1/memory> |
| 9 #include <vector> | 9 #include <vector> |
| 10 | 10 |
| (...skipping 380 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 391 reparent_event->window = xid; | 391 reparent_event->window = xid; |
| 392 reparent_event->parent = 324324; // arbitrary number | 392 reparent_event->parent = 324324; // arbitrary number |
| 393 wm_->HandleEvent(&event); | 393 wm_->HandleEvent(&event); |
| 394 | 394 |
| 395 // After the window gets reparented away from the root, WindowManager | 395 // After the window gets reparented away from the root, WindowManager |
| 396 // should've unredirected it and should no longer be tracking it. | 396 // should've unredirected it and should no longer be tracking it. |
| 397 EXPECT_TRUE(wm_->GetWindow(xid) == NULL); | 397 EXPECT_TRUE(wm_->GetWindow(xid) == NULL); |
| 398 EXPECT_FALSE(info->redirected); | 398 EXPECT_FALSE(info->redirected); |
| 399 } | 399 } |
| 400 | 400 |
| 401 TEST_F(WindowManagerTest, RestackOverrideRedirectWindows) { | 401 TEST_F(WindowManagerTest, OverrideRedirectConfigureNotify) { |
| 402 MockCompositor::StageActor* stage = compositor_->GetDefaultStage(); | 402 MockCompositor::StageActor* stage = compositor_->GetDefaultStage(); |
| 403 XEvent event; | 403 XEvent event; |
| 404 | 404 |
| 405 // Use the _NET_WM_WINDOW_TYPE_MENU hint to make the windows have shadows. | 405 // Use the _NET_WM_WINDOW_TYPE_MENU hint to make the windows have shadows. |
| 406 const XAtom win_type_xatom = xconn_->GetAtomOrDie("_NET_WM_WINDOW_TYPE"); | 406 const XAtom win_type_xatom = xconn_->GetAtomOrDie("_NET_WM_WINDOW_TYPE"); |
| 407 const XAtom atom_xatom = xconn_->GetAtomOrDie("ATOM"); | 407 const XAtom atom_xatom = xconn_->GetAtomOrDie("ATOM"); |
| 408 const XAtom menu_xatom = xconn_->GetAtomOrDie("_NET_WM_WINDOW_TYPE_MENU"); | 408 const XAtom menu_xatom = xconn_->GetAtomOrDie("_NET_WM_WINDOW_TYPE_MENU"); |
| 409 | 409 |
| 410 // Create two override-redirect windows and map them both. | 410 // Create two override-redirect windows and map them both. |
| 411 XWindow xid = xconn_->CreateWindow( | 411 XWindow xid = xconn_->CreateWindow( |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 446 xconn_->InitConfigureNotifyEvent(&event, xid); | 446 xconn_->InitConfigureNotifyEvent(&event, xid); |
| 447 event.xconfigure.above = xid2; | 447 event.xconfigure.above = xid2; |
| 448 wm_->HandleEvent(&event); | 448 wm_->HandleEvent(&event); |
| 449 | 449 |
| 450 EXPECT_LT(stage->GetStackingIndex(win->actor()), | 450 EXPECT_LT(stage->GetStackingIndex(win->actor()), |
| 451 stage->GetStackingIndex(win->shadow()->group())); | 451 stage->GetStackingIndex(win->shadow()->group())); |
| 452 EXPECT_LT(stage->GetStackingIndex(win->shadow()->group()), | 452 EXPECT_LT(stage->GetStackingIndex(win->shadow()->group()), |
| 453 stage->GetStackingIndex(win2->actor())); | 453 stage->GetStackingIndex(win2->actor())); |
| 454 EXPECT_LT(stage->GetStackingIndex(win2->actor()), | 454 EXPECT_LT(stage->GetStackingIndex(win2->actor()), |
| 455 stage->GetStackingIndex(win2->shadow()->group())); | 455 stage->GetStackingIndex(win2->shadow()->group())); |
| 456 |
| 457 // Move and resize the first window and check that its actor is updated |
| 458 // correspondingly. |
| 459 const Rect kNewBounds(300, 400, 60, 70); |
| 460 xconn_->ConfigureWindow(xid, kNewBounds); |
| 461 xconn_->InitConfigureNotifyEvent(&event, xid); |
| 462 wm_->HandleEvent(&event); |
| 463 EXPECT_EQ(kNewBounds, win->actor()->GetBounds()); |
| 456 } | 464 } |
| 457 | 465 |
| 458 TEST_F(WindowManagerTest, StackOverrideRedirectWindowsAboveLayers) { | 466 TEST_F(WindowManagerTest, StackOverrideRedirectWindowsAboveLayers) { |
| 459 MockCompositor::StageActor* stage = compositor_->GetDefaultStage(); | 467 MockCompositor::StageActor* stage = compositor_->GetDefaultStage(); |
| 460 XEvent event; | 468 XEvent event; |
| 461 | 469 |
| 462 // Create a normal, non-override-redirect window. | 470 // Create a normal, non-override-redirect window. |
| 463 XWindow normal_xid = CreateSimpleWindow(); | 471 XWindow normal_xid = CreateSimpleWindow(); |
| 464 SendInitialEventsForWindow(normal_xid); | 472 SendInitialEventsForWindow(normal_xid); |
| 465 Window* normal_win = wm_->GetWindowOrDie(normal_xid); | 473 Window* normal_win = wm_->GetWindowOrDie(normal_xid); |
| (...skipping 577 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1043 XAtom popup_xatom = xconn_->GetAtomOrDie("_NET_WM_WINDOW_TYPE_POPUP_MENU"); | 1051 XAtom popup_xatom = xconn_->GetAtomOrDie("_NET_WM_WINDOW_TYPE_POPUP_MENU"); |
| 1044 | 1052 |
| 1045 // An override-redirect window with no _NET_WM_WINDOW_TYPE property | 1053 // An override-redirect window with no _NET_WM_WINDOW_TYPE property |
| 1046 // shouldn't get a shadow. | 1054 // shouldn't get a shadow. |
| 1047 const XWindow root = xconn_->GetRootWindow(); | 1055 const XWindow root = xconn_->GetRootWindow(); |
| 1048 XWindow xid1 = | 1056 XWindow xid1 = |
| 1049 xconn_->CreateWindow(root, Rect(0, 0, 10, 10), true, false, 0, 0); | 1057 xconn_->CreateWindow(root, Rect(0, 0, 10, 10), true, false, 0, 0); |
| 1050 ASSERT_TRUE(xconn_->MapWindow(xid1)); | 1058 ASSERT_TRUE(xconn_->MapWindow(xid1)); |
| 1051 SendInitialEventsForWindow(xid1); | 1059 SendInitialEventsForWindow(xid1); |
| 1052 Window* win1 = wm_->GetWindowOrDie(xid1); | 1060 Window* win1 = wm_->GetWindowOrDie(xid1); |
| 1053 EXPECT_TRUE(win1->composited_shown()); | |
| 1054 EXPECT_TRUE(win1->shadow() == NULL); | 1061 EXPECT_TRUE(win1->shadow() == NULL); |
| 1055 | 1062 |
| 1056 // _NET_WM_WINDOW_TYPE_MENU (or several other menu-related types) should | 1063 // _NET_WM_WINDOW_TYPE_MENU (or several other menu-related types) should |
| 1057 // result in a shadow getting shown. | 1064 // result in a shadow getting shown. |
| 1058 XWindow xid2 = | 1065 XWindow xid2 = |
| 1059 xconn_->CreateWindow(root, Rect(0, 0, 10, 10), true, false, 0, 0); | 1066 xconn_->CreateWindow(root, Rect(0, 0, 10, 10), true, false, 0, 0); |
| 1060 xconn_->SetIntProperty(xid2, win_type_xatom, atom_xatom, menu_xatom); | 1067 xconn_->SetIntProperty(xid2, win_type_xatom, atom_xatom, menu_xatom); |
| 1061 ASSERT_TRUE(xconn_->MapWindow(xid2)); | 1068 ASSERT_TRUE(xconn_->MapWindow(xid2)); |
| 1062 SendInitialEventsForWindow(xid2); | 1069 SendInitialEventsForWindow(xid2); |
| 1063 ASSERT_TRUE(wm_->GetWindowOrDie(xid2)->shadow() != NULL); | 1070 ASSERT_TRUE(wm_->GetWindowOrDie(xid2)->shadow() != NULL); |
| (...skipping 23 matching lines...) Expand all Loading... |
| 1087 EXPECT_TRUE(wm_->GetWindowOrDie(xid4)->shadow()->is_shown()); | 1094 EXPECT_TRUE(wm_->GetWindowOrDie(xid4)->shadow()->is_shown()); |
| 1088 | 1095 |
| 1089 // We should avoid showing shadows behind RGBA menus. | 1096 // We should avoid showing shadows behind RGBA menus. |
| 1090 XWindow rgba_xid = | 1097 XWindow rgba_xid = |
| 1091 xconn_->CreateWindow(root, Rect(0, 0, 10, 10), true, false, 0, 0); | 1098 xconn_->CreateWindow(root, Rect(0, 0, 10, 10), true, false, 0, 0); |
| 1092 xconn_->GetWindowInfoOrDie(rgba_xid)->depth = 32; | 1099 xconn_->GetWindowInfoOrDie(rgba_xid)->depth = 32; |
| 1093 xconn_->SetIntProperty(rgba_xid, win_type_xatom, atom_xatom, menu_xatom); | 1100 xconn_->SetIntProperty(rgba_xid, win_type_xatom, atom_xatom, menu_xatom); |
| 1094 ASSERT_TRUE(xconn_->MapWindow(rgba_xid)); | 1101 ASSERT_TRUE(xconn_->MapWindow(rgba_xid)); |
| 1095 SendInitialEventsForWindow(rgba_xid); | 1102 SendInitialEventsForWindow(rgba_xid); |
| 1096 Window* rgba_win = wm_->GetWindowOrDie(rgba_xid); | 1103 Window* rgba_win = wm_->GetWindowOrDie(rgba_xid); |
| 1097 EXPECT_TRUE(rgba_win->composited_shown()); | |
| 1098 EXPECT_TRUE(rgba_win->shadow() == NULL); | 1104 EXPECT_TRUE(rgba_win->shadow() == NULL); |
| 1099 } | 1105 } |
| 1100 | 1106 |
| 1101 // Check that we try to guess when is a video is playing by looking at the | 1107 // Check that we try to guess when is a video is playing by looking at the |
| 1102 // rate and size of damage events, and that we set the _CHROME_VIDEO_TIME | 1108 // rate and size of damage events, and that we set the _CHROME_VIDEO_TIME |
| 1103 // property on the root window accordingly. | 1109 // property on the root window accordingly. |
| 1104 TEST_F(WindowManagerTest, VideoTimeProperty) { | 1110 TEST_F(WindowManagerTest, VideoTimeProperty) { |
| 1105 SetMonotonicTimeForTest(CreateTimeTicksFromMs(2000000)); | 1111 SetMonotonicTimeForTest(CreateTimeTicksFromMs(2000000)); |
| 1106 const time_t start_time = 1000; | 1112 const time_t start_time = 1000; |
| 1107 SetCurrentTimeForTest(start_time, 0); | 1113 SetCurrentTimeForTest(start_time, 0); |
| (...skipping 137 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1245 XEvent event; | 1251 XEvent event; |
| 1246 xconn_->InitConfigureNotifyEvent(&event, xwin1); | 1252 xconn_->InitConfigureNotifyEvent(&event, xwin1); |
| 1247 wm_->HandleEvent(&event); | 1253 wm_->HandleEvent(&event); |
| 1248 xconn_->InitConfigureNotifyEvent(&event, xwin2); | 1254 xconn_->InitConfigureNotifyEvent(&event, xwin2); |
| 1249 wm_->HandleEvent(&event); | 1255 wm_->HandleEvent(&event); |
| 1250 | 1256 |
| 1251 // Set up overlay regions for comparison. | 1257 // Set up overlay regions for comparison. |
| 1252 MockXConnection::WindowInfo* overlay_info = | 1258 MockXConnection::WindowInfo* overlay_info = |
| 1253 xconn_->GetWindowInfoOrDie(wm_->overlay_xid_); | 1259 xconn_->GetWindowInfoOrDie(wm_->overlay_xid_); |
| 1254 scoped_ptr<ByteMap> expected_overlay( | 1260 scoped_ptr<ByteMap> expected_overlay( |
| 1255 new ByteMap(overlay_info->bounds.width, overlay_info->bounds.height)); | 1261 new ByteMap(overlay_info->bounds.size())); |
| 1256 scoped_ptr<ByteMap> actual_overlay( | 1262 scoped_ptr<ByteMap> actual_overlay( |
| 1257 new ByteMap(overlay_info->bounds.width, overlay_info->bounds.height)); | 1263 new ByteMap(overlay_info->bounds.size())); |
| 1258 | 1264 |
| 1259 // Make sure no window is unredirected. | 1265 // Make sure no window is unredirected. |
| 1260 FLAGS_unredirect_fullscreen_window = true; | 1266 FLAGS_unredirect_fullscreen_window = true; |
| 1261 EXPECT_EQ(static_cast<XWindow>(0), wm_->unredirected_fullscreen_xid_); | 1267 EXPECT_EQ(static_cast<XWindow>(0), wm_->unredirected_fullscreen_xid_); |
| 1262 EXPECT_TRUE(info1->redirected); | 1268 EXPECT_TRUE(info1->redirected); |
| 1263 EXPECT_TRUE(info2->redirected); | 1269 EXPECT_TRUE(info2->redirected); |
| 1264 expected_overlay->Clear(0xff); | 1270 expected_overlay->Clear(0xff); |
| 1265 xconn_->GetWindowBoundingRegion(wm_->overlay_xid_, actual_overlay.get()); | 1271 xconn_->GetWindowBoundingRegion(wm_->overlay_xid_, actual_overlay.get()); |
| 1266 EXPECT_TRUE(*expected_overlay.get() == *actual_overlay.get()); | 1272 EXPECT_TRUE(*expected_overlay.get() == *actual_overlay.get()); |
| 1267 | 1273 |
| (...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1374 | 1380 |
| 1375 // Notify the window manager that the pixmap has been painted. | 1381 // Notify the window manager that the pixmap has been painted. |
| 1376 // has_initial_pixmap() should return true now, and our event consumer | 1382 // has_initial_pixmap() should return true now, and our event consumer |
| 1377 // should be notified that the pixmap was received. | 1383 // should be notified that the pixmap was received. |
| 1378 SendSyncRequestProtocolAlarm(sync_xid); | 1384 SendSyncRequestProtocolAlarm(sync_xid); |
| 1379 EXPECT_TRUE(sync_win->has_initial_pixmap()); | 1385 EXPECT_TRUE(sync_win->has_initial_pixmap()); |
| 1380 EXPECT_EQ(1, ec.num_fetched_pixmaps()); | 1386 EXPECT_EQ(1, ec.num_fetched_pixmaps()); |
| 1381 | 1387 |
| 1382 // Resize the window and mimic the client syncing with the window manager | 1388 // Resize the window and mimic the client syncing with the window manager |
| 1383 // again, and check that we notify the event consumer about the new pixmap. | 1389 // again, and check that we notify the event consumer about the new pixmap. |
| 1384 sync_win->ResizeClient(600, 500, GRAVITY_NORTHWEST); | 1390 sync_win->Resize(Size(600, 500), GRAVITY_NORTHWEST); |
| 1385 SendSyncRequestProtocolAlarm(sync_xid); | 1391 SendSyncRequestProtocolAlarm(sync_xid); |
| 1386 EXPECT_TRUE(sync_win->has_initial_pixmap()); | 1392 EXPECT_TRUE(sync_win->has_initial_pixmap()); |
| 1387 EXPECT_EQ(2, ec.num_fetched_pixmaps()); | 1393 EXPECT_EQ(2, ec.num_fetched_pixmaps()); |
| 1388 } | 1394 } |
| 1389 | 1395 |
| 1390 // Test that we make a second attempt at loading the sync request counter | 1396 // Test that we make a second attempt at loading the sync request counter |
| 1391 // ID if it only gets set after WM_PROTOCOLS has already told us that the | 1397 // ID if it only gets set after WM_PROTOCOLS has already told us that the |
| 1392 // protocol is supported. See comment #3 at http://crosbug.com/5846. | 1398 // protocol is supported. See comment #3 at http://crosbug.com/5846. |
| 1393 TEST_F(WindowManagerTest, HandleLateSyncRequestCounter) { | 1399 TEST_F(WindowManagerTest, HandleLateSyncRequestCounter) { |
| 1394 XWindow xid = CreateSimpleWindow(); | 1400 XWindow xid = CreateSimpleWindow(); |
| (...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1455 TEST_F(WindowManagerTest, ForceCompositing) { | 1461 TEST_F(WindowManagerTest, ForceCompositing) { |
| 1456 // Create a window. | 1462 // Create a window. |
| 1457 XWindow xid = CreateSimpleWindow(); | 1463 XWindow xid = CreateSimpleWindow(); |
| 1458 ConfigureWindowForSyncRequestProtocol(xid); | 1464 ConfigureWindowForSyncRequestProtocol(xid); |
| 1459 SendInitialEventsForWindow(xid); | 1465 SendInitialEventsForWindow(xid); |
| 1460 SendSyncRequestProtocolAlarm(xid); | 1466 SendSyncRequestProtocolAlarm(xid); |
| 1461 Window* win = wm_->GetWindowOrDie(xid); | 1467 Window* win = wm_->GetWindowOrDie(xid); |
| 1462 MockCompositor::TexturePixmapActor* actor = GetMockActorForWindow(win); | 1468 MockCompositor::TexturePixmapActor* actor = GetMockActorForWindow(win); |
| 1463 | 1469 |
| 1464 // Resize it to cover the whole screen. | 1470 // Resize it to cover the whole screen. |
| 1465 win->ResizeClient(wm_->width(), wm_->height(), GRAVITY_NORTHWEST); | 1471 win->Resize(wm_->root_size(), GRAVITY_NORTHWEST); |
| 1466 SendSyncRequestProtocolAlarm(xid); | 1472 SendSyncRequestProtocolAlarm(xid); |
| 1467 | 1473 |
| 1468 // Tell the WM that the window is covering the screen and check that we | 1474 // Tell the WM that the window is covering the screen and check that we |
| 1469 // disable compositing. | 1475 // disable compositing. |
| 1470 wm_->HandleTopFullscreenActorChange(actor); | 1476 wm_->HandleTopFullscreenActorChange(actor); |
| 1471 EXPECT_EQ(xid, wm_->unredirected_fullscreen_xid_); | 1477 EXPECT_EQ(xid, wm_->unredirected_fullscreen_xid_); |
| 1472 EXPECT_TRUE(wm_->disable_compositing_task_is_pending_); | 1478 EXPECT_TRUE(wm_->disable_compositing_task_is_pending_); |
| 1473 wm_->DisableCompositing(); | 1479 wm_->DisableCompositing(); |
| 1474 EXPECT_FALSE(compositor_->should_draw_frame()); | 1480 EXPECT_FALSE(compositor_->should_draw_frame()); |
| 1475 | 1481 |
| 1476 // Now force compositing back on and check that we redraw the scene. | 1482 // Now force compositing back on and check that we redraw the scene. |
| 1477 const int kPrevForcedDraws = compositor_->num_forced_draws(); | 1483 const int kPrevForcedDraws = compositor_->num_forced_draws(); |
| 1478 wm_->IncrementCompositingRequests(); | 1484 wm_->IncrementCompositingRequests(); |
| 1479 EXPECT_EQ(kPrevForcedDraws + 1, compositor_->num_forced_draws()); | 1485 EXPECT_EQ(kPrevForcedDraws + 1, compositor_->num_forced_draws()); |
| 1480 wm_->HandleTopFullscreenActorChange(actor); | 1486 wm_->HandleTopFullscreenActorChange(actor); |
| 1481 EXPECT_EQ(static_cast<XWindow>(0), wm_->unredirected_fullscreen_xid_); | 1487 EXPECT_EQ(static_cast<XWindow>(0), wm_->unredirected_fullscreen_xid_); |
| 1482 EXPECT_TRUE(compositor_->should_draw_frame()); | 1488 EXPECT_TRUE(compositor_->should_draw_frame()); |
| 1483 EXPECT_FALSE(wm_->disable_compositing_task_is_pending_); | 1489 EXPECT_FALSE(wm_->disable_compositing_task_is_pending_); |
| 1484 | 1490 |
| 1485 // Resize the window and remove the compositing request. Since we're waiting | 1491 // Resize the window and remove the compositing request. Since we're waiting |
| 1486 // for the window to be repainted after the resize, we should continue | 1492 // for the window to be repainted after the resize, we should continue |
| 1487 // compositing. | 1493 // compositing. |
| 1488 win->ResizeClient(wm_->width() / 2, wm_->height() / 2, GRAVITY_NORTHWEST); | 1494 win->Resize(Size(wm_->width() / 2, wm_->height() / 2), GRAVITY_NORTHWEST); |
| 1489 wm_->DecrementCompositingRequests(); | 1495 wm_->DecrementCompositingRequests(); |
| 1490 wm_->HandleTopFullscreenActorChange(actor); | 1496 wm_->HandleTopFullscreenActorChange(actor); |
| 1491 EXPECT_EQ(static_cast<XWindow>(0), wm_->unredirected_fullscreen_xid_); | 1497 EXPECT_EQ(static_cast<XWindow>(0), wm_->unredirected_fullscreen_xid_); |
| 1492 EXPECT_TRUE(compositor_->should_draw_frame()); | 1498 EXPECT_TRUE(compositor_->should_draw_frame()); |
| 1493 EXPECT_FALSE(wm_->disable_compositing_task_is_pending_); | 1499 EXPECT_FALSE(wm_->disable_compositing_task_is_pending_); |
| 1494 | 1500 |
| 1495 // After the window is repainted, we should still be compositing since the | 1501 // After the window is repainted, we should still be compositing since the |
| 1496 // window is no longer covering the entire screen. | 1502 // window is no longer covering the entire screen. |
| 1497 SendSyncRequestProtocolAlarm(xid); | 1503 SendSyncRequestProtocolAlarm(xid); |
| 1498 wm_->HandleTopFullscreenActorChange(NULL); | 1504 wm_->HandleTopFullscreenActorChange(NULL); |
| 1499 EXPECT_EQ(static_cast<XWindow>(0), wm_->unredirected_fullscreen_xid_); | 1505 EXPECT_EQ(static_cast<XWindow>(0), wm_->unredirected_fullscreen_xid_); |
| 1500 EXPECT_TRUE(compositor_->should_draw_frame()); | 1506 EXPECT_TRUE(compositor_->should_draw_frame()); |
| 1501 EXPECT_FALSE(wm_->disable_compositing_task_is_pending_); | 1507 EXPECT_FALSE(wm_->disable_compositing_task_is_pending_); |
| 1502 } | 1508 } |
| 1503 | 1509 |
| 1504 } // namespace window_manager | 1510 } // namespace window_manager |
| 1505 | 1511 |
| 1506 int main(int argc, char** argv) { | 1512 int main(int argc, char** argv) { |
| 1507 return window_manager::InitAndRunTests(&argc, argv, &FLAGS_logtostderr); | 1513 return window_manager::InitAndRunTests(&argc, argv, &FLAGS_logtostderr); |
| 1508 } | 1514 } |
| OLD | NEW |