summaryrefslogtreecommitdiffstats
path: root/webkit/tools
diff options
context:
space:
mode:
authorscottbyer@chromium.org <scottbyer@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2012-02-27 19:30:06 +0000
committerscottbyer@chromium.org <scottbyer@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2012-02-27 19:30:06 +0000
commit39e556928470ab6b8fc25b8a04f68a66941ffcf2 (patch)
treeb07eacb389ae2afbf21eb81b1a606df99a75104f /webkit/tools
parenteb25b03c4711eb37c0d4119501bd10caf7d9686d (diff)
downloadchromium_src-39e556928470ab6b8fc25b8a04f68a66941ffcf2.zip
chromium_src-39e556928470ab6b8fc25b8a04f68a66941ffcf2.tar.gz
chromium_src-39e556928470ab6b8fc25b8a04f68a66941ffcf2.tar.bz2
Revert 123771 - Refactor out foreground_help to fix BringBrowserWindowToFront on Windows
Refactor out foreground_helper so that regular Chromium tests can use it. Use it in ShowAndFocusNativeWindow to make sure the browser window is in front, both when tests ask and when trying to send keyboard events. This should reduce some flakiness of related tests, and certainly makes it easier to debug those tests. The API for SendKeyPress events looks like it changed long ago to add a target window, only the Windows code simply dropped that on the floor. By returning false when the event wouldn't go to the right place, it allows for ui_test_utils::SendKeyPressSync to bring the browser window to the front and try again. BUG=106489 TEST=Run browser_tests or interactive_ui_tests and bring another window to the front. For the tests in question, the browser should now pop in front when it needs to for the test to complete properly. Review URL: http://codereview.chromium.org/9431050 TBR=scottbyer@chromium.org Review URL: https://chromiumcodereview.appspot.com/9474010 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@123781 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'webkit/tools')
-rw-r--r--webkit/tools/test_shell/foreground_helper.h93
-rw-r--r--webkit/tools/test_shell/test_shell.gypi1
-rw-r--r--webkit/tools/test_shell/test_shell_platform_delegate_win.cc6
3 files changed, 97 insertions, 3 deletions
diff --git a/webkit/tools/test_shell/foreground_helper.h b/webkit/tools/test_shell/foreground_helper.h
new file mode 100644
index 0000000..9466183
--- /dev/null
+++ b/webkit/tools/test_shell/foreground_helper.h
@@ -0,0 +1,93 @@
+// Copyright (c) 2009 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.
+
+#ifndef WEBKIT_TOOLS_TEST_SHELL_FOREGROUND_HELPER_H_
+#define WEBKIT_TOOLS_TEST_SHELL_FOREGROUND_HELPER_H_
+
+#include "base/logging.h"
+#include "ui/base/win/window_impl.h"
+
+// Helper class for moving a window to the foreground.
+// Windows XP and later will not allow a window which is in the background to
+// move to the foreground, unless requested by the current window in the
+// foreground. For automated testing, we really want some of our windows
+// to be capable of moving to the foreground.
+//
+// This is probably leveraging a windows bug.
+class ForegroundHelper : public ui::WindowImpl {
+ public:
+ BEGIN_MSG_MAP_EX(ForegroundHelper)
+ MESSAGE_HANDLER(WM_HOTKEY, OnHotKey)
+ END_MSG_MAP()
+
+ // Brings a window into the foreground.
+ // Can be called from any window, even if the caller is not the
+ // foreground window.
+ static HRESULT SetForeground(HWND window) {
+ DCHECK(::IsWindow(window));
+ ForegroundHelper foreground_helper;
+ CHECK(foreground_helper.ForegroundHotKey(window) == S_OK);
+ return S_OK;
+ }
+
+ private:
+ HRESULT ForegroundHotKey(HWND window) {
+ // This implementation registers a hot key (F22) and then
+ // triggers the hot key. When receiving the hot key, we'll
+ // be in the foreground and allowed to move the target window
+ // into the foreground too.
+
+ set_window_style(WS_POPUP);
+ Init(NULL, gfx::Rect());
+
+ static const int hotkey_id = 0x0000baba;
+
+ // Store the target window into our USERDATA for use in our
+ // HotKey handler.
+ SetWindowLongPtr(hwnd(), GWLP_USERDATA,
+ reinterpret_cast<ULONG_PTR>(window));
+ RegisterHotKey(hwnd(), hotkey_id, 0, VK_F22);
+
+ // If the calling thread is not yet a UI thread, call PeekMessage
+ // to ensure creation of its message queue.
+ MSG msg = {0};
+ PeekMessage(&msg, NULL, 0, 0, PM_NOREMOVE);
+
+ // Send the Hotkey.
+ INPUT hotkey = {0};
+ hotkey.type = INPUT_KEYBOARD;
+ hotkey.ki.wVk = VK_F22;
+ if (1 != SendInput(1, &hotkey, sizeof(hotkey)))
+ return E_FAIL;
+
+ // Loop until we get the key.
+ // TODO: It may be possible to get stuck here if the
+ // message gets lost?
+ while (GetMessage(&msg, NULL, 0, 0)) {
+ TranslateMessage(&msg);
+ DispatchMessage(&msg);
+
+ if (WM_HOTKEY == msg.message)
+ break;
+ }
+
+ UnregisterHotKey(hwnd(), hotkey_id);
+ DestroyWindow(hwnd());
+
+ return S_OK;
+ }
+
+ // Handle the registered Hotkey being pressed.
+ LRESULT OnHotKey(UINT message,
+ WPARAM wparam,
+ LPARAM lparam,
+ BOOL& handled) {
+ HWND window = reinterpret_cast<HWND>(GetWindowLongPtr(hwnd(),
+ GWLP_USERDATA));
+ SetForegroundWindow(window);
+ return 1;
+ }
+};
+
+#endif // WEBKIT_TOOLS_TEST_SHELL_FOREGROUND_HELPER_H_
diff --git a/webkit/tools/test_shell/test_shell.gypi b/webkit/tools/test_shell/test_shell.gypi
index 74c2e76..6f49b9b 100644
--- a/webkit/tools/test_shell/test_shell.gypi
+++ b/webkit/tools/test_shell/test_shell.gypi
@@ -70,6 +70,7 @@
'accessibility_ui_element.h',
'drop_delegate.cc',
'drop_delegate.h',
+ 'foreground_helper.h',
'layout_test_controller.cc',
'layout_test_controller.h',
'mock_spellcheck.cc',
diff --git a/webkit/tools/test_shell/test_shell_platform_delegate_win.cc b/webkit/tools/test_shell/test_shell_platform_delegate_win.cc
index ad1c1e3..cb9c3da 100644
--- a/webkit/tools/test_shell/test_shell_platform_delegate_win.cc
+++ b/webkit/tools/test_shell/test_shell_platform_delegate_win.cc
@@ -1,4 +1,4 @@
-// Copyright (c) 2012 The Chromium Authors. All rights reserved.
+// Copyright (c) 2009 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.
@@ -10,8 +10,8 @@
#include "base/command_line.h"
#include "base/event_recorder.h"
#include "base/win/win_util.h"
-#include "ui/base/win/foreground_helper.h"
#include "ui/gfx/native_theme_win.h"
+#include "webkit/tools/test_shell/foreground_helper.h"
#include "webkit/tools/test_shell/test_shell.h"
#include "webkit/tools/test_shell/test_shell_platform_delegate.h"
@@ -150,6 +150,6 @@ void TestShellPlatformDelegate::SetWindowPositionForRecording(
// on build systems where the script invoking us is a background
// process. So for this case, make our window the topmost window
// as well.
- CHECK(ui::ForegroundHelper::SetForeground(shell->mainWnd()) == S_OK);
+ ForegroundHelper::SetForeground(shell->mainWnd());
::SetWindowPos(shell->mainWnd(), HWND_TOP, 0, 0, 600, 800, 0);
}