Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(362)

Unified Diff: chrome/browser/ui/views/find_bar_host_interactive_uitest.cc

Issue 5463001: Figure out error in test PrepopulateRespectBlank.... (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: '' Created 10 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « chrome/browser/automation/ui_controls_win.cc ('k') | chrome/test/ui_test_utils.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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);
« no previous file with comments | « chrome/browser/automation/ui_controls_win.cc ('k') | chrome/test/ui_test_utils.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698