Chromium Code Reviews| Index: chrome/browser/ui/browser_command_controller_interactive_browsertest.cc |
| diff --git a/chrome/browser/ui/browser_command_controller_interactive_browsertest.cc b/chrome/browser/ui/browser_command_controller_interactive_browsertest.cc |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..66faa7108d21eb13e72422ca7ab5cd6a9c3ab787 |
| --- /dev/null |
| +++ b/chrome/browser/ui/browser_command_controller_interactive_browsertest.cc |
| @@ -0,0 +1,715 @@ |
| +// Copyright 2017 The Chromium Authors. All rights reserved. |
| +// Use of this source code is governed by a BSD-style license that can be |
| +// found in the LICENSE file. |
| + |
| +#include <memory> |
| +#include <string> |
| + |
| +#include "base/memory/ptr_util.h" |
| +#include "base/strings/string_util.h" |
| +#include "build/build_config.h" |
| +#include "chrome/app/chrome_command_ids.h" |
| +#include "chrome/browser/chrome_notification_types.h" |
| +#include "chrome/browser/ui/browser.h" |
| +#include "chrome/browser/ui/browser_commands.h" |
| +#include "chrome/browser/ui/tabs/tab_strip_model.h" |
| +#include "chrome/browser/ui/tabs/tab_strip_model_observer.h" |
| +#include "chrome/test/base/in_process_browser_test.h" |
| +#include "chrome/test/base/interactive_test_utils.h" |
| +#include "content/public/browser/notification_service.h" |
| +#include "content/public/test/browser_test_utils.h" |
| +#include "content/public/test/test_utils.h" |
| +#include "ui/events/keycodes/keyboard_codes.h" |
| +#include "url/gurl.h" |
| + |
| +namespace { |
| +// The html file to receive key events, prevent defaults and export all the |
| +// events with "report()" function. It has two magic keys: pressing "S" to enter |
| +// fullscreen mode; pressing "X" to indicate the end of all the keys. |
| +constexpr char kFullscreenKeyboardLockHTML[] = |
| + "/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.
|
| + |
| +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.
|
| + public: |
| + TabCountObserver(Browser* browser, int expected); |
| + ~TabCountObserver() override; |
| + |
| + private: |
| + // TabStripModelObserver implementations. |
| + 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,
|
| + content::WebContents* contents, |
| + int index, |
| + bool foreground) override; |
| + |
| + const int expected_; |
| + 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.
|
| +}; |
| + |
| +TabCountObserver::TabCountObserver(Browser* browser, int expected) |
| + : expected_(expected) { |
| + DCHECK(browser); |
| + 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.
|
| + 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.
|
| + browser->tab_strip_model()->AddObserver(this); |
| + } |
| +} |
| +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.
|
| + 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.
|
| + content::RunAllPendingInMessageLoop(); |
| + } |
| +} |
| + |
| +void TabCountObserver::TabInsertedAt(TabStripModel* tab_strip_model, |
| + content::WebContents* contents, |
| + int index, |
| + bool foreground) { |
| + 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.
|
| + seen_ = true; |
| + } |
| +} |
| + |
| +} // namespace |
| + |
| +class BrowserCommandControllerInteractiveTest : public InProcessBrowserTest { |
| + public: |
| + BrowserCommandControllerInteractiveTest() = default; |
| + ~BrowserCommandControllerInteractiveTest() override = default; |
| + |
| + protected: |
| + // Starts the test page and waits for it to be loaded. |
| + void StartTestPage(); |
| + |
| + // Sends a control or command + |key| shortcut to the focused window. Shift |
| + // 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.
|
| + void SendShortcut(ui::KeyboardCode key, bool shift = false); |
| + |
| + // Sends a control or command + shift + |key| shortcut to the focused window. |
| + 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
|
| + |
| + // Sends a fullscreen shortcut to the focused window and wait for the |
| + // operation to take effect. |
| + void SendFullscreenShortcutAndWait(); |
| + |
| + // Sends a KeyS to the focused window to trigger JavaScript fullscreen and |
| + // wait for the operation to take effect. |
| + void SendJsFullscreenShortcutAndWait(); |
| + |
| + // Sends an ESC to the focused window. |
| + void SendEscape(); |
| + |
| + // Sends an ESC to the focused window to exit JavaScript fullscreen and wait |
| + // for the operation to take effect. |
| + void SendEscapeAndWaitForExitingFullscreen(); |
| + |
| + // Sends a magic KeyX to the focused window to stop the test case and receives |
| + // the result. |
| + std::string FinishTestAndGetResult(); |
| +}; |
|
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.
|
| + |
| +void BrowserCommandControllerInteractiveTest::StartTestPage() { |
| + ASSERT_TRUE(embedded_test_server()->Start()); |
| + ui_test_utils::NavigateToURLWithDisposition( |
| + browser(), |
| + embedded_test_server()->GetURL(kFullscreenKeyboardLockHTML), |
| + WindowOpenDisposition::CURRENT_TAB, |
| + ui_test_utils::BROWSER_TEST_WAIT_FOR_NAVIGATION); |
| + ASSERT_TRUE(ui_test_utils::BringBrowserWindowToFront(browser())); |
| +} |
| + |
| +void BrowserCommandControllerInteractiveTest::SendShortcut( |
| + ui::KeyboardCode key, |
| + bool shift /* = false */) { |
| +#if defined(OS_MACOSX) |
| + const bool control_modifier = false; |
| + const bool command_modifier = true; |
| +#else |
| + const bool control_modifier = true; |
| + const bool command_modifier = false; |
| +#endif |
| + ASSERT_TRUE(ui_test_utils::SendKeyPressSync(browser(), |
| + key, control_modifier, shift, false, command_modifier)); |
| +} |
| + |
| +void BrowserCommandControllerInteractiveTest::SendShiftShortcut( |
| + ui::KeyboardCode key) { |
| + SendShortcut(key, true); |
| +} |
| + |
| +void BrowserCommandControllerInteractiveTest::SendFullscreenShortcutAndWait() { |
| + content::WindowedNotificationObserver observer( |
| + chrome::NOTIFICATION_FULLSCREEN_CHANGED, |
| + content::NotificationService::AllSources()); |
| + // Enter fullscreen. |
| +#if defined(OS_MACOSX) |
| +// 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.
|
| +// 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.
|
| + 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
|
| +#elif defined(OS_CHROMEOS) |
| + // 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.
|
| + // fullscreen command to avoid hacking the key press. |
| + ASSERT_TRUE(chrome::ExecuteCommand(browser(), IDC_FULLSCREEN)); |
| +#else |
| + ASSERT_TRUE(ui_test_utils::SendKeyPressSync( |
| + browser(), ui::VKEY_F11, false, false, false, false)); |
| +#endif |
| + observer.Wait(); |
| +} |
| + |
| +void |
| +BrowserCommandControllerInteractiveTest::SendJsFullscreenShortcutAndWait() { |
| + content::WindowedNotificationObserver observer( |
| + 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
|
| + content::NotificationService::AllSources()); |
| + ASSERT_TRUE(ui_test_utils::SendKeyPressSync( |
| + browser(), ui::VKEY_S, false, false, false, false)); |
| + observer.Wait(); |
| +} |
| + |
| +void BrowserCommandControllerInteractiveTest::SendEscape() { |
| + ASSERT_TRUE(ui_test_utils::SendKeyPressSync( |
| + browser(), ui::VKEY_ESCAPE, false, false, false, false)); |
| +} |
| + |
| +void BrowserCommandControllerInteractiveTest |
| + ::SendEscapeAndWaitForExitingFullscreen() { |
| + content::WindowedNotificationObserver observer( |
| + chrome::NOTIFICATION_FULLSCREEN_CHANGED, |
| + content::NotificationService::AllSources()); |
| + SendEscape(); |
| + observer.Wait(); |
| +} |
| + |
| +std::string BrowserCommandControllerInteractiveTest::FinishTestAndGetResult() { |
| + // Magic KeyX to stop the test. |
| + EXPECT_TRUE(ui_test_utils::SendKeyPressSync(browser(), |
| + ui::VKEY_X, false, false, false, false)); |
| + std::string result; |
| + EXPECT_TRUE(content::ExecuteScriptAndExtractString( |
| + browser()->tab_strip_model()->GetActiveWebContents()->GetRenderViewHost(), |
| + "report();", |
| + &result)); |
| +#if defined(OS_MACOSX) |
| + // On MacOSX command key is used for most of the shortcuts, so replace it with |
| + // control to reduce the complexity of comparison of the results. |
| + base::ReplaceSubstringsAfterOffset(&result, 0, "MetaLeft", "ControlLeft"); |
| +#endif |
| + base::TrimWhitespaceASCII(result, base::TRIM_ALL, &result); |
| + return result; |
| +} |
| + |
| +IN_PROC_BROWSER_TEST_F(BrowserCommandControllerInteractiveTest, |
| + ShortcutsShouldTakeEffectInWindowMode) { |
| + ASSERT_EQ(browser()->tab_strip_model()->count(), 1); |
| + SendShortcut(ui::VKEY_T); |
| + { TabCountObserver observer(browser(), 2); } |
| + ASSERT_EQ(browser()->tab_strip_model()->count(), 2); |
| + SendShortcut(ui::VKEY_T); |
| + { TabCountObserver observer(browser(), 3); } |
| + ASSERT_EQ(browser()->tab_strip_model()->count(), 3); |
| +#if !defined(OS_MACOSX) |
| + // Command + W is not registered to interactive_ui_tests. So the following |
| + // test cases won't work on Mac OSX. |
| + SendShortcut(ui::VKEY_W); |
| + { TabCountObserver observer(browser(), 2); } |
| + ASSERT_EQ(browser()->tab_strip_model()->count(), 2); |
| + SendShortcut(ui::VKEY_W); |
| + { TabCountObserver observer(browser(), 1); } |
| + ASSERT_EQ(browser()->tab_strip_model()->count(), 1); |
| +#endif |
| + SendFullscreenShortcutAndWait(); |
| + ASSERT_TRUE(browser()-> |
| + exclusive_access_manager()-> |
| + fullscreen_controller()-> |
| + IsFullscreenForBrowser()); |
| +} |
| + |
| +IN_PROC_BROWSER_TEST_F(BrowserCommandControllerInteractiveTest, |
| + UnpreservedShortcutsShouldBePreventable) { |
| + ASSERT_EQ(browser()->tab_strip_model()->count(), 1); |
| + StartTestPage(); |
| + |
| + // Print. |
| + SendShortcut(ui::VKEY_P); |
| + // Print by using system function. |
| + SendShiftShortcut(ui::VKEY_P); |
| + std::string result = FinishTestAndGetResult(); |
| + // 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
|
| + // generated on Mac OSX. |
| +#if defined(OS_MACOSX) |
| + ASSERT_EQ(result, |
| + "keydown ControlLeft\n" |
| + "keydown KeyP\n" |
| + "keyup ControlLeft\n" |
| + "keydown ShiftLeft\n" |
| + "keydown ControlLeft\n" |
| + "keydown KeyP\n" |
| + "keyup ControlLeft\n" |
| + "keyup ShiftLeft\n" |
| + "keydown KeyX\n" |
| + "keyup KeyX"); |
| +#else |
| + ASSERT_EQ(result, |
| + "keydown ControlLeft\n" |
| + "keydown KeyP\n" |
| + "keyup KeyP\n" |
| + "keyup ControlLeft\n" |
| + "keydown ControlLeft\n" |
| + "keydown ShiftLeft\n" |
| + "keydown KeyP\n" |
| + "keyup KeyP\n" |
| + "keyup ShiftLeft\n" |
| + "keyup ControlLeft\n" |
| + "keydown KeyX\n" |
| + "keyup KeyX"); |
| +#endif |
| +} |
| + |
| +#if defined(OS_MACOSX) |
| +// 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.
|
| +// command is "SendFullscreenShortcutAndWait()". |
| +#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
|
| +#else |
| +#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.
|
| +#endif |
| +IN_PROC_BROWSER_TEST_F( |
| + BrowserCommandControllerInteractiveTest, |
| + MAYBE(KeyEventsShouldBeConsumedByWebPageInBrowserFullscreen)) { |
| + ASSERT_EQ(browser()->tab_strip_model()->count(), 1); |
| + StartTestPage(); |
| + |
| + SendFullscreenShortcutAndWait(); |
| + // 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.
|
| + SendShortcut(ui::VKEY_W); |
| + // Close window. |
| + SendShiftShortcut(ui::VKEY_W); |
| + // 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.
|
| + // commands, which should respect |
| + // BrowserCommandController::IsReservedCommandOrKey(). |
| + // see http://crbug.com/737307. |
| +#if !defined(OS_CHROMEOS) |
| + // New tab. |
| + SendShortcut(ui::VKEY_T); |
| + // New window. |
| + SendShortcut(ui::VKEY_N); |
| + // New incognito window. |
| + SendShiftShortcut(ui::VKEY_N); |
| + // Restore tab. |
| + SendShiftShortcut(ui::VKEY_T); |
| +#endif |
| + // Next tab. |
| + SendShortcut(ui::VKEY_TAB); |
| + // Previous tab. |
| + SendShiftShortcut(ui::VKEY_TAB); |
| + // Esc. |
| + SendEscape(); |
| + |
| + std::string result = FinishTestAndGetResult(); |
| + // TODO(zijiehe): Investigate why inconsistent key event sequence has been |
| + // generated on Mac OSX. |
| +#if defined(OS_MACOSX) |
| + ASSERT_EQ(result, |
| + "keydown ControlLeft\n" |
| + "keydown KeyW\n" |
| + "keyup ControlLeft\n" |
| + "keydown ShiftLeft\n" |
| + "keydown ControlLeft\n" |
| + "keydown KeyW\n" |
| + "keyup ControlLeft\n" |
| + "keyup ShiftLeft\n" |
| + "keydown ControlLeft\n" |
| + "keydown KeyT\n" |
| + "keyup ControlLeft\n" |
| + "keydown ControlLeft\n" |
| + "keydown KeyN\n" |
| + "keyup ControlLeft\n" |
| + "keydown ShiftLeft\n" |
| + "keydown ControlLeft\n" |
| + "keydown KeyN\n" |
| + "keyup ControlLeft\n" |
| + "keyup ShiftLeft\n" |
| + "keydown ShiftLeft\n" |
| + "keydown ControlLeft\n" |
| + "keydown KeyT\n" |
| + "keyup ControlLeft\n" |
| + "keyup ShiftLeft\n" |
| + "keydown ControlLeft\n" |
| + "keydown Tab\n" |
| + "keyup ControlLeft\n" |
| + "keydown ShiftLeft\n" |
| + "keydown ControlLeft\n" |
| + "keydown Tab\n" |
| + "keyup Tab\n" |
| + "keyup ControlLeft\n" |
| + "keyup ShiftLeft\n" |
| + "keydown Escape\n" |
| + "keydown KeyX\n" |
| + "keyup KeyX"); |
| +#elif defined(OS_CHROMEOS) |
| + ASSERT_EQ(result, |
| + "keydown ControlLeft\n" |
| + "keydown KeyW\n" |
| + "keyup KeyW\n" |
| + "keyup ControlLeft\n" |
| + "keydown ControlLeft\n" |
| + "keydown ShiftLeft\n" |
| + "keydown KeyW\n" |
| + "keyup KeyW\n" |
| + "keyup ShiftLeft\n" |
| + "keyup ControlLeft\n" |
| + "keydown ControlLeft\n" |
| + "keydown Tab\n" |
| + "keyup Tab\n" |
| + "keyup ControlLeft\n" |
| + "keydown ControlLeft\n" |
| + "keydown ShiftLeft\n" |
| + "keydown Tab\n" |
| + "keyup Tab\n" |
| + "keyup ShiftLeft\n" |
| + "keyup ControlLeft\n" |
| + "keydown Escape\n" |
| + "keyup Escape\n" |
| + "keydown KeyX\n" |
| + "keyup KeyX"); |
| +#else |
| + ASSERT_EQ(result, |
| + "keydown ControlLeft\n" |
| + "keydown KeyW\n" |
| + "keyup KeyW\n" |
| + "keyup ControlLeft\n" |
| + "keydown ControlLeft\n" |
| + "keydown ShiftLeft\n" |
| + "keydown KeyW\n" |
| + "keyup KeyW\n" |
| + "keyup ShiftLeft\n" |
| + "keyup ControlLeft\n" |
| + "keydown ControlLeft\n" |
| + "keydown KeyT\n" |
| + "keyup KeyT\n" |
| + "keyup ControlLeft\n" |
| + "keydown ControlLeft\n" |
| + "keydown KeyN\n" |
| + "keyup KeyN\n" |
| + "keyup ControlLeft\n" |
| + "keydown ControlLeft\n" |
| + "keydown ShiftLeft\n" |
| + "keydown KeyN\n" |
| + "keyup KeyN\n" |
| + "keyup ShiftLeft\n" |
| + "keyup ControlLeft\n" |
| + "keydown ControlLeft\n" |
| + "keydown ShiftLeft\n" |
| + "keydown KeyT\n" |
| + "keyup KeyT\n" |
| + "keyup ShiftLeft\n" |
| + "keyup ControlLeft\n" |
| + "keydown ControlLeft\n" |
| + "keydown Tab\n" |
| + "keyup Tab\n" |
| + "keyup ControlLeft\n" |
| + "keydown ControlLeft\n" |
| + "keydown ShiftLeft\n" |
| + "keydown Tab\n" |
| + "keyup Tab\n" |
| + "keyup ShiftLeft\n" |
| + "keyup ControlLeft\n" |
| + "keydown Escape\n" |
| + "keyup Escape\n" |
| + "keydown KeyX\n" |
| + "keyup KeyX"); |
| +#endif |
| +} |
| +#undef MAYBE |
| + |
| +IN_PROC_BROWSER_TEST_F( |
| + BrowserCommandControllerInteractiveTest, |
| + 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
|
| + ASSERT_EQ(browser()->tab_strip_model()->count(), 1); |
| + StartTestPage(); |
| + |
| + SendJsFullscreenShortcutAndWait(); |
| + // Close tab. |
| + SendShortcut(ui::VKEY_W); |
| + // Close window. |
| + SendShiftShortcut(ui::VKEY_W); |
| + // TODO(zijiehe): ChromeOS has special shortcuts for the following four |
| + // commands, which should respect |
| + // BrowserCommandController::IsReservedCommandOrKey(). |
| + // see http://crbug.com/737307. |
| +#if !defined(OS_CHROMEOS) |
| + // New tab. |
| + SendShortcut(ui::VKEY_T); |
| + // New window. |
| + SendShortcut(ui::VKEY_N); |
| + // New incognito window. |
| + SendShiftShortcut(ui::VKEY_N); |
| + // Restore tab. |
| + SendShiftShortcut(ui::VKEY_T); |
| +#endif |
| + // Next tab. |
| + SendShortcut(ui::VKEY_TAB); |
| + // Previous tab. |
| + SendShiftShortcut(ui::VKEY_TAB); |
| + SendEscapeAndWaitForExitingFullscreen(); |
| + |
| + std::string result = FinishTestAndGetResult(); |
| + // TODO(zijiehe): Investigate why inconsistent key event sequence has been |
| + // generated on Mac OSX. |
| +#if defined(OS_MACOSX) |
| + ASSERT_EQ(result, |
| + "keydown KeyS\n" |
| + "keyup KeyS\n" |
| + "keydown ControlLeft\n" |
| + "keydown KeyW\n" |
| + "keyup ControlLeft\n" |
| + "keydown ShiftLeft\n" |
| + "keydown ControlLeft\n" |
| + "keydown KeyW\n" |
| + "keyup ControlLeft\n" |
| + "keyup ShiftLeft\n" |
| + "keydown ControlLeft\n" |
| + "keydown KeyT\n" |
| + "keyup ControlLeft\n" |
| + "keydown ControlLeft\n" |
| + "keydown KeyN\n" |
| + "keyup ControlLeft\n" |
| + "keydown ShiftLeft\n" |
| + "keydown ControlLeft\n" |
| + "keydown KeyN\n" |
| + "keyup ControlLeft\n" |
| + "keyup ShiftLeft\n" |
| + "keydown ShiftLeft\n" |
| + "keydown ControlLeft\n" |
| + "keydown KeyT\n" |
| + "keyup ControlLeft\n" |
| + "keyup ShiftLeft\n" |
| + "keydown ControlLeft\n" |
| + "keydown Tab\n" |
| + "keyup ControlLeft\n" |
| + "keydown ShiftLeft\n" |
| + "keydown ControlLeft\n" |
| + "keydown Tab\n" |
| + "keyup ControlLeft\n" |
| + "keyup ShiftLeft\n" |
| + "keydown KeyX\n" |
| + "keyup KeyX"); |
| +#elif defined(OS_CHROMEOS) |
| + ASSERT_EQ(result, |
| + "keydown KeyS\n" |
| + "keyup KeyS\n" |
| + "keydown ControlLeft\n" |
| + "keydown KeyW\n" |
| + "keyup KeyW\n" |
| + "keyup ControlLeft\n" |
| + "keydown ControlLeft\n" |
| + "keydown ShiftLeft\n" |
| + "keydown KeyW\n" |
| + "keyup KeyW\n" |
| + "keyup ShiftLeft\n" |
| + "keyup ControlLeft\n" |
| + "keydown ControlLeft\n" |
| + "keydown Tab\n" |
| + "keyup Tab\n" |
| + "keyup ControlLeft\n" |
| + "keydown ControlLeft\n" |
| + "keydown ShiftLeft\n" |
| + "keydown Tab\n" |
| + "keyup Tab\n" |
| + "keyup ShiftLeft\n" |
| + "keyup ControlLeft\n" |
| + "keydown KeyX\n" |
| + "keyup KeyX"); |
| +#else |
| + ASSERT_EQ(result, |
| + "keydown KeyS\n" |
| + "keyup KeyS\n" |
| + "keydown ControlLeft\n" |
| + "keydown KeyW\n" |
| + "keyup KeyW\n" |
| + "keyup ControlLeft\n" |
| + "keydown ControlLeft\n" |
| + "keydown ShiftLeft\n" |
| + "keydown KeyW\n" |
| + "keyup KeyW\n" |
| + "keyup ShiftLeft\n" |
| + "keyup ControlLeft\n" |
| + "keydown ControlLeft\n" |
| + "keydown KeyT\n" |
| + "keyup KeyT\n" |
| + "keyup ControlLeft\n" |
| + "keydown ControlLeft\n" |
| + "keydown KeyN\n" |
| + "keyup KeyN\n" |
| + "keyup ControlLeft\n" |
| + "keydown ControlLeft\n" |
| + "keydown ShiftLeft\n" |
| + "keydown KeyN\n" |
| + "keyup KeyN\n" |
| + "keyup ShiftLeft\n" |
| + "keyup ControlLeft\n" |
| + "keydown ControlLeft\n" |
| + "keydown ShiftLeft\n" |
| + "keydown KeyT\n" |
| + "keyup KeyT\n" |
| + "keyup ShiftLeft\n" |
| + "keyup ControlLeft\n" |
| + "keydown ControlLeft\n" |
| + "keydown Tab\n" |
| + "keyup Tab\n" |
| + "keyup ControlLeft\n" |
| + "keydown ControlLeft\n" |
| + "keydown ShiftLeft\n" |
| + "keydown Tab\n" |
| + "keyup Tab\n" |
| + "keyup ShiftLeft\n" |
| + "keyup ControlLeft\n" |
| + "keydown KeyX\n" |
| + "keyup KeyX"); |
| +#endif |
| +} |
| + |
| +IN_PROC_BROWSER_TEST_F( |
| + BrowserCommandControllerInteractiveTest, |
| + KeyEventsShouldBeConsumedByWebPageInJsFullscreenExceptForF11) { |
| + ASSERT_EQ(browser()->tab_strip_model()->count(), 1); |
| + StartTestPage(); |
| + |
| + SendJsFullscreenShortcutAndWait(); |
| + // Close tab. |
| + SendShortcut(ui::VKEY_W); |
| + // Close window. |
| + SendShiftShortcut(ui::VKEY_W); |
| + // TODO(zijiehe): ChromeOS has special shortcuts for the following four |
| + // commands, which should respect |
| + // BrowserCommandController::IsReservedCommandOrKey(). |
| + // see http://crbug.com/737307. |
| +#if !defined(OS_CHROMEOS) |
| + // New tab. |
| + SendShortcut(ui::VKEY_T); |
| + // New window. |
| + SendShortcut(ui::VKEY_N); |
| + // New incognito window. |
| + SendShiftShortcut(ui::VKEY_N); |
| + // Restore tab. |
| + SendShiftShortcut(ui::VKEY_T); |
| +#endif |
| + // Next tab. |
| + SendShortcut(ui::VKEY_TAB); |
| + // Previous tab. |
| + SendShiftShortcut(ui::VKEY_TAB); |
| + SendFullscreenShortcutAndWait(); |
| + |
| + std::string result = FinishTestAndGetResult(); |
| + // TODO(zijiehe): Investigate why inconsistent key event sequence has been |
| + // generated on Mac OSX. |
| +#if defined(OS_MACOSX) |
| + ASSERT_EQ(result, |
| + "keydown KeyS\n" |
| + "keyup KeyS\n" |
| + "keydown ControlLeft\n" |
| + "keydown KeyW\n" |
| + "keyup ControlLeft\n" |
| + "keydown ShiftLeft\n" |
| + "keydown ControlLeft\n" |
| + "keydown KeyW\n" |
| + "keyup ControlLeft\n" |
| + "keyup ShiftLeft\n" |
| + "keydown ControlLeft\n" |
| + "keydown KeyT\n" |
| + "keyup ControlLeft\n" |
| + "keydown ControlLeft\n" |
| + "keydown KeyN\n" |
| + "keyup ControlLeft\n" |
| + "keydown ShiftLeft\n" |
| + "keydown ControlLeft\n" |
| + "keydown KeyN\n" |
| + "keyup ControlLeft\n" |
| + "keyup ShiftLeft\n" |
| + "keydown ShiftLeft\n" |
| + "keydown ControlLeft\n" |
| + "keydown KeyT\n" |
| + "keyup ControlLeft\n" |
| + "keyup ShiftLeft\n" |
| + "keydown ControlLeft\n" |
| + "keydown Tab\n" |
| + "keyup ControlLeft\n" |
| + "keydown ShiftLeft\n" |
| + "keydown ControlLeft\n" |
| + "keydown Tab\n" |
| + "keyup ControlLeft\n" |
| + "keyup ShiftLeft\n" |
| + "keydown KeyX\n" |
| + "keyup KeyX"); |
| +#elif defined(OS_CHROMEOS) |
| + ASSERT_EQ(result, |
| + "keydown KeyS\n" |
| + "keyup KeyS\n" |
| + "keydown ControlLeft\n" |
| + "keydown KeyW\n" |
| + "keyup KeyW\n" |
| + "keyup ControlLeft\n" |
| + "keydown ControlLeft\n" |
| + "keydown ShiftLeft\n" |
| + "keydown KeyW\n" |
| + "keyup KeyW\n" |
| + "keyup ShiftLeft\n" |
| + "keyup ControlLeft\n" |
| + "keydown ControlLeft\n" |
| + "keydown Tab\n" |
| + "keyup Tab\n" |
| + "keyup ControlLeft\n" |
| + "keydown ControlLeft\n" |
| + "keydown ShiftLeft\n" |
| + "keydown Tab\n" |
| + "keyup Tab\n" |
| + "keyup ShiftLeft\n" |
| + "keyup ControlLeft\n" |
| + "keydown KeyX\n" |
| + "keyup KeyX"); |
| +#else |
| + ASSERT_EQ(result, |
| + "keydown KeyS\n" |
| + "keyup KeyS\n" |
| + "keydown ControlLeft\n" |
| + "keydown KeyW\n" |
| + "keyup KeyW\n" |
| + "keyup ControlLeft\n" |
| + "keydown ControlLeft\n" |
| + "keydown ShiftLeft\n" |
| + "keydown KeyW\n" |
| + "keyup KeyW\n" |
| + "keyup ShiftLeft\n" |
| + "keyup ControlLeft\n" |
| + "keydown ControlLeft\n" |
| + "keydown KeyT\n" |
| + "keyup KeyT\n" |
| + "keyup ControlLeft\n" |
| + "keydown ControlLeft\n" |
| + "keydown KeyN\n" |
| + "keyup KeyN\n" |
| + "keyup ControlLeft\n" |
| + "keydown ControlLeft\n" |
| + "keydown ShiftLeft\n" |
| + "keydown KeyN\n" |
| + "keyup KeyN\n" |
| + "keyup ShiftLeft\n" |
| + "keyup ControlLeft\n" |
| + "keydown ControlLeft\n" |
| + "keydown ShiftLeft\n" |
| + "keydown KeyT\n" |
| + "keyup KeyT\n" |
| + "keyup ShiftLeft\n" |
| + "keyup ControlLeft\n" |
| + "keydown ControlLeft\n" |
| + "keydown Tab\n" |
| + "keyup Tab\n" |
| + "keyup ControlLeft\n" |
| + "keydown ControlLeft\n" |
| + "keydown ShiftLeft\n" |
| + "keydown Tab\n" |
| + "keyup Tab\n" |
| + "keyup ShiftLeft\n" |
| + "keyup ControlLeft\n" |
| + "keydown KeyX\n" |
| + "keyup KeyX"); |
| +#endif |
| +} |