OLD | NEW |
| (Empty) |
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 | |
3 // found in the LICENSE file. | |
4 | |
5 #include "chrome/test/base/ui_test_utils.h" | |
6 | |
7 #include "base/logging.h" | |
8 #include "base/message_loop.h" | |
9 #include "chrome/browser/ui/browser.h" | |
10 #include "chrome/browser/ui/browser_window.h" | |
11 #include "chrome/browser/ui/views/frame/browser_view.h" | |
12 #include "ui/aura/window.h" | |
13 #include "ui/ui_controls/ui_controls.h" | |
14 #include "ui/views/focus/focus_manager.h" | |
15 | |
16 namespace ui_test_utils { | |
17 | |
18 bool IsViewFocused(const Browser* browser, ViewID vid) { | |
19 BrowserWindow* browser_window = browser->window(); | |
20 DCHECK(browser_window); | |
21 gfx::NativeWindow window = browser_window->GetNativeWindow(); | |
22 DCHECK(window); | |
23 const views::Widget* widget = | |
24 views::Widget::GetTopLevelWidgetForNativeView(window); | |
25 DCHECK(widget); | |
26 const views::FocusManager* focus_manager = widget->GetFocusManager(); | |
27 DCHECK(focus_manager); | |
28 DCHECK(focus_manager->GetFocusedView()); | |
29 return focus_manager->GetFocusedView()->id() == vid; | |
30 } | |
31 | |
32 void ClickOnView(const Browser* browser, ViewID vid) { | |
33 BrowserWindow* browser_window = browser->window(); | |
34 DCHECK(browser_window); | |
35 views::View* view = | |
36 reinterpret_cast<BrowserView*>(browser_window)->GetViewByID(vid); | |
37 DCHECK(view); | |
38 MoveMouseToCenterAndPress( | |
39 view, | |
40 ui_controls::LEFT, | |
41 ui_controls::DOWN | ui_controls::UP, | |
42 MessageLoop::QuitClosure()); | |
43 content::RunMessageLoop(); | |
44 } | |
45 | |
46 void HideNativeWindow(gfx::NativeWindow window) { | |
47 window->Hide(); | |
48 } | |
49 | |
50 bool ShowAndFocusNativeWindow(gfx::NativeWindow window) { | |
51 window->Show(); | |
52 return true; | |
53 } | |
54 | |
55 void MoveMouseToCenterAndPress(views::View* view, | |
56 ui_controls::MouseButton button, | |
57 int state, | |
58 const base::Closure& closure) { | |
59 DCHECK(view); | |
60 DCHECK(view->GetWidget()); | |
61 gfx::Point view_center(view->width() / 2, view->height() / 2); | |
62 views::View::ConvertPointToScreen(view, &view_center); | |
63 ui_controls::SendMouseMove(view_center.x(), view_center.y()); | |
64 ui_controls::SendMouseEventsNotifyWhenDone(button, state, closure); | |
65 } | |
66 | |
67 } // namespace ui_test_utils | |
OLD | NEW |