| OLD | NEW | 
|    1 /* |    1 /* | 
|    2  *  Copyright (c) 2012 The WebRTC project authors. All Rights Reserved. |    2  *  Copyright (c) 2012 The WebRTC project authors. All Rights Reserved. | 
|    3  * |    3  * | 
|    4  *  Use of this source code is governed by a BSD-style license |    4  *  Use of this source code is governed by a BSD-style license | 
|    5  *  that can be found in the LICENSE file in the root of the source |    5  *  that can be found in the LICENSE file in the root of the source | 
|    6  *  tree. An additional intellectual property rights grant can be found |    6  *  tree. An additional intellectual property rights grant can be found | 
|    7  *  in the file PATENTS.  All contributing project authors may |    7  *  in the file PATENTS.  All contributing project authors may | 
|    8  *  be found in the AUTHORS file in the root of the source tree. |    8  *  be found in the AUTHORS file in the root of the source tree. | 
|    9  */ |    9  */ | 
|   10  |   10  | 
| (...skipping 233 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
|  244 // Tests that we can wake up the worker thread to give us a callback right |  244 // Tests that we can wake up the worker thread to give us a callback right | 
|  245 // away when we know the thread is sleeping. |  245 // away when we know the thread is sleeping. | 
|  246 TEST(ProcessThreadImpl, WakeUp) { |  246 TEST(ProcessThreadImpl, WakeUp) { | 
|  247   ProcessThreadImpl thread("ProcessThread"); |  247   ProcessThreadImpl thread("ProcessThread"); | 
|  248   thread.Start(); |  248   thread.Start(); | 
|  249  |  249  | 
|  250   rtc::scoped_ptr<EventWrapper> started(EventWrapper::Create()); |  250   rtc::scoped_ptr<EventWrapper> started(EventWrapper::Create()); | 
|  251   rtc::scoped_ptr<EventWrapper> called(EventWrapper::Create()); |  251   rtc::scoped_ptr<EventWrapper> called(EventWrapper::Create()); | 
|  252  |  252  | 
|  253   MockModule module; |  253   MockModule module; | 
|  254   int64_t start_time; |  254   int64_t start_time = 0; | 
|  255   int64_t called_time; |  255   int64_t called_time = 0; | 
|  256  |  | 
|  257   // Ask for a callback after 1000ms. |  256   // Ask for a callback after 1000ms. | 
|  258   // TimeUntilNextProcess will be called twice. |  257   // TimeUntilNextProcess will be called twice. | 
|  259   // The first time we use it to get the thread into a waiting state. |  258   // The first time we use it to get the thread into a waiting state. | 
|  260   // Then we  wake the thread and there should not be another call made to |  259   // Then we  wake the thread and there should not be another call made to | 
|  261   // TimeUntilNextProcess before Process() is called. |  260   // TimeUntilNextProcess before Process() is called. | 
|  262   // The second time TimeUntilNextProcess is then called, is after Process |  261   // The second time TimeUntilNextProcess is then called, is after Process | 
|  263   // has been called and we don't expect any more calls. |  262   // has been called and we don't expect any more calls. | 
|  264   EXPECT_CALL(module, TimeUntilNextProcess()) |  263   EXPECT_CALL(module, TimeUntilNextProcess()) | 
|  265       .WillOnce(DoAll(SetTimestamp(&start_time), |  264       .WillOnce(DoAll(SetTimestamp(&start_time), | 
|  266                       SetEvent(started.get()), |  265                       SetEvent(started.get()), | 
|  267                       Return(1000))) |  266                       Return(1000))) | 
|  268       .WillOnce(Return(1000)); |  267       .WillOnce(Return(1000)); | 
|  269   EXPECT_CALL(module, Process()) |  268   EXPECT_CALL(module, Process()) | 
|  270       .WillOnce(DoAll(SetTimestamp(&called_time), |  269       .WillOnce(DoAll(SetTimestamp(&called_time), | 
|  271                       SetEvent(called.get()), |  270                       SetEvent(called.get()), | 
|  272                       Return(0))) |  271                       Return(0))) | 
|  273       .WillRepeatedly(Return(0)); |  272       .WillRepeatedly(Return(0)); | 
|  274  |  273  | 
|  275   EXPECT_CALL(module, ProcessThreadAttached(&thread)).Times(1); |  274   EXPECT_CALL(module, ProcessThreadAttached(&thread)).Times(1); | 
|  276   thread.RegisterModule(&module); |  275   thread.RegisterModule(&module); | 
|  277  |  276  | 
|  278   EXPECT_EQ(kEventSignaled, started->Wait(100)); |  277   EXPECT_EQ(kEventSignaled, started->Wait(100)); | 
|  279   thread.WakeUp(&module); |  278   thread.WakeUp(&module); | 
|  280   EXPECT_EQ(kEventSignaled, called->Wait(100)); |  279   EXPECT_EQ(kEventSignaled, called->Wait(100)); | 
|  281  |  280  | 
|  282   EXPECT_CALL(module, ProcessThreadAttached(nullptr)).Times(1); |  281   EXPECT_CALL(module, ProcessThreadAttached(nullptr)).Times(1); | 
|  283   thread.Stop(); |  282   thread.Stop(); | 
|  284  |  283  | 
 |  284   ASSERT_GT(start_time, 0); | 
 |  285   ASSERT_GT(called_time, 0); | 
|  285   EXPECT_GE(called_time, start_time); |  286   EXPECT_GE(called_time, start_time); | 
|  286   uint32_t diff = called_time - start_time; |  287   uint32_t diff = called_time - start_time; | 
|  287   // We should have been called back much quicker than 1sec. |  288   // We should have been called back much quicker than 1sec. | 
|  288   EXPECT_LE(diff, 100u); |  289   EXPECT_LE(diff, 100u); | 
|  289 } |  290 } | 
|  290  |  291  | 
|  291 // Tests that we can post a task that gets run straight away on the worker |  292 // Tests that we can post a task that gets run straight away on the worker | 
|  292 // thread. |  293 // thread. | 
|  293 TEST(ProcessThreadImpl, PostTask) { |  294 TEST(ProcessThreadImpl, PostTask) { | 
|  294   ProcessThreadImpl thread("ProcessThread"); |  295   ProcessThreadImpl thread("ProcessThread"); | 
|  295   rtc::scoped_ptr<EventWrapper> task_ran(EventWrapper::Create()); |  296   rtc::scoped_ptr<EventWrapper> task_ran(EventWrapper::Create()); | 
|  296   rtc::scoped_ptr<RaiseEventTask> task(new RaiseEventTask(task_ran.get())); |  297   rtc::scoped_ptr<RaiseEventTask> task(new RaiseEventTask(task_ran.get())); | 
|  297   thread.Start(); |  298   thread.Start(); | 
|  298   thread.PostTask(task.Pass()); |  299   thread.PostTask(task.Pass()); | 
|  299   EXPECT_EQ(kEventSignaled, task_ran->Wait(100)); |  300   EXPECT_EQ(kEventSignaled, task_ran->Wait(100)); | 
|  300   thread.Stop(); |  301   thread.Stop(); | 
|  301 } |  302 } | 
|  302  |  303  | 
|  303 }  // namespace webrtc |  304 }  // namespace webrtc | 
| OLD | NEW |