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

Unified Diff: chrome/test/base/interactive_test_utils_mac.mm

Issue 1747803003: MacViews: Implement Tab Dragging (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Remove CGEvent-generating code from ui_controls_mac.mm Created 4 years, 7 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
Index: chrome/test/base/interactive_test_utils_mac.mm
diff --git a/chrome/test/base/interactive_test_utils_mac.mm b/chrome/test/base/interactive_test_utils_mac.mm
index 0d00f3a6614e3aacd4c9141ed971ae02590ea1d1..7cdf0cf10a5ac2081afc079f3a0fb17dd61f39b4 100644
--- a/chrome/test/base/interactive_test_utils_mac.mm
+++ b/chrome/test/base/interactive_test_utils_mac.mm
@@ -7,12 +7,73 @@
#include <Carbon/Carbon.h>
#import <Cocoa/Cocoa.h>
-#include "base/message_loop/message_loop.h"
#include "chrome/app/chrome_command_ids.h"
+#include "chrome/browser/ui/views/tabs/window_finder.h"
tapted 2016/06/01 11:29:55 remove?
themblsha 2016/06/03 17:42:08 Done.
#import "ui/base/test/windowed_nsnotification_observer.h"
+#include "ui/gfx/animation/tween.h"
namespace ui_test_utils {
+namespace {
+
+// Runs a list of drag and drop |operations| on a single RunLoop.
+//
+// We need to execute drag and drop operations as a batch, so the nested
+// RunMoveLoop()'s RunLoop is cancelled before the top-level one from which we
+// post the simulated events, otherwise we'll deadlock.
+class OperationRunner {
+ public:
+ static void Run(const std::list<DragAndDropOperation>& operations) {
+ OperationRunner runner(operations);
+ base::RunLoop run_loop;
+ runner.quit_closure_ = run_loop.QuitClosure();
+ base::MessageLoop::current()->PostTask(
+ FROM_HERE,
+ base::Bind(&OperationRunner::Next, base::Unretained(&runner)));
+ run_loop.Run();
+ }
+
+ private:
+ explicit OperationRunner(const std::list<DragAndDropOperation>& operations)
+ : operations_(operations) {}
+
+ void Next() {
+ if (operations_.empty()) {
+ base::MessageLoop::current()->PostTask(FROM_HERE, quit_closure_);
+ return;
+ }
+
+ const DragAndDropOperation& op = operations_.front();
+ operations_.pop_front();
tapted 2016/06/01 11:29:55 move this to the end of the function, or don't use
themblsha 2016/06/03 17:42:07 ohshi, thanks! Wonder why it wasn't crashing on me
+ auto next = base::Bind(&OperationRunner::Next, base::Unretained(this));
+ switch (op.type()) {
+ case DragAndDropOperation::Type::Move:
+ ui_controls::SendMouseMoveNotifyWhenDone(op.point().x(), op.point().y(),
+ next);
+ break;
+
+ case DragAndDropOperation::Type::MouseDown:
+ ui_controls::SendMouseEventsNotifyWhenDone(ui_controls::LEFT,
+ ui_controls::DOWN, next);
+ break;
+
+ case DragAndDropOperation::Type::MouseUp:
+ ui_controls::SendMouseEventsNotifyWhenDone(ui_controls::LEFT,
+ ui_controls::UP, next);
+ break;
+ }
+ }
+
+ ~OperationRunner() { DCHECK(operations_.empty()); }
+
+ base::Closure quit_closure_;
+ std::list<DragAndDropOperation> operations_;
+
+ DISALLOW_COPY_AND_ASSIGN(OperationRunner);
+};
+
+} // namespace
+
void HideNativeWindow(gfx::NativeWindow window) {
[window orderOut:nil];
}
@@ -44,4 +105,40 @@ bool ShowAndFocusNativeWindow(gfx::NativeWindow window) {
return !async_waiter || notification_observed;
}
+void DragAndDropSequence(const std::list<DragAndDropOperation>& operations) {
tapted 2016/06/01 11:29:55 nit: order should match the header: - move everyt
themblsha 2016/06/03 17:42:08 Thanks. It's so easy to miss, isn't there an autom
tapted 2016/06/06 07:12:36 Sadly not :/
+ OperationRunner::Run(operations);
+}
+
+void DragAndDrop(const gfx::Point& from, const gfx::Point& to, int steps) {
+ DCHECK_GE(steps, 1);
+ std::list<DragAndDropOperation> operations;
+ operations.push_back(DragAndDropOperation::Move(from));
+ operations.push_back(DragAndDropOperation::MouseDown());
+
+ for (int i = 1; i <= steps; ++i) {
+ const double progress = static_cast<double>(i) / steps;
+ operations.push_back(DragAndDropOperation::Move(
+ gfx::Point(gfx::Tween::IntValueBetween(progress, from.x(), to.x()),
+ gfx::Tween::IntValueBetween(progress, from.y(), to.y()))));
+ }
+
+ operations.push_back(DragAndDropOperation::MouseUp());
+ DragAndDropSequence(operations);
+}
+
+// static
+DragAndDropOperation DragAndDropOperation::Move(const gfx::Point& p) {
+ return DragAndDropOperation(Type::Move, p);
+}
+
+// static
+DragAndDropOperation DragAndDropOperation::MouseDown() {
+ return DragAndDropOperation(Type::MouseDown, gfx::Point());
+}
+
+// static
+DragAndDropOperation DragAndDropOperation::MouseUp() {
+ return DragAndDropOperation(Type::MouseUp, gfx::Point());
+}
+
} // namespace ui_test_utils

Powered by Google App Engine
This is Rietveld 408576698