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

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

Issue 2857963003: Add {Lock,Unlock,Show,Hide}Cursor() to the window manager mojom. (Closed)
Patch Set: sky comments 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
« no previous file with comments | « services/ui/ws/cursor_state.cc ('k') | services/ui/ws/display.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 // Copyright 2017 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #include "services/ui/ws/cursor_state.h"
6
7 #include "services/ui/ws/display_manager.h"
8 #include "services/ui/ws/test_utils.h"
9 #include "services/ui/ws/window_server.h"
10 #include "services/ui/ws/window_server_delegate.h"
11 #include "testing/gtest/include/gtest/gtest.h"
12 #include "ui/base/cursor/cursor.h"
13
14 namespace ui {
15 namespace ws {
16 namespace test {
17 namespace {
18
19 const UserId kTestId1 = "2";
20
21 } // namespace
22
23 class CursorStateTest : public testing::Test {
24 public:
25 CursorStateTest() {}
26 ~CursorStateTest() override {}
27
28 WindowServer* window_server() { return ws_test_helper_.window_server(); }
29 DisplayManager* display_manager() {
30 return window_server()->display_manager();
31 }
32 TestScreenManager& screen_manager() { return screen_manager_; }
33 CursorState* cursor_state() { return cursor_state_.get(); }
34 const ui::CursorData& cursor() { return ws_test_helper_.cursor(); }
35
36 protected:
37 // testing::Test:
38 void SetUp() override {
39 screen_manager_.Init(window_server()->display_manager());
40 window_server()->user_id_tracker()->AddUserId(kTestId1);
41 cursor_state_ = base::MakeUnique<CursorState>(display_manager());
42
43 AddWindowManager(window_server(), kTestId1);
44 screen_manager().AddDisplay(MakeDisplay(0, 0, 1024, 768, 1.0f));
45 ASSERT_EQ(1u, display_manager()->displays().size());
46 }
47
48 private:
49 WindowServerTestHelper ws_test_helper_;
50 TestScreenManager screen_manager_;
51
52 std::unique_ptr<CursorState> cursor_state_;
53
54 DISALLOW_COPY_AND_ASSIGN(CursorStateTest);
55 };
56
57 TEST_F(CursorStateTest, CursorLockTest) {
58 cursor_state()->SetCurrentWindowCursor(ui::CursorData(ui::CursorType::kWait));
59 EXPECT_TRUE(cursor().IsType(ui::CursorType::kWait));
60
61 cursor_state()->LockCursor();
62 cursor_state()->SetCurrentWindowCursor(ui::CursorData(ui::CursorType::kCell));
63 EXPECT_TRUE(cursor().IsType(ui::CursorType::kWait));
64
65 cursor_state()->UnlockCursor();
66 EXPECT_TRUE(cursor().IsType(ui::CursorType::kCell));
67 }
68
69 TEST_F(CursorStateTest, CursorVisibilityTest) {
70 cursor_state()->SetCurrentWindowCursor(ui::CursorData(ui::CursorType::kWait));
71 EXPECT_TRUE(cursor().IsType(ui::CursorType::kWait));
72
73 cursor_state()->SetCursorVisible(false);
74 EXPECT_TRUE(cursor().IsType(ui::CursorType::kNone));
75
76 cursor_state()->SetCursorVisible(true);
77 EXPECT_TRUE(cursor().IsType(ui::CursorType::kWait));
78
79 cursor_state()->SetCursorVisible(false);
80 cursor_state()->SetCurrentWindowCursor(ui::CursorData(ui::CursorType::kCell));
81 EXPECT_TRUE(cursor().IsType(ui::CursorType::kNone));
82
83 cursor_state()->SetCursorVisible(true);
84 EXPECT_TRUE(cursor().IsType(ui::CursorType::kCell));
85 }
86
87 TEST_F(CursorStateTest, CursorOverrideTest) {
88 cursor_state()->SetCurrentWindowCursor(ui::CursorData(ui::CursorType::kWait));
89 EXPECT_TRUE(cursor().IsType(ui::CursorType::kWait));
90
91 cursor_state()->SetGlobalOverrideCursor(
92 ui::CursorData(ui::CursorType::kCell));
93 EXPECT_TRUE(cursor().IsType(ui::CursorType::kCell));
94
95 cursor_state()->SetGlobalOverrideCursor(base::nullopt);
96 EXPECT_TRUE(cursor().IsType(ui::CursorType::kWait));
97 }
98
99 TEST_F(CursorStateTest, CursorOverrideLockTest) {
100 // This test is meant to mimic the calls in ScreenshotController when it sets
101 // a cursor.
102 cursor_state()->SetCurrentWindowCursor(ui::CursorData(ui::CursorType::kWait));
103 EXPECT_TRUE(cursor().IsType(ui::CursorType::kWait));
104
105 cursor_state()->SetGlobalOverrideCursor(
106 ui::CursorData(ui::CursorType::kCross));
107 cursor_state()->LockCursor();
108 cursor_state()->SetGlobalOverrideCursor(base::nullopt);
109 EXPECT_TRUE(cursor().IsType(ui::CursorType::kCross));
110
111 cursor_state()->UnlockCursor();
112 EXPECT_TRUE(cursor().IsType(ui::CursorType::kWait));
113 }
114
115 TEST_F(CursorStateTest, CursorOverrideVisibilityTest) {
116 // This test is meant to mimic the calls in ScreenshotController when it
117 // hides the cursor.
118 cursor_state()->SetCurrentWindowCursor(ui::CursorData(ui::CursorType::kWait));
119 EXPECT_TRUE(cursor().IsType(ui::CursorType::kWait));
120
121 cursor_state()->SetCursorVisible(false);
122 cursor_state()->LockCursor();
123 cursor_state()->SetGlobalOverrideCursor(base::nullopt);
124 cursor_state()->SetCursorVisible(true);
125 EXPECT_TRUE(cursor().IsType(ui::CursorType::kNone));
126
127 cursor_state()->UnlockCursor();
128 EXPECT_TRUE(cursor().IsType(ui::CursorType::kWait));
129 }
130
131 } // namespace test
132 } // namespace ws
133 } // namespace ui
OLDNEW
« no previous file with comments | « services/ui/ws/cursor_state.cc ('k') | services/ui/ws/display.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698