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

Unified Diff: chrome/browser/ui/views/drag_and_drop_interactive_uitest_aura.cc

Issue 2622733002: Mac Support for drag-and-drop tests that start dragging via mouse simulation.
Patch Set: . Created 3 years, 11 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « chrome/browser/ui/views/drag_and_drop_interactive_uitest.cc ('k') | chrome/test/BUILD.gn » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: chrome/browser/ui/views/drag_and_drop_interactive_uitest_aura.cc
diff --git a/chrome/browser/ui/views/drag_and_drop_interactive_uitest_aura.cc b/chrome/browser/ui/views/drag_and_drop_interactive_uitest_aura.cc
new file mode 100644
index 0000000000000000000000000000000000000000..f9cb89ca2ee332285368a6f47a387568842d33fe
--- /dev/null
+++ b/chrome/browser/ui/views/drag_and_drop_interactive_uitest_aura.cc
@@ -0,0 +1,135 @@
+// Copyright 2016 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 "chrome/browser/ui/views/drag_and_drop_interactive_uitest.h"
+
+#include "base/macros.h"
+#include "base/memory/ptr_util.h"
+#include "base/strings/utf_string_conversions.h"
+#include "content/public/browser/web_contents.h"
+#include "testing/gtest/include/gtest/gtest.h"
+#include "ui/aura/client/drag_drop_delegate.h"
+#include "ui/aura/window.h"
+#include "ui/base/dragdrop/drag_drop_types.h"
+#include "ui/base/dragdrop/drop_target_event.h"
+#include "ui/base/dragdrop/os_exchange_data.h"
+#include "ui/gfx/geometry/point.h"
+
+namespace {
+
+// Test helper for simulating drag and drop happening in WebContents.
+class ExternalDragEnterSimulatorAura : public ExternalDragEnterSimulator {
+ public:
+ explicit ExternalDragEnterSimulatorAura(content::WebContents* web_contents)
+ : web_contents_(web_contents) {}
+
+ ~ExternalDragEnterSimulatorAura() override {}
+
+ bool SimulateDragEnter(const gfx::Point& location,
+ const std::string& text) override;
+ bool SimulateDrop(const gfx::Point& location) override;
+
+ private:
+ bool SimulateDragEnter(const gfx::Point& location,
+ const ui::OSExchangeData& data);
+ aura::client::DragDropDelegate* GetDragDropDelegate();
+ void CalculateEventLocations(gfx::Point web_contents_relative_location,
+ gfx::Point* out_event_location,
+ gfx::Point* out_event_root_location);
+
+ // These are ui::DropTargetEvent::source_operations_ being sent when manually
+ // trying out drag&drop of an image file from Nemo (Ubuntu's file explorer)
+ // into a content_shell.
+ static constexpr int kDefaultSourceOperations = ui::DragDropTypes::DRAG_MOVE |
+ ui::DragDropTypes::DRAG_COPY |
+ ui::DragDropTypes::DRAG_LINK;
+
+ content::WebContents* web_contents_;
+ std::unique_ptr<ui::DropTargetEvent> active_drag_event_;
+
+ DISALLOW_COPY_AND_ASSIGN(ExternalDragEnterSimulatorAura);
+};
+
+bool ExternalDragEnterSimulatorAura::SimulateDragEnter(
+ const gfx::Point& location,
+ const std::string& text) {
+ ui::OSExchangeData data;
+ data.SetString(base::UTF8ToUTF16(text));
+ return SimulateDragEnter(location, data);
+}
+
+bool ExternalDragEnterSimulatorAura::SimulateDrop(const gfx::Point& location) {
+ if (!active_drag_event_) {
+ ADD_FAILURE() << "Cannot drop a drag that hasn't started yet.";
+ return false;
+ }
+
+ aura::client::DragDropDelegate* delegate = GetDragDropDelegate();
+ if (!delegate)
+ return false;
+
+ gfx::Point event_location;
+ gfx::Point event_root_location;
+ CalculateEventLocations(location, &event_location, &event_root_location);
+ active_drag_event_->set_location(event_location);
+ active_drag_event_->set_root_location(event_root_location);
+
+ delegate->OnDragUpdated(*active_drag_event_);
+ delegate->OnPerformDrop(*active_drag_event_);
+ return true;
+}
+
+bool ExternalDragEnterSimulatorAura::SimulateDragEnter(
+ const gfx::Point& location,
+ const ui::OSExchangeData& data) {
+ if (active_drag_event_) {
+ ADD_FAILURE() << "Cannot start a new drag when old one hasn't ended yet.";
+ return false;
+ }
+
+ aura::client::DragDropDelegate* delegate = GetDragDropDelegate();
+ if (!delegate)
+ return false;
+
+ gfx::Point event_location;
+ gfx::Point event_root_location;
+ CalculateEventLocations(location, &event_location, &event_root_location);
+ active_drag_event_.reset(new ui::DropTargetEvent(
+ data, event_location, event_root_location, kDefaultSourceOperations));
+
+ delegate->OnDragEntered(*active_drag_event_);
+ delegate->OnDragUpdated(*active_drag_event_);
+ return true;
+}
+
+aura::client::DragDropDelegate*
+ExternalDragEnterSimulatorAura::GetDragDropDelegate() {
+ gfx::NativeView view = web_contents_->GetContentNativeView();
+ aura::client::DragDropDelegate* delegate =
+ aura::client::GetDragDropDelegate(view);
+ EXPECT_TRUE(delegate) << "Expecting WebContents to have DragDropDelegate";
+ return delegate;
+}
+
+void ExternalDragEnterSimulatorAura::CalculateEventLocations(
+ gfx::Point web_contents_relative_location,
+ gfx::Point* out_event_location,
+ gfx::Point* out_event_root_location) {
+ gfx::NativeView view = web_contents_->GetNativeView();
+
+ *out_event_location = web_contents_relative_location;
+
+ gfx::Point root_location = web_contents_relative_location;
+ aura::Window::ConvertPointToTarget(view, view->GetRootWindow(),
+ &root_location);
+ *out_event_root_location = root_location;
+}
+
+} // namespace
+
+// static
+std::unique_ptr<ExternalDragEnterSimulator> ExternalDragEnterSimulator::Create(
+ content::WebContents* web_contents) {
+ return base::WrapUnique(new ExternalDragEnterSimulatorAura(web_contents));
+}
« no previous file with comments | « chrome/browser/ui/views/drag_and_drop_interactive_uitest.cc ('k') | chrome/test/BUILD.gn » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698