Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 // Copyright 2017 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 <string> | |
| 6 | |
| 7 #include "base/strings/string_util.h" | |
| 8 #include "build/build_config.h" | |
| 9 #include "chrome/app/chrome_command_ids.h" | |
| 10 #include "chrome/browser/chrome_notification_types.h" | |
| 11 #include "chrome/browser/ui/browser.h" | |
| 12 #include "chrome/browser/ui/browser_commands.h" | |
| 13 #include "chrome/browser/ui/tabs/tab_strip_model.h" | |
| 14 #include "chrome/test/base/interactive_test_utils.h" | |
| 15 #include "chrome/test/base/in_process_browser_test.h" | |
| 16 #include "content/public/browser/notification_service.h" | |
| 17 #include "content/public/test/browser_test_utils.h" | |
| 18 #include "ui/events/keycodes/keyboard_codes.h" | |
| 19 #include "url/gurl.h" | |
| 20 | |
| 21 namespace { | |
| 22 constexpr char kFullscreenKeyboardLockHTML[] = | |
|
msw
2017/06/06 20:32:07
nit: comment on what this is
Hzj_jie
2017/06/28 00:34:43
Done.
| |
| 23 "/fullscreen_keyboardlock/fullscreen_keyboardlock.html"; | |
| 24 | |
| 25 class FullscreenNotificationObserver | |
|
msw
2017/06/06 20:32:07
Avoid this subclass, just construct a WindowedNoti
Hzj_jie
2017/06/28 00:34:43
Done.
| |
| 26 : public content::WindowedNotificationObserver { | |
|
msw
2017/06/06 20:32:06
nit: include content/public/test/test_utils.h to u
Hzj_jie
2017/06/28 00:34:43
Done.
| |
| 27 public: | |
| 28 FullscreenNotificationObserver() : WindowedNotificationObserver( | |
| 29 chrome::NOTIFICATION_FULLSCREEN_CHANGED, | |
| 30 content::NotificationService::AllSources()) {} | |
| 31 ~FullscreenNotificationObserver() override { | |
| 32 Wait(); | |
| 33 } | |
| 34 }; | |
| 35 | |
| 36 } // namespace | |
| 37 | |
| 38 using BrowserCommandControllerInteractiveTest = InProcessBrowserTest; | |
| 39 | |
| 40 #if defined(OS_MACOSX) | |
| 41 // On Mac OSX, accelerators cannot receive the events sent from | |
| 42 // SendKeyPressSync(), so the following tests cannot work. | |
| 43 // TODO(zijiehe): Make SendKeyPressSync() respect shortcuts on Mac OSX. | |
|
msw
2017/06/06 20:32:06
File a bug; cite its number here.
Hzj_jie
2017/06/28 00:34:43
Done.
| |
| 44 #define MAYBE(X) DISABLED_##X | |
| 45 #elif defined(OS_CHROMEOS) | |
| 46 // Crash on ChromeOS | |
| 47 // BrowserTestBase received signal: Terminated. Backtrace: | |
|
msw
2017/06/06 20:32:06
Don't include a stack trace here; address this bef
Hzj_jie
2017/06/28 00:34:43
Done.
| |
| 48 // #0 0x000003363eec base::debug::StackTrace::StackTrace() | |
| 49 // #1 0x0000029b7f62 content::(anonymous namespace)::DumpStackTraceSignalHandler () | |
| 50 // #2 0x7f0297078cb0 <unknown> | |
| 51 // #3 0x7f029713284d __poll | |
| 52 // #4 0x7f029ade5fe4 <unknown> | |
| 53 // #5 0x7f029ade60ec g_main_context_iteration | |
| 54 // #6 0x000003386825 base::MessagePumpGlib::Run() | |
| 55 // #7 0x0000033840eb base::MessageLoop::Run() | |
| 56 // #8 0x0000033ae25a base::RunLoop::Run() | |
| 57 // #9 0x0000029c2726 content::MessageLoopRunner::Run() | |
| 58 // #10 0x0000029c2b9d content::WindowedNotificationObserver::Wait() | |
| 59 // TODO(zijiehe): Fix crash on ChromeOS. | |
| 60 #define MAYBE(X) DISABLED_##X | |
| 61 #elif defined(OS_WIN) | |
| 62 // Tests depending on keyboard inputs are flaky on Windows, see test case | |
|
msw
2017/06/06 20:32:07
Citing that file isn't sufficient (I don't see wha
Hzj_jie
2017/06/28 00:34:43
Done.
| |
| 63 // https://cs.chromium.org/chromium/src/chrome/browser/browser_keyevents_browser test.cc | |
| 64 // for detail. | |
| 65 #define MAYBE(X) DISABLED_##X | |
|
msw
2017/06/06 20:32:06
Sorry I don't have any great ideas for making thes
Hzj_jie
2017/06/28 00:34:43
Done.
| |
| 66 #else | |
| 67 #define MAYBE(X) X | |
| 68 #endif | |
| 69 | |
| 70 IN_PROC_BROWSER_TEST_F(BrowserCommandControllerInteractiveTest, | |
| 71 MAYBE(InF11Fullscreen)) { | |
|
msw
2017/06/06 20:32:06
nit: use a better name here, what is this test che
Hzj_jie
2017/06/28 00:34:43
Done.
| |
| 72 ASSERT_TRUE(embedded_test_server()->Start()); | |
| 73 { | |
| 74 FullscreenNotificationObserver fullscreen_observer; | |
| 75 // Enter fullscreen. | |
| 76 #if defined(OS_MACOSX) | |
|
msw
2017/06/06 20:32:06
nit: add a local helper: void PressFullscreenShort
Hzj_jie
2017/06/28 00:34:43
Done.
| |
| 77 ASSERT_TRUE(ui_test_utils::SendKeyPressSync( | |
| 78 browser(), ui::VKEY_F, true, false, false, true)); | |
| 79 #else | |
| 80 ASSERT_TRUE(ui_test_utils::SendKeyPressSync( | |
| 81 browser(), ui::VKEY_F11, false, false, false, false)); | |
| 82 #endif | |
| 83 } | |
| 84 ui_test_utils::NavigateToURL(browser(), | |
| 85 embedded_test_server()->GetURL(kFullscreenKeyboardLockHTML)); | |
| 86 #if defined(OS_MACOSX) | |
|
msw
2017/06/06 20:32:07
nit: add a local helper: bool PressKeySync(ui::Key
Hzj_jie
2017/06/28 00:34:43
Done.
| |
| 87 const bool control_modifier = false; | |
| 88 const bool command_modifier = true; | |
| 89 #else | |
| 90 const bool control_modifier = true; | |
| 91 const bool command_modifier = false; | |
| 92 #endif | |
| 93 // Close tab. | |
| 94 ASSERT_TRUE(ui_test_utils::SendKeyPressSync(browser(), | |
| 95 ui::VKEY_W, control_modifier, false, false, command_modifier)); | |
| 96 // Close window. | |
| 97 ASSERT_TRUE(ui_test_utils::SendKeyPressSync(browser(), | |
| 98 ui::VKEY_W, control_modifier, true, false, command_modifier)); | |
| 99 // New tab. | |
| 100 ASSERT_TRUE(ui_test_utils::SendKeyPressSync(browser(), | |
| 101 ui::VKEY_T, control_modifier, false, false, command_modifier)); | |
| 102 // New window. | |
| 103 ASSERT_TRUE(ui_test_utils::SendKeyPressSync(browser(), | |
| 104 ui::VKEY_N, control_modifier, false, false, command_modifier)); | |
| 105 // New incognito window. | |
| 106 ASSERT_TRUE(ui_test_utils::SendKeyPressSync(browser(), | |
| 107 ui::VKEY_N, control_modifier, true, false, command_modifier)); | |
| 108 // Restore tab. | |
| 109 ASSERT_TRUE(ui_test_utils::SendKeyPressSync(browser(), | |
| 110 ui::VKEY_T, control_modifier, true, false, command_modifier)); | |
| 111 // Next tab. | |
| 112 ASSERT_TRUE(ui_test_utils::SendKeyPressSync(browser(), | |
| 113 ui::VKEY_TAB, control_modifier, false, false, command_modifier)); | |
| 114 // Previous tab. | |
| 115 ASSERT_TRUE(ui_test_utils::SendKeyPressSync(browser(), | |
| 116 ui::VKEY_TAB, control_modifier, true, false, command_modifier)); | |
| 117 // Esc. | |
| 118 ASSERT_TRUE(ui_test_utils::SendKeyPressSync(browser(), | |
| 119 ui::VKEY_ESCAPE, false, false, false, false)); | |
| 120 // Magic key X to stop the test. | |
| 121 ASSERT_TRUE(ui_test_utils::SendKeyPressSync(browser(), | |
| 122 ui::VKEY_X, false, false, false, false)); | |
| 123 | |
| 124 std::string result; | |
| 125 ASSERT_TRUE(content::ExecuteScriptAndExtractString( | |
| 126 browser()->tab_strip_model()->GetActiveWebContents()->GetRenderViewHost(), | |
| 127 "report()", | |
| 128 &result)); | |
| 129 #if defined(OS_MACOSX) | |
| 130 base::ReplaceSubstringsAfterOffset(&result, 0, "MetaLeft", "ControlLeft"); | |
| 131 #endif | |
| 132 base::TrimWhitespaceASCII(result, base::TRIM_ALL, &result); | |
| 133 ASSERT_EQ(result, | |
| 134 "keydown ControlLeft\n" | |
| 135 "keydown KeyW\n" | |
| 136 "keyup KeyW\n" | |
| 137 "keyup ControlLeft\n" | |
| 138 "keydown ControlLeft\n" | |
| 139 "keydown ShiftLeft\n" | |
| 140 "keydown KeyW\n" | |
| 141 "keyup KeyW\n" | |
| 142 "keyup ShiftLeft\n" | |
| 143 "keyup ControlLeft\n" | |
| 144 "keydown ControlLeft\n" | |
| 145 "keydown KeyT\n" | |
| 146 "keyup KeyT\n" | |
| 147 "keyup ControlLeft\n" | |
| 148 "keydown ControlLeft\n" | |
| 149 "keydown KeyN\n" | |
| 150 "keyup KeyN\n" | |
| 151 "keyup ControlLeft\n" | |
| 152 "keydown ControlLeft\n" | |
| 153 "keydown ShiftLeft\n" | |
| 154 "keydown KeyN\n" | |
| 155 "keyup KeyN\n" | |
| 156 "keyup ShiftLeft\n" | |
| 157 "keyup ControlLeft\n" | |
| 158 "keydown ControlLeft\n" | |
| 159 "keydown ShiftLeft\n" | |
| 160 "keydown KeyT\n" | |
| 161 "keyup KeyT\n" | |
| 162 "keyup ShiftLeft\n" | |
| 163 "keyup ControlLeft\n" | |
| 164 "keydown ControlLeft\n" | |
| 165 "keydown Tab\n" | |
| 166 "keyup Tab\n" | |
| 167 "keyup ControlLeft\n" | |
| 168 "keydown ControlLeft\n" | |
| 169 "keydown ShiftLeft\n" | |
| 170 "keydown Tab\n" | |
| 171 "keyup Tab\n" | |
| 172 "keyup ShiftLeft\n" | |
| 173 "keyup ControlLeft\n" | |
| 174 "keydown Escape\n" | |
| 175 "keyup Escape\n" | |
| 176 "keydown KeyX\n" | |
| 177 "keyup KeyX"); | |
| 178 } | |
| 179 | |
| 180 IN_PROC_BROWSER_TEST_F(BrowserCommandControllerInteractiveTest, | |
| 181 MAYBE(ExitHTMLFullscreenWithEsc)) { | |
|
msw
2017/06/06 20:32:06
nit: try to use a consistent naming pattern for th
Hzj_jie
2017/06/28 00:34:43
Done.
| |
| 182 ASSERT_TRUE(embedded_test_server()->Start()); | |
| 183 ui_test_utils::NavigateToURL(browser(), | |
| 184 embedded_test_server()->GetURL(kFullscreenKeyboardLockHTML)); | |
| 185 { | |
| 186 FullscreenNotificationObserver fullscreen_observer; | |
| 187 ASSERT_TRUE(ui_test_utils::SendKeyPressSync( | |
| 188 browser(), ui::VKEY_S, false, false, false, false)); | |
|
msw
2017/06/06 20:32:07
q: Is 's' another magic key to make the page trigg
Hzj_jie
2017/06/28 00:34:43
Done.
| |
| 189 } | |
| 190 #if defined(OS_MACOSX) | |
| 191 const bool control_modifier = false; | |
| 192 const bool command_modifier = true; | |
| 193 #else | |
| 194 const bool control_modifier = true; | |
| 195 const bool command_modifier = false; | |
| 196 #endif | |
| 197 // Close tab. | |
| 198 ASSERT_TRUE(ui_test_utils::SendKeyPressSync(browser(), | |
| 199 ui::VKEY_W, control_modifier, false, false, command_modifier)); | |
| 200 // Close window. | |
| 201 ASSERT_TRUE(ui_test_utils::SendKeyPressSync(browser(), | |
| 202 ui::VKEY_W, control_modifier, true, false, command_modifier)); | |
| 203 // New tab. | |
| 204 ASSERT_TRUE(ui_test_utils::SendKeyPressSync(browser(), | |
| 205 ui::VKEY_T, control_modifier, false, false, command_modifier)); | |
| 206 // New window. | |
| 207 ASSERT_TRUE(ui_test_utils::SendKeyPressSync(browser(), | |
| 208 ui::VKEY_N, control_modifier, false, false, command_modifier)); | |
| 209 // New incognito window. | |
| 210 ASSERT_TRUE(ui_test_utils::SendKeyPressSync(browser(), | |
| 211 ui::VKEY_N, control_modifier, true, false, command_modifier)); | |
| 212 // Restore tab. | |
| 213 ASSERT_TRUE(ui_test_utils::SendKeyPressSync(browser(), | |
| 214 ui::VKEY_T, control_modifier, true, false, command_modifier)); | |
| 215 // Next tab. | |
| 216 ASSERT_TRUE(ui_test_utils::SendKeyPressSync(browser(), | |
| 217 ui::VKEY_TAB, control_modifier, false, false, command_modifier)); | |
| 218 // Previous tab. | |
| 219 ASSERT_TRUE(ui_test_utils::SendKeyPressSync(browser(), | |
| 220 ui::VKEY_TAB, control_modifier, true, false, command_modifier)); | |
| 221 { | |
| 222 FullscreenNotificationObserver fullscreen_observer; | |
| 223 // Esc. | |
|
msw
2017/06/06 20:32:06
nit: "// Esc should exit fullscreen, when ..." (ex
Hzj_jie
2017/06/28 00:34:43
Done.
| |
| 224 ASSERT_TRUE(ui_test_utils::SendKeyPressSync(browser(), | |
| 225 ui::VKEY_ESCAPE, false, false, false, command_modifier)); | |
| 226 } | |
| 227 // Magic key X to stop the test. | |
| 228 ASSERT_TRUE(ui_test_utils::SendKeyPressSync(browser(), | |
| 229 ui::VKEY_X, false, false, false, false)); | |
| 230 | |
| 231 std::string result; | |
| 232 ASSERT_TRUE(content::ExecuteScriptAndExtractString( | |
| 233 browser()->tab_strip_model()->GetActiveWebContents()->GetRenderViewHost(), | |
| 234 "report()", | |
| 235 &result)); | |
| 236 #if defined(OS_MACOSX) | |
| 237 base::ReplaceSubstringsAfterOffset(&result, 0, "MetaLeft", "ControlLeft"); | |
| 238 #endif | |
| 239 base::TrimWhitespaceASCII(result, base::TRIM_ALL, &result); | |
| 240 ASSERT_EQ(result, | |
| 241 "keydown KeyS\n" | |
| 242 "keyup KeyS\n" | |
| 243 "keydown ControlLeft\n" | |
| 244 "keydown KeyW\n" | |
| 245 "keyup KeyW\n" | |
| 246 "keyup ControlLeft\n" | |
| 247 "keydown ControlLeft\n" | |
| 248 "keydown ShiftLeft\n" | |
| 249 "keydown KeyW\n" | |
| 250 "keyup KeyW\n" | |
| 251 "keyup ShiftLeft\n" | |
| 252 "keyup ControlLeft\n" | |
| 253 "keydown ControlLeft\n" | |
| 254 "keydown KeyT\n" | |
| 255 "keyup KeyT\n" | |
| 256 "keyup ControlLeft\n" | |
| 257 "keydown ControlLeft\n" | |
| 258 "keydown KeyN\n" | |
| 259 "keyup KeyN\n" | |
| 260 "keyup ControlLeft\n" | |
| 261 "keydown ControlLeft\n" | |
| 262 "keydown ShiftLeft\n" | |
| 263 "keydown KeyN\n" | |
| 264 "keyup KeyN\n" | |
| 265 "keyup ShiftLeft\n" | |
| 266 "keyup ControlLeft\n" | |
| 267 "keydown ControlLeft\n" | |
| 268 "keydown ShiftLeft\n" | |
| 269 "keydown KeyT\n" | |
| 270 "keyup KeyT\n" | |
| 271 "keyup ShiftLeft\n" | |
| 272 "keyup ControlLeft\n" | |
| 273 "keydown ControlLeft\n" | |
| 274 "keydown Tab\n" | |
| 275 "keyup Tab\n" | |
| 276 "keyup ControlLeft\n" | |
| 277 "keydown ControlLeft\n" | |
| 278 "keydown ShiftLeft\n" | |
| 279 "keydown Tab\n" | |
| 280 "keyup Tab\n" | |
| 281 "keyup ShiftLeft\n" | |
| 282 "keyup ControlLeft\n" | |
| 283 "keydown KeyX\n" | |
| 284 "keyup KeyX"); | |
| 285 } | |
| 286 | |
| 287 IN_PROC_BROWSER_TEST_F(BrowserCommandControllerInteractiveTest, | |
| 288 MAYBE(ExitHTMLFullscreenWithF11)) { | |
| 289 ASSERT_TRUE(embedded_test_server()->Start()); | |
| 290 ui_test_utils::NavigateToURL(browser(), | |
| 291 embedded_test_server()->GetURL(kFullscreenKeyboardLockHTML)); | |
| 292 { | |
| 293 FullscreenNotificationObserver fullscreen_observer; | |
| 294 ASSERT_TRUE(ui_test_utils::SendKeyPressSync( | |
| 295 browser(), ui::VKEY_S, false, false, false, false)); | |
| 296 } | |
| 297 #if defined(OS_MACOSX) | |
| 298 const bool control_modifier = false; | |
| 299 const bool command_modifier = true; | |
| 300 #else | |
| 301 const bool control_modifier = true; | |
| 302 const bool command_modifier = false; | |
| 303 #endif | |
| 304 // Close tab. | |
| 305 ASSERT_TRUE(ui_test_utils::SendKeyPressSync(browser(), | |
| 306 ui::VKEY_W, control_modifier, false, false, command_modifier)); | |
| 307 // Close window. | |
| 308 ASSERT_TRUE(ui_test_utils::SendKeyPressSync(browser(), | |
| 309 ui::VKEY_W, control_modifier, true, false, command_modifier)); | |
| 310 // New tab. | |
| 311 ASSERT_TRUE(ui_test_utils::SendKeyPressSync(browser(), | |
| 312 ui::VKEY_T, control_modifier, false, false, command_modifier)); | |
| 313 // New window. | |
| 314 ASSERT_TRUE(ui_test_utils::SendKeyPressSync(browser(), | |
| 315 ui::VKEY_N, control_modifier, false, false, command_modifier)); | |
| 316 // New incognito window. | |
| 317 ASSERT_TRUE(ui_test_utils::SendKeyPressSync(browser(), | |
| 318 ui::VKEY_N, control_modifier, true, false, command_modifier)); | |
| 319 // Restore tab. | |
| 320 ASSERT_TRUE(ui_test_utils::SendKeyPressSync(browser(), | |
| 321 ui::VKEY_T, control_modifier, true, false, command_modifier)); | |
| 322 // Next tab. | |
| 323 ASSERT_TRUE(ui_test_utils::SendKeyPressSync(browser(), | |
| 324 ui::VKEY_TAB, control_modifier, false, false, command_modifier)); | |
| 325 // Previous tab. | |
| 326 ASSERT_TRUE(ui_test_utils::SendKeyPressSync(browser(), | |
| 327 ui::VKEY_TAB, control_modifier, true, false, command_modifier)); | |
| 328 { | |
| 329 FullscreenNotificationObserver fullscreen_observer; | |
| 330 // Exit fullscreen. | |
| 331 #if defined(OS_MACOSX) | |
| 332 ASSERT_TRUE(ui_test_utils::SendKeyPressSync( | |
| 333 browser(), ui::VKEY_F, true, false, false, true)); | |
| 334 #else | |
| 335 ASSERT_TRUE(ui_test_utils::SendKeyPressSync( | |
| 336 browser(), ui::VKEY_F11, false, false, false, false)); | |
| 337 #endif | |
| 338 } | |
| 339 // Magic key X to stop the test. | |
| 340 ASSERT_TRUE(ui_test_utils::SendKeyPressSync(browser(), | |
| 341 ui::VKEY_X, false, false, false, false)); | |
| 342 | |
| 343 std::string result; | |
| 344 ASSERT_TRUE(content::ExecuteScriptAndExtractString( | |
| 345 browser()->tab_strip_model()->GetActiveWebContents()->GetRenderViewHost(), | |
| 346 "report()", | |
| 347 &result)); | |
| 348 #if defined(OS_MACOSX) | |
| 349 base::ReplaceSubstringsAfterOffset(&result, 0, "MetaLeft", "ControlLeft"); | |
| 350 #endif | |
| 351 base::TrimWhitespaceASCII(result, base::TRIM_ALL, &result); | |
| 352 ASSERT_EQ(result, | |
| 353 "keydown KeyS\n" | |
| 354 "keyup KeyS\n" | |
| 355 "keydown ControlLeft\n" | |
| 356 "keydown KeyW\n" | |
| 357 "keyup KeyW\n" | |
| 358 "keyup ControlLeft\n" | |
| 359 "keydown ControlLeft\n" | |
| 360 "keydown ShiftLeft\n" | |
| 361 "keydown KeyW\n" | |
| 362 "keyup KeyW\n" | |
| 363 "keyup ShiftLeft\n" | |
| 364 "keyup ControlLeft\n" | |
| 365 "keydown ControlLeft\n" | |
| 366 "keydown KeyT\n" | |
| 367 "keyup KeyT\n" | |
| 368 "keyup ControlLeft\n" | |
| 369 "keydown ControlLeft\n" | |
| 370 "keydown KeyN\n" | |
| 371 "keyup KeyN\n" | |
| 372 "keyup ControlLeft\n" | |
| 373 "keydown ControlLeft\n" | |
| 374 "keydown ShiftLeft\n" | |
| 375 "keydown KeyN\n" | |
| 376 "keyup KeyN\n" | |
| 377 "keyup ShiftLeft\n" | |
| 378 "keyup ControlLeft\n" | |
| 379 "keydown ControlLeft\n" | |
| 380 "keydown ShiftLeft\n" | |
| 381 "keydown KeyT\n" | |
| 382 "keyup KeyT\n" | |
| 383 "keyup ShiftLeft\n" | |
| 384 "keyup ControlLeft\n" | |
| 385 "keydown ControlLeft\n" | |
| 386 "keydown Tab\n" | |
| 387 "keyup Tab\n" | |
| 388 "keyup ControlLeft\n" | |
| 389 "keydown ControlLeft\n" | |
| 390 "keydown ShiftLeft\n" | |
| 391 "keydown Tab\n" | |
| 392 "keyup Tab\n" | |
| 393 "keyup ShiftLeft\n" | |
| 394 "keyup ControlLeft\n" | |
| 395 "keydown KeyX\n" | |
| 396 "keyup KeyX"); | |
| 397 } | |
| OLD | NEW |