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

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: Created 4 years, 9 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/message_loop/message_loop.h"
11 #include "chrome/app/chrome_command_ids.h" 11 #include "chrome/app/chrome_command_ids.h"
12 #include "content/public/test/test_utils.h"
12 #import "ui/base/test/windowed_nsnotification_observer.h" 13 #import "ui/base/test/windowed_nsnotification_observer.h"
14 #include "ui/gfx/animation/tween.h"
15
16 namespace {
17
18 bool WaitForEvent(
19 bool (^dispatch_event_block)(const base::Closure& quit_closure)) {
20 scoped_refptr<content::MessageLoopRunner> runner =
21 new content::MessageLoopRunner;
22 bool result = dispatch_event_block(runner->QuitClosure());
23 runner->Run();
24 return result;
25 }
26
27 bool MouseMove(const gfx::Point& p) {
28 return WaitForEvent(^(const base::Closure& quit_closure) {
29 return ui_controls::SendMouseMoveNotifyWhenDone(p.x(), p.y(), quit_closure);
30 });
31 }
32
33 bool MouseDown() {
34 return WaitForEvent(^(const base::Closure& quit_closure) {
35 return ui_controls::SendMouseEventsNotifyWhenDone(
36 ui_controls::LEFT, ui_controls::DOWN, quit_closure);
37 });
38 }
39
40 bool MouseUp() {
41 return WaitForEvent(^(const base::Closure& quit_closure) {
42 return ui_controls::SendMouseEventsNotifyWhenDone(
43 ui_controls::LEFT, ui_controls::UP, quit_closure);
44 });
45 }
46
47 } // namespace
13 48
14 namespace ui_test_utils { 49 namespace ui_test_utils {
15 50
16 void HideNativeWindow(gfx::NativeWindow window) { 51 void HideNativeWindow(gfx::NativeWindow window) {
17 [window orderOut:nil]; 52 [window orderOut:nil];
18 } 53 }
19 54
20 bool ShowAndFocusNativeWindow(gfx::NativeWindow window) { 55 bool ShowAndFocusNativeWindow(gfx::NativeWindow window) {
21 // Make sure an unbundled program can get the input focus. 56 // Make sure an unbundled program can get the input focus.
22 ProcessSerialNumber psn = { 0, kCurrentProcess }; 57 ProcessSerialNumber psn = { 0, kCurrentProcess };
(...skipping 14 matching lines...) Expand all
37 // This is because normal AppKit menu updating does not get invoked when 72 // This is because normal AppKit menu updating does not get invoked when
38 // events are sent via ui_test_utils::SendKeyPressSync. 73 // events are sent via ui_test_utils::SendKeyPressSync.
39 BOOL notification_observed = [async_waiter wait]; 74 BOOL notification_observed = [async_waiter wait];
40 base::RunLoop().RunUntilIdle(); // There may be other events queued. Flush. 75 base::RunLoop().RunUntilIdle(); // There may be other events queued. Flush.
41 NSMenu* file_menu = [[[NSApp mainMenu] itemWithTag:IDC_FILE_MENU] submenu]; 76 NSMenu* file_menu = [[[NSApp mainMenu] itemWithTag:IDC_FILE_MENU] submenu];
42 [[file_menu delegate] menuNeedsUpdate:file_menu]; 77 [[file_menu delegate] menuNeedsUpdate:file_menu];
43 78
44 return !async_waiter || notification_observed; 79 return !async_waiter || notification_observed;
45 } 80 }
46 81
82 void DragAndDrop(const gfx::Point& from,
83 const gfx::Point& to,
84 base::TimeDelta delay) {
85 auto queue = dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0);
86 scoped_refptr<content::MessageLoopRunner> runner =
87 new content::MessageLoopRunner;
88
89 dispatch_async(queue, ^{
90 scoped_ptr<base::MessageLoop> loop(
91 new base::MessageLoop(base::MessageLoop::TYPE_DEFAULT));
92
93 MouseMove(from);
94 MouseDown();
95
96 // FIXME(mblsha): If we do the drag without an intermediate step, it won't
97 // actually work
98 const int steps = 2;
99 for (int i = 1; i <= steps; ++i) {
100 const double progress = double(i) / steps;
101 const gfx::Point p(
102 gfx::Tween::IntValueBetween(progress, from.x(), to.x()),
103 gfx::Tween::IntValueBetween(progress, from.y(), to.y()));
104 MouseMove(p);
105 }
106
107 // specify a delay if there's a non-zero drag'n'drop delay, like
108 // kTearDuration in tab_strip_drag_controller.mm
109 usleep(delay.InMicroseconds());
110
111 MouseUp();
112
113 dispatch_async(dispatch_get_main_queue(), ^{
114 runner->Quit();
115 });
116 });
117
118 // we need to run the loop on the main thread, so the mouse events will be
119 // actually processed
120 runner->Run();
121 }
122
47 } // namespace ui_test_utils 123 } // namespace ui_test_utils
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698