| OLD | NEW |
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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/public/cpp/window_tree_client.h" | 5 #include "services/ui/public/cpp/window_tree_client.h" |
| 6 | 6 |
| 7 #include <stdint.h> | 7 #include <stdint.h> |
| 8 | 8 |
| 9 #include "base/logging.h" | 9 #include "base/logging.h" |
| 10 #include "base/macros.h" | 10 #include "base/macros.h" |
| (...skipping 463 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 474 ASSERT_TRUE(root); | 474 ASSERT_TRUE(root); |
| 475 | 475 |
| 476 // Set up an event observer. | 476 // Set up an event observer. |
| 477 mojom::EventMatcherPtr matcher = mojom::EventMatcher::New(); | 477 mojom::EventMatcherPtr matcher = mojom::EventMatcher::New(); |
| 478 matcher->type_matcher = mojom::EventTypeMatcher::New(); | 478 matcher->type_matcher = mojom::EventTypeMatcher::New(); |
| 479 matcher->type_matcher->type = ui::mojom::EventType::POINTER_DOWN; | 479 matcher->type_matcher->type = ui::mojom::EventType::POINTER_DOWN; |
| 480 setup.client()->SetEventObserver(std::move(matcher)); | 480 setup.client()->SetEventObserver(std::move(matcher)); |
| 481 | 481 |
| 482 // Simulate the server sending an observed event. | 482 // Simulate the server sending an observed event. |
| 483 uint32_t event_observer_id = setup.GetEventObserverId(); | 483 uint32_t event_observer_id = setup.GetEventObserverId(); |
| 484 std::unique_ptr<ui::Event> ui_event( | 484 ui::PointerEvent ui_event( |
| 485 new ui::MouseEvent(ui::ET_MOUSE_PRESSED, gfx::Point(), gfx::Point(), | 485 ui::ET_POINTER_DOWN, gfx::Point(), gfx::Point(), ui::EF_CONTROL_DOWN, 0, |
| 486 ui::EventTimeForNow(), ui::EF_CONTROL_DOWN, 0)); | 486 ui::PointerDetails(ui::EventPointerType::POINTER_TYPE_MOUSE), |
| 487 setup.window_tree_client()->OnEventObserved(ui::Event::Clone(*ui_event.get()), | 487 ui::EventTimeForNow()); |
| 488 setup.window_tree_client()->OnEventObserved(ui::Event::Clone(ui_event), |
| 488 event_observer_id); | 489 event_observer_id); |
| 489 | 490 |
| 490 // Delegate sensed the event. | 491 // Delegate sensed the event and it has been converted to a mouse down. |
| 491 ui::Event* last_event = setup.window_tree_delegate()->last_event_observed(); | 492 ui::Event* last_event = setup.window_tree_delegate()->last_event_observed(); |
| 492 EXPECT_EQ(ui::ET_MOUSE_PRESSED, last_event->type()); | 493 EXPECT_EQ(ui::ET_MOUSE_PRESSED, last_event->type()); |
| 493 EXPECT_EQ(ui::EF_CONTROL_DOWN, last_event->flags()); | 494 EXPECT_EQ(ui::EF_CONTROL_DOWN, last_event->flags()); |
| 494 setup.window_tree_delegate()->Reset(); | 495 setup.window_tree_delegate()->Reset(); |
| 495 | 496 |
| 496 // Clear the event observer. | 497 // Clear the event observer. |
| 497 setup.client()->SetEventObserver(nullptr); | 498 setup.client()->SetEventObserver(nullptr); |
| 498 | 499 |
| 499 // Simulate another event from the server. | 500 // Simulate another event from the server. |
| 500 setup.window_tree_client()->OnEventObserved(ui::Event::Clone(*ui_event.get()), | 501 setup.window_tree_client()->OnEventObserved(ui::Event::Clone(ui_event), |
| 501 event_observer_id); | 502 event_observer_id); |
| 502 | 503 |
| 503 // No event was sensed. | 504 // No event was sensed. |
| 504 EXPECT_FALSE(setup.window_tree_delegate()->last_event_observed()); | 505 EXPECT_FALSE(setup.window_tree_delegate()->last_event_observed()); |
| 505 } | 506 } |
| 506 | 507 |
| 507 // Tests event observers triggered by events that hit this window tree. | 508 // Tests event observers triggered by events that hit this window tree. |
| 508 TEST_F(WindowTreeClientTest, OnWindowInputEventWithEventObserver) { | 509 TEST_F(WindowTreeClientTest, OnWindowInputEventWithEventObserver) { |
| 509 WindowTreeSetup setup; | 510 WindowTreeSetup setup; |
| 510 Window* root = setup.GetFirstRoot(); | 511 Window* root = setup.GetFirstRoot(); |
| 511 ASSERT_TRUE(root); | 512 ASSERT_TRUE(root); |
| 512 | 513 |
| 513 // Set up an event observer. | 514 // Set up an event observer. |
| 514 mojom::EventMatcherPtr matcher = mojom::EventMatcher::New(); | 515 mojom::EventMatcherPtr matcher = mojom::EventMatcher::New(); |
| 515 matcher->type_matcher = mojom::EventTypeMatcher::New(); | 516 matcher->type_matcher = mojom::EventTypeMatcher::New(); |
| 516 matcher->type_matcher->type = ui::mojom::EventType::POINTER_DOWN; | 517 matcher->type_matcher->type = ui::mojom::EventType::POINTER_DOWN; |
| 517 setup.client()->SetEventObserver(std::move(matcher)); | 518 setup.client()->SetEventObserver(std::move(matcher)); |
| 518 | 519 |
| 519 // Simulate the server dispatching an event that also matched the observer. | 520 // Simulate the server dispatching an event that also matched the observer. |
| 520 uint32_t event_observer_id = setup.GetEventObserverId(); | 521 uint32_t event_observer_id = setup.GetEventObserverId(); |
| 521 std::unique_ptr<ui::Event> ui_event( | 522 std::unique_ptr<ui::Event> ui_event(new ui::PointerEvent( |
| 522 new ui::MouseEvent(ui::ET_MOUSE_PRESSED, gfx::Point(), gfx::Point(), | 523 ui::ET_POINTER_DOWN, gfx::Point(), gfx::Point(), ui::EF_CONTROL_DOWN, 0, |
| 523 ui::EventTimeForNow(), ui::EF_CONTROL_DOWN, 0)); | 524 ui::PointerDetails(ui::EventPointerType::POINTER_TYPE_MOUSE), |
| 525 ui::EventTimeForNow())); |
| 524 setup.window_tree_client()->OnWindowInputEvent( | 526 setup.window_tree_client()->OnWindowInputEvent( |
| 525 1, server_id(root), std::move(ui_event), event_observer_id); | 527 1, server_id(root), std::move(ui_event), event_observer_id); |
| 526 | 528 |
| 527 // Delegate sensed the event. | 529 // Delegate sensed the event. |
| 528 ui::Event* last_event = setup.window_tree_delegate()->last_event_observed(); | 530 ui::Event* last_event = setup.window_tree_delegate()->last_event_observed(); |
| 529 EXPECT_EQ(ui::ET_MOUSE_PRESSED, last_event->type()); | 531 EXPECT_EQ(ui::ET_MOUSE_PRESSED, last_event->type()); |
| 530 EXPECT_EQ(ui::EF_CONTROL_DOWN, last_event->flags()); | 532 EXPECT_EQ(ui::EF_CONTROL_DOWN, last_event->flags()); |
| 531 } | 533 } |
| 532 | 534 |
| 533 // Tests that replacing an event observer with a new one results in only new | 535 // Tests that replacing an event observer with a new one results in only new |
| (...skipping 12 matching lines...) Expand all Loading... |
| 546 | 548 |
| 547 // Replace it with a second observer. | 549 // Replace it with a second observer. |
| 548 mojom::EventMatcherPtr matcher2 = mojom::EventMatcher::New(); | 550 mojom::EventMatcherPtr matcher2 = mojom::EventMatcher::New(); |
| 549 matcher2->type_matcher = mojom::EventTypeMatcher::New(); | 551 matcher2->type_matcher = mojom::EventTypeMatcher::New(); |
| 550 matcher2->type_matcher->type = ui::mojom::EventType::POINTER_UP; | 552 matcher2->type_matcher->type = ui::mojom::EventType::POINTER_UP; |
| 551 setup.client()->SetEventObserver(std::move(matcher2)); | 553 setup.client()->SetEventObserver(std::move(matcher2)); |
| 552 uint32_t event_observer_id2 = setup.GetEventObserverId(); | 554 uint32_t event_observer_id2 = setup.GetEventObserverId(); |
| 553 | 555 |
| 554 // Simulate the server sending an observed event that matched the old observer | 556 // Simulate the server sending an observed event that matched the old observer |
| 555 // (e.g. that was in-flight when the observer was replaced). | 557 // (e.g. that was in-flight when the observer was replaced). |
| 556 std::unique_ptr<ui::Event> pressed_event( | 558 std::unique_ptr<ui::Event> pressed_event(new ui::PointerEvent( |
| 557 new ui::MouseEvent(ui::ET_MOUSE_PRESSED, gfx::Point(), gfx::Point(), | 559 ui::ET_POINTER_DOWN, gfx::Point(), gfx::Point(), ui::EF_NONE, 0, |
| 558 ui::EventTimeForNow(), ui::EF_NONE, 0)); | 560 ui::PointerDetails(ui::EventPointerType::POINTER_TYPE_MOUSE), |
| 561 ui::EventTimeForNow())); |
| 559 setup.window_tree_client()->OnEventObserved(std::move(pressed_event), | 562 setup.window_tree_client()->OnEventObserved(std::move(pressed_event), |
| 560 event_observer_id1); | 563 event_observer_id1); |
| 561 | 564 |
| 562 // The event was not sensed, because it does not match the current observer. | 565 // The event was not sensed, because it does not match the current observer. |
| 563 EXPECT_FALSE(setup.window_tree_delegate()->last_event_observed()); | 566 EXPECT_FALSE(setup.window_tree_delegate()->last_event_observed()); |
| 564 | 567 |
| 565 // Simulate another event that matches the new observer. | 568 // Simulate another event that matches the new observer. |
| 566 std::unique_ptr<ui::Event> released_event( | 569 std::unique_ptr<ui::Event> released_event(new ui::PointerEvent( |
| 567 new ui::MouseEvent(ui::ET_MOUSE_RELEASED, gfx::Point(), gfx::Point(), | 570 ui::ET_POINTER_UP, gfx::Point(), gfx::Point(), ui::EF_CONTROL_DOWN, 0, |
| 568 ui::EventTimeForNow(), ui::EF_CONTROL_DOWN, 0)); | 571 ui::PointerDetails(ui::EventPointerType::POINTER_TYPE_MOUSE), |
| 572 ui::EventTimeForNow())); |
| 569 setup.window_tree_client()->OnEventObserved(std::move(released_event), | 573 setup.window_tree_client()->OnEventObserved(std::move(released_event), |
| 570 event_observer_id2); | 574 event_observer_id2); |
| 571 | 575 |
| 572 // The delegate sensed the event. | 576 // The delegate sensed the event. |
| 573 ui::Event* last_event = setup.window_tree_delegate()->last_event_observed(); | 577 ui::Event* last_event = setup.window_tree_delegate()->last_event_observed(); |
| 574 EXPECT_EQ(ui::ET_MOUSE_RELEASED, last_event->type()); | 578 EXPECT_EQ(ui::ET_MOUSE_RELEASED, last_event->type()); |
| 575 EXPECT_EQ(ui::EF_CONTROL_DOWN, last_event->flags()); | 579 EXPECT_EQ(ui::EF_CONTROL_DOWN, last_event->flags()); |
| 576 } | 580 } |
| 577 | 581 |
| 578 // Verifies focus is reverted if the server replied that the change failed. | 582 // Verifies focus is reverted if the server replied that the change failed. |
| (...skipping 463 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1042 | 1046 |
| 1043 // Create a new Window, and attempt to place capture on that. | 1047 // Create a new Window, and attempt to place capture on that. |
| 1044 Window* child = setup.client()->NewWindow(); | 1048 Window* child = setup.client()->NewWindow(); |
| 1045 child->SetVisible(true); | 1049 child->SetVisible(true); |
| 1046 root->AddChild(child); | 1050 root->AddChild(child); |
| 1047 child->SetCapture(); | 1051 child->SetCapture(); |
| 1048 EXPECT_TRUE(child->HasCapture()); | 1052 EXPECT_TRUE(child->HasCapture()); |
| 1049 } | 1053 } |
| 1050 | 1054 |
| 1051 } // namespace ui | 1055 } // namespace ui |
| OLD | NEW |