OLD | NEW |
| (Empty) |
1 // Copyright (c) 2010 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 "base/keyboard_codes.h" | |
6 #include "chrome/browser/automation/ui_controls.h" | |
7 #include "chrome/browser/views/chrome_views_delegate.h" | |
8 #include "chrome/browser/views/frame/browser_view.h" | |
9 #include "chrome/test/in_process_browser_test.h" | |
10 #include "chrome/test/ui_test_utils.h" | |
11 #include "views/view.h" | |
12 #include "views/accessibility/view_accessibility.h" | |
13 #include "views/widget/widget.h" | |
14 #include "views/window/window.h" | |
15 | |
16 namespace { | |
17 | |
18 class BrowserKeyboardAccessibility : public InProcessBrowserTest, | |
19 public ChromeViewsDelegate { | |
20 public: | |
21 BrowserKeyboardAccessibility() | |
22 : is_waiting_(false), | |
23 current_view_(NULL) { | |
24 // Set ourselves as the currently active ViewsDelegate. | |
25 ViewsDelegate::views_delegate = this; | |
26 } | |
27 | |
28 ~BrowserKeyboardAccessibility() {} | |
29 | |
30 // Overidden from ChromeViewsDelegate. | |
31 // Save the last notification sent by views::View::NotifyAccessibilityEvent. | |
32 virtual void NotifyAccessibilityEvent( | |
33 views::View* view, AccessibilityTypes::Event event_type) { | |
34 current_view_ = view; | |
35 current_event_type_ = event_type; | |
36 | |
37 // Are we within a message loop waiting for a particular event? | |
38 if (is_waiting_) { | |
39 is_waiting_ = false; | |
40 MessageLoop::current()->Quit(); | |
41 } | |
42 } | |
43 | |
44 // Helper that performs tabbing until it cycles back to the original focus. | |
45 void TabCyclerForwardAndBack(gfx::NativeWindow hwnd); | |
46 void TabCycler(gfx::NativeWindow hwnd, bool forward_tab); | |
47 | |
48 views::View* current_view() const { return current_view_; } | |
49 | |
50 gfx::NativeWindow current_view_native_window() const { | |
51 return current_view()->GetWidget()->GetNativeView(); | |
52 } | |
53 | |
54 AccessibilityTypes::Event current_event() const { | |
55 return current_event_type_; | |
56 } | |
57 | |
58 void set_waiting(bool value) { is_waiting_ = value; } | |
59 | |
60 private: | |
61 // Are we waiting for an event? | |
62 bool is_waiting_; | |
63 | |
64 // View of interest (i.e. for testing or one we are waiting to gain focus). | |
65 views::View* current_view_; | |
66 | |
67 // Event type of interest. | |
68 AccessibilityTypes::Event current_event_type_; | |
69 }; | |
70 | |
71 IN_PROC_BROWSER_TEST_F(BrowserKeyboardAccessibility, TabInAboutChromeDialog) { | |
72 views::Window* about_chrome_window = | |
73 BrowserView::GetBrowserViewForNativeWindow( | |
74 browser()->window()->GetNativeHandle())->ShowAboutChromeDialog(); | |
75 | |
76 TabCyclerForwardAndBack(about_chrome_window->GetNativeWindow()); | |
77 } | |
78 | |
79 IN_PROC_BROWSER_TEST_F(BrowserKeyboardAccessibility, | |
80 TabInClearBrowsingDataDialog) { | |
81 browser()->OpenClearBrowsingDataDialog(); | |
82 TabCyclerForwardAndBack(current_view_native_window()); | |
83 } | |
84 | |
85 IN_PROC_BROWSER_TEST_F(BrowserKeyboardAccessibility, | |
86 TabInImportSettingsDialog) { | |
87 browser()->OpenImportSettingsDialog(); | |
88 TabCyclerForwardAndBack(current_view_native_window()); | |
89 } | |
90 | |
91 IN_PROC_BROWSER_TEST_F(BrowserKeyboardAccessibility, TabInKeywordEditor) { | |
92 browser()->OpenKeywordEditor(); | |
93 TabCyclerForwardAndBack(current_view_native_window()); | |
94 } | |
95 | |
96 IN_PROC_BROWSER_TEST_F(BrowserKeyboardAccessibility, TabInOptionsDialog) { | |
97 browser()->OpenOptionsDialog(); | |
98 | |
99 // Tab through each of the three tabs. | |
100 for (int i = 0; i < 3; ++i) { | |
101 TabCyclerForwardAndBack(current_view_native_window()); | |
102 ui_controls::SendKeyPressNotifyWhenDone(current_view_native_window(), | |
103 base::VKEY_TAB, | |
104 true, false, false, false, | |
105 new MessageLoop::QuitTask()); | |
106 set_waiting(true); | |
107 ui_test_utils::RunMessageLoop(); | |
108 } | |
109 } | |
110 | |
111 IN_PROC_BROWSER_TEST_F(BrowserKeyboardAccessibility, TabInPasswordManager) { | |
112 browser()->OpenPasswordManager(); | |
113 TabCyclerForwardAndBack(current_view_native_window()); | |
114 } | |
115 | |
116 // TODO(dtseng): http://www.crbug.com/50402 | |
117 IN_PROC_BROWSER_TEST_F(BrowserKeyboardAccessibility, | |
118 FAILS_TabInSyncMyBookmarksDialog) { | |
119 browser()->OpenSyncMyBookmarksDialog(); | |
120 TabCyclerForwardAndBack(current_view_native_window()); | |
121 } | |
122 | |
123 IN_PROC_BROWSER_TEST_F(BrowserKeyboardAccessibility, TabInTaskManager) { | |
124 browser()->OpenTaskManager(); | |
125 TabCyclerForwardAndBack(current_view_native_window()); | |
126 } | |
127 | |
128 IN_PROC_BROWSER_TEST_F(BrowserKeyboardAccessibility, TabInToolbar) { | |
129 gfx::NativeWindow native_window = browser()->window()->GetNativeHandle(); | |
130 ui_controls::SendKeyPressNotifyWhenDone(native_window, | |
131 base::VKEY_T, | |
132 false, true, true, false, | |
133 new MessageLoop::QuitTask()); | |
134 set_waiting(true); | |
135 ui_test_utils::RunMessageLoop(); | |
136 TabCyclerForwardAndBack(current_view_native_window()); | |
137 } | |
138 | |
139 IN_PROC_BROWSER_TEST_F(BrowserKeyboardAccessibility, TabInUpdateChromeDialog) { | |
140 browser()->OpenUpdateChromeDialog(); | |
141 TabCyclerForwardAndBack(current_view_native_window()); | |
142 } | |
143 | |
144 void BrowserKeyboardAccessibility::TabCyclerForwardAndBack( | |
145 gfx::NativeWindow hwnd) { | |
146 TabCycler(hwnd, true); | |
147 TabCycler(hwnd, false); | |
148 } | |
149 | |
150 void BrowserKeyboardAccessibility::TabCycler(gfx::NativeWindow hwnd, | |
151 bool forward_tab) { | |
152 // Wait for a focus event on the provided native window. | |
153 while (current_event() != AccessibilityTypes::EVENT_FOCUS || | |
154 current_view_native_window() != hwnd) { | |
155 set_waiting(true); | |
156 ui_test_utils::RunMessageLoop(); | |
157 } | |
158 | |
159 views::View* first_focused_item = current_view(); | |
160 | |
161 ASSERT_TRUE(first_focused_item != NULL); | |
162 | |
163 views::View* next_focused_item = first_focused_item; | |
164 | |
165 // Keep tabbing until we reach the originally focused view. | |
166 do { | |
167 ui_controls::SendKeyPressNotifyWhenDone(hwnd, base::VKEY_TAB, | |
168 false, !forward_tab, false, false, new MessageLoop::QuitTask()); | |
169 set_waiting(true); | |
170 ui_test_utils::RunMessageLoop(); | |
171 next_focused_item = current_view(); | |
172 } while (first_focused_item != next_focused_item); | |
173 } | |
174 | |
175 } // namespace | |
OLD | NEW |