diff options
author | robertshield@chromium.org <robertshield@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2013-04-24 20:12:20 +0000 |
---|---|---|
committer | robertshield@chromium.org <robertshield@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2013-04-24 20:12:20 +0000 |
commit | 379a2379cb85e3882775c1d2be87c8c291166194 (patch) | |
tree | fd2494ac7d0c20a30af130d4d125e0ef14f210c9 | |
parent | 1cece685504e68d3cd3bba0b2037962e3daba673 (diff) | |
download | chromium_src-379a2379cb85e3882775c1d2be87c8c291166194.zip chromium_src-379a2379cb85e3882775c1d2be87c8c291166194.tar.gz chromium_src-379a2379cb85e3882775c1d2be87c8c291166194.tar.bz2 |
Re-enable disabled Chrome Frame accelerator tests.
Change mechanism used to send input keys to batch all key-down events into a single SendInput call.
Add SendInput calls with key-up parameters to attempt to reset the modifier keys to an unpressed state on test start/end.
Make CF UI tests that look for a specific window work with Aura Chrome Frame.
BUG=232037,124244
TEST=chrome_frame_tests.exe
Review URL: https://chromiumcodereview.appspot.com/14093015
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@196213 0039d316-1c4b-4281-b951-d872f2087c98
-rw-r--r-- | chrome_frame/test/ie_event_sink.cc | 7 | ||||
-rw-r--r-- | chrome_frame/test/simulate_input.cc | 62 | ||||
-rw-r--r-- | chrome_frame/test/simulate_input.h | 24 | ||||
-rw-r--r-- | chrome_frame/test/ui_test.cc | 32 |
4 files changed, 76 insertions, 49 deletions
diff --git a/chrome_frame/test/ie_event_sink.cc b/chrome_frame/test/ie_event_sink.cc index 0e1f8d0..9bc5f53 100644 --- a/chrome_frame/test/ie_event_sink.cc +++ b/chrome_frame/test/ie_event_sink.cc @@ -389,7 +389,12 @@ HWND IEEventSink::GetRendererWindow() { first_child = ::GetWindow(first_child, GW_CHILD)) { child_window = first_child; GetClassName(child_window, class_name, arraysize(class_name)); - if (!_wcsicmp(class_name, L"Chrome_RenderWidgetHostHWND")) { +#if defined(USE_AURA) + static const wchar_t kWndClassPrefix[] = L"Chrome_WidgetWin_"; +#else + static const wchar_t kWndClassPrefix[] = L"Chrome_RenderWidgetHostHWND"; +#endif + if (!_wcsnicmp(class_name, kWndClassPrefix, wcslen(kWndClassPrefix))) { renderer_window = child_window; break; } diff --git a/chrome_frame/test/simulate_input.cc b/chrome_frame/test/simulate_input.cc index 2ee8cd7..6317d14 100644 --- a/chrome_frame/test/simulate_input.cc +++ b/chrome_frame/test/simulate_input.cc @@ -33,7 +33,7 @@ END_MSG_MAP() MSG msg = {0}; PeekMessage(&msg, NULL, 0, 0, PM_NOREMOVE); - SendMnemonic(VK_F22, NONE, false, false); + SendMnemonic(VK_F22, NONE, false, false, KEY_DOWN); // There are scenarios where the WM_HOTKEY is not dispatched by the // the corresponding foreground thread. To prevent us from indefinitely // waiting for the hotkey, we set a timer and exit the loop. @@ -111,7 +111,7 @@ bool EnsureProcessInForeground(base::ProcessId process_id) { return ret; } -void SendScanCode(short scan_code, Modifier modifiers) { +void SendScanCode(short scan_code, uint32 modifiers) { DCHECK(-1 != scan_code); // High order byte in |scan_code| is SHIFT/CTRL/ALT key state. @@ -119,22 +119,26 @@ void SendScanCode(short scan_code, Modifier modifiers) { DCHECK(modifiers <= ALT); // Low order byte in |scan_code| is the actual scan code. - SendMnemonic(LOBYTE(scan_code), modifiers, false, true); + SendMnemonic(LOBYTE(scan_code), modifiers, false, true, KEY_DOWN); } -void SendCharA(char c, Modifier modifiers) { +void SendCharA(char c, uint32 modifiers) { SendScanCode(VkKeyScanA(c), modifiers); } -void SendCharW(wchar_t c, Modifier modifiers) { +void SendCharW(wchar_t c, uint32 modifiers) { SendScanCode(VkKeyScanW(c), modifiers); } // Sends a keystroke to the currently active application with optional // modifiers set. -void SendMnemonic(WORD mnemonic_char, Modifier modifiers, bool extended, - bool unicode) { - INPUT keys[4] = {0}; // Keyboard events +void SendMnemonic(WORD mnemonic_char, + uint32 modifiers, + bool extended, + bool unicode, + KeyMode key_mode) { + const int kMaxInputs = 4; + INPUT keys[kMaxInputs] = {0}; // Keyboard events int key_count = 0; // Number of generated events if (modifiers & SHIFT) { @@ -158,34 +162,28 @@ void SendMnemonic(WORD mnemonic_char, Modifier modifiers, bool extended, key_count++; } - keys[key_count].type = INPUT_KEYBOARD; - keys[key_count].ki.wVk = mnemonic_char; - keys[key_count].ki.wScan = MapVirtualKey(mnemonic_char, 0); + if (mnemonic_char) { + keys[key_count].type = INPUT_KEYBOARD; + keys[key_count].ki.wVk = mnemonic_char; + keys[key_count].ki.wScan = MapVirtualKey(mnemonic_char, 0); - if (extended) - keys[key_count].ki.dwFlags |= KEYEVENTF_EXTENDEDKEY; - if (unicode) - keys[key_count].ki.dwFlags |= KEYEVENTF_UNICODE; - key_count++; + if (extended) + keys[key_count].ki.dwFlags |= KEYEVENTF_EXTENDEDKEY; + if (unicode) + keys[key_count].ki.dwFlags |= KEYEVENTF_UNICODE; + key_count++; + } - bool should_sleep = key_count > 1; + DCHECK_LE(key_count, kMaxInputs); - // Send key downs - for (int i = 0; i < key_count; i++) { - SendInput(1, &keys[ i ], sizeof(keys[0])); - keys[i].ki.dwFlags |= KEYEVENTF_KEYUP; - if (should_sleep) { - Sleep(10); + // Add the key up bit if needed. + if (key_mode == KEY_UP) { + for (int i = 0; i < key_count; i++) { + keys[i].ki.dwFlags |= KEYEVENTF_KEYUP; } } - // Now send key ups in reverse order - for (int i = key_count; i; i--) { - SendInput(1, &keys[ i - 1 ], sizeof(keys[0])); - if (should_sleep) { - Sleep(10); - } - } + SendInput(key_count, &keys[0], sizeof(keys[0])); } void SetKeyboardFocusToWindow(HWND window) { @@ -240,8 +238,8 @@ void SendMouseClick(HWND window, int x, int y, MouseButton button) { SendMouseClick(cursor_position.x, cursor_position.y, button); } -void SendExtendedKey(WORD key, Modifier modifiers) { - SendMnemonic(key, modifiers, true, false); +void SendExtendedKey(WORD key, uint32 modifiers) { + SendMnemonic(key, modifiers, true, false, KEY_UP); } void SendStringW(const std::wstring& s) { diff --git a/chrome_frame/test/simulate_input.h b/chrome_frame/test/simulate_input.h index 112848b..97f7e0e 100644 --- a/chrome_frame/test/simulate_input.h +++ b/chrome_frame/test/simulate_input.h @@ -20,6 +20,11 @@ enum Modifier { ALT = 4 }; +enum KeyMode { + KEY_DOWN, + KEY_UP, +}; + // Bring a window into foreground to receive user input. // Note that this may not work on bool ForceSetForegroundWindow(HWND window); @@ -33,10 +38,13 @@ bool EnsureProcessInForeground(base::ProcessId process_id); // window. void SetKeyboardFocusToWindow(HWND window); -// Sends a keystroke to the currently active application with optional -// modifiers set. -void SendMnemonic(WORD mnemonic_char, Modifier modifiers, bool extended, - bool unicode); +// Sends a keystroke to the currently active application with optional modifiers +// set. Sends one "key (down|up)" input event for each modifier set, plus one +// for |mnemonic_char| depending on the value of |key_mode|. This can be useful +// as it has been observed that tests will exit after receiving the "key down" +// events leaving the keyboard in an inconsistent state. +void SendMnemonic(WORD mnemonic_char, uint32 modifiers, bool extended, + bool unicode, KeyMode key_mode); // Sends a mouse click to the desktop. enum MouseButton { LEFT, RIGHT, MIDDLE, X }; @@ -46,13 +54,13 @@ void SendMouseClick(int x, int y, MouseButton button); void SendMouseClick(HWND window, int x, int y, MouseButton button); // Translates a single char to a virtual key. -void SendScanCode(short scan_code, Modifier modifiers); -void SendCharA(char c, Modifier modifiers); -void SendCharW(wchar_t c, Modifier modifiers); +void SendScanCode(short scan_code, uint32 modifiers); +void SendCharA(char c, uint32 modifiers); +void SendCharW(wchar_t c, uint32 modifiers); // Sends extended keystroke to the currently active application with optional // modifiers set. -void SendExtendedKey(WORD key, Modifier modifiers); +void SendExtendedKey(WORD key, uint32 modifiers); // Iterates through all the characters in the string and simulates // keyboard input. The input goes to the currently active application. diff --git a/chrome_frame/test/ui_test.cc b/chrome_frame/test/ui_test.cc index 275f34c..cf59b18 100644 --- a/chrome_frame/test/ui_test.cc +++ b/chrome_frame/test/ui_test.cc @@ -16,6 +16,7 @@ #include "chrome_frame/test/chrome_frame_ui_test_utils.h" #include "chrome_frame/test/mock_ie_event_sink_actions.h" #include "chrome_frame/test/mock_ie_event_sink_test.h" +#include "chrome_frame/test/simulate_input.h" #include "testing/gmock_mutant.h" @@ -34,11 +35,30 @@ class FullTabUITest : public MockIEEventSinkTest, FullTabUITest() {} virtual void SetUp() { + ResetKeyState(); + // These are UI-related tests, so we do not care about the exact requests // and navigations that occur. server_mock_.ExpectAndServeAnyRequests(GetParam()); ie_mock_.ExpectAnyNavigations(); } + + virtual void TearDown() { + ResetKeyState(); + } + + void ResetKeyState() { + // Call this to reset the state of any current keyboard modifiers, as it has + // been observed that these tests can leave the desktop in an invalid state + // (e.g. thinking that the Ctrl key is held down). Send F23 as that is + // particularly unlikely to be used by any real application. + simulate_input::SendMnemonic( + VK_F23, + simulate_input::CONTROL | simulate_input::SHIFT | simulate_input::ALT, + false, + false, + simulate_input::KEY_UP); + } }; // Instantiate each test case for the IE case and for CF meta tag case. @@ -114,8 +134,7 @@ TEST_P(FullTabUITest, DISABLED_KeyboardBackForward) { } // Tests new window behavior with ctrl+N. -// Flaky due to DelaySendChar; see http://crbug.com/124244. -TEST_P(FullTabUITest, DISABLED_CtrlN) { +TEST_P(FullTabUITest, CtrlN) { if (IsWorkstationLocked()) { LOG(ERROR) << "This test cannot be run in a locked workstation."; return; @@ -156,8 +175,7 @@ TEST_P(FullTabUITest, DISABLED_CtrlN) { } // Test that Ctrl+F opens the Find dialog. -// Flaky due to DelaySendChar; see http://crbug.com/124244. -TEST_P(FullTabUITest, DISABLED_CtrlF) { +TEST_P(FullTabUITest, CtrlF) { if (IsWorkstationLocked()) { LOG(ERROR) << "This test cannot be run in a locked workstation."; return; @@ -190,8 +208,7 @@ TEST_P(FullTabUITest, DISABLED_CtrlF) { } // Test that ctrl+r does cause a refresh. -// Flaky due to DelaySendChar; see http://crbug.com/124244. -TEST_P(FullTabUITest, DISABLED_CtrlR) { +TEST_P(FullTabUITest, CtrlR) { if (IsWorkstationLocked()) { LOG(ERROR) << "This test cannot be run in a locked workstation."; return; @@ -219,8 +236,7 @@ TEST_P(FullTabUITest, DISABLED_CtrlR) { } // Test window close with ctrl+w. -// Flaky due to DelaySendChar; see http://crbug.com/124244. -TEST_P(FullTabUITest, DISABLED_CtrlW) { +TEST_P(FullTabUITest, CtrlW) { if (IsWorkstationLocked()) { LOG(ERROR) << "This test cannot be run in a locked workstation."; return; |