Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 // Copyright 2015 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 "ash/accelerators/accelerator_controller.h" | |
| 6 | |
| 7 #include "ash/shell.h" | |
| 8 #include "ash/shell_observer.h" | |
| 9 #include "ash/system/tray/system_tray_delegate.h" | |
| 10 #include "ash/system/tray/system_tray_notifier.h" | |
| 11 #include "ash/test/ash_test_base.h" | |
| 12 #include "ash/test/test_screenshot_delegate.h" | |
| 13 #include "ash/test/test_volume_control_delegate.h" | |
| 14 #include "ash/wm/window_state.h" | |
| 15 #include "ash/wm/window_util.h" | |
| 16 #include "base/path_service.h" | |
| 17 #include "base/run_loop.h" | |
| 18 #include "ui/base/resource/resource_bundle.h" | |
| 19 #include "ui/base/test/ui_controls.h" | |
| 20 #include "ui/base/ui_base_paths.h" | |
| 21 #include "ui/gl/gl_surface.h" | |
| 22 | |
| 23 #if defined(OS_CHROMEOS) | |
| 24 #include "ash/system/chromeos/network/network_observer.h" | |
| 25 #include "chromeos/network/network_handler.h" | |
| 26 #endif // defined(OS_CHROMEOS) | |
| 27 | |
| 28 // ----------------------------------------------------------------------------- | |
| 29 // This file is intended to test a sample from each category of accelerators to | |
| 30 // make sure they work properly. The test is done as an interactive ui test | |
| 31 // using ui_controls::Send*() functions. | |
| 32 // This is to catch any future regressions (crbug.com/469235). | |
| 33 // ----------------------------------------------------------------------------- | |
|
oshima
2015/03/24 01:33:44
you can just move this to AcceleratorInteractiveUI
afakhry
2015/03/24 01:51:20
Done.
| |
| 34 | |
| 35 namespace ash { | |
| 36 namespace test { | |
| 37 | |
| 38 namespace { | |
| 39 | |
| 40 // A network observer to watch for the toggle wifi events. | |
| 41 class TestNetworkObserver : public NetworkObserver { | |
| 42 public: | |
| 43 TestNetworkObserver() : wifi_enabled_status_(false) {} | |
| 44 | |
| 45 ~TestNetworkObserver() override {} | |
|
oshima
2015/03/24 01:33:44
new style guide doesn't require empty dtor. you ma
afakhry
2015/03/24 01:51:20
Done.
| |
| 46 | |
| 47 // ash::NetworkObserver: | |
| 48 void RequestToggleWifi() override { | |
| 49 wifi_enabled_status_ = !wifi_enabled_status_; | |
| 50 } | |
| 51 | |
| 52 bool wifi_enabled_status() const { return wifi_enabled_status_; } | |
| 53 | |
| 54 private: | |
| 55 bool wifi_enabled_status_; | |
| 56 | |
| 57 DISALLOW_COPY_AND_ASSIGN(TestNetworkObserver); | |
| 58 }; | |
| 59 | |
| 60 } // namespace | |
| 61 | |
| 62 //////////////////////////////////////////////////////////////////////////////// | |
| 63 | |
| 64 class AcceleratorInteractiveUITest : public AshTestBase, public ShellObserver { | |
| 65 public: | |
| 66 AcceleratorInteractiveUITest() | |
| 67 : network_observer_(), is_in_overview_mode_(false) {} | |
| 68 | |
| 69 ~AcceleratorInteractiveUITest() override {} | |
| 70 | |
| 71 void SetUp() override { | |
| 72 gfx::GLSurface::InitializeOneOffForTests(); | |
| 73 | |
| 74 ui::RegisterPathProvider(); | |
| 75 ui::ResourceBundle::InitSharedInstanceWithLocale( | |
| 76 "en-US", NULL, ui::ResourceBundle::LOAD_COMMON_RESOURCES); | |
| 77 base::FilePath resources_pack_path; | |
| 78 PathService::Get(base::DIR_MODULE, &resources_pack_path); | |
| 79 resources_pack_path = | |
| 80 resources_pack_path.Append(FILE_PATH_LITERAL("resources.pak")); | |
| 81 ResourceBundle::GetSharedInstance().AddDataPackFromPath( | |
| 82 resources_pack_path, ui::SCALE_FACTOR_NONE); | |
| 83 | |
| 84 AshTestBase::SetUp(); | |
| 85 | |
| 86 Shell::GetInstance()->AddShellObserver(this); | |
| 87 | |
| 88 #if defined(OS_CHROMEOS) | |
| 89 chromeos::NetworkHandler::Initialize(); | |
| 90 Shell::GetInstance()->system_tray_notifier()->AddNetworkObserver( | |
| 91 &network_observer_); | |
| 92 #endif // defined(OS_CHROMEOS) | |
| 93 } | |
| 94 | |
| 95 void TearDown() override { | |
| 96 Shell::GetInstance()->RemoveShellObserver(this); | |
| 97 | |
| 98 #if defined(OS_CHROMEOS) | |
| 99 Shell::GetInstance()->system_tray_notifier()->RemoveNetworkObserver( | |
| 100 &network_observer_); | |
| 101 chromeos::NetworkHandler::Shutdown(); | |
| 102 #endif // defined(OS_CHROMEOS) | |
| 103 | |
| 104 AshTestBase::TearDown(); | |
| 105 } | |
| 106 | |
| 107 // Sends a key press event and waits synchronously until it's completely | |
| 108 // processed. | |
| 109 void SendKeyPressSync(ui::KeyboardCode key, | |
| 110 bool control, | |
| 111 bool shift, | |
| 112 bool alt) { | |
| 113 base::RunLoop loop; | |
| 114 ui_controls::SendKeyPressNotifyWhenDone(root_window(), key, control, shift, | |
| 115 alt, false, loop.QuitClosure()); | |
| 116 loop.Run(); | |
| 117 } | |
| 118 | |
| 119 // ash::ShellObserver: | |
| 120 void OnOverviewModeStarting() override { is_in_overview_mode_ = true; } | |
| 121 void OnOverviewModeEnded() override { is_in_overview_mode_ = false; } | |
| 122 | |
| 123 Shell* shell() const { return Shell::GetInstance(); } | |
| 124 aura::Window* root_window() const { return Shell::GetPrimaryRootWindow(); } | |
| 125 bool wifi_status() const { return network_observer_.wifi_enabled_status(); } | |
| 126 | |
| 127 protected: | |
| 128 TestNetworkObserver network_observer_; | |
| 129 bool is_in_overview_mode_; | |
| 130 | |
| 131 private: | |
| 132 DISALLOW_COPY_AND_ASSIGN(AcceleratorInteractiveUITest); | |
| 133 }; | |
| 134 | |
| 135 //////////////////////////////////////////////////////////////////////////////// | |
| 136 | |
| 137 // Tests a sample of the non-repeatable accelerators that need windows to be | |
| 138 // enabled. | |
| 139 TEST_F(AcceleratorInteractiveUITest, TestNonRepeatableNeedingWindowActions) { | |
| 140 // Create a bunch of windows to work with. | |
| 141 aura::Window* window_1 = | |
| 142 CreateTestWindowInShellWithBounds(gfx::Rect(0, 0, 100, 100)); | |
| 143 aura::Window* window_2 = | |
| 144 CreateTestWindowInShellWithBounds(gfx::Rect(0, 0, 100, 100)); | |
| 145 window_1->Show(); | |
| 146 wm::ActivateWindow(window_1); | |
| 147 window_2->Show(); | |
| 148 wm::ActivateWindow(window_2); | |
| 149 | |
| 150 // Test TOGGLE_OVERVIEW. | |
| 151 EXPECT_FALSE(is_in_overview_mode_); | |
| 152 SendKeyPressSync(ui::VKEY_MEDIA_LAUNCH_APP1, false, false, false); | |
| 153 EXPECT_TRUE(is_in_overview_mode_); | |
| 154 SendKeyPressSync(ui::VKEY_MEDIA_LAUNCH_APP1, false, false, false); | |
| 155 EXPECT_FALSE(is_in_overview_mode_); | |
| 156 | |
| 157 // Test CYCLE_FORWARD_MRU and CYCLE_BACKWARD_MRU. | |
| 158 wm::ActivateWindow(window_1); | |
| 159 EXPECT_TRUE(wm::IsActiveWindow(window_1)); | |
| 160 EXPECT_FALSE(wm::IsActiveWindow(window_2)); | |
| 161 SendKeyPressSync(ui::VKEY_TAB, false, false, true); // CYCLE_FORWARD_MRU. | |
| 162 EXPECT_TRUE(wm::IsActiveWindow(window_2)); | |
| 163 EXPECT_FALSE(wm::IsActiveWindow(window_1)); | |
| 164 SendKeyPressSync(ui::VKEY_TAB, false, true, true); // CYCLE_BACKWARD_MRU. | |
| 165 EXPECT_TRUE(wm::IsActiveWindow(window_1)); | |
| 166 EXPECT_FALSE(wm::IsActiveWindow(window_2)); | |
| 167 | |
| 168 // Test TOGGLE_FULLSCREEN. | |
| 169 wm::WindowState* active_window_state = wm::GetActiveWindowState(); | |
| 170 EXPECT_FALSE(active_window_state->IsFullscreen()); | |
| 171 SendKeyPressSync(ui::VKEY_MEDIA_LAUNCH_APP2, false, false, false); | |
| 172 EXPECT_TRUE(active_window_state->IsFullscreen()); | |
| 173 SendKeyPressSync(ui::VKEY_MEDIA_LAUNCH_APP2, false, false, false); | |
| 174 EXPECT_FALSE(active_window_state->IsFullscreen()); | |
| 175 } | |
| 176 | |
| 177 #if defined(OS_CHROMEOS) | |
| 178 // Tests a sample of ChromeOS specific accelerators. | |
| 179 TEST_F(AcceleratorInteractiveUITest, ChromeOsAccelerators) { | |
| 180 // Test TAKE_SCREENSHOT and TAKE_PARTIAL_SCREENSHOT. | |
| 181 TestScreenshotDelegate* screenshot_delegate = GetScreenshotDelegate(); | |
| 182 screenshot_delegate->set_can_take_screenshot(true); | |
| 183 EXPECT_EQ(0, screenshot_delegate->handle_take_screenshot_count()); | |
| 184 SendKeyPressSync(ui::VKEY_MEDIA_LAUNCH_APP1, true, false, false); | |
| 185 EXPECT_EQ(1, screenshot_delegate->handle_take_screenshot_count()); | |
| 186 SendKeyPressSync(ui::VKEY_PRINT, false, false, false); | |
| 187 EXPECT_EQ(2, screenshot_delegate->handle_take_screenshot_count()); | |
| 188 SendKeyPressSync(ui::VKEY_MEDIA_LAUNCH_APP1, true, true, false); | |
| 189 EXPECT_EQ(2, screenshot_delegate->handle_take_screenshot_count()); | |
| 190 // Press ESC to go out of the partial screenshot mode. | |
| 191 SendKeyPressSync(ui::VKEY_ESCAPE, false, false, false); | |
| 192 | |
| 193 // Test VOLUME_MUTE, VOLUME_DOWN, and VOLUME_UP. | |
| 194 TestVolumeControlDelegate* volume_delegate = new TestVolumeControlDelegate; | |
| 195 shell()->system_tray_delegate()->SetVolumeControlDelegate( | |
| 196 scoped_ptr<VolumeControlDelegate>(volume_delegate).Pass()); | |
| 197 // VOLUME_MUTE. | |
| 198 EXPECT_EQ(0, volume_delegate->handle_volume_mute_count()); | |
| 199 SendKeyPressSync(ui::VKEY_VOLUME_MUTE, false, false, false); | |
| 200 EXPECT_EQ(1, volume_delegate->handle_volume_mute_count()); | |
| 201 // VOLUME_DOWN. | |
| 202 EXPECT_EQ(0, volume_delegate->handle_volume_down_count()); | |
| 203 SendKeyPressSync(ui::VKEY_VOLUME_DOWN, false, false, false); | |
| 204 EXPECT_EQ(1, volume_delegate->handle_volume_down_count()); | |
| 205 // VOLUME_UP. | |
| 206 EXPECT_EQ(0, volume_delegate->handle_volume_up_count()); | |
| 207 SendKeyPressSync(ui::VKEY_VOLUME_UP, false, false, false); | |
| 208 EXPECT_EQ(1, volume_delegate->handle_volume_up_count()); | |
| 209 | |
| 210 // Test TOGGLE_WIFI. | |
| 211 EXPECT_FALSE(wifi_status()); | |
| 212 SendKeyPressSync(ui::VKEY_WLAN, false, false, false); | |
| 213 EXPECT_TRUE(wifi_status()); | |
| 214 SendKeyPressSync(ui::VKEY_WLAN, false, false, false); | |
| 215 EXPECT_FALSE(wifi_status()); | |
| 216 } | |
| 217 #endif // defined(OS_CHROMEOS) | |
| 218 | |
| 219 // Tests the app list accelerator. | |
| 220 TEST_F(AcceleratorInteractiveUITest, ToggleAppList) { | |
| 221 EXPECT_FALSE(shell()->GetAppListTargetVisibility()); | |
| 222 SendKeyPressSync(ui::VKEY_LWIN, false, false, false); | |
| 223 EXPECT_TRUE(shell()->GetAppListTargetVisibility()); | |
| 224 SendKeyPressSync(ui::VKEY_LWIN, false, false, false); | |
| 225 EXPECT_FALSE(shell()->GetAppListTargetVisibility()); | |
| 226 } | |
| 227 | |
| 228 } // namespace test | |
| 229 } // namespace ash | |
| OLD | NEW |