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

Side by Side Diff: services/ui/ws/drag_controller_unittest.cc

Issue 2349973010: mus drag and drop: return the completed effect to the caller. (Closed)
Patch Set: Rename some effect_taken to action_taken for consistency. Created 4 years, 2 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 | « services/ui/ws/drag_controller.cc ('k') | services/ui/ws/drag_source.h » ('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 2016 The Chromium Authors. All rights reserved. 1 // Copyright 2016 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 "services/ui/ws/drag_controller.h" 5 #include "services/ui/ws/drag_controller.h"
6 6
7 #include "services/ui/ws/drag_source.h" 7 #include "services/ui/ws/drag_source.h"
8 #include "services/ui/ws/drag_target_connection.h" 8 #include "services/ui/ws/drag_target_connection.h"
9 #include "services/ui/ws/ids.h" 9 #include "services/ui/ws/ids.h"
10 #include "services/ui/ws/server_window.h" 10 #include "services/ui/ws/server_window.h"
(...skipping 161 matching lines...) Expand 10 before | Expand all | Expand 10 after
172 window ? window->window() : nullptr); 172 window ? window->window() : nullptr);
173 } 173 }
174 174
175 void OnTestWindowDestroyed(DragTestWindow* test_window) { 175 void OnTestWindowDestroyed(DragTestWindow* test_window) {
176 drag_operation_->OnWillDestroyDragTargetConnection(test_window); 176 drag_operation_->OnWillDestroyDragTargetConnection(test_window);
177 server_window_by_id_.erase(test_window->window()->id()); 177 server_window_by_id_.erase(test_window->window()->id());
178 connection_by_window_.erase(test_window->window()); 178 connection_by_window_.erase(test_window->window());
179 } 179 }
180 180
181 DragController* drag_operation() const { return drag_operation_.get(); } 181 DragController* drag_operation() const { return drag_operation_.get(); }
182
183 const base::Optional<uint32_t>& drag_completed_action() {
184 return drag_completed_action_;
185 }
182 const base::Optional<bool>& drag_completed_value() { 186 const base::Optional<bool>& drag_completed_value() {
183 return drag_completed_value_; 187 return drag_completed_value_;
184 } 188 }
185 189
186 private: 190 private:
187 // Overridden from testing::Test: 191 // Overridden from testing::Test:
188 void SetUp() override { 192 void SetUp() override {
189 testing::Test::SetUp(); 193 testing::Test::SetUp();
190 194
191 window_delegate_.reset(new TestServerWindowDelegate()); 195 window_delegate_.reset(new TestServerWindowDelegate());
192 root_window_.reset( 196 root_window_.reset(
193 new ServerWindow(window_delegate_.get(), WindowId(1, 2))); 197 new ServerWindow(window_delegate_.get(), WindowId(1, 2)));
194 window_delegate_->set_root_window(root_window_.get()); 198 window_delegate_->set_root_window(root_window_.get());
195 root_window_->SetVisible(true); 199 root_window_->SetVisible(true);
196 } 200 }
197 201
198 void TearDown() override { 202 void TearDown() override {
199 drag_operation_.reset(); 203 drag_operation_.reset();
200 root_window_.reset(); 204 root_window_.reset();
201 window_delegate_.reset(); 205 window_delegate_.reset();
202 206
203 DCHECK(server_window_by_id_.empty()); 207 DCHECK(server_window_by_id_.empty());
204 DCHECK(connection_by_window_.empty()); 208 DCHECK(connection_by_window_.empty());
205 209
206 testing::Test::TearDown(); 210 testing::Test::TearDown();
207 } 211 }
208 212
209 // Overridden from DragControllerSource: 213 // Overridden from DragControllerSource:
210 void OnDragCompleted(bool success) override { 214 void OnDragCompleted(bool success, uint32_t action_taken) override {
215 drag_completed_action_ = action_taken;
211 drag_completed_value_ = success; 216 drag_completed_value_ = success;
212 } 217 }
213 218
214 ServerWindow* GetWindowById(const WindowId& id) override { 219 ServerWindow* GetWindowById(const WindowId& id) override {
215 auto it = server_window_by_id_.find(id); 220 auto it = server_window_by_id_.find(id);
216 if (it == server_window_by_id_.end()) 221 if (it == server_window_by_id_.end())
217 return nullptr; 222 return nullptr;
218 return it->second; 223 return it->second;
219 } 224 }
220 225
221 DragTargetConnection* GetDragTargetForWindow( 226 DragTargetConnection* GetDragTargetForWindow(
222 const ServerWindow* window) override { 227 const ServerWindow* window) override {
223 auto it = connection_by_window_.find(const_cast<ServerWindow*>(window)); 228 auto it = connection_by_window_.find(const_cast<ServerWindow*>(window));
224 if (it == connection_by_window_.end()) 229 if (it == connection_by_window_.end())
225 return nullptr; 230 return nullptr;
226 return it->second; 231 return it->second;
227 } 232 }
228 233
229 int window_id_ = 3; 234 int window_id_ = 3;
230 235
231 std::map<WindowId, ServerWindow*> server_window_by_id_; 236 std::map<WindowId, ServerWindow*> server_window_by_id_;
232 std::map<ServerWindow*, DragTargetConnection*> connection_by_window_; 237 std::map<ServerWindow*, DragTargetConnection*> connection_by_window_;
233 238
234 std::unique_ptr<TestServerWindowDelegate> window_delegate_; 239 std::unique_ptr<TestServerWindowDelegate> window_delegate_;
235 std::unique_ptr<ServerWindow> root_window_; 240 std::unique_ptr<ServerWindow> root_window_;
236 241
237 std::unique_ptr<DragController> drag_operation_; 242 std::unique_ptr<DragController> drag_operation_;
238 243
244 base::Optional<uint32_t> drag_completed_action_;
239 base::Optional<bool> drag_completed_value_; 245 base::Optional<bool> drag_completed_value_;
240 }; 246 };
241 247
242 DragTestWindow::~DragTestWindow() { 248 DragTestWindow::~DragTestWindow() {
243 parent_->OnTestWindowDestroyed(this); 249 parent_->OnTestWindowDestroyed(this);
244 } 250 }
245 251
246 TEST_F(DragControllerTest, SimpleDragDrop) { 252 TEST_F(DragControllerTest, SimpleDragDrop) {
247 std::unique_ptr<DragTestWindow> window = BuildWindow(); 253 std::unique_ptr<DragTestWindow> window = BuildWindow();
248 mojo::Map<mojo::String, mojo::Array<uint8_t>> mime_data; 254 mojo::Map<mojo::String, mojo::Array<uint8_t>> mime_data;
249 StartDragOperation(std::move(mime_data), window.get(), 255 StartDragOperation(std::move(mime_data), window.get(),
250 ui::mojom::kDropEffectMove); 256 ui::mojom::kDropEffectMove);
251 257
252 DispatchDrag(window.get(), false, ui::EF_LEFT_MOUSE_BUTTON, gfx::Point(1, 1)); 258 DispatchDrag(window.get(), false, ui::EF_LEFT_MOUSE_BUTTON, gfx::Point(1, 1));
253 EXPECT_EQ(QueuedType::ENTER, window->queue_response_type()); 259 EXPECT_EQ(QueuedType::ENTER, window->queue_response_type());
254 window->Respond(true); 260 window->Respond(true);
255 261
256 DispatchDrag(window.get(), false, ui::EF_LEFT_MOUSE_BUTTON, gfx::Point(2, 2)); 262 DispatchDrag(window.get(), false, ui::EF_LEFT_MOUSE_BUTTON, gfx::Point(2, 2));
257 EXPECT_EQ(QueuedType::OVER, window->queue_response_type()); 263 EXPECT_EQ(QueuedType::OVER, window->queue_response_type());
258 window->Respond(true); 264 window->Respond(true);
259 265
260 DispatchDrag(window.get(), true, 0, gfx::Point(2, 2)); 266 DispatchDrag(window.get(), true, 0, gfx::Point(2, 2));
261 EXPECT_EQ(QueuedType::DROP, window->queue_response_type()); 267 EXPECT_EQ(QueuedType::DROP, window->queue_response_type());
262 window->Respond(true); 268 window->Respond(true);
263 269
270 EXPECT_EQ(ui::mojom::kDropEffectMove,
271 drag_completed_action().value_or(ui::mojom::kDropEffectNone));
264 EXPECT_TRUE(drag_completed_value().value_or(false)); 272 EXPECT_TRUE(drag_completed_value().value_or(false));
265 } 273 }
266 274
275 TEST_F(DragControllerTest, FailsOnWindowSayingNo) {
276 std::unique_ptr<DragTestWindow> window = BuildWindow();
277 mojo::Map<mojo::String, mojo::Array<uint8_t>> mime_data;
278 StartDragOperation(std::move(mime_data), window.get(),
279 ui::mojom::kDropEffectMove);
280
281 DispatchDrag(window.get(), false, ui::EF_LEFT_MOUSE_BUTTON, gfx::Point(1, 1));
282 EXPECT_EQ(QueuedType::ENTER, window->queue_response_type());
283 window->Respond(true);
284
285 DispatchDrag(window.get(), false, ui::EF_LEFT_MOUSE_BUTTON, gfx::Point(2, 2));
286 EXPECT_EQ(QueuedType::OVER, window->queue_response_type());
287 window->Respond(true);
288
289 DispatchDrag(window.get(), true, 0, gfx::Point(2, 2));
290 EXPECT_EQ(QueuedType::DROP, window->queue_response_type());
291
292 // Unlike SimpleDragDrop, respond with kDropEffectNone, which should make the
293 // drag fail.
294 window->Respond(false);
295
296 EXPECT_EQ(ui::mojom::kDropEffectNone,
297 drag_completed_action().value_or(ui::mojom::kDropEffectCopy));
298 EXPECT_FALSE(drag_completed_value().value_or(true));
299 }
300
267 TEST_F(DragControllerTest, OnlyDeliverMimeDataOnce) { 301 TEST_F(DragControllerTest, OnlyDeliverMimeDataOnce) {
268 std::unique_ptr<DragTestWindow> window1 = BuildWindow(); 302 std::unique_ptr<DragTestWindow> window1 = BuildWindow();
269 std::unique_ptr<DragTestWindow> window2 = BuildWindow(); 303 std::unique_ptr<DragTestWindow> window2 = BuildWindow();
270 mojo::Map<mojo::String, mojo::Array<uint8_t>> mime_data; 304 mojo::Map<mojo::String, mojo::Array<uint8_t>> mime_data;
271 305
272 // The client lib is responsible for sending the data to the window that's 306 // The client lib is responsible for sending the data to the window that's
273 // the drag source to minimize IPC. 307 // the drag source to minimize IPC.
274 EXPECT_EQ(0u, window1->times_received_drag_drop_start()); 308 EXPECT_EQ(0u, window1->times_received_drag_drop_start());
275 StartDragOperation(std::move(mime_data), window1.get(), 309 StartDragOperation(std::move(mime_data), window1.get(),
276 ui::mojom::kDropEffectMove); 310 ui::mojom::kDropEffectMove);
(...skipping 297 matching lines...) Expand 10 before | Expand all | Expand 10 after
574 gfx::Point(1, 1)); 608 gfx::Point(1, 1));
575 ASSERT_EQ(0u, window->queue_size()); 609 ASSERT_EQ(0u, window->queue_size());
576 } 610 }
577 611
578 // TODO(erg): Add a test to ensure windows that the cursor isn't over 612 // TODO(erg): Add a test to ensure windows that the cursor isn't over
579 // responding to messages don't change the cursor when we have cursor handling 613 // responding to messages don't change the cursor when we have cursor handling
580 // code. 614 // code.
581 615
582 } // namespace ws 616 } // namespace ws
583 } // namespace ui 617 } // namespace ui
OLDNEW
« no previous file with comments | « services/ui/ws/drag_controller.cc ('k') | services/ui/ws/drag_source.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698