OLD | NEW |
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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 "ash/shell.h" | 5 #include "ash/shell.h" |
6 #include "ash/sticky_keys/sticky_keys_controller.h" | 6 #include "ash/sticky_keys/sticky_keys_controller.h" |
7 #include "ash/sticky_keys/sticky_keys_overlay.h" | 7 #include "ash/sticky_keys/sticky_keys_overlay.h" |
8 #include "ash/system/tray/system_tray.h" | 8 #include "ash/system/tray/system_tray.h" |
9 #include "base/command_line.h" | 9 #include "base/command_line.h" |
10 #include "base/prefs/pref_service.h" | 10 #include "base/prefs/pref_service.h" |
11 #include "chrome/browser/chromeos/accessibility/accessibility_manager.h" | 11 #include "chrome/browser/chromeos/accessibility/accessibility_manager.h" |
12 #include "chrome/browser/profiles/profile.h" | 12 #include "chrome/browser/profiles/profile.h" |
13 #include "chrome/browser/ui/browser.h" | 13 #include "chrome/browser/ui/browser.h" |
14 #include "chrome/browser/ui/browser_window.h" | 14 #include "chrome/browser/ui/browser_window.h" |
15 #include "chrome/browser/ui/location_bar/location_bar.h" | 15 #include "chrome/browser/ui/location_bar/location_bar.h" |
16 #include "chrome/browser/ui/omnibox/omnibox_view.h" | 16 #include "chrome/browser/ui/omnibox/omnibox_view.h" |
17 #include "chrome/browser/ui/tabs/tab_strip_model.h" | 17 #include "chrome/browser/ui/tabs/tab_strip_model.h" |
18 #include "chrome/browser/ui/view_ids.h" | 18 #include "chrome/browser/ui/view_ids.h" |
19 #include "chrome/common/pref_names.h" | 19 #include "chrome/common/pref_names.h" |
20 #include "chrome/test/base/in_process_browser_test.h" | 20 #include "chrome/test/base/in_process_browser_test.h" |
21 #include "chrome/test/base/interactive_test_utils.h" | 21 #include "chrome/test/base/interactive_test_utils.h" |
22 #include "ui/aura/window_event_dispatcher.h" | 22 #include "ui/aura/window_event_dispatcher.h" |
23 #include "ui/events/keycodes/keyboard_codes.h" | 23 #include "ui/events/keycodes/keyboard_codes.h" |
| 24 #include "ui/events/test/event_generator.h" |
24 #include "ui/gfx/native_widget_types.h" | 25 #include "ui/gfx/native_widget_types.h" |
25 | 26 |
26 namespace chromeos { | 27 namespace chromeos { |
27 | 28 |
28 class StickyKeysBrowserTest : public InProcessBrowserTest { | 29 class StickyKeysBrowserTest : public InProcessBrowserTest { |
| 30 public: |
| 31 void SetUpOnMainThread() override { |
| 32 content::BrowserTestBase::SetUpOnMainThread(); |
| 33 event_generator_.reset( |
| 34 new ui::test::EventGenerator(browser()->window()->GetNativeWindow())); |
| 35 } |
| 36 |
29 protected: | 37 protected: |
30 StickyKeysBrowserTest() {} | 38 StickyKeysBrowserTest() {} |
31 virtual ~StickyKeysBrowserTest() {} | 39 virtual ~StickyKeysBrowserTest() {} |
32 | 40 |
33 void EnableStickyKeys() { | 41 void EnableStickyKeys() { |
34 AccessibilityManager::Get()->EnableStickyKeys(true); | 42 AccessibilityManager::Get()->EnableStickyKeys(true); |
35 } | 43 } |
36 | 44 |
37 void DisableStickyKeys() { | 45 void DisableStickyKeys() { |
38 AccessibilityManager::Get()->EnableStickyKeys(false); | 46 AccessibilityManager::Get()->EnableStickyKeys(false); |
39 } | 47 } |
40 | 48 |
41 ash::SystemTray* GetSystemTray() { | 49 ash::SystemTray* GetSystemTray() { |
42 return ash::Shell::GetInstance()->GetPrimarySystemTray(); | 50 return ash::Shell::GetInstance()->GetPrimarySystemTray(); |
43 } | 51 } |
44 | 52 |
45 void SendKeyPress(ui::KeyboardCode key) { | 53 void SendKeyPress(ui::KeyboardCode key) { |
46 gfx::NativeWindow root_window = | 54 event_generator_->PressKey(key, ui::EF_NONE); |
47 ash::Shell::GetInstance()->GetPrimaryRootWindow(); | 55 event_generator_->ReleaseKey(key, ui::EF_NONE); |
48 ASSERT_TRUE( | |
49 ui_test_utils::SendKeyPressToWindowSync(root_window, | |
50 key, | |
51 false, // control | |
52 false, // shift | |
53 false, // alt | |
54 false)); // command | |
55 } | 56 } |
56 | 57 |
57 content::NotificationRegistrar registrar_; | 58 content::NotificationRegistrar registrar_; |
| 59 scoped_ptr<ui::test::EventGenerator> event_generator_; |
58 | 60 |
59 DISALLOW_COPY_AND_ASSIGN(StickyKeysBrowserTest); | 61 DISALLOW_COPY_AND_ASSIGN(StickyKeysBrowserTest); |
60 }; | 62 }; |
61 | 63 |
62 IN_PROC_BROWSER_TEST_F(StickyKeysBrowserTest, OpenTrayMenu) { | 64 IN_PROC_BROWSER_TEST_F(StickyKeysBrowserTest, OpenTrayMenu) { |
63 EnableStickyKeys(); | 65 EnableStickyKeys(); |
64 | 66 |
65 // Open system tray bubble with shortcut. | 67 // Open system tray bubble with shortcut. |
66 SendKeyPress(ui::VKEY_MENU); // alt key. | 68 SendKeyPress(ui::VKEY_MENU); // alt key. |
67 SendKeyPress(ui::VKEY_SHIFT); | 69 SendKeyPress(ui::VKEY_SHIFT); |
(...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
146 | 148 |
147 IN_PROC_BROWSER_TEST_F(StickyKeysBrowserTest, SearchLeftOmnibox) { | 149 IN_PROC_BROWSER_TEST_F(StickyKeysBrowserTest, SearchLeftOmnibox) { |
148 EnableStickyKeys(); | 150 EnableStickyKeys(); |
149 | 151 |
150 OmniboxView* omnibox = | 152 OmniboxView* omnibox = |
151 browser()->window()->GetLocationBar()->GetOmniboxView(); | 153 browser()->window()->GetLocationBar()->GetOmniboxView(); |
152 | 154 |
153 // Give the omnibox focus. | 155 // Give the omnibox focus. |
154 omnibox->ShowURL(); | 156 omnibox->ShowURL(); |
155 | 157 |
| 158 // Make sure that the AppList is not erronously displayed and the omnibox |
| 159 // doesn't lost focus |
| 160 EXPECT_FALSE(ash::Shell::GetInstance()->GetAppListTargetVisibility()); |
| 161 EXPECT_TRUE(omnibox->GetNativeView()->HasFocus()); |
| 162 |
156 // Type 'foo'. | 163 // Type 'foo'. |
157 SendKeyPress(ui::VKEY_F); | 164 SendKeyPress(ui::VKEY_F); |
158 SendKeyPress(ui::VKEY_O); | 165 SendKeyPress(ui::VKEY_O); |
159 SendKeyPress(ui::VKEY_O); | 166 SendKeyPress(ui::VKEY_O); |
160 | 167 |
161 // Verify the location of the caret. | 168 // Verify the location of the caret. |
162 size_t start, end; | 169 size_t start, end; |
163 omnibox->GetSelectionBounds(&start, &end); | 170 omnibox->GetSelectionBounds(&start, &end); |
164 ASSERT_EQ(3U, start); | 171 ASSERT_EQ(3U, start); |
165 ASSERT_EQ(3U, end); | 172 ASSERT_EQ(3U, end); |
166 | 173 |
| 174 EXPECT_FALSE(ash::Shell::GetInstance()->GetAppListTargetVisibility()); |
| 175 EXPECT_TRUE(omnibox->GetNativeView()->HasFocus()); |
| 176 |
167 // Hit Home by sequencing Search (left Windows) and Left (arrow). | 177 // Hit Home by sequencing Search (left Windows) and Left (arrow). |
168 SendKeyPress(ui::VKEY_LWIN); | 178 SendKeyPress(ui::VKEY_LWIN); |
169 SendKeyPress(ui::VKEY_LEFT); | 179 SendKeyPress(ui::VKEY_LEFT); |
170 | 180 |
| 181 EXPECT_FALSE(ash::Shell::GetInstance()->GetAppListTargetVisibility()); |
| 182 EXPECT_TRUE(omnibox->GetNativeView()->HasFocus()); |
| 183 |
171 // Verify caret moved to the beginning. | 184 // Verify caret moved to the beginning. |
172 omnibox->GetSelectionBounds(&start, &end); | 185 omnibox->GetSelectionBounds(&start, &end); |
173 ASSERT_EQ(0U, start); | 186 ASSERT_EQ(0U, start); |
174 ASSERT_EQ(0U, end); | 187 ASSERT_EQ(0U, end); |
175 } | 188 } |
176 | 189 |
177 IN_PROC_BROWSER_TEST_F(StickyKeysBrowserTest, OverlayShown) { | 190 IN_PROC_BROWSER_TEST_F(StickyKeysBrowserTest, OverlayShown) { |
178 const ui::KeyboardCode modifier_keys[] = { ui::VKEY_CONTROL, | 191 const ui::KeyboardCode modifier_keys[] = { ui::VKEY_CONTROL, |
179 ui::VKEY_SHIFT, | 192 ui::VKEY_SHIFT, |
180 ui::VKEY_MENU, | 193 ui::VKEY_MENU, |
(...skipping 25 matching lines...) Expand all Loading... |
206 EXPECT_TRUE(sticky_keys_overlay->is_visible()); | 219 EXPECT_TRUE(sticky_keys_overlay->is_visible()); |
207 DisableStickyKeys(); | 220 DisableStickyKeys(); |
208 EXPECT_FALSE(controller->GetOverlayForTest()); | 221 EXPECT_FALSE(controller->GetOverlayForTest()); |
209 for (auto key_code : modifier_keys) { | 222 for (auto key_code : modifier_keys) { |
210 SendKeyPress(key_code); | 223 SendKeyPress(key_code); |
211 EXPECT_FALSE(controller->GetOverlayForTest()); | 224 EXPECT_FALSE(controller->GetOverlayForTest()); |
212 } | 225 } |
213 } | 226 } |
214 | 227 |
215 } // namespace chromeos | 228 } // namespace chromeos |
OLD | NEW |