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

Unified Diff: components/mus/ws/event_dispatcher_unittest.cc

Issue 1818333002: Reland: mus: Enable system modal windows (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Cleaned up comments Created 4 years, 8 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 side-by-side diff with in-line comments
Download patch
Index: components/mus/ws/event_dispatcher_unittest.cc
diff --git a/components/mus/ws/event_dispatcher_unittest.cc b/components/mus/ws/event_dispatcher_unittest.cc
index ae4f4179c7ff492d9ec6c58e53d0c8e35d987d1a..b58e0d02ae02a0eac0cee88e8d53d8c5c1ca1c4c 100644
--- a/components/mus/ws/event_dispatcher_unittest.cc
+++ b/components/mus/ws/event_dispatcher_unittest.cc
@@ -197,7 +197,7 @@ class EventDispatcherTest : public testing::Test {
// Creates a window which is a child of |root_window_|.
scoped_ptr<ServerWindow> CreateChildWindow(const WindowId& id);
bool IsMouseButtonDown() const;
- bool IsWindowPointerTarget(ServerWindow* window) const;
+ bool IsWindowPointerTarget(const ServerWindow* window) const;
int NumberPointerTargetsForWindow(ServerWindow* window) const;
protected:
@@ -243,9 +243,10 @@ bool EventDispatcherTest::IsMouseButtonDown() const {
return EventDispatcherTestApi(event_dispatcher_.get()).is_mouse_button_down();
}
-bool EventDispatcherTest::IsWindowPointerTarget(ServerWindow* window) const {
+bool EventDispatcherTest::IsWindowPointerTarget(
+ const ServerWindow* window) const {
return EventDispatcherTestApi(event_dispatcher_.get())
- .IsObservingWindow(window);
+ .IsWindowPointerTarget(window);
}
int EventDispatcherTest::NumberPointerTargetsForWindow(
@@ -1300,6 +1301,62 @@ TEST_F(EventDispatcherTest, ModalWindowEventOnDescendantOfModalParent) {
EXPECT_EQ(gfx::Point(-25, 15), dispatched_event->location());
}
+// Tests that events on a system modal window target the modal window itself.
+TEST_F(EventDispatcherTest, ModalWindowEventOnSystemModal) {
+ scoped_ptr<ServerWindow> w1 = CreateChildWindow(WindowId(1, 3));
+
+ root_window()->SetBounds(gfx::Rect(0, 0, 100, 100));
+ w1->SetBounds(gfx::Rect(10, 10, 30, 30));
+ w1->SetModal();
+
+ // Send event that is over |w1|.
+ const ui::PointerEvent mouse_pressed(ui::MouseEvent(
+ ui::ET_MOUSE_PRESSED, gfx::Point(15, 15), gfx::Point(15, 15),
+ base::TimeDelta(), ui::EF_LEFT_MOUSE_BUTTON, ui::EF_LEFT_MOUSE_BUTTON));
+ event_dispatcher()->ProcessEvent(mouse_pressed);
+
+ scoped_ptr<DispatchedEventDetails> details =
+ test_event_dispatcher_delegate()->GetAndAdvanceDispatchedEventDetails();
+ ASSERT_TRUE(details);
+ EXPECT_EQ(w1.get(), details->window);
+ EXPECT_FALSE(details->in_nonclient_area);
+
+ ASSERT_TRUE(details->event);
+ ASSERT_TRUE(details->event->IsPointerEvent());
+
+ ui::PointerEvent* dispatched_event = details->event->AsPointerEvent();
+ EXPECT_EQ(gfx::Point(15, 15), dispatched_event->root_location());
+ EXPECT_EQ(gfx::Point(5, 5), dispatched_event->location());
+}
+
+// Tests that events outside of system modal window target the modal window.
+TEST_F(EventDispatcherTest, ModalWindowEventOutsideSystemModal) {
+ scoped_ptr<ServerWindow> w1 = CreateChildWindow(WindowId(1, 3));
+
+ root_window()->SetBounds(gfx::Rect(0, 0, 100, 100));
+ w1->SetBounds(gfx::Rect(10, 10, 30, 30));
+ w1->SetModal();
+ event_dispatcher()->SetSystemModalWindow(w1.get());
+
+ // Send event that is over |w1|.
+ const ui::PointerEvent mouse_pressed(ui::MouseEvent(
+ ui::ET_MOUSE_PRESSED, gfx::Point(45, 15), gfx::Point(45, 15),
+ base::TimeDelta(), ui::EF_LEFT_MOUSE_BUTTON, ui::EF_LEFT_MOUSE_BUTTON));
+ event_dispatcher()->ProcessEvent(mouse_pressed);
+
+ scoped_ptr<DispatchedEventDetails> details =
+ test_event_dispatcher_delegate()->GetAndAdvanceDispatchedEventDetails();
+ ASSERT_TRUE(details);
+ EXPECT_EQ(w1.get(), details->window);
+ EXPECT_TRUE(details->in_nonclient_area);
+
+ ASSERT_TRUE(details->event);
+ ASSERT_TRUE(details->event->IsPointerEvent());
+
+ ui::PointerEvent* dispatched_event = details->event->AsPointerEvent();
+ EXPECT_EQ(gfx::Point(45, 15), dispatched_event->root_location());
+ EXPECT_EQ(gfx::Point(35, 5), dispatched_event->location());
+}
// Tests that setting capture to a descendant of a modal parent fails.
TEST_F(EventDispatcherTest, ModalWindowSetCaptureDescendantOfModalParent) {
@@ -1338,6 +1395,22 @@ TEST_F(EventDispatcherTest, ModalWindowSetCaptureUnrelatedWindow) {
EXPECT_EQ(w3.get(), event_dispatcher()->capture_window());
}
+// Tests that setting capture fails when there is a system modal window.
+TEST_F(EventDispatcherTest, ModalWindowSystemSetCapture) {
+ scoped_ptr<ServerWindow> w1 = CreateChildWindow(WindowId(1, 3));
+ scoped_ptr<ServerWindow> w2 = CreateChildWindow(WindowId(1, 4));
+
+ root_window()->SetBounds(gfx::Rect(0, 0, 100, 100));
+ w1->SetBounds(gfx::Rect(10, 10, 30, 30));
+ w2->SetBounds(gfx::Rect(50, 10, 10, 10));
+
+ w2->SetModal();
+ event_dispatcher()->SetSystemModalWindow(w2.get());
+
+ EXPECT_FALSE(event_dispatcher()->SetCaptureWindow(w1.get(), false));
+ EXPECT_EQ(nullptr, event_dispatcher()->capture_window());
+}
+
} // namespace test
} // namespace ws
} // namespace mus

Powered by Google App Engine
This is Rietveld 408576698