| 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 <cmath> | 5 #include <cmath> |
| 6 #include <vector> | 6 #include <vector> |
| 7 | 7 |
| 8 #include <gflags/gflags.h> | 8 #include <gflags/gflags.h> |
| 9 #include <gtest/gtest.h> | 9 #include <gtest/gtest.h> |
| 10 | 10 |
| (...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 60 EXPECT_EQ(0, actor->y()); | 60 EXPECT_EQ(0, actor->y()); |
| 61 EXPECT_FLOAT_EQ(1.0, actor->scale_x()); | 61 EXPECT_FLOAT_EQ(1.0, actor->scale_x()); |
| 62 EXPECT_FLOAT_EQ(1.0, actor->scale_y()); | 62 EXPECT_FLOAT_EQ(1.0, actor->scale_y()); |
| 63 EXPECT_FLOAT_EQ(1.0, actor->opacity()); | 63 EXPECT_FLOAT_EQ(1.0, actor->opacity()); |
| 64 } | 64 } |
| 65 | 65 |
| 66 void TestActorConfiguredForFastClose( | 66 void TestActorConfiguredForFastClose( |
| 67 MockCompositor::TexturePixmapActor* actor) { | 67 MockCompositor::TexturePixmapActor* actor) { |
| 68 CHECK(actor); | 68 CHECK(actor); |
| 69 EXPECT_TRUE(actor->is_shown()); | 69 EXPECT_TRUE(actor->is_shown()); |
| 70 EXPECT_FLOAT_EQ(round(0.5 * wm_->width()), actor->x()); | 70 EXPECT_EQ(static_cast<int>(round(0.5 * wm_->width())), actor->x()); |
| 71 EXPECT_FLOAT_EQ(round(0.5 * wm_->height()), actor->y()); | 71 EXPECT_EQ(static_cast<int>(round(0.5 * wm_->height())), actor->y()); |
| 72 EXPECT_FLOAT_EQ(0.0, actor->scale_x()); | 72 EXPECT_FLOAT_EQ(0.0, actor->scale_x()); |
| 73 EXPECT_FLOAT_EQ(0.0, actor->scale_y()); | 73 EXPECT_FLOAT_EQ(0.0, actor->scale_y()); |
| 74 EXPECT_FLOAT_EQ(0.0, actor->opacity()); | 74 EXPECT_FLOAT_EQ(0.0, actor->opacity()); |
| 75 } | 75 } |
| 76 | 76 |
| 77 void TestActorConfiguredForFadeout( |
| 78 MockCompositor::TexturePixmapActor* actor) { |
| 79 CHECK(actor); |
| 80 EXPECT_TRUE(actor->is_shown()); |
| 81 EXPECT_EQ(0, actor->x()); |
| 82 EXPECT_EQ(0, actor->y()); |
| 83 EXPECT_FLOAT_EQ(1.0, actor->scale_x()); |
| 84 EXPECT_FLOAT_EQ(1.0, actor->scale_y()); |
| 85 EXPECT_FLOAT_EQ(0.0, actor->opacity()); |
| 86 } |
| 87 |
| 77 bool IsOnlyActiveVisibilityGroup(int group) { | 88 bool IsOnlyActiveVisibilityGroup(int group) { |
| 78 if (compositor_->active_visibility_groups().size() != | 89 if (compositor_->active_visibility_groups().size() != |
| 79 static_cast<size_t>(1)) { | 90 static_cast<size_t>(1)) { |
| 80 return false; | 91 return false; |
| 81 } | 92 } |
| 82 return (*(compositor_->active_visibility_groups().begin()) == group); | 93 return (*(compositor_->active_visibility_groups().begin()) == group); |
| 83 } | 94 } |
| 84 | 95 |
| 85 ScreenLockerHandler* handler_; | 96 ScreenLockerHandler* handler_; |
| 86 }; | 97 }; |
| (...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 188 MockCompositor::TexturePixmapActor* actor = GetSnapshotActor(); | 199 MockCompositor::TexturePixmapActor* actor = GetSnapshotActor(); |
| 189 ASSERT_TRUE(actor != NULL); | 200 ASSERT_TRUE(actor != NULL); |
| 190 TestActorConfiguredForSlowClose(actor); | 201 TestActorConfiguredForSlowClose(actor); |
| 191 EXPECT_NE(-1, handler_->destroy_snapshot_timeout_id_); | 202 EXPECT_NE(-1, handler_->destroy_snapshot_timeout_id_); |
| 192 | 203 |
| 193 // The snapshot should be the only actor currently visible. | 204 // The snapshot should be the only actor currently visible. |
| 194 EXPECT_EQ(static_cast<size_t>(2), actor->visibility_groups().size()); | 205 EXPECT_EQ(static_cast<size_t>(2), actor->visibility_groups().size()); |
| 195 EXPECT_TRUE(actor->visibility_groups().count( | 206 EXPECT_TRUE(actor->visibility_groups().count( |
| 196 WindowManager::VISIBILITY_GROUP_SCREEN_LOCKER) != 0); | 207 WindowManager::VISIBILITY_GROUP_SCREEN_LOCKER) != 0); |
| 197 EXPECT_TRUE(actor->visibility_groups().count( | 208 EXPECT_TRUE(actor->visibility_groups().count( |
| 198 WindowManager::VISIBILITY_GROUP_SHUTDOWN) != 0); | 209 WindowManager::VISIBILITY_GROUP_SESSION_ENDING) != 0); |
| 199 EXPECT_TRUE(IsOnlyActiveVisibilityGroup( | 210 EXPECT_TRUE(IsOnlyActiveVisibilityGroup( |
| 200 WindowManager::VISIBILITY_GROUP_SCREEN_LOCKER)); | 211 WindowManager::VISIBILITY_GROUP_SCREEN_LOCKER)); |
| 201 | 212 |
| 202 // Now tell the WM that the button was released before being held long | 213 // Now tell the WM that the button was released before being held long |
| 203 // enough to lock. | 214 // enough to lock. |
| 204 msg.set_param(0, chromeos::WM_IPC_POWER_BUTTON_ABORTED_LOCK); | 215 msg.set_param(0, chromeos::WM_IPC_POWER_BUTTON_ABORTED_LOCK); |
| 205 SendWmIpcMessage(msg); | 216 SendWmIpcMessage(msg); |
| 206 | 217 |
| 207 // Check that we're still showing the same actor, and that it's being | 218 // Check that we're still showing the same actor, and that it's being |
| 208 // scaled back to its natural size. | 219 // scaled back to its natural size. |
| (...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 267 SendWmIpcMessage(msg); | 278 SendWmIpcMessage(msg); |
| 268 | 279 |
| 269 // We should have taken a snapshot of the screen. | 280 // We should have taken a snapshot of the screen. |
| 270 MockCompositor::TexturePixmapActor* actor = GetSnapshotActor(); | 281 MockCompositor::TexturePixmapActor* actor = GetSnapshotActor(); |
| 271 ASSERT_TRUE(actor != NULL); | 282 ASSERT_TRUE(actor != NULL); |
| 272 TestActorConfiguredForSlowClose(actor); | 283 TestActorConfiguredForSlowClose(actor); |
| 273 EXPECT_NE(-1, handler_->destroy_snapshot_timeout_id_); | 284 EXPECT_NE(-1, handler_->destroy_snapshot_timeout_id_); |
| 274 | 285 |
| 275 // The snapshot should be the only actor currently visible. | 286 // The snapshot should be the only actor currently visible. |
| 276 EXPECT_TRUE(actor->visibility_groups().count( | 287 EXPECT_TRUE(actor->visibility_groups().count( |
| 277 WindowManager::VISIBILITY_GROUP_SHUTDOWN) != 0); | 288 WindowManager::VISIBILITY_GROUP_SESSION_ENDING) != 0); |
| 278 EXPECT_TRUE(IsOnlyActiveVisibilityGroup( | 289 EXPECT_TRUE(IsOnlyActiveVisibilityGroup( |
| 279 WindowManager::VISIBILITY_GROUP_SHUTDOWN)); | 290 WindowManager::VISIBILITY_GROUP_SESSION_ENDING)); |
| 280 | 291 |
| 281 // Now tell the WM that the button was released before being held long | 292 // Now tell the WM that the button was released before being held long |
| 282 // enough to shut down. | 293 // enough to shut down. |
| 283 msg.set_param(0, chromeos::WM_IPC_POWER_BUTTON_ABORTED_SHUTDOWN); | 294 msg.set_param(0, chromeos::WM_IPC_POWER_BUTTON_ABORTED_SHUTDOWN); |
| 284 SendWmIpcMessage(msg); | 295 SendWmIpcMessage(msg); |
| 285 | 296 |
| 286 // Check that we're still showing the same actor, and that it's being | 297 // Check that we're still showing the same actor, and that it's being |
| 287 // scaled back to its natural size. | 298 // scaled back to its natural size. |
| 288 ASSERT_EQ(actor, GetSnapshotActor()); | 299 ASSERT_EQ(actor, GetSnapshotActor()); |
| 289 TestActorConfiguredForUndoSlowClose(actor); | 300 TestActorConfiguredForUndoSlowClose(actor); |
| (...skipping 21 matching lines...) Expand all Loading... |
| 311 ASSERT_TRUE(IsOnlyActiveVisibilityGroup( | 322 ASSERT_TRUE(IsOnlyActiveVisibilityGroup( |
| 312 WindowManager::VISIBILITY_GROUP_SCREEN_LOCKER)); | 323 WindowManager::VISIBILITY_GROUP_SCREEN_LOCKER)); |
| 313 | 324 |
| 314 // Enter the pre-shutdown state as before. | 325 // Enter the pre-shutdown state as before. |
| 315 msg.set_param(0, chromeos::WM_IPC_POWER_BUTTON_PRE_SHUTDOWN); | 326 msg.set_param(0, chromeos::WM_IPC_POWER_BUTTON_PRE_SHUTDOWN); |
| 316 SendWmIpcMessage(msg); | 327 SendWmIpcMessage(msg); |
| 317 actor = GetSnapshotActor(); | 328 actor = GetSnapshotActor(); |
| 318 ASSERT_TRUE(actor != NULL); | 329 ASSERT_TRUE(actor != NULL); |
| 319 TestActorConfiguredForSlowClose(actor); | 330 TestActorConfiguredForSlowClose(actor); |
| 320 EXPECT_TRUE(IsOnlyActiveVisibilityGroup( | 331 EXPECT_TRUE(IsOnlyActiveVisibilityGroup( |
| 321 WindowManager::VISIBILITY_GROUP_SHUTDOWN)); | 332 WindowManager::VISIBILITY_GROUP_SESSION_ENDING)); |
| 322 | 333 |
| 323 // After aborting, we should be showing just the screen locker window. | 334 // After aborting, we should be showing just the screen locker window. |
| 324 msg.set_param(0, chromeos::WM_IPC_POWER_BUTTON_ABORTED_SHUTDOWN); | 335 msg.set_param(0, chromeos::WM_IPC_POWER_BUTTON_ABORTED_SHUTDOWN); |
| 325 SendWmIpcMessage(msg); | 336 SendWmIpcMessage(msg); |
| 326 ASSERT_NE(-1, handler_->destroy_snapshot_timeout_id_); | 337 ASSERT_NE(-1, handler_->destroy_snapshot_timeout_id_); |
| 327 wm_->event_loop()->RunTimeoutForTesting( | 338 wm_->event_loop()->RunTimeoutForTesting( |
| 328 handler_->destroy_snapshot_timeout_id_); | 339 handler_->destroy_snapshot_timeout_id_); |
| 329 EXPECT_EQ(-1, handler_->destroy_snapshot_timeout_id_); | 340 EXPECT_EQ(-1, handler_->destroy_snapshot_timeout_id_); |
| 330 EXPECT_TRUE(IsOnlyActiveVisibilityGroup( | 341 EXPECT_TRUE(IsOnlyActiveVisibilityGroup( |
| 331 WindowManager::VISIBILITY_GROUP_SCREEN_LOCKER)); | 342 WindowManager::VISIBILITY_GROUP_SCREEN_LOCKER)); |
| 332 } | 343 } |
| 333 | 344 |
| 334 // Test that we do stuff in response to notification that the system is | 345 // Test that we do stuff in response to notification that the system is |
| 335 // shutting down. | 346 // shutting down. |
| 336 TEST_F(ScreenLockerHandlerTest, HandleShutdown) { | 347 TEST_F(ScreenLockerHandlerTest, HandleShutdown) { |
| 337 // Go into the pre-shutdown state first. | 348 // Go into the pre-shutdown state first. |
| 338 WmIpc::Message msg(chromeos::WM_IPC_MESSAGE_WM_NOTIFY_POWER_BUTTON_STATE); | 349 WmIpc::Message msg(chromeos::WM_IPC_MESSAGE_WM_NOTIFY_POWER_BUTTON_STATE); |
| 339 msg.set_param(0, chromeos::WM_IPC_POWER_BUTTON_PRE_SHUTDOWN); | 350 msg.set_param(0, chromeos::WM_IPC_POWER_BUTTON_PRE_SHUTDOWN); |
| 340 SendWmIpcMessage(msg); | 351 SendWmIpcMessage(msg); |
| 341 | 352 |
| 342 // Check that we've started the slow-close animation. | 353 // Check that we've started the slow-close animation. |
| 343 MockCompositor::TexturePixmapActor* actor = GetSnapshotActor(); | 354 MockCompositor::TexturePixmapActor* actor = GetSnapshotActor(); |
| 344 ASSERT_TRUE(actor != NULL); | 355 ASSERT_TRUE(actor != NULL); |
| 345 TestActorConfiguredForSlowClose(actor); | 356 TestActorConfiguredForSlowClose(actor); |
| 346 EXPECT_NE(-1, handler_->destroy_snapshot_timeout_id_); | 357 EXPECT_NE(-1, handler_->destroy_snapshot_timeout_id_); |
| 347 EXPECT_TRUE(IsOnlyActiveVisibilityGroup( | 358 EXPECT_TRUE(IsOnlyActiveVisibilityGroup( |
| 348 WindowManager::VISIBILITY_GROUP_SHUTDOWN)); | 359 WindowManager::VISIBILITY_GROUP_SESSION_ENDING)); |
| 349 | 360 |
| 350 // Notify the window manager that the system is being shut down. | 361 // Notify the window manager that the system is being shut down. |
| 351 msg.set_type(chromeos::WM_IPC_MESSAGE_WM_NOTIFY_SHUTTING_DOWN); | 362 msg.set_type(chromeos::WM_IPC_MESSAGE_WM_NOTIFY_SHUTTING_DOWN); |
| 352 msg.set_param(0, 0); | 363 msg.set_param(0, 0); |
| 353 SendWmIpcMessage(msg); | 364 SendWmIpcMessage(msg); |
| 354 | 365 |
| 355 // Check that we grabbed the pointer and keyboard and assigned a transparent | 366 // Check that we grabbed the pointer and keyboard and assigned a transparent |
| 356 // cursor to the root window. | 367 // cursor to the root window. |
| 357 XWindow root = xconn_->GetRootWindow(); | 368 XWindow root = xconn_->GetRootWindow(); |
| 358 EXPECT_EQ(root, xconn_->pointer_grab_xid()); | 369 EXPECT_EQ(root, xconn_->pointer_grab_xid()); |
| 359 EXPECT_EQ(root, xconn_->keyboard_grab_xid()); | 370 EXPECT_EQ(root, xconn_->keyboard_grab_xid()); |
| 360 EXPECT_EQ(MockXConnection::kTransparentCursor, | 371 EXPECT_EQ(MockXConnection::kTransparentCursor, |
| 361 xconn_->GetWindowInfoOrDie(root)->cursor); | 372 xconn_->GetWindowInfoOrDie(root)->cursor); |
| 362 | 373 |
| 363 // We should be using the same snapshot that we already grabbed, and we | 374 // We should be using the same snapshot that we already grabbed, and we |
| 364 // should be displaying the fast-close animation. | 375 // should be displaying the fast-close animation. |
| 365 ASSERT_EQ(actor, GetSnapshotActor()); | 376 ASSERT_EQ(actor, GetSnapshotActor()); |
| 366 TestActorConfiguredForFastClose(actor); | 377 TestActorConfiguredForFastClose(actor); |
| 367 EXPECT_TRUE(IsOnlyActiveVisibilityGroup( | 378 EXPECT_TRUE(IsOnlyActiveVisibilityGroup( |
| 368 WindowManager::VISIBILITY_GROUP_SHUTDOWN)); | 379 WindowManager::VISIBILITY_GROUP_SESSION_ENDING)); |
| 369 | 380 |
| 370 // There's no need to destroy the snapshot after we're done with the | 381 // There's no need to destroy the snapshot after we're done with the |
| 371 // animation; we're not going to be showing anything else onscreen. | 382 // animation; we're not going to be showing anything else onscreen. |
| 372 EXPECT_EQ(-1, handler_->destroy_snapshot_timeout_id_); | 383 EXPECT_EQ(-1, handler_->destroy_snapshot_timeout_id_); |
| 373 } | 384 } |
| 374 | 385 |
| 375 // Test that we don't consider the screen to be locked until the screen | 386 // Test that we don't consider the screen to be locked until the screen |
| 376 // locker window is actually visible. | 387 // locker window is actually visible. |
| 377 TEST_F(ScreenLockerHandlerTest, DeferLockUntilWindowIsVisible) { | 388 TEST_F(ScreenLockerHandlerTest, DeferLockUntilWindowIsVisible) { |
| 378 // Enable the sync request protocol on a screen locker window before | 389 // Enable the sync request protocol on a screen locker window before |
| (...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 419 | 430 |
| 420 // The actor should be removed from the visibility group when the window is | 431 // The actor should be removed from the visibility group when the window is |
| 421 // unmapped. | 432 // unmapped. |
| 422 XEvent event; | 433 XEvent event; |
| 423 xconn_->InitUnmapEvent(&event, info_bubble_xid); | 434 xconn_->InitUnmapEvent(&event, info_bubble_xid); |
| 424 wm_->HandleEvent(&event); | 435 wm_->HandleEvent(&event); |
| 425 EXPECT_FALSE(info_bubble_actor->visibility_groups().count( | 436 EXPECT_FALSE(info_bubble_actor->visibility_groups().count( |
| 426 WindowManager::VISIBILITY_GROUP_SCREEN_LOCKER)); | 437 WindowManager::VISIBILITY_GROUP_SCREEN_LOCKER)); |
| 427 } | 438 } |
| 428 | 439 |
| 440 // Test that we handle messages from Chrome notifying us that the user is |
| 441 // signing out. |
| 442 TEST_F(ScreenLockerHandlerTest, SigningOut) { |
| 443 WmIpc::Message msg(chromeos::WM_IPC_MESSAGE_WM_NOTIFY_SIGNING_OUT); |
| 444 SendWmIpcMessage(msg); |
| 445 |
| 446 // We should grab the pointer and keyboard, assign a transparent cursor to the |
| 447 // root window, and fade out a snapshot of the screen. |
| 448 XWindow root = xconn_->GetRootWindow(); |
| 449 EXPECT_EQ(root, xconn_->pointer_grab_xid()); |
| 450 EXPECT_EQ(root, xconn_->keyboard_grab_xid()); |
| 451 EXPECT_EQ(MockXConnection::kTransparentCursor, |
| 452 xconn_->GetWindowInfoOrDie(root)->cursor); |
| 453 TestActorConfiguredForFadeout(GetSnapshotActor()); |
| 454 EXPECT_TRUE(IsOnlyActiveVisibilityGroup( |
| 455 WindowManager::VISIBILITY_GROUP_SESSION_ENDING)); |
| 456 } |
| 457 |
| 429 } // namespace window_manager | 458 } // namespace window_manager |
| 430 | 459 |
| 431 int main(int argc, char** argv) { | 460 int main(int argc, char** argv) { |
| 432 return window_manager::InitAndRunTests(&argc, argv, &FLAGS_logtostderr); | 461 return window_manager::InitAndRunTests(&argc, argv, &FLAGS_logtostderr); |
| 433 } | 462 } |
| OLD | NEW |