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

Unified Diff: ui/views/widget/desktop_aura/desktop_drag_drop_client_aurax11_unittest.cc

Issue 431973006: Fix flakiness of DesktopDragDropClientAuraX11Tests (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 6 years, 4 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 side-by-side diff with in-line comments
Download patch
Index: ui/views/widget/desktop_aura/desktop_drag_drop_client_aurax11_unittest.cc
diff --git a/ui/views/widget/desktop_aura/desktop_drag_drop_client_aurax11_unittest.cc b/ui/views/widget/desktop_aura/desktop_drag_drop_client_aurax11_unittest.cc
index 4286d1873a51805d09053f9c4e900e3213a46332..b911bc412bcefa3f1b1a7f652b9b53f250dd1254 100644
--- a/ui/views/widget/desktop_aura/desktop_drag_drop_client_aurax11_unittest.cc
+++ b/ui/views/widget/desktop_aura/desktop_drag_drop_client_aurax11_unittest.cc
@@ -10,6 +10,7 @@
#include "ui/views/test/views_test_base.h"
#include "base/memory/scoped_ptr.h"
+#include "base/run_loop.h"
#include "base/strings/utf_string_conversions.h"
#include "ui/aura/window.h"
#include "ui/aura/window_tree_host.h"
@@ -21,6 +22,7 @@
#include "ui/views/widget/desktop_aura/desktop_drag_drop_client_aurax11.h"
#include "ui/views/widget/desktop_aura/desktop_native_cursor_manager.h"
#include "ui/views/widget/desktop_aura/desktop_native_widget_aura.h"
+#include "ui/views/widget/desktop_aura/x11_move_loop.h"
#include "ui/views/widget/widget.h"
#include <X11/Xlib.h>
@@ -73,6 +75,34 @@ class ClientMessageEventCollector {
DISALLOW_COPY_AND_ASSIGN(ClientMessageEventCollector);
};
+// An implementation of X11MoveLoop where RunMoveLoop() always starts the move
+// loop.
+class TestMoveLoop : public X11MoveLoop {
+ public:
+ explicit TestMoveLoop(X11MoveLoopDelegate* delegate);
+ virtual ~TestMoveLoop();
+
+ // Returns true if the move loop is running.
+ bool IsRunning() const;
+
+ // X11MoveLoop:
+ virtual bool RunMoveLoop(aura::Window* window,
+ gfx::NativeCursor cursor) OVERRIDE;
+ virtual void UpdateCursor(gfx::NativeCursor cursor) OVERRIDE;
+ virtual void EndMoveLoop() OVERRIDE;
+ virtual void SetDragImage(const gfx::ImageSkia& image,
+ const gfx::Vector2dF& offset) OVERRIDE;
+
+ private:
+ // Not owned.
+ X11MoveLoopDelegate* delegate_;
+
+ // Ends the move loop.
+ base::Closure quit_closure_;
+
+ bool is_running_;
+};
+
// Implementation of DesktopDragDropClientAuraX11 which works with a fake
// |DesktopDragDropClientAuraX11::source_current_window_|.
class TestDragDropClient : public DesktopDragDropClientAuraX11 {
@@ -122,18 +152,10 @@ class TestDragDropClient : public DesktopDragDropClientAuraX11 {
// Returns true if the move loop is running.
bool IsMoveLoopRunning();
- // DesktopDragDropClientAuraX11:
- virtual int StartDragAndDrop(
- const ui::OSExchangeData& data,
- aura::Window* root_window,
- aura::Window* source_window,
- const gfx::Point& root_location,
- int operation,
- ui::DragDropTypes::DragEventSource source) OVERRIDE;
- virtual void OnMoveLoopEnded() OVERRIDE;
-
private:
// DesktopDragDropClientAuraX11:
+ virtual scoped_ptr<X11MoveLoop> CreateMoveLoop(
+ X11MoveLoopDelegate* delegate) OVERRIDE;
virtual ::Window FindWindowFor(const gfx::Point& screen_point) OVERRIDE;
virtual void SendXClientEvent(::Window xid, XEvent* event) OVERRIDE;
@@ -144,8 +166,8 @@ class TestDragDropClient : public DesktopDragDropClientAuraX11 {
// current mouse position.
::Window target_xid_;
- // Whether the move loop is running.
- bool move_loop_running_;
+ // The move loop. Not owned.
+ TestMoveLoop* loop_;
// Map of ::Windows to the collector which intercepts XClientMessageEvents
// for that window.
@@ -183,6 +205,46 @@ void ClientMessageEventCollector::RecordEvent(
}
///////////////////////////////////////////////////////////////////////////////
+// TestMoveLoop
+
+TestMoveLoop::TestMoveLoop(X11MoveLoopDelegate* delegate)
+ : delegate_(delegate),
+ is_running_(false) {
+}
+
+TestMoveLoop::~TestMoveLoop() {
+}
+
+bool TestMoveLoop::IsRunning() const {
+ return is_running_;
+}
+
+bool TestMoveLoop::RunMoveLoop(
+ aura::Window* window,
+ gfx::NativeCursor cursor) {
+ is_running_ = true;
+ base::RunLoop run_loop;
+ quit_closure_ = run_loop.QuitClosure();
+ run_loop.Run();
+ return true;
+}
+
+void TestMoveLoop::UpdateCursor(gfx::NativeCursor cursor) {
+}
+
+void TestMoveLoop::EndMoveLoop() {
+ if (is_running_) {
+ delegate_->OnMoveLoopEnded();
+ is_running_ = false;
+ quit_closure_.Run();
+ }
+}
+
+void TestMoveLoop::SetDragImage(const gfx::ImageSkia& image,
+ const gfx::Vector2dF& offset) {
+}
+
+///////////////////////////////////////////////////////////////////////////////
// TestDragDropClient
// static
@@ -200,7 +262,7 @@ TestDragDropClient::TestDragDropClient(
window->GetHost()->GetAcceleratedWidget()),
source_xid_(window->GetHost()->GetAcceleratedWidget()),
target_xid_(None),
- move_loop_running_(false),
+ loop_(NULL),
atom_cache_(gfx::GetXDisplay(), kAtomsToCache) {
}
@@ -266,24 +328,13 @@ void TestDragDropClient::SetTopmostXWindowAndMoveMouse(::Window xid) {
}
bool TestDragDropClient::IsMoveLoopRunning() {
- return move_loop_running_;
-}
-
-int TestDragDropClient::StartDragAndDrop(
- const ui::OSExchangeData& data,
- aura::Window* root_window,
- aura::Window* source_window,
- const gfx::Point& root_location,
- int operation,
- ui::DragDropTypes::DragEventSource source) {
- move_loop_running_ = true;
- return DesktopDragDropClientAuraX11::StartDragAndDrop(data, root_window,
- source_window, root_location, operation, source);
+ return loop_->IsRunning();
}
-void TestDragDropClient::OnMoveLoopEnded() {
- DesktopDragDropClientAuraX11::OnMoveLoopEnded();
- move_loop_running_ = false;
+scoped_ptr<X11MoveLoop> TestDragDropClient::CreateMoveLoop(
+ X11MoveLoopDelegate* delegate) {
+ loop_ = new TestMoveLoop(delegate);
+ return scoped_ptr<X11MoveLoop>(loop_);
}
::Window TestDragDropClient::FindWindowFor(const gfx::Point& screen_point) {
@@ -338,6 +389,7 @@ class DesktopDragDropClientAuraX11Test : public ViewsTestBase {
client_.reset(new TestDragDropClient(widget_->GetNativeWindow(),
cursor_manager_.get()));
+ client_->Init();
}
virtual void TearDown() OVERRIDE {

Powered by Google App Engine
This is Rietveld 408576698