diff options
21 files changed, 234 insertions, 109 deletions
diff --git a/chrome/browser/automation/automation_provider.cc b/chrome/browser/automation/automation_provider.cc index 1f1adc2..34d1599 100644 --- a/chrome/browser/automation/automation_provider.cc +++ b/chrome/browser/automation/automation_provider.cc @@ -29,6 +29,7 @@ #include "chrome/browser/tab_contents/web_contents_view.h" #include "chrome/common/chrome_paths.h" #include "chrome/common/notification_registrar.h" +#include "chrome/common/platform_util.h" #include "chrome/common/pref_service.h" #include "chrome/test/automation/automation_messages.h" #include "net/base/cookie_monster.h" @@ -1038,6 +1039,8 @@ void AutomationProvider::OnMessageReceived(const IPC::Message& message) { OverrideEncoding) IPC_MESSAGE_HANDLER(AutomationMsg_SavePackageShouldPromptUser, SavePackageShouldPromptUser) + IPC_MESSAGE_HANDLER(AutomationMsg_WindowTitle, + GetWindowTitle) IPC_END_MESSAGE_MAP() } @@ -1896,14 +1899,9 @@ void AutomationProvider::ExecuteJavascript(int handle, void AutomationProvider::GetShelfVisibility(int handle, bool* visible) { *visible = false; -#if defined(OS_WIN) WebContents* web_contents = GetWebContentsForHandle(handle, NULL); if (web_contents) *visible = web_contents->IsDownloadShelfVisible(); -#else - // TODO(port): Enable when web_contents->IsDownloadShelfVisible is ported. - NOTIMPLEMENTED(); -#endif } void AutomationProvider::GetConstrainedWindowCount(int handle, int* count) { @@ -2450,7 +2448,7 @@ void AutomationProvider::IsPageMenuCommandEnabled(int browser_handle, } #if defined(OS_WIN) -// TODO(port): Enable these. +// TODO(port): Enable this. void AutomationProvider::PrintNow(int tab_handle, IPC::Message* reply_message) { NavigationController* tab = NULL; @@ -2467,6 +2465,7 @@ void AutomationProvider::PrintNow(int tab_handle, AutomationMsg_PrintNow::WriteReplyParams(reply_message, false); Send(reply_message); } +#endif void AutomationProvider::SavePage(int tab_handle, const std::wstring& file_name, @@ -2496,6 +2495,8 @@ void AutomationProvider::SavePage(int tab_handle, *success = true; } +#if defined(OS_WIN) +// TODO(port): Enable these. void AutomationProvider::GetAutocompleteEditText(int autocomplete_edit_handle, bool* success, std::wstring* text) { @@ -2850,3 +2851,8 @@ void AutomationProvider::OnTabReposition( } #endif // defined(OS_WIN) + +void AutomationProvider::GetWindowTitle(int handle, string16* text) { + gfx::NativeWindow window = window_tracker_->GetResource(handle); + text->assign(platform_util::GetWindowTitle(window)); +} diff --git a/chrome/browser/automation/automation_provider.h b/chrome/browser/automation/automation_provider.h index d704fa3..01698b4 100644 --- a/chrome/browser/automation/automation_provider.h +++ b/chrome/browser/automation/automation_provider.h @@ -416,6 +416,8 @@ class AutomationProvider : public base::RefCounted<AutomationProvider>, void SavePackageShouldPromptUser(bool should_prompt); + void GetWindowTitle(int handle, string16* text); + // Convert a tab handle into a WebContents. If |tab| is non-NULL a pointer // to the tab is also returned. Returns NULL in case of failure or if the tab // is not of the WebContents type. diff --git a/chrome/browser/automation/automation_window_tracker.h b/chrome/browser/automation/automation_window_tracker.h index cc70dd8..1b9aff8 100644 --- a/chrome/browser/automation/automation_window_tracker.h +++ b/chrome/browser/automation/automation_window_tracker.h @@ -2,8 +2,8 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. -#ifndef CHROME_BROWSER_AUTOMATION_AUTOMATION_WINDOW_TRACKER_H__ -#define CHROME_BROWSER_AUTOMATION_AUTOMATION_WINDOW_TRACKER_H__ +#ifndef CHROME_BROWSER_AUTOMATION_AUTOMATION_WINDOW_TRACKER_H_ +#define CHROME_BROWSER_AUTOMATION_AUTOMATION_WINDOW_TRACKER_H_ #include "base/gfx/native_widget_types.h" #include "build/build_config.h" @@ -51,4 +51,4 @@ class AutomationWindowTracker } }; -#endif // CHROME_BROWSER_AUTOMATION_AUTOMATION_WINDOW_TRACKER_H__ +#endif // CHROME_BROWSER_AUTOMATION_AUTOMATION_WINDOW_TRACKER_H_ diff --git a/chrome/browser/browser_uitest.cc b/chrome/browser/browser_uitest.cc index 3a05636..2f52007 100644 --- a/chrome/browser/browser_uitest.cc +++ b/chrome/browser/browser_uitest.cc @@ -3,12 +3,14 @@ // found in the LICENSE file. #include "base/file_util.h" +#include "base/gfx/native_widget_types.h" #include "base/string_util.h" #include "base/sys_info.h" #include "base/values.h" #include "chrome/app/chrome_dll_resource.h" #include "chrome/common/chrome_constants.h" #include "chrome/common/l10n_util.h" +#include "chrome/common/platform_util.h" #include "chrome/common/pref_names.h" #include "chrome/test/automation/browser_proxy.h" #include "chrome/test/automation/tab_proxy.h" @@ -31,6 +33,7 @@ std::wstring WindowCaptionFromPageTitle(std::wstring page_title) { class BrowserTest : public UITest { protected: +#if defined(OS_WIN) HWND GetMainWindow() { scoped_ptr<BrowserProxy> browser(automation()->GetBrowserWindow(0)); scoped_ptr<WindowProxy> window(browser->GetWindow()); @@ -39,13 +42,15 @@ class BrowserTest : public UITest { EXPECT_TRUE(window->GetHWND(&window_handle)); return window_handle; } +#endif std::wstring GetWindowTitle() { - HWND window_handle = GetMainWindow(); - std::wstring result; - int length = ::GetWindowTextLength(window_handle) + 1; - ::GetWindowText(window_handle, WriteInto(&result, length), length); - return result; + scoped_ptr<BrowserProxy> browser(automation()->GetBrowserWindow(0)); + scoped_ptr<WindowProxy> window(browser->GetWindow()); + + string16 title; + EXPECT_TRUE(window->GetWindowTitle(&title)); + return UTF16ToWide(title); } }; @@ -65,8 +70,8 @@ TEST_F(BrowserTest, NoTitle) { test_file = test_file.AppendASCII("title1.html"); NavigateToURL(net::FilePathToFileURL(test_file)); - Sleep(sleep_timeout_ms()); // The browser lazily updates the title. - + // The browser lazily updates the title. + PlatformThread::Sleep(sleep_timeout_ms()); EXPECT_EQ(WindowCaptionFromPageTitle(L"title1.html"), GetWindowTitle()); EXPECT_EQ(L"title1.html", GetActiveTabTitle()); } @@ -78,7 +83,8 @@ TEST_F(BrowserTest, Title) { test_file = test_file.AppendASCII("title2.html"); NavigateToURL(net::FilePathToFileURL(test_file)); - Sleep(sleep_timeout_ms()); // The browser lazily updates the title. + // The browser lazily updates the title. + PlatformThread::Sleep(sleep_timeout_ms()); const std::wstring test_title(L"Title Of Awesomeness"); EXPECT_EQ(WindowCaptionFromPageTitle(test_title), GetWindowTitle()); @@ -114,20 +120,21 @@ TEST_F(BrowserTest, ThirtyFourTabs) { } } +#if defined(OS_WIN) // The browser should quit quickly if it receives a WM_ENDSESSION message. TEST_F(BrowserTest, WindowsSessionEnd) { FilePath test_file(FilePath::FromWStringHack(test_data_directory_)); test_file = test_file.AppendASCII("title1.html"); NavigateToURL(net::FilePathToFileURL(test_file)); - Sleep(action_timeout_ms()); + PlatformThread::Sleep(action_timeout_ms()); // Simulate an end of session. Normally this happens when the user // shuts down the pc or logs off. HWND window_handle = GetMainWindow(); ASSERT_TRUE(::PostMessageW(window_handle, WM_ENDSESSION, 0, 0)); - Sleep(action_timeout_ms()); + PlatformThread::Sleep(action_timeout_ms()); ASSERT_FALSE(IsBrowserRunning()); // Make sure the UMA metrics say we didn't crash. @@ -151,6 +158,7 @@ TEST_F(BrowserTest, WindowsSessionEnd) { &exited_cleanly)); ASSERT_TRUE(exited_cleanly); } +#endif // This test is flakey, see bug 5668 for details. TEST_F(BrowserTest, DISABLED_JavascriptAlertActivatesTab) { @@ -207,7 +215,7 @@ TEST_F(BrowserTest, NullOpenerRedirectForksProcess) { // Make sure that a new tab has been created and that we have a new renderer // process for it. tab->NavigateToURLAsync(fork_url); - Sleep(action_timeout_ms()); + PlatformThread::Sleep(action_timeout_ms()); ASSERT_EQ(orig_process_count + 1, GetBrowserProcessCount()); int new_tab_count = -1; ASSERT_TRUE(window->GetTabCount(&new_tab_count)); @@ -215,6 +223,8 @@ TEST_F(BrowserTest, NullOpenerRedirectForksProcess) { } #endif +#if !defined(OS_LINUX) +// TODO(port): This passes on linux locally, but fails on the try bot. // Tests that non-Gmail-like script redirects (i.e., non-null window.opener) or // a same-page-redirect) will not fork a new process. TEST_F(BrowserTest, OtherRedirectsDontForkProcess) { @@ -240,13 +250,13 @@ TEST_F(BrowserTest, OtherRedirectsDontForkProcess) { // Use JavaScript URL to almost fork a new tab, but not quite. (Leave the // opener non-null.) Should not fork a process. - std::wstring url_prefix(L"javascript:(function(){w=window.open();"); + std::string url_prefix("javascript:(function(){w=window.open();"); GURL dont_fork_url(url_prefix + - L"w.document.location=\"http://localhost:1337\";})()"); + "w.document.location=\"http://localhost:1337\";})()"); // Make sure that a new tab but not new process has been created. tab->NavigateToURLAsync(dont_fork_url); - Sleep(action_timeout_ms()); + PlatformThread::Sleep(action_timeout_ms()); ASSERT_EQ(orig_process_count, GetBrowserProcessCount()); int new_tab_count = -1; ASSERT_TRUE(window->GetTabCount(&new_tab_count)); @@ -254,14 +264,17 @@ TEST_F(BrowserTest, OtherRedirectsDontForkProcess) { // Same thing if the current tab tries to redirect itself. GURL dont_fork_url2(url_prefix + - L"document.location=\"http://localhost:1337\";})()"); + "document.location=\"http://localhost:1337\";})()"); // Make sure that no new process has been created. tab->NavigateToURLAsync(dont_fork_url2); - Sleep(action_timeout_ms()); + PlatformThread::Sleep(action_timeout_ms()); ASSERT_EQ(orig_process_count, GetBrowserProcessCount()); } +#endif +#if defined(OS_WIN) +// TODO(estade): need to port GetActiveTabTitle(). TEST_F(VisibleBrowserTest, WindowOpenClose) { FilePath test_file(FilePath::FromWStringHack(test_data_directory_)); test_file = test_file.AppendASCII("window.close.html"); @@ -270,7 +283,7 @@ TEST_F(VisibleBrowserTest, WindowOpenClose) { int i; for (i = 0; i < 10; ++i) { - Sleep(action_max_timeout_ms() / 10); + PlatformThread::Sleep(action_max_timeout_ms() / 10); std::wstring title = GetActiveTabTitle(); if (title == L"PASSED") { // Success, bail out. @@ -281,3 +294,4 @@ TEST_F(VisibleBrowserTest, WindowOpenClose) { if (i == 10) FAIL() << "failed to get error page title"; } +#endif diff --git a/chrome/browser/download/save_page_uitest.cc b/chrome/browser/download/save_page_uitest.cc index f9a2036..ecb15e8 100644 --- a/chrome/browser/download/save_page_uitest.cc +++ b/chrome/browser/download/save_page_uitest.cc @@ -17,6 +17,15 @@ const std::string kTestDir = "save_page"; +// We don't append an extension on linux. +#if defined(OS_WIN) +const std::string kAppendedExtension = ".htm"; +#elif defined(OS_LINUX) +const std::string kAppendedExtension = ""; +#elif defined(OS_MAC) +// TODO(port): figure this out for mac. +#endif + class SavePageTest : public UITest { protected: SavePageTest() : UITest() {} @@ -131,8 +140,9 @@ TEST_F(SavePageTest, NoSave) { TEST_F(SavePageTest, FilenameFromPageTitle) { std::string file_name = "b.htm"; + FilePath full_file_name = download_dir_.AppendASCII( - "Test page for saving page feature.htm"); + "Test page for saving page feature" + kAppendedExtension); FilePath dir = download_dir_.AppendASCII( "Test page for saving page feature_files"); @@ -158,9 +168,13 @@ TEST_F(SavePageTest, FilenameFromPageTitle) { EXPECT_TRUE(DieFileDie(dir, true)); } +// This tests that a webpage with the title "test.exe" is saved as "test.htm". +// We probably don't care to handle this on linux. +#if !defined(OS_LINUX) TEST_F(SavePageTest, CleanFilenameFromPageTitle) { std::string file_name = "c.htm"; - FilePath full_file_name = download_dir_.AppendASCII("test.htm"); + FilePath full_file_name = download_dir_.AppendASCII("test" + + kAppendedExtension); FilePath dir = download_dir_.AppendASCII("test_files"); GURL url = URLRequestMockHTTPJob::GetMockUrl(UTF8ToWide(kTestDir + "/" + @@ -180,3 +194,4 @@ TEST_F(SavePageTest, CleanFilenameFromPageTitle) { EXPECT_TRUE(DieFileDie(full_file_name, false)); EXPECT_TRUE(DieFileDie(dir, true)); } +#endif diff --git a/chrome/browser/process_singleton_linux.cc b/chrome/browser/process_singleton_linux.cc index 6ae4596..f37445c 100644 --- a/chrome/browser/process_singleton_linux.cc +++ b/chrome/browser/process_singleton_linux.cc @@ -13,7 +13,7 @@ #include "base/string_util.h" ProcessSingleton::ProcessSingleton(const FilePath& user_data_dir) { - socket_path_ = user_data_dir.Append("Singleton Socket"); + socket_path_ = user_data_dir.Append("SingletonSocket"); } ProcessSingleton::~ProcessSingleton() { diff --git a/chrome/browser/sessions/session_restore_uitest.cc b/chrome/browser/sessions/session_restore_uitest.cc index 4c4538f..0b7315a 100644 --- a/chrome/browser/sessions/session_restore_uitest.cc +++ b/chrome/browser/sessions/session_restore_uitest.cc @@ -22,16 +22,12 @@ namespace { class SessionRestoreUITest : public UITest { protected: SessionRestoreUITest() : UITest() { - FilePath path_prefix = FilePath::FromWStringHack(test_data_directory_); - path_prefix = path_prefix.AppendASCII("session_history") - .Append(FilePath::StringType(&FilePath::kSeparators[0], 1)); - - url1 = net::FilePathToFileURL( - path_prefix.AppendASCII("bot1.html")); - url2 = net::FilePathToFileURL( - path_prefix.AppendASCII("bot2.html")); - url3 = net::FilePathToFileURL( - path_prefix.AppendASCII("bot3.html")); + FilePath path_prefix = FilePath::FromWStringHack(test_data_directory_) + .AppendASCII("session_history"); + + url1 = net::FilePathToFileURL(path_prefix.AppendASCII("bot1.html")); + url2 = net::FilePathToFileURL(path_prefix.AppendASCII("bot2.html")); + url3 = net::FilePathToFileURL(path_prefix.AppendASCII("bot3.html")); } virtual void QuitBrowserAndRestore(int expected_tab_count) { @@ -86,7 +82,7 @@ class SessionRestoreUITest : public UITest { GURL url3; private: - DISALLOW_EVIL_CONSTRUCTORS(SessionRestoreUITest); + DISALLOW_COPY_AND_ASSIGN(SessionRestoreUITest); }; } // namespace diff --git a/chrome/chrome.gyp b/chrome/chrome.gyp index f261250..8e1be3e 100644 --- a/chrome/chrome.gyp +++ b/chrome/chrome.gyp @@ -1814,6 +1814,8 @@ 'test/automation/window_proxy.h', 'test/chrome_process_util.cc', 'test/chrome_process_util.h', + 'test/chrome_process_util_linux.cc', + 'test/chrome_process_util_mac.cc', 'test/chrome_process_util_win.cc', 'test/testing_profile.cc', 'test/testing_profile.h', @@ -1828,11 +1830,6 @@ 'include_dirs': [ 'third_party/wtl/include', ], - }, { # else: OS != "win" - 'sources!': [ - 'test/automation/window_proxy.cc', - 'test/automation/window_proxy.h', - ], }], ], }, @@ -2009,10 +2006,7 @@ 'sources!': [ # TODO(port) 'app/chrome_main_uitest.cc', - 'browser/browser_uitest.cc', 'browser/crash_recovery_uitest.cc', - 'browser/download/download_uitest.cc', - 'browser/download/save_page_uitest.cc', 'browser/login_prompt_uitest.cc', 'browser/metrics/metrics_service_uitest.cc', 'browser/sessions/session_restore_uitest.cc', diff --git a/chrome/common/platform_util.h b/chrome/common/platform_util.h index 3886f17..3e0edda 100644 --- a/chrome/common/platform_util.h +++ b/chrome/common/platform_util.h @@ -6,6 +6,7 @@ #define CHROME_COMMON_PLATFORM_UTIL_H_ #include "base/gfx/native_widget_types.h" +#include "base/string16.h" class FilePath; @@ -17,6 +18,9 @@ void ShowItemInFolder(const FilePath& full_path); // Get the top level window for the native view. This can return NULL. gfx::NativeWindow GetTopLevel(gfx::NativeView view); +// Get the title of the window. +string16 GetWindowTitle(gfx::NativeWindow window); + } #endif // CHROME_COMMON_PLATFORM_UTIL_H_ diff --git a/chrome/common/platform_util_linux.cc b/chrome/common/platform_util_linux.cc index 3c0f5f6..9ef0292 100644 --- a/chrome/common/platform_util_linux.cc +++ b/chrome/common/platform_util_linux.cc @@ -9,6 +9,7 @@ #include "base/file_path.h" #include "base/file_util.h" #include "base/process_util.h" +#include "base/string_util.h" namespace platform_util { @@ -31,4 +32,9 @@ gfx::NativeWindow GetTopLevel(gfx::NativeView view) { return GTK_WINDOW(gtk_widget_get_toplevel(view)); } +string16 GetWindowTitle(gfx::NativeWindow window) { + const gchar* title = gtk_window_get_title(window); + return UTF8ToUTF16(title); +} + } // namespace platform_util diff --git a/chrome/common/platform_util_mac.mm b/chrome/common/platform_util_mac.mm index 308c3af..37cd39c 100644 --- a/chrome/common/platform_util_mac.mm +++ b/chrome/common/platform_util_mac.mm @@ -22,4 +22,9 @@ gfx::NativeWindow GetTopLevel(gfx::NativeView view) { return [view window]; } +string16 GetWindowTitle(gfx::NativeWindow window) { + NOTIMPLEMENTED(); + return string16(); +} + } // namespace platform_util diff --git a/chrome/common/platform_util_win.cc b/chrome/common/platform_util_win.cc index 16ea8c0..1925122 100644 --- a/chrome/common/platform_util_win.cc +++ b/chrome/common/platform_util_win.cc @@ -15,6 +15,7 @@ #include "base/file_util.h" #include "base/gfx/native_widget_types.h" #include "base/logging.h" +#include "base/string_util.h" #include "chrome/common/win_util.h" namespace platform_util { @@ -85,4 +86,11 @@ gfx::NativeWindow GetTopLevel(gfx::NativeView view) { return GetAncestor(view, GA_ROOT); } +string16 GetWindowTitle(gfx::NativeWindow window_handle) { + std::wstring result; + int length = ::GetWindowTextLength(window_handle) + 1; + ::GetWindowText(window_handle, WriteInto(&result, length), length); + return WideToUTF16(result); +} + } // namespace platform_util diff --git a/chrome/common/temp_scaffolding_stubs.cc b/chrome/common/temp_scaffolding_stubs.cc index 5878197..8d2fbff 100644 --- a/chrome/common/temp_scaffolding_stubs.cc +++ b/chrome/common/temp_scaffolding_stubs.cc @@ -83,15 +83,6 @@ void AutomationProvider::PrintNow(int tab_handle, NOTIMPLEMENTED(); } -void AutomationProvider::SavePage(int tab_handle, - const std::wstring& file_name, - const std::wstring& dir_path, - int type, - bool* success) { - *success = false; - NOTIMPLEMENTED(); -} - void AutomationProvider::GetAutocompleteEditText(int autocomplete_edit_handle, bool* success, std::wstring* text) { 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; |