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 "base/bind.h" | 5 #include "base/bind.h" |
6 #include "base/file_util.h" | 6 #include "base/file_util.h" |
7 #include "base/files/file.h" | 7 #include "base/files/file.h" |
8 #include "base/files/file_path.h" | 8 #include "base/files/file_path.h" |
9 #include "base/files/scoped_file.h" | 9 #include "base/files/scoped_file.h" |
10 #include "base/files/scoped_temp_dir.h" | 10 #include "base/files/scoped_temp_dir.h" |
(...skipping 166 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
177 base::FilePath temp_output_file = temp_dir_.path().AppendASCII("output"); | 177 base::FilePath temp_output_file = temp_dir_.path().AppendASCII("output"); |
178 base::FilePath temp_input_file = CreateTempFileWithMessage(kTestMessage); | 178 base::FilePath temp_input_file = CreateTempFileWithMessage(kTestMessage); |
179 ASSERT_FALSE(temp_input_file.empty()); | 179 ASSERT_FALSE(temp_input_file.empty()); |
180 | 180 |
181 scoped_ptr<NativeProcessLauncher> launcher = | 181 scoped_ptr<NativeProcessLauncher> launcher = |
182 FakeLauncher::Create(temp_input_file, temp_output_file).Pass(); | 182 FakeLauncher::Create(temp_input_file, temp_output_file).Pass(); |
183 native_message_process_host_ = NativeMessageProcessHost::CreateWithLauncher( | 183 native_message_process_host_ = NativeMessageProcessHost::CreateWithLauncher( |
184 AsWeakPtr(), ScopedTestNativeMessagingHost::kExtensionId, "empty_app.py", | 184 AsWeakPtr(), ScopedTestNativeMessagingHost::kExtensionId, "empty_app.py", |
185 0, launcher.Pass()); | 185 0, launcher.Pass()); |
186 ASSERT_TRUE(native_message_process_host_.get()); | 186 ASSERT_TRUE(native_message_process_host_.get()); |
| 187 native_message_process_host_->DontWaitToReadForTesting(); |
187 run_loop_.reset(new base::RunLoop()); | 188 run_loop_.reset(new base::RunLoop()); |
188 run_loop_->RunUntilIdle(); | 189 run_loop_->Run(); |
189 | 190 |
190 if (last_message_.empty()) { | |
191 run_loop_.reset(new base::RunLoop()); | |
192 native_message_process_host_->ReadNowForTesting(); | |
193 run_loop_->Run(); | |
194 } | |
195 EXPECT_EQ(kTestMessage, last_message_); | 191 EXPECT_EQ(kTestMessage, last_message_); |
196 } | 192 } |
197 | 193 |
198 // Tests sending a single message. The message should get written to | 194 // Tests sending a single message. The message should get written to |
199 // |temp_file| and should match the contents of single_message_request.msg. | 195 // |temp_file| and should match the contents of single_message_request.msg. |
200 TEST_F(NativeMessagingTest, SingleSendMessageWrite) { | 196 TEST_F(NativeMessagingTest, SingleSendMessageWrite) { |
201 base::FilePath temp_output_file = temp_dir_.path().AppendASCII("output"); | 197 base::FilePath temp_output_file = temp_dir_.path().AppendASCII("output"); |
202 | 198 |
203 base::File read_file; | 199 base::File read_file; |
204 #if defined(OS_WIN) | 200 #if defined(OS_WIN) |
(...skipping 107 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
312 ScopedTestNativeMessagingHost::kHostName, 0, false); | 308 ScopedTestNativeMessagingHost::kHostName, 0, false); |
313 ASSERT_TRUE(native_message_process_host_.get()); | 309 ASSERT_TRUE(native_message_process_host_.get()); |
314 run_loop_.reset(new base::RunLoop()); | 310 run_loop_.reset(new base::RunLoop()); |
315 run_loop_->Run(); | 311 run_loop_->Run(); |
316 | 312 |
317 // The host should fail to start. | 313 // The host should fail to start. |
318 ASSERT_TRUE(channel_closed_); | 314 ASSERT_TRUE(channel_closed_); |
319 } | 315 } |
320 | 316 |
321 } // namespace extensions | 317 } // namespace extensions |
OLD | NEW |