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

Side by Side Diff: chrome/browser/extensions/api/messaging/native_message_process_host_unittest_posix.cc

Issue 11413050: chrome/browser: Update calls from RunAllPending() to RunUntilIdle(). (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 8 years, 1 month 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
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 "base/bind.h" 5 #include "base/bind.h"
6 #include "base/command_line.h" 6 #include "base/command_line.h"
7 #include "base/file_path.h" 7 #include "base/file_path.h"
8 #include "base/file_util.h" 8 #include "base/file_util.h"
9 #include "base/memory/scoped_ptr.h" 9 #include "base/memory/scoped_ptr.h"
10 #include "base/memory/weak_ptr.h" 10 #include "base/memory/weak_ptr.h"
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after
84 &message_loop_)); 84 &message_loop_));
85 file_thread_.reset(new content::TestBrowserThread(BrowserThread::FILE, 85 file_thread_.reset(new content::TestBrowserThread(BrowserThread::FILE,
86 &message_loop_)); 86 &message_loop_));
87 } 87 }
88 88
89 virtual void TearDown() { 89 virtual void TearDown() {
90 // Change the user data dir back for other tests. 90 // Change the user data dir back for other tests.
91 ASSERT_TRUE(PathService::Override(chrome::DIR_USER_DATA, user_data_dir_)); 91 ASSERT_TRUE(PathService::Override(chrome::DIR_USER_DATA, user_data_dir_));
92 BrowserThread::DeleteSoon(BrowserThread::FILE, FROM_HERE, 92 BrowserThread::DeleteSoon(BrowserThread::FILE, FROM_HERE,
93 native_message_process_host_); 93 native_message_process_host_);
94 message_loop_.RunAllPending(); 94 message_loop_.RunUntilIdle();
95 } 95 }
96 96
97 void PostMessageFromNativeProcess(int port_id, const std::string& message) { 97 void PostMessageFromNativeProcess(int port_id, const std::string& message) {
98 last_posted_message_ = message; 98 last_posted_message_ = message;
99 } 99 }
100 100
101 void CloseChannel(int port_id, bool error) { 101 void CloseChannel(int port_id, bool error) {
102 } 102 }
103 103
104 void AcquireProcess(NativeMessageProcessHost::ScopedHost process) { 104 void AcquireProcess(NativeMessageProcessHost::ScopedHost process) {
(...skipping 15 matching lines...) Expand all
120 TEST_F(NativeMessagingTest, SingleSendMessageRead) { 120 TEST_F(NativeMessagingTest, SingleSendMessageRead) {
121 FilePath temp_file; 121 FilePath temp_file;
122 file_util::CreateTemporaryFile(&temp_file); 122 file_util::CreateTemporaryFile(&temp_file);
123 FakeLauncher launcher(GetTestDir().AppendASCII("single_message_response.msg"), 123 FakeLauncher launcher(GetTestDir().AppendASCII("single_message_response.msg"),
124 temp_file); 124 temp_file);
125 NativeMessageProcessHost::CreateWithLauncher( 125 NativeMessageProcessHost::CreateWithLauncher(
126 AsWeakPtr(), "empty_app.py", "{}", 0, 126 AsWeakPtr(), "empty_app.py", "{}", 0,
127 NativeMessageProcessHost::TYPE_SEND_MESSAGE_REQUEST, base::Bind( 127 NativeMessageProcessHost::TYPE_SEND_MESSAGE_REQUEST, base::Bind(
128 &NativeMessagingTest::AcquireProcess, AsWeakPtr()), 128 &NativeMessagingTest::AcquireProcess, AsWeakPtr()),
129 launcher); 129 launcher);
130 message_loop_.RunAllPending(); 130 message_loop_.RunUntilIdle();
131 ASSERT_TRUE(native_message_process_host_); 131 ASSERT_TRUE(native_message_process_host_);
132 native_message_process_host_->ReadNowForTesting(); 132 native_message_process_host_->ReadNowForTesting();
133 message_loop_.RunAllPending(); 133 message_loop_.RunUntilIdle();
134 EXPECT_EQ(last_posted_message_, "{\"text\": \"Hi There!.\"}"); 134 EXPECT_EQ(last_posted_message_, "{\"text\": \"Hi There!.\"}");
135 file_util::Delete(temp_file, false /* non-recursive */); 135 file_util::Delete(temp_file, false /* non-recursive */);
136 } 136 }
137 137
138 // Tests sending a single message. The message should get written to 138 // Tests sending a single message. The message should get written to
139 // |temp_file| and should match the contents of single_message_request.msg. 139 // |temp_file| and should match the contents of single_message_request.msg.
140 TEST_F(NativeMessagingTest, SingleSendMessageWrite) { 140 TEST_F(NativeMessagingTest, SingleSendMessageWrite) {
141 FilePath temp_file; 141 FilePath temp_file;
142 file_util::CreateTemporaryFile(&temp_file); 142 file_util::CreateTemporaryFile(&temp_file);
143 FakeLauncher launcher(GetTestDir().AppendASCII("single_message_response.msg"), 143 FakeLauncher launcher(GetTestDir().AppendASCII("single_message_response.msg"),
144 temp_file); 144 temp_file);
145 NativeMessageProcessHost::CreateWithLauncher( 145 NativeMessageProcessHost::CreateWithLauncher(
146 AsWeakPtr(), "empty_app.py", "{\"text\": \"Hello.\"}", 0, 146 AsWeakPtr(), "empty_app.py", "{\"text\": \"Hello.\"}", 0,
147 NativeMessageProcessHost::TYPE_SEND_MESSAGE_REQUEST, base::Bind( 147 NativeMessageProcessHost::TYPE_SEND_MESSAGE_REQUEST, base::Bind(
148 &NativeMessagingTest::AcquireProcess, AsWeakPtr()), 148 &NativeMessagingTest::AcquireProcess, AsWeakPtr()),
149 launcher); 149 launcher);
150 message_loop_.RunAllPending(); 150 message_loop_.RunUntilIdle();
151 ASSERT_TRUE(native_message_process_host_); 151 ASSERT_TRUE(native_message_process_host_);
152 152
153 EXPECT_TRUE(file_util::ContentsEqual( 153 EXPECT_TRUE(file_util::ContentsEqual(
154 temp_file, GetTestDir().AppendASCII("single_message_request.msg"))); 154 temp_file, GetTestDir().AppendASCII("single_message_request.msg")));
155 155
156 file_util::Delete(temp_file, false /* non-recursive */); 156 file_util::Delete(temp_file, false /* non-recursive */);
157 } 157 }
158 158
159 // Disabled, see http://crbug.com/159754. 159 // Disabled, see http://crbug.com/159754.
160 // Test send message with a real client. The client just echo's back the text 160 // Test send message with a real client. The client just echo's back the text
161 // it recieved. 161 // it recieved.
162 TEST_F(NativeMessagingTest, DISABLED_EchoConnect) { 162 TEST_F(NativeMessagingTest, DISABLED_EchoConnect) {
163 NativeMessageProcessHost::Create( 163 NativeMessageProcessHost::Create(
164 AsWeakPtr(), "echo.py", "{\"text\": \"Hello.\"}", 0, 164 AsWeakPtr(), "echo.py", "{\"text\": \"Hello.\"}", 0,
165 NativeMessageProcessHost::TYPE_CONNECT, base::Bind( 165 NativeMessageProcessHost::TYPE_CONNECT, base::Bind(
166 &NativeMessagingTest::AcquireProcess, AsWeakPtr())); 166 &NativeMessagingTest::AcquireProcess, AsWeakPtr()));
167 message_loop_.RunAllPending(); 167 message_loop_.RunUntilIdle();
168 ASSERT_TRUE(native_message_process_host_); 168 ASSERT_TRUE(native_message_process_host_);
169 169
170 native_message_process_host_->ReadNowForTesting(); 170 native_message_process_host_->ReadNowForTesting();
171 message_loop_.RunAllPending(); 171 message_loop_.RunUntilIdle();
172 EXPECT_EQ(last_posted_message_, 172 EXPECT_EQ(last_posted_message_,
173 "{\"id\": 1, \"echo\": {\"text\": \"Hello.\"}}"); 173 "{\"id\": 1, \"echo\": {\"text\": \"Hello.\"}}");
174 174
175 native_message_process_host_->Send("{\"foo\": \"bar\"}"); 175 native_message_process_host_->Send("{\"foo\": \"bar\"}");
176 message_loop_.RunAllPending(); 176 message_loop_.RunUntilIdle();
177 native_message_process_host_->ReadNowForTesting(); 177 native_message_process_host_->ReadNowForTesting();
178 message_loop_.RunAllPending(); 178 message_loop_.RunUntilIdle();
179 EXPECT_EQ(last_posted_message_, "{\"id\": 2, \"echo\": {\"foo\": \"bar\"}}"); 179 EXPECT_EQ(last_posted_message_, "{\"id\": 2, \"echo\": {\"foo\": \"bar\"}}");
180 } 180 }
181 181
182 } // namespace extensions 182 } // namespace extensions
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698