Cleanup setting of 'sysroot' in common.gypi
[chromium-blink-merge.git] / ash / accelerators / accelerator_interactive_uitest_chromeos.cc
blob4947f564c03d294c7b607b281266945e0f551a99
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.
5 #include "ash/accelerators/accelerator_controller.h"
7 #include "ash/shell.h"
8 #include "ash/shell_observer.h"
9 #include "ash/system/chromeos/network/network_observer.h"
10 #include "ash/system/tray/system_tray_delegate.h"
11 #include "ash/system/tray/system_tray_notifier.h"
12 #include "ash/test/ash_interactive_ui_test_base.h"
13 #include "ash/test/test_screenshot_delegate.h"
14 #include "ash/test/test_volume_control_delegate.h"
15 #include "ash/wm/window_state.h"
16 #include "ash/wm/window_util.h"
17 #include "base/run_loop.h"
18 #include "chromeos/network/network_handler.h"
19 #include "ui/base/test/ui_controls.h"
21 namespace ash {
22 namespace test {
24 namespace {
26 // A network observer to watch for the toggle wifi events.
27 class TestNetworkObserver : public NetworkObserver {
28 public:
29 TestNetworkObserver() : wifi_enabled_status_(false) {}
31 // ash::NetworkObserver:
32 void RequestToggleWifi() override {
33 wifi_enabled_status_ = !wifi_enabled_status_;
36 bool wifi_enabled_status() const { return wifi_enabled_status_; }
38 private:
39 bool wifi_enabled_status_;
41 DISALLOW_COPY_AND_ASSIGN(TestNetworkObserver);
44 } // namespace
46 ////////////////////////////////////////////////////////////////////////////////
48 // This is intended to test few samples from each category of accelerators to
49 // make sure they work properly. The test is done as an interactive ui test
50 // using ui_controls::Send*() functions.
51 // This is to catch any future regressions (crbug.com/469235).
52 class AcceleratorInteractiveUITest : public AshInteractiveUITestBase,
53 public ShellObserver {
54 public:
55 AcceleratorInteractiveUITest() : is_in_overview_mode_(false) {}
57 void SetUp() override {
58 AshInteractiveUITestBase::SetUp();
60 Shell::GetInstance()->AddShellObserver(this);
62 chromeos::NetworkHandler::Initialize();
65 void TearDown() override {
66 chromeos::NetworkHandler::Shutdown();
68 Shell::GetInstance()->RemoveShellObserver(this);
70 AshInteractiveUITestBase::TearDown();
73 // Sends a key press event and waits synchronously until it's completely
74 // processed.
75 void SendKeyPressSync(ui::KeyboardCode key,
76 bool control,
77 bool shift,
78 bool alt) {
79 base::RunLoop loop;
80 ui_controls::SendKeyPressNotifyWhenDone(root_window(), key, control, shift,
81 alt, false, loop.QuitClosure());
82 loop.Run();
85 // ash::ShellObserver:
86 void OnOverviewModeStarting() override { is_in_overview_mode_ = true; }
87 void OnOverviewModeEnded() override { is_in_overview_mode_ = false; }
89 Shell* shell() const { return Shell::GetInstance(); }
90 aura::Window* root_window() const { return Shell::GetPrimaryRootWindow(); }
92 protected:
93 bool is_in_overview_mode_;
95 private:
96 DISALLOW_COPY_AND_ASSIGN(AcceleratorInteractiveUITest);
99 ////////////////////////////////////////////////////////////////////////////////
101 #if defined(OFFICIAL_BUILD)
102 #define MAYBE_NonRepeatableNeedingWindowActions \
103 DISABLED_NonRepeatableNeedingWindowActions
104 #define MAYBE_ChromeOsAccelerators DISABLED_ChromeOsAccelerators
105 #define MAYBE_ToggleAppList DISABLED_ToggleAppList
106 #else
107 #define MAYBE_NonRepeatableNeedingWindowActions \
108 NonRepeatableNeedingWindowActions
109 #define MAYBE_ChromeOsAccelerators ChromeOsAccelerators
110 #define MAYBE_ToggleAppList ToggleAppList
111 #endif // defined(OFFICIAL_BUILD)
113 // Tests a sample of the non-repeatable accelerators that need windows to be
114 // enabled.
115 TEST_F(AcceleratorInteractiveUITest, MAYBE_NonRepeatableNeedingWindowActions) {
116 // Create a bunch of windows to work with.
117 aura::Window* window_1 =
118 CreateTestWindowInShellWithBounds(gfx::Rect(0, 0, 100, 100));
119 aura::Window* window_2 =
120 CreateTestWindowInShellWithBounds(gfx::Rect(0, 0, 100, 100));
121 window_1->Show();
122 wm::ActivateWindow(window_1);
123 window_2->Show();
124 wm::ActivateWindow(window_2);
126 // Test TOGGLE_OVERVIEW.
127 EXPECT_FALSE(is_in_overview_mode_);
128 SendKeyPressSync(ui::VKEY_MEDIA_LAUNCH_APP1, false, false, false);
129 EXPECT_TRUE(is_in_overview_mode_);
130 SendKeyPressSync(ui::VKEY_MEDIA_LAUNCH_APP1, false, false, false);
131 EXPECT_FALSE(is_in_overview_mode_);
133 // Test CYCLE_FORWARD_MRU and CYCLE_BACKWARD_MRU.
134 wm::ActivateWindow(window_1);
135 EXPECT_TRUE(wm::IsActiveWindow(window_1));
136 EXPECT_FALSE(wm::IsActiveWindow(window_2));
137 SendKeyPressSync(ui::VKEY_TAB, false, false, true); // CYCLE_FORWARD_MRU.
138 EXPECT_TRUE(wm::IsActiveWindow(window_2));
139 EXPECT_FALSE(wm::IsActiveWindow(window_1));
140 SendKeyPressSync(ui::VKEY_TAB, false, true, true); // CYCLE_BACKWARD_MRU.
141 EXPECT_TRUE(wm::IsActiveWindow(window_1));
142 EXPECT_FALSE(wm::IsActiveWindow(window_2));
144 // Test TOGGLE_FULLSCREEN.
145 wm::WindowState* active_window_state = wm::GetActiveWindowState();
146 EXPECT_FALSE(active_window_state->IsFullscreen());
147 SendKeyPressSync(ui::VKEY_MEDIA_LAUNCH_APP2, false, false, false);
148 EXPECT_TRUE(active_window_state->IsFullscreen());
149 SendKeyPressSync(ui::VKEY_MEDIA_LAUNCH_APP2, false, false, false);
150 EXPECT_FALSE(active_window_state->IsFullscreen());
153 // Tests a sample of ChromeOS specific accelerators.
154 TEST_F(AcceleratorInteractiveUITest, MAYBE_ChromeOsAccelerators) {
155 // Test TAKE_SCREENSHOT and TAKE_PARTIAL_SCREENSHOT.
156 TestScreenshotDelegate* screenshot_delegate = GetScreenshotDelegate();
157 screenshot_delegate->set_can_take_screenshot(true);
158 EXPECT_EQ(0, screenshot_delegate->handle_take_screenshot_count());
159 SendKeyPressSync(ui::VKEY_MEDIA_LAUNCH_APP1, true, false, false);
160 EXPECT_EQ(1, screenshot_delegate->handle_take_screenshot_count());
161 SendKeyPressSync(ui::VKEY_PRINT, false, false, false);
162 EXPECT_EQ(2, screenshot_delegate->handle_take_screenshot_count());
163 SendKeyPressSync(ui::VKEY_MEDIA_LAUNCH_APP1, true, true, false);
164 EXPECT_EQ(2, screenshot_delegate->handle_take_screenshot_count());
165 // Press ESC to go out of the partial screenshot mode.
166 SendKeyPressSync(ui::VKEY_ESCAPE, false, false, false);
168 // Test VOLUME_MUTE, VOLUME_DOWN, and VOLUME_UP.
169 TestVolumeControlDelegate* volume_delegate = new TestVolumeControlDelegate;
170 shell()->system_tray_delegate()->SetVolumeControlDelegate(
171 scoped_ptr<VolumeControlDelegate>(volume_delegate).Pass());
172 // VOLUME_MUTE.
173 EXPECT_EQ(0, volume_delegate->handle_volume_mute_count());
174 SendKeyPressSync(ui::VKEY_VOLUME_MUTE, false, false, false);
175 EXPECT_EQ(1, volume_delegate->handle_volume_mute_count());
176 // VOLUME_DOWN.
177 EXPECT_EQ(0, volume_delegate->handle_volume_down_count());
178 SendKeyPressSync(ui::VKEY_VOLUME_DOWN, false, false, false);
179 EXPECT_EQ(1, volume_delegate->handle_volume_down_count());
180 // VOLUME_UP.
181 EXPECT_EQ(0, volume_delegate->handle_volume_up_count());
182 SendKeyPressSync(ui::VKEY_VOLUME_UP, false, false, false);
183 EXPECT_EQ(1, volume_delegate->handle_volume_up_count());
185 // Test TOGGLE_WIFI.
186 TestNetworkObserver network_observer;
187 shell()->system_tray_notifier()->AddNetworkObserver(&network_observer);
189 EXPECT_FALSE(network_observer.wifi_enabled_status());
190 SendKeyPressSync(ui::VKEY_WLAN, false, false, false);
191 EXPECT_TRUE(network_observer.wifi_enabled_status());
192 SendKeyPressSync(ui::VKEY_WLAN, false, false, false);
193 EXPECT_FALSE(network_observer.wifi_enabled_status());
195 shell()->system_tray_notifier()->RemoveNetworkObserver(&network_observer);
198 // Tests the app list accelerator.
199 TEST_F(AcceleratorInteractiveUITest, MAYBE_ToggleAppList) {
200 EXPECT_FALSE(shell()->GetAppListTargetVisibility());
201 SendKeyPressSync(ui::VKEY_LWIN, false, false, false);
202 EXPECT_TRUE(shell()->GetAppListTargetVisibility());
203 SendKeyPressSync(ui::VKEY_LWIN, false, false, false);
204 EXPECT_FALSE(shell()->GetAppListTargetVisibility());
207 } // namespace test
208 } // namespace ash