| OLD | NEW |
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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/callback_helpers.h" | 6 #include "base/callback_helpers.h" |
| 7 #include "base/macros.h" | 7 #include "base/macros.h" |
| 8 #include "base/message_loop/message_loop.h" | 8 #include "base/message_loop/message_loop.h" |
| 9 #include "base/test/simple_test_tick_clock.h" | 9 #include "base/test/simple_test_tick_clock.h" |
| 10 #include "media/base/null_video_sink.h" | 10 #include "media/base/null_video_sink.h" |
| (...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 89 | 89 |
| 90 // Verify that toggling background rendering mode issues the right bit to | 90 // Verify that toggling background rendering mode issues the right bit to |
| 91 // each Render() call. | 91 // each Render() call. |
| 92 sink->set_background_render(true); | 92 sink->set_background_render(true); |
| 93 | 93 |
| 94 // A second call returning the same frame should not result in a new call to | 94 // A second call returning the same frame should not result in a new call to |
| 95 // FrameReceived(). | 95 // FrameReceived(). |
| 96 { | 96 { |
| 97 SCOPED_TRACE("Waiting for second render call."); | 97 SCOPED_TRACE("Waiting for second render call."); |
| 98 WaitableMessageLoopEvent event; | 98 WaitableMessageLoopEvent event; |
| 99 scoped_refptr<VideoFrame> test_frame_2 = CreateFrame(kInterval); |
| 99 EXPECT_CALL(*this, Render(_, _, true)) | 100 EXPECT_CALL(*this, Render(_, _, true)) |
| 100 .WillOnce(Return(test_frame)) | 101 .WillOnce(Return(test_frame)) |
| 101 .WillOnce(Return(nullptr)); | 102 .WillOnce(Return(test_frame_2)); |
| 102 EXPECT_CALL(*this, FrameReceived(test_frame)).Times(0); | 103 EXPECT_CALL(*this, FrameReceived(test_frame)).Times(0); |
| 103 EXPECT_CALL(*this, FrameReceived(scoped_refptr<VideoFrame>())) | 104 EXPECT_CALL(*this, FrameReceived(test_frame_2)) |
| 104 .WillOnce(RunClosure(event.GetClosure())); | 105 .WillOnce(RunClosure(event.GetClosure())); |
| 105 event.RunAndWait(); | 106 event.RunAndWait(); |
| 106 } | 107 } |
| 107 | 108 |
| 108 { | 109 { |
| 109 SCOPED_TRACE("Waiting for stop event."); | 110 SCOPED_TRACE("Waiting for stop event."); |
| 110 WaitableMessageLoopEvent event; | 111 WaitableMessageLoopEvent event; |
| 111 sink->set_stop_cb(event.GetClosure()); | 112 sink->set_stop_cb(event.GetClosure()); |
| 112 sink->Stop(); | 113 sink->Stop(); |
| 113 event.RunAndWait(); | 114 event.RunAndWait(); |
| 114 } | 115 } |
| 115 } | 116 } |
| 116 | 117 |
| 117 TEST_F(NullVideoSinkTest, ClocklessFunctionality) { | 118 TEST_F(NullVideoSinkTest, ClocklessFunctionality) { |
| 118 // Construct the sink with a huge interval, it should still complete quickly. | 119 // Construct the sink with a huge interval, it should still complete quickly. |
| 119 const base::TimeDelta interval = base::TimeDelta::FromSeconds(10); | 120 const base::TimeDelta interval = base::TimeDelta::FromSeconds(10); |
| 120 scoped_ptr<NullVideoSink> sink = ConstructSink(true, interval); | 121 scoped_ptr<NullVideoSink> sink = ConstructSink(true, interval); |
| 121 | 122 |
| 122 scoped_refptr<VideoFrame> test_frame = CreateFrame(base::TimeDelta()); | 123 scoped_refptr<VideoFrame> test_frame = CreateFrame(base::TimeDelta()); |
| 124 scoped_refptr<VideoFrame> test_frame_2 = CreateFrame(interval); |
| 123 sink->Start(this); | 125 sink->Start(this); |
| 124 | 126 |
| 125 EXPECT_CALL(*this, FrameReceived(test_frame)).Times(1); | 127 EXPECT_CALL(*this, FrameReceived(test_frame)).Times(1); |
| 126 EXPECT_CALL(*this, FrameReceived(scoped_refptr<VideoFrame>())).Times(1); | 128 EXPECT_CALL(*this, FrameReceived(test_frame_2)).Times(1); |
| 127 | 129 |
| 128 const int kTestRuns = 6; | 130 const int kTestRuns = 6; |
| 129 const base::TimeTicks now = base::TimeTicks::Now(); | 131 const base::TimeTicks now = base::TimeTicks::Now(); |
| 130 const base::TimeTicks current_time = tick_clock_.NowTicks(); | 132 const base::TimeTicks current_time = tick_clock_.NowTicks(); |
| 131 | 133 |
| 132 SCOPED_TRACE("Waiting for multiple render callbacks"); | 134 SCOPED_TRACE("Waiting for multiple render callbacks"); |
| 133 WaitableMessageLoopEvent event; | 135 WaitableMessageLoopEvent event; |
| 134 for (int i = 0; i < kTestRuns; ++i) { | 136 for (int i = 0; i < kTestRuns; ++i) { |
| 135 if (i < kTestRuns - 1) { | 137 if (i < kTestRuns - 1) { |
| 136 EXPECT_CALL(*this, Render(current_time + i * interval, | 138 EXPECT_CALL(*this, Render(current_time + i * interval, |
| 137 current_time + (i + 1) * interval, false)) | 139 current_time + (i + 1) * interval, false)) |
| 138 .WillOnce(Return(test_frame)); | 140 .WillOnce(Return(test_frame)); |
| 139 } else { | 141 } else { |
| 140 EXPECT_CALL(*this, Render(current_time + i * interval, | 142 EXPECT_CALL(*this, Render(current_time + i * interval, |
| 141 current_time + (i + 1) * interval, false)) | 143 current_time + (i + 1) * interval, false)) |
| 142 .WillOnce(DoAll(RunClosure(event.GetClosure()), Return(nullptr))); | 144 .WillOnce( |
| 145 DoAll(RunClosure(event.GetClosure()), Return(test_frame_2))); |
| 143 } | 146 } |
| 144 } | 147 } |
| 145 event.RunAndWait(); | 148 event.RunAndWait(); |
| 146 ASSERT_LT(base::TimeTicks::Now() - now, kTestRuns * interval); | 149 ASSERT_LT(base::TimeTicks::Now() - now, kTestRuns * interval); |
| 147 sink->Stop(); | 150 sink->Stop(); |
| 148 } | 151 } |
| 149 | 152 |
| 150 } // namespace media | 153 } // namespace media |
| OLD | NEW |