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 #include "chrome/test/base/interactive_test_utils.h" | 5 #include "chrome/test/base/interactive_test_utils.h" |
6 | 6 |
7 #include "chrome/browser/ui/browser.h" | 7 #include "chrome/browser/ui/browser.h" |
8 #include "chrome/browser/ui/browser_window.h" | 8 #include "chrome/browser/ui/browser_window.h" |
9 | 9 |
10 namespace ui_test_utils { | 10 namespace ui_test_utils { |
(...skipping 30 matching lines...) Expand all Loading... |
41 return false; | 41 return false; |
42 return SendKeyPressToWindowSync(window, key, control, shift, alt, command); | 42 return SendKeyPressToWindowSync(window, key, control, shift, alt, command); |
43 } | 43 } |
44 | 44 |
45 bool SendKeyPressToWindowSync(const gfx::NativeWindow window, | 45 bool SendKeyPressToWindowSync(const gfx::NativeWindow window, |
46 ui::KeyboardCode key, | 46 ui::KeyboardCode key, |
47 bool control, | 47 bool control, |
48 bool shift, | 48 bool shift, |
49 bool alt, | 49 bool alt, |
50 bool command) { | 50 bool command) { |
51 scoped_refptr<content::MessageLoopRunner> runner = | 51 base::RunLoop run_loop; |
52 new content::MessageLoopRunner; | |
53 bool result; | 52 bool result; |
54 result = ui_controls::SendKeyPressNotifyWhenDone( | 53 result = ui_controls::SendKeyPressNotifyWhenDone( |
55 window, key, control, shift, alt, command, runner->QuitClosure()); | 54 window, key, control, shift, alt, command, run_loop.QuitClosure()); |
56 #if defined(OS_WIN) | 55 #if defined(OS_WIN) |
57 if (!result && ui_test_utils::ShowAndFocusNativeWindow(window)) { | 56 if (!result && ui_test_utils::ShowAndFocusNativeWindow(window)) { |
58 result = ui_controls::SendKeyPressNotifyWhenDone( | 57 result = ui_controls::SendKeyPressNotifyWhenDone( |
59 window, key, control, shift, alt, command, runner->QuitClosure()); | 58 window, key, control, shift, alt, command, run_loop.QuitClosure()); |
60 } | 59 } |
61 #endif | 60 #endif |
62 if (!result) { | 61 if (!result) { |
63 LOG(ERROR) << "ui_controls::SendKeyPressNotifyWhenDone failed"; | 62 LOG(ERROR) << "ui_controls::SendKeyPressNotifyWhenDone failed"; |
64 return false; | 63 return false; |
65 } | 64 } |
66 | 65 |
67 // Run the message loop. It'll stop running when either the key was received | 66 // Run the message loop. It'll stop running when either the key was received |
68 // or the test timed out (in which case testing::Test::HasFatalFailure should | 67 // or the test timed out (in which case testing::Test::HasFatalFailure should |
69 // be set). | 68 // be set). |
70 runner->Run(); | 69 run_loop.Run(); |
71 return !testing::Test::HasFatalFailure(); | 70 return !testing::Test::HasFatalFailure(); |
72 } | 71 } |
73 | 72 |
74 bool SendKeyPressAndWait(const Browser* browser, | 73 bool SendKeyPressAndWait(const Browser* browser, |
75 ui::KeyboardCode key, | 74 ui::KeyboardCode key, |
76 bool control, | 75 bool control, |
77 bool shift, | 76 bool shift, |
78 bool alt, | 77 bool alt, |
79 bool command, | 78 bool command, |
80 int type, | 79 int type, |
81 const content::NotificationSource& source) { | 80 const content::NotificationSource& source) { |
82 content::WindowedNotificationObserver observer(type, source); | 81 content::WindowedNotificationObserver observer(type, source); |
83 | 82 |
84 if (!SendKeyPressSync(browser, key, control, shift, alt, command)) | 83 if (!SendKeyPressSync(browser, key, control, shift, alt, command)) |
85 return false; | 84 return false; |
86 | 85 |
87 observer.Wait(); | 86 observer.Wait(); |
88 return !testing::Test::HasFatalFailure(); | 87 return !testing::Test::HasFatalFailure(); |
89 } | 88 } |
90 | 89 |
91 bool SendMouseMoveSync(const gfx::Point& location) { | 90 bool SendMouseMoveSync(const gfx::Point& location) { |
92 scoped_refptr<content::MessageLoopRunner> runner = | 91 base::RunLoop run_loop; |
93 new content::MessageLoopRunner; | |
94 if (!ui_controls::SendMouseMoveNotifyWhenDone( | 92 if (!ui_controls::SendMouseMoveNotifyWhenDone( |
95 location.x(), location.y(), runner->QuitClosure())) { | 93 location.x(), location.y(), run_loop.QuitClosure())) { |
96 return false; | 94 return false; |
97 } | 95 } |
98 runner->Run(); | 96 run_loop.Run(); |
99 return !testing::Test::HasFatalFailure(); | 97 return !testing::Test::HasFatalFailure(); |
100 } | 98 } |
101 | 99 |
102 bool SendMouseEventsSync(ui_controls::MouseButton type, int state) { | 100 bool SendMouseEventsSync(ui_controls::MouseButton type, int state) { |
103 scoped_refptr<content::MessageLoopRunner> runner = | 101 base::RunLoop run_loop; |
104 new content::MessageLoopRunner; | |
105 if (!ui_controls::SendMouseEventsNotifyWhenDone( | 102 if (!ui_controls::SendMouseEventsNotifyWhenDone( |
106 type, state, runner->QuitClosure())) { | 103 type, state, run_loop.QuitClosure())) { |
107 return false; | 104 return false; |
108 } | 105 } |
109 runner->Run(); | 106 run_loop.Run(); |
110 return !testing::Test::HasFatalFailure(); | 107 return !testing::Test::HasFatalFailure(); |
111 } | 108 } |
112 | 109 |
113 namespace internal { | 110 namespace internal { |
114 | 111 |
115 void ClickTask(ui_controls::MouseButton button, | 112 void ClickTask(ui_controls::MouseButton button, |
116 int state, | 113 int state, |
117 const base::Closure& followup) { | 114 const base::Closure& followup) { |
118 if (!followup.is_null()) | 115 if (!followup.is_null()) |
119 ui_controls::SendMouseEventsNotifyWhenDone(button, state, followup); | 116 ui_controls::SendMouseEventsNotifyWhenDone(button, state, followup); |
120 else | 117 else |
121 ui_controls::SendMouseEvents(button, state); | 118 ui_controls::SendMouseEvents(button, state); |
122 } | 119 } |
123 | 120 |
124 } // namespace internal | 121 } // namespace internal |
125 | 122 |
126 } // namespace ui_test_utils | 123 } // namespace ui_test_utils |
OLD | NEW |