OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 <signal.h> | 7 #include <signal.h> |
8 #include <sys/types.h> | 8 #include <sys/types.h> |
9 #include <sys/wait.h> | 9 #include <sys/wait.h> |
10 #include <unistd.h> | 10 #include <unistd.h> |
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
80 // Put the lock in a temporary directory. Doesn't need to be a | 80 // Put the lock in a temporary directory. Doesn't need to be a |
81 // full profile to test this code. | 81 // full profile to test this code. |
82 ASSERT_TRUE(temp_dir_.CreateUniqueTempDir()); | 82 ASSERT_TRUE(temp_dir_.CreateUniqueTempDir()); |
83 lock_path_ = temp_dir_.path().Append(chrome::kSingletonLockFilename); | 83 lock_path_ = temp_dir_.path().Append(chrome::kSingletonLockFilename); |
84 socket_path_ = temp_dir_.path().Append(chrome::kSingletonSocketFilename); | 84 socket_path_ = temp_dir_.path().Append(chrome::kSingletonSocketFilename); |
85 cookie_path_ = temp_dir_.path().Append(chrome::kSingletonCookieFilename); | 85 cookie_path_ = temp_dir_.path().Append(chrome::kSingletonCookieFilename); |
86 } | 86 } |
87 | 87 |
88 virtual void TearDown() { | 88 virtual void TearDown() { |
89 scoped_refptr<base::ThreadTestHelper> io_helper(new base::ThreadTestHelper( | 89 scoped_refptr<base::ThreadTestHelper> io_helper(new base::ThreadTestHelper( |
90 BrowserThread::GetMessageLoopProxyForThread(BrowserThread::IO))); | 90 BrowserThread::GetMessageLoopProxyForThread(BrowserThread::IO).get())); |
91 ASSERT_TRUE(io_helper->Run()); | 91 ASSERT_TRUE(io_helper->Run()); |
92 | 92 |
93 // Destruct the ProcessSingleton object before the IO thread so that its | 93 // Destruct the ProcessSingleton object before the IO thread so that its |
94 // internals are destructed properly. | 94 // internals are destructed properly. |
95 if (process_singleton_on_thread_) { | 95 if (process_singleton_on_thread_) { |
96 worker_thread_->message_loop()->PostTask( | 96 worker_thread_->message_loop()->PostTask( |
97 FROM_HERE, | 97 FROM_HERE, |
98 base::Bind(&ProcessSingletonLinuxTest::DestructProcessSingleton, | 98 base::Bind(&ProcessSingletonLinuxTest::DestructProcessSingleton, |
99 base::Unretained(this))); | 99 base::Unretained(this))); |
100 | 100 |
101 scoped_refptr<base::ThreadTestHelper> helper( | 101 scoped_refptr<base::ThreadTestHelper> helper(new base::ThreadTestHelper( |
102 new base::ThreadTestHelper(worker_thread_->message_loop_proxy())); | 102 worker_thread_->message_loop_proxy().get())); |
103 ASSERT_TRUE(helper->Run()); | 103 ASSERT_TRUE(helper->Run()); |
104 } | 104 } |
105 | 105 |
106 io_thread_.Stop(); | 106 io_thread_.Stop(); |
107 testing::Test::TearDown(); | 107 testing::Test::TearDown(); |
108 } | 108 } |
109 | 109 |
110 void CreateProcessSingletonOnThread() { | 110 void CreateProcessSingletonOnThread() { |
111 ASSERT_EQ(NULL, worker_thread_.get()); | 111 ASSERT_EQ(NULL, worker_thread_.get()); |
112 worker_thread_.reset(new base::Thread("BlockingThread")); | 112 worker_thread_.reset(new base::Thread("BlockingThread")); |
113 worker_thread_->Start(); | 113 worker_thread_->Start(); |
114 | 114 |
115 worker_thread_->message_loop()->PostTask( | 115 worker_thread_->message_loop()->PostTask( |
116 FROM_HERE, | 116 FROM_HERE, |
117 base::Bind(&ProcessSingletonLinuxTest:: | 117 base::Bind(&ProcessSingletonLinuxTest:: |
118 CreateProcessSingletonInternal, | 118 CreateProcessSingletonInternal, |
119 base::Unretained(this))); | 119 base::Unretained(this))); |
120 | 120 |
121 scoped_refptr<base::ThreadTestHelper> helper( | 121 scoped_refptr<base::ThreadTestHelper> helper( |
122 new base::ThreadTestHelper( | 122 new base::ThreadTestHelper(worker_thread_->message_loop_proxy().get())); |
123 worker_thread_->message_loop_proxy())); | |
124 ASSERT_TRUE(helper->Run()); | 123 ASSERT_TRUE(helper->Run()); |
125 } | 124 } |
126 | 125 |
127 TestableProcessSingleton* CreateProcessSingleton() { | 126 TestableProcessSingleton* CreateProcessSingleton() { |
128 return new TestableProcessSingleton(temp_dir_.path()); | 127 return new TestableProcessSingleton(temp_dir_.path()); |
129 } | 128 } |
130 | 129 |
131 ProcessSingleton::NotifyResult NotifyOtherProcess( | 130 ProcessSingleton::NotifyResult NotifyOtherProcess( |
132 bool override_kill, | 131 bool override_kill, |
133 base::TimeDelta timeout) { | 132 base::TimeDelta timeout) { |
(...skipping 257 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
391 | 390 |
392 // Also change the hostname, so the remote does not retry. | 391 // Also change the hostname, so the remote does not retry. |
393 EXPECT_EQ(0, unlink(lock_path_.value().c_str())); | 392 EXPECT_EQ(0, unlink(lock_path_.value().c_str())); |
394 EXPECT_EQ(0, symlink("FAKEFOOHOST-1234", lock_path_.value().c_str())); | 393 EXPECT_EQ(0, symlink("FAKEFOOHOST-1234", lock_path_.value().c_str())); |
395 | 394 |
396 std::string url("about:blank"); | 395 std::string url("about:blank"); |
397 EXPECT_EQ(ProcessSingleton::PROFILE_IN_USE, | 396 EXPECT_EQ(ProcessSingleton::PROFILE_IN_USE, |
398 NotifyOtherProcessOrCreate(url, TestTimeouts::action_timeout())); | 397 NotifyOtherProcessOrCreate(url, TestTimeouts::action_timeout())); |
399 } | 398 } |
400 | 399 |
OLD | NEW |