| OLD | NEW |
| 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/macros.h" | 13 #include "base/macros.h" |
| 14 #include "base/memory/ptr_util.h" | 14 #include "base/memory/ptr_util.h" |
| 15 #include "base/run_loop.h" | 15 #include "base/run_loop.h" |
| 16 #include "base/strings/utf_string_conversions.h" | 16 #include "base/strings/utf_string_conversions.h" |
| 17 #include "ui/aura/test/test_screen.h" |
| 17 #include "ui/aura/window.h" | 18 #include "ui/aura/window.h" |
| 18 #include "ui/aura/window_tree_host.h" | 19 #include "ui/aura/window_tree_host.h" |
| 19 #include "ui/base/dragdrop/os_exchange_data.h" | 20 #include "ui/base/dragdrop/os_exchange_data.h" |
| 20 #include "ui/base/x/x11_util.h" | 21 #include "ui/base/x/x11_util.h" |
| 21 #include "ui/events/event_utils.h" | 22 #include "ui/events/event_utils.h" |
| 22 #include "ui/gfx/x/x11_atom_cache.h" | 23 #include "ui/gfx/x/x11_atom_cache.h" |
| 23 #include "ui/gfx/x/x11_types.h" | 24 #include "ui/gfx/x/x11_types.h" |
| 24 #include "ui/views/widget/desktop_aura/desktop_cursor_loader_updater.h" | 25 #include "ui/views/widget/desktop_aura/desktop_cursor_loader_updater.h" |
| 25 #include "ui/views/widget/desktop_aura/desktop_drag_drop_client_aurax11.h" | 26 #include "ui/views/widget/desktop_aura/desktop_drag_drop_client_aurax11.h" |
| 26 #include "ui/views/widget/desktop_aura/desktop_native_cursor_manager.h" | 27 #include "ui/views/widget/desktop_aura/desktop_native_cursor_manager.h" |
| (...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 111 SimpleTestDragDropClient(aura::Window*, | 112 SimpleTestDragDropClient(aura::Window*, |
| 112 DesktopNativeCursorManager* cursor_manager); | 113 DesktopNativeCursorManager* cursor_manager); |
| 113 ~SimpleTestDragDropClient() override; | 114 ~SimpleTestDragDropClient() override; |
| 114 | 115 |
| 115 // Sets |xid| as the topmost window for all mouse positions. | 116 // Sets |xid| as the topmost window for all mouse positions. |
| 116 void SetTopmostXWindow(XID xid); | 117 void SetTopmostXWindow(XID xid); |
| 117 | 118 |
| 118 // Returns true if the move loop is running. | 119 // Returns true if the move loop is running. |
| 119 bool IsMoveLoopRunning(); | 120 bool IsMoveLoopRunning(); |
| 120 | 121 |
| 122 Widget* drag_widget() { return DesktopDragDropClientAuraX11::drag_widget(); } |
| 123 |
| 121 private: | 124 private: |
| 122 // DesktopDragDropClientAuraX11: | 125 // DesktopDragDropClientAuraX11: |
| 123 std::unique_ptr<X11MoveLoop> CreateMoveLoop( | 126 std::unique_ptr<X11MoveLoop> CreateMoveLoop( |
| 124 X11MoveLoopDelegate* delegate) override; | 127 X11MoveLoopDelegate* delegate) override; |
| 125 XID FindWindowFor(const gfx::Point& screen_point) override; | 128 XID FindWindowFor(const gfx::Point& screen_point) override; |
| 126 | 129 |
| 127 // The XID of the window which is simulated to be the topmost window. | 130 // The XID of the window which is simulated to be the topmost window. |
| 128 XID target_xid_; | 131 XID target_xid_; |
| 129 | 132 |
| 130 // The move loop. Not owned. | 133 // The move loop. Not owned. |
| (...skipping 247 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 378 class DesktopDragDropClientAuraX11Test : public ViewsTestBase { | 381 class DesktopDragDropClientAuraX11Test : public ViewsTestBase { |
| 379 public: | 382 public: |
| 380 DesktopDragDropClientAuraX11Test() { | 383 DesktopDragDropClientAuraX11Test() { |
| 381 } | 384 } |
| 382 | 385 |
| 383 ~DesktopDragDropClientAuraX11Test() override {} | 386 ~DesktopDragDropClientAuraX11Test() override {} |
| 384 | 387 |
| 385 int StartDragAndDrop() { | 388 int StartDragAndDrop() { |
| 386 ui::OSExchangeData data; | 389 ui::OSExchangeData data; |
| 387 data.SetString(base::ASCIIToUTF16("Test")); | 390 data.SetString(base::ASCIIToUTF16("Test")); |
| 391 SkBitmap drag_bitmap; |
| 392 drag_bitmap.allocN32Pixels(10, 10); |
| 393 gfx::ImageSkia drag_image(gfx::ImageSkia::CreateFrom1xBitmap(drag_bitmap)); |
| 394 data.provider().SetDragImage(drag_image, gfx::Vector2d()); |
| 388 | 395 |
| 389 return client_->StartDragAndDrop( | 396 return client_->StartDragAndDrop( |
| 390 data, | 397 data, |
| 391 widget_->GetNativeWindow()->GetRootWindow(), | 398 widget_->GetNativeWindow()->GetRootWindow(), |
| 392 widget_->GetNativeWindow(), | 399 widget_->GetNativeWindow(), |
| 393 gfx::Point(), | 400 gfx::Point(), |
| 394 ui::DragDropTypes::DRAG_COPY, | 401 ui::DragDropTypes::DRAG_COPY, |
| 395 ui::DragDropTypes::DRAG_EVENT_SOURCE_MOUSE); | 402 ui::DragDropTypes::DRAG_EVENT_SOURCE_MOUSE); |
| 396 } | 403 } |
| 397 | 404 |
| 398 // ViewsTestBase: | 405 // ViewsTestBase: |
| 399 void SetUp() override { | 406 void SetUp() override { |
| 400 ViewsTestBase::SetUp(); | 407 ViewsTestBase::SetUp(); |
| 408 views_delegate()->set_use_desktop_native_widgets(true); |
| 401 | 409 |
| 402 // Create widget to initiate the drags. | 410 // Create widget to initiate the drags. |
| 403 widget_.reset(new Widget); | 411 widget_.reset(new Widget); |
| 404 Widget::InitParams params(Widget::InitParams::TYPE_WINDOW); | 412 Widget::InitParams params(Widget::InitParams::TYPE_WINDOW); |
| 405 params.ownership = Widget::InitParams::WIDGET_OWNS_NATIVE_WIDGET; | 413 params.ownership = Widget::InitParams::WIDGET_OWNS_NATIVE_WIDGET; |
| 406 params.native_widget = new DesktopNativeWidgetAura(widget_.get()); | 414 params.native_widget = new DesktopNativeWidgetAura(widget_.get()); |
| 407 params.bounds = gfx::Rect(100, 100); | 415 params.bounds = gfx::Rect(100, 100); |
| 408 widget_->Init(params); | 416 widget_->Init(params); |
| 409 widget_->Show(); | 417 widget_->Show(); |
| 410 | 418 |
| (...skipping 123 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 534 // Do another drag and drop to test that the data is properly cleaned up as a | 542 // Do another drag and drop to test that the data is properly cleaned up as a |
| 535 // result of the XdndFinished message. | 543 // result of the XdndFinished message. |
| 536 base::MessageLoop::current()->PostTask(FROM_HERE, | 544 base::MessageLoop::current()->PostTask(FROM_HERE, |
| 537 base::Bind(&BasicStep3, | 545 base::Bind(&BasicStep3, |
| 538 client(), | 546 client(), |
| 539 toplevel)); | 547 toplevel)); |
| 540 result = StartDragAndDrop(); | 548 result = StartDragAndDrop(); |
| 541 EXPECT_EQ(ui::DragDropTypes::DRAG_COPY, result); | 549 EXPECT_EQ(ui::DragDropTypes::DRAG_COPY, result); |
| 542 } | 550 } |
| 543 | 551 |
| 552 void HighDPIStep(TestDragDropClient* client) { |
| 553 float scale = |
| 554 display::Screen::GetScreen()->GetPrimaryDisplay().device_scale_factor(); |
| 555 // Start dragging at 100, 100 in native coordinates. |
| 556 gfx::Point mouse_position_in_screen_pixel(100, 100); |
| 557 client->OnMouseMovement(mouse_position_in_screen_pixel, 0, |
| 558 ui::EventTimeForNow()); |
| 559 |
| 560 EXPECT_EQ(gfx::ScaleToFlooredPoint(gfx::Point(100, 100), 1.f / scale), |
| 561 client->drag_widget()->GetWindowBoundsInScreen().origin()); |
| 562 |
| 563 // Drag the mouse down 200 pixels. |
| 564 mouse_position_in_screen_pixel.Offset(200, 0); |
| 565 client->OnMouseMovement(mouse_position_in_screen_pixel, 0, |
| 566 ui::EventTimeForNow()); |
| 567 EXPECT_EQ(gfx::ScaleToFlooredPoint(gfx::Point(300, 100), 1.f / scale), |
| 568 client->drag_widget()->GetWindowBoundsInScreen().origin()); |
| 569 |
| 570 client->OnMouseReleased(); |
| 571 } |
| 572 |
| 573 TEST_F(DesktopDragDropClientAuraX11Test, HighDPI200) { |
| 574 aura::TestScreen* screen = |
| 575 static_cast<aura::TestScreen*>(display::Screen::GetScreen()); |
| 576 screen->SetDeviceScaleFactor(2.0f); |
| 577 |
| 578 base::MessageLoop::current()->PostTask(FROM_HERE, |
| 579 base::Bind(&HighDPIStep, client())); |
| 580 int result = StartDragAndDrop(); |
| 581 EXPECT_EQ(ui::DragDropTypes::DRAG_NONE, result); |
| 582 } |
| 583 |
| 584 TEST_F(DesktopDragDropClientAuraX11Test, HighDPI150) { |
| 585 aura::TestScreen* screen = |
| 586 static_cast<aura::TestScreen*>(display::Screen::GetScreen()); |
| 587 screen->SetDeviceScaleFactor(1.5f); |
| 588 |
| 589 base::MessageLoop::current()->PostTask(FROM_HERE, |
| 590 base::Bind(&HighDPIStep, client())); |
| 591 int result = StartDragAndDrop(); |
| 592 EXPECT_EQ(ui::DragDropTypes::DRAG_NONE, result); |
| 593 } |
| 594 |
| 544 namespace { | 595 namespace { |
| 545 | 596 |
| 546 void TargetDoesNotRespondStep2(TestDragDropClient* client) { | 597 void TargetDoesNotRespondStep2(TestDragDropClient* client) { |
| 547 EXPECT_TRUE(client->IsMoveLoopRunning()); | 598 EXPECT_TRUE(client->IsMoveLoopRunning()); |
| 548 | 599 |
| 549 XID toplevel = 1; | 600 XID toplevel = 1; |
| 550 ClientMessageEventCollector collector(toplevel, client); | 601 ClientMessageEventCollector collector(toplevel, client); |
| 551 client->SetTopmostXWindowAndMoveMouse(toplevel); | 602 client->SetTopmostXWindowAndMoveMouse(toplevel); |
| 552 | 603 |
| 553 std::vector<XClientMessageEvent> events = collector.PopAllEvents(); | 604 std::vector<XClientMessageEvent> events = collector.PopAllEvents(); |
| (...skipping 402 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 956 // the aura::client::DragDropDelegate is properly notified. | 1007 // the aura::client::DragDropDelegate is properly notified. |
| 957 TEST_F(DesktopDragDropClientAuraX11ChromeSourceTargetTest, CtrlPressed) { | 1008 TEST_F(DesktopDragDropClientAuraX11ChromeSourceTargetTest, CtrlPressed) { |
| 958 base::MessageLoop::current()->PostTask( | 1009 base::MessageLoop::current()->PostTask( |
| 959 FROM_HERE, | 1010 FROM_HERE, |
| 960 base::Bind(&ChromeSourceTargetStep2, client(), ui::EF_CONTROL_DOWN)); | 1011 base::Bind(&ChromeSourceTargetStep2, client(), ui::EF_CONTROL_DOWN)); |
| 961 int result = StartDragAndDrop(); | 1012 int result = StartDragAndDrop(); |
| 962 EXPECT_EQ(ui::DragDropTypes::DRAG_COPY, result); | 1013 EXPECT_EQ(ui::DragDropTypes::DRAG_COPY, result); |
| 963 } | 1014 } |
| 964 | 1015 |
| 965 } // namespace views | 1016 } // namespace views |
| OLD | NEW |