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

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

Powered by Google App Engine
This is Rietveld 408576698