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

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: Addressed review comments 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
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 189 matching lines...) Expand 10 before | Expand all | Expand 10 after
200 200
201 bool AreAnyPointersDown() const; 201 bool AreAnyPointersDown() const;
202 // Deletes everything created during SetUp() 202 // Deletes everything created during SetUp()
203 void ClearSetup(); 203 void ClearSetup();
204 std::unique_ptr<ServerWindow> CreateChildWindowWithParent( 204 std::unique_ptr<ServerWindow> CreateChildWindowWithParent(
205 const WindowId& id, 205 const WindowId& id,
206 ServerWindow* parent); 206 ServerWindow* parent);
207 // Creates a window which is a child of |root_window_|. 207 // Creates a window which is a child of |root_window_|.
208 std::unique_ptr<ServerWindow> CreateChildWindow(const WindowId& id); 208 std::unique_ptr<ServerWindow> CreateChildWindow(const WindowId& id);
209 bool IsMouseButtonDown() const; 209 bool IsMouseButtonDown() const;
210 bool IsWindowPointerTarget(ServerWindow* window) const; 210 bool IsWindowPointerTarget(const ServerWindow* window) const;
211 int NumberPointerTargetsForWindow(ServerWindow* window) const; 211 int NumberPointerTargetsForWindow(ServerWindow* window) const;
212 ServerWindow* GetActiveSystemModalWindow() const;
212 213
213 protected: 214 protected:
214 // testing::Test: 215 // testing::Test:
215 void SetUp() override; 216 void SetUp() override;
216 217
217 private: 218 private:
218 std::unique_ptr<TestServerWindowDelegate> window_delegate_; 219 std::unique_ptr<TestServerWindowDelegate> window_delegate_;
219 std::unique_ptr<ServerWindow> root_window_; 220 std::unique_ptr<ServerWindow> root_window_;
220 std::unique_ptr<TestEventDispatcherDelegate> test_event_dispatcher_delegate_; 221 std::unique_ptr<TestEventDispatcherDelegate> test_event_dispatcher_delegate_;
221 std::unique_ptr<EventDispatcher> event_dispatcher_; 222 std::unique_ptr<EventDispatcher> event_dispatcher_;
(...skipping 25 matching lines...) Expand all
247 248
248 std::unique_ptr<ServerWindow> EventDispatcherTest::CreateChildWindow( 249 std::unique_ptr<ServerWindow> EventDispatcherTest::CreateChildWindow(
249 const WindowId& id) { 250 const WindowId& id) {
250 return CreateChildWindowWithParent(id, root_window_.get()); 251 return CreateChildWindowWithParent(id, root_window_.get());
251 } 252 }
252 253
253 bool EventDispatcherTest::IsMouseButtonDown() const { 254 bool EventDispatcherTest::IsMouseButtonDown() const {
254 return EventDispatcherTestApi(event_dispatcher_.get()).is_mouse_button_down(); 255 return EventDispatcherTestApi(event_dispatcher_.get()).is_mouse_button_down();
255 } 256 }
256 257
257 bool EventDispatcherTest::IsWindowPointerTarget(ServerWindow* window) const { 258 bool EventDispatcherTest::IsWindowPointerTarget(
259 const ServerWindow* window) const {
258 return EventDispatcherTestApi(event_dispatcher_.get()) 260 return EventDispatcherTestApi(event_dispatcher_.get())
259 .IsObservingWindow(window); 261 .IsWindowPointerTarget(window);
260 } 262 }
261 263
262 int EventDispatcherTest::NumberPointerTargetsForWindow( 264 int EventDispatcherTest::NumberPointerTargetsForWindow(
263 ServerWindow* window) const { 265 ServerWindow* window) const {
264 return EventDispatcherTestApi(event_dispatcher_.get()) 266 return EventDispatcherTestApi(event_dispatcher_.get())
265 .NumberPointerTargetsForWindow(window); 267 .NumberPointerTargetsForWindow(window);
266 } 268 }
267 269
270 ServerWindow* EventDispatcherTest::GetActiveSystemModalWindow() const {
271 ModalWindowController* mwc =
272 EventDispatcherTestApi(event_dispatcher_.get()).modal_window_controller();
273 return ModalWindowControllerTestApi(mwc).GetActiveSystemModalWindow();
274 }
275
268 void EventDispatcherTest::SetUp() { 276 void EventDispatcherTest::SetUp() {
269 testing::Test::SetUp(); 277 testing::Test::SetUp();
270 278
271 window_delegate_.reset(new TestServerWindowDelegate()); 279 window_delegate_.reset(new TestServerWindowDelegate());
272 root_window_.reset(new ServerWindow(window_delegate_.get(), WindowId(1, 2))); 280 root_window_.reset(new ServerWindow(window_delegate_.get(), WindowId(1, 2)));
273 window_delegate_->set_root_window(root_window_.get()); 281 window_delegate_->set_root_window(root_window_.get());
274 root_window_->SetVisible(true); 282 root_window_->SetVisible(true);
275 283
276 test_event_dispatcher_delegate_.reset( 284 test_event_dispatcher_delegate_.reset(
277 new TestEventDispatcherDelegate(root_window_.get())); 285 new TestEventDispatcherDelegate(root_window_.get()));
(...skipping 1044 matching lines...) Expand 10 before | Expand all | Expand 10 after
1322 EXPECT_TRUE(details->in_nonclient_area); 1330 EXPECT_TRUE(details->in_nonclient_area);
1323 1331
1324 ASSERT_TRUE(details->event); 1332 ASSERT_TRUE(details->event);
1325 ASSERT_TRUE(details->event->IsPointerEvent()); 1333 ASSERT_TRUE(details->event->IsPointerEvent());
1326 1334
1327 ui::PointerEvent* dispatched_event = details->event->AsPointerEvent(); 1335 ui::PointerEvent* dispatched_event = details->event->AsPointerEvent();
1328 EXPECT_EQ(gfx::Point(25, 25), dispatched_event->root_location()); 1336 EXPECT_EQ(gfx::Point(25, 25), dispatched_event->root_location());
1329 EXPECT_EQ(gfx::Point(-25, 15), dispatched_event->location()); 1337 EXPECT_EQ(gfx::Point(-25, 15), dispatched_event->location());
1330 } 1338 }
1331 1339
1340 // Tests that events on a system modal window target the modal window itself.
1341 TEST_F(EventDispatcherTest, ModalWindowEventOnSystemModal) {
1342 std::unique_ptr<ServerWindow> w1 = CreateChildWindow(WindowId(1, 3));
1343
1344 root_window()->SetBounds(gfx::Rect(0, 0, 100, 100));
1345 w1->SetBounds(gfx::Rect(10, 10, 30, 30));
1346 w1->SetModal();
1347
1348 // Send event that is over |w1|.
1349 const ui::PointerEvent mouse_pressed(ui::MouseEvent(
1350 ui::ET_MOUSE_PRESSED, gfx::Point(15, 15), gfx::Point(15, 15),
1351 base::TimeDelta(), ui::EF_LEFT_MOUSE_BUTTON, ui::EF_LEFT_MOUSE_BUTTON));
1352 event_dispatcher()->ProcessEvent(mouse_pressed);
1353
1354 std::unique_ptr<DispatchedEventDetails> details =
1355 test_event_dispatcher_delegate()->GetAndAdvanceDispatchedEventDetails();
1356 ASSERT_TRUE(details);
1357 EXPECT_EQ(w1.get(), details->window);
1358 EXPECT_FALSE(details->in_nonclient_area);
1359
1360 ASSERT_TRUE(details->event);
1361 ASSERT_TRUE(details->event->IsPointerEvent());
1362
1363 ui::PointerEvent* dispatched_event = details->event->AsPointerEvent();
1364 EXPECT_EQ(gfx::Point(15, 15), dispatched_event->root_location());
1365 EXPECT_EQ(gfx::Point(5, 5), dispatched_event->location());
1366 }
1367
1368 // Tests that events outside of system modal window target the modal window.
1369 TEST_F(EventDispatcherTest, ModalWindowEventOutsideSystemModal) {
1370 std::unique_ptr<ServerWindow> w1 = CreateChildWindow(WindowId(1, 3));
1371
1372 root_window()->SetBounds(gfx::Rect(0, 0, 100, 100));
1373 w1->SetBounds(gfx::Rect(10, 10, 30, 30));
1374 w1->SetModal();
1375 event_dispatcher()->AddSystemModalWindow(w1.get());
1376
1377 // Send event that is over |w1|.
1378 const ui::PointerEvent mouse_pressed(ui::MouseEvent(
1379 ui::ET_MOUSE_PRESSED, gfx::Point(45, 15), gfx::Point(45, 15),
1380 base::TimeDelta(), ui::EF_LEFT_MOUSE_BUTTON, ui::EF_LEFT_MOUSE_BUTTON));
1381 event_dispatcher()->ProcessEvent(mouse_pressed);
1382
1383 std::unique_ptr<DispatchedEventDetails> details =
1384 test_event_dispatcher_delegate()->GetAndAdvanceDispatchedEventDetails();
1385 ASSERT_TRUE(details);
1386 EXPECT_EQ(w1.get(), details->window);
1387 EXPECT_TRUE(details->in_nonclient_area);
1388
1389 ASSERT_TRUE(details->event);
1390 ASSERT_TRUE(details->event->IsPointerEvent());
1391
1392 ui::PointerEvent* dispatched_event = details->event->AsPointerEvent();
1393 EXPECT_EQ(gfx::Point(45, 15), dispatched_event->root_location());
1394 EXPECT_EQ(gfx::Point(35, 5), dispatched_event->location());
1395 }
1332 1396
1333 // Tests that setting capture to a descendant of a modal parent fails. 1397 // Tests that setting capture to a descendant of a modal parent fails.
1334 TEST_F(EventDispatcherTest, ModalWindowSetCaptureDescendantOfModalParent) { 1398 TEST_F(EventDispatcherTest, ModalWindowSetCaptureDescendantOfModalParent) {
1335 std::unique_ptr<ServerWindow> w1 = CreateChildWindow(WindowId(1, 3)); 1399 std::unique_ptr<ServerWindow> w1 = CreateChildWindow(WindowId(1, 3));
1336 std::unique_ptr<ServerWindow> w11 = 1400 std::unique_ptr<ServerWindow> w11 =
1337 CreateChildWindowWithParent(WindowId(1, 4), w1.get()); 1401 CreateChildWindowWithParent(WindowId(1, 4), w1.get());
1338 std::unique_ptr<ServerWindow> w2 = CreateChildWindow(WindowId(1, 5)); 1402 std::unique_ptr<ServerWindow> w2 = CreateChildWindow(WindowId(1, 5));
1339 1403
1340 root_window()->SetBounds(gfx::Rect(0, 0, 100, 100)); 1404 root_window()->SetBounds(gfx::Rect(0, 0, 100, 100));
1341 w1->SetBounds(gfx::Rect(10, 10, 30, 30)); 1405 w1->SetBounds(gfx::Rect(10, 10, 30, 30));
1342 w11->SetBounds(gfx::Rect(10, 10, 10, 10)); 1406 w11->SetBounds(gfx::Rect(10, 10, 10, 10));
1343 w2->SetBounds(gfx::Rect(50, 10, 10, 10)); 1407 w2->SetBounds(gfx::Rect(50, 10, 10, 10));
1344 1408
1345 w1->AddTransientWindow(w2.get()); 1409 w1->AddTransientWindow(w2.get());
1346 w2->SetModal(); 1410 w2->SetModal();
1347 1411
1348 EXPECT_FALSE(event_dispatcher()->SetCaptureWindow(w11.get(), false)); 1412 EXPECT_FALSE(event_dispatcher()->SetCaptureWindow(w11.get(), false));
1349 EXPECT_EQ(nullptr, event_dispatcher()->capture_window()); 1413 EXPECT_EQ(nullptr, event_dispatcher()->capture_window());
1350 } 1414 }
1351 1415
1352 // Tests that setting capture to a window unrelated to a modal parent works. 1416 // Tests that setting capture to a window unrelated to a modal parent works.
1353 TEST_F(EventDispatcherTest, ModalWindowSetCaptureUnrelatedWindow) { 1417 TEST_F(EventDispatcherTest, ModalWindowSetCaptureUnrelatedWindow) {
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> w2 = CreateChildWindow(WindowId(1, 5)); 1419 std::unique_ptr<ServerWindow> w2 = CreateChildWindow(WindowId(1, 4));
1356 std::unique_ptr<ServerWindow> w3 = CreateChildWindow(WindowId(1, 6)); 1420 std::unique_ptr<ServerWindow> w3 = CreateChildWindow(WindowId(1, 5));
1357 1421
1358 root_window()->SetBounds(gfx::Rect(0, 0, 100, 100)); 1422 root_window()->SetBounds(gfx::Rect(0, 0, 100, 100));
1359 w1->SetBounds(gfx::Rect(10, 10, 30, 30)); 1423 w1->SetBounds(gfx::Rect(10, 10, 30, 30));
1360 w2->SetBounds(gfx::Rect(50, 10, 10, 10)); 1424 w2->SetBounds(gfx::Rect(50, 10, 10, 10));
1361 w3->SetBounds(gfx::Rect(70, 10, 10, 10)); 1425 w3->SetBounds(gfx::Rect(70, 10, 10, 10));
1362 1426
1363 w1->AddTransientWindow(w2.get()); 1427 w1->AddTransientWindow(w2.get());
1364 w2->SetModal(); 1428 w2->SetModal();
1365 1429
1366 EXPECT_TRUE(event_dispatcher()->SetCaptureWindow(w3.get(), false)); 1430 EXPECT_TRUE(event_dispatcher()->SetCaptureWindow(w3.get(), false));
1367 EXPECT_EQ(w3.get(), event_dispatcher()->capture_window()); 1431 EXPECT_EQ(w3.get(), event_dispatcher()->capture_window());
1368 } 1432 }
1369 1433
1434 // Tests that setting capture fails when there is a system modal window.
1435 TEST_F(EventDispatcherTest, ModalWindowSystemSetCapture) {
1436 std::unique_ptr<ServerWindow> w1 = CreateChildWindow(WindowId(1, 3));
1437 std::unique_ptr<ServerWindow> w2 = CreateChildWindow(WindowId(1, 4));
1438
1439 root_window()->SetBounds(gfx::Rect(0, 0, 100, 100));
1440 w1->SetBounds(gfx::Rect(10, 10, 30, 30));
1441 w2->SetBounds(gfx::Rect(50, 10, 10, 10));
1442
1443 event_dispatcher()->AddSystemModalWindow(w2.get());
1444
1445 EXPECT_FALSE(event_dispatcher()->SetCaptureWindow(w1.get(), false));
1446 EXPECT_EQ(nullptr, event_dispatcher()->capture_window());
1447 }
1448
1449 // Tests having multiple system modal windows.
1450 TEST_F(EventDispatcherTest, ModalWindowMultipleSystemModals) {
1451 std::unique_ptr<ServerWindow> w1 = CreateChildWindow(WindowId(1, 3));
1452 std::unique_ptr<ServerWindow> w2 = CreateChildWindow(WindowId(1, 4));
1453 std::unique_ptr<ServerWindow> w3 = CreateChildWindow(WindowId(1, 5));
1454
1455 w2->SetVisible(false);
1456
1457 // In the beginning, there should be no active system modal window.
1458 EXPECT_EQ(nullptr, GetActiveSystemModalWindow());
1459
1460 // Add a visible system modal window. It should become the active one.
1461 event_dispatcher()->AddSystemModalWindow(w1.get());
1462 EXPECT_EQ(w1.get(), GetActiveSystemModalWindow());
1463
1464 // Add an invisible system modal window. It should not change the active one.
1465 event_dispatcher()->AddSystemModalWindow(w2.get());
1466 EXPECT_EQ(w1.get(), GetActiveSystemModalWindow());
1467
1468 // Add another visible system modal window. It should become the active one.
1469 event_dispatcher()->AddSystemModalWindow(w3.get());
1470 EXPECT_EQ(w3.get(), GetActiveSystemModalWindow());
1471
1472 // Make an existing system modal window visible. It should become the active
1473 // one.
1474 w2->SetVisible(true);
1475 EXPECT_EQ(w2.get(), GetActiveSystemModalWindow());
1476
1477 // Remove the active system modal window. Next one should become active.
1478 w2.reset();
1479 EXPECT_EQ(w3.get(), GetActiveSystemModalWindow());
1480
1481 // Remove an inactive system modal window. It should not change the active
1482 // one.
1483 w1.reset();
1484 EXPECT_EQ(w3.get(), GetActiveSystemModalWindow());
1485
1486 // Remove the last remaining system modal window. There should be no active
1487 // one anymore.
1488 w3.reset();
1489 EXPECT_EQ(nullptr, GetActiveSystemModalWindow());
1490 }
1491
1370 } // namespace test 1492 } // namespace test
1371 } // namespace ws 1493 } // namespace ws
1372 } // namespace mus 1494 } // namespace mus
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698