diff options
author | estade@chromium.org <estade@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-04-14 23:15:47 +0000 |
---|---|---|
committer | estade@chromium.org <estade@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-04-14 23:15:47 +0000 |
commit | 3753f52d42975eaefcafca9fc0257ec24e161a9c (patch) | |
tree | c9622baf613dd1b47c304d30e1ded74fa84fce54 /chrome/test | |
parent | 9e23bb1bba29dad5305e8f8a08341aefe7275502 (diff) | |
download | chromium_src-3753f52d42975eaefcafca9fc0257ec24e161a9c.zip chromium_src-3753f52d42975eaefcafca9fc0257ec24e161a9c.tar.gz chromium_src-3753f52d42975eaefcafca9fc0257ec24e161a9c.tar.bz2 |
Implement chrome_proces_util for linux and enable download ui test.
To get the PID from the socket, we use lsof (fuser doesn't work with unix sockets apparently).
The download shelf, save page, and browser ui tests now pass.
Review URL: http://codereview.chromium.org/66071
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@13716 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/test')
-rw-r--r-- | chrome/test/automation/automation_messages_internal.h | 5 | ||||
-rw-r--r-- | chrome/test/automation/window_proxy.cc | 13 | ||||
-rw-r--r-- | chrome/test/automation/window_proxy.h | 4 | ||||
-rw-r--r-- | chrome/test/chrome_process_util.cc | 43 | ||||
-rw-r--r-- | chrome/test/chrome_process_util_linux.cc | 50 | ||||
-rw-r--r-- | chrome/test/chrome_process_util_mac.cc | 12 | ||||
-rw-r--r-- | chrome/test/chrome_process_util_win.cc | 37 | ||||
-rw-r--r-- | chrome/test/ui/ui_test.cc | 24 |
8 files changed, 136 insertions, 52 deletions
diff --git a/chrome/test/automation/automation_messages_internal.h b/chrome/test/automation/automation_messages_internal.h index f6ed6d5..c2d627d 100644 --- a/chrome/test/automation/automation_messages_internal.h +++ b/chrome/test/automation/automation_messages_internal.h @@ -881,4 +881,9 @@ IPC_BEGIN_MESSAGES(Automation) IPC::Reposition_Params /* SetWindowPos params */) #endif // defined(OS_WIN) + // Gets the title of the top level browser window. + IPC_SYNC_MESSAGE_ROUTED1_1(AutomationMsg_WindowTitle, + int /* automation handle */, + string16 /* title text */ ) + IPC_END_MESSAGES(Automation) diff --git a/chrome/test/automation/window_proxy.cc b/chrome/test/automation/window_proxy.cc index 030fea2..7288595 100644 --- a/chrome/test/automation/window_proxy.cc +++ b/chrome/test/automation/window_proxy.cc @@ -16,6 +16,7 @@ #include "chrome/test/automation/tab_proxy.h" #include "googleurl/src/gurl.h" +#if defined(OS_WIN) bool WindowProxy::GetHWND(HWND* handle) const { if (!is_valid()) return false; @@ -33,6 +34,18 @@ bool WindowProxy::SimulateOSClick(const POINT& click, int flags) { return sender_->Send( new AutomationMsg_WindowClick(0, handle_, click, flags)); } +#endif // defined(OS_WIN) + +bool WindowProxy::GetWindowTitle(string16* text) { + if (!is_valid()) return false; + + if (!text) { + NOTREACHED(); + return false; + } + + return sender_->Send(new AutomationMsg_WindowTitle(0, handle_, text)); +} bool WindowProxy::SimulateOSKeyPress(wchar_t key, int flags) { if (!is_valid()) return false; diff --git a/chrome/test/automation/window_proxy.h b/chrome/test/automation/window_proxy.h index 8bade17..2935480 100644 --- a/chrome/test/automation/window_proxy.h +++ b/chrome/test/automation/window_proxy.h @@ -13,6 +13,7 @@ #include <string> +#include "base/string16.h" #include "base/thread.h" #include "chrome/test/automation/automation_handle_tracker.h" @@ -50,6 +51,9 @@ class WindowProxy : public AutomationResourceProxy { bool SimulateOSClick(const POINT& click, int flags); #endif // defined(OS_WIN) + // Get the title of the top level window. + bool GetWindowTitle(string16* text); + // Simulates a key press at the OS level. |key| is the key pressed and // |flags| specifies which modifiers keys are also pressed (as defined in // chrome/views/event.h). Note that this actually sends the event to the diff --git a/chrome/test/chrome_process_util.cc b/chrome/test/chrome_process_util.cc index 128ec33..461194f 100644 --- a/chrome/test/chrome_process_util.cc +++ b/chrome/test/chrome_process_util.cc @@ -8,11 +8,32 @@ #include "base/process_util.h" #include "base/time.h" +#include "chrome/common/chrome_constants.h" #include "chrome/common/result_codes.h" using base::Time; using base::TimeDelta; +namespace { + +class ChromeProcessFilter : public base::ProcessFilter { + public: + explicit ChromeProcessFilter(base::ProcessId browser_pid) + : browser_pid_(browser_pid) {} + + virtual bool Includes(base::ProcessId pid, base::ProcessId parent_pid) const { + // Match browser process itself and its children. + return browser_pid_ == pid || browser_pid_ == parent_pid; + } + + private: + base::ProcessId browser_pid_; + + DISALLOW_COPY_AND_ASSIGN(ChromeProcessFilter); +}; + +} // namespace + void TerminateAllChromeProcesses(const FilePath& data_dir) { // Total time the function will wait for chrome processes // to terminate after it told them to do so. @@ -48,3 +69,25 @@ void TerminateAllChromeProcesses(const FilePath& data_dir) { for (it = handles.begin(); it != handles.end(); ++it) base::CloseProcessHandle(*it); } + +ChromeProcessList GetRunningChromeProcesses(const FilePath& data_dir) { + ChromeProcessList result; + + base::ProcessId browser_pid = ChromeBrowserProcessId(data_dir); + if (browser_pid < 0) + return result; + + ChromeProcessFilter filter(browser_pid); + base::NamedProcessIterator it(chrome::kBrowserProcessExecutableName, &filter); + + const ProcessEntry* process_entry; + while ((process_entry = it.NextProcessEntry())) { +#if defined(OS_WIN) + result.push_back(process_entry->th32ProcessID); +#elif defined(OS_POSIX) + result.push_back(process_entry->pid); +#endif + } + + return result; +} diff --git a/chrome/test/chrome_process_util_linux.cc b/chrome/test/chrome_process_util_linux.cc new file mode 100644 index 0000000..f5c1df1 --- /dev/null +++ b/chrome/test/chrome_process_util_linux.cc @@ -0,0 +1,50 @@ +// 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. + +#include "chrome/test/chrome_process_util.h" + +#include <stdio.h> + +#include <string> +#include <vector> + +#include "base/logging.h" +#include "base/string_util.h" + +base::ProcessId ChromeBrowserProcessId(const FilePath& data_dir) { + char fuser_output[256]; + + FilePath socket_name = data_dir.Append("SingletonSocket"); + // TODO(phajdan.jr): Do better quoting around the socket name. + std::string cmd = "fuser \"" + socket_name.value() + "\""; + FILE* fuser_pipe = popen(cmd.c_str(), "r"); + if (!fuser_pipe) { + DLOG(ERROR) << "Error launching fuser."; + return -1; + } + + char* rv = fgets(fuser_output, 256, fuser_pipe); + pclose(fuser_pipe); + + if (!rv) + return -1; + + std::string trimmed_output; + TrimWhitespace(fuser_output, TRIM_ALL, &trimmed_output); + + for (size_t i = 0; i < trimmed_output.size(); ++i) { + if (trimmed_output[i] == ' '){ + DLOG(ERROR) << "Expected exactly 1 process to have socket open: " << + fuser_output; + return -1; + } + } + + int pid; + if (!StringToInt(trimmed_output, &pid)) { + DLOG(ERROR) << "Unexpected fuser output: " << fuser_output; + return -1; + } + return pid; +} diff --git a/chrome/test/chrome_process_util_mac.cc b/chrome/test/chrome_process_util_mac.cc new file mode 100644 index 0000000..4d252ba --- /dev/null +++ b/chrome/test/chrome_process_util_mac.cc @@ -0,0 +1,12 @@ +// 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. + +#include "chrome/test/chrome_process_util.h" + +#include "base/logging.h" + +base::ProcessId ChromeBrowserProcessId(const FilePath& data_dir) { + NOTIMPLEMENTED(); + return -1; +} diff --git a/chrome/test/chrome_process_util_win.cc b/chrome/test/chrome_process_util_win.cc index b0e2e40..97fbc19 100644 --- a/chrome/test/chrome_process_util_win.cc +++ b/chrome/test/chrome_process_util_win.cc @@ -12,26 +12,6 @@ #include "base/process_util.h" #include "chrome/common/chrome_constants.h" -namespace { - -class ChromeProcessFilter : public base::ProcessFilter { - public: - explicit ChromeProcessFilter(base::ProcessId browser_pid) - : browser_pid_(browser_pid) {} - - virtual bool Includes(base::ProcessId pid, base::ProcessId parent_pid) const { - // Match browser process itself and its children. - return browser_pid_ == pid || browser_pid_ == parent_pid; - } - - private: - base::ProcessId browser_pid_; - - DISALLOW_COPY_AND_ASSIGN(ChromeProcessFilter); -}; - -} // namespace - base::ProcessId ChromeBrowserProcessId(const FilePath& data_dir) { HWND message_window = FindWindowEx(HWND_MESSAGE, NULL, chrome::kMessageWindowClass, @@ -44,20 +24,3 @@ base::ProcessId ChromeBrowserProcessId(const FilePath& data_dir) { return browser_pid; } - -ChromeProcessList GetRunningChromeProcesses(const FilePath& data_dir) { - ChromeProcessList result; - - base::ProcessId browser_pid = ChromeBrowserProcessId(data_dir); - if (browser_pid < 0) - return result; - - ChromeProcessFilter filter(browser_pid); - base::NamedProcessIterator it(chrome::kBrowserProcessExecutableName, &filter); - - const ProcessEntry* process_entry; - while (process_entry = it.NextProcessEntry()) - result.push_back(process_entry->th32ProcessID); - - return result; -} diff --git a/chrome/test/ui/ui_test.cc b/chrome/test/ui/ui_test.cc index d30643b2..f0f29aa 100644 --- a/chrome/test/ui/ui_test.cc +++ b/chrome/test/ui/ui_test.cc @@ -253,12 +253,7 @@ void UITest::LaunchBrowser(const CommandLine& arguments, bool clear_profile) { std::wstring extra_chrome_flags = CommandLine::ForCurrentProcess()->GetSwitchValue(kExtraChromeFlagsSwitch); if (!extra_chrome_flags.empty()) { -#if defined(OS_WIN) command_line.AppendLooseValue(extra_chrome_flags); -#else - // TODO(port): figure out how to pass through extra flags via a string. - NOTIMPLEMENTED(); -#endif } // We need cookies on file:// for things like the page cycler. @@ -446,7 +441,7 @@ void UITest::QuitBrowser() { } void UITest::AssertAppNotRunning(const std::wstring& error_message) { -#if defined(OS_WIN) +#if defined(OS_WIN) || defined(OS_LINUX) ASSERT_EQ(0, GetBrowserProcessCount()) << error_message; #else // TODO(port): Enable when chrome_process_util is ported. @@ -455,7 +450,7 @@ void UITest::AssertAppNotRunning(const std::wstring& error_message) { } void UITest::CleanupAppProcesses() { -#if defined(OS_WIN) +#if defined(OS_WIN) || defined(OS_LINUX) TerminateAllChromeProcesses(FilePath::FromWStringHack(user_data_dir())); // Suppress spammy failures that seem to be occurring when running @@ -503,10 +498,6 @@ void UITest::NavigateToURL(const GURL& url) { ASSERT_FALSE(is_timeout) << url.spec(); } -// TODO(port): this #if effectively cuts out half of this file on -// non-Windows platforms, and is a temporary hack to get things -// building. -#if defined(OS_WIN) bool UITest::WaitForDownloadShelfVisible(TabProxy* tab) { const int kCycles = 20; for (int i = 0; i < kCycles; i++) { @@ -522,6 +513,10 @@ bool UITest::WaitForDownloadShelfVisible(TabProxy* tab) { return false; } +// TODO(port): this #if effectively cuts out half of this file on +// non-Windows platforms, and is a temporary hack to get things +// building. +#if defined(OS_WIN) bool UITest::WaitForFindWindowVisibilityChange(BrowserProxy* browser, bool wait_for_open) { const int kCycles = 20; @@ -585,16 +580,15 @@ bool UITest::CrashAwareSleep(int time_out_ms) { return base::CrashAwareSleep(process_, time_out_ms); } -#if defined(OS_WIN) -// TODO(port): Port GetRunningChromeProcesses and sort out one w/string issue. - -/*static*/ +// static int UITest::GetBrowserProcessCount() { FilePath data_dir; PathService::Get(chrome::DIR_USER_DATA, &data_dir); return GetRunningChromeProcesses(data_dir).size(); } +#if defined(OS_WIN) +// TODO(port): Port GetRunningChromeProcesses and sort out one w/string issue. static DictionaryValue* LoadDictionaryValueFromPath(const FilePath& path) { if (path.empty()) return NULL; |