OLD | NEW |
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/atomicops.h" | 9 #include "base/atomicops.h" |
10 #include "base/macros.h" | 10 #include "base/macros.h" |
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
84 mojom::FrameDecorationValuesPtr CreateDefaultFrameDecorationValues() { | 84 mojom::FrameDecorationValuesPtr CreateDefaultFrameDecorationValues() { |
85 return mojom::FrameDecorationValues::New(); | 85 return mojom::FrameDecorationValues::New(); |
86 } | 86 } |
87 | 87 |
88 } // namespace | 88 } // namespace |
89 | 89 |
90 // ----------------------------------------------------------------------------- | 90 // ----------------------------------------------------------------------------- |
91 | 91 |
92 class UserDisplayManagerTest : public testing::Test { | 92 class UserDisplayManagerTest : public testing::Test { |
93 public: | 93 public: |
94 UserDisplayManagerTest() | 94 UserDisplayManagerTest() {} |
95 : cursor_id_(0), platform_display_factory_(&cursor_id_) {} | |
96 ~UserDisplayManagerTest() override {} | 95 ~UserDisplayManagerTest() override {} |
97 | 96 |
98 protected: | 97 WindowServer* window_server() { return ws_test_helper_.window_server(); } |
99 // testing::Test: | 98 TestWindowServerDelegate* window_server_delegate() { |
100 void SetUp() override { | 99 return ws_test_helper_.window_server_delegate(); |
101 PlatformDisplay::set_factory_for_testing(&platform_display_factory_); | |
102 window_server_.reset(new WindowServer(&window_server_delegate_)); | |
103 window_server_delegate_.set_window_server(window_server_.get()); | |
104 } | 100 } |
105 | 101 |
106 protected: | |
107 int32_t cursor_id_; | |
108 TestPlatformDisplayFactory platform_display_factory_; | |
109 TestWindowServerDelegate window_server_delegate_; | |
110 std::unique_ptr<WindowServer> window_server_; | |
111 base::MessageLoop message_loop_; | |
112 | |
113 private: | 102 private: |
| 103 WindowServerTestHelper ws_test_helper_; |
114 DISALLOW_COPY_AND_ASSIGN(UserDisplayManagerTest); | 104 DISALLOW_COPY_AND_ASSIGN(UserDisplayManagerTest); |
115 }; | 105 }; |
116 | 106 |
117 TEST_F(UserDisplayManagerTest, OnlyNotifyWhenFrameDecorationsSet) { | 107 TEST_F(UserDisplayManagerTest, OnlyNotifyWhenFrameDecorationsSet) { |
118 window_server_delegate_.set_num_displays_to_create(1); | 108 window_server_delegate()->set_num_displays_to_create(1); |
119 | 109 |
120 const UserId kUserId1 = "2"; | 110 const UserId kUserId1 = "2"; |
121 TestDisplayManagerObserver display_manager_observer1; | 111 TestDisplayManagerObserver display_manager_observer1; |
122 DisplayManager* display_manager = window_server_->display_manager(); | 112 DisplayManager* display_manager = window_server()->display_manager(); |
123 WindowManagerWindowTreeFactorySetTestApi( | 113 WindowManagerWindowTreeFactorySetTestApi( |
124 window_server_->window_manager_window_tree_factory_set()) | 114 window_server()->window_manager_window_tree_factory_set()) |
125 .Add(kUserId1); | 115 .Add(kUserId1); |
126 UserDisplayManager* user_display_manager1 = | 116 UserDisplayManager* user_display_manager1 = |
127 display_manager->GetUserDisplayManager(kUserId1); | 117 display_manager->GetUserDisplayManager(kUserId1); |
128 ASSERT_TRUE(user_display_manager1); | 118 ASSERT_TRUE(user_display_manager1); |
129 UserDisplayManagerTestApi(user_display_manager1) | 119 UserDisplayManagerTestApi(user_display_manager1) |
130 .SetTestObserver(&display_manager_observer1); | 120 .SetTestObserver(&display_manager_observer1); |
131 // Observer should not have been notified yet. | 121 // Observer should not have been notified yet. |
132 EXPECT_EQ(std::string(), | 122 EXPECT_EQ(std::string(), |
133 display_manager_observer1.GetAndClearObserverCalls()); | 123 display_manager_observer1.GetAndClearObserverCalls()); |
134 | 124 |
135 // Set the frame decoration values, which should trigger sending immediately. | 125 // Set the frame decoration values, which should trigger sending immediately. |
136 ASSERT_EQ(1u, display_manager->displays().size()); | 126 ASSERT_EQ(1u, display_manager->displays().size()); |
137 window_server_->window_manager_window_tree_factory_set() | 127 window_server() |
| 128 ->window_manager_window_tree_factory_set() |
138 ->GetWindowManagerStateForUser(kUserId1) | 129 ->GetWindowManagerStateForUser(kUserId1) |
139 ->SetFrameDecorationValues(CreateDefaultFrameDecorationValues()); | 130 ->SetFrameDecorationValues(CreateDefaultFrameDecorationValues()); |
140 EXPECT_EQ("OnDisplays 1", | 131 EXPECT_EQ("OnDisplays 1", |
141 display_manager_observer1.GetAndClearObserverCalls()); | 132 display_manager_observer1.GetAndClearObserverCalls()); |
142 | 133 |
143 UserDisplayManagerTestApi(user_display_manager1).SetTestObserver(nullptr); | 134 UserDisplayManagerTestApi(user_display_manager1).SetTestObserver(nullptr); |
144 } | 135 } |
145 | 136 |
146 TEST_F(UserDisplayManagerTest, AddObserverAfterFrameDecorationsSet) { | 137 TEST_F(UserDisplayManagerTest, AddObserverAfterFrameDecorationsSet) { |
147 window_server_delegate_.set_num_displays_to_create(1); | 138 window_server_delegate()->set_num_displays_to_create(1); |
148 | 139 |
149 const UserId kUserId1 = "2"; | 140 const UserId kUserId1 = "2"; |
150 TestDisplayManagerObserver display_manager_observer1; | 141 TestDisplayManagerObserver display_manager_observer1; |
151 DisplayManager* display_manager = window_server_->display_manager(); | 142 DisplayManager* display_manager = window_server()->display_manager(); |
152 WindowManagerWindowTreeFactorySetTestApi( | 143 WindowManagerWindowTreeFactorySetTestApi( |
153 window_server_->window_manager_window_tree_factory_set()) | 144 window_server()->window_manager_window_tree_factory_set()) |
154 .Add(kUserId1); | 145 .Add(kUserId1); |
155 UserDisplayManager* user_display_manager1 = | 146 UserDisplayManager* user_display_manager1 = |
156 display_manager->GetUserDisplayManager(kUserId1); | 147 display_manager->GetUserDisplayManager(kUserId1); |
157 ASSERT_TRUE(user_display_manager1); | 148 ASSERT_TRUE(user_display_manager1); |
158 ASSERT_EQ(1u, display_manager->displays().size()); | 149 ASSERT_EQ(1u, display_manager->displays().size()); |
159 window_server_->window_manager_window_tree_factory_set() | 150 window_server() |
| 151 ->window_manager_window_tree_factory_set() |
160 ->GetWindowManagerStateForUser(kUserId1) | 152 ->GetWindowManagerStateForUser(kUserId1) |
161 ->SetFrameDecorationValues(CreateDefaultFrameDecorationValues()); | 153 ->SetFrameDecorationValues(CreateDefaultFrameDecorationValues()); |
162 | 154 |
163 UserDisplayManagerTestApi(user_display_manager1) | 155 UserDisplayManagerTestApi(user_display_manager1) |
164 .SetTestObserver(&display_manager_observer1); | 156 .SetTestObserver(&display_manager_observer1); |
165 EXPECT_EQ("OnDisplays 1", | 157 EXPECT_EQ("OnDisplays 1", |
166 display_manager_observer1.GetAndClearObserverCalls()); | 158 display_manager_observer1.GetAndClearObserverCalls()); |
167 | 159 |
168 UserDisplayManagerTestApi(user_display_manager1).SetTestObserver(nullptr); | 160 UserDisplayManagerTestApi(user_display_manager1).SetTestObserver(nullptr); |
169 } | 161 } |
170 | 162 |
171 TEST_F(UserDisplayManagerTest, AddRemoveDisplay) { | 163 TEST_F(UserDisplayManagerTest, AddRemoveDisplay) { |
172 window_server_delegate_.set_num_displays_to_create(1); | 164 window_server_delegate()->set_num_displays_to_create(1); |
173 | 165 |
174 const UserId kUserId1 = "2"; | 166 const UserId kUserId1 = "2"; |
175 TestDisplayManagerObserver display_manager_observer1; | 167 TestDisplayManagerObserver display_manager_observer1; |
176 DisplayManager* display_manager = window_server_->display_manager(); | 168 DisplayManager* display_manager = window_server()->display_manager(); |
177 WindowManagerWindowTreeFactorySetTestApi( | 169 WindowManagerWindowTreeFactorySetTestApi( |
178 window_server_->window_manager_window_tree_factory_set()) | 170 window_server()->window_manager_window_tree_factory_set()) |
179 .Add(kUserId1); | 171 .Add(kUserId1); |
180 UserDisplayManager* user_display_manager1 = | 172 UserDisplayManager* user_display_manager1 = |
181 display_manager->GetUserDisplayManager(kUserId1); | 173 display_manager->GetUserDisplayManager(kUserId1); |
182 ASSERT_TRUE(user_display_manager1); | 174 ASSERT_TRUE(user_display_manager1); |
183 ASSERT_EQ(1u, display_manager->displays().size()); | 175 ASSERT_EQ(1u, display_manager->displays().size()); |
184 window_server_->window_manager_window_tree_factory_set() | 176 window_server() |
| 177 ->window_manager_window_tree_factory_set() |
185 ->GetWindowManagerStateForUser(kUserId1) | 178 ->GetWindowManagerStateForUser(kUserId1) |
186 ->SetFrameDecorationValues(CreateDefaultFrameDecorationValues()); | 179 ->SetFrameDecorationValues(CreateDefaultFrameDecorationValues()); |
187 UserDisplayManagerTestApi(user_display_manager1) | 180 UserDisplayManagerTestApi(user_display_manager1) |
188 .SetTestObserver(&display_manager_observer1); | 181 .SetTestObserver(&display_manager_observer1); |
189 EXPECT_EQ("OnDisplays 1", | 182 EXPECT_EQ("OnDisplays 1", |
190 display_manager_observer1.GetAndClearObserverCalls()); | 183 display_manager_observer1.GetAndClearObserverCalls()); |
191 | 184 |
192 // Add another display. | 185 // Add another display. |
193 Display* display2 = | 186 Display* display2 = new Display(window_server(), PlatformDisplayInitParams()); |
194 new Display(window_server_.get(), PlatformDisplayInitParams()); | |
195 display2->Init(nullptr); | 187 display2->Init(nullptr); |
196 | 188 |
197 // Observer should be notified immediately as frame decorations were set. | 189 // Observer should be notified immediately as frame decorations were set. |
198 EXPECT_EQ("OnDisplaysChanged 2", | 190 EXPECT_EQ("OnDisplaysChanged 2", |
199 display_manager_observer1.GetAndClearObserverCalls()); | 191 display_manager_observer1.GetAndClearObserverCalls()); |
200 | 192 |
201 // Remove the display and verify observer is notified. | 193 // Remove the display and verify observer is notified. |
202 display_manager->DestroyDisplay(display2); | 194 display_manager->DestroyDisplay(display2); |
203 display2 = nullptr; | 195 display2 = nullptr; |
204 EXPECT_EQ("OnDisplayRemoved 2", | 196 EXPECT_EQ("OnDisplayRemoved 2", |
205 display_manager_observer1.GetAndClearObserverCalls()); | 197 display_manager_observer1.GetAndClearObserverCalls()); |
206 | 198 |
207 UserDisplayManagerTestApi(user_display_manager1).SetTestObserver(nullptr); | 199 UserDisplayManagerTestApi(user_display_manager1).SetTestObserver(nullptr); |
208 } | 200 } |
209 | 201 |
210 TEST_F(UserDisplayManagerTest, NegativeCoordinates) { | 202 TEST_F(UserDisplayManagerTest, NegativeCoordinates) { |
211 window_server_delegate_.set_num_displays_to_create(1); | 203 window_server_delegate()->set_num_displays_to_create(1); |
212 | 204 |
213 const UserId kUserId1 = "2"; | 205 const UserId kUserId1 = "2"; |
214 TestDisplayManagerObserver display_manager_observer1; | 206 TestDisplayManagerObserver display_manager_observer1; |
215 DisplayManager* display_manager = window_server_->display_manager(); | 207 DisplayManager* display_manager = window_server()->display_manager(); |
216 WindowManagerWindowTreeFactorySetTestApi( | 208 WindowManagerWindowTreeFactorySetTestApi( |
217 window_server_->window_manager_window_tree_factory_set()) | 209 window_server()->window_manager_window_tree_factory_set()) |
218 .Add(kUserId1); | 210 .Add(kUserId1); |
219 UserDisplayManager* user_display_manager1 = | 211 UserDisplayManager* user_display_manager1 = |
220 display_manager->GetUserDisplayManager(kUserId1); | 212 display_manager->GetUserDisplayManager(kUserId1); |
221 ASSERT_TRUE(user_display_manager1); | 213 ASSERT_TRUE(user_display_manager1); |
222 | 214 |
223 user_display_manager1->OnMouseCursorLocationChanged(gfx::Point(-10, -11)); | 215 user_display_manager1->OnMouseCursorLocationChanged(gfx::Point(-10, -11)); |
224 | 216 |
225 base::subtle::Atomic32* cursor_location_memory = nullptr; | 217 base::subtle::Atomic32* cursor_location_memory = nullptr; |
226 mojo::ScopedSharedBufferHandle handle = | 218 mojo::ScopedSharedBufferHandle handle = |
227 user_display_manager1->GetCursorLocationMemory(); | 219 user_display_manager1->GetCursorLocationMemory(); |
228 mojo::ScopedSharedBufferMapping cursor_location_mapping = | 220 mojo::ScopedSharedBufferMapping cursor_location_mapping = |
229 handle->Map(sizeof(base::subtle::Atomic32)); | 221 handle->Map(sizeof(base::subtle::Atomic32)); |
230 ASSERT_TRUE(cursor_location_mapping); | 222 ASSERT_TRUE(cursor_location_mapping); |
231 cursor_location_memory = | 223 cursor_location_memory = |
232 reinterpret_cast<base::subtle::Atomic32*>(cursor_location_mapping.get()); | 224 reinterpret_cast<base::subtle::Atomic32*>(cursor_location_mapping.get()); |
233 | 225 |
234 base::subtle::Atomic32 location = | 226 base::subtle::Atomic32 location = |
235 base::subtle::NoBarrier_Load(cursor_location_memory); | 227 base::subtle::NoBarrier_Load(cursor_location_memory); |
236 EXPECT_EQ(gfx::Point(static_cast<int16_t>(location >> 16), | 228 EXPECT_EQ(gfx::Point(static_cast<int16_t>(location >> 16), |
237 static_cast<int16_t>(location & 0xFFFF)), | 229 static_cast<int16_t>(location & 0xFFFF)), |
238 gfx::Point(-10, -11)); | 230 gfx::Point(-10, -11)); |
239 } | 231 } |
240 | 232 |
241 } // namespace test | 233 } // namespace test |
242 } // namespace ws | 234 } // namespace ws |
243 } // namespace ui | 235 } // namespace ui |
OLD | NEW |