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

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

Issue 2811173003: ProcessSingletonPosix: don't CHECK if trying to connect to existing process with too long socket sy… (Closed)
Patch Set: Created 3 years, 8 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
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 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 <fcntl.h> 7 #include <fcntl.h>
8 #include <limits.h> 8 #include <limits.h>
9 #include <signal.h> 9 #include <signal.h>
10 #include <stddef.h> 10 #include <stddef.h>
(...skipping 390 matching lines...) Expand 10 before | Expand all | Expand 10 after
401 EXPECT_EQ(0, symlink("INCORRECTCOOKIE", cookie_path_.value().c_str())); 401 EXPECT_EQ(0, symlink("INCORRECTCOOKIE", cookie_path_.value().c_str()));
402 402
403 // Also change the hostname, so the remote does not retry. 403 // Also change the hostname, so the remote does not retry.
404 EXPECT_EQ(0, unlink(lock_path_.value().c_str())); 404 EXPECT_EQ(0, unlink(lock_path_.value().c_str()));
405 EXPECT_EQ(0, symlink("FAKEFOOHOST-1234", lock_path_.value().c_str())); 405 EXPECT_EQ(0, symlink("FAKEFOOHOST-1234", lock_path_.value().c_str()));
406 406
407 std::string url("about:blank"); 407 std::string url("about:blank");
408 EXPECT_EQ(ProcessSingleton::PROFILE_IN_USE, NotifyOtherProcessOrCreate(url)); 408 EXPECT_EQ(ProcessSingleton::PROFILE_IN_USE, NotifyOtherProcessOrCreate(url));
409 } 409 }
410 410
411 TEST_F(ProcessSingletonPosixTest, IgnoreSocketSymlinkWithTooLongTarget) {
412 CreateProcessSingletonOnThread();
413 // Change the symlink to one with a too-long target.
414 char buf[PATH_MAX];
415 ssize_t len = readlink(socket_path_.value().c_str(), buf, PATH_MAX);
416 ASSERT_GT(len, 0);
417 base::FilePath socket_target_path = base::FilePath(std::string(buf, len));
418 base::FilePath long_socket_target_path = socket_target_path.DirName().Append(
419 std::string(sizeof(sockaddr_un::sun_path), 'b'));
420 ASSERT_EQ(0, unlink(socket_path_.value().c_str()));
421 ASSERT_EQ(0, symlink(long_socket_target_path.value().c_str(),
422 socket_path_.value().c_str()));
423
424 // A new ProcessSingleton should ignore the invalid socket path target.
425 std::string url("about:blank");
426 EXPECT_EQ(ProcessSingleton::PROCESS_NONE, NotifyOtherProcessOrCreate(url));
427 }
428
411 #if defined(OS_MACOSX) 429 #if defined(OS_MACOSX)
412 // Test that if there is an existing lock file, and we could not flock() 430 // Test that if there is an existing lock file, and we could not flock()
413 // it, then exit. 431 // it, then exit.
414 TEST_F(ProcessSingletonPosixTest, CreateRespectsOldMacLock) { 432 TEST_F(ProcessSingletonPosixTest, CreateRespectsOldMacLock) {
415 std::unique_ptr<TestableProcessSingleton> process_singleton( 433 std::unique_ptr<TestableProcessSingleton> process_singleton(
416 CreateProcessSingleton()); 434 CreateProcessSingleton());
417 base::ScopedFD lock_fd(HANDLE_EINTR( 435 base::ScopedFD lock_fd(HANDLE_EINTR(
418 open(lock_path_.value().c_str(), O_RDWR | O_CREAT | O_EXLOCK, 0644))); 436 open(lock_path_.value().c_str(), O_RDWR | O_CREAT | O_EXLOCK, 0644)));
419 ASSERT_TRUE(lock_fd.is_valid()); 437 ASSERT_TRUE(lock_fd.is_valid());
420 EXPECT_FALSE(process_singleton->Create()); 438 EXPECT_FALSE(process_singleton->Create());
421 base::File::Info info; 439 base::File::Info info;
422 EXPECT_TRUE(base::GetFileInfo(lock_path_, &info)); 440 EXPECT_TRUE(base::GetFileInfo(lock_path_, &info));
423 EXPECT_FALSE(info.is_directory); 441 EXPECT_FALSE(info.is_directory);
424 EXPECT_FALSE(info.is_symbolic_link); 442 EXPECT_FALSE(info.is_symbolic_link);
425 } 443 }
426 444
427 // Test that if there is an existing lock file, and it's not locked, we replace 445 // Test that if there is an existing lock file, and it's not locked, we replace
428 // it. 446 // it.
429 TEST_F(ProcessSingletonPosixTest, CreateReplacesOldMacLock) { 447 TEST_F(ProcessSingletonPosixTest, CreateReplacesOldMacLock) {
430 std::unique_ptr<TestableProcessSingleton> process_singleton( 448 std::unique_ptr<TestableProcessSingleton> process_singleton(
431 CreateProcessSingleton()); 449 CreateProcessSingleton());
432 EXPECT_EQ(0, base::WriteFile(lock_path_, "", 0)); 450 EXPECT_EQ(0, base::WriteFile(lock_path_, "", 0));
433 EXPECT_TRUE(process_singleton->Create()); 451 EXPECT_TRUE(process_singleton->Create());
434 VerifyFiles(); 452 VerifyFiles();
435 } 453 }
436 #endif // defined(OS_MACOSX) 454 #endif // defined(OS_MACOSX)
OLDNEW
« chrome/browser/process_singleton_posix.cc ('K') | « chrome/browser/process_singleton_posix.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698