Commit 6bda4d62 authored by Xiyuan Xia's avatar Xiyuan Xia Committed by Commit Bot

ws2: Re-enable DragTestInteractive.DragTest

- Add TestDragDropClient based on ash::DragDropController to map mouse
  events to DragTargetEvents and dispatch them;
- Implement RunDragLoop/CancelDragLoop in test_ws using
  TestDragDropClient;
- Re-enable RunDragLoop/CancelDragLoop;

Bug: 864616
Change-Id: I349e5c80abe8f20e27a5da34992c15cc611a98b3
Reviewed-on: https://chromium-review.googlesource.com/1152461
Commit-Queue: Xiyuan Xia <xiyuan@chromium.org>
Reviewed-by: default avatarMichael Wasserman <msw@chromium.org>
Cr-Commit-Position: refs/heads/master@{#578690}
parent fe4d0ac5
...@@ -9,6 +9,8 @@ service("test_ws") { ...@@ -9,6 +9,8 @@ service("test_ws") {
testonly = true testonly = true
sources = [ sources = [
"test_drag_drop_client.cc",
"test_drag_drop_client.h",
"test_gpu_interface_provider.cc", "test_gpu_interface_provider.cc",
"test_gpu_interface_provider.h", "test_gpu_interface_provider.h",
"test_ws.cc", "test_ws.cc",
......
// Copyright 2018 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "services/ui/test_ws/test_drag_drop_client.h"
#include "base/logging.h"
#include "ui/aura/client/drag_drop_delegate.h"
#include "ui/aura/window.h"
#include "ui/base/dragdrop/drop_target_event.h"
namespace ui {
namespace test {
TestDragDropClient::TestDragDropClient() = default;
TestDragDropClient::~TestDragDropClient() = default;
int TestDragDropClient::StartDragAndDrop(
const ui::OSExchangeData& data,
aura::Window* root_window,
aura::Window* source_window,
const gfx::Point& screen_location,
int operation,
ui::DragDropTypes::DragEventSource source) {
if (IsDragDropInProgress())
return ui::DragDropTypes::DRAG_NONE;
DCHECK(!root_window_);
root_window_ = root_window;
root_window_->AddObserver(this);
root_window_->AddPreTargetHandler(this, ui::EventTarget::Priority::kSystem);
drag_data_ = &data;
drag_operation_ = operation;
drag_loop_ = std::make_unique<base::RunLoop>(
base::RunLoop::Type::kNestableTasksAllowed);
drag_loop_->Run();
drag_loop_.reset();
if (root_window_) {
root_window_->RemovePreTargetHandler(this);
root_window_->RemoveObserver(this);
root_window_ = nullptr;
}
return drag_operation_;
}
void TestDragDropClient::DragCancel() {
if (!IsDragDropInProgress())
return;
drag_operation_ = ui::DragDropTypes::DRAG_NONE;
drag_loop_->Quit();
}
bool TestDragDropClient::IsDragDropInProgress() {
return !!drag_loop_;
}
void TestDragDropClient::OnWindowDestroyed(aura::Window* window) {
DCHECK_EQ(root_window_, window);
root_window_ = nullptr;
DragCancel();
}
void TestDragDropClient::OnMouseEvent(ui::MouseEvent* event) {
DCHECK(IsDragDropInProgress());
DCHECK(root_window_);
aura::Window* target =
root_window_->GetEventHandlerForPoint(event->location());
if (!target) {
NOTREACHED() << "No target found for drag and drop mouse event.";
event->StopPropagation();
return;
}
event->ConvertLocationToTarget(root_window_, target);
switch (event->type()) {
case ui::ET_MOUSE_DRAGGED:
DragUpdate(target, *event);
break;
case ui::ET_MOUSE_RELEASED:
Drop(target, *event);
break;
default:
break;
}
event->StopPropagation();
}
void TestDragDropClient::DragUpdate(aura::Window* target,
const ui::LocatedEvent& event) {
if (target != drag_window_) {
if (drag_window_) {
aura::client::DragDropDelegate* delegate =
aura::client::GetDragDropDelegate(drag_window_);
if (delegate)
delegate->OnDragExited();
}
drag_window_ = target;
if (drag_window_) {
aura::client::DragDropDelegate* delegate =
aura::client::GetDragDropDelegate(drag_window_);
if (delegate) {
ui::DropTargetEvent e(*drag_data_, gfx::Point(), gfx::Point(),
drag_operation_);
e.set_location_f(event.location_f());
e.set_root_location_f(event.root_location_f());
e.set_flags(event.flags());
ui::Event::DispatcherApi(&e).set_target(target);
delegate->OnDragEntered(e);
}
}
} else {
aura::client::DragDropDelegate* delegate =
aura::client::GetDragDropDelegate(drag_window_);
if (delegate) {
ui::DropTargetEvent e(*drag_data_, gfx::Point(), gfx::Point(),
drag_operation_);
e.set_location_f(event.location_f());
e.set_root_location_f(event.root_location_f());
e.set_flags(event.flags());
ui::Event::DispatcherApi(&e).set_target(target);
delegate->OnDragUpdated(e);
}
}
}
void TestDragDropClient::Drop(aura::Window* target,
const ui::LocatedEvent& event) {
if (target != drag_window_)
DragUpdate(target, event);
aura::client::DragDropDelegate* delegate =
aura::client::GetDragDropDelegate(target);
if (delegate) {
ui::DropTargetEvent e(*drag_data_, gfx::Point(), gfx::Point(),
drag_operation_);
e.set_location_f(event.location_f());
e.set_root_location_f(event.root_location_f());
e.set_flags(event.flags());
ui::Event::DispatcherApi(&e).set_target(target);
drag_operation_ = delegate->OnPerformDrop(e);
}
drag_loop_->Quit();
}
} // namespace test
} // namespace ui
// Copyright 2018 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef SERVICES_UI_TEST_WS_TEST_DRAG_DROP_CLIENT_H_
#define SERVICES_UI_TEST_WS_TEST_DRAG_DROP_CLIENT_H_
#include <memory>
#include "base/macros.h"
#include "base/run_loop.h"
#include "ui/aura/client/drag_drop_client.h"
#include "ui/aura/window_observer.h"
#include "ui/base/dragdrop/drag_drop_types.h"
#include "ui/events/event.h"
#include "ui/events/event_handler.h"
namespace ui {
namespace test {
// Drives drag and drop loop in a single root window for test. The logic is
// based on ash::DragDropController.
class TestDragDropClient : public aura::client::DragDropClient,
public aura::WindowObserver,
public ui::EventHandler {
public:
TestDragDropClient();
~TestDragDropClient() override;
// aura::client::DragDropClient
int StartDragAndDrop(const ui::OSExchangeData& data,
aura::Window* root_window,
aura::Window* source_window,
const gfx::Point& screen_location,
int operation,
ui::DragDropTypes::DragEventSource source) override;
void DragCancel() override;
bool IsDragDropInProgress() override;
void AddObserver(aura::client::DragDropClientObserver* observer) override {}
void RemoveObserver(aura::client::DragDropClientObserver* observer) override {
}
// aura::WindowObserer
void OnWindowDestroyed(aura::Window* window) override;
// ui::EventHandler
void OnMouseEvent(ui::MouseEvent* event) override;
private:
void DragUpdate(aura::Window* target, const ui::LocatedEvent& event);
void Drop(aura::Window* target, const ui::LocatedEvent& event);
// The root window where drag and drop happens.
aura::Window* root_window_ = nullptr;
// The window that is under the drag cursor.
aura::Window* drag_window_ = nullptr;
const ui::OSExchangeData* drag_data_ = nullptr;
int drag_operation_ = ui::DragDropTypes::DRAG_NONE;
std::unique_ptr<base::RunLoop> drag_loop_;
DISALLOW_COPY_AND_ASSIGN(TestDragDropClient);
};
} // namespace test
} // namespace ui
#endif // SERVICES_UI_TEST_WS_TEST_DRAG_DROP_CLIENT_H_
...@@ -18,6 +18,7 @@ ...@@ -18,6 +18,7 @@
#include "services/service_manager/public/mojom/service_factory.mojom.h" #include "services/service_manager/public/mojom/service_factory.mojom.h"
#include "services/ui/public/interfaces/constants.mojom.h" #include "services/ui/public/interfaces/constants.mojom.h"
#include "services/ui/public/interfaces/window_tree_host_factory.mojom.h" #include "services/ui/public/interfaces/window_tree_host_factory.mojom.h"
#include "services/ui/test_ws/test_drag_drop_client.h"
#include "services/ui/test_ws/test_gpu_interface_provider.h" #include "services/ui/test_ws/test_gpu_interface_provider.h"
#include "services/ui/ws2/window_service.h" #include "services/ui/ws2/window_service.h"
#include "services/ui/ws2/window_service_delegate.h" #include "services/ui/ws2/window_service_delegate.h"
...@@ -33,6 +34,7 @@ ...@@ -33,6 +34,7 @@
#include "ui/compositor/test/context_factories_for_test.h" #include "ui/compositor/test/context_factories_for_test.h"
#include "ui/gfx/gfx_paths.h" #include "ui/gfx/gfx_paths.h"
#include "ui/gl/test/gl_surface_test_support.h" #include "ui/gl/test/gl_surface_test_support.h"
#include "ui/wm/core/default_screen_position_client.h"
namespace ui { namespace ui {
namespace test { namespace test {
...@@ -115,6 +117,8 @@ class TestWindowService : public service_manager::Service, ...@@ -115,6 +117,8 @@ class TestWindowService : public service_manager::Service,
TestWindowService() = default; TestWindowService() = default;
~TestWindowService() override { ~TestWindowService() override {
aura::client::SetScreenPositionClient(aura_test_helper_->root_window(),
nullptr);
// WindowService depends upon Screen, which is owned by AuraTestHelper. // WindowService depends upon Screen, which is owned by AuraTestHelper.
service_context_.reset(); service_context_.reset();
// AuraTestHelper expects TearDown() to be called. // AuraTestHelper expects TearDown() to be called.
...@@ -139,6 +143,19 @@ class TestWindowService : public service_manager::Service, ...@@ -139,6 +143,19 @@ class TestWindowService : public service_manager::Service,
} }
return top_level; return top_level;
} }
void RunDragLoop(aura::Window* window,
const ui::OSExchangeData& data,
const gfx::Point& screen_location,
uint32_t drag_operation,
ui::DragDropTypes::DragEventSource source,
DragDropCompletedCallback callback) override {
std::move(callback).Run(drag_drop_client_.StartDragAndDrop(
data, window->GetRootWindow(), window, screen_location, drag_operation,
source));
}
void CancelDragLoop(aura::Window* window) override {
drag_drop_client_.DragCancel();
}
aura::WindowTreeHost* GetWindowTreeHostForDisplayId( aura::WindowTreeHost* GetWindowTreeHostForDisplayId(
int64_t display_id) override { int64_t display_id) override {
...@@ -162,6 +179,9 @@ class TestWindowService : public service_manager::Service, ...@@ -162,6 +179,9 @@ class TestWindowService : public service_manager::Service,
aura_test_helper_ = std::make_unique<aura::test::AuraTestHelper>(); aura_test_helper_ = std::make_unique<aura::test::AuraTestHelper>();
aura_test_helper_->SetUp(context_factory, context_factory_private); aura_test_helper_->SetUp(context_factory, context_factory_private);
aura::client::SetScreenPositionClient(aura_test_helper_->root_window(),
&screen_position_client_);
registry_.AddInterface(base::BindRepeating( registry_.AddInterface(base::BindRepeating(
&TestWindowService::BindServiceFactory, base::Unretained(this))); &TestWindowService::BindServiceFactory, base::Unretained(this)));
} }
...@@ -209,6 +229,11 @@ class TestWindowService : public service_manager::Service, ...@@ -209,6 +229,11 @@ class TestWindowService : public service_manager::Service,
std::unique_ptr<aura::test::AuraTestHelper> aura_test_helper_; std::unique_ptr<aura::test::AuraTestHelper> aura_test_helper_;
std::unique_ptr<WindowTreeHostFactory> window_tree_host_factory_; std::unique_ptr<WindowTreeHostFactory> window_tree_host_factory_;
// For drag and drop code to convert to/from screen coordinates.
wm::DefaultScreenPositionClient screen_position_client_;
TestDragDropClient drag_drop_client_;
bool started_ = false; bool started_ = false;
bool ui_service_created_ = false; bool ui_service_created_ = false;
......
...@@ -147,8 +147,7 @@ void DragTest_Part1(ui::mojom::EventInjector* event_injector, ...@@ -147,8 +147,7 @@ void DragTest_Part1(ui::mojom::EventInjector* event_injector,
display_id, quit_closure)); display_id, quit_closure));
} }
// TODO(http://crbug.com/864616): Hangs indefinitely in mus with ws2. TEST_F(DragTestInteractive, DragTest) {
TEST_F(DragTestInteractive, DISABLED_DragTest) {
ui::mojom::EventInjectorPtr event_injector; ui::mojom::EventInjectorPtr event_injector;
MusClient::Get()->window_tree_client()->connector()->BindInterface( MusClient::Get()->window_tree_client()->connector()->BindInterface(
ui::mojom::kServiceName, &event_injector); ui::mojom::kServiceName, &event_injector);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment