Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(347)

Side by Side Diff: services/ui/ws/display_unittest.cc

Issue 2857963003: Add {Lock,Unlock,Show,Hide}Cursor() to the window manager mojom. (Closed)
Patch Set: General cleanup. Created 3 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright 2016 The Chromium Authors. All rights reserved. 1 // Copyright 2016 The Chromium 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 <stdint.h> 5 #include <stdint.h>
6 6
7 #include <string> 7 #include <string>
8 8
9 #include "base/macros.h" 9 #include "base/macros.h"
10 #include "base/message_loop/message_loop.h" 10 #include "base/message_loop/message_loop.h"
11 #include "services/ui/common/types.h" 11 #include "services/ui/common/types.h"
12 #include "services/ui/common/util.h" 12 #include "services/ui/common/util.h"
13 #include "services/ui/display/viewport_metrics.h" 13 #include "services/ui/display/viewport_metrics.h"
14 #include "services/ui/public/interfaces/window_tree.mojom.h" 14 #include "services/ui/public/interfaces/window_tree.mojom.h"
15 #include "services/ui/ws/display_manager.h" 15 #include "services/ui/ws/display_manager.h"
16 #include "services/ui/ws/ids.h" 16 #include "services/ui/ws/ids.h"
17 #include "services/ui/ws/platform_display.h" 17 #include "services/ui/ws/platform_display.h"
18 #include "services/ui/ws/platform_display_factory.h" 18 #include "services/ui/ws/platform_display_factory.h"
19 #include "services/ui/ws/server_window.h" 19 #include "services/ui/ws/server_window.h"
20 #include "services/ui/ws/test_utils.h" 20 #include "services/ui/ws/test_utils.h"
21 #include "services/ui/ws/window_manager_display_root.h" 21 #include "services/ui/ws/window_manager_display_root.h"
22 #include "services/ui/ws/window_manager_state.h" 22 #include "services/ui/ws/window_manager_state.h"
23 #include "services/ui/ws/window_server.h" 23 #include "services/ui/ws/window_server.h"
24 #include "services/ui/ws/window_server_delegate.h" 24 #include "services/ui/ws/window_server_delegate.h"
25 #include "services/ui/ws/window_tree.h" 25 #include "services/ui/ws/window_tree.h"
26 #include "services/ui/ws/window_tree_binding.h" 26 #include "services/ui/ws/window_tree_binding.h"
27 #include "testing/gtest/include/gtest/gtest.h" 27 #include "testing/gtest/include/gtest/gtest.h"
28 #include "ui/base/cursor/cursor.h"
28 #include "ui/display/display.h" 29 #include "ui/display/display.h"
29 #include "ui/events/event.h" 30 #include "ui/events/event.h"
30 #include "ui/gfx/geometry/rect.h" 31 #include "ui/gfx/geometry/rect.h"
31 32
32 namespace ui { 33 namespace ui {
33 namespace ws { 34 namespace ws {
34 namespace test { 35 namespace test {
35 namespace { 36 namespace {
36 37
37 const UserId kTestId1 = "2"; 38 const UserId kTestId1 = "2";
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after
96 ~DisplayTest() override {} 97 ~DisplayTest() override {}
97 98
98 WindowServer* window_server() { return ws_test_helper_.window_server(); } 99 WindowServer* window_server() { return ws_test_helper_.window_server(); }
99 DisplayManager* display_manager() { 100 DisplayManager* display_manager() {
100 return window_server()->display_manager(); 101 return window_server()->display_manager();
101 } 102 }
102 TestWindowServerDelegate* window_server_delegate() { 103 TestWindowServerDelegate* window_server_delegate() {
103 return ws_test_helper_.window_server_delegate(); 104 return ws_test_helper_.window_server_delegate();
104 } 105 }
105 TestScreenManager& screen_manager() { return screen_manager_; } 106 TestScreenManager& screen_manager() { return screen_manager_; }
107 const ui::CursorData& cursor() { return ws_test_helper_.cursor(); }
106 108
107 protected: 109 protected:
108 // testing::Test: 110 // testing::Test:
109 void SetUp() override { 111 void SetUp() override {
110 screen_manager_.Init(window_server()->display_manager()); 112 screen_manager_.Init(window_server()->display_manager());
111 window_server()->user_id_tracker()->AddUserId(kTestId1); 113 window_server()->user_id_tracker()->AddUserId(kTestId1);
112 window_server()->user_id_tracker()->AddUserId(kTestId2); 114 window_server()->user_id_tracker()->AddUserId(kTestId2);
113 } 115 }
114 116
115 private: 117 private:
(...skipping 305 matching lines...) Expand 10 before | Expand all | Expand 10 after
421 // The window should still be valid on the server side. 423 // The window should still be valid on the server side.
422 ASSERT_TRUE(tree->GetWindowByClientId(secondary_root_id)); 424 ASSERT_TRUE(tree->GetWindowByClientId(secondary_root_id));
423 // No changes. 425 // No changes.
424 ASSERT_EQ(0u, tree_client->tracker()->changes()->size()); 426 ASSERT_EQ(0u, tree_client->tracker()->changes()->size());
425 427
426 // The window should be destroyed when the client says so. 428 // The window should be destroyed when the client says so.
427 ASSERT_TRUE(tree->DeleteWindow(secondary_root_id)); 429 ASSERT_TRUE(tree->DeleteWindow(secondary_root_id));
428 EXPECT_TRUE(secondary_root_destroyed); 430 EXPECT_TRUE(secondary_root_destroyed);
429 } 431 }
430 432
433 TEST_F(DisplayTest, CursorLockTest) {
434 AddWindowManager(window_server(), kTestId1);
435 const int64_t display_id =
436 screen_manager().AddDisplay(MakeDisplay(0, 0, 1024, 768, 1.0f));
437
438 ASSERT_EQ(1u, display_manager()->displays().size());
439 Display* display = display_manager()->GetDisplayById(display_id);
440
441 display->UpdateNativeCursor(ui::CursorData(ui::CursorType::kWait));
442 EXPECT_TRUE(cursor().IsType(ui::CursorType::kWait));
443
444 display->LockCursor();
445
446 display->UpdateNativeCursor(ui::CursorData(ui::CursorType::kCell));
447 EXPECT_TRUE(cursor().IsType(ui::CursorType::kWait));
448
449 display->UnlockCursor();
450
451 EXPECT_TRUE(cursor().IsType(ui::CursorType::kCell));
452 }
453
454 TEST_F(DisplayTest, CursorVisibilityTest) {
455 AddWindowManager(window_server(), kTestId1);
456 const int64_t display_id =
457 screen_manager().AddDisplay(MakeDisplay(0, 0, 1024, 768, 1.0f));
458
459 ASSERT_EQ(1u, display_manager()->displays().size());
460 Display* display = display_manager()->GetDisplayById(display_id);
461
462 display->UpdateNativeCursor(ui::CursorData(ui::CursorType::kWait));
463 EXPECT_TRUE(cursor().IsType(ui::CursorType::kWait));
464
465 display->HideCursor();
466 EXPECT_TRUE(cursor().IsType(ui::CursorType::kNone));
467
468 display->ShowCursor();
469 EXPECT_TRUE(cursor().IsType(ui::CursorType::kWait));
470
471 display->HideCursor();
472 display->UpdateNativeCursor(ui::CursorData(ui::CursorType::kCell));
473 EXPECT_TRUE(cursor().IsType(ui::CursorType::kNone));
474
475 display->ShowCursor();
476 EXPECT_TRUE(cursor().IsType(ui::CursorType::kCell));
477 }
478
479 TEST_F(DisplayTest, CursorOverrideTest) {
480 AddWindowManager(window_server(), kTestId1);
481 const int64_t display_id =
482 screen_manager().AddDisplay(MakeDisplay(0, 0, 1024, 768, 1.0f));
483
484 ASSERT_EQ(1u, display_manager()->displays().size());
485 Display* display = display_manager()->GetDisplayById(display_id);
486
487 display->UpdateNativeCursor(ui::CursorData(ui::CursorType::kWait));
488 EXPECT_TRUE(cursor().IsType(ui::CursorType::kWait));
489
490 display->SetGlobalOverrideCursor(ui::CursorData(ui::CursorType::kCell));
491 EXPECT_TRUE(cursor().IsType(ui::CursorType::kCell));
492
493 display->SetGlobalOverrideCursor(base::nullopt);
494 EXPECT_TRUE(cursor().IsType(ui::CursorType::kWait));
495 }
496
497 TEST_F(DisplayTest, CursorOverrideLockTest) {
498 // This test is meant to mimic the calls in ScreenshotController when it sets
499 // a cursor.
500 AddWindowManager(window_server(), kTestId1);
501 const int64_t display_id =
502 screen_manager().AddDisplay(MakeDisplay(0, 0, 1024, 768, 1.0f));
503
504 ASSERT_EQ(1u, display_manager()->displays().size());
505 Display* display = display_manager()->GetDisplayById(display_id);
506
507 display->UpdateNativeCursor(ui::CursorData(ui::CursorType::kWait));
508 EXPECT_TRUE(cursor().IsType(ui::CursorType::kWait));
509
510 display->SetGlobalOverrideCursor(ui::CursorData(ui::CursorType::kCross));
511 display->LockCursor();
512 display->SetGlobalOverrideCursor(base::nullopt);
513 EXPECT_TRUE(cursor().IsType(ui::CursorType::kCross));
514
515 display->UnlockCursor();
516 EXPECT_TRUE(cursor().IsType(ui::CursorType::kWait));
517 }
518
519 TEST_F(DisplayTest, CursorOverrideVisibilityTest) {
520 // This test is meant to mimic the calls in ScreenshotController when it
521 // hides the cursor.
522 AddWindowManager(window_server(), kTestId1);
523 const int64_t display_id =
524 screen_manager().AddDisplay(MakeDisplay(0, 0, 1024, 768, 1.0f));
525
526 ASSERT_EQ(1u, display_manager()->displays().size());
527 Display* display = display_manager()->GetDisplayById(display_id);
528
529 display->UpdateNativeCursor(ui::CursorData(ui::CursorType::kWait));
530 EXPECT_TRUE(cursor().IsType(ui::CursorType::kWait));
531
532 display->HideCursor();
533 display->LockCursor();
534 display->SetGlobalOverrideCursor(base::nullopt);
535 display->ShowCursor();
536 EXPECT_TRUE(cursor().IsType(ui::CursorType::kNone));
537
538 display->UnlockCursor();
539 EXPECT_TRUE(cursor().IsType(ui::CursorType::kWait));
540 }
541
431 } // namespace test 542 } // namespace test
432 } // namespace ws 543 } // namespace ws
433 } // namespace ui 544 } // namespace ui
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698