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

Side by Side Diff: ui/views/widget/desktop_aura/desktop_drag_drop_client_aurax11_unittest.cc

Issue 2049493004: Remove use of deprecated MessageLoop methods in ui. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: rebase Created 4 years, 6 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 | « ui/views/mouse_watcher.cc ('k') | ui/views/widget/desktop_aura/desktop_window_tree_host_x11.cc » ('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 <map> 5 #include <map>
6 #include <memory> 6 #include <memory>
7 #include <vector> 7 #include <vector>
8 8
9 // Include views_test_base.h first because the definition of None in X.h 9 // Include views_test_base.h first because the definition of None in X.h
10 // conflicts with the definition of None in gtest-type-util.h 10 // conflicts with the definition of None in gtest-type-util.h
11 #include "ui/views/test/views_test_base.h" 11 #include "ui/views/test/views_test_base.h"
12 12
13 #include "base/location.h"
13 #include "base/macros.h" 14 #include "base/macros.h"
14 #include "base/memory/ptr_util.h" 15 #include "base/memory/ptr_util.h"
15 #include "base/run_loop.h" 16 #include "base/run_loop.h"
17 #include "base/single_thread_task_runner.h"
16 #include "base/strings/utf_string_conversions.h" 18 #include "base/strings/utf_string_conversions.h"
19 #include "base/threading/thread_task_runner_handle.h"
17 #include "ui/aura/test/test_screen.h" 20 #include "ui/aura/test/test_screen.h"
18 #include "ui/aura/window.h" 21 #include "ui/aura/window.h"
19 #include "ui/aura/window_tree_host.h" 22 #include "ui/aura/window_tree_host.h"
20 #include "ui/base/dragdrop/os_exchange_data.h" 23 #include "ui/base/dragdrop/os_exchange_data.h"
21 #include "ui/base/x/x11_util.h" 24 #include "ui/base/x/x11_util.h"
22 #include "ui/events/event_utils.h" 25 #include "ui/events/event_utils.h"
23 #include "ui/gfx/x/x11_atom_cache.h" 26 #include "ui/gfx/x/x11_atom_cache.h"
24 #include "ui/gfx/x/x11_types.h" 27 #include "ui/gfx/x/x11_types.h"
25 #include "ui/views/widget/desktop_aura/desktop_cursor_loader_updater.h" 28 #include "ui/views/widget/desktop_aura/desktop_cursor_loader_updater.h"
26 #include "ui/views/widget/desktop_aura/desktop_drag_drop_client_aurax11.h" 29 #include "ui/views/widget/desktop_aura/desktop_drag_drop_client_aurax11.h"
(...skipping 499 matching lines...) Expand 10 before | Expand all | Expand 10 after
526 EXPECT_TRUE(client->IsMoveLoopRunning()); 529 EXPECT_TRUE(client->IsMoveLoopRunning());
527 client->OnFinished(toplevel, true, client->GetAtom("XdndActionCopy")); 530 client->OnFinished(toplevel, true, client->GetAtom("XdndActionCopy"));
528 EXPECT_FALSE(client->IsMoveLoopRunning()); 531 EXPECT_FALSE(client->IsMoveLoopRunning());
529 } 532 }
530 533
531 } // namespace 534 } // namespace
532 535
533 TEST_F(DesktopDragDropClientAuraX11Test, Basic) { 536 TEST_F(DesktopDragDropClientAuraX11Test, Basic) {
534 XID toplevel = 1; 537 XID toplevel = 1;
535 538
536 base::MessageLoop::current()->PostTask(FROM_HERE, 539 base::ThreadTaskRunnerHandle::Get()->PostTask(
537 base::Bind(&BasicStep2, 540 FROM_HERE, base::Bind(&BasicStep2, client(), toplevel));
538 client(),
539 toplevel));
540 int result = StartDragAndDrop(); 541 int result = StartDragAndDrop();
541 EXPECT_EQ(ui::DragDropTypes::DRAG_COPY, result); 542 EXPECT_EQ(ui::DragDropTypes::DRAG_COPY, result);
542 543
543 // Do another drag and drop to test that the data is properly cleaned up as a 544 // Do another drag and drop to test that the data is properly cleaned up as a
544 // result of the XdndFinished message. 545 // result of the XdndFinished message.
545 base::MessageLoop::current()->PostTask(FROM_HERE, 546 base::ThreadTaskRunnerHandle::Get()->PostTask(
546 base::Bind(&BasicStep3, 547 FROM_HERE, base::Bind(&BasicStep3, client(), toplevel));
547 client(),
548 toplevel));
549 result = StartDragAndDrop(); 548 result = StartDragAndDrop();
550 EXPECT_EQ(ui::DragDropTypes::DRAG_COPY, result); 549 EXPECT_EQ(ui::DragDropTypes::DRAG_COPY, result);
551 } 550 }
552 551
553 void HighDPIStep(TestDragDropClient* client) { 552 void HighDPIStep(TestDragDropClient* client) {
554 float scale = 553 float scale =
555 display::Screen::GetScreen()->GetPrimaryDisplay().device_scale_factor(); 554 display::Screen::GetScreen()->GetPrimaryDisplay().device_scale_factor();
556 // Start dragging at 100, 100 in native coordinates. 555 // Start dragging at 100, 100 in native coordinates.
557 gfx::Point mouse_position_in_screen_pixel(100, 100); 556 gfx::Point mouse_position_in_screen_pixel(100, 100);
558 client->OnMouseMovement(mouse_position_in_screen_pixel, 0, 557 client->OnMouseMovement(mouse_position_in_screen_pixel, 0,
(...skipping 10 matching lines...) Expand all
569 client->drag_widget()->GetWindowBoundsInScreen().origin()); 568 client->drag_widget()->GetWindowBoundsInScreen().origin());
570 569
571 client->OnMouseReleased(); 570 client->OnMouseReleased();
572 } 571 }
573 572
574 TEST_F(DesktopDragDropClientAuraX11Test, HighDPI200) { 573 TEST_F(DesktopDragDropClientAuraX11Test, HighDPI200) {
575 aura::TestScreen* screen = 574 aura::TestScreen* screen =
576 static_cast<aura::TestScreen*>(display::Screen::GetScreen()); 575 static_cast<aura::TestScreen*>(display::Screen::GetScreen());
577 screen->SetDeviceScaleFactor(2.0f); 576 screen->SetDeviceScaleFactor(2.0f);
578 577
579 base::MessageLoop::current()->PostTask(FROM_HERE, 578 base::ThreadTaskRunnerHandle::Get()->PostTask(
580 base::Bind(&HighDPIStep, client())); 579 FROM_HERE, base::Bind(&HighDPIStep, client()));
581 int result = StartDragAndDrop(); 580 int result = StartDragAndDrop();
582 EXPECT_EQ(ui::DragDropTypes::DRAG_NONE, result); 581 EXPECT_EQ(ui::DragDropTypes::DRAG_NONE, result);
583 } 582 }
584 583
585 TEST_F(DesktopDragDropClientAuraX11Test, HighDPI150) { 584 TEST_F(DesktopDragDropClientAuraX11Test, HighDPI150) {
586 aura::TestScreen* screen = 585 aura::TestScreen* screen =
587 static_cast<aura::TestScreen*>(display::Screen::GetScreen()); 586 static_cast<aura::TestScreen*>(display::Screen::GetScreen());
588 screen->SetDeviceScaleFactor(1.5f); 587 screen->SetDeviceScaleFactor(1.5f);
589 588
590 base::MessageLoop::current()->PostTask(FROM_HERE, 589 base::ThreadTaskRunnerHandle::Get()->PostTask(
591 base::Bind(&HighDPIStep, client())); 590 FROM_HERE, base::Bind(&HighDPIStep, client()));
592 int result = StartDragAndDrop(); 591 int result = StartDragAndDrop();
593 EXPECT_EQ(ui::DragDropTypes::DRAG_NONE, result); 592 EXPECT_EQ(ui::DragDropTypes::DRAG_NONE, result);
594 } 593 }
595 594
596 namespace { 595 namespace {
597 596
598 void TargetDoesNotRespondStep2(TestDragDropClient* client) { 597 void TargetDoesNotRespondStep2(TestDragDropClient* client) {
599 EXPECT_TRUE(client->IsMoveLoopRunning()); 598 EXPECT_TRUE(client->IsMoveLoopRunning());
600 599
601 XID toplevel = 1; 600 XID toplevel = 1;
(...skipping 12 matching lines...) Expand all
614 EXPECT_FALSE(client->IsMoveLoopRunning()); 613 EXPECT_FALSE(client->IsMoveLoopRunning());
615 } 614 }
616 615
617 } // namespace 616 } // namespace
618 617
619 // Test that we do not wait for the target to send XdndStatus if we have not 618 // Test that we do not wait for the target to send XdndStatus if we have not
620 // received any XdndStatus messages at all from the target. The Unity 619 // received any XdndStatus messages at all from the target. The Unity
621 // DNDCollectionWindow is an example of an XdndAware target which does not 620 // DNDCollectionWindow is an example of an XdndAware target which does not
622 // respond to XdndPosition messages at all. 621 // respond to XdndPosition messages at all.
623 TEST_F(DesktopDragDropClientAuraX11Test, TargetDoesNotRespond) { 622 TEST_F(DesktopDragDropClientAuraX11Test, TargetDoesNotRespond) {
624 base::MessageLoop::current()->PostTask( 623 base::ThreadTaskRunnerHandle::Get()->PostTask(
625 FROM_HERE, 624 FROM_HERE, base::Bind(&TargetDoesNotRespondStep2, client()));
626 base::Bind(&TargetDoesNotRespondStep2, client()));
627 int result = StartDragAndDrop(); 625 int result = StartDragAndDrop();
628 EXPECT_EQ(ui::DragDropTypes::DRAG_NONE, result); 626 EXPECT_EQ(ui::DragDropTypes::DRAG_NONE, result);
629 } 627 }
630 628
631 namespace { 629 namespace {
632 630
633 void QueuePositionStep2(TestDragDropClient* client) { 631 void QueuePositionStep2(TestDragDropClient* client) {
634 EXPECT_TRUE(client->IsMoveLoopRunning()); 632 EXPECT_TRUE(client->IsMoveLoopRunning());
635 633
636 XID toplevel = 1; 634 XID toplevel = 1;
(...skipping 23 matching lines...) Expand all
660 EXPECT_TRUE(client->IsMoveLoopRunning()); 658 EXPECT_TRUE(client->IsMoveLoopRunning());
661 client->OnFinished(toplevel, true, client->GetAtom("XdndActionCopy")); 659 client->OnFinished(toplevel, true, client->GetAtom("XdndActionCopy"));
662 EXPECT_FALSE(client->IsMoveLoopRunning()); 660 EXPECT_FALSE(client->IsMoveLoopRunning());
663 } 661 }
664 662
665 } // namespace 663 } // namespace
666 664
667 // Test that XdndPosition messages are queued till the pending XdndPosition 665 // Test that XdndPosition messages are queued till the pending XdndPosition
668 // message is acked via an XdndStatus message. 666 // message is acked via an XdndStatus message.
669 TEST_F(DesktopDragDropClientAuraX11Test, QueuePosition) { 667 TEST_F(DesktopDragDropClientAuraX11Test, QueuePosition) {
670 base::MessageLoop::current()->PostTask( 668 base::ThreadTaskRunnerHandle::Get()->PostTask(
671 FROM_HERE, 669 FROM_HERE, base::Bind(&QueuePositionStep2, client()));
672 base::Bind(&QueuePositionStep2, client()));
673 int result = StartDragAndDrop(); 670 int result = StartDragAndDrop();
674 EXPECT_EQ(ui::DragDropTypes::DRAG_COPY, result); 671 EXPECT_EQ(ui::DragDropTypes::DRAG_COPY, result);
675 } 672 }
676 673
677 namespace { 674 namespace {
678 675
679 void TargetChangesStep2(TestDragDropClient* client) { 676 void TargetChangesStep2(TestDragDropClient* client) {
680 EXPECT_TRUE(client->IsMoveLoopRunning()); 677 EXPECT_TRUE(client->IsMoveLoopRunning());
681 678
682 XID toplevel1 = 1; 679 XID toplevel1 = 1;
(...skipping 30 matching lines...) Expand all
713 710
714 EXPECT_TRUE(client->IsMoveLoopRunning()); 711 EXPECT_TRUE(client->IsMoveLoopRunning());
715 client->OnFinished(toplevel2, true, client->GetAtom("XdndActionCopy")); 712 client->OnFinished(toplevel2, true, client->GetAtom("XdndActionCopy"));
716 EXPECT_FALSE(client->IsMoveLoopRunning()); 713 EXPECT_FALSE(client->IsMoveLoopRunning());
717 } 714 }
718 715
719 } // namespace 716 } // namespace
720 717
721 // Test the behavior when the target changes during a drag. 718 // Test the behavior when the target changes during a drag.
722 TEST_F(DesktopDragDropClientAuraX11Test, TargetChanges) { 719 TEST_F(DesktopDragDropClientAuraX11Test, TargetChanges) {
723 base::MessageLoop::current()->PostTask( 720 base::ThreadTaskRunnerHandle::Get()->PostTask(
724 FROM_HERE, 721 FROM_HERE, base::Bind(&TargetChangesStep2, client()));
725 base::Bind(&TargetChangesStep2, client()));
726 int result = StartDragAndDrop(); 722 int result = StartDragAndDrop();
727 EXPECT_EQ(ui::DragDropTypes::DRAG_COPY, result); 723 EXPECT_EQ(ui::DragDropTypes::DRAG_COPY, result);
728 } 724 }
729 725
730 namespace { 726 namespace {
731 727
732 void RejectAfterMouseReleaseStep2(TestDragDropClient* client) { 728 void RejectAfterMouseReleaseStep2(TestDragDropClient* client) {
733 EXPECT_TRUE(client->IsMoveLoopRunning()); 729 EXPECT_TRUE(client->IsMoveLoopRunning());
734 730
735 XID toplevel = 1; 731 XID toplevel = 1;
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after
783 EXPECT_TRUE(client->IsMoveLoopRunning()); 779 EXPECT_TRUE(client->IsMoveLoopRunning());
784 client->OnFinished(toplevel, false, None); 780 client->OnFinished(toplevel, false, None);
785 EXPECT_FALSE(client->IsMoveLoopRunning()); 781 EXPECT_FALSE(client->IsMoveLoopRunning());
786 } 782 }
787 783
788 } // namespace 784 } // namespace
789 785
790 // Test that the source sends XdndLeave instead of XdndDrop if the drag 786 // Test that the source sends XdndLeave instead of XdndDrop if the drag
791 // operation is rejected after the mouse is released. 787 // operation is rejected after the mouse is released.
792 TEST_F(DesktopDragDropClientAuraX11Test, RejectAfterMouseRelease) { 788 TEST_F(DesktopDragDropClientAuraX11Test, RejectAfterMouseRelease) {
793 base::MessageLoop::current()->PostTask( 789 base::ThreadTaskRunnerHandle::Get()->PostTask(
794 FROM_HERE, 790 FROM_HERE, base::Bind(&RejectAfterMouseReleaseStep2, client()));
795 base::Bind(&RejectAfterMouseReleaseStep2, client()));
796 int result = StartDragAndDrop(); 791 int result = StartDragAndDrop();
797 EXPECT_EQ(ui::DragDropTypes::DRAG_NONE, result); 792 EXPECT_EQ(ui::DragDropTypes::DRAG_NONE, result);
798 793
799 // Repeat the test but reject the drop in the XdndFinished message instead. 794 // Repeat the test but reject the drop in the XdndFinished message instead.
800 base::MessageLoop::current()->PostTask( 795 base::ThreadTaskRunnerHandle::Get()->PostTask(
801 FROM_HERE, 796 FROM_HERE, base::Bind(&RejectAfterMouseReleaseStep3, client()));
802 base::Bind(&RejectAfterMouseReleaseStep3, client()));
803 result = StartDragAndDrop(); 797 result = StartDragAndDrop();
804 EXPECT_EQ(ui::DragDropTypes::DRAG_NONE, result); 798 EXPECT_EQ(ui::DragDropTypes::DRAG_NONE, result);
805 } 799 }
806 800
807 namespace { 801 namespace {
808 802
809 // DragDropDelegate which counts the number of each type of drag-drop event and 803 // DragDropDelegate which counts the number of each type of drag-drop event and
810 // keeps track of the most recent drag-drop event. 804 // keeps track of the most recent drag-drop event.
811 class TestDragDropDelegate : public aura::client::DragDropDelegate { 805 class TestDragDropDelegate : public aura::client::DragDropDelegate {
812 public: 806 public:
(...skipping 178 matching lines...) Expand 10 before | Expand all | Expand 10 after
991 EXPECT_EQ(point2_in_target_widget.ToString(), 985 EXPECT_EQ(point2_in_target_widget.ToString(),
992 delegate->last_event_mouse_position().ToString()); 986 delegate->last_event_mouse_position().ToString());
993 EXPECT_EQ(modifier_flags, delegate->last_event_flags()); 987 EXPECT_EQ(modifier_flags, delegate->last_event_flags());
994 988
995 EXPECT_FALSE(client->IsMoveLoopRunning()); 989 EXPECT_FALSE(client->IsMoveLoopRunning());
996 } 990 }
997 991
998 } // namespace 992 } // namespace
999 993
1000 TEST_F(DesktopDragDropClientAuraX11ChromeSourceTargetTest, Basic) { 994 TEST_F(DesktopDragDropClientAuraX11ChromeSourceTargetTest, Basic) {
1001 base::MessageLoop::current()->PostTask( 995 base::ThreadTaskRunnerHandle::Get()->PostTask(
1002 FROM_HERE, 996 FROM_HERE, base::Bind(&ChromeSourceTargetStep2, client(), ui::EF_NONE));
1003 base::Bind(&ChromeSourceTargetStep2, client(), ui::EF_NONE));
1004 int result = StartDragAndDrop(); 997 int result = StartDragAndDrop();
1005 EXPECT_EQ(ui::DragDropTypes::DRAG_COPY, result); 998 EXPECT_EQ(ui::DragDropTypes::DRAG_COPY, result);
1006 } 999 }
1007 1000
1008 // Test that if 'Ctrl' is pressed during a drag and drop operation, that 1001 // Test that if 'Ctrl' is pressed during a drag and drop operation, that
1009 // the aura::client::DragDropDelegate is properly notified. 1002 // the aura::client::DragDropDelegate is properly notified.
1010 TEST_F(DesktopDragDropClientAuraX11ChromeSourceTargetTest, CtrlPressed) { 1003 TEST_F(DesktopDragDropClientAuraX11ChromeSourceTargetTest, CtrlPressed) {
1011 base::MessageLoop::current()->PostTask( 1004 base::ThreadTaskRunnerHandle::Get()->PostTask(
1012 FROM_HERE, 1005 FROM_HERE,
1013 base::Bind(&ChromeSourceTargetStep2, client(), ui::EF_CONTROL_DOWN)); 1006 base::Bind(&ChromeSourceTargetStep2, client(), ui::EF_CONTROL_DOWN));
1014 int result = StartDragAndDrop(); 1007 int result = StartDragAndDrop();
1015 EXPECT_EQ(ui::DragDropTypes::DRAG_COPY, result); 1008 EXPECT_EQ(ui::DragDropTypes::DRAG_COPY, result);
1016 } 1009 }
1017 1010
1018 } // namespace views 1011 } // namespace views
OLDNEW
« no previous file with comments | « ui/views/mouse_watcher.cc ('k') | ui/views/widget/desktop_aura/desktop_window_tree_host_x11.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698