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

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

Issue 443773003: Revert of 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 unified diff | Download patch | Annotate | Revision Log
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 <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"
11 11
12 #include "base/memory/scoped_ptr.h" 12 #include "base/memory/scoped_ptr.h"
13 #include "base/run_loop.h"
14 #include "base/strings/utf_string_conversions.h" 13 #include "base/strings/utf_string_conversions.h"
15 #include "ui/aura/window.h" 14 #include "ui/aura/window.h"
16 #include "ui/aura/window_tree_host.h" 15 #include "ui/aura/window_tree_host.h"
17 #include "ui/base/dragdrop/os_exchange_data.h" 16 #include "ui/base/dragdrop/os_exchange_data.h"
18 #include "ui/base/x/x11_util.h" 17 #include "ui/base/x/x11_util.h"
19 #include "ui/gfx/x/x11_atom_cache.h" 18 #include "ui/gfx/x/x11_atom_cache.h"
20 #include "ui/gfx/x/x11_types.h" 19 #include "ui/gfx/x/x11_types.h"
21 #include "ui/views/widget/desktop_aura/desktop_cursor_loader_updater.h" 20 #include "ui/views/widget/desktop_aura/desktop_cursor_loader_updater.h"
22 #include "ui/views/widget/desktop_aura/desktop_drag_drop_client_aurax11.h" 21 #include "ui/views/widget/desktop_aura/desktop_drag_drop_client_aurax11.h"
23 #include "ui/views/widget/desktop_aura/desktop_native_cursor_manager.h" 22 #include "ui/views/widget/desktop_aura/desktop_native_cursor_manager.h"
24 #include "ui/views/widget/desktop_aura/desktop_native_widget_aura.h" 23 #include "ui/views/widget/desktop_aura/desktop_native_widget_aura.h"
25 #include "ui/views/widget/desktop_aura/x11_move_loop.h"
26 #include "ui/views/widget/widget.h" 24 #include "ui/views/widget/widget.h"
27 25
28 #include <X11/Xlib.h> 26 #include <X11/Xlib.h>
29 27
30 namespace views { 28 namespace views {
31 29
32 namespace { 30 namespace {
33 31
34 const char* kAtomsToCache[] = { 32 const char* kAtomsToCache[] = {
35 "XdndActionCopy", 33 "XdndActionCopy",
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
68 ::Window xid_; 66 ::Window xid_;
69 67
70 // Not owned. 68 // Not owned.
71 TestDragDropClient* client_; 69 TestDragDropClient* client_;
72 70
73 std::vector<XClientMessageEvent> events_; 71 std::vector<XClientMessageEvent> events_;
74 72
75 DISALLOW_COPY_AND_ASSIGN(ClientMessageEventCollector); 73 DISALLOW_COPY_AND_ASSIGN(ClientMessageEventCollector);
76 }; 74 };
77 75
78 // An implementation of X11MoveLoop where RunMoveLoop() always starts the move
79 // loop.
80 class TestMoveLoop : public X11MoveLoop {
81 public:
82 explicit TestMoveLoop(X11MoveLoopDelegate* delegate);
83 virtual ~TestMoveLoop();
84
85 // Returns true if the move loop is running.
86 bool IsRunning() const;
87
88 // X11MoveLoop:
89 virtual bool RunMoveLoop(aura::Window* window,
90 gfx::NativeCursor cursor) OVERRIDE;
91 virtual void UpdateCursor(gfx::NativeCursor cursor) OVERRIDE;
92 virtual void EndMoveLoop() OVERRIDE;
93 virtual void SetDragImage(const gfx::ImageSkia& image,
94 const gfx::Vector2dF& offset) OVERRIDE;
95
96 private:
97 // Not owned.
98 X11MoveLoopDelegate* delegate_;
99
100 // Ends the move loop.
101 base::Closure quit_closure_;
102
103 bool is_running_;
104 };
105
106 // Implementation of DesktopDragDropClientAuraX11 which works with a fake 76 // Implementation of DesktopDragDropClientAuraX11 which works with a fake
107 // |DesktopDragDropClientAuraX11::source_current_window_|. 77 // |DesktopDragDropClientAuraX11::source_current_window_|.
108 class TestDragDropClient : public DesktopDragDropClientAuraX11 { 78 class TestDragDropClient : public DesktopDragDropClientAuraX11 {
109 public: 79 public:
110 // The location in screen coordinates used for the synthetic mouse moves 80 // The location in screen coordinates used for the synthetic mouse moves
111 // generated in SetTopmostXWindowAndMoveMouse(). 81 // generated in SetTopmostXWindowAndMoveMouse().
112 static const int kMouseMoveX; 82 static const int kMouseMoveX;
113 static const int kMouseMoveY; 83 static const int kMouseMoveY;
114 84
115 TestDragDropClient(aura::Window* window, 85 TestDragDropClient(aura::Window* window,
(...skipping 29 matching lines...) Expand all
145 bool accepted_drop, 115 bool accepted_drop,
146 ::Atom performed_action); 116 ::Atom performed_action);
147 117
148 // Sets |xid| as the topmost window at the current mouse position and 118 // Sets |xid| as the topmost window at the current mouse position and
149 // generates a synthetic mouse move. 119 // generates a synthetic mouse move.
150 void SetTopmostXWindowAndMoveMouse(::Window xid); 120 void SetTopmostXWindowAndMoveMouse(::Window xid);
151 121
152 // Returns true if the move loop is running. 122 // Returns true if the move loop is running.
153 bool IsMoveLoopRunning(); 123 bool IsMoveLoopRunning();
154 124
125 // DesktopDragDropClientAuraX11:
126 virtual int StartDragAndDrop(
127 const ui::OSExchangeData& data,
128 aura::Window* root_window,
129 aura::Window* source_window,
130 const gfx::Point& root_location,
131 int operation,
132 ui::DragDropTypes::DragEventSource source) OVERRIDE;
133 virtual void OnMoveLoopEnded() OVERRIDE;
134
155 private: 135 private:
156 // DesktopDragDropClientAuraX11: 136 // DesktopDragDropClientAuraX11:
157 virtual scoped_ptr<X11MoveLoop> CreateMoveLoop(
158 X11MoveLoopDelegate* delegate) OVERRIDE;
159 virtual ::Window FindWindowFor(const gfx::Point& screen_point) OVERRIDE; 137 virtual ::Window FindWindowFor(const gfx::Point& screen_point) OVERRIDE;
160 virtual void SendXClientEvent(::Window xid, XEvent* event) OVERRIDE; 138 virtual void SendXClientEvent(::Window xid, XEvent* event) OVERRIDE;
161 139
162 // The XID of the window which initiated the drag. 140 // The XID of the window which initiated the drag.
163 ::Window source_xid_; 141 ::Window source_xid_;
164 142
165 // The XID of the window which is simulated to be the topmost window at the 143 // The XID of the window which is simulated to be the topmost window at the
166 // current mouse position. 144 // current mouse position.
167 ::Window target_xid_; 145 ::Window target_xid_;
168 146
169 // The move loop. Not owned. 147 // Whether the move loop is running.
170 TestMoveLoop* loop_; 148 bool move_loop_running_;
171 149
172 // Map of ::Windows to the collector which intercepts XClientMessageEvents 150 // Map of ::Windows to the collector which intercepts XClientMessageEvents
173 // for that window. 151 // for that window.
174 std::map< ::Window, ClientMessageEventCollector*> collectors_; 152 std::map< ::Window, ClientMessageEventCollector*> collectors_;
175 153
176 ui::X11AtomCache atom_cache_; 154 ui::X11AtomCache atom_cache_;
177 155
178 DISALLOW_COPY_AND_ASSIGN(TestDragDropClient); 156 DISALLOW_COPY_AND_ASSIGN(TestDragDropClient);
179 }; 157 };
180 158
(...skipping 17 matching lines...) Expand all
198 to_return.swap(events_); 176 to_return.swap(events_);
199 return to_return; 177 return to_return;
200 } 178 }
201 179
202 void ClientMessageEventCollector::RecordEvent( 180 void ClientMessageEventCollector::RecordEvent(
203 const XClientMessageEvent& event) { 181 const XClientMessageEvent& event) {
204 events_.push_back(event); 182 events_.push_back(event);
205 } 183 }
206 184
207 /////////////////////////////////////////////////////////////////////////////// 185 ///////////////////////////////////////////////////////////////////////////////
208 // TestMoveLoop
209
210 TestMoveLoop::TestMoveLoop(X11MoveLoopDelegate* delegate)
211 : delegate_(delegate),
212 is_running_(false) {
213 }
214
215 TestMoveLoop::~TestMoveLoop() {
216 }
217
218 bool TestMoveLoop::IsRunning() const {
219 return is_running_;
220 }
221
222 bool TestMoveLoop::RunMoveLoop(
223 aura::Window* window,
224 gfx::NativeCursor cursor) {
225 is_running_ = true;
226 base::RunLoop run_loop;
227 quit_closure_ = run_loop.QuitClosure();
228 run_loop.Run();
229 return true;
230 }
231
232 void TestMoveLoop::UpdateCursor(gfx::NativeCursor cursor) {
233 }
234
235 void TestMoveLoop::EndMoveLoop() {
236 if (is_running_) {
237 delegate_->OnMoveLoopEnded();
238 is_running_ = false;
239 quit_closure_.Run();
240 }
241 }
242
243 void TestMoveLoop::SetDragImage(const gfx::ImageSkia& image,
244 const gfx::Vector2dF& offset) {
245 }
246
247 ///////////////////////////////////////////////////////////////////////////////
248 // TestDragDropClient 186 // TestDragDropClient
249 187
250 // static 188 // static
251 const int TestDragDropClient::kMouseMoveX = 100; 189 const int TestDragDropClient::kMouseMoveX = 100;
252 190
253 // static 191 // static
254 const int TestDragDropClient::kMouseMoveY = 200; 192 const int TestDragDropClient::kMouseMoveY = 200;
255 193
256 TestDragDropClient::TestDragDropClient( 194 TestDragDropClient::TestDragDropClient(
257 aura::Window* window, 195 aura::Window* window,
258 DesktopNativeCursorManager* cursor_manager) 196 DesktopNativeCursorManager* cursor_manager)
259 : DesktopDragDropClientAuraX11(window, 197 : DesktopDragDropClientAuraX11(window,
260 cursor_manager, 198 cursor_manager,
261 gfx::GetXDisplay(), 199 gfx::GetXDisplay(),
262 window->GetHost()->GetAcceleratedWidget()), 200 window->GetHost()->GetAcceleratedWidget()),
263 source_xid_(window->GetHost()->GetAcceleratedWidget()), 201 source_xid_(window->GetHost()->GetAcceleratedWidget()),
264 target_xid_(None), 202 target_xid_(None),
265 loop_(NULL), 203 move_loop_running_(false),
266 atom_cache_(gfx::GetXDisplay(), kAtomsToCache) { 204 atom_cache_(gfx::GetXDisplay(), kAtomsToCache) {
267 } 205 }
268 206
269 TestDragDropClient::~TestDragDropClient() { 207 TestDragDropClient::~TestDragDropClient() {
270 } 208 }
271 209
272 Atom TestDragDropClient::GetAtom(const char* name) { 210 Atom TestDragDropClient::GetAtom(const char* name) {
273 return atom_cache_.GetAtom(name); 211 return atom_cache_.GetAtom(name);
274 } 212 }
275 213
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after
321 target_xid_ = xid; 259 target_xid_ = xid;
322 260
323 XMotionEvent event; 261 XMotionEvent event;
324 event.time = CurrentTime; 262 event.time = CurrentTime;
325 event.x_root = kMouseMoveX; 263 event.x_root = kMouseMoveX;
326 event.y_root = kMouseMoveY; 264 event.y_root = kMouseMoveY;
327 OnMouseMovement(&event); 265 OnMouseMovement(&event);
328 } 266 }
329 267
330 bool TestDragDropClient::IsMoveLoopRunning() { 268 bool TestDragDropClient::IsMoveLoopRunning() {
331 return loop_->IsRunning(); 269 return move_loop_running_;
332 } 270 }
333 271
334 scoped_ptr<X11MoveLoop> TestDragDropClient::CreateMoveLoop( 272 int TestDragDropClient::StartDragAndDrop(
335 X11MoveLoopDelegate* delegate) { 273 const ui::OSExchangeData& data,
336 loop_ = new TestMoveLoop(delegate); 274 aura::Window* root_window,
337 return scoped_ptr<X11MoveLoop>(loop_); 275 aura::Window* source_window,
276 const gfx::Point& root_location,
277 int operation,
278 ui::DragDropTypes::DragEventSource source) {
279 move_loop_running_ = true;
280 return DesktopDragDropClientAuraX11::StartDragAndDrop(data, root_window,
281 source_window, root_location, operation, source);
282 }
283
284 void TestDragDropClient::OnMoveLoopEnded() {
285 DesktopDragDropClientAuraX11::OnMoveLoopEnded();
286 move_loop_running_ = false;
338 } 287 }
339 288
340 ::Window TestDragDropClient::FindWindowFor(const gfx::Point& screen_point) { 289 ::Window TestDragDropClient::FindWindowFor(const gfx::Point& screen_point) {
341 return target_xid_; 290 return target_xid_;
342 } 291 }
343 292
344 void TestDragDropClient::SendXClientEvent(::Window xid, XEvent* event) { 293 void TestDragDropClient::SendXClientEvent(::Window xid, XEvent* event) {
345 std::map< ::Window, ClientMessageEventCollector*>::iterator it = 294 std::map< ::Window, ClientMessageEventCollector*>::iterator it =
346 collectors_.find(xid); 295 collectors_.find(xid);
347 if (it != collectors_.end()) 296 if (it != collectors_.end())
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
382 params.native_widget = new DesktopNativeWidgetAura(widget_.get()); 331 params.native_widget = new DesktopNativeWidgetAura(widget_.get());
383 params.bounds = gfx::Rect(100, 100); 332 params.bounds = gfx::Rect(100, 100);
384 widget_->Init(params); 333 widget_->Init(params);
385 widget_->Show(); 334 widget_->Show();
386 335
387 cursor_manager_.reset(new DesktopNativeCursorManager( 336 cursor_manager_.reset(new DesktopNativeCursorManager(
388 DesktopCursorLoaderUpdater::Create())); 337 DesktopCursorLoaderUpdater::Create()));
389 338
390 client_.reset(new TestDragDropClient(widget_->GetNativeWindow(), 339 client_.reset(new TestDragDropClient(widget_->GetNativeWindow(),
391 cursor_manager_.get())); 340 cursor_manager_.get()));
392 client_->Init();
393 } 341 }
394 342
395 virtual void TearDown() OVERRIDE { 343 virtual void TearDown() OVERRIDE {
396 client_.reset(); 344 client_.reset();
397 cursor_manager_.reset(); 345 cursor_manager_.reset();
398 widget_.reset(); 346 widget_.reset();
399 ViewsTestBase::TearDown(); 347 ViewsTestBase::TearDown();
400 } 348 }
401 349
402 TestDragDropClient* client() { 350 TestDragDropClient* client() {
(...skipping 319 matching lines...) Expand 10 before | Expand all | Expand 10 after
722 670
723 // Repeat the test but reject the drop in the XdndFinished message instead. 671 // Repeat the test but reject the drop in the XdndFinished message instead.
724 base::MessageLoop::current()->PostTask( 672 base::MessageLoop::current()->PostTask(
725 FROM_HERE, 673 FROM_HERE,
726 base::Bind(&RejectAfterMouseReleaseStep3, client())); 674 base::Bind(&RejectAfterMouseReleaseStep3, client()));
727 result = StartDragAndDrop(); 675 result = StartDragAndDrop();
728 EXPECT_EQ(ui::DragDropTypes::DRAG_NONE, result); 676 EXPECT_EQ(ui::DragDropTypes::DRAG_NONE, result);
729 } 677 }
730 678
731 } // namespace views 679 } // namespace views
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698