summaryrefslogtreecommitdiffstats
path: root/chrome_frame
diff options
context:
space:
mode:
authorananta@chromium.org <ananta@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2009-11-13 17:46:40 +0000
committerananta@chromium.org <ananta@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2009-11-13 17:46:40 +0000
commit24a20e0d58bfc9c176930f90b4ea3245fa742815 (patch)
tree747dc184de34af34e394d80b7b04bb12531aba28 /chrome_frame
parentdd807ba64f2a3c276757010fcb488f5dc3b5722e (diff)
downloadchromium_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')
-rw-r--r--chrome_frame/test/chrome_frame_test_utils.cc60
-rw-r--r--chrome_frame/test/chrome_frame_test_utils.h8
-rw-r--r--chrome_frame/test/chrome_frame_unittests.cc24
-rw-r--r--chrome_frame/test/data/keyevent.html36
4 files changed, 127 insertions, 1 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.
diff --git a/chrome_frame/test/chrome_frame_test_utils.h b/chrome_frame/test/chrome_frame_test_utils.h
index 900f532..26da481 100644
--- a/chrome_frame/test/chrome_frame_test_utils.h
+++ b/chrome_frame/test/chrome_frame_test_utils.h
@@ -69,6 +69,14 @@ void SelectAboutChromeFrame();
// Returns NULL on failure.
HWND GetChromeRendererWindow();
+// Sends the specified input to the window passed in.
+void SendInputToWindow(HWND window, const std::string& input_string);
+
+// Helper function to set keyboard focus to a window. This is achieved by
+// sending a mouse move followed by a mouse down/mouse up combination to the
+// window.
+void SetKeyboardFocusToWindow(HWND window, int x, int y);
+
} // namespace chrome_frame_test
#endif // CHROME_FRAME_CHROMETAB_UNITTESTS_CF_TEST_UTILS_H_
diff --git a/chrome_frame/test/chrome_frame_unittests.cc b/chrome_frame/test/chrome_frame_unittests.cc
index 79b8d13..66d7ab5 100644
--- a/chrome_frame/test/chrome_frame_unittests.cc
+++ b/chrome_frame/test/chrome_frame_unittests.cc
@@ -1364,6 +1364,7 @@ HRESULT WebBrowserEventSink::LaunchIEAndNavigate(
return hr;
}
+const int kChromeFrameLaunchDelay = 5;
const int kChromeFrameLongNavigationTimeoutInSeconds = 10;
// This class provides functionality to add expectations to IE full tab mode
@@ -1505,7 +1506,7 @@ const wchar_t kChromeFrameAboutVersion[] =
// with the chrome revision. The test finally checks for success by comparing
// the URL of the window being opened with cf:about:version, which indicates
// that the operation succeeded.
-TEST_F(ChromeFrameTestWithWebServer, FLAKY_FullTabModeIE_AboutChromeFrame) {
+TEST_F(ChromeFrameTestWithWebServer, FullTabModeIE_AboutChromeFrame) {
TimedMsgLoop loop;
CComObjectStackEx<MockWebBrowserEventSink> mock;
@@ -1541,3 +1542,24 @@ TEST_F(ChromeFrameTestWithWebServer, FLAKY_FullTabModeIE_AboutChromeFrame) {
chrome_frame_test::CloseAllIEWindows();
}
+const wchar_t kChromeFrameFullTabModeKeyEventUrl[] = L"files/keyevent.html";
+
+TEST_F(ChromeFrameTestWithWebServer, FullTabModeIE_ChromeFrameKeyboardTest) {
+ TimedMsgLoop loop;
+
+ ASSERT_TRUE(LaunchBrowser(IE, kChromeFrameFullTabModeKeyEventUrl));
+
+ // Allow some time for chrome to be launched.
+ loop.RunFor(kChromeFrameLaunchDelay);
+
+ HWND renderer_window = chrome_frame_test::GetChromeRendererWindow();
+ EXPECT_TRUE(IsWindow(renderer_window));
+
+ chrome_frame_test::SendInputToWindow(renderer_window, "Chrome");
+
+ loop.RunFor(kChromeFrameLongNavigationTimeoutInSeconds);
+
+ chrome_frame_test::CloseAllIEWindows();
+ ASSERT_TRUE(CheckResultFile(L"FullTab_KeyboardTest", "OK"));
+}
+
diff --git a/chrome_frame/test/data/keyevent.html b/chrome_frame/test/data/keyevent.html
new file mode 100644
index 0000000..73c5e40
--- /dev/null
+++ b/chrome_frame/test/data/keyevent.html
@@ -0,0 +1,36 @@
+<html>
+ <head>
+ <meta http-equiv="x-ua-compatible" content="chrome=1" />
+ <title>ChromeFrame keyevent test</title>
+ <script type="text/javascript"
+ src="chrome_frame_tester_helpers.js"></script>
+
+ <script type="text/javascript">
+ function ValidateUserAgent() {
+ if (isRunningInMSIE()) {
+ onFailure("FullTab_KeyboardTest", 1, "Failed");
+ }
+ }
+
+ var key_count = 0;
+ var input_string = "";
+
+ function OnKeyPress() {
+ if (key_count <= 6) {
+ input_string += String.fromCharCode(event.keyCode).toString();
+ }
+
+ if (input_string == "Chrome") {
+ onSuccess("FullTab_KeyboardTest", 1);
+ } else if (key_count >= 6) {
+ onFailure("FullTab_KeyboardTest", 1, "Invalid input string");
+ }
+ }
+ </script>
+ </head>
+
+ <body onLoad="setTimeout(ValidateUserAgent, 100);" onkeypress="OnKeyPress()">
+ ChromeFrame full tab mode keyboard test. Verifies that keypress events make
+ it correctly into ChromeFrame.
+ </body>
+</html>