Index: chrome/common/service_process_util_unittest.cc |
=================================================================== |
--- chrome/common/service_process_util_unittest.cc (revision 75945) |
+++ chrome/common/service_process_util_unittest.cc (working copy) |
@@ -8,15 +8,28 @@ |
// TODO(dmaclach): Figure out tests that will work with launchd on Mac OS. |
#include "base/at_exit.h" |
+#include "base/command_line.h" |
#include "base/process_util.h" |
+#include "base/scoped_ptr.h" |
#include "base/string_util.h" |
#include "base/test/multiprocess_test.h" |
#include "base/test/test_timeouts.h" |
#include "base/threading/thread.h" |
+#include "base/utf_string_conversions.h" |
+#include "chrome/common/chrome_switches.h" |
#include "chrome/common/chrome_version_info.h" |
#include "chrome/common/service_process_util.h" |
#include "testing/multiprocess_func_list.h" |
+#if defined(OS_WIN) |
+#include "base/win/win_util.h" |
+#endif |
+ |
+#if defined(OS_LINUX) |
+#include <glib.h> |
+#include "chrome/common/auto_start_linux.h" |
+#endif |
+ |
namespace { |
bool g_good_shutdown = false; |
@@ -91,6 +104,52 @@ |
LaunchAndWait("ServiceProcessStateTestReadyFalse"); |
} |
+TEST_F(ServiceProcessStateTest, AutoRun) { |
+ ServiceProcessState* state = ServiceProcessState::GetInstance(); |
+ ASSERT_TRUE(state->AddToAutoRun()); |
+ scoped_ptr<CommandLine> autorun_command_line; |
+#if defined(OS_WIN) |
+ std::string value_name = GetServiceProcessScopedName("_service_run"); |
+ string16 value; |
+ EXPECT_TRUE(base::win::ReadCommandFromAutoRun(HKEY_CURRENT_USER, |
+ UTF8ToWide(value_name), |
+ &value)); |
+ autorun_command_line.reset(new CommandLine(CommandLine::FromString(value))); |
+#elif defined(OS_LINUX) |
+#if defined(GOOGLE_CHROME_BUILD) |
+ std::string base_desktop_name = "google-chrome-service.desktop"; |
+#else // CHROMIUM_BUILD |
+ std::string base_desktop_name = "chromium-service.desktop"; |
+#endif |
+ std::string exec_value; |
+ EXPECT_TRUE(AutoStart::GetAutostartFileValue( |
+ GetServiceProcessScopedName(base_desktop_name), "Exec", &exec_value)); |
+ GError *error = NULL; |
+ gchar **argv = NULL; |
+ gint argc = NULL; |
+ if (g_shell_parse_argv(exec_value.c_str(), &argc, &argv, &error)) { |
+ autorun_command_line.reset(new CommandLine(argc, argv)); |
+ g_strfreev(argv); |
+ } else { |
+ ADD_FAILURE(); |
+ g_error_free(error); |
+ } |
+#endif // defined(OS_WIN) |
+ if (autorun_command_line.get()) { |
+ EXPECT_EQ(autorun_command_line->GetSwitchValueASCII(switches::kProcessType), |
+ std::string(switches::kServiceProcess)); |
+ } |
+ ASSERT_TRUE(state->RemoveFromAutoRun()); |
+#if defined(OS_WIN) |
+ EXPECT_FALSE(base::win::ReadCommandFromAutoRun(HKEY_CURRENT_USER, |
+ UTF8ToWide(value_name), |
+ &value)); |
+#elif defined(OS_LINUX) |
+ EXPECT_FALSE(AutoStart::GetAutostartFileValue( |
+ GetServiceProcessScopedName(base_desktop_name), "Exec", &exec_value)); |
+#endif // defined(OS_WIN) |
+} |
+ |
TEST_F(ServiceProcessStateTest, SharedMem) { |
std::string version; |
base::ProcessId pid; |