| 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 "services/ui/ws/window_manager_state.h" | 5 #include "services/ui/ws/window_manager_state.h" |
| 6 | 6 |
| 7 #include <memory> | 7 #include <memory> |
| 8 | 8 |
| 9 #include "base/macros.h" | 9 #include "base/macros.h" |
| 10 #include "base/memory/ptr_util.h" | 10 #include "base/memory/ptr_util.h" |
| (...skipping 435 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 446 EXPECT_FALSE(target_window_manager.on_accelerator_called()); | 446 EXPECT_FALSE(target_window_manager.on_accelerator_called()); |
| 447 EXPECT_TRUE(window_manager()->on_accelerator_called()); | 447 EXPECT_TRUE(window_manager()->on_accelerator_called()); |
| 448 } | 448 } |
| 449 | 449 |
| 450 // Tests that if a tree is destroyed before acking an event, that mus won't | 450 // Tests that if a tree is destroyed before acking an event, that mus won't |
| 451 // then try to send any queued events. | 451 // then try to send any queued events. |
| 452 TEST_F(WindowManagerStateTest, DontSendQueuedEventsToADeadTree) { | 452 TEST_F(WindowManagerStateTest, DontSendQueuedEventsToADeadTree) { |
| 453 ServerWindow* target = window(); | 453 ServerWindow* target = window(); |
| 454 TestChangeTracker* tracker = window_tree_client()->tracker(); | 454 TestChangeTracker* tracker = window_tree_client()->tracker(); |
| 455 | 455 |
| 456 ui::MouseEvent press(ui::ET_MOUSE_PRESSED, gfx::Point(5, 5), gfx::Point(5, 5), | 456 ui::MouseEvent press( |
| 457 base::TimeTicks(), EF_LEFT_MOUSE_BUTTON, | 457 ui::ET_MOUSE_PRESSED, gfx::Point(5, 5), gfx::Point(5, 5), |
| 458 EF_LEFT_MOUSE_BUTTON); | 458 base::TimeTicks(), EF_LEFT_MOUSE_BUTTON, EF_LEFT_MOUSE_BUTTON, |
| 459 ui::PointerDetails(ui::EventPointerType::POINTER_TYPE_MOUSE)); |
| 459 DispatchInputEventToWindow(target, press, nullptr); | 460 DispatchInputEventToWindow(target, press, nullptr); |
| 460 ASSERT_EQ(1u, tracker->changes()->size()); | 461 ASSERT_EQ(1u, tracker->changes()->size()); |
| 461 EXPECT_EQ("InputEvent window=1,1 event_action=1", | 462 EXPECT_EQ("InputEvent window=1,1 event_action=1", |
| 462 ChangesToDescription1(*tracker->changes())[0]); | 463 ChangesToDescription1(*tracker->changes())[0]); |
| 463 tracker->changes()->clear(); | 464 tracker->changes()->clear(); |
| 464 // The above is not setting TreeAwaitingInputAck. | 465 // The above is not setting TreeAwaitingInputAck. |
| 465 | 466 |
| 466 // Queue the key release event; it should not be immediately dispatched | 467 // Queue the key release event; it should not be immediately dispatched |
| 467 // because there's no ACK for the last one. | 468 // because there's no ACK for the last one. |
| 468 ui::MouseEvent release(ui::ET_MOUSE_RELEASED, gfx::Point(5, 5), | 469 ui::MouseEvent release( |
| 469 gfx::Point(5, 5), base::TimeTicks(), | 470 ui::ET_MOUSE_RELEASED, gfx::Point(5, 5), gfx::Point(5, 5), |
| 470 EF_LEFT_MOUSE_BUTTON, EF_LEFT_MOUSE_BUTTON); | 471 base::TimeTicks(), EF_LEFT_MOUSE_BUTTON, EF_LEFT_MOUSE_BUTTON, |
| 472 ui::PointerDetails(ui::EventPointerType::POINTER_TYPE_MOUSE)); |
| 471 DispatchInputEventToWindow(target, release, nullptr); | 473 DispatchInputEventToWindow(target, release, nullptr); |
| 472 EXPECT_EQ(0u, tracker->changes()->size()); | 474 EXPECT_EQ(0u, tracker->changes()->size()); |
| 473 | 475 |
| 474 // Destroying a window tree with an event in queue shouldn't crash. | 476 // Destroying a window tree with an event in queue shouldn't crash. |
| 475 DestroyWindowTree(); | 477 DestroyWindowTree(); |
| 476 } | 478 } |
| 477 | 479 |
| 478 // Tests that when an ack times out that the accelerator is notified. | 480 // Tests that when an ack times out that the accelerator is notified. |
| 479 TEST_F(WindowManagerStateTest, AckTimeout) { | 481 TEST_F(WindowManagerStateTest, AckTimeout) { |
| 480 ui::KeyEvent key(ui::ET_KEY_PRESSED, ui::VKEY_W, ui::EF_CONTROL_DOWN); | 482 ui::KeyEvent key(ui::ET_KEY_PRESSED, ui::VKEY_W, ui::EF_CONTROL_DOWN); |
| (...skipping 26 matching lines...) Expand all Loading... |
| 507 { | 509 { |
| 508 // Do a normal embed. | 510 // Do a normal embed. |
| 509 const uint32_t embed_flags = 0; | 511 const uint32_t embed_flags = 0; |
| 510 WindowTree* embed_tree = nullptr; | 512 WindowTree* embed_tree = nullptr; |
| 511 TestWindowTreeClient* embed_client_proxy = nullptr; | 513 TestWindowTreeClient* embed_client_proxy = nullptr; |
| 512 EmbedAt(embedder_tree, embed_window_id, embed_flags, &embed_tree, | 514 EmbedAt(embedder_tree, embed_window_id, embed_flags, &embed_tree, |
| 513 &embed_client_proxy); | 515 &embed_client_proxy); |
| 514 ASSERT_TRUE(embed_client_proxy); | 516 ASSERT_TRUE(embed_client_proxy); |
| 515 | 517 |
| 516 // Send an event to the embed window. It should go to the embedded client. | 518 // Send an event to the embed window. It should go to the embedded client. |
| 517 ui::MouseEvent mouse(ui::ET_MOUSE_MOVED, gfx::Point(), gfx::Point(), | 519 ui::MouseEvent mouse( |
| 518 base::TimeTicks(), 0, 0); | 520 ui::ET_MOUSE_MOVED, gfx::Point(), gfx::Point(), base::TimeTicks(), 0, 0, |
| 521 ui::PointerDetails(ui::EventPointerType::POINTER_TYPE_MOUSE)); |
| 519 DispatchInputEventToWindow(embedder_window, mouse, nullptr); | 522 DispatchInputEventToWindow(embedder_window, mouse, nullptr); |
| 520 ASSERT_EQ(1u, embed_client_proxy->tracker()->changes()->size()); | 523 ASSERT_EQ(1u, embed_client_proxy->tracker()->changes()->size()); |
| 521 EXPECT_EQ(CHANGE_TYPE_INPUT_EVENT, | 524 EXPECT_EQ(CHANGE_TYPE_INPUT_EVENT, |
| 522 (*embed_client_proxy->tracker()->changes())[0].type); | 525 (*embed_client_proxy->tracker()->changes())[0].type); |
| 523 WindowTreeTestApi(embed_tree).AckLastEvent(mojom::EventResult::UNHANDLED); | 526 WindowTreeTestApi(embed_tree).AckLastEvent(mojom::EventResult::UNHANDLED); |
| 524 embed_client_proxy->tracker()->changes()->clear(); | 527 embed_client_proxy->tracker()->changes()->clear(); |
| 525 } | 528 } |
| 526 | 529 |
| 527 { | 530 { |
| 528 // Do an embed where the embedder wants to intercept events to the embedded | 531 // Do an embed where the embedder wants to intercept events to the embedded |
| 529 // tree. | 532 // tree. |
| 530 const uint32_t embed_flags = mojom::kEmbedFlagEmbedderInterceptsEvents; | 533 const uint32_t embed_flags = mojom::kEmbedFlagEmbedderInterceptsEvents; |
| 531 WindowTree* embed_tree = nullptr; | 534 WindowTree* embed_tree = nullptr; |
| 532 TestWindowTreeClient* embed_client_proxy = nullptr; | 535 TestWindowTreeClient* embed_client_proxy = nullptr; |
| 533 EmbedAt(embedder_tree, embed_window_id, embed_flags, &embed_tree, | 536 EmbedAt(embedder_tree, embed_window_id, embed_flags, &embed_tree, |
| 534 &embed_client_proxy); | 537 &embed_client_proxy); |
| 535 ASSERT_TRUE(embed_client_proxy); | 538 ASSERT_TRUE(embed_client_proxy); |
| 536 embedder_client->tracker()->changes()->clear(); | 539 embedder_client->tracker()->changes()->clear(); |
| 537 | 540 |
| 538 // Send an event to the embed window. But this time, it should reach the | 541 // Send an event to the embed window. But this time, it should reach the |
| 539 // embedder. | 542 // embedder. |
| 540 ui::MouseEvent mouse(ui::ET_MOUSE_MOVED, gfx::Point(), gfx::Point(), | 543 ui::MouseEvent mouse( |
| 541 base::TimeTicks(), 0, 0); | 544 ui::ET_MOUSE_MOVED, gfx::Point(), gfx::Point(), base::TimeTicks(), 0, 0, |
| 545 ui::PointerDetails(ui::EventPointerType::POINTER_TYPE_MOUSE)); |
| 542 DispatchInputEventToWindow(embedder_window, mouse, nullptr); | 546 DispatchInputEventToWindow(embedder_window, mouse, nullptr); |
| 543 ASSERT_EQ(0u, embed_client_proxy->tracker()->changes()->size()); | 547 ASSERT_EQ(0u, embed_client_proxy->tracker()->changes()->size()); |
| 544 ASSERT_EQ(1u, embedder_client->tracker()->changes()->size()); | 548 ASSERT_EQ(1u, embedder_client->tracker()->changes()->size()); |
| 545 EXPECT_EQ(CHANGE_TYPE_INPUT_EVENT, | 549 EXPECT_EQ(CHANGE_TYPE_INPUT_EVENT, |
| 546 (*embedder_client->tracker()->changes())[0].type); | 550 (*embedder_client->tracker()->changes())[0].type); |
| 547 WindowTreeTestApi(embedder_tree) | 551 WindowTreeTestApi(embedder_tree) |
| 548 .AckLastEvent(mojom::EventResult::UNHANDLED); | 552 .AckLastEvent(mojom::EventResult::UNHANDLED); |
| 549 embedder_client->tracker()->changes()->clear(); | 553 embedder_client->tracker()->changes()->clear(); |
| 550 | 554 |
| 551 // Embed another tree in the embedded tree. | 555 // Embed another tree in the embedded tree. |
| (...skipping 10 matching lines...) Expand all Loading... |
| 562 &nested_embed_client_proxy); | 566 &nested_embed_client_proxy); |
| 563 ASSERT_TRUE(nested_embed_client_proxy); | 567 ASSERT_TRUE(nested_embed_client_proxy); |
| 564 embed_client_proxy->tracker()->changes()->clear(); | 568 embed_client_proxy->tracker()->changes()->clear(); |
| 565 embedder_client->tracker()->changes()->clear(); | 569 embedder_client->tracker()->changes()->clear(); |
| 566 | 570 |
| 567 // Send an event to the nested embed window. The event should still reach | 571 // Send an event to the nested embed window. The event should still reach |
| 568 // the outermost embedder. | 572 // the outermost embedder. |
| 569 ServerWindow* nested_embed_window = | 573 ServerWindow* nested_embed_window = |
| 570 embed_tree->GetWindowByClientId(nested_embed_window_id); | 574 embed_tree->GetWindowByClientId(nested_embed_window_id); |
| 571 DCHECK(nested_embed_window->parent()); | 575 DCHECK(nested_embed_window->parent()); |
| 572 mouse = ui::MouseEvent(ui::ET_MOUSE_MOVED, gfx::Point(), gfx::Point(), | 576 mouse = ui::MouseEvent( |
| 573 base::TimeTicks(), 0, 0); | 577 ui::ET_MOUSE_MOVED, gfx::Point(), gfx::Point(), base::TimeTicks(), 0, 0, |
| 578 ui::PointerDetails(ui::EventPointerType::POINTER_TYPE_MOUSE)); |
| 574 DispatchInputEventToWindow(nested_embed_window, mouse, nullptr); | 579 DispatchInputEventToWindow(nested_embed_window, mouse, nullptr); |
| 575 ASSERT_EQ(0u, nested_embed_client_proxy->tracker()->changes()->size()); | 580 ASSERT_EQ(0u, nested_embed_client_proxy->tracker()->changes()->size()); |
| 576 ASSERT_EQ(0u, embed_client_proxy->tracker()->changes()->size()); | 581 ASSERT_EQ(0u, embed_client_proxy->tracker()->changes()->size()); |
| 577 | 582 |
| 578 ASSERT_EQ(1u, embedder_client->tracker()->changes()->size()); | 583 ASSERT_EQ(1u, embedder_client->tracker()->changes()->size()); |
| 579 EXPECT_EQ(CHANGE_TYPE_INPUT_EVENT, | 584 EXPECT_EQ(CHANGE_TYPE_INPUT_EVENT, |
| 580 (*embedder_client->tracker()->changes())[0].type); | 585 (*embedder_client->tracker()->changes())[0].type); |
| 581 WindowTreeTestApi(embedder_tree) | 586 WindowTreeTestApi(embedder_tree) |
| 582 .AckLastEvent(mojom::EventResult::UNHANDLED); | 587 .AckLastEvent(mojom::EventResult::UNHANDLED); |
| 583 } | 588 } |
| (...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 657 base::TimeTicks()); | 662 base::TimeTicks()); |
| 658 window_manager_state()->ProcessEvent(move, 0); | 663 window_manager_state()->ProcessEvent(move, 0); |
| 659 // The event isn't over a valid target, which should trigger resetting the | 664 // The event isn't over a valid target, which should trigger resetting the |
| 660 // cursor to POINTER. | 665 // cursor to POINTER. |
| 661 EXPECT_EQ(ui::mojom::CursorType::POINTER, display_test_api.last_cursor()); | 666 EXPECT_EQ(ui::mojom::CursorType::POINTER, display_test_api.last_cursor()); |
| 662 } | 667 } |
| 663 | 668 |
| 664 } // namespace test | 669 } // namespace test |
| 665 } // namespace ws | 670 } // namespace ws |
| 666 } // namespace ui | 671 } // namespace ui |
| OLD | NEW |