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

Side by Side 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: Rebased after fixing the crash Created 4 years, 7 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 | « components/mus/ws/event_dispatcher.cc ('k') | components/mus/ws/modal_window_controller.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 "components/mus/ws/event_dispatcher.h" 5 #include "components/mus/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 203 matching lines...) Expand 10 before | Expand all | Expand 10 after
214 214
215 bool AreAnyPointersDown() const; 215 bool AreAnyPointersDown() const;
216 // Deletes everything created during SetUp() 216 // Deletes everything created during SetUp()
217 void ClearSetup(); 217 void ClearSetup();
218 std::unique_ptr<ServerWindow> CreateChildWindowWithParent( 218 std::unique_ptr<ServerWindow> CreateChildWindowWithParent(
219 const WindowId& id, 219 const WindowId& id,
220 ServerWindow* parent); 220 ServerWindow* parent);
221 // Creates a window which is a child of |root_window_|. 221 // Creates a window which is a child of |root_window_|.
222 std::unique_ptr<ServerWindow> CreateChildWindow(const WindowId& id); 222 std::unique_ptr<ServerWindow> CreateChildWindow(const WindowId& id);
223 bool IsMouseButtonDown() const; 223 bool IsMouseButtonDown() const;
224 bool IsWindowPointerTarget(ServerWindow* window) const; 224 bool IsWindowPointerTarget(const ServerWindow* window) const;
225 int NumberPointerTargetsForWindow(ServerWindow* window) const; 225 int NumberPointerTargetsForWindow(ServerWindow* window) const;
226 ServerWindow* GetActiveSystemModalWindow() const;
226 227
227 protected: 228 protected:
228 // testing::Test: 229 // testing::Test:
229 void SetUp() override; 230 void SetUp() override;
230 231
231 private: 232 private:
232 // TestEventDispatcherDelegate::Delegate: 233 // TestEventDispatcherDelegate::Delegate:
233 void ReleaseCapture() override { 234 void ReleaseCapture() override {
234 event_dispatcher_->SetCaptureWindow(nullptr, false); 235 event_dispatcher_->SetCaptureWindow(nullptr, false);
235 } 236 }
(...skipping 30 matching lines...) Expand all
266 267
267 std::unique_ptr<ServerWindow> EventDispatcherTest::CreateChildWindow( 268 std::unique_ptr<ServerWindow> EventDispatcherTest::CreateChildWindow(
268 const WindowId& id) { 269 const WindowId& id) {
269 return CreateChildWindowWithParent(id, root_window_.get()); 270 return CreateChildWindowWithParent(id, root_window_.get());
270 } 271 }
271 272
272 bool EventDispatcherTest::IsMouseButtonDown() const { 273 bool EventDispatcherTest::IsMouseButtonDown() const {
273 return EventDispatcherTestApi(event_dispatcher_.get()).is_mouse_button_down(); 274 return EventDispatcherTestApi(event_dispatcher_.get()).is_mouse_button_down();
274 } 275 }
275 276
276 bool EventDispatcherTest::IsWindowPointerTarget(ServerWindow* window) const { 277 bool EventDispatcherTest::IsWindowPointerTarget(
278 const ServerWindow* window) const {
277 return EventDispatcherTestApi(event_dispatcher_.get()) 279 return EventDispatcherTestApi(event_dispatcher_.get())
278 .IsObservingWindow(window); 280 .IsWindowPointerTarget(window);
279 } 281 }
280 282
281 int EventDispatcherTest::NumberPointerTargetsForWindow( 283 int EventDispatcherTest::NumberPointerTargetsForWindow(
282 ServerWindow* window) const { 284 ServerWindow* window) const {
283 return EventDispatcherTestApi(event_dispatcher_.get()) 285 return EventDispatcherTestApi(event_dispatcher_.get())
284 .NumberPointerTargetsForWindow(window); 286 .NumberPointerTargetsForWindow(window);
285 } 287 }
286 288
289 ServerWindow* EventDispatcherTest::GetActiveSystemModalWindow() const {
290 ModalWindowController* mwc =
291 EventDispatcherTestApi(event_dispatcher_.get()).modal_window_controller();
292 return ModalWindowControllerTestApi(mwc).GetActiveSystemModalWindow();
293 }
294
287 void EventDispatcherTest::SetUp() { 295 void EventDispatcherTest::SetUp() {
288 testing::Test::SetUp(); 296 testing::Test::SetUp();
289 297
290 window_delegate_.reset(new TestServerWindowDelegate()); 298 window_delegate_.reset(new TestServerWindowDelegate());
291 root_window_.reset(new ServerWindow(window_delegate_.get(), WindowId(1, 2))); 299 root_window_.reset(new ServerWindow(window_delegate_.get(), WindowId(1, 2)));
292 window_delegate_->set_root_window(root_window_.get()); 300 window_delegate_->set_root_window(root_window_.get());
293 root_window_->SetVisible(true); 301 root_window_->SetVisible(true);
294 302
295 test_event_dispatcher_delegate_.reset( 303 test_event_dispatcher_delegate_.reset(
296 new TestEventDispatcherDelegate(this, root_window_.get())); 304 new TestEventDispatcherDelegate(this, root_window_.get()));
(...skipping 1044 matching lines...) Expand 10 before | Expand all | Expand 10 after
1341 EXPECT_TRUE(details->in_nonclient_area); 1349 EXPECT_TRUE(details->in_nonclient_area);
1342 1350
1343 ASSERT_TRUE(details->event); 1351 ASSERT_TRUE(details->event);
1344 ASSERT_TRUE(details->event->IsPointerEvent()); 1352 ASSERT_TRUE(details->event->IsPointerEvent());
1345 1353
1346 ui::PointerEvent* dispatched_event = details->event->AsPointerEvent(); 1354 ui::PointerEvent* dispatched_event = details->event->AsPointerEvent();
1347 EXPECT_EQ(gfx::Point(25, 25), dispatched_event->root_location()); 1355 EXPECT_EQ(gfx::Point(25, 25), dispatched_event->root_location());
1348 EXPECT_EQ(gfx::Point(-25, 15), dispatched_event->location()); 1356 EXPECT_EQ(gfx::Point(-25, 15), dispatched_event->location());
1349 } 1357 }
1350 1358
1359 // Tests that events on a system modal window target the modal window itself.
1360 TEST_F(EventDispatcherTest, ModalWindowEventOnSystemModal) {
1361 std::unique_ptr<ServerWindow> w1 = CreateChildWindow(WindowId(1, 3));
1362
1363 root_window()->SetBounds(gfx::Rect(0, 0, 100, 100));
1364 w1->SetBounds(gfx::Rect(10, 10, 30, 30));
1365 w1->SetModal();
1366
1367 // Send event that is over |w1|.
1368 const ui::PointerEvent mouse_pressed(ui::MouseEvent(
1369 ui::ET_MOUSE_PRESSED, gfx::Point(15, 15), gfx::Point(15, 15),
1370 base::TimeDelta(), ui::EF_LEFT_MOUSE_BUTTON, ui::EF_LEFT_MOUSE_BUTTON));
1371 event_dispatcher()->ProcessEvent(mouse_pressed);
1372
1373 std::unique_ptr<DispatchedEventDetails> details =
1374 test_event_dispatcher_delegate()->GetAndAdvanceDispatchedEventDetails();
1375 ASSERT_TRUE(details);
1376 EXPECT_EQ(w1.get(), details->window);
1377 EXPECT_FALSE(details->in_nonclient_area);
1378
1379 ASSERT_TRUE(details->event);
1380 ASSERT_TRUE(details->event->IsPointerEvent());
1381
1382 ui::PointerEvent* dispatched_event = details->event->AsPointerEvent();
1383 EXPECT_EQ(gfx::Point(15, 15), dispatched_event->root_location());
1384 EXPECT_EQ(gfx::Point(5, 5), dispatched_event->location());
1385 }
1386
1387 // Tests that events outside of system modal window target the modal window.
1388 TEST_F(EventDispatcherTest, ModalWindowEventOutsideSystemModal) {
1389 std::unique_ptr<ServerWindow> w1 = CreateChildWindow(WindowId(1, 3));
1390
1391 root_window()->SetBounds(gfx::Rect(0, 0, 100, 100));
1392 w1->SetBounds(gfx::Rect(10, 10, 30, 30));
1393 w1->SetModal();
1394 event_dispatcher()->AddSystemModalWindow(w1.get());
1395
1396 // Send event that is over |w1|.
1397 const ui::PointerEvent mouse_pressed(ui::MouseEvent(
1398 ui::ET_MOUSE_PRESSED, gfx::Point(45, 15), gfx::Point(45, 15),
1399 base::TimeDelta(), ui::EF_LEFT_MOUSE_BUTTON, ui::EF_LEFT_MOUSE_BUTTON));
1400 event_dispatcher()->ProcessEvent(mouse_pressed);
1401
1402 std::unique_ptr<DispatchedEventDetails> details =
1403 test_event_dispatcher_delegate()->GetAndAdvanceDispatchedEventDetails();
1404 ASSERT_TRUE(details);
1405 EXPECT_EQ(w1.get(), details->window);
1406 EXPECT_TRUE(details->in_nonclient_area);
1407
1408 ASSERT_TRUE(details->event);
1409 ASSERT_TRUE(details->event->IsPointerEvent());
1410
1411 ui::PointerEvent* dispatched_event = details->event->AsPointerEvent();
1412 EXPECT_EQ(gfx::Point(45, 15), dispatched_event->root_location());
1413 EXPECT_EQ(gfx::Point(35, 5), dispatched_event->location());
1414 }
1351 1415
1352 // Tests that setting capture to a descendant of a modal parent fails. 1416 // Tests that setting capture to a descendant of a modal parent fails.
1353 TEST_F(EventDispatcherTest, ModalWindowSetCaptureDescendantOfModalParent) { 1417 TEST_F(EventDispatcherTest, ModalWindowSetCaptureDescendantOfModalParent) {
1354 std::unique_ptr<ServerWindow> w1 = CreateChildWindow(WindowId(1, 3)); 1418 std::unique_ptr<ServerWindow> w1 = CreateChildWindow(WindowId(1, 3));
1355 std::unique_ptr<ServerWindow> w11 = 1419 std::unique_ptr<ServerWindow> w11 =
1356 CreateChildWindowWithParent(WindowId(1, 4), w1.get()); 1420 CreateChildWindowWithParent(WindowId(1, 4), w1.get());
1357 std::unique_ptr<ServerWindow> w2 = CreateChildWindow(WindowId(1, 5)); 1421 std::unique_ptr<ServerWindow> w2 = CreateChildWindow(WindowId(1, 5));
1358 1422
1359 root_window()->SetBounds(gfx::Rect(0, 0, 100, 100)); 1423 root_window()->SetBounds(gfx::Rect(0, 0, 100, 100));
1360 w1->SetBounds(gfx::Rect(10, 10, 30, 30)); 1424 w1->SetBounds(gfx::Rect(10, 10, 30, 30));
1361 w11->SetBounds(gfx::Rect(10, 10, 10, 10)); 1425 w11->SetBounds(gfx::Rect(10, 10, 10, 10));
1362 w2->SetBounds(gfx::Rect(50, 10, 10, 10)); 1426 w2->SetBounds(gfx::Rect(50, 10, 10, 10));
1363 1427
1364 w1->AddTransientWindow(w2.get()); 1428 w1->AddTransientWindow(w2.get());
1365 w2->SetModal(); 1429 w2->SetModal();
1366 1430
1367 EXPECT_FALSE(event_dispatcher()->SetCaptureWindow(w11.get(), false)); 1431 EXPECT_FALSE(event_dispatcher()->SetCaptureWindow(w11.get(), false));
1368 EXPECT_EQ(nullptr, event_dispatcher()->capture_window()); 1432 EXPECT_EQ(nullptr, event_dispatcher()->capture_window());
1369 } 1433 }
1370 1434
1371 // Tests that setting capture to a window unrelated to a modal parent works. 1435 // Tests that setting capture to a window unrelated to a modal parent works.
1372 TEST_F(EventDispatcherTest, ModalWindowSetCaptureUnrelatedWindow) { 1436 TEST_F(EventDispatcherTest, ModalWindowSetCaptureUnrelatedWindow) {
1373 std::unique_ptr<ServerWindow> w1 = CreateChildWindow(WindowId(1, 3)); 1437 std::unique_ptr<ServerWindow> w1 = CreateChildWindow(WindowId(1, 3));
1374 std::unique_ptr<ServerWindow> w2 = CreateChildWindow(WindowId(1, 5)); 1438 std::unique_ptr<ServerWindow> w2 = CreateChildWindow(WindowId(1, 4));
1375 std::unique_ptr<ServerWindow> w3 = CreateChildWindow(WindowId(1, 6)); 1439 std::unique_ptr<ServerWindow> w3 = CreateChildWindow(WindowId(1, 5));
1376 1440
1377 root_window()->SetBounds(gfx::Rect(0, 0, 100, 100)); 1441 root_window()->SetBounds(gfx::Rect(0, 0, 100, 100));
1378 w1->SetBounds(gfx::Rect(10, 10, 30, 30)); 1442 w1->SetBounds(gfx::Rect(10, 10, 30, 30));
1379 w2->SetBounds(gfx::Rect(50, 10, 10, 10)); 1443 w2->SetBounds(gfx::Rect(50, 10, 10, 10));
1380 w3->SetBounds(gfx::Rect(70, 10, 10, 10)); 1444 w3->SetBounds(gfx::Rect(70, 10, 10, 10));
1381 1445
1382 w1->AddTransientWindow(w2.get()); 1446 w1->AddTransientWindow(w2.get());
1383 w2->SetModal(); 1447 w2->SetModal();
1384 1448
1385 EXPECT_TRUE(event_dispatcher()->SetCaptureWindow(w3.get(), false)); 1449 EXPECT_TRUE(event_dispatcher()->SetCaptureWindow(w3.get(), false));
1386 EXPECT_EQ(w3.get(), event_dispatcher()->capture_window()); 1450 EXPECT_EQ(w3.get(), event_dispatcher()->capture_window());
1387 } 1451 }
1388 1452
1453 // Tests that setting capture fails when there is a system modal window.
1454 TEST_F(EventDispatcherTest, ModalWindowSystemSetCapture) {
1455 std::unique_ptr<ServerWindow> w1 = CreateChildWindow(WindowId(1, 3));
1456 std::unique_ptr<ServerWindow> w2 = CreateChildWindow(WindowId(1, 4));
1457
1458 root_window()->SetBounds(gfx::Rect(0, 0, 100, 100));
1459 w1->SetBounds(gfx::Rect(10, 10, 30, 30));
1460 w2->SetBounds(gfx::Rect(50, 10, 10, 10));
1461
1462 event_dispatcher()->AddSystemModalWindow(w2.get());
1463
1464 EXPECT_FALSE(event_dispatcher()->SetCaptureWindow(w1.get(), false));
1465 EXPECT_EQ(nullptr, event_dispatcher()->capture_window());
1466 }
1467
1468 // Tests having multiple system modal windows.
1469 TEST_F(EventDispatcherTest, ModalWindowMultipleSystemModals) {
1470 std::unique_ptr<ServerWindow> w1 = CreateChildWindow(WindowId(1, 3));
1471 std::unique_ptr<ServerWindow> w2 = CreateChildWindow(WindowId(1, 4));
1472 std::unique_ptr<ServerWindow> w3 = CreateChildWindow(WindowId(1, 5));
1473
1474 w2->SetVisible(false);
1475
1476 // In the beginning, there should be no active system modal window.
1477 EXPECT_EQ(nullptr, GetActiveSystemModalWindow());
1478
1479 // Add a visible system modal window. It should become the active one.
1480 event_dispatcher()->AddSystemModalWindow(w1.get());
1481 EXPECT_EQ(w1.get(), GetActiveSystemModalWindow());
1482
1483 // Add an invisible system modal window. It should not change the active one.
1484 event_dispatcher()->AddSystemModalWindow(w2.get());
1485 EXPECT_EQ(w1.get(), GetActiveSystemModalWindow());
1486
1487 // Add another visible system modal window. It should become the active one.
1488 event_dispatcher()->AddSystemModalWindow(w3.get());
1489 EXPECT_EQ(w3.get(), GetActiveSystemModalWindow());
1490
1491 // Make an existing system modal window visible. It should become the active
1492 // one.
1493 w2->SetVisible(true);
1494 EXPECT_EQ(w2.get(), GetActiveSystemModalWindow());
1495
1496 // Remove the active system modal window. Next one should become active.
1497 w2.reset();
1498 EXPECT_EQ(w3.get(), GetActiveSystemModalWindow());
1499
1500 // Remove an inactive system modal window. It should not change the active
1501 // one.
1502 w1.reset();
1503 EXPECT_EQ(w3.get(), GetActiveSystemModalWindow());
1504
1505 // Remove the last remaining system modal window. There should be no active
1506 // one anymore.
1507 w3.reset();
1508 EXPECT_EQ(nullptr, GetActiveSystemModalWindow());
1509 }
1510
1389 } // namespace test 1511 } // namespace test
1390 } // namespace ws 1512 } // namespace ws
1391 } // namespace mus 1513 } // namespace mus
OLDNEW
« no previous file with comments | « components/mus/ws/event_dispatcher.cc ('k') | components/mus/ws/modal_window_controller.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698