OLD | NEW |
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "base/basictypes.h" | 5 #include "base/basictypes.h" |
6 | 6 |
7 #if !defined(OS_MACOSX) | 7 #if !defined(OS_MACOSX) |
8 // TODO(dmaclach): Figure out tests that will work with launchd on Mac OS. | 8 // TODO(dmaclach): Figure out tests that will work with launchd on Mac OS. |
9 | 9 |
10 #include "base/at_exit.h" | 10 #include "base/at_exit.h" |
| 11 #include "base/command_line.h" |
11 #include "base/process_util.h" | 12 #include "base/process_util.h" |
| 13 #include "base/scoped_ptr.h" |
12 #include "base/string_util.h" | 14 #include "base/string_util.h" |
13 #include "base/test/multiprocess_test.h" | 15 #include "base/test/multiprocess_test.h" |
14 #include "base/test/test_timeouts.h" | 16 #include "base/test/test_timeouts.h" |
15 #include "base/threading/thread.h" | 17 #include "base/threading/thread.h" |
| 18 #include "base/utf_string_conversions.h" |
| 19 #include "chrome/common/chrome_switches.h" |
16 #include "chrome/common/chrome_version_info.h" | 20 #include "chrome/common/chrome_version_info.h" |
17 #include "chrome/common/service_process_util.h" | 21 #include "chrome/common/service_process_util.h" |
18 #include "testing/multiprocess_func_list.h" | 22 #include "testing/multiprocess_func_list.h" |
19 | 23 |
| 24 #if defined(OS_WIN) |
| 25 #include "base/win/win_util.h" |
| 26 #endif |
| 27 |
| 28 #if defined(OS_LINUX) |
| 29 #include <glib.h> |
| 30 #include "chrome/common/auto_start_linux.h" |
| 31 #endif |
| 32 |
20 namespace { | 33 namespace { |
21 | 34 |
22 bool g_good_shutdown = false; | 35 bool g_good_shutdown = false; |
23 | 36 |
24 void ShutdownTask(MessageLoop* loop) { | 37 void ShutdownTask(MessageLoop* loop) { |
25 // Quit the main message loop. | 38 // Quit the main message loop. |
26 ASSERT_FALSE(g_good_shutdown); | 39 ASSERT_FALSE(g_good_shutdown); |
27 g_good_shutdown = true; | 40 g_good_shutdown = true; |
28 loop->PostTask(FROM_HERE, new MessageLoop::QuitTask()); | 41 loop->PostTask(FROM_HERE, new MessageLoop::QuitTask()); |
29 } | 42 } |
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
84 TEST_F(ServiceProcessStateTest, ReadyState) { | 97 TEST_F(ServiceProcessStateTest, ReadyState) { |
85 ASSERT_FALSE(CheckServiceProcessReady()); | 98 ASSERT_FALSE(CheckServiceProcessReady()); |
86 ServiceProcessState* state = ServiceProcessState::GetInstance(); | 99 ServiceProcessState* state = ServiceProcessState::GetInstance(); |
87 ASSERT_TRUE(state->Initialize()); | 100 ASSERT_TRUE(state->Initialize()); |
88 ASSERT_TRUE(state->SignalReady(IOMessageLoopProxy(), NULL)); | 101 ASSERT_TRUE(state->SignalReady(IOMessageLoopProxy(), NULL)); |
89 LaunchAndWait("ServiceProcessStateTestReadyTrue"); | 102 LaunchAndWait("ServiceProcessStateTestReadyTrue"); |
90 state->SignalStopped(); | 103 state->SignalStopped(); |
91 LaunchAndWait("ServiceProcessStateTestReadyFalse"); | 104 LaunchAndWait("ServiceProcessStateTestReadyFalse"); |
92 } | 105 } |
93 | 106 |
| 107 TEST_F(ServiceProcessStateTest, AutoRun) { |
| 108 ServiceProcessState* state = ServiceProcessState::GetInstance(); |
| 109 ASSERT_TRUE(state->AddToAutoRun()); |
| 110 scoped_ptr<CommandLine> autorun_command_line; |
| 111 #if defined(OS_WIN) |
| 112 std::string value_name = GetServiceProcessScopedName("_service_run"); |
| 113 string16 value; |
| 114 EXPECT_TRUE(base::win::ReadCommandFromAutoRun(HKEY_CURRENT_USER, |
| 115 UTF8ToWide(value_name), |
| 116 &value)); |
| 117 autorun_command_line.reset(new CommandLine(CommandLine::FromString(value))); |
| 118 #elif defined(OS_LINUX) |
| 119 #if defined(GOOGLE_CHROME_BUILD) |
| 120 std::string base_desktop_name = "google-chrome-service.desktop"; |
| 121 #else // CHROMIUM_BUILD |
| 122 std::string base_desktop_name = "chromium-service.desktop"; |
| 123 #endif |
| 124 std::string exec_value; |
| 125 EXPECT_TRUE(AutoStart::GetAutostartFileValue( |
| 126 GetServiceProcessScopedName(base_desktop_name), "Exec", &exec_value)); |
| 127 GError *error = NULL; |
| 128 gchar **argv = NULL; |
| 129 gint argc = NULL; |
| 130 if (g_shell_parse_argv(exec_value.c_str(), &argc, &argv, &error)) { |
| 131 autorun_command_line.reset(new CommandLine(argc, argv)); |
| 132 g_strfreev(argv); |
| 133 } else { |
| 134 ADD_FAILURE(); |
| 135 g_error_free(error); |
| 136 } |
| 137 #endif // defined(OS_WIN) |
| 138 if (autorun_command_line.get()) { |
| 139 EXPECT_EQ(autorun_command_line->GetSwitchValueASCII(switches::kProcessType), |
| 140 std::string(switches::kServiceProcess)); |
| 141 } |
| 142 ASSERT_TRUE(state->RemoveFromAutoRun()); |
| 143 #if defined(OS_WIN) |
| 144 EXPECT_FALSE(base::win::ReadCommandFromAutoRun(HKEY_CURRENT_USER, |
| 145 UTF8ToWide(value_name), |
| 146 &value)); |
| 147 #elif defined(OS_LINUX) |
| 148 EXPECT_FALSE(AutoStart::GetAutostartFileValue( |
| 149 GetServiceProcessScopedName(base_desktop_name), "Exec", &exec_value)); |
| 150 #endif // defined(OS_WIN) |
| 151 } |
| 152 |
94 TEST_F(ServiceProcessStateTest, SharedMem) { | 153 TEST_F(ServiceProcessStateTest, SharedMem) { |
95 std::string version; | 154 std::string version; |
96 base::ProcessId pid; | 155 base::ProcessId pid; |
97 #if defined(OS_WIN) | 156 #if defined(OS_WIN) |
98 // On Posix, named shared memory uses a file on disk. This file | 157 // On Posix, named shared memory uses a file on disk. This file |
99 // could be lying around from previous crashes which could cause | 158 // could be lying around from previous crashes which could cause |
100 // GetServiceProcessPid to lie. On Windows, we use a named event so we | 159 // GetServiceProcessPid to lie. On Windows, we use a named event so we |
101 // don't have this issue. Until we have a more stable shared memory | 160 // don't have this issue. Until we have a more stable shared memory |
102 // implementation on Posix, this check will only execute on Windows. | 161 // implementation on Posix, this check will only execute on Windows. |
103 ASSERT_FALSE(GetServiceProcessData(&version, &pid)); | 162 ASSERT_FALSE(GetServiceProcessData(&version, &pid)); |
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
156 message_loop.PostDelayedTask(FROM_HERE, | 215 message_loop.PostDelayedTask(FROM_HERE, |
157 new MessageLoop::QuitTask(), | 216 new MessageLoop::QuitTask(), |
158 TestTimeouts::action_max_timeout_ms()); | 217 TestTimeouts::action_max_timeout_ms()); |
159 EXPECT_FALSE(g_good_shutdown); | 218 EXPECT_FALSE(g_good_shutdown); |
160 message_loop.Run(); | 219 message_loop.Run(); |
161 EXPECT_TRUE(g_good_shutdown); | 220 EXPECT_TRUE(g_good_shutdown); |
162 return 0; | 221 return 0; |
163 } | 222 } |
164 | 223 |
165 #endif // !OS_MACOSX | 224 #endif // !OS_MACOSX |
OLD | NEW |