Chromium Code Reviews| 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,7 @@ |
| // found in the LICENSE file. |
| #include "app/keyboard_codes.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 +19,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 +50,43 @@ |
| << " 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::string caption; |
| + std::string filename; |
| + int len = ::GetWindowTextLength(window) + 1; |
| + ::GetWindowTextA(window, WriteInto(&caption, len), len); |
|
M-A Ruel
2010/12/01 14:22:35
? Why not GetWindowText with a std::wstring?
|
| + bool chrome_window_in_foreground = (caption == "about:blank - Google Chrome"); |
| + if (!chrome_window_in_foreground) { |
| + DWORD process_id; |
| + int thread_id = ::GetWindowThreadProcessId(window, &process_id); |
| + |
| + HANDLE process = ::OpenProcess(PROCESS_QUERY_LIMITED_INFORMATION, |
|
M-A Ruel
2010/12/01 14:22:35
OpenProcessHandle() in base/process_util.h
|
| + false, |
| + process_id); |
| + if (process > 0) { |
| + len = MAX_PATH; |
| + if (!GetProcessImageFileNameA(process, WriteInto(&filename, len), len)) { |
|
M-A Ruel
2010/12/01 14:22:35
Why ansi?
Finnur
2010/12/01 14:40:35
No good reason. Changed.
On 2010/12/01 14:22:35,
|
| + int error = GetLastError(); |
| + filename = std::string("Unable to read filename (error ") + |
| + base::IntToString(error) + ")"; |
| + } |
| + CloseHandle(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 +176,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); |