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