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

Side by Side Diff: services/ui/ws/window_tree_unittest.cc

Issue 2833163002: Change ui cursor identifiers to an enum class. (Closed)
Patch Set: OK, it can't be explicit for mac. Created 3 years, 8 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 | « services/ui/ws/window_tree_client_unittest.cc ('k') | ui/aura/mus/window_port_mus.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 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 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 "services/ui/ws/window_tree.h" 5 #include "services/ui/ws/window_tree.h"
6 6
7 #include <stdint.h> 7 #include <stdint.h>
8 8
9 #include <string> 9 #include <string>
10 #include <vector> 10 #include <vector>
(...skipping 457 matching lines...) Expand 10 before | Expand all | Expand 10 after
468 TestWindowTreeClient* embed_client = nullptr; 468 TestWindowTreeClient* embed_client = nullptr;
469 WindowTree* tree = nullptr; 469 WindowTree* tree = nullptr;
470 ServerWindow* window = nullptr; 470 ServerWindow* window = nullptr;
471 EXPECT_NO_FATAL_FAILURE(SetupEventTargeting(&embed_client, &tree, &window)); 471 EXPECT_NO_FATAL_FAILURE(SetupEventTargeting(&embed_client, &tree, &window));
472 472
473 // Like in BasicInputEventTarget, we send a pointer down event to be 473 // Like in BasicInputEventTarget, we send a pointer down event to be
474 // dispatched. This is only to place the mouse cursor over that window though. 474 // dispatched. This is only to place the mouse cursor over that window though.
475 DispatchEventAndAckImmediately(CreateMouseMoveEvent(21, 22)); 475 DispatchEventAndAckImmediately(CreateMouseMoveEvent(21, 22));
476 476
477 // Set the cursor on the parent as that is where the cursor is picked up from. 477 // Set the cursor on the parent as that is where the cursor is picked up from.
478 window->parent()->SetPredefinedCursor(mojom::CursorType::IBEAM); 478 window->parent()->SetPredefinedCursor(mojom::CursorType::kIBeam);
479 479
480 // Because the cursor is over the window when SetCursor was called, we should 480 // Because the cursor is over the window when SetCursor was called, we should
481 // have immediately changed the cursor. 481 // have immediately changed the cursor.
482 EXPECT_EQ(mojom::CursorType::IBEAM, cursor_id()); 482 EXPECT_EQ(mojom::CursorType::kIBeam, cursor_id());
483 } 483 }
484 484
485 TEST_F(WindowTreeTest, CursorChangesWhenEnteringWindowWithDifferentCursor) { 485 TEST_F(WindowTreeTest, CursorChangesWhenEnteringWindowWithDifferentCursor) {
486 TestWindowTreeClient* embed_client = nullptr; 486 TestWindowTreeClient* embed_client = nullptr;
487 WindowTree* tree = nullptr; 487 WindowTree* tree = nullptr;
488 ServerWindow* window = nullptr; 488 ServerWindow* window = nullptr;
489 EXPECT_NO_FATAL_FAILURE(SetupEventTargeting(&embed_client, &tree, &window)); 489 EXPECT_NO_FATAL_FAILURE(SetupEventTargeting(&embed_client, &tree, &window));
490 490
491 // Let's create a pointer event outside the window and then move the pointer 491 // Let's create a pointer event outside the window and then move the pointer
492 // inside. 492 // inside.
493 DispatchEventAndAckImmediately(CreateMouseMoveEvent(5, 5)); 493 DispatchEventAndAckImmediately(CreateMouseMoveEvent(5, 5));
494 // Set the cursor on the parent as that is where the cursor is picked up from. 494 // Set the cursor on the parent as that is where the cursor is picked up from.
495 window->parent()->SetPredefinedCursor(mojom::CursorType::IBEAM); 495 window->parent()->SetPredefinedCursor(mojom::CursorType::kIBeam);
496 EXPECT_EQ(mojom::CursorType::POINTER, cursor_id()); 496 EXPECT_EQ(mojom::CursorType::kPointer, cursor_id());
497 497
498 DispatchEventAndAckImmediately(CreateMouseMoveEvent(21, 22)); 498 DispatchEventAndAckImmediately(CreateMouseMoveEvent(21, 22));
499 EXPECT_EQ(mojom::CursorType::IBEAM, cursor_id()); 499 EXPECT_EQ(mojom::CursorType::kIBeam, cursor_id());
500 } 500 }
501 501
502 TEST_F(WindowTreeTest, TouchesDontChangeCursor) { 502 TEST_F(WindowTreeTest, TouchesDontChangeCursor) {
503 TestWindowTreeClient* embed_client = nullptr; 503 TestWindowTreeClient* embed_client = nullptr;
504 WindowTree* tree = nullptr; 504 WindowTree* tree = nullptr;
505 ServerWindow* window = nullptr; 505 ServerWindow* window = nullptr;
506 EXPECT_NO_FATAL_FAILURE(SetupEventTargeting(&embed_client, &tree, &window)); 506 EXPECT_NO_FATAL_FAILURE(SetupEventTargeting(&embed_client, &tree, &window));
507 507
508 // Let's create a pointer event outside the window and then move the pointer 508 // Let's create a pointer event outside the window and then move the pointer
509 // inside. 509 // inside.
510 DispatchEventAndAckImmediately(CreateMouseMoveEvent(5, 5)); 510 DispatchEventAndAckImmediately(CreateMouseMoveEvent(5, 5));
511 window->SetPredefinedCursor(mojom::CursorType::IBEAM); 511 window->SetPredefinedCursor(mojom::CursorType::kIBeam);
512 EXPECT_EQ(mojom::CursorType::POINTER, cursor_id()); 512 EXPECT_EQ(mojom::CursorType::kPointer, cursor_id());
513 513
514 // With a touch event, we shouldn't update the cursor. 514 // With a touch event, we shouldn't update the cursor.
515 DispatchEventAndAckImmediately(CreatePointerDownEvent(21, 22)); 515 DispatchEventAndAckImmediately(CreatePointerDownEvent(21, 22));
516 EXPECT_EQ(mojom::CursorType::POINTER, cursor_id()); 516 EXPECT_EQ(mojom::CursorType::kPointer, cursor_id());
517 } 517 }
518 518
519 TEST_F(WindowTreeTest, DragOutsideWindow) { 519 TEST_F(WindowTreeTest, DragOutsideWindow) {
520 TestWindowTreeClient* embed_client = nullptr; 520 TestWindowTreeClient* embed_client = nullptr;
521 WindowTree* tree = nullptr; 521 WindowTree* tree = nullptr;
522 ServerWindow* window = nullptr; 522 ServerWindow* window = nullptr;
523 EXPECT_NO_FATAL_FAILURE(SetupEventTargeting(&embed_client, &tree, &window)); 523 EXPECT_NO_FATAL_FAILURE(SetupEventTargeting(&embed_client, &tree, &window));
524 524
525 // Start with the cursor outside the window. Setting the cursor shouldn't 525 // Start with the cursor outside the window. Setting the cursor shouldn't
526 // change the cursor. 526 // change the cursor.
527 DispatchEventAndAckImmediately(CreateMouseMoveEvent(5, 5)); 527 DispatchEventAndAckImmediately(CreateMouseMoveEvent(5, 5));
528 // Set the cursor on the parent as that is where the cursor is picked up from. 528 // Set the cursor on the parent as that is where the cursor is picked up from.
529 window->parent()->SetPredefinedCursor(mojom::CursorType::IBEAM); 529 window->parent()->SetPredefinedCursor(mojom::CursorType::kIBeam);
530 EXPECT_EQ(mojom::CursorType::POINTER, cursor_id()); 530 EXPECT_EQ(mojom::CursorType::kPointer, cursor_id());
531 531
532 // Move the pointer to the inside of the window 532 // Move the pointer to the inside of the window
533 DispatchEventAndAckImmediately(CreateMouseMoveEvent(21, 22)); 533 DispatchEventAndAckImmediately(CreateMouseMoveEvent(21, 22));
534 EXPECT_EQ(mojom::CursorType::IBEAM, cursor_id()); 534 EXPECT_EQ(mojom::CursorType::kIBeam, cursor_id());
535 535
536 // Start the drag. 536 // Start the drag.
537 DispatchEventAndAckImmediately(CreateMouseDownEvent(21, 22)); 537 DispatchEventAndAckImmediately(CreateMouseDownEvent(21, 22));
538 EXPECT_EQ(mojom::CursorType::IBEAM, cursor_id()); 538 EXPECT_EQ(mojom::CursorType::kIBeam, cursor_id());
539 539
540 // Move the cursor (mouse is still down) outside the window. 540 // Move the cursor (mouse is still down) outside the window.
541 DispatchEventAndAckImmediately(CreateMouseMoveEvent(5, 5)); 541 DispatchEventAndAckImmediately(CreateMouseMoveEvent(5, 5));
542 EXPECT_EQ(mojom::CursorType::IBEAM, cursor_id()); 542 EXPECT_EQ(mojom::CursorType::kIBeam, cursor_id());
543 543
544 // Release the cursor. We should now adapt the cursor of the window 544 // Release the cursor. We should now adapt the cursor of the window
545 // underneath the pointer. 545 // underneath the pointer.
546 DispatchEventAndAckImmediately(CreateMouseUpEvent(5, 5)); 546 DispatchEventAndAckImmediately(CreateMouseUpEvent(5, 5));
547 EXPECT_EQ(mojom::CursorType::POINTER, cursor_id()); 547 EXPECT_EQ(mojom::CursorType::kPointer, cursor_id());
548 } 548 }
549 549
550 TEST_F(WindowTreeTest, ChangingWindowBoundsChangesCursor) { 550 TEST_F(WindowTreeTest, ChangingWindowBoundsChangesCursor) {
551 TestWindowTreeClient* embed_client = nullptr; 551 TestWindowTreeClient* embed_client = nullptr;
552 WindowTree* tree = nullptr; 552 WindowTree* tree = nullptr;
553 ServerWindow* window = nullptr; 553 ServerWindow* window = nullptr;
554 EXPECT_NO_FATAL_FAILURE(SetupEventTargeting(&embed_client, &tree, &window)); 554 EXPECT_NO_FATAL_FAILURE(SetupEventTargeting(&embed_client, &tree, &window));
555 555
556 // Put the cursor just outside the bounds of the window. 556 // Put the cursor just outside the bounds of the window.
557 DispatchEventAndAckImmediately(CreateMouseMoveEvent(41, 41)); 557 DispatchEventAndAckImmediately(CreateMouseMoveEvent(41, 41));
558 // Sets the cursor on the root as that is where the cursor is picked up from. 558 // Sets the cursor on the root as that is where the cursor is picked up from.
559 window->parent()->SetPredefinedCursor(mojom::CursorType::IBEAM); 559 window->parent()->SetPredefinedCursor(mojom::CursorType::kIBeam);
560 EXPECT_EQ(mojom::CursorType::POINTER, cursor_id()); 560 EXPECT_EQ(mojom::CursorType::kPointer, cursor_id());
561 561
562 // Expand the bounds of the window so they now include where the cursor now 562 // Expand the bounds of the window so they now include where the cursor now
563 // is. 563 // is.
564 window->SetBounds(gfx::Rect(20, 20, 25, 25)); 564 window->SetBounds(gfx::Rect(20, 20, 25, 25));
565 EXPECT_EQ(mojom::CursorType::IBEAM, cursor_id()); 565 EXPECT_EQ(mojom::CursorType::kIBeam, cursor_id());
566 566
567 // Contract the bounds again. 567 // Contract the bounds again.
568 window->SetBounds(gfx::Rect(20, 20, 20, 20)); 568 window->SetBounds(gfx::Rect(20, 20, 20, 20));
569 EXPECT_EQ(mojom::CursorType::POINTER, cursor_id()); 569 EXPECT_EQ(mojom::CursorType::kPointer, cursor_id());
570 } 570 }
571 571
572 TEST_F(WindowTreeTest, WindowReorderingChangesCursor) { 572 TEST_F(WindowTreeTest, WindowReorderingChangesCursor) {
573 // Setup two trees parented to the root with the same bounds. 573 // Setup two trees parented to the root with the same bounds.
574 ServerWindow* embed_window1 = 574 ServerWindow* embed_window1 =
575 window_event_targeting_helper_.CreatePrimaryTree( 575 window_event_targeting_helper_.CreatePrimaryTree(
576 gfx::Rect(0, 0, 200, 200), gfx::Rect(0, 0, 50, 50)); 576 gfx::Rect(0, 0, 200, 200), gfx::Rect(0, 0, 50, 50));
577 ServerWindow* embed_window2 = 577 ServerWindow* embed_window2 =
578 window_event_targeting_helper_.CreatePrimaryTree( 578 window_event_targeting_helper_.CreatePrimaryTree(
579 gfx::Rect(0, 0, 200, 200), gfx::Rect(0, 0, 50, 50)); 579 gfx::Rect(0, 0, 200, 200), gfx::Rect(0, 0, 50, 50));
580 580
581 ASSERT_EQ(embed_window1->parent(), embed_window2->parent()); 581 ASSERT_EQ(embed_window1->parent(), embed_window2->parent());
582 embed_window1->set_event_targeting_policy( 582 embed_window1->set_event_targeting_policy(
583 mojom::EventTargetingPolicy::TARGET_AND_DESCENDANTS); 583 mojom::EventTargetingPolicy::TARGET_AND_DESCENDANTS);
584 embed_window2->set_event_targeting_policy( 584 embed_window2->set_event_targeting_policy(
585 mojom::EventTargetingPolicy::TARGET_AND_DESCENDANTS); 585 mojom::EventTargetingPolicy::TARGET_AND_DESCENDANTS);
586 embed_window1->SetPredefinedCursor(mojom::CursorType::IBEAM); 586 embed_window1->SetPredefinedCursor(mojom::CursorType::kIBeam);
587 embed_window2->SetPredefinedCursor(mojom::CursorType::CROSS); 587 embed_window2->SetPredefinedCursor(mojom::CursorType::kCross);
588 DispatchEventAndAckImmediately(CreateMouseMoveEvent(5, 5)); 588 DispatchEventAndAckImmediately(CreateMouseMoveEvent(5, 5));
589 // Cursor should match that of top-most window, which is |embed_window2|. 589 // Cursor should match that of top-most window, which is |embed_window2|.
590 EXPECT_EQ(mojom::CursorType::CROSS, cursor_id()); 590 EXPECT_EQ(mojom::CursorType::kCross, cursor_id());
591 // Move |embed_window1| on top, cursor should now match it. 591 // Move |embed_window1| on top, cursor should now match it.
592 embed_window1->parent()->StackChildAtTop(embed_window1); 592 embed_window1->parent()->StackChildAtTop(embed_window1);
593 EXPECT_EQ(mojom::CursorType::IBEAM, cursor_id()); 593 EXPECT_EQ(mojom::CursorType::kIBeam, cursor_id());
594 } 594 }
595 595
596 // Assertions around moving cursor between trees with roots. 596 // Assertions around moving cursor between trees with roots.
597 TEST_F(WindowTreeTest, CursorMultipleTrees) { 597 TEST_F(WindowTreeTest, CursorMultipleTrees) {
598 // Setup two trees parented to the root with the same bounds. 598 // Setup two trees parented to the root with the same bounds.
599 ServerWindow* embed_window1 = 599 ServerWindow* embed_window1 =
600 window_event_targeting_helper_.CreatePrimaryTree( 600 window_event_targeting_helper_.CreatePrimaryTree(
601 gfx::Rect(0, 0, 200, 200), gfx::Rect(0, 0, 10, 10)); 601 gfx::Rect(0, 0, 200, 200), gfx::Rect(0, 0, 10, 10));
602 ServerWindow* embed_window2 = 602 ServerWindow* embed_window2 =
603 window_event_targeting_helper_.CreatePrimaryTree( 603 window_event_targeting_helper_.CreatePrimaryTree(
604 gfx::Rect(0, 0, 200, 200), gfx::Rect(20, 20, 20, 20)); 604 gfx::Rect(0, 0, 200, 200), gfx::Rect(20, 20, 20, 20));
605 embed_window1->set_event_targeting_policy( 605 embed_window1->set_event_targeting_policy(
606 mojom::EventTargetingPolicy::TARGET_AND_DESCENDANTS); 606 mojom::EventTargetingPolicy::TARGET_AND_DESCENDANTS);
607 embed_window2->set_event_targeting_policy( 607 embed_window2->set_event_targeting_policy(
608 mojom::EventTargetingPolicy::TARGET_AND_DESCENDANTS); 608 mojom::EventTargetingPolicy::TARGET_AND_DESCENDANTS);
609 embed_window2->parent()->set_event_targeting_policy( 609 embed_window2->parent()->set_event_targeting_policy(
610 mojom::EventTargetingPolicy::TARGET_AND_DESCENDANTS); 610 mojom::EventTargetingPolicy::TARGET_AND_DESCENDANTS);
611 embed_window1->SetPredefinedCursor(mojom::CursorType::IBEAM); 611 embed_window1->SetPredefinedCursor(mojom::CursorType::kIBeam);
612 embed_window2->SetPredefinedCursor(mojom::CursorType::CROSS); 612 embed_window2->SetPredefinedCursor(mojom::CursorType::kCross);
613 embed_window1->parent()->SetPredefinedCursor(mojom::CursorType::COPY); 613 embed_window1->parent()->SetPredefinedCursor(mojom::CursorType::kCopy);
614 614
615 // Create a child of |embed_window1|. 615 // Create a child of |embed_window1|.
616 ServerWindow* embed_window1_child = NewWindowInTreeWithParent( 616 ServerWindow* embed_window1_child = NewWindowInTreeWithParent(
617 window_server()->GetTreeWithRoot(embed_window1), embed_window1); 617 window_server()->GetTreeWithRoot(embed_window1), embed_window1);
618 ASSERT_TRUE(embed_window1_child); 618 ASSERT_TRUE(embed_window1_child);
619 embed_window1_child->SetBounds(gfx::Rect(0, 0, 10, 10)); 619 embed_window1_child->SetBounds(gfx::Rect(0, 0, 10, 10));
620 embed_window1_child->SetVisible(true); 620 embed_window1_child->SetVisible(true);
621 621
622 // Move mouse into |embed_window1|. 622 // Move mouse into |embed_window1|.
623 DispatchEventAndAckImmediately(CreateMouseMoveEvent(5, 5)); 623 DispatchEventAndAckImmediately(CreateMouseMoveEvent(5, 5));
624 EXPECT_EQ(mojom::CursorType::IBEAM, cursor_id()); 624 EXPECT_EQ(mojom::CursorType::kIBeam, cursor_id());
625 625
626 // Move mouse into |embed_window2|. 626 // Move mouse into |embed_window2|.
627 DispatchEventAndAckImmediately(CreateMouseMoveEvent(25, 25)); 627 DispatchEventAndAckImmediately(CreateMouseMoveEvent(25, 25));
628 EXPECT_EQ(mojom::CursorType::CROSS, cursor_id()); 628 EXPECT_EQ(mojom::CursorType::kCross, cursor_id());
629 629
630 // Move mouse into area between, which should use cursor set on parent. 630 // Move mouse into area between, which should use cursor set on parent.
631 DispatchEventAndAckImmediately(CreateMouseMoveEvent(15, 15)); 631 DispatchEventAndAckImmediately(CreateMouseMoveEvent(15, 15));
632 EXPECT_EQ(mojom::CursorType::COPY, cursor_id()); 632 EXPECT_EQ(mojom::CursorType::kCopy, cursor_id());
633 } 633 }
634 634
635 TEST_F(WindowTreeTest, EventAck) { 635 TEST_F(WindowTreeTest, EventAck) {
636 const ClientWindowId embed_window_id = BuildClientWindowId(wm_tree(), 1); 636 const ClientWindowId embed_window_id = BuildClientWindowId(wm_tree(), 1);
637 EXPECT_TRUE( 637 EXPECT_TRUE(
638 wm_tree()->NewWindow(embed_window_id, ServerWindow::Properties())); 638 wm_tree()->NewWindow(embed_window_id, ServerWindow::Properties()));
639 EXPECT_TRUE(wm_tree()->SetWindowVisibility(embed_window_id, true)); 639 EXPECT_TRUE(wm_tree()->SetWindowVisibility(embed_window_id, true));
640 ASSERT_TRUE(FirstRoot(wm_tree())); 640 ASSERT_TRUE(FirstRoot(wm_tree()));
641 EXPECT_TRUE(wm_tree()->AddWindow(FirstRootId(wm_tree()), embed_window_id)); 641 EXPECT_TRUE(wm_tree()->AddWindow(FirstRootId(wm_tree()), embed_window_id));
642 ASSERT_EQ(1u, display()->root_window()->children().size()); 642 ASSERT_EQ(1u, display()->root_window()->children().size());
(...skipping 936 matching lines...) Expand 10 before | Expand all | Expand 10 after
1579 EXPECT_TRUE(window_manager_tree->DeleteWindow(display_root_id)); 1579 EXPECT_TRUE(window_manager_tree->DeleteWindow(display_root_id));
1580 EXPECT_TRUE(window_manager_tree->roots().empty()); 1580 EXPECT_TRUE(window_manager_tree->roots().empty());
1581 EXPECT_TRUE(WindowManagerStateTestApi(window_manager_state) 1581 EXPECT_TRUE(WindowManagerStateTestApi(window_manager_state)
1582 .window_manager_display_roots() 1582 .window_manager_display_roots()
1583 .empty()); 1583 .empty());
1584 } 1584 }
1585 1585
1586 } // namespace test 1586 } // namespace test
1587 } // namespace ws 1587 } // namespace ws
1588 } // namespace ui 1588 } // namespace ui
OLDNEW
« no previous file with comments | « services/ui/ws/window_tree_client_unittest.cc ('k') | ui/aura/mus/window_port_mus.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698