| 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/views/frame/browser_view.h" | |
| 11 #include "ui/ui_controls/ui_controls.h" | |
| 12 #include "ui/views/focus/focus_manager.h" | |
| 13 | |
| 14 namespace ui_test_utils { | |
| 15 | |
| 16 bool IsViewFocused(const Browser* browser, ViewID vid) { | |
| 17 BrowserWindow* browser_window = browser->window(); | |
| 18 DCHECK(browser_window); | |
| 19 gfx::NativeWindow window = browser_window->GetNativeWindow(); | |
| 20 DCHECK(window); | |
| 21 const views::Widget* widget = | |
| 22 views::Widget::GetTopLevelWidgetForNativeView(window); | |
| 23 DCHECK(widget); | |
| 24 const views::FocusManager* focus_manager = widget->GetFocusManager(); | |
| 25 DCHECK(focus_manager); | |
| 26 DCHECK(focus_manager->GetFocusedView()); | |
| 27 return focus_manager->GetFocusedView()->id() == vid; | |
| 28 } | |
| 29 | |
| 30 void ClickOnView(const Browser* browser, ViewID vid) { | |
| 31 views::View* view = | |
| 32 BrowserView::GetBrowserViewForBrowser(browser)->GetViewByID(vid); | |
| 33 DCHECK(view); | |
| 34 MoveMouseToCenterAndPress( | |
| 35 view, | |
| 36 ui_controls::LEFT, | |
| 37 ui_controls::DOWN | ui_controls::UP, | |
| 38 MessageLoop::QuitClosure()); | |
| 39 content::RunMessageLoop(); | |
| 40 } | |
| 41 | |
| 42 void MoveMouseToCenterAndPress(views::View* view, | |
| 43 ui_controls::MouseButton button, | |
| 44 int state, | |
| 45 const base::Closure& closure) { | |
| 46 DCHECK(view); | |
| 47 DCHECK(view->GetWidget()); | |
| 48 gfx::Point view_center(view->width() / 2, view->height() / 2); | |
| 49 views::View::ConvertPointToScreen(view, &view_center); | |
| 50 ui_controls::SendMouseMove(view_center.x(), view_center.y()); | |
| 51 ui_controls::SendMouseEventsNotifyWhenDone(button, state, closure); | |
| 52 } | |
| 53 | |
| 54 } // namespace ui_test_utils | |
| OLD | NEW |