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

Side by Side Diff: chromeos/process_proxy/process_proxy_unittest.cc

Issue 15774005: chromeos: Use base::MessageLoop. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: rebase Created 7 years, 6 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 | « chromeos/power/power_manager_handler_unittest.cc ('k') | no next file » | 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) 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 <gtest/gtest.h> 5 #include <gtest/gtest.h>
6 6
7 #include <string> 7 #include <string>
8 #include <sys/wait.h> 8 #include <sys/wait.h>
9 9
10 #include "base/bind.h" 10 #include "base/bind.h"
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after
70 bool valid = true; 70 bool valid = true;
71 for (size_t i = 0; i < output.length(); i++) { 71 for (size_t i = 0; i < output.length(); i++) {
72 // The character output[i] should be next in at least one of the lines we 72 // The character output[i] should be next in at least one of the lines we
73 // are testing. 73 // are testing.
74 valid = (ProcessReceivedCharacter(output[i], 0) || 74 valid = (ProcessReceivedCharacter(output[i], 0) ||
75 ProcessReceivedCharacter(output[i], 1)); 75 ProcessReceivedCharacter(output[i], 1));
76 EXPECT_TRUE(valid) << "Received: " << output; 76 EXPECT_TRUE(valid) << "Received: " << output;
77 } 77 }
78 78
79 if (!valid || TestSucceeded()) { 79 if (!valid || TestSucceeded()) {
80 MessageLoop::current()->PostTask(FROM_HERE, 80 base::MessageLoop::current()->PostTask(FROM_HERE,
81 MessageLoop::QuitClosure()); 81 base::MessageLoop::QuitClosure());
82 } 82 }
83 } 83 }
84 84
85 virtual void StartRegistryTest(ProcessProxyRegistry* registry) OVERRIDE { 85 virtual void StartRegistryTest(ProcessProxyRegistry* registry) OVERRIDE {
86 for (int i = 0; i < kTestLineNum; i++) { 86 for (int i = 0; i < kTestLineNum; i++) {
87 EXPECT_TRUE(registry->SendInput(pid_, kTestLineToSend)); 87 EXPECT_TRUE(registry->SendInput(pid_, kTestLineToSend));
88 } 88 }
89 } 89 }
90 90
91 private: 91 private:
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
130 const std::string& output) OVERRIDE { 130 const std::string& output) OVERRIDE {
131 EXPECT_EQ(pid_, pid); 131 EXPECT_EQ(pid_, pid);
132 if (!output_received_) { 132 if (!output_received_) {
133 output_received_ = true; 133 output_received_ = true;
134 EXPECT_EQ(type, "stdout"); 134 EXPECT_EQ(type, "stdout");
135 EXPECT_EQ(output, "p"); 135 EXPECT_EQ(output, "p");
136 base::KillProcess(pid_, 0 , true); 136 base::KillProcess(pid_, 0 , true);
137 return; 137 return;
138 } 138 }
139 EXPECT_EQ("exit", type); 139 EXPECT_EQ("exit", type);
140 MessageLoop::current()->PostTask(FROM_HERE, 140 base::MessageLoop::current()->PostTask(FROM_HERE,
141 MessageLoop::QuitClosure()); 141 base::MessageLoop::QuitClosure());
142 } 142 }
143 143
144 virtual void StartRegistryTest(ProcessProxyRegistry* registry) OVERRIDE { 144 virtual void StartRegistryTest(ProcessProxyRegistry* registry) OVERRIDE {
145 EXPECT_TRUE(registry->SendInput(pid_, "p")); 145 EXPECT_TRUE(registry->SendInput(pid_, "p"));
146 } 146 }
147 147
148 private: 148 private:
149 bool output_received_; 149 bool output_received_;
150 }; 150 };
151 151
152 class SigIntTestRunner : public TestRunner { 152 class SigIntTestRunner : public TestRunner {
153 public: 153 public:
154 virtual ~SigIntTestRunner() {} 154 virtual ~SigIntTestRunner() {}
155 155
156 virtual void SetupExpectations(pid_t pid) OVERRIDE { 156 virtual void SetupExpectations(pid_t pid) OVERRIDE {
157 pid_ = pid; 157 pid_ = pid;
158 } 158 }
159 159
160 virtual void OnSomeRead(pid_t pid, const std::string& type, 160 virtual void OnSomeRead(pid_t pid, const std::string& type,
161 const std::string& output) OVERRIDE { 161 const std::string& output) OVERRIDE {
162 EXPECT_EQ(pid_, pid); 162 EXPECT_EQ(pid_, pid);
163 // We may receive ^C on stdout, but we don't care about that, as long as we 163 // We may receive ^C on stdout, but we don't care about that, as long as we
164 // eventually received exit event. 164 // eventually received exit event.
165 if (type == "exit") { 165 if (type == "exit") {
166 MessageLoop::current()->PostTask(FROM_HERE, 166 base::MessageLoop::current()->PostTask(FROM_HERE,
167 MessageLoop::QuitClosure()); 167 base::MessageLoop::QuitClosure());
168 } 168 }
169 } 169 }
170 170
171 virtual void StartRegistryTest(ProcessProxyRegistry* registry) OVERRIDE { 171 virtual void StartRegistryTest(ProcessProxyRegistry* registry) OVERRIDE {
172 // Send SingInt and verify the process exited. 172 // Send SingInt and verify the process exited.
173 EXPECT_TRUE(registry->SendInput(pid_, "\003")); 173 EXPECT_TRUE(registry->SendInput(pid_, "\003"));
174 } 174 }
175 }; 175 };
176 176
177 } // namespace 177 } // namespace
(...skipping 17 matching lines...) Expand all
195 } 195 }
196 196
197 void EndRegistryTest() { 197 void EndRegistryTest() {
198 registry_->CloseProcess(pid_); 198 registry_->CloseProcess(pid_);
199 199
200 base::TerminationStatus status = base::GetTerminationStatus(pid_, NULL); 200 base::TerminationStatus status = base::GetTerminationStatus(pid_, NULL);
201 EXPECT_NE(base::TERMINATION_STATUS_STILL_RUNNING, status); 201 EXPECT_NE(base::TERMINATION_STATUS_STILL_RUNNING, status);
202 if (status == base::TERMINATION_STATUS_STILL_RUNNING) 202 if (status == base::TERMINATION_STATUS_STILL_RUNNING)
203 base::KillProcess(pid_, 0, true); 203 base::KillProcess(pid_, 0, true);
204 204
205 MessageLoop::current()->PostTask(FROM_HERE, 205 base::MessageLoop::current()->PostTask(FROM_HERE,
206 MessageLoop::QuitClosure()); 206 base::MessageLoop::QuitClosure());
207 } 207 }
208 208
209 void RunTest() { 209 void RunTest() {
210 MessageLoop::current()->PostTask( 210 base::MessageLoop::current()->PostTask(
211 FROM_HERE, 211 FROM_HERE,
212 base::Bind(&ProcessProxyTest::InitRegistryTest, 212 base::Bind(&ProcessProxyTest::InitRegistryTest,
213 base::Unretained(this))); 213 base::Unretained(this)));
214 214
215 // Wait until all data from output watcher is received (QuitTask will be 215 // Wait until all data from output watcher is received (QuitTask will be
216 // fired on watcher thread). 216 // fired on watcher thread).
217 MessageLoop::current()->Run(); 217 base::MessageLoop::current()->Run();
218 218
219 MessageLoop::current()->PostTask( 219 base::MessageLoop::current()->PostTask(
220 FROM_HERE, 220 FROM_HERE,
221 base::Bind(&ProcessProxyTest::EndRegistryTest, 221 base::Bind(&ProcessProxyTest::EndRegistryTest,
222 base::Unretained(this))); 222 base::Unretained(this)));
223 223
224 // Wait until we clean up the process proxy. 224 // Wait until we clean up the process proxy.
225 MessageLoop::current()->Run(); 225 base::MessageLoop::current()->Run();
226 } 226 }
227 227
228 scoped_ptr<TestRunner> test_runner_; 228 scoped_ptr<TestRunner> test_runner_;
229 229
230 private: 230 private:
231 ProcessProxyRegistry* registry_; 231 ProcessProxyRegistry* registry_;
232 pid_t pid_; 232 pid_t pid_;
233 233
234 MessageLoop message_loop_; 234 base::MessageLoop message_loop_;
235 }; 235 };
236 236
237 // Test will open new process that will run cat command, and verify data we 237 // Test will open new process that will run cat command, and verify data we
238 // write to process gets echoed back. 238 // write to process gets echoed back.
239 TEST_F(ProcessProxyTest, RegistryTest) { 239 TEST_F(ProcessProxyTest, RegistryTest) {
240 test_runner_.reset(new RegistryTestRunner()); 240 test_runner_.reset(new RegistryTestRunner());
241 RunTest(); 241 RunTest();
242 } 242 }
243 243
244 // Open new process, then kill it. Verifiy that we detect when the process dies. 244 // Open new process, then kill it. Verifiy that we detect when the process dies.
245 TEST_F(ProcessProxyTest, RegistryNotifiedOnProcessExit) { 245 TEST_F(ProcessProxyTest, RegistryNotifiedOnProcessExit) {
246 test_runner_.reset(new RegistryNotifiedOnProcessExitTestRunner()); 246 test_runner_.reset(new RegistryNotifiedOnProcessExitTestRunner());
247 RunTest(); 247 RunTest();
248 } 248 }
249 249
250 // Test verifies that \003 message send to process is processed as SigInt. 250 // Test verifies that \003 message send to process is processed as SigInt.
251 // Timing out on the waterfall: http://crbug.com/115064 251 // Timing out on the waterfall: http://crbug.com/115064
252 TEST_F(ProcessProxyTest, DISABLED_SigInt) { 252 TEST_F(ProcessProxyTest, DISABLED_SigInt) {
253 test_runner_.reset(new SigIntTestRunner()); 253 test_runner_.reset(new SigIntTestRunner());
254 RunTest(); 254 RunTest();
255 } 255 }
256 256
257 } // namespace chromeos 257 } // namespace chromeos
OLDNEW
« no previous file with comments | « chromeos/power/power_manager_handler_unittest.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698