OLD | NEW |
---|---|
(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" | |
sky
2017/05/14 16:12:31
newline between 5/6.
| |
6 #include "services/ui/ws/display_manager.h" | |
7 #include "services/ui/ws/test_utils.h" | |
8 #include "services/ui/ws/window_server.h" | |
9 #include "services/ui/ws/window_server_delegate.h" | |
10 #include "testing/gtest/include/gtest/gtest.h" | |
11 #include "ui/base/cursor/cursor.h" | |
12 | |
13 namespace ui { | |
14 namespace ws { | |
15 namespace test { | |
16 namespace { | |
17 | |
18 const UserId kTestId1 = "2"; | |
19 | |
20 } // namespace | |
21 | |
22 class CursorStateTest : public testing::Test { | |
23 public: | |
24 CursorStateTest() {} | |
25 ~CursorStateTest() override {} | |
26 | |
27 WindowServer* window_server() { return ws_test_helper_.window_server(); } | |
28 DisplayManager* display_manager() { | |
29 return window_server()->display_manager(); | |
30 } | |
31 TestScreenManager& screen_manager() { return screen_manager_; } | |
32 CursorState* cursor_state() { return cursor_state_.get(); } | |
33 const ui::CursorData& cursor() { return ws_test_helper_.cursor(); } | |
34 | |
35 protected: | |
36 // testing::Test: | |
37 void SetUp() override { | |
38 screen_manager_.Init(window_server()->display_manager()); | |
39 window_server()->user_id_tracker()->AddUserId(kTestId1); | |
40 cursor_state_ = base::MakeUnique<CursorState>(display_manager()); | |
41 | |
42 AddWindowManager(window_server(), kTestId1); | |
43 screen_manager().AddDisplay(MakeDisplay(0, 0, 1024, 768, 1.0f)); | |
44 ASSERT_EQ(1u, display_manager()->displays().size()); | |
45 } | |
46 | |
47 private: | |
48 WindowServerTestHelper ws_test_helper_; | |
49 TestScreenManager screen_manager_; | |
50 | |
51 std::unique_ptr<CursorState> cursor_state_; | |
52 | |
53 DISALLOW_COPY_AND_ASSIGN(CursorStateTest); | |
54 }; | |
55 | |
56 TEST_F(CursorStateTest, CursorLockTest) { | |
57 cursor_state()->SetCurrentWindowCursor(ui::CursorData(ui::CursorType::kWait)); | |
58 EXPECT_TRUE(cursor().IsType(ui::CursorType::kWait)); | |
59 | |
60 cursor_state()->LockCursor(); | |
61 cursor_state()->SetCurrentWindowCursor(ui::CursorData(ui::CursorType::kCell)); | |
62 EXPECT_TRUE(cursor().IsType(ui::CursorType::kWait)); | |
63 | |
64 cursor_state()->UnlockCursor(); | |
65 EXPECT_TRUE(cursor().IsType(ui::CursorType::kCell)); | |
66 } | |
67 | |
68 TEST_F(CursorStateTest, CursorVisibilityTest) { | |
69 cursor_state()->SetCurrentWindowCursor(ui::CursorData(ui::CursorType::kWait)); | |
70 EXPECT_TRUE(cursor().IsType(ui::CursorType::kWait)); | |
71 | |
72 cursor_state()->SetCursorVisible(false); | |
73 EXPECT_TRUE(cursor().IsType(ui::CursorType::kNone)); | |
74 | |
75 cursor_state()->SetCursorVisible(true); | |
76 EXPECT_TRUE(cursor().IsType(ui::CursorType::kWait)); | |
77 | |
78 cursor_state()->SetCursorVisible(false); | |
79 cursor_state()->SetCurrentWindowCursor(ui::CursorData(ui::CursorType::kCell)); | |
80 EXPECT_TRUE(cursor().IsType(ui::CursorType::kNone)); | |
81 | |
82 cursor_state()->SetCursorVisible(true); | |
83 EXPECT_TRUE(cursor().IsType(ui::CursorType::kCell)); | |
84 } | |
85 | |
86 TEST_F(CursorStateTest, CursorOverrideTest) { | |
87 cursor_state()->SetCurrentWindowCursor(ui::CursorData(ui::CursorType::kWait)); | |
88 EXPECT_TRUE(cursor().IsType(ui::CursorType::kWait)); | |
89 | |
90 cursor_state()->SetGlobalOverrideCursor( | |
91 ui::CursorData(ui::CursorType::kCell)); | |
92 EXPECT_TRUE(cursor().IsType(ui::CursorType::kCell)); | |
93 | |
94 cursor_state()->SetGlobalOverrideCursor(base::nullopt); | |
95 EXPECT_TRUE(cursor().IsType(ui::CursorType::kWait)); | |
96 } | |
97 | |
98 TEST_F(CursorStateTest, CursorOverrideLockTest) { | |
99 // This test is meant to mimic the calls in ScreenshotController when it sets | |
100 // a cursor. | |
101 cursor_state()->SetCurrentWindowCursor(ui::CursorData(ui::CursorType::kWait)); | |
102 EXPECT_TRUE(cursor().IsType(ui::CursorType::kWait)); | |
103 | |
104 cursor_state()->SetGlobalOverrideCursor( | |
105 ui::CursorData(ui::CursorType::kCross)); | |
106 cursor_state()->LockCursor(); | |
107 cursor_state()->SetGlobalOverrideCursor(base::nullopt); | |
108 EXPECT_TRUE(cursor().IsType(ui::CursorType::kCross)); | |
109 | |
110 cursor_state()->UnlockCursor(); | |
111 EXPECT_TRUE(cursor().IsType(ui::CursorType::kWait)); | |
112 } | |
113 | |
114 TEST_F(CursorStateTest, CursorOverrideVisibilityTest) { | |
115 // This test is meant to mimic the calls in ScreenshotController when it | |
116 // hides the cursor. | |
117 cursor_state()->SetCurrentWindowCursor(ui::CursorData(ui::CursorType::kWait)); | |
118 EXPECT_TRUE(cursor().IsType(ui::CursorType::kWait)); | |
119 | |
120 cursor_state()->SetCursorVisible(false); | |
121 cursor_state()->LockCursor(); | |
122 cursor_state()->SetGlobalOverrideCursor(base::nullopt); | |
123 cursor_state()->SetCursorVisible(true); | |
124 EXPECT_TRUE(cursor().IsType(ui::CursorType::kNone)); | |
125 | |
126 cursor_state()->UnlockCursor(); | |
127 EXPECT_TRUE(cursor().IsType(ui::CursorType::kWait)); | |
128 } | |
129 | |
130 } // namespace test | |
131 } // namespace ws | |
132 } // namespace ui | |
OLD | NEW |