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

Side by Side Diff: jingle/glue/thread_wrapper_unittest.cc

Issue 2028993003: Migrate WaitableEvent to enum-based constructor in jingle/ (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@WEvent_enums
Patch Set: Created 4 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
« no previous file with comments | « jingle/glue/thread_wrapper.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 <stdint.h> 5 #include <stdint.h>
6 6
7 #include "base/bind.h" 7 #include "base/bind.h"
8 #include "base/compiler_specific.h" 8 #include "base/compiler_specific.h"
9 #include "base/message_loop/message_loop.h" 9 #include "base/message_loop/message_loop.h"
10 #include "base/threading/thread.h" 10 #include "base/threading/thread.h"
(...skipping 228 matching lines...) Expand 10 before | Expand all | Expand 10 after
239 } 239 }
240 240
241 // Verify that Send() calls handler synchronously when called for a 241 // Verify that Send() calls handler synchronously when called for a
242 // different thread. 242 // different thread.
243 TEST_F(ThreadWrapperTest, SendToOtherThread) { 243 TEST_F(ThreadWrapperTest, SendToOtherThread) {
244 JingleThreadWrapper::current()->set_send_allowed(true); 244 JingleThreadWrapper::current()->set_send_allowed(true);
245 245
246 base::Thread second_thread("JingleThreadWrapperTest"); 246 base::Thread second_thread("JingleThreadWrapperTest");
247 second_thread.Start(); 247 second_thread.Start();
248 248
249 base::WaitableEvent initialized_event(true, false); 249 base::WaitableEvent initialized_event(
250 base::WaitableEvent::ResetPolicy::MANUAL,
251 base::WaitableEvent::InitialState::NOT_SIGNALED);
250 rtc::Thread* target; 252 rtc::Thread* target;
251 second_thread.message_loop()->PostTask( 253 second_thread.message_loop()->PostTask(
252 FROM_HERE, base::Bind(&InitializeWrapperForNewThread, 254 FROM_HERE, base::Bind(&InitializeWrapperForNewThread,
253 &target, &initialized_event)); 255 &target, &initialized_event));
254 initialized_event.Wait(); 256 initialized_event.Wait();
255 257
256 ASSERT_TRUE(target != NULL); 258 ASSERT_TRUE(target != NULL);
257 259
258 rtc::MessageData* data = new rtc::MessageData(); 260 rtc::MessageData* data = new rtc::MessageData();
259 261
260 EXPECT_CALL(handler1_, OnMessage( 262 EXPECT_CALL(handler1_, OnMessage(
261 MatchMessage(&handler1_, kTestMessage1, data))) 263 MatchMessage(&handler1_, kTestMessage1, data)))
262 .WillOnce(DeleteMessageData()); 264 .WillOnce(DeleteMessageData());
263 target->Send(&handler1_, kTestMessage1, data); 265 target->Send(&handler1_, kTestMessage1, data);
264 266
265 Mock::VerifyAndClearExpectations(&handler1_); 267 Mock::VerifyAndClearExpectations(&handler1_);
266 } 268 }
267 269
268 // Verify that thread handles Send() while another Send() is 270 // Verify that thread handles Send() while another Send() is
269 // pending. The test creates second thread and Send()s kTestMessage1 271 // pending. The test creates second thread and Send()s kTestMessage1
270 // to that thread. kTestMessage1 handler calls PingMainThread() which 272 // to that thread. kTestMessage1 handler calls PingMainThread() which
271 // tries to Send() kTestMessage2 to the main thread. 273 // tries to Send() kTestMessage2 to the main thread.
272 TEST_F(ThreadWrapperTest, SendDuringSend) { 274 TEST_F(ThreadWrapperTest, SendDuringSend) {
273 JingleThreadWrapper::current()->set_send_allowed(true); 275 JingleThreadWrapper::current()->set_send_allowed(true);
274 276
275 base::Thread second_thread("JingleThreadWrapperTest"); 277 base::Thread second_thread("JingleThreadWrapperTest");
276 second_thread.Start(); 278 second_thread.Start();
277 279
278 base::WaitableEvent initialized_event(true, false); 280 base::WaitableEvent initialized_event(
281 base::WaitableEvent::ResetPolicy::MANUAL,
282 base::WaitableEvent::InitialState::NOT_SIGNALED);
279 rtc::Thread* target; 283 rtc::Thread* target;
280 second_thread.message_loop()->PostTask( 284 second_thread.message_loop()->PostTask(
281 FROM_HERE, base::Bind(&InitializeWrapperForNewThread, 285 FROM_HERE, base::Bind(&InitializeWrapperForNewThread,
282 &target, &initialized_event)); 286 &target, &initialized_event));
283 initialized_event.Wait(); 287 initialized_event.Wait();
284 288
285 ASSERT_TRUE(target != NULL); 289 ASSERT_TRUE(target != NULL);
286 290
287 rtc::MessageData* data = new rtc::MessageData(); 291 rtc::MessageData* data = new rtc::MessageData();
288 292
(...skipping 10 matching lines...) Expand all
299 303
300 TEST_F(ThreadWrapperTest, Dispose) { 304 TEST_F(ThreadWrapperTest, Dispose) {
301 bool deleted_ = false; 305 bool deleted_ = false;
302 thread_->Dispose(new DeletableObject(&deleted_)); 306 thread_->Dispose(new DeletableObject(&deleted_));
303 EXPECT_FALSE(deleted_); 307 EXPECT_FALSE(deleted_);
304 message_loop_.RunUntilIdle(); 308 message_loop_.RunUntilIdle();
305 EXPECT_TRUE(deleted_); 309 EXPECT_TRUE(deleted_);
306 } 310 }
307 311
308 } // namespace jingle_glue 312 } // namespace jingle_glue
OLDNEW
« no previous file with comments | « jingle/glue/thread_wrapper.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698