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 <memory> | |
| 6 #include <string> | |
| 7 | |
| 8 #include "base/memory/ptr_util.h" | |
| 9 #include "base/strings/string_util.h" | |
| 10 #include "build/build_config.h" | |
| 11 #include "chrome/app/chrome_command_ids.h" | |
| 12 #include "chrome/browser/chrome_notification_types.h" | |
| 13 #include "chrome/browser/ui/browser.h" | |
| 14 #include "chrome/browser/ui/browser_commands.h" | |
| 15 #include "chrome/browser/ui/tabs/tab_strip_model.h" | |
| 16 #include "chrome/browser/ui/tabs/tab_strip_model_observer.h" | |
| 17 #include "chrome/test/base/in_process_browser_test.h" | |
| 18 #include "chrome/test/base/interactive_test_utils.h" | |
| 19 #include "content/public/browser/notification_service.h" | |
| 20 #include "content/public/test/browser_test_utils.h" | |
| 21 #include "content/public/test/test_utils.h" | |
| 22 #include "ui/events/keycodes/keyboard_codes.h" | |
| 23 #include "url/gurl.h" | |
| 24 | |
| 25 namespace { | |
| 26 // The html file to receive key events, prevent defaults and export all the | |
| 27 // events with "report()" function. It has two magic keys: pressing "S" to enter | |
| 28 // fullscreen mode; pressing "X" to indicate the end of all the keys. | |
| 29 constexpr char kFullscreenKeyboardLockHTML[] = | |
| 30 "/fullscreen_keyboardlock/fullscreen_keyboardlock.html"; | |
|
msw
2017/06/30 20:17:29
It seems a bit silly to create a new subdirectory
Hzj_jie
2017/07/01 01:56:47
Yes, I followed the fullscreen_mouselock. Done.
| |
| 31 | |
| 32 class TabCountObserver : public TabStripModelObserver { | |
|
msw
2017/06/30 20:17:28
Could you replace this class with a simpler helper
Hzj_jie
2017/07/01 01:56:47
Done.
| |
| 33 public: | |
| 34 TabCountObserver(Browser* browser, int expected); | |
| 35 ~TabCountObserver() override; | |
| 36 | |
| 37 private: | |
| 38 // TabStripModelObserver implementations. | |
| 39 void TabInsertedAt(TabStripModel* tab_strip_model, | |
|
msw
2017/06/30 20:17:29
Since you use this class to also track the closing
Hzj_jie
2017/07/01 01:56:47
Since a function is used to replace the observer,
| |
| 40 content::WebContents* contents, | |
| 41 int index, | |
| 42 bool foreground) override; | |
| 43 | |
| 44 const int expected_; | |
| 45 bool seen_ = false; | |
|
msw
2017/06/30 20:17:29
nit: rename |seen_| to something like |has_expecte
Hzj_jie
2017/07/01 01:56:48
Acknowledged.
| |
| 46 }; | |
| 47 | |
| 48 TabCountObserver::TabCountObserver(Browser* browser, int expected) | |
| 49 : expected_(expected) { | |
| 50 DCHECK(browser); | |
| 51 seen_ = (browser->tab_strip_model()->count() == expected_); | |
|
msw
2017/06/30 20:17:28
nit: parens not needed
Hzj_jie
2017/07/01 01:56:46
Acknowledged.
| |
| 52 if (!seen_) { | |
|
msw
2017/06/30 20:17:28
nit: curlies not needed for one line conditional a
Hzj_jie
2017/07/01 01:56:47
Acknowledged.
| |
| 53 browser->tab_strip_model()->AddObserver(this); | |
| 54 } | |
| 55 } | |
| 56 TabCountObserver::~TabCountObserver() { | |
|
msw
2017/06/30 20:17:28
nit: blank line above (or inline the definitions i
Hzj_jie
2017/07/01 01:56:46
Acknowledged.
| |
| 57 while (!seen_) { | |
|
msw
2017/06/30 20:17:29
ditto nit: curlies not needed for one line conditi
Hzj_jie
2017/07/01 01:56:47
Acknowledged.
| |
| 58 content::RunAllPendingInMessageLoop(); | |
| 59 } | |
| 60 } | |
| 61 | |
| 62 void TabCountObserver::TabInsertedAt(TabStripModel* tab_strip_model, | |
| 63 content::WebContents* contents, | |
| 64 int index, | |
| 65 bool foreground) { | |
| 66 if (tab_strip_model->count() == expected_) { | |
|
msw
2017/06/30 20:17:28
ditto nit: curlies not needed for one line conditi
Hzj_jie
2017/07/01 01:56:47
Acknowledged.
| |
| 67 seen_ = true; | |
| 68 } | |
| 69 } | |
| 70 | |
| 71 } // namespace | |
| 72 | |
| 73 class BrowserCommandControllerInteractiveTest : public InProcessBrowserTest { | |
| 74 public: | |
| 75 BrowserCommandControllerInteractiveTest() = default; | |
| 76 ~BrowserCommandControllerInteractiveTest() override = default; | |
| 77 | |
| 78 protected: | |
| 79 // Starts the test page and waits for it to be loaded. | |
| 80 void StartTestPage(); | |
| 81 | |
| 82 // Sends a control or command + |key| shortcut to the focused window. Shift | |
| 83 // modifier will be added once |shift| is true. | |
|
msw
2017/06/30 20:17:28
nit: s/once/if/
Hzj_jie
2017/07/01 01:56:46
Done.
| |
| 84 void SendShortcut(ui::KeyboardCode key, bool shift = false); | |
| 85 | |
| 86 // Sends a control or command + shift + |key| shortcut to the focused window. | |
| 87 void SendShiftShortcut(ui::KeyboardCode key); | |
|
msw
2017/06/30 20:17:28
nit: I'd opt to just use "SendShortcut(foo, true);
Hzj_jie
2017/07/01 01:56:47
My concern is
SendShortcut(ui::VKEY_A, true);
is n
| |
| 88 | |
| 89 // Sends a fullscreen shortcut to the focused window and wait for the | |
| 90 // operation to take effect. | |
| 91 void SendFullscreenShortcutAndWait(); | |
| 92 | |
| 93 // Sends a KeyS to the focused window to trigger JavaScript fullscreen and | |
| 94 // wait for the operation to take effect. | |
| 95 void SendJsFullscreenShortcutAndWait(); | |
| 96 | |
| 97 // Sends an ESC to the focused window. | |
| 98 void SendEscape(); | |
| 99 | |
| 100 // Sends an ESC to the focused window to exit JavaScript fullscreen and wait | |
| 101 // for the operation to take effect. | |
| 102 void SendEscapeAndWaitForExitingFullscreen(); | |
| 103 | |
| 104 // Sends a magic KeyX to the focused window to stop the test case and receives | |
| 105 // the result. | |
| 106 std::string FinishTestAndGetResult(); | |
| 107 }; | |
|
msw
2017/06/30 20:17:28
nit: add the private: DISSALLOW_COPY_AND_ASSIGN(Br
Hzj_jie
2017/07/01 01:56:47
Done.
| |
| 108 | |
| 109 void BrowserCommandControllerInteractiveTest::StartTestPage() { | |
| 110 ASSERT_TRUE(embedded_test_server()->Start()); | |
| 111 ui_test_utils::NavigateToURLWithDisposition( | |
| 112 browser(), | |
| 113 embedded_test_server()->GetURL(kFullscreenKeyboardLockHTML), | |
| 114 WindowOpenDisposition::CURRENT_TAB, | |
| 115 ui_test_utils::BROWSER_TEST_WAIT_FOR_NAVIGATION); | |
| 116 ASSERT_TRUE(ui_test_utils::BringBrowserWindowToFront(browser())); | |
| 117 } | |
| 118 | |
| 119 void BrowserCommandControllerInteractiveTest::SendShortcut( | |
| 120 ui::KeyboardCode key, | |
| 121 bool shift /* = false */) { | |
| 122 #if defined(OS_MACOSX) | |
| 123 const bool control_modifier = false; | |
| 124 const bool command_modifier = true; | |
| 125 #else | |
| 126 const bool control_modifier = true; | |
| 127 const bool command_modifier = false; | |
| 128 #endif | |
| 129 ASSERT_TRUE(ui_test_utils::SendKeyPressSync(browser(), | |
| 130 key, control_modifier, shift, false, command_modifier)); | |
| 131 } | |
| 132 | |
| 133 void BrowserCommandControllerInteractiveTest::SendShiftShortcut( | |
| 134 ui::KeyboardCode key) { | |
| 135 SendShortcut(key, true); | |
| 136 } | |
| 137 | |
| 138 void BrowserCommandControllerInteractiveTest::SendFullscreenShortcutAndWait() { | |
| 139 content::WindowedNotificationObserver observer( | |
| 140 chrome::NOTIFICATION_FULLSCREEN_CHANGED, | |
| 141 content::NotificationService::AllSources()); | |
| 142 // Enter fullscreen. | |
| 143 #if defined(OS_MACOSX) | |
| 144 // Command + Shift + F shortcut is not registered to interactive_ui_tests, so | |
|
msw
2017/06/30 20:17:29
nit: indent these two comment lines
Hzj_jie
2017/07/01 01:56:48
Done.
| |
| 145 // sending directly a fullscreen command instead. | |
|
msw
2017/06/30 20:17:28
nit: "send a fullscreen command directly instead."
Hzj_jie
2017/07/01 01:56:47
Done.
| |
| 146 ASSERT_TRUE(chrome::ExecuteCommand(browser(), IDC_FULLSCREEN)); | |
|
msw
2017/06/30 20:17:28
Strange, can you point to a bug or more info about
Hzj_jie
2017/07/01 01:56:47
I have very limited understanding to MacOSX. But i
tapted
2017/07/03 00:57:47
This doesn't match my experience.
There is an int
Hzj_jie
2017/07/07 23:18:10
Found the root cause: interactive_ui_tests window
| |
| 147 #elif defined(OS_CHROMEOS) | |
| 148 // A dedicated fullscreen key is used on Chrome OS, so sending directly a | |
|
msw
2017/06/30 20:17:28
nit: "send a fullscreen command directly instead,
Hzj_jie
2017/07/01 01:56:47
Done.
| |
| 149 // fullscreen command to avoid hacking the key press. | |
| 150 ASSERT_TRUE(chrome::ExecuteCommand(browser(), IDC_FULLSCREEN)); | |
| 151 #else | |
| 152 ASSERT_TRUE(ui_test_utils::SendKeyPressSync( | |
| 153 browser(), ui::VKEY_F11, false, false, false, false)); | |
| 154 #endif | |
| 155 observer.Wait(); | |
| 156 } | |
| 157 | |
| 158 void | |
| 159 BrowserCommandControllerInteractiveTest::SendJsFullscreenShortcutAndWait() { | |
| 160 content::WindowedNotificationObserver observer( | |
| 161 chrome::NOTIFICATION_FULLSCREEN_CHANGED, | |
|
tapted
2017/07/03 00:57:47
This might not be enough for Mac. We have a NSWin
Hzj_jie
2017/07/03 05:08:15
Emmm, indeed this test passes on Mac OSX, though I
| |
| 162 content::NotificationService::AllSources()); | |
| 163 ASSERT_TRUE(ui_test_utils::SendKeyPressSync( | |
| 164 browser(), ui::VKEY_S, false, false, false, false)); | |
| 165 observer.Wait(); | |
| 166 } | |
| 167 | |
| 168 void BrowserCommandControllerInteractiveTest::SendEscape() { | |
| 169 ASSERT_TRUE(ui_test_utils::SendKeyPressSync( | |
| 170 browser(), ui::VKEY_ESCAPE, false, false, false, false)); | |
| 171 } | |
| 172 | |
| 173 void BrowserCommandControllerInteractiveTest | |
| 174 ::SendEscapeAndWaitForExitingFullscreen() { | |
| 175 content::WindowedNotificationObserver observer( | |
| 176 chrome::NOTIFICATION_FULLSCREEN_CHANGED, | |
| 177 content::NotificationService::AllSources()); | |
| 178 SendEscape(); | |
| 179 observer.Wait(); | |
| 180 } | |
| 181 | |
| 182 std::string BrowserCommandControllerInteractiveTest::FinishTestAndGetResult() { | |
| 183 // Magic KeyX to stop the test. | |
| 184 EXPECT_TRUE(ui_test_utils::SendKeyPressSync(browser(), | |
| 185 ui::VKEY_X, false, false, false, false)); | |
| 186 std::string result; | |
| 187 EXPECT_TRUE(content::ExecuteScriptAndExtractString( | |
| 188 browser()->tab_strip_model()->GetActiveWebContents()->GetRenderViewHost(), | |
| 189 "report();", | |
| 190 &result)); | |
| 191 #if defined(OS_MACOSX) | |
| 192 // On MacOSX command key is used for most of the shortcuts, so replace it with | |
| 193 // control to reduce the complexity of comparison of the results. | |
| 194 base::ReplaceSubstringsAfterOffset(&result, 0, "MetaLeft", "ControlLeft"); | |
| 195 #endif | |
| 196 base::TrimWhitespaceASCII(result, base::TRIM_ALL, &result); | |
| 197 return result; | |
| 198 } | |
| 199 | |
| 200 IN_PROC_BROWSER_TEST_F(BrowserCommandControllerInteractiveTest, | |
| 201 ShortcutsShouldTakeEffectInWindowMode) { | |
| 202 ASSERT_EQ(browser()->tab_strip_model()->count(), 1); | |
| 203 SendShortcut(ui::VKEY_T); | |
| 204 { TabCountObserver observer(browser(), 2); } | |
| 205 ASSERT_EQ(browser()->tab_strip_model()->count(), 2); | |
| 206 SendShortcut(ui::VKEY_T); | |
| 207 { TabCountObserver observer(browser(), 3); } | |
| 208 ASSERT_EQ(browser()->tab_strip_model()->count(), 3); | |
| 209 #if !defined(OS_MACOSX) | |
| 210 // Command + W is not registered to interactive_ui_tests. So the following | |
| 211 // test cases won't work on Mac OSX. | |
| 212 SendShortcut(ui::VKEY_W); | |
| 213 { TabCountObserver observer(browser(), 2); } | |
| 214 ASSERT_EQ(browser()->tab_strip_model()->count(), 2); | |
| 215 SendShortcut(ui::VKEY_W); | |
| 216 { TabCountObserver observer(browser(), 1); } | |
| 217 ASSERT_EQ(browser()->tab_strip_model()->count(), 1); | |
| 218 #endif | |
| 219 SendFullscreenShortcutAndWait(); | |
| 220 ASSERT_TRUE(browser()-> | |
| 221 exclusive_access_manager()-> | |
| 222 fullscreen_controller()-> | |
| 223 IsFullscreenForBrowser()); | |
| 224 } | |
| 225 | |
| 226 IN_PROC_BROWSER_TEST_F(BrowserCommandControllerInteractiveTest, | |
| 227 UnpreservedShortcutsShouldBePreventable) { | |
| 228 ASSERT_EQ(browser()->tab_strip_model()->count(), 1); | |
| 229 StartTestPage(); | |
| 230 | |
| 231 // Print. | |
| 232 SendShortcut(ui::VKEY_P); | |
| 233 // Print by using system function. | |
| 234 SendShiftShortcut(ui::VKEY_P); | |
| 235 std::string result = FinishTestAndGetResult(); | |
| 236 // TODO(zijiehe): Investigate why inconsistent key event sequence has been | |
|
msw
2017/06/30 20:17:28
Can you clarify what's unexpected about the report
Hzj_jie
2017/07/01 01:56:47
IMO, this is an issue in test utilities: the test
tapted
2017/07/03 00:57:47
This probably has something to do with how the tes
Hzj_jie
2017/07/03 05:08:14
Besides the order of modifier keys, the keyup even
tapted
2017/07/03 05:52:41
The point is that if a result in a test is not rel
Hzj_jie
2017/07/03 20:08:15
Thank you for the information. Since the keyup is
tapted
2017/07/03 23:22:17
The kind of fragility I'm talking about here comes
| |
| 237 // generated on Mac OSX. | |
| 238 #if defined(OS_MACOSX) | |
| 239 ASSERT_EQ(result, | |
| 240 "keydown ControlLeft\n" | |
| 241 "keydown KeyP\n" | |
| 242 "keyup ControlLeft\n" | |
| 243 "keydown ShiftLeft\n" | |
| 244 "keydown ControlLeft\n" | |
| 245 "keydown KeyP\n" | |
| 246 "keyup ControlLeft\n" | |
| 247 "keyup ShiftLeft\n" | |
| 248 "keydown KeyX\n" | |
| 249 "keyup KeyX"); | |
| 250 #else | |
| 251 ASSERT_EQ(result, | |
| 252 "keydown ControlLeft\n" | |
| 253 "keydown KeyP\n" | |
| 254 "keyup KeyP\n" | |
| 255 "keyup ControlLeft\n" | |
| 256 "keydown ControlLeft\n" | |
| 257 "keydown ShiftLeft\n" | |
| 258 "keydown KeyP\n" | |
| 259 "keyup KeyP\n" | |
| 260 "keyup ShiftLeft\n" | |
| 261 "keyup ControlLeft\n" | |
| 262 "keydown KeyX\n" | |
| 263 "keyup KeyX"); | |
| 264 #endif | |
| 265 } | |
| 266 | |
| 267 #if defined(OS_MACOSX) | |
| 268 // TODO(zijiehe): Figure out why this test crashes on Mac OSX. The suspecious | |
|
msw
2017/06/30 20:17:28
nit: suspicious
Hzj_jie
2017/07/01 01:56:47
Done.
| |
| 269 // command is "SendFullscreenShortcutAndWait()". | |
| 270 #define MAYBE(X) DISABLED_##X | |
|
msw
2017/06/30 20:17:29
Hmm, bummer this entire test is broken on Mac... t
tapted
2017/07/03 00:57:47
urp - yeah what's the crash stacktrace? There are
Hzj_jie
2017/07/03 05:08:15
I tend to believe combining
content::WindowedNotif
Hzj_jie
2017/07/07 23:18:10
Crash stack traces are included in bug http://crbu
| |
| 271 #else | |
| 272 #define MAYBE(X) X | |
|
msw
2017/06/30 20:17:28
Please follow the more common pattern of:
#if defi
Hzj_jie
2017/07/01 01:56:46
Done.
| |
| 273 #endif | |
| 274 IN_PROC_BROWSER_TEST_F( | |
| 275 BrowserCommandControllerInteractiveTest, | |
| 276 MAYBE(KeyEventsShouldBeConsumedByWebPageInBrowserFullscreen)) { | |
| 277 ASSERT_EQ(browser()->tab_strip_model()->count(), 1); | |
| 278 StartTestPage(); | |
| 279 | |
| 280 SendFullscreenShortcutAndWait(); | |
| 281 // Close tab. | |
|
msw
2017/06/30 20:17:28
Rather than just commenting on what the shortcut t
Hzj_jie
2017/07/01 01:56:46
Done.
| |
| 282 SendShortcut(ui::VKEY_W); | |
| 283 // Close window. | |
| 284 SendShiftShortcut(ui::VKEY_W); | |
| 285 // TODO(zijiehe): ChromeOS has special shortcuts for the following four | |
|
msw
2017/06/30 20:17:29
nit: "// TODO(zijiehe): ChromeOS incorrectly handl
Hzj_jie
2017/07/01 01:56:47
Done.
| |
| 286 // commands, which should respect | |
| 287 // BrowserCommandController::IsReservedCommandOrKey(). | |
| 288 // see http://crbug.com/737307. | |
| 289 #if !defined(OS_CHROMEOS) | |
| 290 // New tab. | |
| 291 SendShortcut(ui::VKEY_T); | |
| 292 // New window. | |
| 293 SendShortcut(ui::VKEY_N); | |
| 294 // New incognito window. | |
| 295 SendShiftShortcut(ui::VKEY_N); | |
| 296 // Restore tab. | |
| 297 SendShiftShortcut(ui::VKEY_T); | |
| 298 #endif | |
| 299 // Next tab. | |
| 300 SendShortcut(ui::VKEY_TAB); | |
| 301 // Previous tab. | |
| 302 SendShiftShortcut(ui::VKEY_TAB); | |
| 303 // Esc. | |
| 304 SendEscape(); | |
| 305 | |
| 306 std::string result = FinishTestAndGetResult(); | |
| 307 // TODO(zijiehe): Investigate why inconsistent key event sequence has been | |
| 308 // generated on Mac OSX. | |
| 309 #if defined(OS_MACOSX) | |
| 310 ASSERT_EQ(result, | |
| 311 "keydown ControlLeft\n" | |
| 312 "keydown KeyW\n" | |
| 313 "keyup ControlLeft\n" | |
| 314 "keydown ShiftLeft\n" | |
| 315 "keydown ControlLeft\n" | |
| 316 "keydown KeyW\n" | |
| 317 "keyup ControlLeft\n" | |
| 318 "keyup ShiftLeft\n" | |
| 319 "keydown ControlLeft\n" | |
| 320 "keydown KeyT\n" | |
| 321 "keyup ControlLeft\n" | |
| 322 "keydown ControlLeft\n" | |
| 323 "keydown KeyN\n" | |
| 324 "keyup ControlLeft\n" | |
| 325 "keydown ShiftLeft\n" | |
| 326 "keydown ControlLeft\n" | |
| 327 "keydown KeyN\n" | |
| 328 "keyup ControlLeft\n" | |
| 329 "keyup ShiftLeft\n" | |
| 330 "keydown ShiftLeft\n" | |
| 331 "keydown ControlLeft\n" | |
| 332 "keydown KeyT\n" | |
| 333 "keyup ControlLeft\n" | |
| 334 "keyup ShiftLeft\n" | |
| 335 "keydown ControlLeft\n" | |
| 336 "keydown Tab\n" | |
| 337 "keyup ControlLeft\n" | |
| 338 "keydown ShiftLeft\n" | |
| 339 "keydown ControlLeft\n" | |
| 340 "keydown Tab\n" | |
| 341 "keyup Tab\n" | |
| 342 "keyup ControlLeft\n" | |
| 343 "keyup ShiftLeft\n" | |
| 344 "keydown Escape\n" | |
| 345 "keydown KeyX\n" | |
| 346 "keyup KeyX"); | |
| 347 #elif defined(OS_CHROMEOS) | |
| 348 ASSERT_EQ(result, | |
| 349 "keydown ControlLeft\n" | |
| 350 "keydown KeyW\n" | |
| 351 "keyup KeyW\n" | |
| 352 "keyup ControlLeft\n" | |
| 353 "keydown ControlLeft\n" | |
| 354 "keydown ShiftLeft\n" | |
| 355 "keydown KeyW\n" | |
| 356 "keyup KeyW\n" | |
| 357 "keyup ShiftLeft\n" | |
| 358 "keyup ControlLeft\n" | |
| 359 "keydown ControlLeft\n" | |
| 360 "keydown Tab\n" | |
| 361 "keyup Tab\n" | |
| 362 "keyup ControlLeft\n" | |
| 363 "keydown ControlLeft\n" | |
| 364 "keydown ShiftLeft\n" | |
| 365 "keydown Tab\n" | |
| 366 "keyup Tab\n" | |
| 367 "keyup ShiftLeft\n" | |
| 368 "keyup ControlLeft\n" | |
| 369 "keydown Escape\n" | |
| 370 "keyup Escape\n" | |
| 371 "keydown KeyX\n" | |
| 372 "keyup KeyX"); | |
| 373 #else | |
| 374 ASSERT_EQ(result, | |
| 375 "keydown ControlLeft\n" | |
| 376 "keydown KeyW\n" | |
| 377 "keyup KeyW\n" | |
| 378 "keyup ControlLeft\n" | |
| 379 "keydown ControlLeft\n" | |
| 380 "keydown ShiftLeft\n" | |
| 381 "keydown KeyW\n" | |
| 382 "keyup KeyW\n" | |
| 383 "keyup ShiftLeft\n" | |
| 384 "keyup ControlLeft\n" | |
| 385 "keydown ControlLeft\n" | |
| 386 "keydown KeyT\n" | |
| 387 "keyup KeyT\n" | |
| 388 "keyup ControlLeft\n" | |
| 389 "keydown ControlLeft\n" | |
| 390 "keydown KeyN\n" | |
| 391 "keyup KeyN\n" | |
| 392 "keyup ControlLeft\n" | |
| 393 "keydown ControlLeft\n" | |
| 394 "keydown ShiftLeft\n" | |
| 395 "keydown KeyN\n" | |
| 396 "keyup KeyN\n" | |
| 397 "keyup ShiftLeft\n" | |
| 398 "keyup ControlLeft\n" | |
| 399 "keydown ControlLeft\n" | |
| 400 "keydown ShiftLeft\n" | |
| 401 "keydown KeyT\n" | |
| 402 "keyup KeyT\n" | |
| 403 "keyup ShiftLeft\n" | |
| 404 "keyup ControlLeft\n" | |
| 405 "keydown ControlLeft\n" | |
| 406 "keydown Tab\n" | |
| 407 "keyup Tab\n" | |
| 408 "keyup ControlLeft\n" | |
| 409 "keydown ControlLeft\n" | |
| 410 "keydown ShiftLeft\n" | |
| 411 "keydown Tab\n" | |
| 412 "keyup Tab\n" | |
| 413 "keyup ShiftLeft\n" | |
| 414 "keyup ControlLeft\n" | |
| 415 "keydown Escape\n" | |
| 416 "keyup Escape\n" | |
| 417 "keydown KeyX\n" | |
| 418 "keyup KeyX"); | |
| 419 #endif | |
| 420 } | |
| 421 #undef MAYBE | |
| 422 | |
| 423 IN_PROC_BROWSER_TEST_F( | |
| 424 BrowserCommandControllerInteractiveTest, | |
| 425 KeyEventsShouldBeConsumedByWebPageInJsFullscreenExceptForEsc) { | |
|
msw
2017/06/30 20:17:28
Can you split these tests up a bit to avoid redund
Hzj_jie
2017/07/01 01:56:46
Yes, maybe I can use Send* functions to generate t
| |
| 426 ASSERT_EQ(browser()->tab_strip_model()->count(), 1); | |
| 427 StartTestPage(); | |
| 428 | |
| 429 SendJsFullscreenShortcutAndWait(); | |
| 430 // Close tab. | |
| 431 SendShortcut(ui::VKEY_W); | |
| 432 // Close window. | |
| 433 SendShiftShortcut(ui::VKEY_W); | |
| 434 // TODO(zijiehe): ChromeOS has special shortcuts for the following four | |
| 435 // commands, which should respect | |
| 436 // BrowserCommandController::IsReservedCommandOrKey(). | |
| 437 // see http://crbug.com/737307. | |
| 438 #if !defined(OS_CHROMEOS) | |
| 439 // New tab. | |
| 440 SendShortcut(ui::VKEY_T); | |
| 441 // New window. | |
| 442 SendShortcut(ui::VKEY_N); | |
| 443 // New incognito window. | |
| 444 SendShiftShortcut(ui::VKEY_N); | |
| 445 // Restore tab. | |
| 446 SendShiftShortcut(ui::VKEY_T); | |
| 447 #endif | |
| 448 // Next tab. | |
| 449 SendShortcut(ui::VKEY_TAB); | |
| 450 // Previous tab. | |
| 451 SendShiftShortcut(ui::VKEY_TAB); | |
| 452 SendEscapeAndWaitForExitingFullscreen(); | |
| 453 | |
| 454 std::string result = FinishTestAndGetResult(); | |
| 455 // TODO(zijiehe): Investigate why inconsistent key event sequence has been | |
| 456 // generated on Mac OSX. | |
| 457 #if defined(OS_MACOSX) | |
| 458 ASSERT_EQ(result, | |
| 459 "keydown KeyS\n" | |
| 460 "keyup KeyS\n" | |
| 461 "keydown ControlLeft\n" | |
| 462 "keydown KeyW\n" | |
| 463 "keyup ControlLeft\n" | |
| 464 "keydown ShiftLeft\n" | |
| 465 "keydown ControlLeft\n" | |
| 466 "keydown KeyW\n" | |
| 467 "keyup ControlLeft\n" | |
| 468 "keyup ShiftLeft\n" | |
| 469 "keydown ControlLeft\n" | |
| 470 "keydown KeyT\n" | |
| 471 "keyup ControlLeft\n" | |
| 472 "keydown ControlLeft\n" | |
| 473 "keydown KeyN\n" | |
| 474 "keyup ControlLeft\n" | |
| 475 "keydown ShiftLeft\n" | |
| 476 "keydown ControlLeft\n" | |
| 477 "keydown KeyN\n" | |
| 478 "keyup ControlLeft\n" | |
| 479 "keyup ShiftLeft\n" | |
| 480 "keydown ShiftLeft\n" | |
| 481 "keydown ControlLeft\n" | |
| 482 "keydown KeyT\n" | |
| 483 "keyup ControlLeft\n" | |
| 484 "keyup ShiftLeft\n" | |
| 485 "keydown ControlLeft\n" | |
| 486 "keydown Tab\n" | |
| 487 "keyup ControlLeft\n" | |
| 488 "keydown ShiftLeft\n" | |
| 489 "keydown ControlLeft\n" | |
| 490 "keydown Tab\n" | |
| 491 "keyup ControlLeft\n" | |
| 492 "keyup ShiftLeft\n" | |
| 493 "keydown KeyX\n" | |
| 494 "keyup KeyX"); | |
| 495 #elif defined(OS_CHROMEOS) | |
| 496 ASSERT_EQ(result, | |
| 497 "keydown KeyS\n" | |
| 498 "keyup KeyS\n" | |
| 499 "keydown ControlLeft\n" | |
| 500 "keydown KeyW\n" | |
| 501 "keyup KeyW\n" | |
| 502 "keyup ControlLeft\n" | |
| 503 "keydown ControlLeft\n" | |
| 504 "keydown ShiftLeft\n" | |
| 505 "keydown KeyW\n" | |
| 506 "keyup KeyW\n" | |
| 507 "keyup ShiftLeft\n" | |
| 508 "keyup ControlLeft\n" | |
| 509 "keydown ControlLeft\n" | |
| 510 "keydown Tab\n" | |
| 511 "keyup Tab\n" | |
| 512 "keyup ControlLeft\n" | |
| 513 "keydown ControlLeft\n" | |
| 514 "keydown ShiftLeft\n" | |
| 515 "keydown Tab\n" | |
| 516 "keyup Tab\n" | |
| 517 "keyup ShiftLeft\n" | |
| 518 "keyup ControlLeft\n" | |
| 519 "keydown KeyX\n" | |
| 520 "keyup KeyX"); | |
| 521 #else | |
| 522 ASSERT_EQ(result, | |
| 523 "keydown KeyS\n" | |
| 524 "keyup KeyS\n" | |
| 525 "keydown ControlLeft\n" | |
| 526 "keydown KeyW\n" | |
| 527 "keyup KeyW\n" | |
| 528 "keyup ControlLeft\n" | |
| 529 "keydown ControlLeft\n" | |
| 530 "keydown ShiftLeft\n" | |
| 531 "keydown KeyW\n" | |
| 532 "keyup KeyW\n" | |
| 533 "keyup ShiftLeft\n" | |
| 534 "keyup ControlLeft\n" | |
| 535 "keydown ControlLeft\n" | |
| 536 "keydown KeyT\n" | |
| 537 "keyup KeyT\n" | |
| 538 "keyup ControlLeft\n" | |
| 539 "keydown ControlLeft\n" | |
| 540 "keydown KeyN\n" | |
| 541 "keyup KeyN\n" | |
| 542 "keyup ControlLeft\n" | |
| 543 "keydown ControlLeft\n" | |
| 544 "keydown ShiftLeft\n" | |
| 545 "keydown KeyN\n" | |
| 546 "keyup KeyN\n" | |
| 547 "keyup ShiftLeft\n" | |
| 548 "keyup ControlLeft\n" | |
| 549 "keydown ControlLeft\n" | |
| 550 "keydown ShiftLeft\n" | |
| 551 "keydown KeyT\n" | |
| 552 "keyup KeyT\n" | |
| 553 "keyup ShiftLeft\n" | |
| 554 "keyup ControlLeft\n" | |
| 555 "keydown ControlLeft\n" | |
| 556 "keydown Tab\n" | |
| 557 "keyup Tab\n" | |
| 558 "keyup ControlLeft\n" | |
| 559 "keydown ControlLeft\n" | |
| 560 "keydown ShiftLeft\n" | |
| 561 "keydown Tab\n" | |
| 562 "keyup Tab\n" | |
| 563 "keyup ShiftLeft\n" | |
| 564 "keyup ControlLeft\n" | |
| 565 "keydown KeyX\n" | |
| 566 "keyup KeyX"); | |
| 567 #endif | |
| 568 } | |
| 569 | |
| 570 IN_PROC_BROWSER_TEST_F( | |
| 571 BrowserCommandControllerInteractiveTest, | |
| 572 KeyEventsShouldBeConsumedByWebPageInJsFullscreenExceptForF11) { | |
| 573 ASSERT_EQ(browser()->tab_strip_model()->count(), 1); | |
| 574 StartTestPage(); | |
| 575 | |
| 576 SendJsFullscreenShortcutAndWait(); | |
| 577 // Close tab. | |
| 578 SendShortcut(ui::VKEY_W); | |
| 579 // Close window. | |
| 580 SendShiftShortcut(ui::VKEY_W); | |
| 581 // TODO(zijiehe): ChromeOS has special shortcuts for the following four | |
| 582 // commands, which should respect | |
| 583 // BrowserCommandController::IsReservedCommandOrKey(). | |
| 584 // see http://crbug.com/737307. | |
| 585 #if !defined(OS_CHROMEOS) | |
| 586 // New tab. | |
| 587 SendShortcut(ui::VKEY_T); | |
| 588 // New window. | |
| 589 SendShortcut(ui::VKEY_N); | |
| 590 // New incognito window. | |
| 591 SendShiftShortcut(ui::VKEY_N); | |
| 592 // Restore tab. | |
| 593 SendShiftShortcut(ui::VKEY_T); | |
| 594 #endif | |
| 595 // Next tab. | |
| 596 SendShortcut(ui::VKEY_TAB); | |
| 597 // Previous tab. | |
| 598 SendShiftShortcut(ui::VKEY_TAB); | |
| 599 SendFullscreenShortcutAndWait(); | |
| 600 | |
| 601 std::string result = FinishTestAndGetResult(); | |
| 602 // TODO(zijiehe): Investigate why inconsistent key event sequence has been | |
| 603 // generated on Mac OSX. | |
| 604 #if defined(OS_MACOSX) | |
| 605 ASSERT_EQ(result, | |
| 606 "keydown KeyS\n" | |
| 607 "keyup KeyS\n" | |
| 608 "keydown ControlLeft\n" | |
| 609 "keydown KeyW\n" | |
| 610 "keyup ControlLeft\n" | |
| 611 "keydown ShiftLeft\n" | |
| 612 "keydown ControlLeft\n" | |
| 613 "keydown KeyW\n" | |
| 614 "keyup ControlLeft\n" | |
| 615 "keyup ShiftLeft\n" | |
| 616 "keydown ControlLeft\n" | |
| 617 "keydown KeyT\n" | |
| 618 "keyup ControlLeft\n" | |
| 619 "keydown ControlLeft\n" | |
| 620 "keydown KeyN\n" | |
| 621 "keyup ControlLeft\n" | |
| 622 "keydown ShiftLeft\n" | |
| 623 "keydown ControlLeft\n" | |
| 624 "keydown KeyN\n" | |
| 625 "keyup ControlLeft\n" | |
| 626 "keyup ShiftLeft\n" | |
| 627 "keydown ShiftLeft\n" | |
| 628 "keydown ControlLeft\n" | |
| 629 "keydown KeyT\n" | |
| 630 "keyup ControlLeft\n" | |
| 631 "keyup ShiftLeft\n" | |
| 632 "keydown ControlLeft\n" | |
| 633 "keydown Tab\n" | |
| 634 "keyup ControlLeft\n" | |
| 635 "keydown ShiftLeft\n" | |
| 636 "keydown ControlLeft\n" | |
| 637 "keydown Tab\n" | |
| 638 "keyup ControlLeft\n" | |
| 639 "keyup ShiftLeft\n" | |
| 640 "keydown KeyX\n" | |
| 641 "keyup KeyX"); | |
| 642 #elif defined(OS_CHROMEOS) | |
| 643 ASSERT_EQ(result, | |
| 644 "keydown KeyS\n" | |
| 645 "keyup KeyS\n" | |
| 646 "keydown ControlLeft\n" | |
| 647 "keydown KeyW\n" | |
| 648 "keyup KeyW\n" | |
| 649 "keyup ControlLeft\n" | |
| 650 "keydown ControlLeft\n" | |
| 651 "keydown ShiftLeft\n" | |
| 652 "keydown KeyW\n" | |
| 653 "keyup KeyW\n" | |
| 654 "keyup ShiftLeft\n" | |
| 655 "keyup ControlLeft\n" | |
| 656 "keydown ControlLeft\n" | |
| 657 "keydown Tab\n" | |
| 658 "keyup Tab\n" | |
| 659 "keyup ControlLeft\n" | |
| 660 "keydown ControlLeft\n" | |
| 661 "keydown ShiftLeft\n" | |
| 662 "keydown Tab\n" | |
| 663 "keyup Tab\n" | |
| 664 "keyup ShiftLeft\n" | |
| 665 "keyup ControlLeft\n" | |
| 666 "keydown KeyX\n" | |
| 667 "keyup KeyX"); | |
| 668 #else | |
| 669 ASSERT_EQ(result, | |
| 670 "keydown KeyS\n" | |
| 671 "keyup KeyS\n" | |
| 672 "keydown ControlLeft\n" | |
| 673 "keydown KeyW\n" | |
| 674 "keyup KeyW\n" | |
| 675 "keyup ControlLeft\n" | |
| 676 "keydown ControlLeft\n" | |
| 677 "keydown ShiftLeft\n" | |
| 678 "keydown KeyW\n" | |
| 679 "keyup KeyW\n" | |
| 680 "keyup ShiftLeft\n" | |
| 681 "keyup ControlLeft\n" | |
| 682 "keydown ControlLeft\n" | |
| 683 "keydown KeyT\n" | |
| 684 "keyup KeyT\n" | |
| 685 "keyup ControlLeft\n" | |
| 686 "keydown ControlLeft\n" | |
| 687 "keydown KeyN\n" | |
| 688 "keyup KeyN\n" | |
| 689 "keyup ControlLeft\n" | |
| 690 "keydown ControlLeft\n" | |
| 691 "keydown ShiftLeft\n" | |
| 692 "keydown KeyN\n" | |
| 693 "keyup KeyN\n" | |
| 694 "keyup ShiftLeft\n" | |
| 695 "keyup ControlLeft\n" | |
| 696 "keydown ControlLeft\n" | |
| 697 "keydown ShiftLeft\n" | |
| 698 "keydown KeyT\n" | |
| 699 "keyup KeyT\n" | |
| 700 "keyup ShiftLeft\n" | |
| 701 "keyup ControlLeft\n" | |
| 702 "keydown ControlLeft\n" | |
| 703 "keydown Tab\n" | |
| 704 "keyup Tab\n" | |
| 705 "keyup ControlLeft\n" | |
| 706 "keydown ControlLeft\n" | |
| 707 "keydown ShiftLeft\n" | |
| 708 "keydown Tab\n" | |
| 709 "keyup Tab\n" | |
| 710 "keyup ShiftLeft\n" | |
| 711 "keyup ControlLeft\n" | |
| 712 "keydown KeyX\n" | |
| 713 "keyup KeyX"); | |
| 714 #endif | |
| 715 } | |
| OLD | NEW |