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 eb1cc66fdc2ebd3f03ab1b0aee85ebb8bbe71e26..cdc0a58ad38cbeceaa02f523f7959c36d86bd250 100644 |
--- a/components/mus/ws/event_dispatcher_unittest.cc |
+++ b/components/mus/ws/event_dispatcher_unittest.cc |
@@ -221,8 +221,9 @@ class EventDispatcherTest : public testing::Test, |
// Creates a window which is a child of |root_window_|. |
std::unique_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; |
+ ServerWindow* GetActiveSystemModalWindow() const; |
protected: |
// testing::Test: |
@@ -273,9 +274,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( |
@@ -284,6 +286,12 @@ int EventDispatcherTest::NumberPointerTargetsForWindow( |
.NumberPointerTargetsForWindow(window); |
} |
+ServerWindow* EventDispatcherTest::GetActiveSystemModalWindow() const { |
+ ModalWindowController* mwc = |
+ EventDispatcherTestApi(event_dispatcher_.get()).modal_window_controller(); |
+ return ModalWindowControllerTestApi(mwc).GetActiveSystemModalWindow(); |
+} |
+ |
void EventDispatcherTest::SetUp() { |
testing::Test::SetUp(); |
@@ -1348,6 +1356,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) { |
+ std::unique_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); |
+ |
+ std::unique_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) { |
+ std::unique_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()->AddSystemModalWindow(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); |
+ |
+ std::unique_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) { |
@@ -1371,8 +1435,8 @@ TEST_F(EventDispatcherTest, ModalWindowSetCaptureDescendantOfModalParent) { |
// Tests that setting capture to a window unrelated to a modal parent works. |
TEST_F(EventDispatcherTest, ModalWindowSetCaptureUnrelatedWindow) { |
std::unique_ptr<ServerWindow> w1 = CreateChildWindow(WindowId(1, 3)); |
- std::unique_ptr<ServerWindow> w2 = CreateChildWindow(WindowId(1, 5)); |
- std::unique_ptr<ServerWindow> w3 = CreateChildWindow(WindowId(1, 6)); |
+ std::unique_ptr<ServerWindow> w2 = CreateChildWindow(WindowId(1, 4)); |
+ std::unique_ptr<ServerWindow> w3 = CreateChildWindow(WindowId(1, 5)); |
root_window()->SetBounds(gfx::Rect(0, 0, 100, 100)); |
w1->SetBounds(gfx::Rect(10, 10, 30, 30)); |
@@ -1386,6 +1450,64 @@ 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) { |
+ std::unique_ptr<ServerWindow> w1 = CreateChildWindow(WindowId(1, 3)); |
+ std::unique_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)); |
+ |
+ event_dispatcher()->AddSystemModalWindow(w2.get()); |
+ |
+ EXPECT_FALSE(event_dispatcher()->SetCaptureWindow(w1.get(), false)); |
+ EXPECT_EQ(nullptr, event_dispatcher()->capture_window()); |
+} |
+ |
+// Tests having multiple system modal windows. |
+TEST_F(EventDispatcherTest, ModalWindowMultipleSystemModals) { |
+ std::unique_ptr<ServerWindow> w1 = CreateChildWindow(WindowId(1, 3)); |
+ std::unique_ptr<ServerWindow> w2 = CreateChildWindow(WindowId(1, 4)); |
+ std::unique_ptr<ServerWindow> w3 = CreateChildWindow(WindowId(1, 5)); |
+ |
+ w2->SetVisible(false); |
+ |
+ // In the beginning, there should be no active system modal window. |
+ EXPECT_EQ(nullptr, GetActiveSystemModalWindow()); |
+ |
+ // Add a visible system modal window. It should become the active one. |
+ event_dispatcher()->AddSystemModalWindow(w1.get()); |
+ EXPECT_EQ(w1.get(), GetActiveSystemModalWindow()); |
+ |
+ // Add an invisible system modal window. It should not change the active one. |
+ event_dispatcher()->AddSystemModalWindow(w2.get()); |
+ EXPECT_EQ(w1.get(), GetActiveSystemModalWindow()); |
+ |
+ // Add another visible system modal window. It should become the active one. |
+ event_dispatcher()->AddSystemModalWindow(w3.get()); |
+ EXPECT_EQ(w3.get(), GetActiveSystemModalWindow()); |
+ |
+ // Make an existing system modal window visible. It should become the active |
+ // one. |
+ w2->SetVisible(true); |
+ EXPECT_EQ(w2.get(), GetActiveSystemModalWindow()); |
+ |
+ // Remove the active system modal window. Next one should become active. |
+ w2.reset(); |
+ EXPECT_EQ(w3.get(), GetActiveSystemModalWindow()); |
+ |
+ // Remove an inactive system modal window. It should not change the active |
+ // one. |
+ w1.reset(); |
+ EXPECT_EQ(w3.get(), GetActiveSystemModalWindow()); |
+ |
+ // Remove the last remaining system modal window. There should be no active |
+ // one anymore. |
+ w3.reset(); |
+ EXPECT_EQ(nullptr, GetActiveSystemModalWindow()); |
+} |
+ |
} // namespace test |
} // namespace ws |
} // namespace mus |