Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(206)

Side by Side Diff: services/ui/ws/event_dispatcher_unittest.cc

Issue 2667073002: mash: changes can_accept_events to an enum (Closed)
Patch Set: merge Created 3 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « services/ui/ws/display.cc ('k') | services/ui/ws/server_window.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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/ws/event_dispatcher.h" 5 #include "services/ui/ws/event_dispatcher.h"
6 6
7 #include <stddef.h> 7 #include <stddef.h>
8 #include <stdint.h> 8 #include <stdint.h>
9 9
10 #include <queue> 10 #include <queue>
(...skipping 268 matching lines...) Expand 10 before | Expand all | Expand 10 after
279 event_dispatcher_.reset(); 279 event_dispatcher_.reset();
280 } 280 }
281 281
282 std::unique_ptr<ServerWindow> EventDispatcherTest::CreateChildWindowWithParent( 282 std::unique_ptr<ServerWindow> EventDispatcherTest::CreateChildWindowWithParent(
283 const WindowId& id, 283 const WindowId& id,
284 ServerWindow* parent) { 284 ServerWindow* parent) {
285 std::unique_ptr<ServerWindow> child( 285 std::unique_ptr<ServerWindow> child(
286 new ServerWindow(window_delegate_.get(), id)); 286 new ServerWindow(window_delegate_.get(), id));
287 parent->Add(child.get()); 287 parent->Add(child.get());
288 child->SetVisible(true); 288 child->SetVisible(true);
289 EnableHitTest(child.get());
290 return child; 289 return child;
291 } 290 }
292 291
293 std::unique_ptr<ServerWindow> EventDispatcherTest::CreateChildWindow( 292 std::unique_ptr<ServerWindow> EventDispatcherTest::CreateChildWindow(
294 const WindowId& id) { 293 const WindowId& id) {
295 return CreateChildWindowWithParent(id, root_window_.get()); 294 return CreateChildWindowWithParent(id, root_window_.get());
296 } 295 }
297 296
298 bool EventDispatcherTest::IsMouseButtonDown() const { 297 bool EventDispatcherTest::IsMouseButtonDown() const {
299 return EventDispatcherTestApi(event_dispatcher_.get()).is_mouse_button_down(); 298 return EventDispatcherTestApi(event_dispatcher_.get()).is_mouse_button_down();
(...skipping 16 matching lines...) Expand all
316 EventDispatcherTestApi(event_dispatcher_.get()).modal_window_controller(); 315 EventDispatcherTestApi(event_dispatcher_.get()).modal_window_controller();
317 return ModalWindowControllerTestApi(mwc).GetActiveSystemModalWindow(); 316 return ModalWindowControllerTestApi(mwc).GetActiveSystemModalWindow();
318 } 317 }
319 318
320 void EventDispatcherTest::SetUp() { 319 void EventDispatcherTest::SetUp() {
321 testing::Test::SetUp(); 320 testing::Test::SetUp();
322 321
323 window_delegate_ = base::MakeUnique<TestServerWindowDelegate>(); 322 window_delegate_ = base::MakeUnique<TestServerWindowDelegate>();
324 root_window_ = 323 root_window_ =
325 base::MakeUnique<ServerWindow>(window_delegate_.get(), WindowId(1, 2)); 324 base::MakeUnique<ServerWindow>(window_delegate_.get(), WindowId(1, 2));
326 EnableHitTest(root_window_.get());
327 window_delegate_->set_root_window(root_window_.get()); 325 window_delegate_->set_root_window(root_window_.get());
328 root_window_->SetVisible(true); 326 root_window_->SetVisible(true);
329 327
330 test_event_dispatcher_delegate_ = 328 test_event_dispatcher_delegate_ =
331 base::MakeUnique<TestEventDispatcherDelegate>(this); 329 base::MakeUnique<TestEventDispatcherDelegate>(this);
332 event_dispatcher_ = 330 event_dispatcher_ =
333 base::MakeUnique<EventDispatcher>(test_event_dispatcher_delegate_.get()); 331 base::MakeUnique<EventDispatcher>(test_event_dispatcher_delegate_.get());
334 test_event_dispatcher_delegate_->set_root(root_window_.get()); 332 test_event_dispatcher_delegate_->set_root(root_window_.get());
335 } 333 }
336 334
(...skipping 1319 matching lines...) Expand 10 before | Expand all | Expand 10 after
1656 EXPECT_EQ(w3.get(), GetActiveSystemModalWindow()); 1654 EXPECT_EQ(w3.get(), GetActiveSystemModalWindow());
1657 1655
1658 // Remove the last remaining system modal window. There should be no active 1656 // Remove the last remaining system modal window. There should be no active
1659 // one anymore. 1657 // one anymore.
1660 w3.reset(); 1658 w3.reset();
1661 EXPECT_EQ(nullptr, GetActiveSystemModalWindow()); 1659 EXPECT_EQ(nullptr, GetActiveSystemModalWindow());
1662 } 1660 }
1663 1661
1664 TEST_F(EventDispatcherTest, CaptureNotResetOnParentChange) { 1662 TEST_F(EventDispatcherTest, CaptureNotResetOnParentChange) {
1665 std::unique_ptr<ServerWindow> w1 = CreateChildWindow(WindowId(1, 3)); 1663 std::unique_ptr<ServerWindow> w1 = CreateChildWindow(WindowId(1, 3));
1666 DisableHitTest(w1.get()); 1664 w1->set_event_targeting_policy(mojom::EventTargetingPolicy::DESCENDANTS_ONLY);
1667 std::unique_ptr<ServerWindow> w11 = 1665 std::unique_ptr<ServerWindow> w11 =
1668 CreateChildWindowWithParent(WindowId(1, 4), w1.get()); 1666 CreateChildWindowWithParent(WindowId(1, 4), w1.get());
1669 std::unique_ptr<ServerWindow> w2 = CreateChildWindow(WindowId(1, 5)); 1667 std::unique_ptr<ServerWindow> w2 = CreateChildWindow(WindowId(1, 5));
1670 DisableHitTest(w2.get()); 1668 w2->set_event_targeting_policy(mojom::EventTargetingPolicy::DESCENDANTS_ONLY);
1671 1669
1672 root_window()->SetBounds(gfx::Rect(0, 0, 100, 100)); 1670 root_window()->SetBounds(gfx::Rect(0, 0, 100, 100));
1673 w1->SetBounds(gfx::Rect(0, 0, 100, 100)); 1671 w1->SetBounds(gfx::Rect(0, 0, 100, 100));
1674 w11->SetBounds(gfx::Rect(10, 10, 10, 10)); 1672 w11->SetBounds(gfx::Rect(10, 10, 10, 10));
1675 w2->SetBounds(gfx::Rect(0, 0, 100, 100)); 1673 w2->SetBounds(gfx::Rect(0, 0, 100, 100));
1676 1674
1677 // Send event that is over |w11|. 1675 // Send event that is over |w11|.
1678 const ui::PointerEvent mouse_pressed(ui::MouseEvent( 1676 const ui::PointerEvent mouse_pressed(ui::MouseEvent(
1679 ui::ET_MOUSE_PRESSED, gfx::Point(15, 15), gfx::Point(15, 15), 1677 ui::ET_MOUSE_PRESSED, gfx::Point(15, 15), gfx::Point(15, 15),
1680 base::TimeTicks(), ui::EF_LEFT_MOUSE_BUTTON, ui::EF_LEFT_MOUSE_BUTTON)); 1678 base::TimeTicks(), ui::EF_LEFT_MOUSE_BUTTON, ui::EF_LEFT_MOUSE_BUTTON));
(...skipping 25 matching lines...) Expand all
1706 // Changing capture from client to non-client should notify the delegate. 1704 // Changing capture from client to non-client should notify the delegate.
1707 // The delegate can decide if it really wants to forward the event or not. 1705 // The delegate can decide if it really wants to forward the event or not.
1708 EXPECT_EQ(child.get(), 1706 EXPECT_EQ(child.get(),
1709 test_event_dispatcher_delegate()->lost_capture_window()); 1707 test_event_dispatcher_delegate()->lost_capture_window());
1710 EXPECT_EQ(child.get(), event_dispatcher()->capture_window()); 1708 EXPECT_EQ(child.get(), event_dispatcher()->capture_window());
1711 EXPECT_EQ(kClientAreaId, event_dispatcher()->capture_window_client_id()); 1709 EXPECT_EQ(kClientAreaId, event_dispatcher()->capture_window_client_id());
1712 } 1710 }
1713 1711
1714 TEST_F(EventDispatcherTest, MoveMouseFromNoTargetToValidTarget) { 1712 TEST_F(EventDispatcherTest, MoveMouseFromNoTargetToValidTarget) {
1715 ServerWindow* root = root_window(); 1713 ServerWindow* root = root_window();
1716 DisableHitTest(root); 1714 root->set_event_targeting_policy(
1715 mojom::EventTargetingPolicy::DESCENDANTS_ONLY);
1717 std::unique_ptr<ServerWindow> child = CreateChildWindow(WindowId(1, 3)); 1716 std::unique_ptr<ServerWindow> child = CreateChildWindow(WindowId(1, 3));
1718 1717
1719 root->SetBounds(gfx::Rect(0, 0, 100, 100)); 1718 root->SetBounds(gfx::Rect(0, 0, 100, 100));
1720 child->SetBounds(gfx::Rect(10, 10, 20, 20)); 1719 child->SetBounds(gfx::Rect(10, 10, 20, 20));
1721 1720
1722 MouseEventTest tests[] = { 1721 MouseEventTest tests[] = {
1723 // Send a mouse down over the root, but not the child. No event should 1722 // Send a mouse down over the root, but not the child. No event should
1724 // be generated. 1723 // be generated.
1725 {ui::MouseEvent(ui::ET_MOUSE_MOVED, gfx::Point(5, 5), gfx::Point(5, 5), 1724 {ui::MouseEvent(ui::ET_MOUSE_MOVED, gfx::Point(5, 5), gfx::Point(5, 5),
1726 base::TimeTicks(), 0, 0), 1725 base::TimeTicks(), 0, 0),
1727 nullptr, gfx::Point(), gfx::Point(), nullptr, gfx::Point(), 1726 nullptr, gfx::Point(), gfx::Point(), nullptr, gfx::Point(),
1728 gfx::Point()}, 1727 gfx::Point()},
1729 1728
1730 // Move into child. 1729 // Move into child.
1731 {ui::MouseEvent(ui::ET_MOUSE_MOVED, gfx::Point(12, 12), 1730 {ui::MouseEvent(ui::ET_MOUSE_MOVED, gfx::Point(12, 12),
1732 gfx::Point(12, 12), base::TimeTicks(), 0, 0), 1731 gfx::Point(12, 12), base::TimeTicks(), 0, 0),
1733 child.get(), gfx::Point(12, 12), gfx::Point(2, 2), nullptr, gfx::Point(), 1732 child.get(), gfx::Point(12, 12), gfx::Point(2, 2), nullptr, gfx::Point(),
1734 gfx::Point()}}; 1733 gfx::Point()}};
1735 RunMouseEventTests(event_dispatcher(), test_event_dispatcher_delegate(), 1734 RunMouseEventTests(event_dispatcher(), test_event_dispatcher_delegate(),
1736 tests, arraysize(tests)); 1735 tests, arraysize(tests));
1737 } 1736 }
1738 1737
1739 TEST_F(EventDispatcherTest, NoTargetToTargetWithMouseDown) { 1738 TEST_F(EventDispatcherTest, NoTargetToTargetWithMouseDown) {
1740 ServerWindow* root = root_window(); 1739 ServerWindow* root = root_window();
1741 DisableHitTest(root); 1740 root->set_event_targeting_policy(
1741 mojom::EventTargetingPolicy::DESCENDANTS_ONLY);
1742 std::unique_ptr<ServerWindow> child = CreateChildWindow(WindowId(1, 3)); 1742 std::unique_ptr<ServerWindow> child = CreateChildWindow(WindowId(1, 3));
1743 1743
1744 root->SetBounds(gfx::Rect(0, 0, 100, 100)); 1744 root->SetBounds(gfx::Rect(0, 0, 100, 100));
1745 child->SetBounds(gfx::Rect(10, 10, 20, 20)); 1745 child->SetBounds(gfx::Rect(10, 10, 20, 20));
1746 1746
1747 MouseEventTest tests[] = { 1747 MouseEventTest tests[] = {
1748 // Mouse over the root, but not the child. No event should be generated. 1748 // Mouse over the root, but not the child. No event should be generated.
1749 {ui::MouseEvent(ui::ET_MOUSE_MOVED, gfx::Point(5, 5), gfx::Point(5, 5), 1749 {ui::MouseEvent(ui::ET_MOUSE_MOVED, gfx::Point(5, 5), gfx::Point(5, 5),
1750 base::TimeTicks(), 0, 0), 1750 base::TimeTicks(), 0, 0),
1751 nullptr, gfx::Point(), gfx::Point(), nullptr, gfx::Point(), 1751 nullptr, gfx::Point(), gfx::Point(), nullptr, gfx::Point(),
(...skipping 11 matching lines...) Expand all
1763 gfx::Point(12, 12), base::TimeTicks(), 1763 gfx::Point(12, 12), base::TimeTicks(),
1764 ui::EF_LEFT_MOUSE_BUTTON, 0), 1764 ui::EF_LEFT_MOUSE_BUTTON, 0),
1765 nullptr, gfx::Point(), gfx::Point(), nullptr, gfx::Point(), 1765 nullptr, gfx::Point(), gfx::Point(), nullptr, gfx::Point(),
1766 gfx::Point()}}; 1766 gfx::Point()}};
1767 RunMouseEventTests(event_dispatcher(), test_event_dispatcher_delegate(), 1767 RunMouseEventTests(event_dispatcher(), test_event_dispatcher_delegate(),
1768 tests, arraysize(tests)); 1768 tests, arraysize(tests));
1769 } 1769 }
1770 1770
1771 TEST_F(EventDispatcherTest, DontSendExitToSameClientWhenCaptureChanges) { 1771 TEST_F(EventDispatcherTest, DontSendExitToSameClientWhenCaptureChanges) {
1772 ServerWindow* root = root_window(); 1772 ServerWindow* root = root_window();
1773 DisableHitTest(root); 1773 root->set_event_targeting_policy(
1774 mojom::EventTargetingPolicy::DESCENDANTS_ONLY);
1774 std::unique_ptr<ServerWindow> c1 = CreateChildWindow(WindowId(1, 3)); 1775 std::unique_ptr<ServerWindow> c1 = CreateChildWindow(WindowId(1, 3));
1775 std::unique_ptr<ServerWindow> c2 = CreateChildWindow(WindowId(1, 4)); 1776 std::unique_ptr<ServerWindow> c2 = CreateChildWindow(WindowId(1, 4));
1776 1777
1777 root->SetBounds(gfx::Rect(0, 0, 100, 100)); 1778 root->SetBounds(gfx::Rect(0, 0, 100, 100));
1778 c1->SetBounds(gfx::Rect(10, 10, 20, 20)); 1779 c1->SetBounds(gfx::Rect(10, 10, 20, 20));
1779 c2->SetBounds(gfx::Rect(15, 15, 20, 20)); 1780 c2->SetBounds(gfx::Rect(15, 15, 20, 20));
1780 1781
1781 MouseEventTest tests[] = { 1782 MouseEventTest tests[] = {
1782 // Mouse over |c2|. 1783 // Mouse over |c2|.
1783 {ui::MouseEvent(ui::ET_MOUSE_MOVED, gfx::Point(16, 16), 1784 {ui::MouseEvent(ui::ET_MOUSE_MOVED, gfx::Point(16, 16),
(...skipping 12 matching lines...) Expand all
1796 1797
1797 // Set capture on |c1|. No events should be sent as |c1| is in the same 1798 // Set capture on |c1|. No events should be sent as |c1| is in the same
1798 // client. 1799 // client.
1799 event_dispatcher()->SetCaptureWindow(c1.get(), kClientAreaId); 1800 event_dispatcher()->SetCaptureWindow(c1.get(), kClientAreaId);
1800 EXPECT_FALSE(test_event_dispatcher_delegate()->has_queued_events()); 1801 EXPECT_FALSE(test_event_dispatcher_delegate()->has_queued_events());
1801 } 1802 }
1802 1803
1803 } // namespace test 1804 } // namespace test
1804 } // namespace ws 1805 } // namespace ws
1805 } // namespace ui 1806 } // namespace ui
OLDNEW
« no previous file with comments | « services/ui/ws/display.cc ('k') | services/ui/ws/server_window.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698