Add ICU message format support
[chromium-blink-merge.git] / ash / accelerators / accelerator_interactive_uitest_chromeos.cc
blob3babbc5f0cbdacc87620cce34f8f2ed901e96864
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_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/path_service.h"
18 #include "base/run_loop.h"
19 #include "chromeos/network/network_handler.h"
20 #include "ui/aura/env.h"
21 #include "ui/base/resource/resource_bundle.h"
22 #include "ui/base/test/ui_controls.h"
23 #include "ui/base/ui_base_paths.h"
24 #include "ui/gl/test/gl_surface_test_support.h"
26 namespace ash {
27 namespace test {
29 namespace {
31 // A network observer to watch for the toggle wifi events.
32 class TestNetworkObserver : public NetworkObserver {
33 public:
34 TestNetworkObserver() : wifi_enabled_status_(false) {}
36 // ash::NetworkObserver:
37 void RequestToggleWifi() override {
38 wifi_enabled_status_ = !wifi_enabled_status_;
41 bool wifi_enabled_status() const { return wifi_enabled_status_; }
43 private:
44 bool wifi_enabled_status_;
46 DISALLOW_COPY_AND_ASSIGN(TestNetworkObserver);
49 } // namespace
51 ////////////////////////////////////////////////////////////////////////////////
53 // This is intended to test few samples from each category of accelerators to
54 // make sure they work properly. The test is done as an interactive ui test
55 // using ui_controls::Send*() functions.
56 // This is to catch any future regressions (crbug.com/469235).
57 class AcceleratorInteractiveUITest : public AshTestBase, public ShellObserver {
58 public:
59 AcceleratorInteractiveUITest() : is_in_overview_mode_(false) {}
61 void SetUp() override {
62 gfx::GLSurfaceTestSupport::InitializeOneOff();
64 ui::RegisterPathProvider();
65 ui::ResourceBundle::InitSharedInstanceWithLocale(
66 "en-US", NULL, ui::ResourceBundle::LOAD_COMMON_RESOURCES);
67 base::FilePath resources_pack_path;
68 PathService::Get(base::DIR_MODULE, &resources_pack_path);
69 resources_pack_path =
70 resources_pack_path.Append(FILE_PATH_LITERAL("resources.pak"));
71 ResourceBundle::GetSharedInstance().AddDataPackFromPath(
72 resources_pack_path, ui::SCALE_FACTOR_NONE);
73 aura::Env::CreateInstance(true);
75 AshTestBase::SetUp();
77 Shell::GetInstance()->AddShellObserver(this);
79 chromeos::NetworkHandler::Initialize();
82 void TearDown() override {
83 chromeos::NetworkHandler::Shutdown();
85 Shell::GetInstance()->RemoveShellObserver(this);
87 AshTestBase::TearDown();
88 aura::Env::DeleteInstance();
91 // Sends a key press event and waits synchronously until it's completely
92 // processed.
93 void SendKeyPressSync(ui::KeyboardCode key,
94 bool control,
95 bool shift,
96 bool alt) {
97 base::RunLoop loop;
98 ui_controls::SendKeyPressNotifyWhenDone(root_window(), key, control, shift,
99 alt, false, loop.QuitClosure());
100 loop.Run();
103 // ash::ShellObserver:
104 void OnOverviewModeStarting() override { is_in_overview_mode_ = true; }
105 void OnOverviewModeEnded() override { is_in_overview_mode_ = false; }
107 Shell* shell() const { return Shell::GetInstance(); }
108 aura::Window* root_window() const { return Shell::GetPrimaryRootWindow(); }
110 protected:
111 bool is_in_overview_mode_;
113 private:
114 DISALLOW_COPY_AND_ASSIGN(AcceleratorInteractiveUITest);
117 ////////////////////////////////////////////////////////////////////////////////
119 #if defined(OFFICIAL_BUILD)
120 #define MAYBE_NonRepeatableNeedingWindowActions \
121 DISABLED_NonRepeatableNeedingWindowActions
122 #define MAYBE_ChromeOsAccelerators DISABLED_ChromeOsAccelerators
123 #define MAYBE_ToggleAppList DISABLED_ToggleAppList
124 #else
125 #define MAYBE_NonRepeatableNeedingWindowActions \
126 NonRepeatableNeedingWindowActions
127 #define MAYBE_ChromeOsAccelerators ChromeOsAccelerators
128 #define MAYBE_ToggleAppList ToggleAppList
129 #endif // defined(OFFICIAL_BUILD)
131 // Tests a sample of the non-repeatable accelerators that need windows to be
132 // enabled.
133 TEST_F(AcceleratorInteractiveUITest, MAYBE_NonRepeatableNeedingWindowActions) {
134 // Create a bunch of windows to work with.
135 aura::Window* window_1 =
136 CreateTestWindowInShellWithBounds(gfx::Rect(0, 0, 100, 100));
137 aura::Window* window_2 =
138 CreateTestWindowInShellWithBounds(gfx::Rect(0, 0, 100, 100));
139 window_1->Show();
140 wm::ActivateWindow(window_1);
141 window_2->Show();
142 wm::ActivateWindow(window_2);
144 // Test TOGGLE_OVERVIEW.
145 EXPECT_FALSE(is_in_overview_mode_);
146 SendKeyPressSync(ui::VKEY_MEDIA_LAUNCH_APP1, false, false, false);
147 EXPECT_TRUE(is_in_overview_mode_);
148 SendKeyPressSync(ui::VKEY_MEDIA_LAUNCH_APP1, false, false, false);
149 EXPECT_FALSE(is_in_overview_mode_);
151 // Test CYCLE_FORWARD_MRU and CYCLE_BACKWARD_MRU.
152 wm::ActivateWindow(window_1);
153 EXPECT_TRUE(wm::IsActiveWindow(window_1));
154 EXPECT_FALSE(wm::IsActiveWindow(window_2));
155 SendKeyPressSync(ui::VKEY_TAB, false, false, true); // CYCLE_FORWARD_MRU.
156 EXPECT_TRUE(wm::IsActiveWindow(window_2));
157 EXPECT_FALSE(wm::IsActiveWindow(window_1));
158 SendKeyPressSync(ui::VKEY_TAB, false, true, true); // CYCLE_BACKWARD_MRU.
159 EXPECT_TRUE(wm::IsActiveWindow(window_1));
160 EXPECT_FALSE(wm::IsActiveWindow(window_2));
162 // Test TOGGLE_FULLSCREEN.
163 wm::WindowState* active_window_state = wm::GetActiveWindowState();
164 EXPECT_FALSE(active_window_state->IsFullscreen());
165 SendKeyPressSync(ui::VKEY_MEDIA_LAUNCH_APP2, false, false, false);
166 EXPECT_TRUE(active_window_state->IsFullscreen());
167 SendKeyPressSync(ui::VKEY_MEDIA_LAUNCH_APP2, false, false, false);
168 EXPECT_FALSE(active_window_state->IsFullscreen());
171 // Tests a sample of ChromeOS specific accelerators.
172 TEST_F(AcceleratorInteractiveUITest, MAYBE_ChromeOsAccelerators) {
173 // Test TAKE_SCREENSHOT and TAKE_PARTIAL_SCREENSHOT.
174 TestScreenshotDelegate* screenshot_delegate = GetScreenshotDelegate();
175 screenshot_delegate->set_can_take_screenshot(true);
176 EXPECT_EQ(0, screenshot_delegate->handle_take_screenshot_count());
177 SendKeyPressSync(ui::VKEY_MEDIA_LAUNCH_APP1, true, false, false);
178 EXPECT_EQ(1, screenshot_delegate->handle_take_screenshot_count());
179 SendKeyPressSync(ui::VKEY_PRINT, false, false, false);
180 EXPECT_EQ(2, screenshot_delegate->handle_take_screenshot_count());
181 SendKeyPressSync(ui::VKEY_MEDIA_LAUNCH_APP1, true, true, false);
182 EXPECT_EQ(2, screenshot_delegate->handle_take_screenshot_count());
183 // Press ESC to go out of the partial screenshot mode.
184 SendKeyPressSync(ui::VKEY_ESCAPE, false, false, false);
186 // Test VOLUME_MUTE, VOLUME_DOWN, and VOLUME_UP.
187 TestVolumeControlDelegate* volume_delegate = new TestVolumeControlDelegate;
188 shell()->system_tray_delegate()->SetVolumeControlDelegate(
189 scoped_ptr<VolumeControlDelegate>(volume_delegate).Pass());
190 // VOLUME_MUTE.
191 EXPECT_EQ(0, volume_delegate->handle_volume_mute_count());
192 SendKeyPressSync(ui::VKEY_VOLUME_MUTE, false, false, false);
193 EXPECT_EQ(1, volume_delegate->handle_volume_mute_count());
194 // VOLUME_DOWN.
195 EXPECT_EQ(0, volume_delegate->handle_volume_down_count());
196 SendKeyPressSync(ui::VKEY_VOLUME_DOWN, false, false, false);
197 EXPECT_EQ(1, volume_delegate->handle_volume_down_count());
198 // VOLUME_UP.
199 EXPECT_EQ(0, volume_delegate->handle_volume_up_count());
200 SendKeyPressSync(ui::VKEY_VOLUME_UP, false, false, false);
201 EXPECT_EQ(1, volume_delegate->handle_volume_up_count());
203 // Test TOGGLE_WIFI.
204 TestNetworkObserver network_observer;
205 shell()->system_tray_notifier()->AddNetworkObserver(&network_observer);
207 EXPECT_FALSE(network_observer.wifi_enabled_status());
208 SendKeyPressSync(ui::VKEY_WLAN, false, false, false);
209 EXPECT_TRUE(network_observer.wifi_enabled_status());
210 SendKeyPressSync(ui::VKEY_WLAN, false, false, false);
211 EXPECT_FALSE(network_observer.wifi_enabled_status());
213 shell()->system_tray_notifier()->RemoveNetworkObserver(&network_observer);
216 // Tests the app list accelerator.
217 TEST_F(AcceleratorInteractiveUITest, MAYBE_ToggleAppList) {
218 EXPECT_FALSE(shell()->GetAppListTargetVisibility());
219 SendKeyPressSync(ui::VKEY_LWIN, false, false, false);
220 EXPECT_TRUE(shell()->GetAppListTargetVisibility());
221 SendKeyPressSync(ui::VKEY_LWIN, false, false, false);
222 EXPECT_FALSE(shell()->GetAppListTargetVisibility());
225 } // namespace test
226 } // namespace ash