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

Side by Side 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: Fix review issues. Created 4 years, 6 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 unified diff | Download patch
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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 "chrome/test/base/interactive_test_utils.h" 5 #include "chrome/test/base/interactive_test_utils.h"
6 6
7 #include <Carbon/Carbon.h> 7 #include <Carbon/Carbon.h>
8 #import <Cocoa/Cocoa.h> 8 #import <Cocoa/Cocoa.h>
9 9
10 #include "base/message_loop/message_loop.h" 10 #include "base/threading/thread_task_runner_handle.h"
11 #include "chrome/app/chrome_command_ids.h" 11 #include "chrome/app/chrome_command_ids.h"
12 #import "ui/base/test/windowed_nsnotification_observer.h" 12 #import "ui/base/test/windowed_nsnotification_observer.h"
13 #include "ui/gfx/animation/tween.h"
13 14
14 namespace ui_test_utils { 15 namespace ui_test_utils {
15 16
17 namespace {
18
19 // Runs a list of drag and drop |operations| on a single RunLoop.
20 //
21 // We need to execute drag and drop operations as a batch, so the nested
22 // RunMoveLoop()'s RunLoop is cancelled before the top-level one from which we
23 // post the simulated events, otherwise we'll deadlock.
24 class OperationRunner {
25 public:
26 static void Run(const std::list<DragAndDropOperation>& operations) {
27 OperationRunner runner(operations);
28 base::RunLoop run_loop;
29 runner.quit_closure_ = run_loop.QuitClosure();
30 base::ThreadTaskRunnerHandle::Get()->PostTask(
31 FROM_HERE,
32 base::Bind(&OperationRunner::Next, base::Unretained(&runner)));
33 run_loop.Run();
34 }
35
36 private:
37 explicit OperationRunner(const std::list<DragAndDropOperation>& operations)
38 : operations_(operations) {}
39
40 void Next() {
41 if (operations_.empty()) {
42 base::ThreadTaskRunnerHandle::Get()->PostTask(FROM_HERE, quit_closure_);
43 return;
44 }
45
46 const DragAndDropOperation op = operations_.front();
47 operations_.pop_front();
48 auto next = base::Bind(&OperationRunner::Next, base::Unretained(this));
49 switch (op.type()) {
50 case DragAndDropOperation::Type::Move:
51 ui_controls::SendMouseMoveNotifyWhenDone(op.point().x(), op.point().y(),
52 next);
53 break;
54
55 case DragAndDropOperation::Type::MouseDown:
56 ui_controls::SendMouseEventsNotifyWhenDone(ui_controls::LEFT,
57 ui_controls::DOWN, next);
58 break;
59
60 case DragAndDropOperation::Type::MouseUp:
61 ui_controls::SendMouseEventsNotifyWhenDone(ui_controls::LEFT,
62 ui_controls::UP, next);
63 break;
64 }
65 }
66
67 ~OperationRunner() { DCHECK(operations_.empty()); }
68
69 base::Closure quit_closure_;
70 std::list<DragAndDropOperation> operations_;
71
72 DISALLOW_COPY_AND_ASSIGN(OperationRunner);
73 };
74
75 } // namespace
76
77 // static
78 DragAndDropOperation DragAndDropOperation::Move(const gfx::Point& p) {
79 return DragAndDropOperation(Type::Move, p);
80 }
81
82 // static
83 DragAndDropOperation DragAndDropOperation::MouseDown() {
84 return DragAndDropOperation(Type::MouseDown, gfx::Point());
85 }
86
87 // static
88 DragAndDropOperation DragAndDropOperation::MouseUp() {
89 return DragAndDropOperation(Type::MouseUp, gfx::Point());
90 }
91
92 void DragAndDropSequence(const std::list<DragAndDropOperation>& operations) {
93 OperationRunner::Run(operations);
94 }
95
96 void DragAndDrop(const gfx::Point& from, const gfx::Point& to, int steps) {
97 DCHECK_GE(steps, 1);
98 std::list<DragAndDropOperation> operations;
99 operations.push_back(DragAndDropOperation::Move(from));
100 operations.push_back(DragAndDropOperation::MouseDown());
101
102 for (int i = 1; i <= steps; ++i) {
103 const double progress = static_cast<double>(i) / steps;
104 operations.push_back(DragAndDropOperation::Move(
105 gfx::Point(gfx::Tween::IntValueBetween(progress, from.x(), to.x()),
106 gfx::Tween::IntValueBetween(progress, from.y(), to.y()))));
107 }
108
109 operations.push_back(DragAndDropOperation::MouseUp());
110 DragAndDropSequence(operations);
111 }
112
16 void HideNativeWindow(gfx::NativeWindow window) { 113 void HideNativeWindow(gfx::NativeWindow window) {
17 [window orderOut:nil]; 114 [window orderOut:nil];
18 } 115 }
19 116
20 bool ShowAndFocusNativeWindow(gfx::NativeWindow window) { 117 bool ShowAndFocusNativeWindow(gfx::NativeWindow window) {
21 // Make sure an unbundled program can get the input focus. 118 // Make sure an unbundled program can get the input focus.
22 ProcessSerialNumber psn = { 0, kCurrentProcess }; 119 ProcessSerialNumber psn = { 0, kCurrentProcess };
23 TransformProcessType(&psn,kProcessTransformToForegroundApplication); 120 TransformProcessType(&psn,kProcessTransformToForegroundApplication);
24 SetFrontProcess(&psn); 121 SetFrontProcess(&psn);
25 122
(...skipping 12 matching lines...) Expand all
38 // events are sent via ui_test_utils::SendKeyPressSync. 135 // events are sent via ui_test_utils::SendKeyPressSync.
39 BOOL notification_observed = [async_waiter wait]; 136 BOOL notification_observed = [async_waiter wait];
40 base::RunLoop().RunUntilIdle(); // There may be other events queued. Flush. 137 base::RunLoop().RunUntilIdle(); // There may be other events queued. Flush.
41 NSMenu* file_menu = [[[NSApp mainMenu] itemWithTag:IDC_FILE_MENU] submenu]; 138 NSMenu* file_menu = [[[NSApp mainMenu] itemWithTag:IDC_FILE_MENU] submenu];
42 [[file_menu delegate] menuNeedsUpdate:file_menu]; 139 [[file_menu delegate] menuNeedsUpdate:file_menu];
43 140
44 return !async_waiter || notification_observed; 141 return !async_waiter || notification_observed;
45 } 142 }
46 143
47 } // namespace ui_test_utils 144 } // namespace ui_test_utils
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698