OLD | NEW |
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 #ifndef CHROME_TEST_BASE_INTERACTIVE_TEST_UTILS_H_ | 5 #ifndef CHROME_TEST_BASE_INTERACTIVE_TEST_UTILS_H_ |
6 #define CHROME_TEST_BASE_INTERACTIVE_TEST_UTILS_H_ | 6 #define CHROME_TEST_BASE_INTERACTIVE_TEST_UTILS_H_ |
7 | 7 |
8 #include "chrome/browser/ui/view_ids.h" | 8 #include "chrome/browser/ui/view_ids.h" |
9 #include "chrome/test/base/ui_test_utils.h" | 9 #include "chrome/test/base/ui_test_utils.h" |
10 #include "ui/base/test/ui_controls.h" | 10 #include "ui/base/test/ui_controls.h" |
11 | 11 #include "ui/gfx/geometry/point.h" |
12 namespace gfx { | |
13 class Point; | |
14 } | |
15 | 12 |
16 #if defined(TOOLKIT_VIEWS) | 13 #if defined(TOOLKIT_VIEWS) |
17 namespace views { | 14 namespace views { |
18 class View; | 15 class View; |
19 } | 16 } |
20 #endif | 17 #endif |
21 | 18 |
22 namespace ui_test_utils { | 19 namespace ui_test_utils { |
23 | 20 |
| 21 #if defined(OS_MACOSX) |
| 22 // Moves the mouse to the |from| position, presses left mouse button, |
| 23 // then moves mouse to the |to| position and releases left mouse button. |
| 24 // |steps| indicates number of intermediate points that are interpolated between |
| 25 // |from| and |to|. |
| 26 void DragAndDrop(const gfx::Point& from, const gfx::Point& to, int steps = 1); |
| 27 |
| 28 class DragAndDropOperation { |
| 29 public: |
| 30 enum class Type { |
| 31 Move, |
| 32 MoveWithoutAck, |
| 33 MouseDown, |
| 34 MouseUp, |
| 35 SetMousePositionOverride, |
| 36 UnsetMousePositionOverride, |
| 37 DebugDelay |
| 38 }; |
| 39 |
| 40 static DragAndDropOperation Move(const gfx::Point& p); |
| 41 // Doesn't wait for the event to finish processing, instead it waits for |
| 42 // |delay|. |
| 43 static DragAndDropOperation MoveWithoutAck(const gfx::Point& p, |
| 44 const base::TimeDelta& delay); |
| 45 static DragAndDropOperation MouseDown(); |
| 46 static DragAndDropOperation MouseUp(); |
| 47 static DragAndDropOperation SetMousePositionOverride(const gfx::Point& p); |
| 48 static DragAndDropOperation UnsetMousePositionOverride(); |
| 49 static DragAndDropOperation DebugDelay(); |
| 50 |
| 51 Type type() const { return type_; } |
| 52 const gfx::Point& point() const { return point_; } |
| 53 const base::TimeDelta& delay() const { return delay_; } |
| 54 |
| 55 private: |
| 56 DragAndDropOperation(Type type, |
| 57 const gfx::Point& p, |
| 58 const base::TimeDelta& delay = base::TimeDelta()) |
| 59 : type_(type), point_(p), delay_(delay) {} |
| 60 |
| 61 Type type_; |
| 62 gfx::Point point_; |
| 63 base::TimeDelta delay_; |
| 64 }; |
| 65 |
| 66 // Performs a series of drag-and-drop operations on a background thread, while |
| 67 // spinning a RunLoop on the main thread. If there are nested eventloops on the |
| 68 // main thread's queue, our helper RunLoop won't quit and we'll get stuck. |
| 69 // BridgedNativeWidget::RunMoveLoop() creates a RunLoop, so we need to ensure |
| 70 // that Drag'n'Drop is finished before trying to return from the function. |
| 71 void DragAndDrop(const std::list<DragAndDropOperation>& operations); |
| 72 #endif // OS_MACOSX |
| 73 |
24 // Brings the native window for |browser| to the foreground. Returns true on | 74 // Brings the native window for |browser| to the foreground. Returns true on |
25 // success. | 75 // success. |
26 bool BringBrowserWindowToFront(const Browser* browser) WARN_UNUSED_RESULT; | 76 bool BringBrowserWindowToFront(const Browser* browser) WARN_UNUSED_RESULT; |
27 | 77 |
28 // Returns true if the View is focused. | 78 // Returns true if the View is focused. |
29 bool IsViewFocused(const Browser* browser, ViewID vid); | 79 bool IsViewFocused(const Browser* browser, ViewID vid); |
30 | 80 |
31 // Simulates a mouse click on a View in the browser. | 81 // Simulates a mouse click on a View in the browser. |
32 void ClickOnView(const Browser* browser, ViewID vid); | 82 void ClickOnView(const Browser* browser, ViewID vid); |
33 | 83 |
(...skipping 109 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
143 // ui_controls_linux.cc and ui_controls_mac.cc | 193 // ui_controls_linux.cc and ui_controls_mac.cc |
144 void ClickTask(ui_controls::MouseButton button, | 194 void ClickTask(ui_controls::MouseButton button, |
145 int state, | 195 int state, |
146 const base::Closure& followup); | 196 const base::Closure& followup); |
147 | 197 |
148 } // namespace internal | 198 } // namespace internal |
149 | 199 |
150 } // namespace ui_test_utils | 200 } // namespace ui_test_utils |
151 | 201 |
152 #endif // CHROME_TEST_BASE_INTERACTIVE_TEST_UTILS_H_ | 202 #endif // CHROME_TEST_BASE_INTERACTIVE_TEST_UTILS_H_ |
OLD | NEW |