| OLD | NEW |
| 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 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 72 queued_callbacks_.front().callback.Run( | 72 queued_callbacks_.front().callback.Run( |
| 73 respond_with_effect ? queued_callbacks_.front().effect_bitmask : 0); | 73 respond_with_effect ? queued_callbacks_.front().effect_bitmask : 0); |
| 74 } | 74 } |
| 75 | 75 |
| 76 queued_callbacks_.pop(); | 76 queued_callbacks_.pop(); |
| 77 } | 77 } |
| 78 } | 78 } |
| 79 | 79 |
| 80 // Overridden from DragTestConnection: | 80 // Overridden from DragTestConnection: |
| 81 void PerformOnDragDropStart( | 81 void PerformOnDragDropStart( |
| 82 mojo::Map<mojo::String, mojo::Array<uint8_t>> mime_data) override { | 82 std::unordered_map<std::string, std::vector<uint8_t>> mime_data) |
| 83 override { |
| 83 times_received_drag_drop_start_++; | 84 times_received_drag_drop_start_++; |
| 84 mime_data_ = std::move(mime_data); | 85 mime_data_ = std::move(mime_data); |
| 85 } | 86 } |
| 86 | 87 |
| 87 void PerformOnDragEnter( | 88 void PerformOnDragEnter( |
| 88 const ServerWindow* window, | 89 const ServerWindow* window, |
| 89 uint32_t key_state, | 90 uint32_t key_state, |
| 90 const gfx::Point& cursor_offset, | 91 const gfx::Point& cursor_offset, |
| 91 uint32_t effect_bitmask, | 92 uint32_t effect_bitmask, |
| 92 const base::Callback<void(uint32_t)>& callback) override { | 93 const base::Callback<void(uint32_t)>& callback) override { |
| (...skipping 23 matching lines...) Expand all Loading... |
| 116 const ServerWindow* window, | 117 const ServerWindow* window, |
| 117 uint32_t key_state, | 118 uint32_t key_state, |
| 118 const gfx::Point& cursor_offset, | 119 const gfx::Point& cursor_offset, |
| 119 uint32_t effect_bitmask, | 120 uint32_t effect_bitmask, |
| 120 const base::Callback<void(uint32_t)>& callback) override { | 121 const base::Callback<void(uint32_t)>& callback) override { |
| 121 DCHECK_EQ(window, &window_); | 122 DCHECK_EQ(window, &window_); |
| 122 queued_callbacks_.push( | 123 queued_callbacks_.push( |
| 123 {QueuedType::DROP, key_state, cursor_offset, effect_bitmask, callback}); | 124 {QueuedType::DROP, key_state, cursor_offset, effect_bitmask, callback}); |
| 124 } | 125 } |
| 125 | 126 |
| 126 void PerformOnDragDropDone() override { mime_data_.SetToEmpty(); } | 127 void PerformOnDragDropDone() override { mime_data_.clear(); } |
| 127 | 128 |
| 128 private: | 129 private: |
| 129 DragControllerTest* parent_; | 130 DragControllerTest* parent_; |
| 130 TestServerWindowDelegate window_delegate_; | 131 TestServerWindowDelegate window_delegate_; |
| 131 ServerWindow window_; | 132 ServerWindow window_; |
| 132 mojo::Map<mojo::String, mojo::Array<uint8_t>> mime_data_; | 133 std::unordered_map<std::string, std::vector<uint8_t>> mime_data_; |
| 133 uint32_t times_received_drag_drop_start_ = 0; | 134 uint32_t times_received_drag_drop_start_ = 0; |
| 134 | 135 |
| 135 std::queue<DragEvent> queued_callbacks_; | 136 std::queue<DragEvent> queued_callbacks_; |
| 136 }; | 137 }; |
| 137 | 138 |
| 138 class DragControllerTest : public testing::Test, | 139 class DragControllerTest : public testing::Test, |
| 139 public DragCursorUpdater, | 140 public DragCursorUpdater, |
| 140 public DragSource { | 141 public DragSource { |
| 141 public: | 142 public: |
| 142 std::unique_ptr<DragTestWindow> BuildWindow() { | 143 std::unique_ptr<DragTestWindow> BuildWindow() { |
| 143 WindowId id(1, ++window_id_); | 144 WindowId id(1, ++window_id_); |
| 144 std::unique_ptr<DragTestWindow> p = | 145 std::unique_ptr<DragTestWindow> p = |
| 145 base::MakeUnique<DragTestWindow>(this, id); | 146 base::MakeUnique<DragTestWindow>(this, id); |
| 146 server_window_by_id_[id] = p->window(); | 147 server_window_by_id_[id] = p->window(); |
| 147 connection_by_window_[p->window()] = p.get(); | 148 connection_by_window_[p->window()] = p.get(); |
| 148 return p; | 149 return p; |
| 149 } | 150 } |
| 150 | 151 |
| 151 void StartDragOperation( | 152 void StartDragOperation( |
| 152 mojo::Map<mojo::String, mojo::Array<uint8_t>> mime_data, | |
| 153 DragTestWindow* window, | 153 DragTestWindow* window, |
| 154 uint32_t drag_operations) { | 154 uint32_t drag_operations) { |
| 155 window->PerformOnDragDropStart(mime_data.Clone()); | 155 window->PerformOnDragDropStart( |
| 156 std::unordered_map<std::string, std::vector<uint8_t>>()); |
| 156 drag_operation_ = base::MakeUnique<DragController>( | 157 drag_operation_ = base::MakeUnique<DragController>( |
| 157 this, this, window->window(), window, PointerEvent::kMousePointerId, | 158 this, this, window->window(), window, PointerEvent::kMousePointerId, |
| 158 std::move(mime_data), drag_operations); | 159 std::unordered_map<std::string, std::vector<uint8_t>>(), |
| 160 drag_operations); |
| 159 | 161 |
| 160 // 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 |
| 161 // 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 |
| 162 // yet. | 164 // yet. |
| 163 cursor_ = ui::mojom::Cursor(drag_operation_->current_cursor()); | 165 cursor_ = ui::mojom::Cursor(drag_operation_->current_cursor()); |
| 164 } | 166 } |
| 165 | 167 |
| 166 void DispatchDrag(DragTestWindow* window, | 168 void DispatchDrag(DragTestWindow* window, |
| 167 bool mouse_released, | 169 bool mouse_released, |
| 168 uint32_t flags, | 170 uint32_t flags, |
| (...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 268 base::Optional<uint32_t> drag_completed_action_; | 270 base::Optional<uint32_t> drag_completed_action_; |
| 269 base::Optional<bool> drag_completed_value_; | 271 base::Optional<bool> drag_completed_value_; |
| 270 }; | 272 }; |
| 271 | 273 |
| 272 DragTestWindow::~DragTestWindow() { | 274 DragTestWindow::~DragTestWindow() { |
| 273 parent_->OnTestWindowDestroyed(this); | 275 parent_->OnTestWindowDestroyed(this); |
| 274 } | 276 } |
| 275 | 277 |
| 276 TEST_F(DragControllerTest, SimpleDragDrop) { | 278 TEST_F(DragControllerTest, SimpleDragDrop) { |
| 277 std::unique_ptr<DragTestWindow> window = BuildWindow(); | 279 std::unique_ptr<DragTestWindow> window = BuildWindow(); |
| 278 mojo::Map<mojo::String, mojo::Array<uint8_t>> mime_data; | 280 StartDragOperation(window.get(), ui::mojom::kDropEffectMove); |
| 279 StartDragOperation(std::move(mime_data), window.get(), | |
| 280 ui::mojom::kDropEffectMove); | |
| 281 | 281 |
| 282 EXPECT_EQ(ui::mojom::Cursor::NO_DROP, cursor()); | 282 EXPECT_EQ(ui::mojom::Cursor::NO_DROP, cursor()); |
| 283 | 283 |
| 284 DispatchDrag(window.get(), false, ui::EF_LEFT_MOUSE_BUTTON, gfx::Point(1, 1)); | 284 DispatchDrag(window.get(), false, ui::EF_LEFT_MOUSE_BUTTON, gfx::Point(1, 1)); |
| 285 EXPECT_EQ(QueuedType::ENTER, window->queue_response_type()); | 285 EXPECT_EQ(QueuedType::ENTER, window->queue_response_type()); |
| 286 window->Respond(true); | 286 window->Respond(true); |
| 287 | 287 |
| 288 // (Even though we're doing a move, the cursor name is COPY.) | 288 // (Even though we're doing a move, the cursor name is COPY.) |
| 289 EXPECT_EQ(ui::mojom::Cursor::COPY, cursor()); | 289 EXPECT_EQ(ui::mojom::Cursor::COPY, cursor()); |
| 290 | 290 |
| 291 DispatchDrag(window.get(), false, ui::EF_LEFT_MOUSE_BUTTON, gfx::Point(2, 2)); | 291 DispatchDrag(window.get(), false, ui::EF_LEFT_MOUSE_BUTTON, gfx::Point(2, 2)); |
| 292 EXPECT_EQ(QueuedType::OVER, window->queue_response_type()); | 292 EXPECT_EQ(QueuedType::OVER, window->queue_response_type()); |
| 293 window->Respond(true); | 293 window->Respond(true); |
| 294 | 294 |
| 295 DispatchDrag(window.get(), true, 0, gfx::Point(2, 2)); | 295 DispatchDrag(window.get(), true, 0, gfx::Point(2, 2)); |
| 296 EXPECT_EQ(QueuedType::DROP, window->queue_response_type()); | 296 EXPECT_EQ(QueuedType::DROP, window->queue_response_type()); |
| 297 window->Respond(true); | 297 window->Respond(true); |
| 298 | 298 |
| 299 EXPECT_EQ(ui::mojom::kDropEffectMove, | 299 EXPECT_EQ(ui::mojom::kDropEffectMove, |
| 300 drag_completed_action().value_or(ui::mojom::kDropEffectNone)); | 300 drag_completed_action().value_or(ui::mojom::kDropEffectNone)); |
| 301 EXPECT_TRUE(drag_completed_value().value_or(false)); | 301 EXPECT_TRUE(drag_completed_value().value_or(false)); |
| 302 } | 302 } |
| 303 | 303 |
| 304 TEST_F(DragControllerTest, FailsOnWindowSayingNo) { | 304 TEST_F(DragControllerTest, FailsOnWindowSayingNo) { |
| 305 std::unique_ptr<DragTestWindow> window = BuildWindow(); | 305 std::unique_ptr<DragTestWindow> window = BuildWindow(); |
| 306 mojo::Map<mojo::String, mojo::Array<uint8_t>> mime_data; | 306 StartDragOperation(window.get(), ui::mojom::kDropEffectMove); |
| 307 StartDragOperation(std::move(mime_data), window.get(), | |
| 308 ui::mojom::kDropEffectMove); | |
| 309 | 307 |
| 310 DispatchDrag(window.get(), false, ui::EF_LEFT_MOUSE_BUTTON, gfx::Point(1, 1)); | 308 DispatchDrag(window.get(), false, ui::EF_LEFT_MOUSE_BUTTON, gfx::Point(1, 1)); |
| 311 EXPECT_EQ(QueuedType::ENTER, window->queue_response_type()); | 309 EXPECT_EQ(QueuedType::ENTER, window->queue_response_type()); |
| 312 window->Respond(true); | 310 window->Respond(true); |
| 313 | 311 |
| 314 DispatchDrag(window.get(), false, ui::EF_LEFT_MOUSE_BUTTON, gfx::Point(2, 2)); | 312 DispatchDrag(window.get(), false, ui::EF_LEFT_MOUSE_BUTTON, gfx::Point(2, 2)); |
| 315 EXPECT_EQ(QueuedType::OVER, window->queue_response_type()); | 313 EXPECT_EQ(QueuedType::OVER, window->queue_response_type()); |
| 316 window->Respond(true); | 314 window->Respond(true); |
| 317 | 315 |
| 318 DispatchDrag(window.get(), true, 0, gfx::Point(2, 2)); | 316 DispatchDrag(window.get(), true, 0, gfx::Point(2, 2)); |
| 319 EXPECT_EQ(QueuedType::DROP, window->queue_response_type()); | 317 EXPECT_EQ(QueuedType::DROP, window->queue_response_type()); |
| 320 | 318 |
| 321 // Unlike SimpleDragDrop, respond with kDropEffectNone, which should make the | 319 // Unlike SimpleDragDrop, respond with kDropEffectNone, which should make the |
| 322 // drag fail. | 320 // drag fail. |
| 323 window->Respond(false); | 321 window->Respond(false); |
| 324 | 322 |
| 325 EXPECT_EQ(ui::mojom::kDropEffectNone, | 323 EXPECT_EQ(ui::mojom::kDropEffectNone, |
| 326 drag_completed_action().value_or(ui::mojom::kDropEffectCopy)); | 324 drag_completed_action().value_or(ui::mojom::kDropEffectCopy)); |
| 327 EXPECT_FALSE(drag_completed_value().value_or(true)); | 325 EXPECT_FALSE(drag_completed_value().value_or(true)); |
| 328 } | 326 } |
| 329 | 327 |
| 330 TEST_F(DragControllerTest, OnlyDeliverMimeDataOnce) { | 328 TEST_F(DragControllerTest, OnlyDeliverMimeDataOnce) { |
| 331 std::unique_ptr<DragTestWindow> window1 = BuildWindow(); | 329 std::unique_ptr<DragTestWindow> window1 = BuildWindow(); |
| 332 std::unique_ptr<DragTestWindow> window2 = BuildWindow(); | 330 std::unique_ptr<DragTestWindow> window2 = BuildWindow(); |
| 333 mojo::Map<mojo::String, mojo::Array<uint8_t>> mime_data; | |
| 334 | 331 |
| 335 // The client lib is responsible for sending the data to the window that's | 332 // The client lib is responsible for sending the data to the window that's |
| 336 // the drag source to minimize IPC. | 333 // the drag source to minimize IPC. |
| 337 EXPECT_EQ(0u, window1->times_received_drag_drop_start()); | 334 EXPECT_EQ(0u, window1->times_received_drag_drop_start()); |
| 338 StartDragOperation(std::move(mime_data), window1.get(), | 335 StartDragOperation(window1.get(), ui::mojom::kDropEffectMove); |
| 339 ui::mojom::kDropEffectMove); | |
| 340 EXPECT_EQ(1u, window1->times_received_drag_drop_start()); | 336 EXPECT_EQ(1u, window1->times_received_drag_drop_start()); |
| 341 DispatchDrag(window1.get(), false, ui::EF_LEFT_MOUSE_BUTTON, | 337 DispatchDrag(window1.get(), false, ui::EF_LEFT_MOUSE_BUTTON, |
| 342 gfx::Point(1, 1)); | 338 gfx::Point(1, 1)); |
| 343 EXPECT_EQ(1u, window1->times_received_drag_drop_start()); | 339 EXPECT_EQ(1u, window1->times_received_drag_drop_start()); |
| 344 window1->Respond(true); | 340 window1->Respond(true); |
| 345 | 341 |
| 346 // Window2 doesn't receive the drag data until mouse is over it. | 342 // Window2 doesn't receive the drag data until mouse is over it. |
| 347 EXPECT_EQ(0u, window2->times_received_drag_drop_start()); | 343 EXPECT_EQ(0u, window2->times_received_drag_drop_start()); |
| 348 DispatchDrag(window2.get(), false, ui::EF_LEFT_MOUSE_BUTTON, | 344 DispatchDrag(window2.get(), false, ui::EF_LEFT_MOUSE_BUTTON, |
| 349 gfx::Point(2, 2)); | 345 gfx::Point(2, 2)); |
| 350 EXPECT_EQ(1u, window2->times_received_drag_drop_start()); | 346 EXPECT_EQ(1u, window2->times_received_drag_drop_start()); |
| 351 | 347 |
| 352 // Moving back to the source window doesn't send an additional start message. | 348 // Moving back to the source window doesn't send an additional start message. |
| 353 DispatchDrag(window1.get(), false, ui::EF_LEFT_MOUSE_BUTTON, | 349 DispatchDrag(window1.get(), false, ui::EF_LEFT_MOUSE_BUTTON, |
| 354 gfx::Point(1, 1)); | 350 gfx::Point(1, 1)); |
| 355 EXPECT_EQ(1u, window1->times_received_drag_drop_start()); | 351 EXPECT_EQ(1u, window1->times_received_drag_drop_start()); |
| 356 | 352 |
| 357 // Moving back to window2 doesn't send an additional start message. | 353 // Moving back to window2 doesn't send an additional start message. |
| 358 DispatchDrag(window2.get(), false, ui::EF_LEFT_MOUSE_BUTTON, | 354 DispatchDrag(window2.get(), false, ui::EF_LEFT_MOUSE_BUTTON, |
| 359 gfx::Point(1, 1)); | 355 gfx::Point(1, 1)); |
| 360 EXPECT_EQ(1u, window2->times_received_drag_drop_start()); | 356 EXPECT_EQ(1u, window2->times_received_drag_drop_start()); |
| 361 } | 357 } |
| 362 | 358 |
| 363 TEST_F(DragControllerTest, DeliverMessageToParent) { | 359 TEST_F(DragControllerTest, DeliverMessageToParent) { |
| 364 std::unique_ptr<DragTestWindow> window1 = BuildWindow(); | 360 std::unique_ptr<DragTestWindow> window1 = BuildWindow(); |
| 365 std::unique_ptr<DragTestWindow> window2 = BuildWindow(); | 361 std::unique_ptr<DragTestWindow> window2 = BuildWindow(); |
| 366 std::unique_ptr<DragTestWindow> window3 = BuildWindow(); | 362 std::unique_ptr<DragTestWindow> window3 = BuildWindow(); |
| 367 mojo::Map<mojo::String, mojo::Array<uint8_t>> mime_data; | |
| 368 | 363 |
| 369 window3->SetParent(window2.get()); | 364 window3->SetParent(window2.get()); |
| 370 window3->OptOutOfDrag(); | 365 window3->OptOutOfDrag(); |
| 371 | 366 |
| 372 StartDragOperation(std::move(mime_data), window1.get(), | 367 StartDragOperation(window1.get(), ui::mojom::kDropEffectMove); |
| 373 ui::mojom::kDropEffectMove); | |
| 374 | 368 |
| 375 // Dispatching a drag to window3 (which has can accept drags off) redirects | 369 // Dispatching a drag to window3 (which has can accept drags off) redirects |
| 376 // to window2, which is its parent. | 370 // to window2, which is its parent. |
| 377 DispatchDrag(window3.get(), false, ui::EF_LEFT_MOUSE_BUTTON, | 371 DispatchDrag(window3.get(), false, ui::EF_LEFT_MOUSE_BUTTON, |
| 378 gfx::Point(1, 1)); | 372 gfx::Point(1, 1)); |
| 379 EXPECT_EQ(1u, window2->times_received_drag_drop_start()); | 373 EXPECT_EQ(1u, window2->times_received_drag_drop_start()); |
| 380 } | 374 } |
| 381 | 375 |
| 382 TEST_F(DragControllerTest, FailWhenDropOverNoWindow) { | 376 TEST_F(DragControllerTest, FailWhenDropOverNoWindow) { |
| 383 std::unique_ptr<DragTestWindow> window = BuildWindow(); | 377 std::unique_ptr<DragTestWindow> window = BuildWindow(); |
| 384 mojo::Map<mojo::String, mojo::Array<uint8_t>> mime_data; | 378 StartDragOperation(window.get(), ui::mojom::kDropEffectMove); |
| 385 StartDragOperation(std::move(mime_data), window.get(), | |
| 386 ui::mojom::kDropEffectMove); | |
| 387 | 379 |
| 388 DispatchDrag(window.get(), false, ui::EF_LEFT_MOUSE_BUTTON, gfx::Point(1, 1)); | 380 DispatchDrag(window.get(), false, ui::EF_LEFT_MOUSE_BUTTON, gfx::Point(1, 1)); |
| 389 EXPECT_EQ(QueuedType::ENTER, window->queue_response_type()); | 381 EXPECT_EQ(QueuedType::ENTER, window->queue_response_type()); |
| 390 window->Respond(true); | 382 window->Respond(true); |
| 391 | 383 |
| 392 DispatchDrag(window.get(), false, ui::EF_LEFT_MOUSE_BUTTON, gfx::Point(2, 2)); | 384 DispatchDrag(window.get(), false, ui::EF_LEFT_MOUSE_BUTTON, gfx::Point(2, 2)); |
| 393 EXPECT_EQ(QueuedType::OVER, window->queue_response_type()); | 385 EXPECT_EQ(QueuedType::OVER, window->queue_response_type()); |
| 394 window->Respond(true); | 386 window->Respond(true); |
| 395 | 387 |
| 396 DispatchDrag(nullptr, true, 0, gfx::Point(2, 2)); | 388 DispatchDrag(nullptr, true, 0, gfx::Point(2, 2)); |
| 397 // Moving outside of |window| should result in |window| getting a leave. | 389 // Moving outside of |window| should result in |window| getting a leave. |
| 398 EXPECT_EQ(QueuedType::LEAVE, window->queue_response_type()); | 390 EXPECT_EQ(QueuedType::LEAVE, window->queue_response_type()); |
| 399 window->Respond(true); | 391 window->Respond(true); |
| 400 | 392 |
| 401 EXPECT_FALSE(drag_completed_value().value_or(true)); | 393 EXPECT_FALSE(drag_completed_value().value_or(true)); |
| 402 } | 394 } |
| 403 | 395 |
| 404 TEST_F(DragControllerTest, EnterLeaveWhenMovingBetweenTwoWindows) { | 396 TEST_F(DragControllerTest, EnterLeaveWhenMovingBetweenTwoWindows) { |
| 405 std::unique_ptr<DragTestWindow> window1 = BuildWindow(); | 397 std::unique_ptr<DragTestWindow> window1 = BuildWindow(); |
| 406 std::unique_ptr<DragTestWindow> window2 = BuildWindow(); | 398 std::unique_ptr<DragTestWindow> window2 = BuildWindow(); |
| 407 mojo::Map<mojo::String, mojo::Array<uint8_t>> mime_data; | 399 StartDragOperation(window1.get(), ui::mojom::kDropEffectMove); |
| 408 StartDragOperation(std::move(mime_data), window1.get(), | |
| 409 ui::mojom::kDropEffectMove); | |
| 410 | 400 |
| 411 DispatchDrag(window1.get(), false, ui::EF_LEFT_MOUSE_BUTTON, | 401 DispatchDrag(window1.get(), false, ui::EF_LEFT_MOUSE_BUTTON, |
| 412 gfx::Point(1, 1)); | 402 gfx::Point(1, 1)); |
| 413 EXPECT_EQ(QueuedType::ENTER, window1->queue_response_type()); | 403 EXPECT_EQ(QueuedType::ENTER, window1->queue_response_type()); |
| 414 window1->Respond(true); | 404 window1->Respond(true); |
| 415 | 405 |
| 416 DispatchDrag(window2.get(), false, ui::EF_LEFT_MOUSE_BUTTON, | 406 DispatchDrag(window2.get(), false, ui::EF_LEFT_MOUSE_BUTTON, |
| 417 gfx::Point(2, 2)); | 407 gfx::Point(2, 2)); |
| 418 EXPECT_EQ(QueuedType::ENTER, window2->queue_response_type()); | 408 EXPECT_EQ(QueuedType::ENTER, window2->queue_response_type()); |
| 419 EXPECT_EQ(QueuedType::LEAVE, window1->queue_response_type()); | 409 EXPECT_EQ(QueuedType::LEAVE, window1->queue_response_type()); |
| 420 window1->Respond(true); | 410 window1->Respond(true); |
| 421 window2->Respond(true); | 411 window2->Respond(true); |
| 422 } | 412 } |
| 423 | 413 |
| 424 TEST_F(DragControllerTest, DeadWindowDoesntBlock) { | 414 TEST_F(DragControllerTest, DeadWindowDoesntBlock) { |
| 425 std::unique_ptr<DragTestWindow> window1 = BuildWindow(); | 415 std::unique_ptr<DragTestWindow> window1 = BuildWindow(); |
| 426 std::unique_ptr<DragTestWindow> window2 = BuildWindow(); | 416 std::unique_ptr<DragTestWindow> window2 = BuildWindow(); |
| 427 mojo::Map<mojo::String, mojo::Array<uint8_t>> mime_data; | 417 StartDragOperation(window1.get(), ui::mojom::kDropEffectMove); |
| 428 StartDragOperation(std::move(mime_data), window1.get(), | |
| 429 ui::mojom::kDropEffectMove); | |
| 430 | 418 |
| 431 test::DragControllerTestApi api(drag_operation()); | 419 test::DragControllerTestApi api(drag_operation()); |
| 432 | 420 |
| 433 // Simulate a dead window by giving it a few messages, but don't respond to | 421 // Simulate a dead window by giving it a few messages, but don't respond to |
| 434 // them. | 422 // them. |
| 435 DispatchDrag(window1.get(), false, ui::EF_LEFT_MOUSE_BUTTON, | 423 DispatchDrag(window1.get(), false, ui::EF_LEFT_MOUSE_BUTTON, |
| 436 gfx::Point(1, 1)); | 424 gfx::Point(1, 1)); |
| 437 DispatchDrag(window1.get(), false, ui::EF_LEFT_MOUSE_BUTTON, | 425 DispatchDrag(window1.get(), false, ui::EF_LEFT_MOUSE_BUTTON, |
| 438 gfx::Point(2, 2)); | 426 gfx::Point(2, 2)); |
| 439 EXPECT_EQ(1u, window1->queue_size()); | 427 EXPECT_EQ(1u, window1->queue_size()); |
| 440 EXPECT_EQ(2u, api.GetSizeOfQueueForWindow(window1->window())); | 428 EXPECT_EQ(2u, api.GetSizeOfQueueForWindow(window1->window())); |
| 441 | 429 |
| 442 // Moving to window2 should dispatch the enter event to it immediately. | 430 // Moving to window2 should dispatch the enter event to it immediately. |
| 443 DispatchDrag(window2.get(), false, ui::EF_LEFT_MOUSE_BUTTON, | 431 DispatchDrag(window2.get(), false, ui::EF_LEFT_MOUSE_BUTTON, |
| 444 gfx::Point(3, 3)); | 432 gfx::Point(3, 3)); |
| 445 EXPECT_EQ(QueuedType::ENTER, window2->queue_response_type()); | 433 EXPECT_EQ(QueuedType::ENTER, window2->queue_response_type()); |
| 446 EXPECT_EQ(1u, window1->queue_size()); | 434 EXPECT_EQ(1u, window1->queue_size()); |
| 447 } | 435 } |
| 448 | 436 |
| 449 TEST_F(DragControllerTest, EnterToOverQueued) { | 437 TEST_F(DragControllerTest, EnterToOverQueued) { |
| 450 std::unique_ptr<DragTestWindow> window = BuildWindow(); | 438 std::unique_ptr<DragTestWindow> window = BuildWindow(); |
| 451 mojo::Map<mojo::String, mojo::Array<uint8_t>> mime_data; | 439 StartDragOperation(window.get(), ui::mojom::kDropEffectMove); |
| 452 StartDragOperation(std::move(mime_data), window.get(), | |
| 453 ui::mojom::kDropEffectMove); | |
| 454 | 440 |
| 455 DispatchDrag(window.get(), false, ui::EF_LEFT_MOUSE_BUTTON, gfx::Point(1, 1)); | 441 DispatchDrag(window.get(), false, ui::EF_LEFT_MOUSE_BUTTON, gfx::Point(1, 1)); |
| 456 ASSERT_EQ(1u, window->queue_size()); | 442 ASSERT_EQ(1u, window->queue_size()); |
| 457 EXPECT_EQ(QueuedType::ENTER, window->queue_response_type()); | 443 EXPECT_EQ(QueuedType::ENTER, window->queue_response_type()); |
| 458 // Don't respond. | 444 // Don't respond. |
| 459 | 445 |
| 460 // We don't receive another message since we haven't acknowledged the first. | 446 // We don't receive another message since we haven't acknowledged the first. |
| 461 DispatchDrag(window.get(), false, ui::EF_LEFT_MOUSE_BUTTON, gfx::Point(1, 2)); | 447 DispatchDrag(window.get(), false, ui::EF_LEFT_MOUSE_BUTTON, gfx::Point(1, 2)); |
| 462 ASSERT_EQ(1u, window->queue_size()); | 448 ASSERT_EQ(1u, window->queue_size()); |
| 463 | 449 |
| 464 // Responding causes us to receive our next event. | 450 // Responding causes us to receive our next event. |
| 465 window->Respond(true); | 451 window->Respond(true); |
| 466 ASSERT_EQ(1u, window->queue_size()); | 452 ASSERT_EQ(1u, window->queue_size()); |
| 467 EXPECT_EQ(QueuedType::OVER, window->queue_response_type()); | 453 EXPECT_EQ(QueuedType::OVER, window->queue_response_type()); |
| 468 } | 454 } |
| 469 | 455 |
| 470 TEST_F(DragControllerTest, CoalesceMouseOverEvents) { | 456 TEST_F(DragControllerTest, CoalesceMouseOverEvents) { |
| 471 std::unique_ptr<DragTestWindow> window = BuildWindow(); | 457 std::unique_ptr<DragTestWindow> window = BuildWindow(); |
| 472 mojo::Map<mojo::String, mojo::Array<uint8_t>> mime_data; | 458 StartDragOperation(window.get(), ui::mojom::kDropEffectMove); |
| 473 StartDragOperation(std::move(mime_data), window.get(), | |
| 474 ui::mojom::kDropEffectMove); | |
| 475 | 459 |
| 476 DispatchDrag(window.get(), false, ui::EF_LEFT_MOUSE_BUTTON, gfx::Point(1, 1)); | 460 DispatchDrag(window.get(), false, ui::EF_LEFT_MOUSE_BUTTON, gfx::Point(1, 1)); |
| 477 EXPECT_EQ(QueuedType::ENTER, window->queue_response_type()); | 461 EXPECT_EQ(QueuedType::ENTER, window->queue_response_type()); |
| 478 | 462 |
| 479 DispatchDrag(window.get(), false, ui::EF_LEFT_MOUSE_BUTTON, gfx::Point(1, 2)); | 463 DispatchDrag(window.get(), false, ui::EF_LEFT_MOUSE_BUTTON, gfx::Point(1, 2)); |
| 480 DispatchDrag(window.get(), false, ui::EF_LEFT_MOUSE_BUTTON, gfx::Point(2, 2)); | 464 DispatchDrag(window.get(), false, ui::EF_LEFT_MOUSE_BUTTON, gfx::Point(2, 2)); |
| 481 DispatchDrag(window.get(), false, ui::EF_LEFT_MOUSE_BUTTON, gfx::Point(2, 3)); | 465 DispatchDrag(window.get(), false, ui::EF_LEFT_MOUSE_BUTTON, gfx::Point(2, 3)); |
| 482 | 466 |
| 483 // Responding to the first delivers us the last mouse over event's position. | 467 // Responding to the first delivers us the last mouse over event's position. |
| 484 window->Respond(true); | 468 window->Respond(true); |
| 485 ASSERT_EQ(1u, window->queue_size()); | 469 ASSERT_EQ(1u, window->queue_size()); |
| 486 EXPECT_EQ(QueuedType::OVER, window->queue_response_type()); | 470 EXPECT_EQ(QueuedType::OVER, window->queue_response_type()); |
| 487 EXPECT_EQ(gfx::Point(2, 3), window->queue_front().cursor_offset); | 471 EXPECT_EQ(gfx::Point(2, 3), window->queue_front().cursor_offset); |
| 488 | 472 |
| 489 // There are no queued events because they were coalesced. | 473 // There are no queued events because they were coalesced. |
| 490 window->Respond(true); | 474 window->Respond(true); |
| 491 EXPECT_EQ(0u, window->queue_size()); | 475 EXPECT_EQ(0u, window->queue_size()); |
| 492 } | 476 } |
| 493 | 477 |
| 494 TEST_F(DragControllerTest, RemovePendingMouseOversOnLeave) { | 478 TEST_F(DragControllerTest, RemovePendingMouseOversOnLeave) { |
| 495 std::unique_ptr<DragTestWindow> window1 = BuildWindow(); | 479 std::unique_ptr<DragTestWindow> window1 = BuildWindow(); |
| 496 std::unique_ptr<DragTestWindow> window2 = BuildWindow(); | 480 std::unique_ptr<DragTestWindow> window2 = BuildWindow(); |
| 497 mojo::Map<mojo::String, mojo::Array<uint8_t>> mime_data; | 481 StartDragOperation(window1.get(), ui::mojom::kDropEffectMove); |
| 498 StartDragOperation(std::move(mime_data), window1.get(), | |
| 499 ui::mojom::kDropEffectMove); | |
| 500 | 482 |
| 501 // Enter | 483 // Enter |
| 502 DispatchDrag(window1.get(), false, ui::EF_LEFT_MOUSE_BUTTON, | 484 DispatchDrag(window1.get(), false, ui::EF_LEFT_MOUSE_BUTTON, |
| 503 gfx::Point(1, 1)); | 485 gfx::Point(1, 1)); |
| 504 EXPECT_EQ(QueuedType::ENTER, window1->queue_response_type()); | 486 EXPECT_EQ(QueuedType::ENTER, window1->queue_response_type()); |
| 505 | 487 |
| 506 // Over | 488 // Over |
| 507 DispatchDrag(window1.get(), false, ui::EF_LEFT_MOUSE_BUTTON, | 489 DispatchDrag(window1.get(), false, ui::EF_LEFT_MOUSE_BUTTON, |
| 508 gfx::Point(1, 1)); | 490 gfx::Point(1, 1)); |
| 509 | 491 |
| 510 // Leave | 492 // Leave |
| 511 DispatchDrag(window2.get(), false, ui::EF_LEFT_MOUSE_BUTTON, | 493 DispatchDrag(window2.get(), false, ui::EF_LEFT_MOUSE_BUTTON, |
| 512 gfx::Point(1, 1)); | 494 gfx::Point(1, 1)); |
| 513 | 495 |
| 514 // The window finally responds to the enter message; we should not receive | 496 // The window finally responds to the enter message; we should not receive |
| 515 // any over messages since we didn't respond to the enter message in time. | 497 // any over messages since we didn't respond to the enter message in time. |
| 516 window1->Respond(true); | 498 window1->Respond(true); |
| 517 ASSERT_EQ(1u, window1->queue_size()); | 499 ASSERT_EQ(1u, window1->queue_size()); |
| 518 EXPECT_EQ(QueuedType::LEAVE, window1->queue_response_type()); | 500 EXPECT_EQ(QueuedType::LEAVE, window1->queue_response_type()); |
| 519 } | 501 } |
| 520 | 502 |
| 521 TEST_F(DragControllerTest, TargetWindowClosedWhileDrag) { | 503 TEST_F(DragControllerTest, TargetWindowClosedWhileDrag) { |
| 522 std::unique_ptr<DragTestWindow> window1 = BuildWindow(); | 504 std::unique_ptr<DragTestWindow> window1 = BuildWindow(); |
| 523 std::unique_ptr<DragTestWindow> window2 = BuildWindow(); | 505 std::unique_ptr<DragTestWindow> window2 = BuildWindow(); |
| 524 mojo::Map<mojo::String, mojo::Array<uint8_t>> mime_data; | 506 StartDragOperation(window1.get(), ui::mojom::kDropEffectMove); |
| 525 StartDragOperation(std::move(mime_data), window1.get(), | |
| 526 ui::mojom::kDropEffectMove); | |
| 527 | 507 |
| 528 test::DragControllerTestApi api(drag_operation()); | 508 test::DragControllerTestApi api(drag_operation()); |
| 529 | 509 |
| 530 // Send some events to |window|. | 510 // Send some events to |window|. |
| 531 DispatchDrag(window2.get(), false, ui::EF_LEFT_MOUSE_BUTTON, | 511 DispatchDrag(window2.get(), false, ui::EF_LEFT_MOUSE_BUTTON, |
| 532 gfx::Point(1, 1)); | 512 gfx::Point(1, 1)); |
| 533 EXPECT_EQ(QueuedType::ENTER, window2->queue_response_type()); | 513 EXPECT_EQ(QueuedType::ENTER, window2->queue_response_type()); |
| 534 DispatchDrag(window2.get(), false, ui::EF_LEFT_MOUSE_BUTTON, | 514 DispatchDrag(window2.get(), false, ui::EF_LEFT_MOUSE_BUTTON, |
| 535 gfx::Point(1, 1)); | 515 gfx::Point(1, 1)); |
| 536 | 516 |
| (...skipping 10 matching lines...) Expand all Loading... |
| 547 EXPECT_EQ(0u, api.GetSizeOfQueueForWindow(server_window)); | 527 EXPECT_EQ(0u, api.GetSizeOfQueueForWindow(server_window)); |
| 548 EXPECT_EQ(nullptr, api.GetCurrentTarget()); | 528 EXPECT_EQ(nullptr, api.GetCurrentTarget()); |
| 549 | 529 |
| 550 // But a target window closing out from under us doesn't fail the drag. | 530 // But a target window closing out from under us doesn't fail the drag. |
| 551 EXPECT_FALSE(drag_completed_value().has_value()); | 531 EXPECT_FALSE(drag_completed_value().has_value()); |
| 552 } | 532 } |
| 553 | 533 |
| 554 TEST_F(DragControllerTest, TargetWindowClosedResetsCursor) { | 534 TEST_F(DragControllerTest, TargetWindowClosedResetsCursor) { |
| 555 std::unique_ptr<DragTestWindow> window1 = BuildWindow(); | 535 std::unique_ptr<DragTestWindow> window1 = BuildWindow(); |
| 556 std::unique_ptr<DragTestWindow> window2 = BuildWindow(); | 536 std::unique_ptr<DragTestWindow> window2 = BuildWindow(); |
| 557 mojo::Map<mojo::String, mojo::Array<uint8_t>> mime_data; | 537 StartDragOperation(window1.get(), ui::mojom::kDropEffectMove); |
| 558 StartDragOperation(std::move(mime_data), window1.get(), | |
| 559 ui::mojom::kDropEffectMove); | |
| 560 EXPECT_EQ(ui::mojom::Cursor::NO_DROP, cursor()); | 538 EXPECT_EQ(ui::mojom::Cursor::NO_DROP, cursor()); |
| 561 | 539 |
| 562 // Send some events to |window|. | 540 // Send some events to |window|. |
| 563 DispatchDrag(window2.get(), false, ui::EF_LEFT_MOUSE_BUTTON, | 541 DispatchDrag(window2.get(), false, ui::EF_LEFT_MOUSE_BUTTON, |
| 564 gfx::Point(1, 1)); | 542 gfx::Point(1, 1)); |
| 565 EXPECT_EQ(QueuedType::ENTER, window2->queue_response_type()); | 543 EXPECT_EQ(QueuedType::ENTER, window2->queue_response_type()); |
| 566 window2->Respond(true); | 544 window2->Respond(true); |
| 567 DispatchDrag(window2.get(), false, ui::EF_LEFT_MOUSE_BUTTON, | 545 DispatchDrag(window2.get(), false, ui::EF_LEFT_MOUSE_BUTTON, |
| 568 gfx::Point(1, 1)); | 546 gfx::Point(1, 1)); |
| 569 window2->Respond(true); | 547 window2->Respond(true); |
| 570 EXPECT_EQ(ui::mojom::Cursor::COPY, cursor()); | 548 EXPECT_EQ(ui::mojom::Cursor::COPY, cursor()); |
| 571 | 549 |
| 572 // Force the destruction of |window.window|. | 550 // Force the destruction of |window.window|. |
| 573 window2.reset(); | 551 window2.reset(); |
| 574 | 552 |
| 575 // The cursor no loner indicates that it can drop on |window2|. | 553 // The cursor no loner indicates that it can drop on |window2|. |
| 576 EXPECT_EQ(ui::mojom::Cursor::NO_DROP, cursor()); | 554 EXPECT_EQ(ui::mojom::Cursor::NO_DROP, cursor()); |
| 577 } | 555 } |
| 578 | 556 |
| 579 TEST_F(DragControllerTest, SourceWindowClosedWhileDrag) { | 557 TEST_F(DragControllerTest, SourceWindowClosedWhileDrag) { |
| 580 std::unique_ptr<DragTestWindow> window1 = BuildWindow(); | 558 std::unique_ptr<DragTestWindow> window1 = BuildWindow(); |
| 581 std::unique_ptr<DragTestWindow> window2 = BuildWindow(); | 559 std::unique_ptr<DragTestWindow> window2 = BuildWindow(); |
| 582 mojo::Map<mojo::String, mojo::Array<uint8_t>> mime_data; | 560 StartDragOperation(window1.get(), ui::mojom::kDropEffectMove); |
| 583 StartDragOperation(std::move(mime_data), window1.get(), | |
| 584 ui::mojom::kDropEffectMove); | |
| 585 | 561 |
| 586 test::DragControllerTestApi api(drag_operation()); | 562 test::DragControllerTestApi api(drag_operation()); |
| 587 | 563 |
| 588 // Send some events to |windoww|. | 564 // Send some events to |windoww|. |
| 589 DispatchDrag(window2.get(), false, ui::EF_LEFT_MOUSE_BUTTON, | 565 DispatchDrag(window2.get(), false, ui::EF_LEFT_MOUSE_BUTTON, |
| 590 gfx::Point(1, 1)); | 566 gfx::Point(1, 1)); |
| 591 EXPECT_EQ(QueuedType::ENTER, window2->queue_response_type()); | 567 EXPECT_EQ(QueuedType::ENTER, window2->queue_response_type()); |
| 592 DispatchDrag(window2.get(), false, ui::EF_LEFT_MOUSE_BUTTON, | 568 DispatchDrag(window2.get(), false, ui::EF_LEFT_MOUSE_BUTTON, |
| 593 gfx::Point(1, 1)); | 569 gfx::Point(1, 1)); |
| 594 | 570 |
| 595 ServerWindow* server_window = window2->window(); | 571 ServerWindow* server_window = window2->window(); |
| 596 | 572 |
| 597 // Ensure that DragController is waiting for a response from |window2|. | 573 // Ensure that DragController is waiting for a response from |window2|. |
| 598 EXPECT_EQ(2u, api.GetSizeOfQueueForWindow(server_window)); | 574 EXPECT_EQ(2u, api.GetSizeOfQueueForWindow(server_window)); |
| 599 EXPECT_EQ(server_window, api.GetCurrentTarget()); | 575 EXPECT_EQ(server_window, api.GetCurrentTarget()); |
| 600 | 576 |
| 601 // Force the destruction of the source window. | 577 // Force the destruction of the source window. |
| 602 window1.reset(); | 578 window1.reset(); |
| 603 | 579 |
| 604 // The source window going away fails the drag. | 580 // The source window going away fails the drag. |
| 605 EXPECT_FALSE(drag_completed_value().value_or(true)); | 581 EXPECT_FALSE(drag_completed_value().value_or(true)); |
| 606 } | 582 } |
| 607 | 583 |
| 608 TEST_F(DragControllerTest, DontQueueEventsAfterDrop) { | 584 TEST_F(DragControllerTest, DontQueueEventsAfterDrop) { |
| 609 // The DragController needs to stick around to coordinate the drop, but | 585 // The DragController needs to stick around to coordinate the drop, but |
| 610 // it should ignore further mouse events during this time. | 586 // it should ignore further mouse events during this time. |
| 611 std::unique_ptr<DragTestWindow> window = BuildWindow(); | 587 std::unique_ptr<DragTestWindow> window = BuildWindow(); |
| 612 mojo::Map<mojo::String, mojo::Array<uint8_t>> mime_data; | 588 StartDragOperation(window.get(), ui::mojom::kDropEffectMove); |
| 613 StartDragOperation(std::move(mime_data), window.get(), | |
| 614 ui::mojom::kDropEffectMove); | |
| 615 | 589 |
| 616 test::DragControllerTestApi api(drag_operation()); | 590 test::DragControllerTestApi api(drag_operation()); |
| 617 | 591 |
| 618 DispatchDrag(window.get(), false, ui::EF_LEFT_MOUSE_BUTTON, gfx::Point(1, 1)); | 592 DispatchDrag(window.get(), false, ui::EF_LEFT_MOUSE_BUTTON, gfx::Point(1, 1)); |
| 619 EXPECT_EQ(QueuedType::ENTER, window->queue_response_type()); | 593 EXPECT_EQ(QueuedType::ENTER, window->queue_response_type()); |
| 620 window->Respond(true); | 594 window->Respond(true); |
| 621 | 595 |
| 622 DispatchDrag(window.get(), false, ui::EF_LEFT_MOUSE_BUTTON, gfx::Point(2, 2)); | 596 DispatchDrag(window.get(), false, ui::EF_LEFT_MOUSE_BUTTON, gfx::Point(2, 2)); |
| 623 EXPECT_EQ(QueuedType::OVER, window->queue_response_type()); | 597 EXPECT_EQ(QueuedType::OVER, window->queue_response_type()); |
| 624 window->Respond(true); | 598 window->Respond(true); |
| 625 | 599 |
| 626 DispatchDrag(window.get(), true, 0, gfx::Point(2, 2)); | 600 DispatchDrag(window.get(), true, 0, gfx::Point(2, 2)); |
| 627 EXPECT_EQ(QueuedType::DROP, window->queue_response_type()); | 601 EXPECT_EQ(QueuedType::DROP, window->queue_response_type()); |
| 628 EXPECT_EQ(1u, api.GetSizeOfQueueForWindow(window->window())); | 602 EXPECT_EQ(1u, api.GetSizeOfQueueForWindow(window->window())); |
| 629 | 603 |
| 630 // Further located events don't result in additional drag messages. | 604 // Further located events don't result in additional drag messages. |
| 631 DispatchDrag(window.get(), false, ui::EF_LEFT_MOUSE_BUTTON, gfx::Point(2, 2)); | 605 DispatchDrag(window.get(), false, ui::EF_LEFT_MOUSE_BUTTON, gfx::Point(2, 2)); |
| 632 DispatchDrag(window.get(), false, ui::EF_LEFT_MOUSE_BUTTON, gfx::Point(2, 2)); | 606 DispatchDrag(window.get(), false, ui::EF_LEFT_MOUSE_BUTTON, gfx::Point(2, 2)); |
| 633 EXPECT_EQ(1u, api.GetSizeOfQueueForWindow(window->window())); | 607 EXPECT_EQ(1u, api.GetSizeOfQueueForWindow(window->window())); |
| 634 } | 608 } |
| 635 | 609 |
| 636 TEST_F(DragControllerTest, CancelDrag) { | 610 TEST_F(DragControllerTest, CancelDrag) { |
| 637 // The DragController needs to stick around to coordinate the drop, but | 611 // The DragController needs to stick around to coordinate the drop, but |
| 638 // it should ignore further mouse events during this time. | 612 // it should ignore further mouse events during this time. |
| 639 std::unique_ptr<DragTestWindow> window = BuildWindow(); | 613 std::unique_ptr<DragTestWindow> window = BuildWindow(); |
| 640 mojo::Map<mojo::String, mojo::Array<uint8_t>> mime_data; | 614 StartDragOperation(window.get(), ui::mojom::kDropEffectMove); |
| 641 StartDragOperation(std::move(mime_data), window.get(), | |
| 642 ui::mojom::kDropEffectMove); | |
| 643 | 615 |
| 644 DispatchDrag(window.get(), false, ui::EF_LEFT_MOUSE_BUTTON, gfx::Point(1, 1)); | 616 DispatchDrag(window.get(), false, ui::EF_LEFT_MOUSE_BUTTON, gfx::Point(1, 1)); |
| 645 EXPECT_EQ(QueuedType::ENTER, window->queue_response_type()); | 617 EXPECT_EQ(QueuedType::ENTER, window->queue_response_type()); |
| 646 window->Respond(true); | 618 window->Respond(true); |
| 647 | 619 |
| 648 drag_operation()->Cancel(); | 620 drag_operation()->Cancel(); |
| 649 | 621 |
| 650 EXPECT_FALSE(drag_completed_value().value_or(true)); | 622 EXPECT_FALSE(drag_completed_value().value_or(true)); |
| 651 } | 623 } |
| 652 | 624 |
| 653 TEST_F(DragControllerTest, IgnoreEventsFromOtherPointers) { | 625 TEST_F(DragControllerTest, IgnoreEventsFromOtherPointers) { |
| 654 std::unique_ptr<DragTestWindow> window = BuildWindow(); | 626 std::unique_ptr<DragTestWindow> window = BuildWindow(); |
| 655 mojo::Map<mojo::String, mojo::Array<uint8_t>> mime_data; | |
| 656 // This starts the operation with PointerEvent::kMousePointerId. | 627 // This starts the operation with PointerEvent::kMousePointerId. |
| 657 StartDragOperation(std::move(mime_data), window.get(), | 628 StartDragOperation(window.get(), ui::mojom::kDropEffectMove); |
| 658 ui::mojom::kDropEffectMove); | |
| 659 | 629 |
| 660 // Ignore events from pointer 5. | 630 // Ignore events from pointer 5. |
| 661 DispatchDragWithPointer(window.get(), 5, false, ui::EF_LEFT_MOUSE_BUTTON, | 631 DispatchDragWithPointer(window.get(), 5, false, ui::EF_LEFT_MOUSE_BUTTON, |
| 662 gfx::Point(1, 1)); | 632 gfx::Point(1, 1)); |
| 663 ASSERT_EQ(0u, window->queue_size()); | 633 ASSERT_EQ(0u, window->queue_size()); |
| 664 } | 634 } |
| 665 | 635 |
| 666 TEST_F(DragControllerTest, RejectingWindowHasProperCursor) { | 636 TEST_F(DragControllerTest, RejectingWindowHasProperCursor) { |
| 667 std::unique_ptr<DragTestWindow> window = BuildWindow(); | 637 std::unique_ptr<DragTestWindow> window = BuildWindow(); |
| 668 mojo::Map<mojo::String, mojo::Array<uint8_t>> mime_data; | 638 StartDragOperation(window.get(), ui::mojom::kDropEffectMove); |
| 669 StartDragOperation(std::move(mime_data), window.get(), | |
| 670 ui::mojom::kDropEffectMove); | |
| 671 | 639 |
| 672 EXPECT_EQ(ui::mojom::Cursor::NO_DROP, cursor()); | 640 EXPECT_EQ(ui::mojom::Cursor::NO_DROP, cursor()); |
| 673 | 641 |
| 674 DispatchDrag(window.get(), false, ui::EF_LEFT_MOUSE_BUTTON, gfx::Point(1, 1)); | 642 DispatchDrag(window.get(), false, ui::EF_LEFT_MOUSE_BUTTON, gfx::Point(1, 1)); |
| 675 EXPECT_EQ(QueuedType::ENTER, window->queue_response_type()); | 643 EXPECT_EQ(QueuedType::ENTER, window->queue_response_type()); |
| 676 window->Respond(true); | 644 window->Respond(true); |
| 677 | 645 |
| 678 EXPECT_EQ(ui::mojom::Cursor::COPY, cursor()); | 646 EXPECT_EQ(ui::mojom::Cursor::COPY, cursor()); |
| 679 | 647 |
| 680 DispatchDrag(window.get(), false, ui::EF_LEFT_MOUSE_BUTTON, gfx::Point(2, 2)); | 648 DispatchDrag(window.get(), false, ui::EF_LEFT_MOUSE_BUTTON, gfx::Point(2, 2)); |
| 681 EXPECT_EQ(QueuedType::OVER, window->queue_response_type()); | 649 EXPECT_EQ(QueuedType::OVER, window->queue_response_type()); |
| 682 | 650 |
| 683 // At this point, we respond with no available drag actions at this pixel. | 651 // At this point, we respond with no available drag actions at this pixel. |
| 684 window->Respond(false); | 652 window->Respond(false); |
| 685 EXPECT_EQ(ui::mojom::Cursor::NO_DROP, cursor()); | 653 EXPECT_EQ(ui::mojom::Cursor::NO_DROP, cursor()); |
| 686 } | 654 } |
| 687 | 655 |
| 688 TEST_F(DragControllerTest, ResopnseFromOtherWindowDoesntChangeCursor) { | 656 TEST_F(DragControllerTest, ResopnseFromOtherWindowDoesntChangeCursor) { |
| 689 std::unique_ptr<DragTestWindow> window1 = BuildWindow(); | 657 std::unique_ptr<DragTestWindow> window1 = BuildWindow(); |
| 690 std::unique_ptr<DragTestWindow> window2 = BuildWindow(); | 658 std::unique_ptr<DragTestWindow> window2 = BuildWindow(); |
| 691 mojo::Map<mojo::String, mojo::Array<uint8_t>> mime_data; | 659 StartDragOperation(window1.get(), ui::mojom::kDropEffectMove); |
| 692 StartDragOperation(std::move(mime_data), window1.get(), | |
| 693 ui::mojom::kDropEffectMove); | |
| 694 | 660 |
| 695 // Send some events to |window2|. | 661 // Send some events to |window2|. |
| 696 DispatchDrag(window2.get(), false, ui::EF_LEFT_MOUSE_BUTTON, | 662 DispatchDrag(window2.get(), false, ui::EF_LEFT_MOUSE_BUTTON, |
| 697 gfx::Point(1, 1)); | 663 gfx::Point(1, 1)); |
| 698 EXPECT_EQ(QueuedType::ENTER, window2->queue_response_type()); | 664 EXPECT_EQ(QueuedType::ENTER, window2->queue_response_type()); |
| 699 DispatchDrag(window2.get(), false, ui::EF_LEFT_MOUSE_BUTTON, | 665 DispatchDrag(window2.get(), false, ui::EF_LEFT_MOUSE_BUTTON, |
| 700 gfx::Point(1, 1)); | 666 gfx::Point(1, 1)); |
| 701 | 667 |
| 702 EXPECT_EQ(ui::mojom::Cursor::NO_DROP, cursor()); | 668 EXPECT_EQ(ui::mojom::Cursor::NO_DROP, cursor()); |
| 703 | 669 |
| 704 // Now enter |window1|, and respond. | 670 // Now enter |window1|, and respond. |
| 705 DispatchDrag(window1.get(), false, ui::EF_LEFT_MOUSE_BUTTON, | 671 DispatchDrag(window1.get(), false, ui::EF_LEFT_MOUSE_BUTTON, |
| 706 gfx::Point(5, 5)); | 672 gfx::Point(5, 5)); |
| 707 EXPECT_EQ(QueuedType::ENTER, window1->queue_response_type()); | 673 EXPECT_EQ(QueuedType::ENTER, window1->queue_response_type()); |
| 708 window1->Respond(true); | 674 window1->Respond(true); |
| 709 | 675 |
| 710 EXPECT_EQ(ui::mojom::Cursor::COPY, cursor()); | 676 EXPECT_EQ(ui::mojom::Cursor::COPY, cursor()); |
| 711 | 677 |
| 712 // Window 2 responding negatively to its queued messages shouldn't change the | 678 // Window 2 responding negatively to its queued messages shouldn't change the |
| 713 // cursor. | 679 // cursor. |
| 714 window2->Respond(false); | 680 window2->Respond(false); |
| 715 | 681 |
| 716 EXPECT_EQ(ui::mojom::Cursor::COPY, cursor()); | 682 EXPECT_EQ(ui::mojom::Cursor::COPY, cursor()); |
| 717 } | 683 } |
| 718 | 684 |
| 719 } // namespace ws | 685 } // namespace ws |
| 720 } // namespace ui | 686 } // namespace ui |
| OLD | NEW |