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

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

Issue 2086353002: Remove calls to deprecated MessageLoop methods in media. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: rebase Created 4 years, 5 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/fake_demuxer_stream_unittest.cc ('k') | media/base/serial_runner_unittest.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 (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 "media/base/pipeline_impl.h" 5 #include "media/base/pipeline_impl.h"
6 6
7 #include <stddef.h> 7 #include <stddef.h>
8 #include <memory> 8 #include <memory>
9 #include <utility> 9 #include <utility>
10 #include <vector> 10 #include <vector>
11 11
12 #include "base/bind.h" 12 #include "base/bind.h"
13 #include "base/location.h" 13 #include "base/location.h"
14 #include "base/macros.h" 14 #include "base/macros.h"
15 #include "base/message_loop/message_loop.h" 15 #include "base/message_loop/message_loop.h"
16 #include "base/run_loop.h"
16 #include "base/single_thread_task_runner.h" 17 #include "base/single_thread_task_runner.h"
17 #include "base/stl_util.h" 18 #include "base/stl_util.h"
18 #include "base/test/simple_test_tick_clock.h" 19 #include "base/test/simple_test_tick_clock.h"
19 #include "base/threading/simple_thread.h" 20 #include "base/threading/simple_thread.h"
20 #include "base/threading/thread_task_runner_handle.h" 21 #include "base/threading/thread_task_runner_handle.h"
21 #include "base/time/clock.h" 22 #include "base/time/clock.h"
22 #include "media/base/fake_text_track_stream.h" 23 #include "media/base/fake_text_track_stream.h"
23 #include "media/base/gmock_callback_support.h" 24 #include "media/base/gmock_callback_support.h"
24 #include "media/base/media_log.h" 25 #include "media/base/media_log.h"
25 #include "media/base/mock_filters.h" 26 #include "media/base/mock_filters.h"
(...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after
122 123
123 // The mock demuxer doesn't stop the fake text track stream, 124 // The mock demuxer doesn't stop the fake text track stream,
124 // so just stop it manually. 125 // so just stop it manually.
125 if (text_stream_) 126 if (text_stream_)
126 text_stream_->Stop(); 127 text_stream_->Stop();
127 128
128 pipeline_->Stop(); 129 pipeline_->Stop();
129 } 130 }
130 131
131 pipeline_.reset(); 132 pipeline_.reset();
132 message_loop_.RunUntilIdle(); 133 base::RunLoop().RunUntilIdle();
133 } 134 }
134 135
135 void OnDemuxerError() { demuxer_host_->OnDemuxerError(PIPELINE_ERROR_ABORT); } 136 void OnDemuxerError() { demuxer_host_->OnDemuxerError(PIPELINE_ERROR_ABORT); }
136 137
137 protected: 138 protected:
138 // Sets up expectations to allow the demuxer to initialize. 139 // Sets up expectations to allow the demuxer to initialize.
139 typedef std::vector<MockDemuxerStream*> MockDemuxerStreamVector; 140 typedef std::vector<MockDemuxerStream*> MockDemuxerStreamVector;
140 void SetDemuxerExpectations(MockDemuxerStreamVector* streams, 141 void SetDemuxerExpectations(MockDemuxerStreamVector* streams,
141 const base::TimeDelta& duration) { 142 const base::TimeDelta& duration) {
142 EXPECT_CALL(callbacks_, OnDurationChange()); 143 EXPECT_CALL(callbacks_, OnDurationChange());
(...skipping 29 matching lines...) Expand all
172 DoAll(SaveArg<1>(&renderer_client_), PostCallback<2>(PIPELINE_OK))); 173 DoAll(SaveArg<1>(&renderer_client_), PostCallback<2>(PIPELINE_OK)));
173 EXPECT_CALL(*renderer_, HasAudio()).WillRepeatedly(Return(audio_stream())); 174 EXPECT_CALL(*renderer_, HasAudio()).WillRepeatedly(Return(audio_stream()));
174 EXPECT_CALL(*renderer_, HasVideo()).WillRepeatedly(Return(video_stream())); 175 EXPECT_CALL(*renderer_, HasVideo()).WillRepeatedly(Return(video_stream()));
175 } 176 }
176 177
177 void AddTextStream() { 178 void AddTextStream() {
178 EXPECT_CALL(callbacks_, OnAddTextTrack(_, _)) 179 EXPECT_CALL(callbacks_, OnAddTextTrack(_, _))
179 .WillOnce(Invoke(this, &PipelineImplTest::DoOnAddTextTrack)); 180 .WillOnce(Invoke(this, &PipelineImplTest::DoOnAddTextTrack));
180 demuxer_host_->AddTextStream(text_stream(), 181 demuxer_host_->AddTextStream(text_stream(),
181 TextTrackConfig(kTextSubtitles, "", "", "")); 182 TextTrackConfig(kTextSubtitles, "", "", ""));
182 message_loop_.RunUntilIdle(); 183 base::RunLoop().RunUntilIdle();
183 } 184 }
184 185
185 void StartPipeline() { 186 void StartPipeline() {
186 EXPECT_CALL(callbacks_, OnWaitingForDecryptionKey()).Times(0); 187 EXPECT_CALL(callbacks_, OnWaitingForDecryptionKey()).Times(0);
187 pipeline_->Start( 188 pipeline_->Start(
188 demuxer_.get(), std::move(scoped_renderer_), &callbacks_, 189 demuxer_.get(), std::move(scoped_renderer_), &callbacks_,
189 base::Bind(&CallbackHelper::OnStart, base::Unretained(&callbacks_))); 190 base::Bind(&CallbackHelper::OnStart, base::Unretained(&callbacks_)));
190 } 191 }
191 192
192 // Sets up expectations on the callback and initializes the pipeline. Called 193 // Sets up expectations on the callback and initializes the pipeline. Called
193 // after tests have set expectations any filters they wish to use. 194 // after tests have set expectations any filters they wish to use.
194 void StartPipelineAndExpect(PipelineStatus start_status) { 195 void StartPipelineAndExpect(PipelineStatus start_status) {
195 EXPECT_CALL(callbacks_, OnStart(start_status)); 196 EXPECT_CALL(callbacks_, OnStart(start_status));
196 197
197 if (start_status == PIPELINE_OK) { 198 if (start_status == PIPELINE_OK) {
198 EXPECT_CALL(callbacks_, OnMetadata(_)).WillOnce(SaveArg<0>(&metadata_)); 199 EXPECT_CALL(callbacks_, OnMetadata(_)).WillOnce(SaveArg<0>(&metadata_));
199 EXPECT_CALL(*renderer_, SetPlaybackRate(0.0)); 200 EXPECT_CALL(*renderer_, SetPlaybackRate(0.0));
200 EXPECT_CALL(*renderer_, SetVolume(1.0f)); 201 EXPECT_CALL(*renderer_, SetVolume(1.0f));
201 EXPECT_CALL(*renderer_, StartPlayingFrom(start_time_)) 202 EXPECT_CALL(*renderer_, StartPlayingFrom(start_time_))
202 .WillOnce( 203 .WillOnce(
203 SetBufferingState(&renderer_client_, BUFFERING_HAVE_ENOUGH)); 204 SetBufferingState(&renderer_client_, BUFFERING_HAVE_ENOUGH));
204 EXPECT_CALL(callbacks_, OnBufferingStateChange(BUFFERING_HAVE_ENOUGH)); 205 EXPECT_CALL(callbacks_, OnBufferingStateChange(BUFFERING_HAVE_ENOUGH));
205 } 206 }
206 207
207 StartPipeline(); 208 StartPipeline();
208 message_loop_.RunUntilIdle(); 209 base::RunLoop().RunUntilIdle();
209 } 210 }
210 211
211 void CreateAudioStream() { 212 void CreateAudioStream() {
212 audio_stream_ = CreateStream(DemuxerStream::AUDIO); 213 audio_stream_ = CreateStream(DemuxerStream::AUDIO);
213 } 214 }
214 215
215 void CreateVideoStream() { 216 void CreateVideoStream() {
216 video_stream_ = CreateStream(DemuxerStream::VIDEO); 217 video_stream_ = CreateStream(DemuxerStream::VIDEO);
217 video_stream_->set_video_decoder_config(video_decoder_config_); 218 video_stream_->set_video_decoder_config(video_decoder_config_);
218 } 219 }
(...skipping 25 matching lines...) Expand all
244 EXPECT_CALL(callbacks_, OnBufferingStateChange(BUFFERING_HAVE_NOTHING)); 245 EXPECT_CALL(callbacks_, OnBufferingStateChange(BUFFERING_HAVE_NOTHING));
245 246
246 // We expect a successful seek callback followed by a buffering update. 247 // We expect a successful seek callback followed by a buffering update.
247 EXPECT_CALL(callbacks_, OnSeek(PIPELINE_OK)); 248 EXPECT_CALL(callbacks_, OnSeek(PIPELINE_OK));
248 EXPECT_CALL(callbacks_, OnBufferingStateChange(BUFFERING_HAVE_ENOUGH)); 249 EXPECT_CALL(callbacks_, OnBufferingStateChange(BUFFERING_HAVE_ENOUGH));
249 } 250 }
250 251
251 void DoSeek(const base::TimeDelta& seek_time) { 252 void DoSeek(const base::TimeDelta& seek_time) {
252 pipeline_->Seek(seek_time, base::Bind(&CallbackHelper::OnSeek, 253 pipeline_->Seek(seek_time, base::Bind(&CallbackHelper::OnSeek,
253 base::Unretained(&callbacks_))); 254 base::Unretained(&callbacks_)));
254 message_loop_.RunUntilIdle(); 255 base::RunLoop().RunUntilIdle();
255 } 256 }
256 257
257 void ExpectSuspend() { 258 void ExpectSuspend() {
258 EXPECT_CALL(*renderer_, SetPlaybackRate(0)); 259 EXPECT_CALL(*renderer_, SetPlaybackRate(0));
259 EXPECT_CALL(*renderer_, Flush(_)) 260 EXPECT_CALL(*renderer_, Flush(_))
260 .WillOnce( 261 .WillOnce(
261 DoAll(SetBufferingState(&renderer_client_, BUFFERING_HAVE_NOTHING), 262 DoAll(SetBufferingState(&renderer_client_, BUFFERING_HAVE_NOTHING),
262 RunClosure<0>())); 263 RunClosure<0>()));
263 EXPECT_CALL(callbacks_, OnBufferingStateChange(BUFFERING_HAVE_NOTHING)); 264 EXPECT_CALL(callbacks_, OnBufferingStateChange(BUFFERING_HAVE_NOTHING));
264 EXPECT_CALL(callbacks_, OnSuspend(PIPELINE_OK)); 265 EXPECT_CALL(callbacks_, OnSuspend(PIPELINE_OK));
265 } 266 }
266 267
267 void DoSuspend() { 268 void DoSuspend() {
268 pipeline_->Suspend( 269 pipeline_->Suspend(
269 base::Bind(&CallbackHelper::OnSuspend, base::Unretained(&callbacks_))); 270 base::Bind(&CallbackHelper::OnSuspend, base::Unretained(&callbacks_)));
270 message_loop_.RunUntilIdle(); 271 base::RunLoop().RunUntilIdle();
271 272
272 // |renderer_| has been deleted, replace it. 273 // |renderer_| has been deleted, replace it.
273 scoped_renderer_.reset(new StrictMock<MockRenderer>()), 274 scoped_renderer_.reset(new StrictMock<MockRenderer>()),
274 renderer_ = scoped_renderer_.get(); 275 renderer_ = scoped_renderer_.get();
275 } 276 }
276 277
277 void ExpectResume(const base::TimeDelta& seek_time) { 278 void ExpectResume(const base::TimeDelta& seek_time) {
278 SetRendererExpectations(); 279 SetRendererExpectations();
279 EXPECT_CALL(*demuxer_, Seek(seek_time, _)) 280 EXPECT_CALL(*demuxer_, Seek(seek_time, _))
280 .WillOnce(RunCallback<1>(PIPELINE_OK)); 281 .WillOnce(RunCallback<1>(PIPELINE_OK));
281 EXPECT_CALL(*renderer_, SetPlaybackRate(_)); 282 EXPECT_CALL(*renderer_, SetPlaybackRate(_));
282 EXPECT_CALL(*renderer_, SetVolume(_)); 283 EXPECT_CALL(*renderer_, SetVolume(_));
283 EXPECT_CALL(*renderer_, StartPlayingFrom(seek_time)) 284 EXPECT_CALL(*renderer_, StartPlayingFrom(seek_time))
284 .WillOnce(SetBufferingState(&renderer_client_, BUFFERING_HAVE_ENOUGH)); 285 .WillOnce(SetBufferingState(&renderer_client_, BUFFERING_HAVE_ENOUGH));
285 EXPECT_CALL(callbacks_, OnBufferingStateChange(BUFFERING_HAVE_ENOUGH)); 286 EXPECT_CALL(callbacks_, OnBufferingStateChange(BUFFERING_HAVE_ENOUGH));
286 EXPECT_CALL(callbacks_, OnResume(PIPELINE_OK)); 287 EXPECT_CALL(callbacks_, OnResume(PIPELINE_OK));
287 } 288 }
288 289
289 void DoResume(const base::TimeDelta& seek_time) { 290 void DoResume(const base::TimeDelta& seek_time) {
290 pipeline_->Resume( 291 pipeline_->Resume(
291 std::move(scoped_renderer_), seek_time, 292 std::move(scoped_renderer_), seek_time,
292 base::Bind(&CallbackHelper::OnResume, base::Unretained(&callbacks_))); 293 base::Bind(&CallbackHelper::OnResume, base::Unretained(&callbacks_)));
293 message_loop_.RunUntilIdle(); 294 base::RunLoop().RunUntilIdle();
294 } 295 }
295 296
296 void ExpectDemuxerStop() { 297 void ExpectDemuxerStop() {
297 if (demuxer_) 298 if (demuxer_)
298 EXPECT_CALL(*demuxer_, Stop()); 299 EXPECT_CALL(*demuxer_, Stop());
299 } 300 }
300 301
301 void DoOnAddTextTrack(const TextTrackConfig& config, 302 void DoOnAddTextTrack(const TextTrackConfig& config,
302 const AddTextTrackDoneCB& done_cb) { 303 const AddTextTrackDoneCB& done_cb) {
303 std::unique_ptr<TextTrack> text_track(new MockTextTrack); 304 std::unique_ptr<TextTrack> text_track(new MockTextTrack);
304 done_cb.Run(std::move(text_track)); 305 done_cb.Run(std::move(text_track));
305 } 306 }
306 307
307 void RunBufferedTimeRangesTest(const base::TimeDelta duration) { 308 void RunBufferedTimeRangesTest(const base::TimeDelta duration) {
308 EXPECT_EQ(0u, pipeline_->GetBufferedTimeRanges().size()); 309 EXPECT_EQ(0u, pipeline_->GetBufferedTimeRanges().size());
309 EXPECT_FALSE(pipeline_->DidLoadingProgress()); 310 EXPECT_FALSE(pipeline_->DidLoadingProgress());
310 311
311 Ranges<base::TimeDelta> ranges; 312 Ranges<base::TimeDelta> ranges;
312 ranges.Add(base::TimeDelta(), duration); 313 ranges.Add(base::TimeDelta(), duration);
313 demuxer_host_->OnBufferedTimeRangesChanged(ranges); 314 demuxer_host_->OnBufferedTimeRangesChanged(ranges);
314 message_loop_.RunUntilIdle(); 315 base::RunLoop().RunUntilIdle();
315 316
316 EXPECT_TRUE(pipeline_->DidLoadingProgress()); 317 EXPECT_TRUE(pipeline_->DidLoadingProgress());
317 EXPECT_FALSE(pipeline_->DidLoadingProgress()); 318 EXPECT_FALSE(pipeline_->DidLoadingProgress());
318 EXPECT_EQ(1u, pipeline_->GetBufferedTimeRanges().size()); 319 EXPECT_EQ(1u, pipeline_->GetBufferedTimeRanges().size());
319 EXPECT_EQ(base::TimeDelta(), pipeline_->GetBufferedTimeRanges().start(0)); 320 EXPECT_EQ(base::TimeDelta(), pipeline_->GetBufferedTimeRanges().start(0));
320 EXPECT_EQ(duration, pipeline_->GetBufferedTimeRanges().end(0)); 321 EXPECT_EQ(duration, pipeline_->GetBufferedTimeRanges().end(0));
321 } 322 }
322 323
323 // Fixture members. 324 // Fixture members.
324 StrictMock<CallbackHelper> callbacks_; 325 StrictMock<CallbackHelper> callbacks_;
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after
371 } 372 }
372 373
373 TEST_F(PipelineImplTest, NeverInitializes) { 374 TEST_F(PipelineImplTest, NeverInitializes) {
374 // Don't execute the callback passed into Initialize(). 375 // Don't execute the callback passed into Initialize().
375 EXPECT_CALL(*demuxer_, Initialize(_, _, _)); 376 EXPECT_CALL(*demuxer_, Initialize(_, _, _));
376 377
377 // This test hangs during initialization by never calling 378 // This test hangs during initialization by never calling
378 // InitializationComplete(). StrictMock<> will ensure that the callback is 379 // InitializationComplete(). StrictMock<> will ensure that the callback is
379 // never executed. 380 // never executed.
380 StartPipeline(); 381 StartPipeline();
381 message_loop_.RunUntilIdle(); 382 base::RunLoop().RunUntilIdle();
382 383
383 // Because our callback will get executed when the test tears down, we'll 384 // Because our callback will get executed when the test tears down, we'll
384 // verify that nothing has been called, then set our expectation for the call 385 // verify that nothing has been called, then set our expectation for the call
385 // made during tear down. 386 // made during tear down.
386 Mock::VerifyAndClear(&callbacks_); 387 Mock::VerifyAndClear(&callbacks_);
387 } 388 }
388 389
389 TEST_F(PipelineImplTest, StopWithoutStart) { 390 TEST_F(PipelineImplTest, StopWithoutStart) {
390 pipeline_->Stop(); 391 pipeline_->Stop();
391 message_loop_.RunUntilIdle(); 392 base::RunLoop().RunUntilIdle();
392 } 393 }
393 394
394 TEST_F(PipelineImplTest, StartThenStopImmediately) { 395 TEST_F(PipelineImplTest, StartThenStopImmediately) {
395 EXPECT_CALL(*demuxer_, Initialize(_, _, _)) 396 EXPECT_CALL(*demuxer_, Initialize(_, _, _))
396 .WillOnce(PostCallback<1>(PIPELINE_OK)); 397 .WillOnce(PostCallback<1>(PIPELINE_OK));
397 EXPECT_CALL(*demuxer_, Stop()); 398 EXPECT_CALL(*demuxer_, Stop());
398 EXPECT_CALL(callbacks_, OnMetadata(_)); 399 EXPECT_CALL(callbacks_, OnMetadata(_));
399 400
400 EXPECT_CALL(callbacks_, OnStart(_)); 401 EXPECT_CALL(callbacks_, OnStart(_));
401 StartPipeline(); 402 StartPipeline();
402 message_loop_.RunUntilIdle(); 403 base::RunLoop().RunUntilIdle();
403 404
404 pipeline_->Stop(); 405 pipeline_->Stop();
405 } 406 }
406 407
407 TEST_F(PipelineImplTest, DemuxerErrorDuringStop) { 408 TEST_F(PipelineImplTest, DemuxerErrorDuringStop) {
408 CreateAudioStream(); 409 CreateAudioStream();
409 MockDemuxerStreamVector streams; 410 MockDemuxerStreamVector streams;
410 streams.push_back(audio_stream()); 411 streams.push_back(audio_stream());
411 412
412 SetDemuxerExpectations(&streams); 413 SetDemuxerExpectations(&streams);
413 SetRendererExpectations(); 414 SetRendererExpectations();
414 415
415 StartPipelineAndExpect(PIPELINE_OK); 416 StartPipelineAndExpect(PIPELINE_OK);
416 message_loop_.RunUntilIdle(); 417 base::RunLoop().RunUntilIdle();
417 418
418 EXPECT_CALL(*demuxer_, Stop()) 419 EXPECT_CALL(*demuxer_, Stop())
419 .WillOnce(InvokeWithoutArgs(this, &PipelineImplTest::OnDemuxerError)); 420 .WillOnce(InvokeWithoutArgs(this, &PipelineImplTest::OnDemuxerError));
420 pipeline_->Stop(); 421 pipeline_->Stop();
421 message_loop_.RunUntilIdle(); 422 base::RunLoop().RunUntilIdle();
422 } 423 }
423 424
424 TEST_F(PipelineImplTest, NoStreams) { 425 TEST_F(PipelineImplTest, NoStreams) {
425 EXPECT_CALL(*demuxer_, Initialize(_, _, _)) 426 EXPECT_CALL(*demuxer_, Initialize(_, _, _))
426 .WillOnce(PostCallback<1>(PIPELINE_OK)); 427 .WillOnce(PostCallback<1>(PIPELINE_OK));
427 EXPECT_CALL(*demuxer_, Stop()); 428 EXPECT_CALL(*demuxer_, Stop());
428 EXPECT_CALL(callbacks_, OnMetadata(_)); 429 EXPECT_CALL(callbacks_, OnMetadata(_));
429 430
430 StartPipelineAndExpect(PIPELINE_ERROR_COULD_NOT_RENDER); 431 StartPipelineAndExpect(PIPELINE_ERROR_COULD_NOT_RENDER);
431 } 432 }
(...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after
532 533
533 SetDemuxerExpectations(&streams, base::TimeDelta::FromSeconds(3000)); 534 SetDemuxerExpectations(&streams, base::TimeDelta::FromSeconds(3000));
534 SetRendererExpectations(); 535 SetRendererExpectations();
535 536
536 // Initialize then seek! 537 // Initialize then seek!
537 StartPipelineAndExpect(PIPELINE_OK); 538 StartPipelineAndExpect(PIPELINE_OK);
538 539
539 EXPECT_CALL(*demuxer_, Stop()); 540 EXPECT_CALL(*demuxer_, Stop());
540 EXPECT_CALL(callbacks_, OnError(_)); 541 EXPECT_CALL(callbacks_, OnError(_));
541 OnDemuxerError(); 542 OnDemuxerError();
542 message_loop_.RunUntilIdle(); 543 base::RunLoop().RunUntilIdle();
543 544
544 pipeline_->Seek( 545 pipeline_->Seek(
545 base::TimeDelta::FromMilliseconds(100), 546 base::TimeDelta::FromMilliseconds(100),
546 base::Bind(&CallbackHelper::OnSeek, base::Unretained(&callbacks_))); 547 base::Bind(&CallbackHelper::OnSeek, base::Unretained(&callbacks_)));
547 message_loop_.RunUntilIdle(); 548 base::RunLoop().RunUntilIdle();
548 } 549 }
549 550
550 TEST_F(PipelineImplTest, SuspendResume) { 551 TEST_F(PipelineImplTest, SuspendResume) {
551 CreateAudioStream(); 552 CreateAudioStream();
552 CreateVideoStream(); 553 CreateVideoStream();
553 CreateTextStream(); 554 CreateTextStream();
554 MockDemuxerStreamVector streams; 555 MockDemuxerStreamVector streams;
555 streams.push_back(audio_stream()); 556 streams.push_back(audio_stream());
556 streams.push_back(video_stream()); 557 streams.push_back(video_stream());
557 558
558 SetDemuxerExpectations(&streams, base::TimeDelta::FromSeconds(3000)); 559 SetDemuxerExpectations(&streams, base::TimeDelta::FromSeconds(3000));
559 SetRendererExpectations(); 560 SetRendererExpectations();
560 561
561 StartPipelineAndExpect(PIPELINE_OK); 562 StartPipelineAndExpect(PIPELINE_OK);
562 563
563 // Inject some fake memory usage to verify its cleared after suspend. 564 // Inject some fake memory usage to verify its cleared after suspend.
564 PipelineStatistics stats; 565 PipelineStatistics stats;
565 stats.audio_memory_usage = 12345; 566 stats.audio_memory_usage = 12345;
566 stats.video_memory_usage = 67890; 567 stats.video_memory_usage = 67890;
567 renderer_client_->OnStatisticsUpdate(stats); 568 renderer_client_->OnStatisticsUpdate(stats);
568 message_loop_.RunUntilIdle(); 569 base::RunLoop().RunUntilIdle();
569 570
570 EXPECT_EQ(stats.audio_memory_usage, 571 EXPECT_EQ(stats.audio_memory_usage,
571 pipeline_->GetStatistics().audio_memory_usage); 572 pipeline_->GetStatistics().audio_memory_usage);
572 EXPECT_EQ(stats.video_memory_usage, 573 EXPECT_EQ(stats.video_memory_usage,
573 pipeline_->GetStatistics().video_memory_usage); 574 pipeline_->GetStatistics().video_memory_usage);
574 575
575 ExpectSuspend(); 576 ExpectSuspend();
576 DoSuspend(); 577 DoSuspend();
577 578
578 EXPECT_EQ(0, pipeline_->GetStatistics().audio_memory_usage); 579 EXPECT_EQ(0, pipeline_->GetStatistics().audio_memory_usage);
(...skipping 12 matching lines...) Expand all
591 SetDemuxerExpectations(&streams); 592 SetDemuxerExpectations(&streams);
592 SetRendererExpectations(); 593 SetRendererExpectations();
593 594
594 // The audio renderer should receive a call to SetVolume(). 595 // The audio renderer should receive a call to SetVolume().
595 float expected = 0.5f; 596 float expected = 0.5f;
596 EXPECT_CALL(*renderer_, SetVolume(expected)); 597 EXPECT_CALL(*renderer_, SetVolume(expected));
597 598
598 // Initialize then set volume! 599 // Initialize then set volume!
599 StartPipelineAndExpect(PIPELINE_OK); 600 StartPipelineAndExpect(PIPELINE_OK);
600 pipeline_->SetVolume(expected); 601 pipeline_->SetVolume(expected);
601 message_loop_.RunUntilIdle(); 602 base::RunLoop().RunUntilIdle();
602 } 603 }
603 604
604 TEST_F(PipelineImplTest, Properties) { 605 TEST_F(PipelineImplTest, Properties) {
605 CreateVideoStream(); 606 CreateVideoStream();
606 MockDemuxerStreamVector streams; 607 MockDemuxerStreamVector streams;
607 streams.push_back(video_stream()); 608 streams.push_back(video_stream());
608 609
609 const base::TimeDelta kDuration = base::TimeDelta::FromSeconds(100); 610 const base::TimeDelta kDuration = base::TimeDelta::FromSeconds(100);
610 SetDemuxerExpectations(&streams, kDuration); 611 SetDemuxerExpectations(&streams, kDuration);
611 SetRendererExpectations(); 612 SetRendererExpectations();
(...skipping 24 matching lines...) Expand all
636 } 637 }
637 638
638 TEST_F(PipelineImplTest, BufferedTimeRangesCanChangeAfterStop) { 639 TEST_F(PipelineImplTest, BufferedTimeRangesCanChangeAfterStop) {
639 EXPECT_CALL(*demuxer_, Initialize(_, _, _)) 640 EXPECT_CALL(*demuxer_, Initialize(_, _, _))
640 .WillOnce( 641 .WillOnce(
641 DoAll(SaveArg<0>(&demuxer_host_), PostCallback<1>(PIPELINE_OK))); 642 DoAll(SaveArg<0>(&demuxer_host_), PostCallback<1>(PIPELINE_OK)));
642 EXPECT_CALL(*demuxer_, Stop()); 643 EXPECT_CALL(*demuxer_, Stop());
643 EXPECT_CALL(callbacks_, OnMetadata(_)); 644 EXPECT_CALL(callbacks_, OnMetadata(_));
644 EXPECT_CALL(callbacks_, OnStart(_)); 645 EXPECT_CALL(callbacks_, OnStart(_));
645 StartPipeline(); 646 StartPipeline();
646 message_loop_.RunUntilIdle(); 647 base::RunLoop().RunUntilIdle();
647 648
648 pipeline_->Stop(); 649 pipeline_->Stop();
649 RunBufferedTimeRangesTest(base::TimeDelta::FromSeconds(5)); 650 RunBufferedTimeRangesTest(base::TimeDelta::FromSeconds(5));
650 } 651 }
651 652
652 TEST_F(PipelineImplTest, EndedCallback) { 653 TEST_F(PipelineImplTest, EndedCallback) {
653 CreateAudioStream(); 654 CreateAudioStream();
654 CreateVideoStream(); 655 CreateVideoStream();
655 CreateTextStream(); 656 CreateTextStream();
656 MockDemuxerStreamVector streams; 657 MockDemuxerStreamVector streams;
657 streams.push_back(audio_stream()); 658 streams.push_back(audio_stream());
658 streams.push_back(video_stream()); 659 streams.push_back(video_stream());
659 660
660 SetDemuxerExpectations(&streams); 661 SetDemuxerExpectations(&streams);
661 SetRendererExpectations(); 662 SetRendererExpectations();
662 StartPipelineAndExpect(PIPELINE_OK); 663 StartPipelineAndExpect(PIPELINE_OK);
663 664
664 AddTextStream(); 665 AddTextStream();
665 666
666 // The ended callback shouldn't run until all renderers have ended. 667 // The ended callback shouldn't run until all renderers have ended.
667 renderer_client_->OnEnded(); 668 renderer_client_->OnEnded();
668 message_loop_.RunUntilIdle(); 669 base::RunLoop().RunUntilIdle();
669 670
670 EXPECT_CALL(callbacks_, OnEnded()); 671 EXPECT_CALL(callbacks_, OnEnded());
671 text_stream()->SendEosNotification(); 672 text_stream()->SendEosNotification();
672 message_loop_.RunUntilIdle(); 673 base::RunLoop().RunUntilIdle();
673 } 674 }
674 675
675 TEST_F(PipelineImplTest, ErrorDuringSeek) { 676 TEST_F(PipelineImplTest, ErrorDuringSeek) {
676 CreateAudioStream(); 677 CreateAudioStream();
677 MockDemuxerStreamVector streams; 678 MockDemuxerStreamVector streams;
678 streams.push_back(audio_stream()); 679 streams.push_back(audio_stream());
679 680
680 SetDemuxerExpectations(&streams); 681 SetDemuxerExpectations(&streams);
681 SetRendererExpectations(); 682 SetRendererExpectations();
682 StartPipelineAndExpect(PIPELINE_OK); 683 StartPipelineAndExpect(PIPELINE_OK);
683 684
684 double playback_rate = 1.0; 685 double playback_rate = 1.0;
685 EXPECT_CALL(*renderer_, SetPlaybackRate(playback_rate)); 686 EXPECT_CALL(*renderer_, SetPlaybackRate(playback_rate));
686 pipeline_->SetPlaybackRate(playback_rate); 687 pipeline_->SetPlaybackRate(playback_rate);
687 message_loop_.RunUntilIdle(); 688 base::RunLoop().RunUntilIdle();
688 689
689 base::TimeDelta seek_time = base::TimeDelta::FromSeconds(5); 690 base::TimeDelta seek_time = base::TimeDelta::FromSeconds(5);
690 691
691 EXPECT_CALL(callbacks_, OnBufferingStateChange(BUFFERING_HAVE_NOTHING)); 692 EXPECT_CALL(callbacks_, OnBufferingStateChange(BUFFERING_HAVE_NOTHING));
692 EXPECT_CALL(*renderer_, Flush(_)) 693 EXPECT_CALL(*renderer_, Flush(_))
693 .WillOnce( 694 .WillOnce(
694 DoAll(SetBufferingState(&renderer_client_, BUFFERING_HAVE_NOTHING), 695 DoAll(SetBufferingState(&renderer_client_, BUFFERING_HAVE_NOTHING),
695 RunClosure<0>())); 696 RunClosure<0>()));
696 697
697 EXPECT_CALL(*demuxer_, Seek(seek_time, _)) 698 EXPECT_CALL(*demuxer_, Seek(seek_time, _))
698 .WillOnce(RunCallback<1>(PIPELINE_ERROR_READ)); 699 .WillOnce(RunCallback<1>(PIPELINE_ERROR_READ));
699 EXPECT_CALL(*demuxer_, Stop()); 700 EXPECT_CALL(*demuxer_, Stop());
700 701
701 pipeline_->Seek(seek_time, base::Bind(&CallbackHelper::OnSeek, 702 pipeline_->Seek(seek_time, base::Bind(&CallbackHelper::OnSeek,
702 base::Unretained(&callbacks_))); 703 base::Unretained(&callbacks_)));
703 EXPECT_CALL(callbacks_, OnSeek(PIPELINE_ERROR_READ)); 704 EXPECT_CALL(callbacks_, OnSeek(PIPELINE_ERROR_READ));
704 message_loop_.RunUntilIdle(); 705 base::RunLoop().RunUntilIdle();
705 } 706 }
706 707
707 // Invoked function OnError. This asserts that the pipeline does not enqueue 708 // Invoked function OnError. This asserts that the pipeline does not enqueue
708 // non-teardown related tasks while tearing down. 709 // non-teardown related tasks while tearing down.
709 static void TestNoCallsAfterError(PipelineImpl* pipeline, 710 static void TestNoCallsAfterError(PipelineImpl* pipeline,
710 base::MessageLoop* message_loop, 711 base::MessageLoop* message_loop,
711 PipelineStatus /* status */) { 712 PipelineStatus /* status */) {
712 CHECK(pipeline); 713 CHECK(pipeline);
713 CHECK(message_loop); 714 CHECK(message_loop);
714 715
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
747 RunClosure<0>())); 748 RunClosure<0>()));
748 EXPECT_CALL(callbacks_, OnBufferingStateChange(BUFFERING_HAVE_NOTHING)); 749 EXPECT_CALL(callbacks_, OnBufferingStateChange(BUFFERING_HAVE_NOTHING));
749 750
750 EXPECT_CALL(*demuxer_, Seek(seek_time, _)) 751 EXPECT_CALL(*demuxer_, Seek(seek_time, _))
751 .WillOnce(RunCallback<1>(PIPELINE_ERROR_READ)); 752 .WillOnce(RunCallback<1>(PIPELINE_ERROR_READ));
752 EXPECT_CALL(*demuxer_, Stop()); 753 EXPECT_CALL(*demuxer_, Stop());
753 754
754 pipeline_->Seek(seek_time, base::Bind(&CallbackHelper::OnSeek, 755 pipeline_->Seek(seek_time, base::Bind(&CallbackHelper::OnSeek,
755 base::Unretained(&callbacks_))); 756 base::Unretained(&callbacks_)));
756 EXPECT_CALL(callbacks_, OnSeek(PIPELINE_ERROR_READ)); 757 EXPECT_CALL(callbacks_, OnSeek(PIPELINE_ERROR_READ));
757 message_loop_.RunUntilIdle(); 758 base::RunLoop().RunUntilIdle();
758 } 759 }
759 760
760 TEST_F(PipelineImplTest, DestroyAfterStop) { 761 TEST_F(PipelineImplTest, DestroyAfterStop) {
761 CreateAudioStream(); 762 CreateAudioStream();
762 MockDemuxerStreamVector streams; 763 MockDemuxerStreamVector streams;
763 streams.push_back(audio_stream()); 764 streams.push_back(audio_stream());
764 SetDemuxerExpectations(&streams); 765 SetDemuxerExpectations(&streams);
765 SetRendererExpectations(); 766 SetRendererExpectations();
766 StartPipelineAndExpect(PIPELINE_OK); 767 StartPipelineAndExpect(PIPELINE_OK);
767 768
768 ExpectDemuxerStop(); 769 ExpectDemuxerStop();
769 pipeline_->Stop(); 770 pipeline_->Stop();
770 message_loop_.RunUntilIdle(); 771 base::RunLoop().RunUntilIdle();
771 } 772 }
772 773
773 TEST_F(PipelineImplTest, Underflow) { 774 TEST_F(PipelineImplTest, Underflow) {
774 CreateAudioStream(); 775 CreateAudioStream();
775 CreateVideoStream(); 776 CreateVideoStream();
776 MockDemuxerStreamVector streams; 777 MockDemuxerStreamVector streams;
777 streams.push_back(audio_stream()); 778 streams.push_back(audio_stream());
778 streams.push_back(video_stream()); 779 streams.push_back(video_stream());
779 780
780 SetDemuxerExpectations(&streams); 781 SetDemuxerExpectations(&streams);
781 SetRendererExpectations(); 782 SetRendererExpectations();
782 StartPipelineAndExpect(PIPELINE_OK); 783 StartPipelineAndExpect(PIPELINE_OK);
783 784
784 // Simulate underflow. 785 // Simulate underflow.
785 EXPECT_CALL(callbacks_, OnBufferingStateChange(BUFFERING_HAVE_NOTHING)); 786 EXPECT_CALL(callbacks_, OnBufferingStateChange(BUFFERING_HAVE_NOTHING));
786 renderer_client_->OnBufferingStateChange(BUFFERING_HAVE_NOTHING); 787 renderer_client_->OnBufferingStateChange(BUFFERING_HAVE_NOTHING);
787 message_loop_.RunUntilIdle(); 788 base::RunLoop().RunUntilIdle();
788 789
789 // Seek while underflowed. 790 // Seek while underflowed.
790 base::TimeDelta expected = base::TimeDelta::FromSeconds(5); 791 base::TimeDelta expected = base::TimeDelta::FromSeconds(5);
791 ExpectSeek(expected, true); 792 ExpectSeek(expected, true);
792 DoSeek(expected); 793 DoSeek(expected);
793 } 794 }
794 795
795 TEST_F(PipelineImplTest, PositiveStartTime) { 796 TEST_F(PipelineImplTest, PositiveStartTime) {
796 start_time_ = base::TimeDelta::FromSeconds(1); 797 start_time_ = base::TimeDelta::FromSeconds(1);
797 EXPECT_CALL(*demuxer_, GetStartTime()).WillRepeatedly(Return(start_time_)); 798 EXPECT_CALL(*demuxer_, GetStartTime()).WillRepeatedly(Return(start_time_));
798 CreateAudioStream(); 799 CreateAudioStream();
799 MockDemuxerStreamVector streams; 800 MockDemuxerStreamVector streams;
800 streams.push_back(audio_stream()); 801 streams.push_back(audio_stream());
801 SetDemuxerExpectations(&streams); 802 SetDemuxerExpectations(&streams);
802 SetRendererExpectations(); 803 SetRendererExpectations();
803 StartPipelineAndExpect(PIPELINE_OK); 804 StartPipelineAndExpect(PIPELINE_OK);
804 ExpectDemuxerStop(); 805 ExpectDemuxerStop();
805 pipeline_->Stop(); 806 pipeline_->Stop();
806 message_loop_.RunUntilIdle(); 807 base::RunLoop().RunUntilIdle();
807 } 808 }
808 809
809 class PipelineTeardownTest : public PipelineImplTest { 810 class PipelineTeardownTest : public PipelineImplTest {
810 public: 811 public:
811 enum TeardownState { 812 enum TeardownState {
812 kInitDemuxer, 813 kInitDemuxer,
813 kInitRenderer, 814 kInitRenderer,
814 kFlushing, 815 kFlushing,
815 kSeeking, 816 kSeeking,
816 kPlaying, 817 kPlaying,
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
855 } 856 }
856 } 857 }
857 858
858 private: 859 private:
859 // TODO(scherkus): We do radically different things whether teardown is 860 // TODO(scherkus): We do radically different things whether teardown is
860 // invoked via stop vs error. The teardown path should be the same, 861 // invoked via stop vs error. The teardown path should be the same,
861 // see http://crbug.com/110228 862 // see http://crbug.com/110228
862 void DoInitialize(TeardownState state, StopOrError stop_or_error) { 863 void DoInitialize(TeardownState state, StopOrError stop_or_error) {
863 SetInitializeExpectations(state, stop_or_error); 864 SetInitializeExpectations(state, stop_or_error);
864 StartPipeline(); 865 StartPipeline();
865 message_loop_.RunUntilIdle(); 866 base::RunLoop().RunUntilIdle();
866 } 867 }
867 868
868 void SetInitializeExpectations(TeardownState state, 869 void SetInitializeExpectations(TeardownState state,
869 StopOrError stop_or_error) { 870 StopOrError stop_or_error) {
870 if (state == kInitDemuxer) { 871 if (state == kInitDemuxer) {
871 if (stop_or_error == kStop) { 872 if (stop_or_error == kStop) {
872 EXPECT_CALL(*demuxer_, Initialize(_, _, _)) 873 EXPECT_CALL(*demuxer_, Initialize(_, _, _))
873 .WillOnce( 874 .WillOnce(
874 DoAll(Stop(pipeline_.get()), PostCallback<1>(PIPELINE_OK))); 875 DoAll(Stop(pipeline_.get()), PostCallback<1>(PIPELINE_OK)));
875 // Note: OnStart callback is not called after pipeline is stopped. 876 // Note: OnStart callback is not called after pipeline is stopped.
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after
927 } 928 }
928 929
929 void DoSeek(TeardownState state, StopOrError stop_or_error) { 930 void DoSeek(TeardownState state, StopOrError stop_or_error) {
930 SetSeekExpectations(state, stop_or_error); 931 SetSeekExpectations(state, stop_or_error);
931 932
932 EXPECT_CALL(*demuxer_, Stop()); 933 EXPECT_CALL(*demuxer_, Stop());
933 934
934 pipeline_->Seek( 935 pipeline_->Seek(
935 base::TimeDelta::FromSeconds(10), 936 base::TimeDelta::FromSeconds(10),
936 base::Bind(&CallbackHelper::OnSeek, base::Unretained(&callbacks_))); 937 base::Bind(&CallbackHelper::OnSeek, base::Unretained(&callbacks_)));
937 message_loop_.RunUntilIdle(); 938 base::RunLoop().RunUntilIdle();
938 } 939 }
939 940
940 void SetSeekExpectations(TeardownState state, StopOrError stop_or_error) { 941 void SetSeekExpectations(TeardownState state, StopOrError stop_or_error) {
941 if (state == kFlushing) { 942 if (state == kFlushing) {
942 if (stop_or_error == kStop) { 943 if (stop_or_error == kStop) {
943 EXPECT_CALL(*renderer_, Flush(_)) 944 EXPECT_CALL(*renderer_, Flush(_))
944 .WillOnce(DoAll( 945 .WillOnce(DoAll(
945 SetBufferingState(&renderer_client_, BUFFERING_HAVE_NOTHING), 946 SetBufferingState(&renderer_client_, BUFFERING_HAVE_NOTHING),
946 Stop(pipeline_.get()), RunClosure<0>())); 947 Stop(pipeline_.get()), RunClosure<0>()));
947 // Note: OnBufferingStateChange or OnSeek callbacks are not called 948 // Note: OnBufferingStateChange or OnSeek callbacks are not called
(...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after
1037 EXPECT_CALL(callbacks_, OnError(PIPELINE_ERROR_READ)); 1038 EXPECT_CALL(callbacks_, OnError(PIPELINE_ERROR_READ));
1038 } 1039 }
1039 renderer_client_->OnError(PIPELINE_ERROR_READ); 1040 renderer_client_->OnError(PIPELINE_ERROR_READ);
1040 break; 1041 break;
1041 1042
1042 case kErrorAndStop: 1043 case kErrorAndStop:
1043 EXPECT_CALL(*demuxer_, Stop()); 1044 EXPECT_CALL(*demuxer_, Stop());
1044 if (expect_errors) 1045 if (expect_errors)
1045 EXPECT_CALL(callbacks_, OnError(PIPELINE_ERROR_READ)); 1046 EXPECT_CALL(callbacks_, OnError(PIPELINE_ERROR_READ));
1046 renderer_client_->OnError(PIPELINE_ERROR_READ); 1047 renderer_client_->OnError(PIPELINE_ERROR_READ);
1047 message_loop_.RunUntilIdle(); 1048 base::RunLoop().RunUntilIdle();
1048 pipeline_->Stop(); 1049 pipeline_->Stop();
1049 break; 1050 break;
1050 } 1051 }
1051 1052
1052 message_loop_.RunUntilIdle(); 1053 base::RunLoop().RunUntilIdle();
1053 } 1054 }
1054 1055
1055 DISALLOW_COPY_AND_ASSIGN(PipelineTeardownTest); 1056 DISALLOW_COPY_AND_ASSIGN(PipelineTeardownTest);
1056 }; 1057 };
1057 1058
1058 #define INSTANTIATE_TEARDOWN_TEST(stop_or_error, state) \ 1059 #define INSTANTIATE_TEARDOWN_TEST(stop_or_error, state) \
1059 TEST_F(PipelineTeardownTest, stop_or_error##_##state) { \ 1060 TEST_F(PipelineTeardownTest, stop_or_error##_##state) { \
1060 RunTest(k##state, k##stop_or_error); \ 1061 RunTest(k##state, k##stop_or_error); \
1061 } 1062 }
1062 1063
(...skipping 12 matching lines...) Expand all
1075 INSTANTIATE_TEARDOWN_TEST(Error, Seeking); 1076 INSTANTIATE_TEARDOWN_TEST(Error, Seeking);
1076 INSTANTIATE_TEARDOWN_TEST(Error, Playing); 1077 INSTANTIATE_TEARDOWN_TEST(Error, Playing);
1077 INSTANTIATE_TEARDOWN_TEST(Error, Suspending); 1078 INSTANTIATE_TEARDOWN_TEST(Error, Suspending);
1078 INSTANTIATE_TEARDOWN_TEST(Error, Suspended); 1079 INSTANTIATE_TEARDOWN_TEST(Error, Suspended);
1079 INSTANTIATE_TEARDOWN_TEST(Error, Resuming); 1080 INSTANTIATE_TEARDOWN_TEST(Error, Resuming);
1080 1081
1081 INSTANTIATE_TEARDOWN_TEST(ErrorAndStop, Playing); 1082 INSTANTIATE_TEARDOWN_TEST(ErrorAndStop, Playing);
1082 INSTANTIATE_TEARDOWN_TEST(ErrorAndStop, Suspended); 1083 INSTANTIATE_TEARDOWN_TEST(ErrorAndStop, Suspended);
1083 1084
1084 } // namespace media 1085 } // namespace media
OLDNEW
« no previous file with comments | « media/base/fake_demuxer_stream_unittest.cc ('k') | media/base/serial_runner_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698