| 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" |
| 11 #include "base/thread_task_runner_handle.h" | 11 #include "base/thread_task_runner_handle.h" |
| 12 #include "components/mus/public/cpp/event_matcher.h" | 12 #include "components/mus/public/cpp/event_matcher_util.h" |
| 13 #include "components/mus/surfaces/surfaces_state.h" | 13 #include "components/mus/surfaces/surfaces_state.h" |
| 14 #include "components/mus/ws/accelerator.h" | 14 #include "components/mus/ws/accelerator.h" |
| 15 #include "components/mus/ws/display_binding.h" | 15 #include "components/mus/ws/display_binding.h" |
| 16 #include "components/mus/ws/platform_display.h" | 16 #include "components/mus/ws/platform_display.h" |
| 17 #include "components/mus/ws/platform_display_init_params.h" | 17 #include "components/mus/ws/platform_display_init_params.h" |
| 18 #include "components/mus/ws/server_window_surface_manager_test_api.h" | 18 #include "components/mus/ws/server_window_surface_manager_test_api.h" |
| 19 #include "components/mus/ws/test_change_tracker.h" | 19 #include "components/mus/ws/test_change_tracker.h" |
| 20 #include "components/mus/ws/test_server_window_delegate.h" | 20 #include "components/mus/ws/test_server_window_delegate.h" |
| 21 #include "components/mus/ws/test_utils.h" | 21 #include "components/mus/ws/test_utils.h" |
| 22 #include "components/mus/ws/window_manager_access_policy.h" | 22 #include "components/mus/ws/window_manager_access_policy.h" |
| (...skipping 170 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 193 TEST_F(WindowManagerStateTest, NullAccelerator) { | 193 TEST_F(WindowManagerStateTest, NullAccelerator) { |
| 194 WindowManagerState* state = window_manager_state(); | 194 WindowManagerState* state = window_manager_state(); |
| 195 EXPECT_TRUE(state); | 195 EXPECT_TRUE(state); |
| 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 matched_observer=false", |
| 204 ChangesToDescription1(*tracker->changes())[0]); | 204 ChangesToDescription1(*tracker->changes())[0]); |
| 205 | 205 |
| 206 state->OnEventAck(target_tree, mojom::EventResult::UNHANDLED); | 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 matched_observer=false", |
| 221 ChangesToDescription1(*tracker->changes())[0]); | 221 ChangesToDescription1(*tracker->changes())[0]); |
| 222 | 222 |
| 223 window_manager_state()->OnEventAck(tree(), mojom::EventResult::UNHANDLED); | 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 matched_observer=false", |
| 239 ChangesToDescription1(*tracker->changes())[0]); | 239 ChangesToDescription1(*tracker->changes())[0]); |
| 240 | 240 |
| 241 window_manager_state()->OnEventAck(tree(), mojom::EventResult::HANDLED); | 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 matched_observer=false", |
| 256 ChangesToDescription1(*tracker->changes())[0]); | 256 ChangesToDescription1(*tracker->changes())[0]); |
| 257 | 257 |
| 258 accelerator.reset(); | 258 accelerator.reset(); |
| 259 window_manager_state()->OnEventAck(tree(), mojom::EventResult::UNHANDLED); | 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()); |
| 270 | 270 |
| 271 ServerWindow* target = window(); | 271 ServerWindow* target = window(); |
| 272 DispatchInputEventToWindow(target, true, key, accelerator.get()); | 272 DispatchInputEventToWindow(target, true, key, accelerator.get()); |
| 273 TestChangeTracker* tracker = wm_client()->tracker(); | 273 TestChangeTracker* tracker = wm_client()->tracker(); |
| 274 EXPECT_EQ(1u, tracker->changes()->size()); | 274 EXPECT_EQ(1u, tracker->changes()->size()); |
| 275 EXPECT_EQ("InputEvent window=1,1 event_action=1", | 275 EXPECT_EQ("InputEvent window=1,1 event_action=1 matched_observer=false", |
| 276 ChangesToDescription1(*tracker->changes())[0]); | 276 ChangesToDescription1(*tracker->changes())[0]); |
| 277 | 277 |
| 278 tracker->changes()->clear(); | 278 tracker->changes()->clear(); |
| 279 ui::KeyEvent key2(ui::ET_KEY_PRESSED, ui::VKEY_Y, ui::EF_CONTROL_DOWN); | 279 ui::KeyEvent key2(ui::ET_KEY_PRESSED, ui::VKEY_Y, ui::EF_CONTROL_DOWN); |
| 280 mojom::EventMatcherPtr matcher = mus::CreateKeyMatcher( | 280 mojom::EventMatcherPtr matcher = mus::CreateKeyMatcher( |
| 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, mojom::EventResult::UNHANDLED); | 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 matched_observer=false", |
| 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); |
| 302 scoped_ptr<Accelerator> accelerator = CreateAccelerator(); | 302 scoped_ptr<Accelerator> accelerator = CreateAccelerator(); |
| 303 | 303 |
| 304 ServerWindow* target = window(); | 304 ServerWindow* target = window(); |
| 305 DispatchInputEventToWindow(target, true, key, accelerator.get()); | 305 DispatchInputEventToWindow(target, true, key, accelerator.get()); |
| 306 TestChangeTracker* tracker = wm_client()->tracker(); | 306 TestChangeTracker* tracker = wm_client()->tracker(); |
| 307 EXPECT_EQ(1u, tracker->changes()->size()); | 307 EXPECT_EQ(1u, tracker->changes()->size()); |
| 308 EXPECT_EQ("InputEvent window=1,1 event_action=1", | 308 EXPECT_EQ("InputEvent window=1,1 event_action=1 matched_observer=false", |
| 309 ChangesToDescription1(*tracker->changes())[0]); | 309 ChangesToDescription1(*tracker->changes())[0]); |
| 310 | 310 |
| 311 window_manager_state()->OnWillDestroyTree(tree()); | 311 window_manager_state()->OnWillDestroyTree(tree()); |
| 312 EXPECT_FALSE(window_manager()->on_accelerator_called()); | 312 EXPECT_FALSE(window_manager()->on_accelerator_called()); |
| 313 } | 313 } |
| 314 | 314 |
| 315 // Tests that if a tree is destroyed before acking, that the accelerator is | 315 // Tests that if a tree is destroyed before acking, that the accelerator is |
| 316 // still sent if it is not the root tree. | 316 // still sent if it is not the root tree. |
| 317 TEST_F(WindowManagerStateTest, DeleteNonRootTree) { | 317 TEST_F(WindowManagerStateTest, DeleteNonRootTree) { |
| 318 TestWindowTreeClient* embed_connection = nullptr; | 318 TestWindowTreeClient* embed_connection = nullptr; |
| 319 WindowTree* target_tree = nullptr; | 319 WindowTree* target_tree = nullptr; |
| 320 ServerWindow* target = nullptr; | 320 ServerWindow* target = nullptr; |
| 321 CreateSecondaryTree(&embed_connection, &target_tree, &target); | 321 CreateSecondaryTree(&embed_connection, &target_tree, &target); |
| 322 TestWindowManager target_window_manager; | 322 TestWindowManager target_window_manager; |
| 323 WindowTreeTestApi(target_tree) | 323 WindowTreeTestApi(target_tree) |
| 324 .set_window_manager_internal(&target_window_manager); | 324 .set_window_manager_internal(&target_window_manager); |
| 325 | 325 |
| 326 ui::KeyEvent key(ui::ET_KEY_PRESSED, ui::VKEY_W, ui::EF_CONTROL_DOWN); | 326 ui::KeyEvent key(ui::ET_KEY_PRESSED, ui::VKEY_W, ui::EF_CONTROL_DOWN); |
| 327 scoped_ptr<Accelerator> accelerator = CreateAccelerator(); | 327 scoped_ptr<Accelerator> accelerator = CreateAccelerator(); |
| 328 DispatchInputEventToWindow(target, true, key, accelerator.get()); | 328 DispatchInputEventToWindow(target, true, key, accelerator.get()); |
| 329 TestChangeTracker* tracker = embed_connection->tracker(); | 329 TestChangeTracker* tracker = embed_connection->tracker(); |
| 330 EXPECT_EQ(1u, tracker->changes()->size()); | 330 EXPECT_EQ(1u, tracker->changes()->size()); |
| 331 EXPECT_EQ("InputEvent window=2,1 event_action=1", | 331 EXPECT_EQ("InputEvent window=2,1 event_action=1 matched_observer=false", |
| 332 ChangesToDescription1(*tracker->changes())[0]); | 332 ChangesToDescription1(*tracker->changes())[0]); |
| 333 EXPECT_TRUE(wm_client()->tracker()->changes()->empty()); | 333 EXPECT_TRUE(wm_client()->tracker()->changes()->empty()); |
| 334 | 334 |
| 335 window_manager_state()->OnWillDestroyTree(target_tree); | 335 window_manager_state()->OnWillDestroyTree(target_tree); |
| 336 EXPECT_FALSE(target_window_manager.on_accelerator_called()); | 336 EXPECT_FALSE(target_window_manager.on_accelerator_called()); |
| 337 EXPECT_TRUE(window_manager()->on_accelerator_called()); | 337 EXPECT_TRUE(window_manager()->on_accelerator_called()); |
| 338 } | 338 } |
| 339 | 339 |
| 340 // Tests that when an ack times out that the accelerator is notified. | 340 // Tests that when an ack times out that the accelerator is notified. |
| 341 TEST_F(WindowManagerStateTest, AckTimeout) { | 341 TEST_F(WindowManagerStateTest, AckTimeout) { |
| 342 ui::KeyEvent key(ui::ET_KEY_PRESSED, ui::VKEY_W, ui::EF_CONTROL_DOWN); | 342 ui::KeyEvent key(ui::ET_KEY_PRESSED, ui::VKEY_W, ui::EF_CONTROL_DOWN); |
| 343 scoped_ptr<Accelerator> accelerator = CreateAccelerator(); | 343 scoped_ptr<Accelerator> accelerator = CreateAccelerator(); |
| 344 DispatchInputEventToWindow(window(), true, key, accelerator.get()); | 344 DispatchInputEventToWindow(window(), true, key, accelerator.get()); |
| 345 TestChangeTracker* tracker = wm_client()->tracker(); | 345 TestChangeTracker* tracker = wm_client()->tracker(); |
| 346 EXPECT_EQ(1u, tracker->changes()->size()); | 346 EXPECT_EQ(1u, tracker->changes()->size()); |
| 347 EXPECT_EQ("InputEvent window=1,1 event_action=1", | 347 EXPECT_EQ("InputEvent window=1,1 event_action=1 matched_observer=false", |
| 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 |