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

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

Issue 5744002: Refactor PipelineImpl to use CompositeFilter to manage Filter state transitions. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Fix CR nits & remove dead code. Created 9 years, 11 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 | Annotate | Revision Log
« no previous file with comments | « media/base/composite_filter.cc ('k') | media/base/mock_filters.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #include "media/base/composite_filter.h"
6 #include "media/base/mock_filter_host.h"
7 #include "media/base/mock_filters.h"
8 #include "testing/gtest/include/gtest/gtest.h"
9
10 using ::testing::_;
11 using ::testing::InSequence;
12 using ::testing::Return;
13 using ::testing::SaveArg;
14 using ::testing::StrictMock;
15
16 namespace media {
17
18 class CompositeFilterTest : public testing::Test {
19 public:
20 CompositeFilterTest();
21 virtual ~CompositeFilterTest();
22
23 // Sets up a new CompositeFilter in |composite_|, creates |filter_1_| and
24 // |filter_2_|, and adds these filters to |composite_|.
25 void SetupAndAdd2Filters();
26
27 // Helper enum that indicates what filter method to call.
28 enum MethodToCall {
29 PLAY,
30 PAUSE,
31 FLUSH,
32 STOP,
33 SEEK,
34 };
35
36 // Helper method that adds a filter method call expectation based on the value
37 // of |method_to_call|.
38 //
39 // |method_to_call| - Indicates which method we expect a call for.
40 // |filter| - The MockFilter to add the expectation to.
41 // |seek_time| - The time to pass to the Seek() call if |method_to_call|
42 // equals SEEK.
43 void ExpectFilterCall(MethodToCall method_to_call, MockFilter* filter,
44 base::TimeDelta seek_time);
45
46 // Helper method that calls a filter method based on the value of
47 // |method_to_call|.
48 //
49 // |method_to_call| - Indicates which method to call.
50 // |filter| - The Filter to make the method call on.
51 // |seek_time| - The time to pass to the Seek() call if |method_to_call|
52 // equals SEEK.
53 // |callback| - The callback object to pass to the method.
54 void DoFilterCall(MethodToCall method_to_call, Filter* filter,
55 base::TimeDelta seek_time,
56 FilterCallback* callback);
57
58 // Creates an expectation sequence based on the value of method_to_call.
59 //
60 // |method_to_call| - Indicates which method we want a success sequence for.
61 // |seek_time| - The time to pass in the Seek() call if |method_to_call|
62 // equals SEEK.
63 void ExpectSuccess(MethodToCall method_to_call,
64 base::TimeDelta seek_time = base::TimeDelta());
65
66 // Issue a Play(), Pause(), Flush(), Stop(), or Seek() on the composite and
67 // verify all the expected calls on the filters.
68 void DoPlay();
69 void DoPause();
70 void DoFlush();
71 void DoStop();
72 void DoSeek(base::TimeDelta time);
73
74 // Issue a Play(), Pause(), Flush(), or Seek() and expect the calls to fail
75 // with a PIPELINE_ERROR_INVALID_STATE error.
76 //
77 // |method_to_call| - Indicates whick method to call.
78 // |seek_time| - The time to pass to the Seek() call if |method_to_call|
79 // equals SEEK.
80 void ExpectInvalidStateFail(MethodToCall method_to_call,
81 base::TimeDelta seek_time = base::TimeDelta());
82
83 // Run the callback stored in |filter_1_callback_|.
84 void RunFilter1Callback();
85
86 // Run the callback stored in |filter_2_callback_|.
87 void RunFilter2Callback();
88
89 protected:
90 MessageLoop message_loop_;
91
92 // The composite object being tested.
93 scoped_refptr<CompositeFilter> composite_;
94
95 // First filter added to the composite.
96 scoped_refptr<StrictMock<MockFilter> > filter_1_;
97
98 // Callback passed to |filter_1_| during last Play(), Pause(), Flush(),
99 // Stop(), or Seek() call.
100 FilterCallback* filter_1_callback_;
101
102 // Second filter added to the composite.
103 scoped_refptr<StrictMock<MockFilter> > filter_2_;
104
105 // Callback passed to |filter_2_| during last Play(), Pause(), Flush(),
106 // Stop(), or Seek() call.
107 FilterCallback* filter_2_callback_;
108
109 // FilterHost implementation passed to |composite_| via set_host().
110 scoped_ptr<StrictMock<MockFilterHost> > mock_filter_host_;
111
112 DISALLOW_COPY_AND_ASSIGN(CompositeFilterTest);
113 };
114
115 CompositeFilterTest::CompositeFilterTest() :
116 composite_(new CompositeFilter(&message_loop_)),
117 filter_1_callback_(NULL),
118 filter_2_callback_(NULL),
119 mock_filter_host_(new StrictMock<MockFilterHost>()) {
120 }
121
122 CompositeFilterTest::~CompositeFilterTest() {}
123
124 void CompositeFilterTest::SetupAndAdd2Filters() {
125 mock_filter_host_.reset(new StrictMock<MockFilterHost>());
126 composite_ = new CompositeFilter(&message_loop_);
127 composite_->set_host(mock_filter_host_.get());
128
129 // Setup |filter_1_| and arrange for methods to set
130 // |filter_1_callback_| when they are called.
131 filter_1_ = new StrictMock<MockFilter>();
132 filter_1_callback_ = NULL;
133 ON_CALL(*filter_1_, Play(_))
134 .WillByDefault(SaveArg<0>(&filter_1_callback_));
135 ON_CALL(*filter_1_, Pause(_))
136 .WillByDefault(SaveArg<0>(&filter_1_callback_));
137 ON_CALL(*filter_1_, Flush(_))
138 .WillByDefault(SaveArg<0>(&filter_1_callback_));
139 ON_CALL(*filter_1_, Stop(_))
140 .WillByDefault(SaveArg<0>(&filter_1_callback_));
141 ON_CALL(*filter_1_, Seek(_,_))
142 .WillByDefault(SaveArg<1>(&filter_1_callback_));
143
144 // Setup |filter_2_| and arrange for methods to set
145 // |filter_2_callback_| when they are called.
146 filter_2_ = new StrictMock<MockFilter>();
147 filter_2_callback_ = NULL;
148 ON_CALL(*filter_2_, Play(_))
149 .WillByDefault(SaveArg<0>(&filter_2_callback_));
150 ON_CALL(*filter_2_, Pause(_))
151 .WillByDefault(SaveArg<0>(&filter_2_callback_));
152 ON_CALL(*filter_2_, Flush(_))
153 .WillByDefault(SaveArg<0>(&filter_2_callback_));
154 ON_CALL(*filter_2_, Stop(_))
155 .WillByDefault(SaveArg<0>(&filter_2_callback_));
156 ON_CALL(*filter_2_, Seek(_,_))
157 .WillByDefault(SaveArg<1>(&filter_2_callback_));
158
159 composite_->AddFilter(filter_1_);
160 composite_->AddFilter(filter_2_);
161 }
162
163 void CompositeFilterTest::ExpectFilterCall(MethodToCall method_to_call,
164 MockFilter* filter,
165 base::TimeDelta seek_time) {
166 switch(method_to_call) {
167 case PLAY:
168 EXPECT_CALL(*filter, Play(_));
169 break;
170 case PAUSE:
171 EXPECT_CALL(*filter, Pause(_));
172 break;
173 case FLUSH:
174 EXPECT_CALL(*filter, Flush(_));
175 break;
176 case STOP:
177 EXPECT_CALL(*filter, Stop(_));
178 break;
179 case SEEK:
180 EXPECT_CALL(*filter, Seek(seek_time, _));
181 break;
182 };
183 }
184
185 void CompositeFilterTest::DoFilterCall(MethodToCall method_to_call,
186 Filter* filter,
187 base::TimeDelta seek_time,
188 FilterCallback* callback) {
189 switch(method_to_call) {
190 case PLAY:
191 filter->Play(callback);
192 break;
193 case PAUSE:
194 filter->Pause(callback);
195 break;
196 case FLUSH:
197 filter->Flush(callback);
198 break;
199 case STOP:
200 filter->Stop(callback);
201 break;
202 case SEEK:
203 filter->Seek(seek_time, callback);
204 break;
205 };
206 }
207
208 void CompositeFilterTest::ExpectSuccess(MethodToCall method_to_call,
209 base::TimeDelta seek_time) {
210 InSequence seq;
211
212 scoped_ptr<StrictMock<MockFilterCallback> > mock_callback(
213 new StrictMock<MockFilterCallback>(false));
214
215 bool is_parallel_call = (method_to_call == FLUSH);
216
217 ExpectFilterCall(method_to_call, filter_1_.get(), seek_time);
218
219 if (is_parallel_call) {
220 ExpectFilterCall(method_to_call, filter_2_.get(), seek_time);
221 }
222
223 // Make method call on the composite.
224 DoFilterCall(method_to_call, composite_.get(), seek_time,
225 mock_callback->NewCallback());
226
227 if (is_parallel_call) {
228 // Make sure both filters have their callbacks set.
229 EXPECT_TRUE(filter_1_callback_ != NULL);
230 EXPECT_TRUE(filter_2_callback_ != NULL);
231
232 RunFilter1Callback();
233 } else {
234 // Make sure that only |filter_1_| has its callback set.
235 EXPECT_TRUE(filter_1_callback_ != NULL);
236 EXPECT_EQ((FilterCallback*)NULL, filter_2_callback_);
237
238 ExpectFilterCall(method_to_call, filter_2_.get(), seek_time);
239
240 RunFilter1Callback();
241
242 // Verify that |filter_2_| was called by checking the callback pointer.
243 EXPECT_TRUE(filter_2_callback_ != NULL);
244 }
245
246 EXPECT_CALL(*mock_callback, OnFilterCallback());
247
248 RunFilter2Callback();
249 }
250
251 void CompositeFilterTest::DoPlay() {
252 ExpectSuccess(PLAY);
253 }
254
255 void CompositeFilterTest::DoPause() {
256 ExpectSuccess(PAUSE);
257 }
258
259 void CompositeFilterTest::DoFlush() {
260 ExpectSuccess(FLUSH);
261 }
262
263 void CompositeFilterTest::DoStop() {
264 ExpectSuccess(STOP);
265 }
266
267 void CompositeFilterTest::DoSeek(base::TimeDelta time) {
268 ExpectSuccess(SEEK, time);
269 }
270
271 void CompositeFilterTest::ExpectInvalidStateFail(MethodToCall method_to_call,
272 base::TimeDelta seek_time) {
273 InSequence seq;
274 scoped_ptr<StrictMock<MockFilterCallback> > mock_callback(
275 new StrictMock<MockFilterCallback>(false));
276
277 EXPECT_CALL(*mock_filter_host_, SetError(PIPELINE_ERROR_INVALID_STATE))
278 .WillOnce(Return());
279 EXPECT_CALL(*mock_callback, OnFilterCallback());
280
281 DoFilterCall(method_to_call, composite_, seek_time,
282 mock_callback->NewCallback());
283
284 // Make sure that neither of the filters were called by
285 // verifying that the callback pointers weren't set.
286 EXPECT_EQ((FilterCallback*)NULL, filter_1_callback_);
287 EXPECT_EQ((FilterCallback*)NULL, filter_2_callback_);
288 }
289
290 void CompositeFilterTest::RunFilter1Callback() {
291 EXPECT_TRUE(filter_1_callback_ != NULL);
292 FilterCallback* callback = filter_1_callback_;
293 filter_1_callback_ = NULL;
294 callback->Run();
295 delete callback;
296 }
297
298 void CompositeFilterTest::RunFilter2Callback() {
299 EXPECT_TRUE(filter_2_callback_ != NULL);
300 FilterCallback* callback = filter_2_callback_;
301 filter_2_callback_ = NULL;
302 callback->Run();
303 delete callback;
304 }
305
306 static base::Thread* NullThreadFactory(const char* thread_name) {
307 return NULL;
308 }
309
310 // Test AddFilter() failure cases.
311 TEST_F(CompositeFilterTest, TestAddFilterFailCases) {
312 // Test adding a null pointer.
313 EXPECT_FALSE(composite_->AddFilter(NULL));
314
315 scoped_refptr<StrictMock<MockFilter> > filter =
316 new StrictMock<MockFilter>(true);
317 EXPECT_EQ(NULL, filter->host());
318 EXPECT_EQ(NULL, filter->message_loop());
319
320 // Test failing because set_host() hasn't been called yet.
321 EXPECT_FALSE(composite_->AddFilter(filter));
322
323 // Test thread creation failure.
324 composite_ = new CompositeFilter(&message_loop_, &NullThreadFactory);
325 composite_->set_host(mock_filter_host_.get());
326 EXPECT_FALSE(composite_->AddFilter(filter));
327 EXPECT_EQ(NULL, filter->host());
328 EXPECT_EQ(NULL, filter->message_loop());
329 }
330
331 // Test successful AddFilter() cases.
332 TEST_F(CompositeFilterTest, TestAddFilter) {
333 composite_->set_host(mock_filter_host_.get());
334
335 // Add a filter that doesn't require a message loop.
336 scoped_refptr<StrictMock<MockFilter> > filter = new StrictMock<MockFilter>();
337 EXPECT_EQ(NULL, filter->host());
338 EXPECT_EQ(NULL, filter->message_loop());
339
340 EXPECT_TRUE(composite_->AddFilter(filter));
341
342 EXPECT_TRUE(filter->host() != NULL);
343 EXPECT_EQ(NULL, filter->message_loop());
344
345 // Add a filter that requires a message loop.
346 scoped_refptr<StrictMock<MockFilter> > filter_2 =
347 new StrictMock<MockFilter>(true);
348
349 EXPECT_EQ(NULL, filter_2->host());
350 EXPECT_EQ(NULL, filter_2->message_loop());
351
352 EXPECT_TRUE(composite_->AddFilter(filter_2));
353
354 EXPECT_TRUE(filter_2->host() != NULL);
355 EXPECT_TRUE(filter_2->message_loop() != NULL);
356 }
357
358 TEST_F(CompositeFilterTest, TestPlay) {
359 InSequence sequence;
360
361 SetupAndAdd2Filters();
362
363 // Verify successful call to Play().
364 DoPlay();
365
366 // At this point we are now in the kPlaying state.
367 scoped_ptr<StrictMock<MockFilterCallback> > mock_callback(
368 new StrictMock<MockFilterCallback>(false));
369
370 // Try calling Play() again to make sure that we simply get a callback.
371 // We are already in the Play() state so there is no point calling the
372 // filters.
373 EXPECT_CALL(*mock_callback, OnFilterCallback());
374
375 composite_->Play(mock_callback->NewCallback());
376
377 // Verify that neither of the filter callbacks were set.
378 EXPECT_EQ((FilterCallback*)NULL, filter_1_callback_);
379 EXPECT_EQ((FilterCallback*)NULL, filter_2_callback_);
380
381 // Stop playback.
382 DoStop();
383
384 // At this point we should be in the kStopped state.
385
386 // Try calling Stop() again to make sure neither filter is called.
387 EXPECT_CALL(*mock_callback, OnFilterCallback());
388
389 composite_->Stop(mock_callback->NewCallback());
390
391 // Verify that neither of the filter callbacks were set.
392 EXPECT_EQ((FilterCallback*)NULL, filter_1_callback_);
393 EXPECT_EQ((FilterCallback*)NULL, filter_2_callback_);
394
395 // Try calling Play() again to make sure we get an error.
396 ExpectInvalidStateFail(PLAY);
397 }
398
399 // Test errors in the middle of a serial call sequence like Play().
400 TEST_F(CompositeFilterTest, TestPlayErrors) {
401 InSequence sequence;
402
403 SetupAndAdd2Filters();
404
405 scoped_ptr<StrictMock<MockFilterCallback> > mock_callback(
406 new StrictMock<MockFilterCallback>(false));
407
408 EXPECT_CALL(*filter_1_, Play(_));
409
410 // Call Play() on the composite.
411 composite_->Play(mock_callback->NewCallback());
412
413 EXPECT_CALL(*filter_2_, Play(_));
414
415 // Run callback to indicate that |filter_1_|'s Play() has completed.
416 RunFilter1Callback();
417
418 // At this point Play() has been called on |filter_2_|. Simulate an
419 // error by calling SetError() on its FilterHost interface.
420 filter_2_->host()->SetError(PIPELINE_ERROR_OUT_OF_MEMORY);
421
422 // Expect error to be reported and "play done" callback to be called.
423 EXPECT_CALL(*mock_filter_host_, SetError(PIPELINE_ERROR_OUT_OF_MEMORY));
424 EXPECT_CALL(*mock_callback, OnFilterCallback());
425
426 // Run callback to indicate that |filter_2_|'s Play() has completed.
427 RunFilter2Callback();
428
429 // Verify that Play/Pause/Flush/Seek fail now that an error occured.
430 ExpectInvalidStateFail(PLAY);
431 ExpectInvalidStateFail(PAUSE);
432 ExpectInvalidStateFail(FLUSH);
433 ExpectInvalidStateFail(SEEK);
434
435 // Make sure you can still Stop().
436 DoStop();
437 }
438
439 TEST_F(CompositeFilterTest, TestPause) {
440 InSequence sequence;
441
442 SetupAndAdd2Filters();
443
444 scoped_ptr<StrictMock<MockFilterCallback> > mock_callback(
445 new StrictMock<MockFilterCallback>(false));
446
447 // Try calling Pause() to make sure we get an error because we aren't in
448 // the playing state.
449 ExpectInvalidStateFail(PAUSE);
450
451 // Transition to playing state.
452 DoPlay();
453
454 // Issue a successful Pause().
455 DoPause();
456
457 // At this point we are paused.
458
459 // Try calling Pause() again to make sure that the filters aren't called
460 // because we are already in the paused state.
461 EXPECT_CALL(*mock_callback, OnFilterCallback());
462
463 composite_->Pause(mock_callback->NewCallback());
464
465 // Verify that neither of the filter callbacks were set.
466 EXPECT_EQ((FilterCallback*)NULL, filter_1_callback_);
467 EXPECT_EQ((FilterCallback*)NULL, filter_2_callback_);
468
469 // Verify that we can transition pack to the play state.
470 DoPlay();
471
472 // Go back to the pause state.
473 DoPause();
474
475 // Transition to the stop state.
476 DoStop();
477
478 // Try calling Pause() to make sure we get an error because we aren't in
479 // the playing state.
480 ExpectInvalidStateFail(PAUSE);
481 }
482
483 // Test errors in the middle of a serial call sequence like Pause().
484 TEST_F(CompositeFilterTest, TestPauseErrors) {
485 InSequence sequence;
486
487 SetupAndAdd2Filters();
488
489 DoPlay();
490
491 scoped_ptr<StrictMock<MockFilterCallback> > mock_callback(
492 new StrictMock<MockFilterCallback>(false));
493
494 EXPECT_CALL(*filter_1_, Pause(_));
495
496 // Call Pause() on the composite.
497 composite_->Pause(mock_callback->NewCallback());
498
499 // Simulate an error by calling SetError() on |filter_1_|'s FilterHost
500 // interface.
501 filter_1_->host()->SetError(PIPELINE_ERROR_OUT_OF_MEMORY);
502
503 // Expect error to be reported and "pause done" callback to be called.
504 EXPECT_CALL(*mock_filter_host_, SetError(PIPELINE_ERROR_OUT_OF_MEMORY));
505 EXPECT_CALL(*mock_callback, OnFilterCallback());
506
507 RunFilter1Callback();
508
509 // Make sure |filter_2_callback_| was not set.
510 EXPECT_EQ((FilterCallback*)NULL, filter_2_callback_);
511
512 // Verify that Play/Pause/Flush/Seek fail now that an error occured.
513 ExpectInvalidStateFail(PLAY);
514 ExpectInvalidStateFail(PAUSE);
515 ExpectInvalidStateFail(FLUSH);
516 ExpectInvalidStateFail(SEEK);
517
518 // Make sure you can still Stop().
519 DoStop();
520 }
521
522 TEST_F(CompositeFilterTest, TestFlush) {
523 InSequence sequence;
524
525 SetupAndAdd2Filters();
526
527 scoped_ptr<StrictMock<MockFilterCallback> > mock_callback(
528 new StrictMock<MockFilterCallback>(false));
529
530 // Make sure Flush() works before calling Play().
531 DoFlush();
532
533 // Transition to playing state.
534 DoPlay();
535
536 // Call Flush() to make sure we get an error because we are in
537 // the playing state.
538 ExpectInvalidStateFail(FLUSH);
539
540 // Issue a successful Pause().
541 DoPause();
542
543 // Make sure Flush() works after pausing.
544 DoFlush();
545
546 // Verify that we can transition back to the play state.
547 DoPlay();
548
549 // Transition to the stop state.
550 DoStop();
551
552 // Try calling Flush() to make sure we get an error because we are stopped.
553 ExpectInvalidStateFail(FLUSH);
554 }
555
556 // Test errors in the middle of a parallel call sequence like Flush().
557 TEST_F(CompositeFilterTest, TestFlushErrors) {
558 InSequence sequence;
559
560 SetupAndAdd2Filters();
561
562 scoped_ptr<StrictMock<MockFilterCallback> > mock_callback(
563 new StrictMock<MockFilterCallback>(false));
564
565 EXPECT_CALL(*filter_1_, Flush(_));
566 EXPECT_CALL(*filter_2_, Flush(_));
567
568 // Call Flush() on the composite.
569 composite_->Flush(mock_callback->NewCallback());
570
571 // Simulate an error by calling SetError() on |filter_1_|'s FilterHost
572 // interface.
573 filter_1_->host()->SetError(PIPELINE_ERROR_OUT_OF_MEMORY);
574
575 RunFilter1Callback();
576
577 // Expect error to be reported and "pause done" callback to be called.
578 EXPECT_CALL(*mock_filter_host_, SetError(PIPELINE_ERROR_OUT_OF_MEMORY));
579 EXPECT_CALL(*mock_callback, OnFilterCallback());
580
581 RunFilter2Callback();
582
583 // Verify that Play/Pause/Flush/Seek fail now that an error occured.
584 ExpectInvalidStateFail(PLAY);
585 ExpectInvalidStateFail(PAUSE);
586 ExpectInvalidStateFail(FLUSH);
587 ExpectInvalidStateFail(SEEK);
588
589 // Make sure you can still Stop().
590 DoStop();
591 }
592
593 TEST_F(CompositeFilterTest, TestSeek) {
594 InSequence sequence;
595
596 SetupAndAdd2Filters();
597
598 // Verify that seek is allowed to be called before a Play() call.
599 DoSeek(base::TimeDelta::FromSeconds(5));
600
601 // Verify we can issue a Play() after the Seek().
602 DoPlay();
603
604 scoped_ptr<StrictMock<MockFilterCallback> > mock_callback(
605 new StrictMock<MockFilterCallback>(false));
606
607 // Try calling Seek() while playing to make sure we get an error.
608 ExpectInvalidStateFail(SEEK);
609
610 // Transition to paused state.
611 DoPause();
612
613 // Verify that seek is allowed after pausing.
614 DoSeek(base::TimeDelta::FromSeconds(5));
615
616 // Verify we can still play again.
617 DoPlay();
618
619 // Stop playback.
620 DoStop();
621
622 // Try calling Seek() to make sure we get an error.
623 ExpectInvalidStateFail(SEEK);
624 }
625
626 TEST_F(CompositeFilterTest, TestStop) {
627 InSequence sequence;
628
629 // Test Stop() before any other call.
630 SetupAndAdd2Filters();
631 DoStop();
632
633 // Test error during Stop() sequence.
634 SetupAndAdd2Filters();
635 scoped_ptr<StrictMock<MockFilterCallback> > mock_callback(
636 new StrictMock<MockFilterCallback>(false));
637
638 EXPECT_CALL(*filter_1_, Stop(_));
639
640 composite_->Stop(mock_callback->NewCallback());
641
642 // Have |filter_1_| signal an error.
643 filter_1_->host()->SetError(PIPELINE_ERROR_READ);
644
645 EXPECT_CALL(*filter_2_, Stop(_));
646
647 RunFilter1Callback();
648
649 EXPECT_CALL(*mock_callback, OnFilterCallback());
650
651 RunFilter2Callback();
652 }
653
654 // Test stopping in the middle of a serial call sequence.
655 TEST_F(CompositeFilterTest, TestStopWhilePlayPending) {
656 InSequence sequence;
657
658 SetupAndAdd2Filters();
659
660 scoped_ptr<StrictMock<MockFilterCallback> > mock_callback(
661 new StrictMock<MockFilterCallback>());
662
663 EXPECT_CALL(*filter_1_, Play(_));
664
665 composite_->Play(mock_callback->NewCallback());
666
667 // Note: Play() is pending on |filter_1_| right now.
668
669 scoped_ptr<StrictMock<MockFilterCallback> > mock_callback_2(
670 new StrictMock<MockFilterCallback>(false));
671
672 EXPECT_CALL(*mock_callback, OnCallbackDestroyed());
673
674 composite_->Stop(mock_callback_2->NewCallback());
675
676 EXPECT_CALL(*filter_1_, Stop(_));
677
678 // Run |filter_1_|'s callback again to indicate Play() has completed.
679 RunFilter1Callback();
680
681 EXPECT_CALL(*filter_2_, Stop(_));
682
683 // Run |filter_1_|'s callback again to indicate Stop() has completed.
684 RunFilter1Callback();
685
686 EXPECT_CALL(*mock_callback_2, OnFilterCallback());
687
688 // Run |filter_2_|'s callback to indicate Stop() has completed.
689 RunFilter2Callback();
690 }
691
692 // Test stopping in the middle of a parallel call sequence.
693 TEST_F(CompositeFilterTest, TestStopWhileFlushPending) {
694 InSequence sequence;
695
696 SetupAndAdd2Filters();
697
698 scoped_ptr<StrictMock<MockFilterCallback> > mock_callback(
699 new StrictMock<MockFilterCallback>());
700
701 EXPECT_CALL(*filter_1_, Flush(_));
702 EXPECT_CALL(*filter_2_, Flush(_));
703
704 composite_->Flush(mock_callback->NewCallback());
705
706 // Note: |filter_1_| and |filter_2_| have pending Flush() calls at this point.
707
708 scoped_ptr<StrictMock<MockFilterCallback> > mock_callback_2(
709 new StrictMock<MockFilterCallback>(false));
710
711 EXPECT_CALL(*mock_callback, OnCallbackDestroyed());
712
713 composite_->Stop(mock_callback_2->NewCallback());
714
715 // Run callback to indicate that |filter_1_|'s Flush() has completed.
716 RunFilter1Callback();
717
718 EXPECT_CALL(*filter_1_, Stop(_));
719
720 // Run callback to indicate that |filter_2_|'s Flush() has completed.
721 RunFilter2Callback();
722
723 EXPECT_CALL(*filter_2_, Stop(_));
724
725 // Run callback to indicate that |filter_1_|'s Stop() has completed.
726 RunFilter1Callback();
727
728 EXPECT_CALL(*mock_callback_2, OnFilterCallback());
729
730 // Run callback to indicate that |filter_2_|'s Stop() has completed.
731 RunFilter2Callback();
732 }
733
734 TEST_F(CompositeFilterTest, TestErrorWhilePlaying) {
735 InSequence sequence;
736
737 SetupAndAdd2Filters();
738
739 // Simulate an error on |filter_2_| while in kCreated state. This
740 // can happen if an error occurs during filter initialization.
741 EXPECT_CALL(*mock_filter_host_, SetError(PIPELINE_ERROR_OUT_OF_MEMORY));
742 filter_2_->host()->SetError(PIPELINE_ERROR_OUT_OF_MEMORY);
743
744 DoPlay();
745
746 // Simulate an error on |filter_2_| while playing.
747 EXPECT_CALL(*mock_filter_host_, SetError(PIPELINE_ERROR_OUT_OF_MEMORY));
748 filter_2_->host()->SetError(PIPELINE_ERROR_OUT_OF_MEMORY);
749
750 DoPause();
751
752 // Simulate an error on |filter_2_| while paused.
753 EXPECT_CALL(*mock_filter_host_, SetError(PIPELINE_ERROR_NETWORK));
754 filter_2_->host()->SetError(PIPELINE_ERROR_NETWORK);
755
756 DoStop();
757
758 // Verify that errors are not passed to |mock_filter_host_|
759 // after Stop() has been called.
760 filter_2_->host()->SetError(PIPELINE_ERROR_NETWORK);
761 }
762
763 // Make sure that state transitions act as expected even
764 // if the composite doesn't contain any filters.
765 TEST_F(CompositeFilterTest, TestEmptyComposite) {
766 InSequence sequence;
767
768 composite_->set_host(mock_filter_host_.get());
769
770 scoped_ptr<StrictMock<MockFilterCallback> > mock_callback(
771 new StrictMock<MockFilterCallback>(false));
772
773 // Issue a Play() and expect no errors.
774 EXPECT_CALL(*mock_callback, OnFilterCallback());
775 composite_->Play(mock_callback->NewCallback());
776
777 // Issue a Pause() and expect no errors.
778 EXPECT_CALL(*mock_callback, OnFilterCallback());
779 composite_->Pause(mock_callback->NewCallback());
780
781 // Issue a Flush() and expect no errors.
782 EXPECT_CALL(*mock_callback, OnFilterCallback());
783 composite_->Flush(mock_callback->NewCallback());
784
785 // Issue a Seek() and expect no errors.
786 EXPECT_CALL(*mock_callback, OnFilterCallback());
787 composite_->Seek(base::TimeDelta::FromSeconds(5),
788 mock_callback->NewCallback());
789
790 // Issue a Play() and expect no errors.
791 EXPECT_CALL(*mock_callback, OnFilterCallback());
792 composite_->Play(mock_callback->NewCallback());
793
794 // Issue a Stop() and expect no errors.
795 EXPECT_CALL(*mock_callback, OnFilterCallback());
796 composite_->Stop(mock_callback->NewCallback());
797 }
798
799 } // namespace media
OLDNEW
« no previous file with comments | « media/base/composite_filter.cc ('k') | media/base/mock_filters.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698