Index: chrome/browser/ui/views/find_bar_host_interactive_uitest.cc |
=================================================================== |
--- chrome/browser/ui/views/find_bar_host_interactive_uitest.cc (revision 67835) |
+++ chrome/browser/ui/views/find_bar_host_interactive_uitest.cc (working copy) |
@@ -3,6 +3,8 @@ |
// found in the LICENSE file. |
#include "app/keyboard_codes.h" |
+#include "base/process_util.h" |
+#include "base/string_number_conversions.h" |
#include "base/string_util.h" |
#include "base/utf_string_conversions.h" |
#include "chrome/browser/find_bar_controller.h" |
@@ -18,6 +20,11 @@ |
#include "views/focus/focus_manager.h" |
#include "views/view.h" |
+#if defined(OS_WIN) |
+#include <windows.h> |
+#include <Psapi.h> |
+#endif |
+ |
namespace { |
// The delay waited after sending an OS simulated event. |
@@ -44,6 +51,44 @@ |
<< " ms" << std::flush; |
} |
+// Test to make sure Chrome is in the foreground as we start testing. This is |
+// required for tests that synthesize input to the Chrome window. |
+bool ChromeInForeground() { |
+#if defined(OS_WIN) |
+ HWND window = ::GetForegroundWindow(); |
+ std::wstring caption; |
+ std::wstring filename; |
+ int len = ::GetWindowTextLength(window) + 1; |
+ ::GetWindowText(window, WriteInto(&caption, len), len); |
+ bool chrome_window_in_foreground = |
+ (caption == L"about:blank - Google Chrome"); |
+ if (!chrome_window_in_foreground) { |
+ DWORD process_id; |
+ int thread_id = ::GetWindowThreadProcessId(window, &process_id); |
+ |
+ base::ProcessHandle process; |
+ if (base::OpenProcessHandleWithAccess(process_id, |
+ PROCESS_QUERY_LIMITED_INFORMATION, |
+ &process)) { |
+ len = MAX_PATH; |
+ if (!GetProcessImageFileName(process, WriteInto(&filename, len), len)) { |
+ int error = GetLastError(); |
+ filename = std::wstring(L"Unable to read filename (error ") + |
M-A Ruel
2010/12/01 14:51:12
The 'std::wstring(' part is not strictly necessary
|
+ base::IntToString16(error) + L")"; |
+ } |
+ base::CloseProcessHandle(process); |
+ } |
+ } |
+ EXPECT_TRUE(chrome_window_in_foreground) |
+ << "Chrome must be in the foreground when running interactive tests\n" |
+ << "Process in foreground: " << filename.c_str(); |
+ return chrome_window_in_foreground; |
+#else |
+ // Windows only at the moment. |
+ return true; |
+#endif |
+} |
+ |
} // namespace |
IN_PROC_BROWSER_TEST_F(FindInPageTest, CrashEscHandlers) { |
@@ -133,12 +178,15 @@ |
// FindInPage on Mac doesn't use prepopulated values. Search there is global. |
return; |
#endif |
- |
base::TimeTicks start_time = base::TimeTicks::Now(); |
Checkpoint("Starting test server", start_time); |
ASSERT_TRUE(test_server()->Start()); |
+ // Make sure Chrome is in the foreground, otherwise sending input |
+ // won't do anything and the test will hang. |
+ ASSERT_TRUE(ChromeInForeground()); |
+ |
// First we navigate to any page. |
Checkpoint("Navigating", start_time); |
GURL url = test_server()->GetURL(kSimplePage); |