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

Side by Side Diff: media/base/null_video_sink_unittest.cc

Issue 1924513003: Ignore sink start attempts when no frames are present. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Add test. Created 4 years, 8 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 | « media/base/null_video_sink.cc ('k') | media/renderers/video_renderer_impl.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 <memory> 5 #include <memory>
6 6
7 #include "base/bind.h" 7 #include "base/bind.h"
8 #include "base/callback_helpers.h" 8 #include "base/callback_helpers.h"
9 #include "base/macros.h" 9 #include "base/macros.h"
10 #include "base/message_loop/message_loop.h" 10 #include "base/message_loop/message_loop.h"
(...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after
91 91
92 // Verify that toggling background rendering mode issues the right bit to 92 // Verify that toggling background rendering mode issues the right bit to
93 // each Render() call. 93 // each Render() call.
94 sink->set_background_render(true); 94 sink->set_background_render(true);
95 95
96 // A second call returning the same frame should not result in a new call to 96 // A second call returning the same frame should not result in a new call to
97 // FrameReceived(). 97 // FrameReceived().
98 { 98 {
99 SCOPED_TRACE("Waiting for second render call."); 99 SCOPED_TRACE("Waiting for second render call.");
100 WaitableMessageLoopEvent event; 100 WaitableMessageLoopEvent event;
101 scoped_refptr<VideoFrame> test_frame_2 = CreateFrame(kInterval);
101 EXPECT_CALL(*this, Render(_, _, true)) 102 EXPECT_CALL(*this, Render(_, _, true))
102 .WillOnce(Return(test_frame)) 103 .WillOnce(Return(test_frame))
103 .WillOnce(Return(nullptr)); 104 .WillOnce(Return(test_frame_2));
104 EXPECT_CALL(*this, FrameReceived(test_frame)).Times(0); 105 EXPECT_CALL(*this, FrameReceived(test_frame)).Times(0);
105 EXPECT_CALL(*this, FrameReceived(scoped_refptr<VideoFrame>())) 106 EXPECT_CALL(*this, FrameReceived(test_frame_2))
106 .WillOnce(RunClosure(event.GetClosure())); 107 .WillOnce(RunClosure(event.GetClosure()));
107 event.RunAndWait(); 108 event.RunAndWait();
108 } 109 }
109 110
110 { 111 {
111 SCOPED_TRACE("Waiting for stop event."); 112 SCOPED_TRACE("Waiting for stop event.");
112 WaitableMessageLoopEvent event; 113 WaitableMessageLoopEvent event;
113 sink->set_stop_cb(event.GetClosure()); 114 sink->set_stop_cb(event.GetClosure());
114 sink->Stop(); 115 sink->Stop();
115 event.RunAndWait(); 116 event.RunAndWait();
116 } 117 }
117 } 118 }
118 119
119 TEST_F(NullVideoSinkTest, ClocklessFunctionality) { 120 TEST_F(NullVideoSinkTest, ClocklessFunctionality) {
120 // Construct the sink with a huge interval, it should still complete quickly. 121 // Construct the sink with a huge interval, it should still complete quickly.
121 const base::TimeDelta interval = base::TimeDelta::FromSeconds(10); 122 const base::TimeDelta interval = base::TimeDelta::FromSeconds(10);
122 std::unique_ptr<NullVideoSink> sink = ConstructSink(true, interval); 123 std::unique_ptr<NullVideoSink> sink = ConstructSink(true, interval);
123 124
124 scoped_refptr<VideoFrame> test_frame = CreateFrame(base::TimeDelta()); 125 scoped_refptr<VideoFrame> test_frame = CreateFrame(base::TimeDelta());
126 scoped_refptr<VideoFrame> test_frame_2 = CreateFrame(interval);
125 sink->Start(this); 127 sink->Start(this);
126 128
127 EXPECT_CALL(*this, FrameReceived(test_frame)).Times(1); 129 EXPECT_CALL(*this, FrameReceived(test_frame)).Times(1);
128 EXPECT_CALL(*this, FrameReceived(scoped_refptr<VideoFrame>())).Times(1); 130 EXPECT_CALL(*this, FrameReceived(test_frame_2)).Times(1);
129 131
130 const int kTestRuns = 6; 132 const int kTestRuns = 6;
131 const base::TimeTicks now = base::TimeTicks::Now(); 133 const base::TimeTicks now = base::TimeTicks::Now();
132 const base::TimeTicks current_time = tick_clock_.NowTicks(); 134 const base::TimeTicks current_time = tick_clock_.NowTicks();
133 135
134 SCOPED_TRACE("Waiting for multiple render callbacks"); 136 SCOPED_TRACE("Waiting for multiple render callbacks");
135 WaitableMessageLoopEvent event; 137 WaitableMessageLoopEvent event;
136 for (int i = 0; i < kTestRuns; ++i) { 138 for (int i = 0; i < kTestRuns; ++i) {
137 if (i < kTestRuns - 1) { 139 if (i < kTestRuns - 1) {
138 EXPECT_CALL(*this, Render(current_time + i * interval, 140 EXPECT_CALL(*this, Render(current_time + i * interval,
139 current_time + (i + 1) * interval, false)) 141 current_time + (i + 1) * interval, false))
140 .WillOnce(Return(test_frame)); 142 .WillOnce(Return(test_frame));
141 } else { 143 } else {
142 EXPECT_CALL(*this, Render(current_time + i * interval, 144 EXPECT_CALL(*this, Render(current_time + i * interval,
143 current_time + (i + 1) * interval, false)) 145 current_time + (i + 1) * interval, false))
144 .WillOnce(DoAll(RunClosure(event.GetClosure()), Return(nullptr))); 146 .WillOnce(
147 DoAll(RunClosure(event.GetClosure()), Return(test_frame_2)));
145 } 148 }
146 } 149 }
147 event.RunAndWait(); 150 event.RunAndWait();
148 ASSERT_LT(base::TimeTicks::Now() - now, kTestRuns * interval); 151 ASSERT_LT(base::TimeTicks::Now() - now, kTestRuns * interval);
149 sink->Stop(); 152 sink->Stop();
150 } 153 }
151 154
152 } // namespace media 155 } // namespace media
OLDNEW
« no previous file with comments | « media/base/null_video_sink.cc ('k') | media/renderers/video_renderer_impl.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698