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

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

Issue 2784663003: mus: Rename mojom::Cursor to mojom::CursorType. (Closed)
Patch Set: Created 3 years, 8 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/event_dispatcher.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 <map> 7 #include <map>
8 #include <memory> 8 #include <memory>
9 #include <queue> 9 #include <queue>
10 #include <utility> 10 #include <utility>
(...skipping 144 matching lines...) Expand 10 before | Expand all | Expand 10 after
155 window->PerformOnDragDropStart( 155 window->PerformOnDragDropStart(
156 std::unordered_map<std::string, std::vector<uint8_t>>()); 156 std::unordered_map<std::string, std::vector<uint8_t>>());
157 drag_operation_ = base::MakeUnique<DragController>( 157 drag_operation_ = base::MakeUnique<DragController>(
158 this, this, window->window(), window, PointerEvent::kMousePointerId, 158 this, this, window->window(), window, PointerEvent::kMousePointerId,
159 std::unordered_map<std::string, std::vector<uint8_t>>(), 159 std::unordered_map<std::string, std::vector<uint8_t>>(),
160 drag_operations); 160 drag_operations);
161 161
162 // It would be nice if we could just let the observer method fire, but it 162 // It would be nice if we could just let the observer method fire, but it
163 // fires during the constructor when we haven't assigned the unique_ptr 163 // fires during the constructor when we haven't assigned the unique_ptr
164 // yet. 164 // yet.
165 cursor_ = ui::mojom::Cursor(drag_operation_->current_cursor()); 165 cursor_ = ui::mojom::CursorType(drag_operation_->current_cursor());
166 } 166 }
167 167
168 void DispatchDrag(DragTestWindow* window, 168 void DispatchDrag(DragTestWindow* window,
169 bool mouse_released, 169 bool mouse_released,
170 uint32_t flags, 170 uint32_t flags,
171 const gfx::Point& position) { 171 const gfx::Point& position) {
172 ui::PointerEvent event( 172 ui::PointerEvent event(
173 ui::MouseEvent(mouse_released ? ET_MOUSE_RELEASED : ET_MOUSE_PRESSED, 173 ui::MouseEvent(mouse_released ? ET_MOUSE_RELEASED : ET_MOUSE_PRESSED,
174 position, position, ui::EventTimeForNow(), flags, 0)); 174 position, position, ui::EventTimeForNow(), flags, 0));
175 drag_operation_->DispatchPointerEvent(event, 175 drag_operation_->DispatchPointerEvent(event,
(...skipping 21 matching lines...) Expand all
197 197
198 DragController* drag_operation() const { return drag_operation_.get(); } 198 DragController* drag_operation() const { return drag_operation_.get(); }
199 199
200 const base::Optional<uint32_t>& drag_completed_action() { 200 const base::Optional<uint32_t>& drag_completed_action() {
201 return drag_completed_action_; 201 return drag_completed_action_;
202 } 202 }
203 const base::Optional<bool>& drag_completed_value() { 203 const base::Optional<bool>& drag_completed_value() {
204 return drag_completed_value_; 204 return drag_completed_value_;
205 } 205 }
206 206
207 ui::mojom::Cursor cursor() { return cursor_; } 207 ui::mojom::CursorType cursor() { return cursor_; }
208 208
209 private: 209 private:
210 // Overridden from testing::Test: 210 // Overridden from testing::Test:
211 void SetUp() override { 211 void SetUp() override {
212 testing::Test::SetUp(); 212 testing::Test::SetUp();
213 213
214 window_delegate_ = base::MakeUnique<TestServerWindowDelegate>(); 214 window_delegate_ = base::MakeUnique<TestServerWindowDelegate>();
215 root_window_ = 215 root_window_ =
216 base::MakeUnique<ServerWindow>(window_delegate_.get(), WindowId(1, 2)); 216 base::MakeUnique<ServerWindow>(window_delegate_.get(), WindowId(1, 2));
217 window_delegate_->set_root_window(root_window_.get()); 217 window_delegate_->set_root_window(root_window_.get());
218 root_window_->SetVisible(true); 218 root_window_->SetVisible(true);
219 } 219 }
220 220
221 void TearDown() override { 221 void TearDown() override {
222 drag_operation_.reset(); 222 drag_operation_.reset();
223 root_window_.reset(); 223 root_window_.reset();
224 window_delegate_.reset(); 224 window_delegate_.reset();
225 225
226 DCHECK(server_window_by_id_.empty()); 226 DCHECK(server_window_by_id_.empty());
227 DCHECK(connection_by_window_.empty()); 227 DCHECK(connection_by_window_.empty());
228 228
229 testing::Test::TearDown(); 229 testing::Test::TearDown();
230 } 230 }
231 231
232 // Overridden from DragCursorUpdater: 232 // Overridden from DragCursorUpdater:
233 void OnDragCursorUpdated() override { 233 void OnDragCursorUpdated() override {
234 if (drag_operation_) 234 if (drag_operation_)
235 cursor_ = ui::mojom::Cursor(drag_operation_->current_cursor()); 235 cursor_ = ui::mojom::CursorType(drag_operation_->current_cursor());
236 } 236 }
237 237
238 // Overridden from DragControllerSource: 238 // Overridden from DragControllerSource:
239 void OnDragMoved(const gfx::Point& location) override {} 239 void OnDragMoved(const gfx::Point& location) override {}
240 240
241 void OnDragCompleted(bool success, uint32_t action_taken) override { 241 void OnDragCompleted(bool success, uint32_t action_taken) override {
242 drag_completed_action_ = action_taken; 242 drag_completed_action_ = action_taken;
243 drag_completed_value_ = success; 243 drag_completed_value_ = success;
244 } 244 }
245 245
246 ServerWindow* GetWindowById(const WindowId& id) override { 246 ServerWindow* GetWindowById(const WindowId& id) override {
247 auto it = server_window_by_id_.find(id); 247 auto it = server_window_by_id_.find(id);
248 if (it == server_window_by_id_.end()) 248 if (it == server_window_by_id_.end())
249 return nullptr; 249 return nullptr;
250 return it->second; 250 return it->second;
251 } 251 }
252 252
253 DragTargetConnection* GetDragTargetForWindow( 253 DragTargetConnection* GetDragTargetForWindow(
254 const ServerWindow* window) override { 254 const ServerWindow* window) override {
255 auto it = connection_by_window_.find(const_cast<ServerWindow*>(window)); 255 auto it = connection_by_window_.find(const_cast<ServerWindow*>(window));
256 if (it == connection_by_window_.end()) 256 if (it == connection_by_window_.end())
257 return nullptr; 257 return nullptr;
258 return it->second; 258 return it->second;
259 } 259 }
260 260
261 int window_id_ = 3; 261 int window_id_ = 3;
262 262
263 ui::mojom::Cursor cursor_; 263 ui::mojom::CursorType cursor_;
264 264
265 std::map<WindowId, ServerWindow*> server_window_by_id_; 265 std::map<WindowId, ServerWindow*> server_window_by_id_;
266 std::map<ServerWindow*, DragTargetConnection*> connection_by_window_; 266 std::map<ServerWindow*, DragTargetConnection*> connection_by_window_;
267 267
268 std::unique_ptr<TestServerWindowDelegate> window_delegate_; 268 std::unique_ptr<TestServerWindowDelegate> window_delegate_;
269 std::unique_ptr<ServerWindow> root_window_; 269 std::unique_ptr<ServerWindow> root_window_;
270 270
271 std::unique_ptr<DragController> drag_operation_; 271 std::unique_ptr<DragController> drag_operation_;
272 272
273 base::Optional<uint32_t> drag_completed_action_; 273 base::Optional<uint32_t> drag_completed_action_;
274 base::Optional<bool> drag_completed_value_; 274 base::Optional<bool> drag_completed_value_;
275 }; 275 };
276 276
277 DragTestWindow::~DragTestWindow() { 277 DragTestWindow::~DragTestWindow() {
278 parent_->OnTestWindowDestroyed(this); 278 parent_->OnTestWindowDestroyed(this);
279 } 279 }
280 280
281 TEST_F(DragControllerTest, SimpleDragDrop) { 281 TEST_F(DragControllerTest, SimpleDragDrop) {
282 std::unique_ptr<DragTestWindow> window = BuildWindow(); 282 std::unique_ptr<DragTestWindow> window = BuildWindow();
283 StartDragOperation(window.get(), ui::mojom::kDropEffectMove); 283 StartDragOperation(window.get(), ui::mojom::kDropEffectMove);
284 284
285 EXPECT_EQ(ui::mojom::Cursor::NO_DROP, cursor()); 285 EXPECT_EQ(ui::mojom::CursorType::NO_DROP, cursor());
286 286
287 DispatchDrag(window.get(), false, ui::EF_LEFT_MOUSE_BUTTON, gfx::Point(1, 1)); 287 DispatchDrag(window.get(), false, ui::EF_LEFT_MOUSE_BUTTON, gfx::Point(1, 1));
288 EXPECT_EQ(QueuedType::ENTER, window->queue_response_type()); 288 EXPECT_EQ(QueuedType::ENTER, window->queue_response_type());
289 window->Respond(true); 289 window->Respond(true);
290 290
291 // (Even though we're doing a move, the cursor name is COPY.) 291 // (Even though we're doing a move, the cursor name is COPY.)
292 EXPECT_EQ(ui::mojom::Cursor::COPY, cursor()); 292 EXPECT_EQ(ui::mojom::CursorType::COPY, cursor());
293 293
294 DispatchDrag(window.get(), false, ui::EF_LEFT_MOUSE_BUTTON, gfx::Point(2, 2)); 294 DispatchDrag(window.get(), false, ui::EF_LEFT_MOUSE_BUTTON, gfx::Point(2, 2));
295 EXPECT_EQ(QueuedType::OVER, window->queue_response_type()); 295 EXPECT_EQ(QueuedType::OVER, window->queue_response_type());
296 window->Respond(true); 296 window->Respond(true);
297 297
298 DispatchDrag(window.get(), true, 0, gfx::Point(2, 2)); 298 DispatchDrag(window.get(), true, 0, gfx::Point(2, 2));
299 EXPECT_EQ(QueuedType::DROP, window->queue_response_type()); 299 EXPECT_EQ(QueuedType::DROP, window->queue_response_type());
300 window->Respond(true); 300 window->Respond(true);
301 301
302 EXPECT_EQ(ui::mojom::kDropEffectMove, 302 EXPECT_EQ(ui::mojom::kDropEffectMove,
(...skipping 228 matching lines...) Expand 10 before | Expand all | Expand 10 after
531 EXPECT_EQ(nullptr, api.GetCurrentTarget()); 531 EXPECT_EQ(nullptr, api.GetCurrentTarget());
532 532
533 // But a target window closing out from under us doesn't fail the drag. 533 // But a target window closing out from under us doesn't fail the drag.
534 EXPECT_FALSE(drag_completed_value().has_value()); 534 EXPECT_FALSE(drag_completed_value().has_value());
535 } 535 }
536 536
537 TEST_F(DragControllerTest, TargetWindowClosedResetsCursor) { 537 TEST_F(DragControllerTest, TargetWindowClosedResetsCursor) {
538 std::unique_ptr<DragTestWindow> window1 = BuildWindow(); 538 std::unique_ptr<DragTestWindow> window1 = BuildWindow();
539 std::unique_ptr<DragTestWindow> window2 = BuildWindow(); 539 std::unique_ptr<DragTestWindow> window2 = BuildWindow();
540 StartDragOperation(window1.get(), ui::mojom::kDropEffectMove); 540 StartDragOperation(window1.get(), ui::mojom::kDropEffectMove);
541 EXPECT_EQ(ui::mojom::Cursor::NO_DROP, cursor()); 541 EXPECT_EQ(ui::mojom::CursorType::NO_DROP, cursor());
542 542
543 // Send some events to |window|. 543 // Send some events to |window|.
544 DispatchDrag(window2.get(), false, ui::EF_LEFT_MOUSE_BUTTON, 544 DispatchDrag(window2.get(), false, ui::EF_LEFT_MOUSE_BUTTON,
545 gfx::Point(1, 1)); 545 gfx::Point(1, 1));
546 EXPECT_EQ(QueuedType::ENTER, window2->queue_response_type()); 546 EXPECT_EQ(QueuedType::ENTER, window2->queue_response_type());
547 window2->Respond(true); 547 window2->Respond(true);
548 DispatchDrag(window2.get(), false, ui::EF_LEFT_MOUSE_BUTTON, 548 DispatchDrag(window2.get(), false, ui::EF_LEFT_MOUSE_BUTTON,
549 gfx::Point(1, 1)); 549 gfx::Point(1, 1));
550 window2->Respond(true); 550 window2->Respond(true);
551 EXPECT_EQ(ui::mojom::Cursor::COPY, cursor()); 551 EXPECT_EQ(ui::mojom::CursorType::COPY, cursor());
552 552
553 // Force the destruction of |window.window|. 553 // Force the destruction of |window.window|.
554 window2.reset(); 554 window2.reset();
555 555
556 // The cursor no loner indicates that it can drop on |window2|. 556 // The cursor no loner indicates that it can drop on |window2|.
557 EXPECT_EQ(ui::mojom::Cursor::NO_DROP, cursor()); 557 EXPECT_EQ(ui::mojom::CursorType::NO_DROP, cursor());
558 } 558 }
559 559
560 TEST_F(DragControllerTest, SourceWindowClosedWhileDrag) { 560 TEST_F(DragControllerTest, SourceWindowClosedWhileDrag) {
561 std::unique_ptr<DragTestWindow> window1 = BuildWindow(); 561 std::unique_ptr<DragTestWindow> window1 = BuildWindow();
562 std::unique_ptr<DragTestWindow> window2 = BuildWindow(); 562 std::unique_ptr<DragTestWindow> window2 = BuildWindow();
563 StartDragOperation(window1.get(), ui::mojom::kDropEffectMove); 563 StartDragOperation(window1.get(), ui::mojom::kDropEffectMove);
564 564
565 test::DragControllerTestApi api(drag_operation()); 565 test::DragControllerTestApi api(drag_operation());
566 566
567 // Send some events to |windoww|. 567 // Send some events to |windoww|.
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after
633 // Ignore events from pointer 5. 633 // Ignore events from pointer 5.
634 DispatchDragWithPointer(window.get(), 5, false, ui::EF_LEFT_MOUSE_BUTTON, 634 DispatchDragWithPointer(window.get(), 5, false, ui::EF_LEFT_MOUSE_BUTTON,
635 gfx::Point(1, 1)); 635 gfx::Point(1, 1));
636 ASSERT_EQ(0u, window->queue_size()); 636 ASSERT_EQ(0u, window->queue_size());
637 } 637 }
638 638
639 TEST_F(DragControllerTest, RejectingWindowHasProperCursor) { 639 TEST_F(DragControllerTest, RejectingWindowHasProperCursor) {
640 std::unique_ptr<DragTestWindow> window = BuildWindow(); 640 std::unique_ptr<DragTestWindow> window = BuildWindow();
641 StartDragOperation(window.get(), ui::mojom::kDropEffectMove); 641 StartDragOperation(window.get(), ui::mojom::kDropEffectMove);
642 642
643 EXPECT_EQ(ui::mojom::Cursor::NO_DROP, cursor()); 643 EXPECT_EQ(ui::mojom::CursorType::NO_DROP, cursor());
644 644
645 DispatchDrag(window.get(), false, ui::EF_LEFT_MOUSE_BUTTON, gfx::Point(1, 1)); 645 DispatchDrag(window.get(), false, ui::EF_LEFT_MOUSE_BUTTON, gfx::Point(1, 1));
646 EXPECT_EQ(QueuedType::ENTER, window->queue_response_type()); 646 EXPECT_EQ(QueuedType::ENTER, window->queue_response_type());
647 window->Respond(true); 647 window->Respond(true);
648 648
649 EXPECT_EQ(ui::mojom::Cursor::COPY, cursor()); 649 EXPECT_EQ(ui::mojom::CursorType::COPY, cursor());
650 650
651 DispatchDrag(window.get(), false, ui::EF_LEFT_MOUSE_BUTTON, gfx::Point(2, 2)); 651 DispatchDrag(window.get(), false, ui::EF_LEFT_MOUSE_BUTTON, gfx::Point(2, 2));
652 EXPECT_EQ(QueuedType::OVER, window->queue_response_type()); 652 EXPECT_EQ(QueuedType::OVER, window->queue_response_type());
653 653
654 // At this point, we respond with no available drag actions at this pixel. 654 // At this point, we respond with no available drag actions at this pixel.
655 window->Respond(false); 655 window->Respond(false);
656 EXPECT_EQ(ui::mojom::Cursor::NO_DROP, cursor()); 656 EXPECT_EQ(ui::mojom::CursorType::NO_DROP, cursor());
657 } 657 }
658 658
659 TEST_F(DragControllerTest, ResopnseFromOtherWindowDoesntChangeCursor) { 659 TEST_F(DragControllerTest, ResopnseFromOtherWindowDoesntChangeCursor) {
660 std::unique_ptr<DragTestWindow> window1 = BuildWindow(); 660 std::unique_ptr<DragTestWindow> window1 = BuildWindow();
661 std::unique_ptr<DragTestWindow> window2 = BuildWindow(); 661 std::unique_ptr<DragTestWindow> window2 = BuildWindow();
662 StartDragOperation(window1.get(), ui::mojom::kDropEffectMove); 662 StartDragOperation(window1.get(), ui::mojom::kDropEffectMove);
663 663
664 // Send some events to |window2|. 664 // Send some events to |window2|.
665 DispatchDrag(window2.get(), false, ui::EF_LEFT_MOUSE_BUTTON, 665 DispatchDrag(window2.get(), false, ui::EF_LEFT_MOUSE_BUTTON,
666 gfx::Point(1, 1)); 666 gfx::Point(1, 1));
667 EXPECT_EQ(QueuedType::ENTER, window2->queue_response_type()); 667 EXPECT_EQ(QueuedType::ENTER, window2->queue_response_type());
668 DispatchDrag(window2.get(), false, ui::EF_LEFT_MOUSE_BUTTON, 668 DispatchDrag(window2.get(), false, ui::EF_LEFT_MOUSE_BUTTON,
669 gfx::Point(1, 1)); 669 gfx::Point(1, 1));
670 670
671 EXPECT_EQ(ui::mojom::Cursor::NO_DROP, cursor()); 671 EXPECT_EQ(ui::mojom::CursorType::NO_DROP, cursor());
672 672
673 // Now enter |window1|, and respond. 673 // Now enter |window1|, and respond.
674 DispatchDrag(window1.get(), false, ui::EF_LEFT_MOUSE_BUTTON, 674 DispatchDrag(window1.get(), false, ui::EF_LEFT_MOUSE_BUTTON,
675 gfx::Point(5, 5)); 675 gfx::Point(5, 5));
676 EXPECT_EQ(QueuedType::ENTER, window1->queue_response_type()); 676 EXPECT_EQ(QueuedType::ENTER, window1->queue_response_type());
677 window1->Respond(true); 677 window1->Respond(true);
678 678
679 EXPECT_EQ(ui::mojom::Cursor::COPY, cursor()); 679 EXPECT_EQ(ui::mojom::CursorType::COPY, cursor());
680 680
681 // Window 2 responding negatively to its queued messages shouldn't change the 681 // Window 2 responding negatively to its queued messages shouldn't change the
682 // cursor. 682 // cursor.
683 window2->Respond(false); 683 window2->Respond(false);
684 684
685 EXPECT_EQ(ui::mojom::Cursor::COPY, cursor()); 685 EXPECT_EQ(ui::mojom::CursorType::COPY, cursor());
686 } 686 }
687 687
688 } // namespace ws 688 } // namespace ws
689 } // namespace ui 689 } // namespace ui
OLDNEW
« no previous file with comments | « services/ui/ws/drag_controller.cc ('k') | services/ui/ws/event_dispatcher.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698