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

Side by Side Diff: chrome/test/ui_test_utils_linux.cc

Issue 1576008: Enable interactive_ui_tests (Closed)
Patch Set: include Created 10 years, 8 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/interactive_ui/view_event_test_base.cc ('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) 2009 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2009 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/ui_test_utils.h" 5 #include "chrome/test/ui_test_utils.h"
6 6
7 #include <gtk/gtk.h> 7 #include <gtk/gtk.h>
8 8
9 #include "base/logging.h" 9 #include "base/logging.h"
10 #include "base/message_loop.h" 10 #include "base/message_loop.h"
11 #include "chrome/browser/browser.h" 11 #include "chrome/browser/browser.h"
12 #include "chrome/browser/browser_window.h" 12 #include "chrome/browser/browser_window.h"
13 #include "chrome/browser/automation/ui_controls.h" 13 #include "chrome/browser/automation/ui_controls.h"
14 #if defined(TOOLKIT_VIEWS) 14 #if defined(TOOLKIT_VIEWS)
15 #include "chrome/browser/views/frame/browser_view.h" 15 #include "chrome/browser/views/frame/browser_view.h"
16 #include "views/focus/focus_manager.h"
16 #endif 17 #endif
17 18
18 #include "chrome/browser/gtk/view_id_util.h" 19 #include "chrome/browser/gtk/view_id_util.h"
19 20
20 namespace ui_test_utils { 21 namespace ui_test_utils {
21 22
23 #if !defined(TOOLKIT_VIEWS)
22 namespace { 24 namespace {
23 25
24 // Check if the focused widget for |root| is |target| or a child of |target|. 26 // Check if the focused widget for |root| is |target| or a child of |target|.
25 static bool IsWidgetInFocusChain(GtkWidget* root, GtkWidget* target) { 27 static bool IsWidgetInFocusChain(GtkWidget* root, GtkWidget* target) {
26 GtkWidget* iter = root; 28 GtkWidget* iter = root;
27 29
28 while (iter) { 30 while (iter) {
29 if (iter == target) 31 if (iter == target)
30 return true; 32 return true;
31 33
32 if (!GTK_IS_CONTAINER(iter)) 34 if (!GTK_IS_CONTAINER(iter))
33 return false; 35 return false;
34 36
35 iter = GTK_CONTAINER(iter)->focus_child; 37 iter = GTK_CONTAINER(iter)->focus_child;
36 } 38 }
37 39
38 return false; 40 return false;
39 } 41 }
40 42
41 } // namespace 43 } // namespace
44 #endif
42 45
43 bool IsViewFocused(const Browser* browser, ViewID vid) { 46 bool IsViewFocused(const Browser* browser, ViewID vid) {
44 BrowserWindow* browser_window = browser->window(); 47 BrowserWindow* browser_window = browser->window();
45 DCHECK(browser_window); 48 DCHECK(browser_window);
49 #if defined(TOOLKIT_VIEWS)
50 gfx::NativeWindow window = browser_window->GetNativeHandle();
51 DCHECK(window);
52 views::FocusManager* focus_manager =
53 views::FocusManager::GetFocusManagerForNativeView(
54 GTK_WIDGET(window));
55 DCHECK(focus_manager);
56 return focus_manager->GetFocusedView() &&
57 focus_manager->GetFocusedView()->GetID() == vid;
58 #else
46 gfx::NativeWindow window = browser_window->GetNativeHandle(); 59 gfx::NativeWindow window = browser_window->GetNativeHandle();
47 DCHECK(window); 60 DCHECK(window);
48 GtkWidget* widget = ViewIDUtil::GetWidget(GTK_WIDGET(window), vid); 61 GtkWidget* widget = ViewIDUtil::GetWidget(GTK_WIDGET(window), vid);
49 DCHECK(widget); 62 DCHECK(widget);
50 return IsWidgetInFocusChain(GTK_WIDGET(window), widget); 63 return IsWidgetInFocusChain(GTK_WIDGET(window), widget);
64 #endif
51 } 65 }
52 66
53 void ClickOnView(const Browser* browser, ViewID vid) { 67 void ClickOnView(const Browser* browser, ViewID vid) {
54 BrowserWindow* browser_window = browser->window(); 68 BrowserWindow* browser_window = browser->window();
55 DCHECK(browser_window); 69 DCHECK(browser_window);
56 #if defined(TOOLKIT_VIEWS) 70 #if defined(TOOLKIT_VIEWS)
57 views::View* view = 71 views::View* view =
58 reinterpret_cast<BrowserView*>(browser_window)->GetViewByID(vid); 72 reinterpret_cast<BrowserView*>(browser_window)->GetViewByID(vid);
59 #else 73 #else
60 gfx::NativeWindow window = browser_window->GetNativeHandle(); 74 gfx::NativeWindow window = browser_window->GetNativeHandle();
61 DCHECK(window); 75 DCHECK(window);
62 GtkWidget* view = ViewIDUtil::GetWidget(GTK_WIDGET(window), vid); 76 GtkWidget* view = ViewIDUtil::GetWidget(GTK_WIDGET(window), vid);
63 #endif 77 #endif
64 78
65 DCHECK(view); 79 DCHECK(view);
66 ui_controls::MoveMouseToCenterAndPress( 80 ui_controls::MoveMouseToCenterAndPress(
67 view, 81 view,
68 ui_controls::LEFT, 82 ui_controls::LEFT,
69 ui_controls::DOWN | ui_controls::UP, 83 ui_controls::DOWN | ui_controls::UP,
70 new MessageLoop::QuitTask()); 84 new MessageLoop::QuitTask());
71 RunMessageLoop(); 85 RunMessageLoop();
72 } 86 }
73 87
74 } // namespace ui_test_utils 88 } // namespace ui_test_utils
OLDNEW
« no previous file with comments | « chrome/test/interactive_ui/view_event_test_base.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698