| Index: services/ui/ws/drag_controller_unittest.cc
|
| diff --git a/services/ui/ws/drag_controller_unittest.cc b/services/ui/ws/drag_controller_unittest.cc
|
| index 8b9360d87046d40ddb2a7d0b46022443e730bed7..71df3b1b76837cba61d501e44d7eba0151e9f56f 100644
|
| --- a/services/ui/ws/drag_controller_unittest.cc
|
| +++ b/services/ui/ws/drag_controller_unittest.cc
|
| @@ -4,6 +4,12 @@
|
|
|
| #include "services/ui/ws/drag_controller.h"
|
|
|
| +#include <map>
|
| +#include <memory>
|
| +#include <queue>
|
| +#include <utility>
|
| +
|
| +#include "services/ui/public/interfaces/cursor.mojom.h"
|
| #include "services/ui/ws/drag_source.h"
|
| #include "services/ui/ws/drag_target_connection.h"
|
| #include "services/ui/ws/ids.h"
|
| @@ -128,7 +134,9 @@ class DragTestWindow : public DragTargetConnection {
|
| std::queue<DragEvent> queued_callbacks_;
|
| };
|
|
|
| -class DragControllerTest : public testing::Test, public DragSource {
|
| +class DragControllerTest : public testing::Test,
|
| + public DragCursorUpdater,
|
| + public DragSource {
|
| public:
|
| std::unique_ptr<DragTestWindow> BuildWindow() {
|
| WindowId id(1, ++window_id_);
|
| @@ -145,8 +153,13 @@ class DragControllerTest : public testing::Test, public DragSource {
|
| uint32_t drag_operations) {
|
| window->PerformOnDragDropStart(mime_data.Clone());
|
| drag_operation_ = base::MakeUnique<DragController>(
|
| - this, window->window(), window, PointerEvent::kMousePointerId,
|
| + this, this, window->window(), window, PointerEvent::kMousePointerId,
|
| std::move(mime_data), drag_operations);
|
| +
|
| + // It would be nice if we could just let the observer method fire, but it
|
| + // fires during the constructor when we haven't assigned the unique_ptr
|
| + // yet.
|
| + cursor_ = ui::mojom::Cursor(drag_operation_->current_cursor());
|
| }
|
|
|
| void DispatchDrag(DragTestWindow* window,
|
| @@ -187,6 +200,8 @@ class DragControllerTest : public testing::Test, public DragSource {
|
| return drag_completed_value_;
|
| }
|
|
|
| + ui::mojom::Cursor cursor() { return cursor_; }
|
| +
|
| private:
|
| // Overridden from testing::Test:
|
| void SetUp() override {
|
| @@ -210,6 +225,12 @@ class DragControllerTest : public testing::Test, public DragSource {
|
| testing::Test::TearDown();
|
| }
|
|
|
| + // Overridden from DragCursorUpdater:
|
| + void OnDragCursorUpdated() override {
|
| + if (drag_operation_)
|
| + cursor_ = ui::mojom::Cursor(drag_operation_->current_cursor());
|
| + }
|
| +
|
| // Overridden from DragControllerSource:
|
| void OnDragCompleted(bool success, uint32_t action_taken) override {
|
| drag_completed_action_ = action_taken;
|
| @@ -233,6 +254,8 @@ class DragControllerTest : public testing::Test, public DragSource {
|
|
|
| int window_id_ = 3;
|
|
|
| + ui::mojom::Cursor cursor_;
|
| +
|
| std::map<WindowId, ServerWindow*> server_window_by_id_;
|
| std::map<ServerWindow*, DragTargetConnection*> connection_by_window_;
|
|
|
| @@ -255,10 +278,15 @@ TEST_F(DragControllerTest, SimpleDragDrop) {
|
| StartDragOperation(std::move(mime_data), window.get(),
|
| ui::mojom::kDropEffectMove);
|
|
|
| + EXPECT_EQ(ui::mojom::Cursor::NO_DROP, cursor());
|
| +
|
| DispatchDrag(window.get(), false, ui::EF_LEFT_MOUSE_BUTTON, gfx::Point(1, 1));
|
| EXPECT_EQ(QueuedType::ENTER, window->queue_response_type());
|
| window->Respond(true);
|
|
|
| + // (Even though we're doing a move, the cursor name is COPY.)
|
| + EXPECT_EQ(ui::mojom::Cursor::COPY, cursor());
|
| +
|
| DispatchDrag(window.get(), false, ui::EF_LEFT_MOUSE_BUTTON, gfx::Point(2, 2));
|
| EXPECT_EQ(QueuedType::OVER, window->queue_response_type());
|
| window->Respond(true);
|
| @@ -522,6 +550,31 @@ TEST_F(DragControllerTest, TargetWindowClosedWhileDrag) {
|
| EXPECT_FALSE(drag_completed_value().has_value());
|
| }
|
|
|
| +TEST_F(DragControllerTest, TargetWindowClosedResetsCursor) {
|
| + std::unique_ptr<DragTestWindow> window1 = BuildWindow();
|
| + std::unique_ptr<DragTestWindow> window2 = BuildWindow();
|
| + mojo::Map<mojo::String, mojo::Array<uint8_t>> mime_data;
|
| + StartDragOperation(std::move(mime_data), window1.get(),
|
| + ui::mojom::kDropEffectMove);
|
| + EXPECT_EQ(ui::mojom::Cursor::NO_DROP, cursor());
|
| +
|
| + // Send some events to |window|.
|
| + DispatchDrag(window2.get(), false, ui::EF_LEFT_MOUSE_BUTTON,
|
| + gfx::Point(1, 1));
|
| + EXPECT_EQ(QueuedType::ENTER, window2->queue_response_type());
|
| + window2->Respond(true);
|
| + DispatchDrag(window2.get(), false, ui::EF_LEFT_MOUSE_BUTTON,
|
| + gfx::Point(1, 1));
|
| + window2->Respond(true);
|
| + EXPECT_EQ(ui::mojom::Cursor::COPY, cursor());
|
| +
|
| + // Force the destruction of |window.window|.
|
| + window2.reset();
|
| +
|
| + // The cursor no loner indicates that it can drop on |window2|.
|
| + EXPECT_EQ(ui::mojom::Cursor::NO_DROP, cursor());
|
| +}
|
| +
|
| TEST_F(DragControllerTest, SourceWindowClosedWhileDrag) {
|
| std::unique_ptr<DragTestWindow> window1 = BuildWindow();
|
| std::unique_ptr<DragTestWindow> window2 = BuildWindow();
|
| @@ -531,7 +584,7 @@ TEST_F(DragControllerTest, SourceWindowClosedWhileDrag) {
|
|
|
| test::DragControllerTestApi api(drag_operation());
|
|
|
| - // Send some events to |window|.
|
| + // Send some events to |windoww|.
|
| DispatchDrag(window2.get(), false, ui::EF_LEFT_MOUSE_BUTTON,
|
| gfx::Point(1, 1));
|
| EXPECT_EQ(QueuedType::ENTER, window2->queue_response_type());
|
| @@ -540,7 +593,7 @@ TEST_F(DragControllerTest, SourceWindowClosedWhileDrag) {
|
|
|
| ServerWindow* server_window = window2->window();
|
|
|
| - // Ensure that DragController is waiting for a response from |window|.
|
| + // Ensure that DragController is waiting for a response from |window2|.
|
| EXPECT_EQ(2u, api.GetSizeOfQueueForWindow(server_window));
|
| EXPECT_EQ(server_window, api.GetCurrentTarget());
|
|
|
| @@ -609,9 +662,58 @@ TEST_F(DragControllerTest, IgnoreEventsFromOtherPointers) {
|
| ASSERT_EQ(0u, window->queue_size());
|
| }
|
|
|
| -// TODO(erg): Add a test to ensure windows that the cursor isn't over
|
| -// responding to messages don't change the cursor when we have cursor handling
|
| -// code.
|
| +TEST_F(DragControllerTest, RejectingWindowHasProperCursor) {
|
| + std::unique_ptr<DragTestWindow> window = BuildWindow();
|
| + mojo::Map<mojo::String, mojo::Array<uint8_t>> mime_data;
|
| + StartDragOperation(std::move(mime_data), window.get(),
|
| + ui::mojom::kDropEffectMove);
|
| +
|
| + EXPECT_EQ(ui::mojom::Cursor::NO_DROP, cursor());
|
| +
|
| + DispatchDrag(window.get(), false, ui::EF_LEFT_MOUSE_BUTTON, gfx::Point(1, 1));
|
| + EXPECT_EQ(QueuedType::ENTER, window->queue_response_type());
|
| + window->Respond(true);
|
| +
|
| + EXPECT_EQ(ui::mojom::Cursor::COPY, cursor());
|
| +
|
| + DispatchDrag(window.get(), false, ui::EF_LEFT_MOUSE_BUTTON, gfx::Point(2, 2));
|
| + EXPECT_EQ(QueuedType::OVER, window->queue_response_type());
|
| +
|
| + // At this point, we respond with no available drag actions at this pixel.
|
| + window->Respond(false);
|
| + EXPECT_EQ(ui::mojom::Cursor::NO_DROP, cursor());
|
| +}
|
| +
|
| +TEST_F(DragControllerTest, ResopnseFromOtherWindowDoesntChangeCursor) {
|
| + std::unique_ptr<DragTestWindow> window1 = BuildWindow();
|
| + std::unique_ptr<DragTestWindow> window2 = BuildWindow();
|
| + mojo::Map<mojo::String, mojo::Array<uint8_t>> mime_data;
|
| + StartDragOperation(std::move(mime_data), window1.get(),
|
| + ui::mojom::kDropEffectMove);
|
| +
|
| + // Send some events to |window2|.
|
| + DispatchDrag(window2.get(), false, ui::EF_LEFT_MOUSE_BUTTON,
|
| + gfx::Point(1, 1));
|
| + EXPECT_EQ(QueuedType::ENTER, window2->queue_response_type());
|
| + DispatchDrag(window2.get(), false, ui::EF_LEFT_MOUSE_BUTTON,
|
| + gfx::Point(1, 1));
|
| +
|
| + EXPECT_EQ(ui::mojom::Cursor::NO_DROP, cursor());
|
| +
|
| + // Now enter |window1|, and respond.
|
| + DispatchDrag(window1.get(), false, ui::EF_LEFT_MOUSE_BUTTON,
|
| + gfx::Point(5, 5));
|
| + EXPECT_EQ(QueuedType::ENTER, window1->queue_response_type());
|
| + window1->Respond(true);
|
| +
|
| + EXPECT_EQ(ui::mojom::Cursor::COPY, cursor());
|
| +
|
| + // Window 2 responding negatively to its queued messages shouldn't change the
|
| + // cursor.
|
| + window2->Respond(false);
|
| +
|
| + EXPECT_EQ(ui::mojom::Cursor::COPY, cursor());
|
| +}
|
|
|
| } // namespace ws
|
| } // namespace ui
|
|
|