| 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 <stddef.h> | 5 #include <stddef.h> |
| 6 | 6 |
| 7 #include "ash/common/system/tray/system_tray.h" | 7 #include "ash/common/system/tray/system_tray.h" |
| 8 #include "ash/common/test/wm_shell_test_api.h" | |
| 9 #include "ash/common/wm_shell.h" | 8 #include "ash/common/wm_shell.h" |
| 10 #include "ash/public/interfaces/new_window.mojom.h" | |
| 11 #include "ash/shell.h" | 9 #include "ash/shell.h" |
| 12 #include "ash/sticky_keys/sticky_keys_controller.h" | 10 #include "ash/sticky_keys/sticky_keys_controller.h" |
| 13 #include "ash/sticky_keys/sticky_keys_overlay.h" | 11 #include "ash/sticky_keys/sticky_keys_overlay.h" |
| 14 #include "base/command_line.h" | 12 #include "base/command_line.h" |
| 15 #include "base/macros.h" | 13 #include "base/macros.h" |
| 16 #include "chrome/browser/chromeos/accessibility/accessibility_manager.h" | 14 #include "chrome/browser/chromeos/accessibility/accessibility_manager.h" |
| 17 #include "chrome/browser/profiles/profile.h" | 15 #include "chrome/browser/profiles/profile.h" |
| 18 #include "chrome/browser/ui/browser.h" | 16 #include "chrome/browser/ui/browser.h" |
| 19 #include "chrome/browser/ui/browser_window.h" | 17 #include "chrome/browser/ui/browser_window.h" |
| 20 #include "chrome/browser/ui/location_bar/location_bar.h" | 18 #include "chrome/browser/ui/location_bar/location_bar.h" |
| 21 #include "chrome/browser/ui/tabs/tab_strip_model.h" | 19 #include "chrome/browser/ui/tabs/tab_strip_model.h" |
| 22 #include "chrome/browser/ui/view_ids.h" | 20 #include "chrome/browser/ui/view_ids.h" |
| 23 #include "chrome/common/pref_names.h" | 21 #include "chrome/common/pref_names.h" |
| 24 #include "chrome/test/base/in_process_browser_test.h" | 22 #include "chrome/test/base/in_process_browser_test.h" |
| 25 #include "chrome/test/base/interactive_test_utils.h" | 23 #include "chrome/test/base/interactive_test_utils.h" |
| 26 #include "components/omnibox/browser/omnibox_view.h" | 24 #include "components/omnibox/browser/omnibox_view.h" |
| 27 #include "components/prefs/pref_service.h" | 25 #include "components/prefs/pref_service.h" |
| 28 #include "ui/aura/window_event_dispatcher.h" | 26 #include "ui/aura/window_event_dispatcher.h" |
| 29 #include "ui/events/keycodes/keyboard_codes.h" | 27 #include "ui/events/keycodes/keyboard_codes.h" |
| 30 #include "ui/events/test/event_generator.h" | 28 #include "ui/events/test/event_generator.h" |
| 31 #include "ui/gfx/native_widget_types.h" | 29 #include "ui/gfx/native_widget_types.h" |
| 32 | 30 |
| 33 namespace chromeos { | 31 namespace chromeos { |
| 34 | 32 |
| 35 class CountingNewWindowClient : public ash::mojom::NewWindowClient { | |
| 36 public: | |
| 37 CountingNewWindowClient() {} | |
| 38 ~CountingNewWindowClient() override {} | |
| 39 | |
| 40 int new_tab_action_count() const { return new_tab_action_count_; } | |
| 41 | |
| 42 // ash::mojom::NewWindowClient: | |
| 43 void NewTab() override { new_tab_action_count_++; } | |
| 44 void NewWindow(bool incognito) override {} | |
| 45 void OpenFileManager() override {} | |
| 46 void OpenCrosh() override {} | |
| 47 void OpenGetHelp() override {} | |
| 48 void RestoreTab() override {} | |
| 49 void ShowKeyboardOverlay() override {} | |
| 50 void ShowTaskManager() override {} | |
| 51 void OpenFeedbackPage() override {} | |
| 52 | |
| 53 private: | |
| 54 int new_tab_action_count_ = 0; | |
| 55 | |
| 56 DISALLOW_COPY_AND_ASSIGN(CountingNewWindowClient); | |
| 57 }; | |
| 58 | |
| 59 class StickyKeysBrowserTest : public InProcessBrowserTest { | 33 class StickyKeysBrowserTest : public InProcessBrowserTest { |
| 60 public: | 34 public: |
| 61 void SetUpOnMainThread() override { | 35 void SetUpOnMainThread() override { |
| 62 content::BrowserTestBase::SetUpOnMainThread(); | 36 content::BrowserTestBase::SetUpOnMainThread(); |
| 63 event_generator_.reset( | 37 event_generator_.reset( |
| 64 new ui::test::EventGenerator(browser()->window()->GetNativeWindow())); | 38 new ui::test::EventGenerator(browser()->window()->GetNativeWindow())); |
| 65 | |
| 66 new_window_client_ = new CountingNewWindowClient; | |
| 67 ash::WmShellTestApi().SetNewWindowClient( | |
| 68 base::WrapUnique(new_window_client_)); | |
| 69 } | 39 } |
| 70 | 40 |
| 71 protected: | 41 protected: |
| 72 StickyKeysBrowserTest() {} | 42 StickyKeysBrowserTest() {} |
| 73 ~StickyKeysBrowserTest() override {} | 43 ~StickyKeysBrowserTest() override {} |
| 74 | 44 |
| 75 void EnableStickyKeys() { | 45 void EnableStickyKeys() { |
| 76 AccessibilityManager::Get()->EnableStickyKeys(true); | 46 AccessibilityManager::Get()->EnableStickyKeys(true); |
| 77 } | 47 } |
| 78 | 48 |
| 79 void DisableStickyKeys() { | 49 void DisableStickyKeys() { |
| 80 AccessibilityManager::Get()->EnableStickyKeys(false); | 50 AccessibilityManager::Get()->EnableStickyKeys(false); |
| 81 } | 51 } |
| 82 | 52 |
| 83 ash::SystemTray* GetSystemTray() { | 53 ash::SystemTray* GetSystemTray() { |
| 84 return ash::Shell::GetInstance()->GetPrimarySystemTray(); | 54 return ash::Shell::GetInstance()->GetPrimarySystemTray(); |
| 85 } | 55 } |
| 86 | 56 |
| 87 void SendKeyPress(ui::KeyboardCode key) { | 57 void SendKeyPress(ui::KeyboardCode key) { |
| 88 event_generator_->PressKey(key, ui::EF_NONE); | 58 event_generator_->PressKey(key, ui::EF_NONE); |
| 59 content::RunAllPendingInMessageLoop(); |
| 89 event_generator_->ReleaseKey(key, ui::EF_NONE); | 60 event_generator_->ReleaseKey(key, ui::EF_NONE); |
| 61 content::RunAllPendingInMessageLoop(); |
| 90 } | 62 } |
| 91 | 63 |
| 92 content::NotificationRegistrar registrar_; | 64 content::NotificationRegistrar registrar_; |
| 93 std::unique_ptr<ui::test::EventGenerator> event_generator_; | 65 std::unique_ptr<ui::test::EventGenerator> event_generator_; |
| 94 CountingNewWindowClient* new_window_client_; | |
| 95 | 66 |
| 96 DISALLOW_COPY_AND_ASSIGN(StickyKeysBrowserTest); | 67 DISALLOW_COPY_AND_ASSIGN(StickyKeysBrowserTest); |
| 97 }; | 68 }; |
| 98 | 69 |
| 99 IN_PROC_BROWSER_TEST_F(StickyKeysBrowserTest, OpenTrayMenu) { | 70 IN_PROC_BROWSER_TEST_F(StickyKeysBrowserTest, OpenTrayMenu) { |
| 100 EnableStickyKeys(); | 71 EnableStickyKeys(); |
| 101 | 72 |
| 102 // Open system tray bubble with shortcut. | 73 // Open system tray bubble with shortcut. |
| 103 SendKeyPress(ui::VKEY_MENU); // alt key. | 74 SendKeyPress(ui::VKEY_MENU); // alt key. |
| 104 SendKeyPress(ui::VKEY_SHIFT); | 75 SendKeyPress(ui::VKEY_SHIFT); |
| (...skipping 16 matching lines...) Expand all Loading... |
| 121 EXPECT_FALSE(GetSystemTray()->HasSystemBubble()); | 92 EXPECT_FALSE(GetSystemTray()->HasSystemBubble()); |
| 122 } | 93 } |
| 123 | 94 |
| 124 IN_PROC_BROWSER_TEST_F(StickyKeysBrowserTest, OpenNewTabs) { | 95 IN_PROC_BROWSER_TEST_F(StickyKeysBrowserTest, OpenNewTabs) { |
| 125 // Lock the modifier key. | 96 // Lock the modifier key. |
| 126 EnableStickyKeys(); | 97 EnableStickyKeys(); |
| 127 SendKeyPress(ui::VKEY_CONTROL); | 98 SendKeyPress(ui::VKEY_CONTROL); |
| 128 SendKeyPress(ui::VKEY_CONTROL); | 99 SendKeyPress(ui::VKEY_CONTROL); |
| 129 | 100 |
| 130 // In the locked state, pressing 't' should open a new tab each time. | 101 // In the locked state, pressing 't' should open a new tab each time. |
| 131 int tab_count = 0; | 102 TabStripModel* tab_strip_model = browser()->tab_strip_model(); |
| 132 for (; tab_count < 4; ++tab_count) { | 103 int tab_count = 1; |
| 133 EXPECT_EQ(tab_count, new_window_client_->new_tab_action_count()); | 104 for (; tab_count < 5; ++tab_count) { |
| 105 EXPECT_EQ(tab_count, tab_strip_model->count()); |
| 134 SendKeyPress(ui::VKEY_T); | 106 SendKeyPress(ui::VKEY_T); |
| 135 } | 107 } |
| 136 | 108 |
| 137 // Unlock the modifier key and shortcut should no longer activate. | 109 // Unlock the modifier key and shortcut should no longer activate. |
| 138 SendKeyPress(ui::VKEY_CONTROL); | 110 SendKeyPress(ui::VKEY_CONTROL); |
| 139 SendKeyPress(ui::VKEY_T); | 111 SendKeyPress(ui::VKEY_T); |
| 140 EXPECT_EQ(tab_count, new_window_client_->new_tab_action_count()); | 112 EXPECT_EQ(tab_count, tab_strip_model->count()); |
| 141 | 113 |
| 142 // Shortcut should not work after disabling sticky keys. | 114 // Shortcut should not work after disabling sticky keys. |
| 143 DisableStickyKeys(); | 115 DisableStickyKeys(); |
| 144 SendKeyPress(ui::VKEY_CONTROL); | 116 SendKeyPress(ui::VKEY_CONTROL); |
| 145 SendKeyPress(ui::VKEY_CONTROL); | 117 SendKeyPress(ui::VKEY_CONTROL); |
| 146 SendKeyPress(ui::VKEY_T); | 118 SendKeyPress(ui::VKEY_T); |
| 147 EXPECT_EQ(tab_count, new_window_client_->new_tab_action_count()); | 119 EXPECT_EQ(tab_count, tab_strip_model->count()); |
| 148 } | 120 } |
| 149 | 121 |
| 150 IN_PROC_BROWSER_TEST_F(StickyKeysBrowserTest, CtrlClickHomeButton) { | 122 IN_PROC_BROWSER_TEST_F(StickyKeysBrowserTest, CtrlClickHomeButton) { |
| 151 // Show home page button. | 123 // Show home page button. |
| 152 browser()->profile()->GetPrefs()->SetBoolean(prefs::kShowHomeButton, true); | 124 browser()->profile()->GetPrefs()->SetBoolean(prefs::kShowHomeButton, true); |
| 153 TabStripModel* tab_strip_model = browser()->tab_strip_model(); | 125 TabStripModel* tab_strip_model = browser()->tab_strip_model(); |
| 154 int tab_count = 1; | 126 int tab_count = 1; |
| 155 EXPECT_EQ(tab_count, tab_strip_model->count()); | 127 EXPECT_EQ(tab_count, tab_strip_model->count()); |
| 156 | 128 |
| 157 // Test sticky keys with modified mouse click action. | 129 // Test sticky keys with modified mouse click action. |
| (...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 253 EXPECT_TRUE(sticky_keys_overlay->is_visible()); | 225 EXPECT_TRUE(sticky_keys_overlay->is_visible()); |
| 254 DisableStickyKeys(); | 226 DisableStickyKeys(); |
| 255 EXPECT_FALSE(controller->GetOverlayForTest()); | 227 EXPECT_FALSE(controller->GetOverlayForTest()); |
| 256 for (auto key_code : modifier_keys) { | 228 for (auto key_code : modifier_keys) { |
| 257 SendKeyPress(key_code); | 229 SendKeyPress(key_code); |
| 258 EXPECT_FALSE(controller->GetOverlayForTest()); | 230 EXPECT_FALSE(controller->GetOverlayForTest()); |
| 259 } | 231 } |
| 260 } | 232 } |
| 261 | 233 |
| 262 } // namespace chromeos | 234 } // namespace chromeos |
| OLD | NEW |