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

Side by Side Diff: chrome/test/base/interactive_test_utils_views.cc

Issue 2910033002: Fail tests that use ClickOnView() on an inactive window.
Patch Set: Fail more Created 3 years, 6 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
« no previous file with comments | « chrome/test/base/interactive_test_utils_cocoa.mm ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 "base/message_loop/message_loop.h" 7 #include "base/message_loop/message_loop.h"
8 #include "chrome/browser/ui/browser.h" 8 #include "chrome/browser/ui/browser.h"
9 #include "chrome/browser/ui/browser_window.h"
9 #include "chrome/browser/ui/views/frame/browser_view.h" 10 #include "chrome/browser/ui/views/frame/browser_view.h"
11 #include "testing/gtest/include/gtest/gtest.h"
10 #include "ui/views/focus/focus_manager.h" 12 #include "ui/views/focus/focus_manager.h"
11 13
12 namespace ui_test_utils { 14 namespace ui_test_utils {
13 15
14 bool IsViewFocused(const Browser* browser, ViewID vid) { 16 bool IsViewFocused(const Browser* browser, ViewID vid) {
15 BrowserWindow* browser_window = browser->window(); 17 BrowserWindow* browser_window = browser->window();
16 DCHECK(browser_window); 18 DCHECK(browser_window);
17 gfx::NativeWindow window = browser_window->GetNativeWindow(); 19 gfx::NativeWindow window = browser_window->GetNativeWindow();
18 DCHECK(window); 20 DCHECK(window);
19 const views::Widget* widget = views::Widget::GetWidgetForNativeWindow(window); 21 const views::Widget* widget = views::Widget::GetWidgetForNativeWindow(window);
20 DCHECK(widget); 22 DCHECK(widget);
21 const views::FocusManager* focus_manager = widget->GetFocusManager(); 23 const views::FocusManager* focus_manager = widget->GetFocusManager();
22 DCHECK(focus_manager); 24 DCHECK(focus_manager);
23 DCHECK(focus_manager->GetFocusedView()); 25 DCHECK(focus_manager->GetFocusedView());
24 return focus_manager->GetFocusedView()->id() == vid; 26 return focus_manager->GetFocusedView()->id() == vid;
25 } 27 }
26 28
27 void ClickOnView(const Browser* browser, ViewID vid) { 29 void ClickOnView(const Browser* browser, ViewID vid) {
28 views::View* view = 30 views::View* view =
29 BrowserView::GetBrowserViewForBrowser(browser)->GetViewByID(vid); 31 BrowserView::GetBrowserViewForBrowser(browser)->GetViewByID(vid);
32 // Fail tests that use ClickOnView() on an inactive window. Tests that do will
33 // flake too easily.
34 EXPECT_TRUE(browser->window()->IsActive())
35 << "ClickOnView() in an inactive window is not robust.";
30 DCHECK(view); 36 DCHECK(view);
31 MoveMouseToCenterAndPress(view, ui_controls::LEFT, 37 MoveMouseToCenterAndPress(view, ui_controls::LEFT,
32 ui_controls::DOWN | ui_controls::UP, 38 ui_controls::DOWN | ui_controls::UP,
33 base::MessageLoop::QuitWhenIdleClosure()); 39 base::MessageLoop::QuitWhenIdleClosure());
34 content::RunMessageLoop(); 40 content::RunMessageLoop();
35 } 41 }
36 42
37 void FocusView(const Browser* browser, ViewID vid) { 43 void FocusView(const Browser* browser, ViewID vid) {
38 views::View* view = 44 views::View* view =
39 BrowserView::GetBrowserViewForBrowser(browser)->GetViewByID(vid); 45 BrowserView::GetBrowserViewForBrowser(browser)->GetViewByID(vid);
40 DCHECK(view); 46 DCHECK(view);
41 view->RequestFocus(); 47 view->RequestFocus();
42 } 48 }
43 49
44 gfx::Point GetCenterInScreenCoordinates(const views::View* view) { 50 gfx::Point GetCenterInScreenCoordinates(const views::View* view) {
45 gfx::Point center(view->width() / 2, view->height() / 2); 51 gfx::Point center(view->width() / 2, view->height() / 2);
46 views::View::ConvertPointToScreen(view, &center); 52 views::View::ConvertPointToScreen(view, &center);
47 return center; 53 return center;
48 } 54 }
49 55
50 } // namespace ui_test_utils 56 } // namespace ui_test_utils
OLDNEW
« no previous file with comments | « chrome/test/base/interactive_test_utils_cocoa.mm ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698