Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(159)

Side by Side Diff: ash/accelerators/accelerator_interactive_uitest.cc

Issue 1005093004: Test Accelerators In Interactive UI Tests in CrOs (Retry) (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | chrome/chrome_tests.gypi » ('j') | chrome/chrome_tests.gypi » ('J')
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(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 namespace ash {
29 namespace test {
30
31 namespace {
32
33 #if defined(OS_CHROMEOS)
34 // A network observer to watch for the toggle wifi events.
35 class TestNetworkObserver : public NetworkObserver {
36 public:
37 TestNetworkObserver() : wifi_enabled_status_(false) {}
38
39 // ash::NetworkObserver:
40 void RequestToggleWifi() override {
41 wifi_enabled_status_ = !wifi_enabled_status_;
42 }
43
44 bool wifi_enabled_status() const { return wifi_enabled_status_; }
45
46 private:
47 bool wifi_enabled_status_;
48
49 DISALLOW_COPY_AND_ASSIGN(TestNetworkObserver);
50 };
51 #endif // defined(OS_CHROMEOS)
52
53 } // namespace
54
55 ////////////////////////////////////////////////////////////////////////////////
56
57 // This is intended to test few samples from each category of accelerators to
58 // make sure they work properly. The test is done as an interactive ui test
59 // using ui_controls::Send*() functions.
60 // This is to catch any future regressions (crbug.com/469235).
61 class AcceleratorInteractiveUITest : public AshTestBase, public ShellObserver {
62 public:
63 AcceleratorInteractiveUITest() : is_in_overview_mode_(false) {}
64
65 void SetUp() override {
66 gfx::GLSurface::InitializeOneOffForTests();
67
68 ui::RegisterPathProvider();
69 ui::ResourceBundle::InitSharedInstanceWithLocale(
70 "en-US", NULL, ui::ResourceBundle::LOAD_COMMON_RESOURCES);
71 base::FilePath resources_pack_path;
72 PathService::Get(base::DIR_MODULE, &resources_pack_path);
73 resources_pack_path =
74 resources_pack_path.Append(FILE_PATH_LITERAL("resources.pak"));
75 ResourceBundle::GetSharedInstance().AddDataPackFromPath(
76 resources_pack_path, ui::SCALE_FACTOR_NONE);
77
78 AshTestBase::SetUp();
79
80 Shell::GetInstance()->AddShellObserver(this);
81
82 #if defined(OS_CHROMEOS)
83 chromeos::NetworkHandler::Initialize();
84 #endif // defined(OS_CHROMEOS)
85 }
86
87 void TearDown() override {
88 #if defined(OS_CHROMEOS)
89 chromeos::NetworkHandler::Shutdown();
90 #endif // defined(OS_CHROMEOS)
91
92 Shell::GetInstance()->RemoveShellObserver(this);
93
94 AshTestBase::TearDown();
95 }
96
97 // Sends a key press event and waits synchronously until it's completely
98 // processed.
99 void SendKeyPressSync(ui::KeyboardCode key,
100 bool control,
101 bool shift,
102 bool alt) {
103 base::RunLoop loop;
104 ui_controls::SendKeyPressNotifyWhenDone(root_window(), key, control, shift,
105 alt, false, loop.QuitClosure());
106 loop.Run();
107 }
108
109 // ash::ShellObserver:
110 void OnOverviewModeStarting() override { is_in_overview_mode_ = true; }
111 void OnOverviewModeEnded() override { is_in_overview_mode_ = false; }
112
113 Shell* shell() const { return Shell::GetInstance(); }
114 aura::Window* root_window() const { return Shell::GetPrimaryRootWindow(); }
115
116 protected:
117 bool is_in_overview_mode_;
118
119 private:
120 DISALLOW_COPY_AND_ASSIGN(AcceleratorInteractiveUITest);
121 };
122
123 ////////////////////////////////////////////////////////////////////////////////
124
125 #if defined(OS_CHROMEOS) && !defined(OFFICIAL_BUILD)
James Cook 2015/03/25 20:14:54 Now that I think about it more I would just rename
afakhry 2015/03/25 20:46:52 Done.
126 // Tests a sample of the non-repeatable accelerators that need windows to be
127 // enabled.
128 TEST_F(AcceleratorInteractiveUITest, TestNonRepeatableNeedingWindowActions) {
129 // Create a bunch of windows to work with.
130 aura::Window* window_1 =
131 CreateTestWindowInShellWithBounds(gfx::Rect(0, 0, 100, 100));
132 aura::Window* window_2 =
133 CreateTestWindowInShellWithBounds(gfx::Rect(0, 0, 100, 100));
134 window_1->Show();
135 wm::ActivateWindow(window_1);
136 window_2->Show();
137 wm::ActivateWindow(window_2);
138
139 // Test TOGGLE_OVERVIEW.
140 EXPECT_FALSE(is_in_overview_mode_);
141 SendKeyPressSync(ui::VKEY_MEDIA_LAUNCH_APP1, false, false, false);
142 EXPECT_TRUE(is_in_overview_mode_);
143 SendKeyPressSync(ui::VKEY_MEDIA_LAUNCH_APP1, false, false, false);
144 EXPECT_FALSE(is_in_overview_mode_);
145
146 // Test CYCLE_FORWARD_MRU and CYCLE_BACKWARD_MRU.
147 wm::ActivateWindow(window_1);
148 EXPECT_TRUE(wm::IsActiveWindow(window_1));
149 EXPECT_FALSE(wm::IsActiveWindow(window_2));
150 SendKeyPressSync(ui::VKEY_TAB, false, false, true); // CYCLE_FORWARD_MRU.
151 EXPECT_TRUE(wm::IsActiveWindow(window_2));
152 EXPECT_FALSE(wm::IsActiveWindow(window_1));
153 SendKeyPressSync(ui::VKEY_TAB, false, true, true); // CYCLE_BACKWARD_MRU.
154 EXPECT_TRUE(wm::IsActiveWindow(window_1));
155 EXPECT_FALSE(wm::IsActiveWindow(window_2));
156
157 // Test TOGGLE_FULLSCREEN.
158 wm::WindowState* active_window_state = wm::GetActiveWindowState();
159 EXPECT_FALSE(active_window_state->IsFullscreen());
160 SendKeyPressSync(ui::VKEY_MEDIA_LAUNCH_APP2, false, false, false);
161 EXPECT_TRUE(active_window_state->IsFullscreen());
162 SendKeyPressSync(ui::VKEY_MEDIA_LAUNCH_APP2, false, false, false);
163 EXPECT_FALSE(active_window_state->IsFullscreen());
164 }
165
166 // Tests a sample of ChromeOS specific accelerators.
167 TEST_F(AcceleratorInteractiveUITest, ChromeOsAccelerators) {
168 // Test TAKE_SCREENSHOT and TAKE_PARTIAL_SCREENSHOT.
169 TestScreenshotDelegate* screenshot_delegate = GetScreenshotDelegate();
170 screenshot_delegate->set_can_take_screenshot(true);
171 EXPECT_EQ(0, screenshot_delegate->handle_take_screenshot_count());
172 SendKeyPressSync(ui::VKEY_MEDIA_LAUNCH_APP1, true, false, false);
173 EXPECT_EQ(1, screenshot_delegate->handle_take_screenshot_count());
174 SendKeyPressSync(ui::VKEY_PRINT, false, false, false);
175 EXPECT_EQ(2, screenshot_delegate->handle_take_screenshot_count());
176 SendKeyPressSync(ui::VKEY_MEDIA_LAUNCH_APP1, true, true, false);
177 EXPECT_EQ(2, screenshot_delegate->handle_take_screenshot_count());
178 // Press ESC to go out of the partial screenshot mode.
179 SendKeyPressSync(ui::VKEY_ESCAPE, false, false, false);
180
181 // Test VOLUME_MUTE, VOLUME_DOWN, and VOLUME_UP.
182 TestVolumeControlDelegate* volume_delegate = new TestVolumeControlDelegate;
183 shell()->system_tray_delegate()->SetVolumeControlDelegate(
184 scoped_ptr<VolumeControlDelegate>(volume_delegate).Pass());
185 // VOLUME_MUTE.
186 EXPECT_EQ(0, volume_delegate->handle_volume_mute_count());
187 SendKeyPressSync(ui::VKEY_VOLUME_MUTE, false, false, false);
188 EXPECT_EQ(1, volume_delegate->handle_volume_mute_count());
189 // VOLUME_DOWN.
190 EXPECT_EQ(0, volume_delegate->handle_volume_down_count());
191 SendKeyPressSync(ui::VKEY_VOLUME_DOWN, false, false, false);
192 EXPECT_EQ(1, volume_delegate->handle_volume_down_count());
193 // VOLUME_UP.
194 EXPECT_EQ(0, volume_delegate->handle_volume_up_count());
195 SendKeyPressSync(ui::VKEY_VOLUME_UP, false, false, false);
196 EXPECT_EQ(1, volume_delegate->handle_volume_up_count());
197
198 // Test TOGGLE_WIFI.
199 TestNetworkObserver network_observer;
200 shell()->system_tray_notifier()->AddNetworkObserver(&network_observer);
201
202 EXPECT_FALSE(network_observer.wifi_enabled_status());
203 SendKeyPressSync(ui::VKEY_WLAN, false, false, false);
204 EXPECT_TRUE(network_observer.wifi_enabled_status());
205 SendKeyPressSync(ui::VKEY_WLAN, false, false, false);
206 EXPECT_FALSE(network_observer.wifi_enabled_status());
207
208 shell()->system_tray_notifier()->RemoveNetworkObserver(&network_observer);
209 }
210
211 // Tests the app list accelerator.
212 TEST_F(AcceleratorInteractiveUITest, ToggleAppList) {
213 EXPECT_FALSE(shell()->GetAppListTargetVisibility());
214 SendKeyPressSync(ui::VKEY_LWIN, false, false, false);
215 EXPECT_TRUE(shell()->GetAppListTargetVisibility());
216 SendKeyPressSync(ui::VKEY_LWIN, false, false, false);
217 EXPECT_FALSE(shell()->GetAppListTargetVisibility());
218 }
219 #endif // defined(OS_CHROMEOS)
220
221 } // namespace test
222 } // namespace ash
OLDNEW
« no previous file with comments | « no previous file | chrome/chrome_tests.gypi » ('j') | chrome/chrome_tests.gypi » ('J')

Powered by Google App Engine
This is Rietveld 408576698