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

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

Issue 1759523002: mus: Server-side implementation of modal windows (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: More cleanup Created 4 years, 9 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
« components/mus/ws/event_dispatcher.cc ('K') | « components/mus/ws/window_tree.cc ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: components/mus/ws/window_tree_unittest.cc
diff --git a/components/mus/ws/window_tree_unittest.cc b/components/mus/ws/window_tree_unittest.cc
index 17f59eb267b7de38db71e0fb7f501580d20cf0ca..43d63ed4c3895e9d622144d7d6a7be499b016c54 100644
--- a/components/mus/ws/window_tree_unittest.cc
+++ b/components/mus/ws/window_tree_unittest.cc
@@ -659,6 +659,187 @@ TEST_F(WindowTreeTest, ExplicitSetCapture) {
EXPECT_EQ(nullptr, display->GetCaptureWindow());
}
+// Tests that showing a modal window releases the capture if the capture is on a
+// descendant of the modal parent.
+TEST_F(WindowTreeTest, ShowModalWindowWithDescendantCapture) {
+ TestWindowTreeClient* embed_connection = nullptr;
+ WindowTree* tree = nullptr;
+ ServerWindow* w1 = nullptr;
+ EXPECT_NO_FATAL_FAILURE(SetupEventTargeting(&embed_connection, &tree, &w1));
+
+ w1->SetBounds(gfx::Rect(10, 10, 30, 30));
+ const ServerWindow* root_window = *tree->roots().begin();
+ ClientWindowId root_window_id = ClientWindowIdForWindow(tree, root_window);
+ ClientWindowId w1_id = ClientWindowIdForWindow(tree, w1);
+ Display* display = tree->GetDisplay(w1);
+ mojom::WindowTree* mojom_window_tree = tree;
+
+ // Create |w11| as a child of |w1| and make it visible.
+ ClientWindowId w11_id = BuildClientWindowId(tree, 11);
+ ASSERT_TRUE(tree->NewWindow(w11_id, ServerWindow::Properties()));
+ ServerWindow* w11 = tree->GetWindowByClientId(w11_id);
+ w11->SetBounds(gfx::Rect(10, 10, 10, 10));
+ ASSERT_TRUE(tree->AddWindow(w1_id, w11_id));
+ ASSERT_TRUE(tree->SetWindowVisibility(w11_id, true));
+
+ // Create |w2| as a child of |root_window| and modal to |w1| and leave it
+ // hidden.
+ ClientWindowId w2_id = BuildClientWindowId(tree, 2);
+ ASSERT_TRUE(tree->NewWindow(w2_id, ServerWindow::Properties()));
+ ServerWindow* w2 = tree->GetWindowByClientId(w2_id);
+ w2->SetBounds(gfx::Rect(50, 10, 10, 10));
+ ASSERT_TRUE(tree->AddWindow(root_window_id, w2_id));
+ ASSERT_TRUE(tree->AddTransientWindow(w1_id, w2_id));
+ ASSERT_TRUE(tree->SetAsModal(w2_id));
+
+ // Set capture to |w11|.
+ DispatchEventWithoutAck(CreatePointerDownEvent(25, 25));
+ uint32_t change_id = 42;
+ mojom_window_tree->SetCapture(change_id, w11_id.id);
+ EXPECT_EQ(w11, display->GetCaptureWindow());
+ AckPreviousEvent();
+
+ // Make |w2| visible. This should release capture as capture is set to a
+ // descendant of the modal parent.
+ ASSERT_TRUE(tree->SetWindowVisibility(w2_id, true));
+ EXPECT_EQ(nullptr, display->GetCaptureWindow());
+}
+
+// Tests that setting a visible window as modal releases the capture if the
+// capture is on a descendant of the modal parent.
+TEST_F(WindowTreeTest, VisibleWindowToModalWithDescendantCapture) {
+ TestWindowTreeClient* embed_connection = nullptr;
+ WindowTree* tree = nullptr;
+ ServerWindow* w1 = nullptr;
+ EXPECT_NO_FATAL_FAILURE(SetupEventTargeting(&embed_connection, &tree, &w1));
+
+ w1->SetBounds(gfx::Rect(10, 10, 30, 30));
+ const ServerWindow* root_window = *tree->roots().begin();
+ ClientWindowId root_window_id = ClientWindowIdForWindow(tree, root_window);
+ ClientWindowId w1_id = ClientWindowIdForWindow(tree, w1);
+ Display* display = tree->GetDisplay(w1);
+ mojom::WindowTree* mojom_window_tree = tree;
+
+ // Create |w11| as a child of |w1| and make it visible.
+ ClientWindowId w11_id = BuildClientWindowId(tree, 11);
+ ASSERT_TRUE(tree->NewWindow(w11_id, ServerWindow::Properties()));
+ ServerWindow* w11 = tree->GetWindowByClientId(w11_id);
+ w11->SetBounds(gfx::Rect(10, 10, 10, 10));
+ ASSERT_TRUE(tree->AddWindow(w1_id, w11_id));
+ ASSERT_TRUE(tree->SetWindowVisibility(w11_id, true));
+
+ // Create |w2| as a child of |root_window| and make it visible.
+ ClientWindowId w2_id = BuildClientWindowId(tree, 2);
+ ASSERT_TRUE(tree->NewWindow(w2_id, ServerWindow::Properties()));
+ ServerWindow* w2 = tree->GetWindowByClientId(w2_id);
+ w2->SetBounds(gfx::Rect(50, 10, 10, 10));
+ ASSERT_TRUE(tree->AddWindow(root_window_id, w2_id));
+ ASSERT_TRUE(tree->SetWindowVisibility(w2_id, true));
+
+ // Set capture to |w11|.
+ DispatchEventWithoutAck(CreatePointerDownEvent(25, 25));
+ uint32_t change_id = 42;
+ mojom_window_tree->SetCapture(change_id, w11_id.id);
+ EXPECT_EQ(w11, display->GetCaptureWindow());
+ AckPreviousEvent();
+
+ // Set |w2| modal to |w1|. This should release the capture as the capture is
+ // set to a descendant of the modal parent.
+ ASSERT_TRUE(tree->AddTransientWindow(w1_id, w2_id));
+ ASSERT_TRUE(tree->SetAsModal(w2_id));
+ EXPECT_EQ(nullptr, display->GetCaptureWindow());
+}
+
+// Tests that showing a modal window does not change capture if the capture is
+// not on a descendant of the modal parent.
+TEST_F(WindowTreeTest, ShowModalWindowWithNonDescendantCapture) {
+ TestWindowTreeClient* embed_connection = nullptr;
+ WindowTree* tree = nullptr;
+ ServerWindow* w1 = nullptr;
+ EXPECT_NO_FATAL_FAILURE(SetupEventTargeting(&embed_connection, &tree, &w1));
+
+ w1->SetBounds(gfx::Rect(10, 10, 30, 30));
+ const ServerWindow* root_window = *tree->roots().begin();
+ ClientWindowId root_window_id = ClientWindowIdForWindow(tree, root_window);
+ ClientWindowId w1_id = ClientWindowIdForWindow(tree, w1);
+ Display* display = tree->GetDisplay(w1);
+ mojom::WindowTree* mojom_window_tree = tree;
+
+ // Create |w2| as a child of |root_window| and modal to |w1| and leave it
+ // hidden..
+ ClientWindowId w2_id = BuildClientWindowId(tree, 2);
+ ASSERT_TRUE(tree->NewWindow(w2_id, ServerWindow::Properties()));
+ ServerWindow* w2 = tree->GetWindowByClientId(w2_id);
+ w2->SetBounds(gfx::Rect(50, 10, 10, 10));
+ ASSERT_TRUE(tree->AddWindow(root_window_id, w2_id));
+ ASSERT_TRUE(tree->AddTransientWindow(w1_id, w2_id));
+ ASSERT_TRUE(tree->SetAsModal(w2_id));
+
+ // Create |w3| as a child of |root_window| and make it visible.
+ ClientWindowId w3_id = BuildClientWindowId(tree, 3);
+ ASSERT_TRUE(tree->NewWindow(w3_id, ServerWindow::Properties()));
+ ServerWindow* w3 = tree->GetWindowByClientId(w3_id);
+ w3->SetBounds(gfx::Rect(70, 10, 10, 10));
+ ASSERT_TRUE(tree->AddWindow(root_window_id, w3_id));
+ ASSERT_TRUE(tree->SetWindowVisibility(w3_id, true));
+
+ // Set capture to |w3|.
+ DispatchEventWithoutAck(CreatePointerDownEvent(25, 25));
+ uint32_t change_id = 42;
+ mojom_window_tree->SetCapture(change_id, w3_id.id);
+ EXPECT_EQ(w3, display->GetCaptureWindow());
+ AckPreviousEvent();
+
+ // Make |w2| visible. This should not change the capture as the capture is not
+ // set to a descendant of the modal parent.
+ ASSERT_TRUE(tree->SetWindowVisibility(w2_id, true));
+ EXPECT_EQ(w3, display->GetCaptureWindow());
+}
+
+// Tests that setting a visible window as modal does not change the capture if
+// the capture is not set to a descendant of the modal parent.
+TEST_F(WindowTreeTest, VisibleWindowToModalWithNonDescendantCapture) {
+ TestWindowTreeClient* embed_connection = nullptr;
+ WindowTree* tree = nullptr;
+ ServerWindow* w1 = nullptr;
+ EXPECT_NO_FATAL_FAILURE(SetupEventTargeting(&embed_connection, &tree, &w1));
+
+ w1->SetBounds(gfx::Rect(10, 10, 30, 30));
+ const ServerWindow* root_window = *tree->roots().begin();
+ ClientWindowId root_window_id = ClientWindowIdForWindow(tree, root_window);
+ ClientWindowId w1_id = ClientWindowIdForWindow(tree, w1);
+ Display* display = tree->GetDisplay(w1);
+ mojom::WindowTree* mojom_window_tree = tree;
+
+ // Create |w2| and |w3| as children of |root_window| and make them visible.
+ ClientWindowId w2_id = BuildClientWindowId(tree, 2);
+ ASSERT_TRUE(tree->NewWindow(w2_id, ServerWindow::Properties()));
+ ServerWindow* w2 = tree->GetWindowByClientId(w2_id);
+ w2->SetBounds(gfx::Rect(50, 10, 10, 10));
+ ASSERT_TRUE(tree->AddWindow(root_window_id, w2_id));
+ ASSERT_TRUE(tree->SetWindowVisibility(w2_id, true));
+
+ ClientWindowId w3_id = BuildClientWindowId(tree, 3);
+ ASSERT_TRUE(tree->NewWindow(w3_id, ServerWindow::Properties()));
+ ServerWindow* w3 = tree->GetWindowByClientId(w3_id);
+ w3->SetBounds(gfx::Rect(70, 10, 10, 10));
+ ASSERT_TRUE(tree->AddWindow(root_window_id, w3_id));
+ ASSERT_TRUE(tree->SetWindowVisibility(w3_id, true));
+
+ // Set capture to |w3|.
+ DispatchEventWithoutAck(CreatePointerDownEvent(25, 25));
+ uint32_t change_id = 42;
+ mojom_window_tree->SetCapture(change_id, w3_id.id);
+ EXPECT_EQ(w3, display->GetCaptureWindow());
+ AckPreviousEvent();
+
+ // Set |w2| modal to |w1|. This should not release the capture as the capture
+ // is not set to a descendant of the modal parent.
+ ASSERT_TRUE(tree->AddTransientWindow(w1_id, w2_id));
+ ASSERT_TRUE(tree->SetAsModal(w2_id));
+ EXPECT_EQ(w3, display->GetCaptureWindow());
+}
+
} // namespace test
} // namespace ws
} // namespace mus
« components/mus/ws/event_dispatcher.cc ('K') | « components/mus/ws/window_tree.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698