| 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 <vector> | 6 #include <vector> |
| 7 | 7 |
| 8 // Include views_test_base.h first because the definition of None in X.h | 8 // Include views_test_base.h first because the definition of None in X.h |
| 9 // conflicts with the definition of None in gtest-type-util.h | 9 // conflicts with the definition of None in gtest-type-util.h |
| 10 #include "ui/views/test/views_test_base.h" | 10 #include "ui/views/test/views_test_base.h" |
| (...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 73 std::vector<XClientMessageEvent> events_; | 73 std::vector<XClientMessageEvent> events_; |
| 74 | 74 |
| 75 DISALLOW_COPY_AND_ASSIGN(ClientMessageEventCollector); | 75 DISALLOW_COPY_AND_ASSIGN(ClientMessageEventCollector); |
| 76 }; | 76 }; |
| 77 | 77 |
| 78 // An implementation of X11MoveLoop where RunMoveLoop() always starts the move | 78 // An implementation of X11MoveLoop where RunMoveLoop() always starts the move |
| 79 // loop. | 79 // loop. |
| 80 class TestMoveLoop : public X11MoveLoop { | 80 class TestMoveLoop : public X11MoveLoop { |
| 81 public: | 81 public: |
| 82 explicit TestMoveLoop(X11MoveLoopDelegate* delegate); | 82 explicit TestMoveLoop(X11MoveLoopDelegate* delegate); |
| 83 virtual ~TestMoveLoop(); | 83 ~TestMoveLoop() override; |
| 84 | 84 |
| 85 // Returns true if the move loop is running. | 85 // Returns true if the move loop is running. |
| 86 bool IsRunning() const; | 86 bool IsRunning() const; |
| 87 | 87 |
| 88 // X11MoveLoop: | 88 // X11MoveLoop: |
| 89 virtual bool RunMoveLoop(aura::Window* window, | 89 bool RunMoveLoop(aura::Window* window, gfx::NativeCursor cursor) override; |
| 90 gfx::NativeCursor cursor) override; | 90 void UpdateCursor(gfx::NativeCursor cursor) override; |
| 91 virtual void UpdateCursor(gfx::NativeCursor cursor) override; | 91 void EndMoveLoop() override; |
| 92 virtual void EndMoveLoop() override; | |
| 93 | 92 |
| 94 private: | 93 private: |
| 95 // Not owned. | 94 // Not owned. |
| 96 X11MoveLoopDelegate* delegate_; | 95 X11MoveLoopDelegate* delegate_; |
| 97 | 96 |
| 98 // Ends the move loop. | 97 // Ends the move loop. |
| 99 base::Closure quit_closure_; | 98 base::Closure quit_closure_; |
| 100 | 99 |
| 101 bool is_running_; | 100 bool is_running_; |
| 102 }; | 101 }; |
| 103 | 102 |
| 104 // Implementation of DesktopDragDropClientAuraX11 which works with a fake | 103 // Implementation of DesktopDragDropClientAuraX11 which works with a fake |
| 105 // |DesktopDragDropClientAuraX11::source_current_window_|. | 104 // |DesktopDragDropClientAuraX11::source_current_window_|. |
| 106 class TestDragDropClient : public DesktopDragDropClientAuraX11 { | 105 class TestDragDropClient : public DesktopDragDropClientAuraX11 { |
| 107 public: | 106 public: |
| 108 // The location in screen coordinates used for the synthetic mouse moves | 107 // The location in screen coordinates used for the synthetic mouse moves |
| 109 // generated in SetTopmostXWindowAndMoveMouse(). | 108 // generated in SetTopmostXWindowAndMoveMouse(). |
| 110 static const int kMouseMoveX; | 109 static const int kMouseMoveX; |
| 111 static const int kMouseMoveY; | 110 static const int kMouseMoveY; |
| 112 | 111 |
| 113 TestDragDropClient(aura::Window* window, | 112 TestDragDropClient(aura::Window* window, |
| 114 DesktopNativeCursorManager* cursor_manager); | 113 DesktopNativeCursorManager* cursor_manager); |
| 115 virtual ~TestDragDropClient(); | 114 ~TestDragDropClient() override; |
| 116 | 115 |
| 117 // Returns the XID of the window which initiated the drag. | 116 // Returns the XID of the window which initiated the drag. |
| 118 ::Window source_xwindow() { | 117 ::Window source_xwindow() { |
| 119 return source_xid_; | 118 return source_xid_; |
| 120 } | 119 } |
| 121 | 120 |
| 122 // Returns the Atom with |name|. | 121 // Returns the Atom with |name|. |
| 123 Atom GetAtom(const char* name); | 122 Atom GetAtom(const char* name); |
| 124 | 123 |
| 125 // Returns true if the event's message has |type|. | 124 // Returns true if the event's message has |type|. |
| (...skipping 19 matching lines...) Expand all Loading... |
| 145 | 144 |
| 146 // Sets |xid| as the topmost window at the current mouse position and | 145 // Sets |xid| as the topmost window at the current mouse position and |
| 147 // generates a synthetic mouse move. | 146 // generates a synthetic mouse move. |
| 148 void SetTopmostXWindowAndMoveMouse(::Window xid); | 147 void SetTopmostXWindowAndMoveMouse(::Window xid); |
| 149 | 148 |
| 150 // Returns true if the move loop is running. | 149 // Returns true if the move loop is running. |
| 151 bool IsMoveLoopRunning(); | 150 bool IsMoveLoopRunning(); |
| 152 | 151 |
| 153 private: | 152 private: |
| 154 // DesktopDragDropClientAuraX11: | 153 // DesktopDragDropClientAuraX11: |
| 155 virtual scoped_ptr<X11MoveLoop> CreateMoveLoop( | 154 scoped_ptr<X11MoveLoop> CreateMoveLoop( |
| 156 X11MoveLoopDelegate* delegate) override; | 155 X11MoveLoopDelegate* delegate) override; |
| 157 virtual ::Window FindWindowFor(const gfx::Point& screen_point) override; | 156 ::Window FindWindowFor(const gfx::Point& screen_point) override; |
| 158 virtual void SendXClientEvent(::Window xid, XEvent* event) override; | 157 void SendXClientEvent(::Window xid, XEvent* event) override; |
| 159 | 158 |
| 160 // The XID of the window which initiated the drag. | 159 // The XID of the window which initiated the drag. |
| 161 ::Window source_xid_; | 160 ::Window source_xid_; |
| 162 | 161 |
| 163 // The XID of the window which is simulated to be the topmost window at the | 162 // The XID of the window which is simulated to be the topmost window at the |
| 164 // current mouse position. | 163 // current mouse position. |
| 165 ::Window target_xid_; | 164 ::Window target_xid_; |
| 166 | 165 |
| 167 // The move loop. Not owned. | 166 // The move loop. Not owned. |
| 168 TestMoveLoop* loop_; | 167 TestMoveLoop* loop_; |
| (...skipping 173 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 342 it->second->RecordEvent(event->xclient); | 341 it->second->RecordEvent(event->xclient); |
| 343 } | 342 } |
| 344 | 343 |
| 345 } // namespace | 344 } // namespace |
| 346 | 345 |
| 347 class DesktopDragDropClientAuraX11Test : public ViewsTestBase { | 346 class DesktopDragDropClientAuraX11Test : public ViewsTestBase { |
| 348 public: | 347 public: |
| 349 DesktopDragDropClientAuraX11Test() { | 348 DesktopDragDropClientAuraX11Test() { |
| 350 } | 349 } |
| 351 | 350 |
| 352 virtual ~DesktopDragDropClientAuraX11Test() { | 351 ~DesktopDragDropClientAuraX11Test() override {} |
| 353 } | |
| 354 | 352 |
| 355 int StartDragAndDrop() { | 353 int StartDragAndDrop() { |
| 356 ui::OSExchangeData data; | 354 ui::OSExchangeData data; |
| 357 data.SetString(base::ASCIIToUTF16("Test")); | 355 data.SetString(base::ASCIIToUTF16("Test")); |
| 358 | 356 |
| 359 return client_->StartDragAndDrop( | 357 return client_->StartDragAndDrop( |
| 360 data, | 358 data, |
| 361 widget_->GetNativeWindow()->GetRootWindow(), | 359 widget_->GetNativeWindow()->GetRootWindow(), |
| 362 widget_->GetNativeWindow(), | 360 widget_->GetNativeWindow(), |
| 363 gfx::Point(), | 361 gfx::Point(), |
| 364 ui::DragDropTypes::DRAG_COPY, | 362 ui::DragDropTypes::DRAG_COPY, |
| 365 ui::DragDropTypes::DRAG_EVENT_SOURCE_MOUSE); | 363 ui::DragDropTypes::DRAG_EVENT_SOURCE_MOUSE); |
| 366 } | 364 } |
| 367 | 365 |
| 368 // ViewsTestBase: | 366 // ViewsTestBase: |
| 369 virtual void SetUp() override { | 367 void SetUp() override { |
| 370 ViewsTestBase::SetUp(); | 368 ViewsTestBase::SetUp(); |
| 371 | 369 |
| 372 // Create widget to initiate the drags. | 370 // Create widget to initiate the drags. |
| 373 widget_.reset(new Widget); | 371 widget_.reset(new Widget); |
| 374 Widget::InitParams params(Widget::InitParams::TYPE_WINDOW); | 372 Widget::InitParams params(Widget::InitParams::TYPE_WINDOW); |
| 375 params.ownership = Widget::InitParams::WIDGET_OWNS_NATIVE_WIDGET; | 373 params.ownership = Widget::InitParams::WIDGET_OWNS_NATIVE_WIDGET; |
| 376 params.native_widget = new DesktopNativeWidgetAura(widget_.get()); | 374 params.native_widget = new DesktopNativeWidgetAura(widget_.get()); |
| 377 params.bounds = gfx::Rect(100, 100); | 375 params.bounds = gfx::Rect(100, 100); |
| 378 widget_->Init(params); | 376 widget_->Init(params); |
| 379 widget_->Show(); | 377 widget_->Show(); |
| 380 | 378 |
| 381 cursor_manager_.reset(new DesktopNativeCursorManager( | 379 cursor_manager_.reset(new DesktopNativeCursorManager( |
| 382 DesktopCursorLoaderUpdater::Create())); | 380 DesktopCursorLoaderUpdater::Create())); |
| 383 | 381 |
| 384 client_.reset(new TestDragDropClient(widget_->GetNativeWindow(), | 382 client_.reset(new TestDragDropClient(widget_->GetNativeWindow(), |
| 385 cursor_manager_.get())); | 383 cursor_manager_.get())); |
| 386 client_->Init(); | 384 client_->Init(); |
| 387 } | 385 } |
| 388 | 386 |
| 389 virtual void TearDown() override { | 387 void TearDown() override { |
| 390 client_.reset(); | 388 client_.reset(); |
| 391 cursor_manager_.reset(); | 389 cursor_manager_.reset(); |
| 392 widget_.reset(); | 390 widget_.reset(); |
| 393 ViewsTestBase::TearDown(); | 391 ViewsTestBase::TearDown(); |
| 394 } | 392 } |
| 395 | 393 |
| 396 TestDragDropClient* client() { | 394 TestDragDropClient* client() { |
| 397 return client_.get(); | 395 return client_.get(); |
| 398 } | 396 } |
| 399 | 397 |
| (...skipping 316 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 716 | 714 |
| 717 // Repeat the test but reject the drop in the XdndFinished message instead. | 715 // Repeat the test but reject the drop in the XdndFinished message instead. |
| 718 base::MessageLoop::current()->PostTask( | 716 base::MessageLoop::current()->PostTask( |
| 719 FROM_HERE, | 717 FROM_HERE, |
| 720 base::Bind(&RejectAfterMouseReleaseStep3, client())); | 718 base::Bind(&RejectAfterMouseReleaseStep3, client())); |
| 721 result = StartDragAndDrop(); | 719 result = StartDragAndDrop(); |
| 722 EXPECT_EQ(ui::DragDropTypes::DRAG_NONE, result); | 720 EXPECT_EQ(ui::DragDropTypes::DRAG_NONE, result); |
| 723 } | 721 } |
| 724 | 722 |
| 725 } // namespace views | 723 } // namespace views |
| OLD | NEW |