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

Side by Side Diff: chrome/browser/process_singleton_linux_uitest.cc

Issue 6282002: Remove action_timeout_ms and fix all the callers. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 9 years, 11 months 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 unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « no previous file | chrome/browser/tab_restore_uitest.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 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 "chrome/browser/process_singleton.h" 5 #include "chrome/browser/process_singleton.h"
6 6
7 #include <sys/types.h> 7 #include <sys/types.h>
8 #include <sys/wait.h> 8 #include <sys/wait.h>
9 #include <signal.h> 9 #include <signal.h>
10 #include <unistd.h> 10 #include <unistd.h>
(...skipping 128 matching lines...) Expand 10 before | Expand all | Expand 10 after
139 #define NotifyOtherProcessHostChanged FAILS_NotifyOtherProcessHostChanged 139 #define NotifyOtherProcessHostChanged FAILS_NotifyOtherProcessHostChanged
140 #endif 140 #endif
141 141
142 // TODO(james.su@gmail.com): port following tests to Windows. 142 // TODO(james.su@gmail.com): port following tests to Windows.
143 // Test success case of NotifyOtherProcess(). 143 // Test success case of NotifyOtherProcess().
144 TEST_F(ProcessSingletonLinuxTest, NotifyOtherProcessSuccess) { 144 TEST_F(ProcessSingletonLinuxTest, NotifyOtherProcessSuccess) {
145 std::string url("about:blank"); 145 std::string url("about:blank");
146 int original_tab_count = GetTabCount(); 146 int original_tab_count = GetTabCount();
147 147
148 EXPECT_EQ(ProcessSingleton::PROCESS_NOTIFIED, 148 EXPECT_EQ(ProcessSingleton::PROCESS_NOTIFIED,
149 NotifyOtherProcess(url, action_timeout_ms())); 149 NotifyOtherProcess(url, TestTimeouts::action_timeout_ms()));
150 EXPECT_EQ(original_tab_count + 1, GetTabCount()); 150 EXPECT_EQ(original_tab_count + 1, GetTabCount());
151 EXPECT_EQ(url, GetActiveTabURL().spec()); 151 EXPECT_EQ(url, GetActiveTabURL().spec());
152 } 152 }
153 153
154 // Test failure case of NotifyOtherProcess(). 154 // Test failure case of NotifyOtherProcess().
155 TEST_F(ProcessSingletonLinuxTest, NotifyOtherProcessFailure) { 155 TEST_F(ProcessSingletonLinuxTest, NotifyOtherProcessFailure) {
156 base::ProcessId pid = browser_process_id(); 156 base::ProcessId pid = browser_process_id();
157 157
158 ASSERT_GE(pid, 1); 158 ASSERT_GE(pid, 1);
159 159
160 // Block the browser process, then it'll be killed by 160 // Block the browser process, then it'll be killed by
161 // ProcessSingleton::NotifyOtherProcess(). 161 // ProcessSingleton::NotifyOtherProcess().
162 kill(pid, SIGSTOP); 162 kill(pid, SIGSTOP);
163 163
164 // Wait to make sure the browser process is actually stopped. 164 // Wait to make sure the browser process is actually stopped.
165 // It's necessary when running with valgrind. 165 // It's necessary when running with valgrind.
166 EXPECT_GE(HANDLE_EINTR(waitpid(pid, 0, WUNTRACED)), 0); 166 EXPECT_GE(HANDLE_EINTR(waitpid(pid, 0, WUNTRACED)), 0);
167 167
168 std::string url("about:blank"); 168 std::string url("about:blank");
169 EXPECT_EQ(ProcessSingleton::PROCESS_NONE, 169 EXPECT_EQ(ProcessSingleton::PROCESS_NONE,
170 NotifyOtherProcess(url, action_timeout_ms())); 170 NotifyOtherProcess(url, TestTimeouts::action_timeout_ms()));
171 171
172 // Wait for a while to make sure the browser process is actually killed. 172 // Wait for a while to make sure the browser process is actually killed.
173 EXPECT_FALSE(CrashAwareSleep(TestTimeouts::action_timeout_ms())); 173 EXPECT_FALSE(CrashAwareSleep(TestTimeouts::action_timeout_ms()));
174 } 174 }
175 175
176 // Test that we don't kill ourselves by accident if a lockfile with the same pid 176 // Test that we don't kill ourselves by accident if a lockfile with the same pid
177 // happens to exist. 177 // happens to exist.
178 // TODO(mattm): This doesn't really need to be a uitest. (We don't use the 178 // TODO(mattm): This doesn't really need to be a uitest. (We don't use the
179 // uitest created browser process, but we do use some uitest provided stuff like 179 // uitest created browser process, but we do use some uitest provided stuff like
180 // the user_data_dir and the NotifyOtherProcess function in this file, which 180 // the user_data_dir and the NotifyOtherProcess function in this file, which
181 // would have to be duplicated or shared if this test was moved into a 181 // would have to be duplicated or shared if this test was moved into a
182 // unittest.) 182 // unittest.)
183 TEST_F(ProcessSingletonLinuxTest, NotifyOtherProcessNoSuicide) { 183 TEST_F(ProcessSingletonLinuxTest, NotifyOtherProcessNoSuicide) {
184 // Replace lockfile with one containing our own pid. 184 // Replace lockfile with one containing our own pid.
185 EXPECT_EQ(0, unlink(lock_path_.value().c_str())); 185 EXPECT_EQ(0, unlink(lock_path_.value().c_str()));
186 std::string symlink_content = StringPrintf( 186 std::string symlink_content = StringPrintf(
187 "%s%c%u", 187 "%s%c%u",
188 net::GetHostName().c_str(), 188 net::GetHostName().c_str(),
189 '-', 189 '-',
190 base::GetCurrentProcId()); 190 base::GetCurrentProcId());
191 EXPECT_EQ(0, symlink(symlink_content.c_str(), lock_path_.value().c_str())); 191 EXPECT_EQ(0, symlink(symlink_content.c_str(), lock_path_.value().c_str()));
192 192
193 // Remove socket so that we will not be able to notify the existing browser. 193 // Remove socket so that we will not be able to notify the existing browser.
194 EXPECT_EQ(0, unlink(socket_path_.value().c_str())); 194 EXPECT_EQ(0, unlink(socket_path_.value().c_str()));
195 195
196 std::string url("about:blank"); 196 std::string url("about:blank");
197 EXPECT_EQ(ProcessSingleton::PROCESS_NONE, 197 EXPECT_EQ(ProcessSingleton::PROCESS_NONE,
198 NotifyOtherProcess(url, action_timeout_ms())); 198 NotifyOtherProcess(url, TestTimeouts::action_timeout_ms()));
199 // If we've gotten to this point without killing ourself, the test succeeded. 199 // If we've gotten to this point without killing ourself, the test succeeded.
200 } 200 }
201 201
202 // Test that we can still notify a process on the same host even after the 202 // Test that we can still notify a process on the same host even after the
203 // hostname changed. 203 // hostname changed.
204 TEST_F(ProcessSingletonLinuxTest, NotifyOtherProcessHostChanged) { 204 TEST_F(ProcessSingletonLinuxTest, NotifyOtherProcessHostChanged) {
205 EXPECT_EQ(0, unlink(lock_path_.value().c_str())); 205 EXPECT_EQ(0, unlink(lock_path_.value().c_str()));
206 EXPECT_EQ(0, symlink("FAKEFOOHOST-1234", lock_path_.value().c_str())); 206 EXPECT_EQ(0, symlink("FAKEFOOHOST-1234", lock_path_.value().c_str()));
207 207
208 int original_tab_count = GetTabCount(); 208 int original_tab_count = GetTabCount();
209 209
210 std::string url("about:blank"); 210 std::string url("about:blank");
211 EXPECT_EQ(ProcessSingleton::PROCESS_NOTIFIED, 211 EXPECT_EQ(ProcessSingleton::PROCESS_NOTIFIED,
212 NotifyOtherProcess(url, action_timeout_ms())); 212 NotifyOtherProcess(url, TestTimeouts::action_timeout_ms()));
213 EXPECT_EQ(original_tab_count + 1, GetTabCount()); 213 EXPECT_EQ(original_tab_count + 1, GetTabCount());
214 EXPECT_EQ(url, GetActiveTabURL().spec()); 214 EXPECT_EQ(url, GetActiveTabURL().spec());
215 } 215 }
216 216
217 // Test that we fail when lock says process is on another host and we can't 217 // Test that we fail when lock says process is on another host and we can't
218 // notify it over the socket. 218 // notify it over the socket.
219 TEST_F(ProcessSingletonLinuxTest, NotifyOtherProcessDifferingHost) { 219 TEST_F(ProcessSingletonLinuxTest, NotifyOtherProcessDifferingHost) {
220 base::ProcessId pid = browser_process_id(); 220 base::ProcessId pid = browser_process_id();
221 221
222 ASSERT_GE(pid, 1); 222 ASSERT_GE(pid, 1);
223 223
224 // Kill the browser process, so that it does not respond on the socket. 224 // Kill the browser process, so that it does not respond on the socket.
225 kill(pid, SIGKILL); 225 kill(pid, SIGKILL);
226 // Wait for a while to make sure the browser process is actually killed. 226 // Wait for a while to make sure the browser process is actually killed.
227 EXPECT_FALSE(CrashAwareSleep(TestTimeouts::action_timeout_ms())); 227 EXPECT_FALSE(CrashAwareSleep(TestTimeouts::action_timeout_ms()));
228 228
229 EXPECT_EQ(0, unlink(lock_path_.value().c_str())); 229 EXPECT_EQ(0, unlink(lock_path_.value().c_str()));
230 EXPECT_EQ(0, symlink("FAKEFOOHOST-1234", lock_path_.value().c_str())); 230 EXPECT_EQ(0, symlink("FAKEFOOHOST-1234", lock_path_.value().c_str()));
231 231
232 std::string url("about:blank"); 232 std::string url("about:blank");
233 EXPECT_EQ(ProcessSingleton::PROFILE_IN_USE, 233 EXPECT_EQ(ProcessSingleton::PROFILE_IN_USE,
234 NotifyOtherProcess(url, action_timeout_ms())); 234 NotifyOtherProcess(url, TestTimeouts::action_timeout_ms()));
235 235
236 ASSERT_EQ(0, unlink(lock_path_.value().c_str())); 236 ASSERT_EQ(0, unlink(lock_path_.value().c_str()));
237 } 237 }
238 238
239 // Test that we fail when lock says process is on another host and we can't 239 // Test that we fail when lock says process is on another host and we can't
240 // notify it over the socket. 240 // notify it over the socket.
241 TEST_F(ProcessSingletonLinuxTest, NotifyOtherProcessOrCreate_DifferingHost) { 241 TEST_F(ProcessSingletonLinuxTest, NotifyOtherProcessOrCreate_DifferingHost) {
242 base::ProcessId pid = browser_process_id(); 242 base::ProcessId pid = browser_process_id();
243 243
244 ASSERT_GE(pid, 1); 244 ASSERT_GE(pid, 1);
245 245
246 // Kill the browser process, so that it does not respond on the socket. 246 // Kill the browser process, so that it does not respond on the socket.
247 kill(pid, SIGKILL); 247 kill(pid, SIGKILL);
248 // Wait for a while to make sure the browser process is actually killed. 248 // Wait for a while to make sure the browser process is actually killed.
249 EXPECT_FALSE(CrashAwareSleep(TestTimeouts::action_timeout_ms())); 249 EXPECT_FALSE(CrashAwareSleep(TestTimeouts::action_timeout_ms()));
250 250
251 EXPECT_EQ(0, unlink(lock_path_.value().c_str())); 251 EXPECT_EQ(0, unlink(lock_path_.value().c_str()));
252 EXPECT_EQ(0, symlink("FAKEFOOHOST-1234", lock_path_.value().c_str())); 252 EXPECT_EQ(0, symlink("FAKEFOOHOST-1234", lock_path_.value().c_str()));
253 253
254 std::string url("about:blank"); 254 std::string url("about:blank");
255 EXPECT_EQ(ProcessSingleton::PROFILE_IN_USE, 255 EXPECT_EQ(ProcessSingleton::PROFILE_IN_USE,
256 NotifyOtherProcessOrCreate(url, action_timeout_ms())); 256 NotifyOtherProcessOrCreate(url, TestTimeouts::action_timeout_ms()));
257 257
258 ASSERT_EQ(0, unlink(lock_path_.value().c_str())); 258 ASSERT_EQ(0, unlink(lock_path_.value().c_str()));
259 } 259 }
260 260
261 // Test that Create fails when another browser is using the profile directory. 261 // Test that Create fails when another browser is using the profile directory.
262 TEST_F(ProcessSingletonLinuxTest, CreateFailsWithExistingBrowser) { 262 TEST_F(ProcessSingletonLinuxTest, CreateFailsWithExistingBrowser) {
263 scoped_ptr<ProcessSingleton> process_singleton(CreateProcessSingleton()); 263 scoped_ptr<ProcessSingleton> process_singleton(CreateProcessSingleton());
264 EXPECT_FALSE(process_singleton->Create()); 264 EXPECT_FALSE(process_singleton->Create());
265 } 265 }
266 266
(...skipping 21 matching lines...) Expand all
288 // Change the cookie. 288 // Change the cookie.
289 EXPECT_EQ(0, unlink(cookie_path_.value().c_str())); 289 EXPECT_EQ(0, unlink(cookie_path_.value().c_str()));
290 EXPECT_EQ(0, symlink("INCORRECTCOOKIE", cookie_path_.value().c_str())); 290 EXPECT_EQ(0, symlink("INCORRECTCOOKIE", cookie_path_.value().c_str()));
291 291
292 // Also change the hostname, so the remote does not retry. 292 // Also change the hostname, so the remote does not retry.
293 EXPECT_EQ(0, unlink(lock_path_.value().c_str())); 293 EXPECT_EQ(0, unlink(lock_path_.value().c_str()));
294 EXPECT_EQ(0, symlink("FAKEFOOHOST-1234", lock_path_.value().c_str())); 294 EXPECT_EQ(0, symlink("FAKEFOOHOST-1234", lock_path_.value().c_str()));
295 295
296 std::string url("about:blank"); 296 std::string url("about:blank");
297 EXPECT_EQ(ProcessSingleton::PROFILE_IN_USE, 297 EXPECT_EQ(ProcessSingleton::PROFILE_IN_USE,
298 NotifyOtherProcessOrCreate(url, action_timeout_ms())); 298 NotifyOtherProcessOrCreate(url, TestTimeouts::action_timeout_ms()));
299 } 299 }
OLDNEW
« no previous file with comments | « no previous file | chrome/browser/tab_restore_uitest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698