diff options
author | ananta@chromium.org <ananta@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-11-13 17:46:40 +0000 |
---|---|---|
committer | ananta@chromium.org <ananta@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-11-13 17:46:40 +0000 |
commit | 24a20e0d58bfc9c176930f90b4ea3245fa742815 (patch) | |
tree | 747dc184de34af34e394d80b7b04bb12531aba28 /chrome_frame/test/chrome_frame_test_utils.cc | |
parent | dd807ba64f2a3c276757010fcb488f5dc3b5722e (diff) | |
download | chromium_src-24a20e0d58bfc9c176930f90b4ea3245fa742815.zip chromium_src-24a20e0d58bfc9c176930f90b4ea3245fa742815.tar.gz chromium_src-24a20e0d58bfc9c176930f90b4ea3245fa742815.tar.bz2 |
Added a regression test which validates that keystrokes are received correctly in ChromeFrame. We specifically
test for uppercase characters generated in combination with the Shift key.
Added a helper function to explicitly give focus to a passed in HWND. This is done by sending the mouse move/mouse
down and mouse up events to the window. We also use this in the AboutChromeFrame test, which was flaky at times.
Bug=27173,26549
Review URL: http://codereview.chromium.org/389029
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@31915 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome_frame/test/chrome_frame_test_utils.cc')
-rw-r--r-- | chrome_frame/test/chrome_frame_test_utils.cc | 60 |
1 files changed, 60 insertions, 0 deletions
diff --git a/chrome_frame/test/chrome_frame_test_utils.cc b/chrome_frame/test/chrome_frame_test_utils.cc index e9786fc..4912901 100644 --- a/chrome_frame/test/chrome_frame_test_utils.cc +++ b/chrome_frame/test/chrome_frame_test_utils.cc @@ -420,6 +420,8 @@ void ShowChromeFrameContextMenuTask() { HWND renderer_window = GetChromeRendererWindow(); EXPECT_TRUE(IsWindow(renderer_window)); + SetKeyboardFocusToWindow(renderer_window, 100, 100); + // Bring up the context menu in the Chrome renderer window. PostMessage(renderer_window, WM_RBUTTONDOWN, MK_RBUTTON, MAKELPARAM(50, 50)); PostMessage(renderer_window, WM_RBUTTONUP, MK_RBUTTON, MAKELPARAM(50, 50)); @@ -439,6 +441,64 @@ void ShowChromeFrameContextMenu() { kContextMenuDelay); } +void SetKeyboardFocusToWindow(HWND window, int x, int y) { + if (!IsTopLevelWindow(window)) { + window = GetAncestor(window, GA_ROOT); + } + ForceSetForegroundWindow(window); + + POINT cursor_position = {130, 130}; + ClientToScreen(window, &cursor_position); + + double screen_width = ::GetSystemMetrics( SM_CXSCREEN ) - 1; + double screen_height = ::GetSystemMetrics( SM_CYSCREEN ) - 1; + double location_x = cursor_position.x * (65535.0f / screen_width); + double location_y = cursor_position.y * (65535.0f / screen_height); + + INPUT input_info = {0}; + input_info.type = INPUT_MOUSE; + input_info.mi.dwFlags = MOUSEEVENTF_MOVE | MOUSEEVENTF_ABSOLUTE; + input_info.mi.dx = static_cast<long>(location_x); + input_info.mi.dy = static_cast<long>(location_y); + ::SendInput(1, &input_info, sizeof(INPUT)); + + Sleep(10); + + input_info.mi.dwFlags = MOUSEEVENTF_LEFTDOWN | MOUSEEVENTF_ABSOLUTE; + ::SendInput(1, &input_info, sizeof(INPUT)); + + Sleep(10); + + input_info.mi.dwFlags = MOUSEEVENTF_LEFTUP | MOUSEEVENTF_ABSOLUTE; + ::SendInput(1, &input_info, sizeof(INPUT)); +} + +void SendInputToWindow(HWND window, const std::string& input_string) { + SetKeyboardFocusToWindow(window, 100, 100); + + for (size_t index = 0; index < input_string.length(); index++) { + bool is_upper_case = isupper(input_string[index]); + if (is_upper_case) { + INPUT input = { INPUT_KEYBOARD }; + input.ki.wVk = VK_SHIFT; + input.ki.dwFlags = 0; + SendInput(1, &input, sizeof(input)); + Sleep(200); + } + + // The WM_KEYDOWN and WM_KEYUP messages for characters always contain + // the uppercase character codes. + SendVirtualKey(toupper(input_string[index]), false); + + if (is_upper_case) { + INPUT input = { INPUT_KEYBOARD }; + input.ki.wVk = VK_SHIFT; + input.ki.dwFlags = KEYEVENTF_KEYUP; + SendInput(1, &input, sizeof(input)); + } + } +} + void SelectAboutChromeFrame() { // Send a key up message to enable the About chrome frame option to be // selected followed by a return to select it. |