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 "components/mus/ws/window_manager_state.h" | 5 #include "components/mus/ws/window_manager_state.h" |
6 | 6 |
7 #include "base/macros.h" | 7 #include "base/macros.h" |
8 #include "base/memory/ref_counted.h" | 8 #include "base/memory/ref_counted.h" |
9 #include "base/memory/scoped_ptr.h" | 9 #include "base/memory/scoped_ptr.h" |
10 #include "base/test/test_simple_task_runner.h" | 10 #include "base/test/test_simple_task_runner.h" |
(...skipping 185 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
196 | 196 |
197 ServerWindow* target = window(); | 197 ServerWindow* target = window(); |
198 ui::KeyEvent key(ui::ET_KEY_PRESSED, ui::VKEY_W, ui::EF_CONTROL_DOWN); | 198 ui::KeyEvent key(ui::ET_KEY_PRESSED, ui::VKEY_W, ui::EF_CONTROL_DOWN); |
199 DispatchInputEventToWindow(target, true, key, nullptr); | 199 DispatchInputEventToWindow(target, true, key, nullptr); |
200 WindowTree* target_tree = tree(); | 200 WindowTree* target_tree = tree(); |
201 TestChangeTracker* tracker = wm_client()->tracker(); | 201 TestChangeTracker* tracker = wm_client()->tracker(); |
202 EXPECT_EQ(1u, tracker->changes()->size()); | 202 EXPECT_EQ(1u, tracker->changes()->size()); |
203 EXPECT_EQ("InputEvent window=1,1 event_action=1", | 203 EXPECT_EQ("InputEvent window=1,1 event_action=1", |
204 ChangesToDescription1(*tracker->changes())[0]); | 204 ChangesToDescription1(*tracker->changes())[0]); |
205 | 205 |
206 state->OnEventAck(target_tree, false); | 206 state->OnEventAck(target_tree, mojom::EventResult::UNHANDLED); |
207 EXPECT_FALSE(window_manager()->on_accelerator_called()); | 207 EXPECT_FALSE(window_manager()->on_accelerator_called()); |
208 } | 208 } |
209 | 209 |
210 // Tests that when a post target accelerator is provided on an event, that it is | 210 // Tests that when a post target accelerator is provided on an event, that it is |
211 // called on ack. | 211 // called on ack. |
212 TEST_F(WindowManagerStateTest, PostTargetAccelerator) { | 212 TEST_F(WindowManagerStateTest, PostTargetAccelerator) { |
213 ui::KeyEvent key(ui::ET_KEY_PRESSED, ui::VKEY_W, ui::EF_CONTROL_DOWN); | 213 ui::KeyEvent key(ui::ET_KEY_PRESSED, ui::VKEY_W, ui::EF_CONTROL_DOWN); |
214 scoped_ptr<Accelerator> accelerator = CreateAccelerator(); | 214 scoped_ptr<Accelerator> accelerator = CreateAccelerator(); |
215 | 215 |
216 ServerWindow* target = window(); | 216 ServerWindow* target = window(); |
217 DispatchInputEventToWindow(target, true, key, accelerator.get()); | 217 DispatchInputEventToWindow(target, true, key, accelerator.get()); |
218 TestChangeTracker* tracker = wm_client()->tracker(); | 218 TestChangeTracker* tracker = wm_client()->tracker(); |
219 EXPECT_EQ(1u, tracker->changes()->size()); | 219 EXPECT_EQ(1u, tracker->changes()->size()); |
220 EXPECT_EQ("InputEvent window=1,1 event_action=1", | 220 EXPECT_EQ("InputEvent window=1,1 event_action=1", |
221 ChangesToDescription1(*tracker->changes())[0]); | 221 ChangesToDescription1(*tracker->changes())[0]); |
222 | 222 |
223 window_manager_state()->OnEventAck(tree(), false); | 223 window_manager_state()->OnEventAck(tree(), mojom::EventResult::UNHANDLED); |
224 EXPECT_TRUE(window_manager()->on_accelerator_called()); | 224 EXPECT_TRUE(window_manager()->on_accelerator_called()); |
225 EXPECT_EQ(accelerator->id(), window_manager()->on_accelerator_id()); | 225 EXPECT_EQ(accelerator->id(), window_manager()->on_accelerator_id()); |
226 } | 226 } |
227 | 227 |
228 // Tests that when a client handles an event that post target accelerators are | 228 // Tests that when a client handles an event that post target accelerators are |
229 // not called. | 229 // not called. |
230 TEST_F(WindowManagerStateTest, ClientHandlesEvent) { | 230 TEST_F(WindowManagerStateTest, ClientHandlesEvent) { |
231 ui::KeyEvent key(ui::ET_KEY_PRESSED, ui::VKEY_W, ui::EF_CONTROL_DOWN); | 231 ui::KeyEvent key(ui::ET_KEY_PRESSED, ui::VKEY_W, ui::EF_CONTROL_DOWN); |
232 scoped_ptr<Accelerator> accelerator = CreateAccelerator(); | 232 scoped_ptr<Accelerator> accelerator = CreateAccelerator(); |
233 | 233 |
234 ServerWindow* target = window(); | 234 ServerWindow* target = window(); |
235 DispatchInputEventToWindow(target, true, key, accelerator.get()); | 235 DispatchInputEventToWindow(target, true, key, accelerator.get()); |
236 TestChangeTracker* tracker = wm_client()->tracker(); | 236 TestChangeTracker* tracker = wm_client()->tracker(); |
237 EXPECT_EQ(1u, tracker->changes()->size()); | 237 EXPECT_EQ(1u, tracker->changes()->size()); |
238 EXPECT_EQ("InputEvent window=1,1 event_action=1", | 238 EXPECT_EQ("InputEvent window=1,1 event_action=1", |
239 ChangesToDescription1(*tracker->changes())[0]); | 239 ChangesToDescription1(*tracker->changes())[0]); |
240 | 240 |
241 window_manager_state()->OnEventAck(tree(), true); | 241 window_manager_state()->OnEventAck(tree(), mojom::EventResult::HANDLED); |
242 EXPECT_FALSE(window_manager()->on_accelerator_called()); | 242 EXPECT_FALSE(window_manager()->on_accelerator_called()); |
243 } | 243 } |
244 | 244 |
245 // Tests that when an accelerator is deleted before an ack, that it is not | 245 // Tests that when an accelerator is deleted before an ack, that it is not |
246 // called. | 246 // called. |
247 TEST_F(WindowManagerStateTest, AcceleratorDeleted) { | 247 TEST_F(WindowManagerStateTest, AcceleratorDeleted) { |
248 ui::KeyEvent key(ui::ET_KEY_PRESSED, ui::VKEY_W, ui::EF_CONTROL_DOWN); | 248 ui::KeyEvent key(ui::ET_KEY_PRESSED, ui::VKEY_W, ui::EF_CONTROL_DOWN); |
249 scoped_ptr<Accelerator> accelerator(CreateAccelerator()); | 249 scoped_ptr<Accelerator> accelerator(CreateAccelerator()); |
250 | 250 |
251 ServerWindow* target = window(); | 251 ServerWindow* target = window(); |
252 DispatchInputEventToWindow(target, true, key, accelerator.get()); | 252 DispatchInputEventToWindow(target, true, key, accelerator.get()); |
253 TestChangeTracker* tracker = wm_client()->tracker(); | 253 TestChangeTracker* tracker = wm_client()->tracker(); |
254 EXPECT_EQ(1u, tracker->changes()->size()); | 254 EXPECT_EQ(1u, tracker->changes()->size()); |
255 EXPECT_EQ("InputEvent window=1,1 event_action=1", | 255 EXPECT_EQ("InputEvent window=1,1 event_action=1", |
256 ChangesToDescription1(*tracker->changes())[0]); | 256 ChangesToDescription1(*tracker->changes())[0]); |
257 | 257 |
258 accelerator.reset(); | 258 accelerator.reset(); |
259 window_manager_state()->OnEventAck(tree(), false); | 259 window_manager_state()->OnEventAck(tree(), mojom::EventResult::UNHANDLED); |
260 EXPECT_FALSE(window_manager()->on_accelerator_called()); | 260 EXPECT_FALSE(window_manager()->on_accelerator_called()); |
261 } | 261 } |
262 | 262 |
263 // Tests that a events arriving before an ack don't notify the tree until the | 263 // Tests that a events arriving before an ack don't notify the tree until the |
264 // ack arrives, and that the correct accelerator is called. | 264 // ack arrives, and that the correct accelerator is called. |
265 TEST_F(WindowManagerStateTest, EnqueuedAccelerators) { | 265 TEST_F(WindowManagerStateTest, EnqueuedAccelerators) { |
266 WindowManagerState* state = window_manager_state(); | 266 WindowManagerState* state = window_manager_state(); |
267 | 267 |
268 ui::KeyEvent key(ui::ET_KEY_PRESSED, ui::VKEY_W, ui::EF_CONTROL_DOWN); | 268 ui::KeyEvent key(ui::ET_KEY_PRESSED, ui::VKEY_W, ui::EF_CONTROL_DOWN); |
269 scoped_ptr<Accelerator> accelerator(CreateAccelerator()); | 269 scoped_ptr<Accelerator> accelerator(CreateAccelerator()); |
(...skipping 11 matching lines...) Expand all Loading... |
281 mus::mojom::KeyboardCode::Y, mus::mojom::kEventFlagControlDown); | 281 mus::mojom::KeyboardCode::Y, mus::mojom::kEventFlagControlDown); |
282 matcher->accelerator_phase = mojom::AcceleratorPhase::POST_TARGET; | 282 matcher->accelerator_phase = mojom::AcceleratorPhase::POST_TARGET; |
283 uint32_t accelerator_id = 2; | 283 uint32_t accelerator_id = 2; |
284 scoped_ptr<Accelerator> accelerator2( | 284 scoped_ptr<Accelerator> accelerator2( |
285 new Accelerator(accelerator_id, *matcher)); | 285 new Accelerator(accelerator_id, *matcher)); |
286 DispatchInputEventToWindow(target, true, key2, accelerator2.get()); | 286 DispatchInputEventToWindow(target, true, key2, accelerator2.get()); |
287 EXPECT_TRUE(tracker->changes()->empty()); | 287 EXPECT_TRUE(tracker->changes()->empty()); |
288 | 288 |
289 WindowTree* target_tree = tree(); | 289 WindowTree* target_tree = tree(); |
290 WindowTreeTestApi(target_tree).ClearAck(); | 290 WindowTreeTestApi(target_tree).ClearAck(); |
291 state->OnEventAck(target_tree, false); | 291 state->OnEventAck(target_tree, mojom::EventResult::UNHANDLED); |
292 EXPECT_EQ(1u, tracker->changes()->size()); | 292 EXPECT_EQ(1u, tracker->changes()->size()); |
293 EXPECT_EQ("InputEvent window=1,1 event_action=1", | 293 EXPECT_EQ("InputEvent window=1,1 event_action=1", |
294 ChangesToDescription1(*tracker->changes())[0]); | 294 ChangesToDescription1(*tracker->changes())[0]); |
295 EXPECT_TRUE(window_manager()->on_accelerator_called()); | 295 EXPECT_TRUE(window_manager()->on_accelerator_called()); |
296 EXPECT_EQ(accelerator->id(), window_manager()->on_accelerator_id()); | 296 EXPECT_EQ(accelerator->id(), window_manager()->on_accelerator_id()); |
297 } | 297 } |
298 | 298 |
299 // Tests that the accelerator is not sent when the tree is dying. | 299 // Tests that the accelerator is not sent when the tree is dying. |
300 TEST_F(WindowManagerStateTest, DeleteTree) { | 300 TEST_F(WindowManagerStateTest, DeleteTree) { |
301 ui::KeyEvent key(ui::ET_KEY_PRESSED, ui::VKEY_W, ui::EF_CONTROL_DOWN); | 301 ui::KeyEvent key(ui::ET_KEY_PRESSED, ui::VKEY_W, ui::EF_CONTROL_DOWN); |
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
348 ChangesToDescription1(*tracker->changes())[0]); | 348 ChangesToDescription1(*tracker->changes())[0]); |
349 | 349 |
350 OnEventAckTimeout(); | 350 OnEventAckTimeout(); |
351 EXPECT_TRUE(window_manager()->on_accelerator_called()); | 351 EXPECT_TRUE(window_manager()->on_accelerator_called()); |
352 EXPECT_EQ(accelerator->id(), window_manager()->on_accelerator_id()); | 352 EXPECT_EQ(accelerator->id(), window_manager()->on_accelerator_id()); |
353 } | 353 } |
354 | 354 |
355 } // namespace test | 355 } // namespace test |
356 } // namespace ws | 356 } // namespace ws |
357 } // namespace mus | 357 } // namespace mus |
OLD | NEW |