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

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

Issue 6350001: Replace MockFilterCallback with MockCallback and simplify unit tests. (Closed) Base URL: svn://chrome-svn/chrome/trunk/src
Patch Set: copyright years 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 | « no previous file | media/base/mock_callback.h » ('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) 2010 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 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/composite_filter.h" 5 #include "media/base/composite_filter.h"
6 #include "media/base/mock_callback.h"
6 #include "media/base/mock_filter_host.h" 7 #include "media/base/mock_filter_host.h"
7 #include "media/base/mock_filters.h" 8 #include "media/base/mock_filters.h"
8 #include "testing/gtest/include/gtest/gtest.h" 9 #include "testing/gtest/include/gtest/gtest.h"
9 10
10 using ::testing::_; 11 using ::testing::_;
11 using ::testing::InSequence; 12 using ::testing::InSequence;
12 using ::testing::Return; 13 using ::testing::Return;
13 using ::testing::SaveArg; 14 using ::testing::SaveArg;
14 using ::testing::StrictMock; 15 using ::testing::StrictMock;
15 16
(...skipping 186 matching lines...) Expand 10 before | Expand all | Expand 10 after
202 case SEEK: 203 case SEEK:
203 filter->Seek(seek_time, callback); 204 filter->Seek(seek_time, callback);
204 break; 205 break;
205 }; 206 };
206 } 207 }
207 208
208 void CompositeFilterTest::ExpectSuccess(MethodToCall method_to_call, 209 void CompositeFilterTest::ExpectSuccess(MethodToCall method_to_call,
209 base::TimeDelta seek_time) { 210 base::TimeDelta seek_time) {
210 InSequence seq; 211 InSequence seq;
211 212
212 scoped_ptr<StrictMock<MockFilterCallback> > mock_callback(
213 new StrictMock<MockFilterCallback>(false));
214
215 bool is_parallel_call = (method_to_call == FLUSH); 213 bool is_parallel_call = (method_to_call == FLUSH);
216 214
217 ExpectFilterCall(method_to_call, filter_1_.get(), seek_time); 215 ExpectFilterCall(method_to_call, filter_1_.get(), seek_time);
218 216
219 if (is_parallel_call) { 217 if (is_parallel_call) {
220 ExpectFilterCall(method_to_call, filter_2_.get(), seek_time); 218 ExpectFilterCall(method_to_call, filter_2_.get(), seek_time);
221 } 219 }
222 220
223 // Make method call on the composite. 221 // Make method call on the composite.
224 DoFilterCall(method_to_call, composite_.get(), seek_time, 222 StrictMock<MockCallback>* callback = new StrictMock<MockCallback>();
225 mock_callback->NewCallback()); 223 DoFilterCall(method_to_call, composite_.get(), seek_time, callback);
226 224
227 if (is_parallel_call) { 225 if (is_parallel_call) {
228 // Make sure both filters have their callbacks set. 226 // Make sure both filters have their callbacks set.
229 EXPECT_TRUE(filter_1_callback_ != NULL); 227 EXPECT_TRUE(filter_1_callback_ != NULL);
230 EXPECT_TRUE(filter_2_callback_ != NULL); 228 EXPECT_TRUE(filter_2_callback_ != NULL);
231 229
232 RunFilter1Callback(); 230 RunFilter1Callback();
233 } else { 231 } else {
234 // Make sure that only |filter_1_| has its callback set. 232 // Make sure that only |filter_1_| has its callback set.
235 EXPECT_TRUE(filter_1_callback_ != NULL); 233 EXPECT_TRUE(filter_1_callback_ != NULL);
236 EXPECT_EQ((FilterCallback*)NULL, filter_2_callback_); 234 EXPECT_EQ((FilterCallback*)NULL, filter_2_callback_);
237 235
238 ExpectFilterCall(method_to_call, filter_2_.get(), seek_time); 236 ExpectFilterCall(method_to_call, filter_2_.get(), seek_time);
239 237
240 RunFilter1Callback(); 238 RunFilter1Callback();
241 239
242 // Verify that |filter_2_| was called by checking the callback pointer. 240 // Verify that |filter_2_| was called by checking the callback pointer.
243 EXPECT_TRUE(filter_2_callback_ != NULL); 241 EXPECT_TRUE(filter_2_callback_ != NULL);
244 } 242 }
245 243
246 EXPECT_CALL(*mock_callback, OnFilterCallback()); 244 EXPECT_CALL(*callback, RunWithParams(_));
acolwell GONE FROM CHROMIUM 2011/01/14 19:29:14 Perhaps create a ExpectRunAndDestroy() method on t
scherkus (not reviewing) 2011/01/15 02:11:09 I like it! Done.
245 EXPECT_CALL(*callback, Destructor());
247 246
248 RunFilter2Callback(); 247 RunFilter2Callback();
249 } 248 }
250 249
251 void CompositeFilterTest::DoPlay() { 250 void CompositeFilterTest::DoPlay() {
252 ExpectSuccess(PLAY); 251 ExpectSuccess(PLAY);
253 } 252 }
254 253
255 void CompositeFilterTest::DoPause() { 254 void CompositeFilterTest::DoPause() {
256 ExpectSuccess(PAUSE); 255 ExpectSuccess(PAUSE);
257 } 256 }
258 257
259 void CompositeFilterTest::DoFlush() { 258 void CompositeFilterTest::DoFlush() {
260 ExpectSuccess(FLUSH); 259 ExpectSuccess(FLUSH);
261 } 260 }
262 261
263 void CompositeFilterTest::DoStop() { 262 void CompositeFilterTest::DoStop() {
264 ExpectSuccess(STOP); 263 ExpectSuccess(STOP);
265 } 264 }
266 265
267 void CompositeFilterTest::DoSeek(base::TimeDelta time) { 266 void CompositeFilterTest::DoSeek(base::TimeDelta time) {
268 ExpectSuccess(SEEK, time); 267 ExpectSuccess(SEEK, time);
269 } 268 }
270 269
271 void CompositeFilterTest::ExpectInvalidStateFail(MethodToCall method_to_call, 270 void CompositeFilterTest::ExpectInvalidStateFail(MethodToCall method_to_call,
272 base::TimeDelta seek_time) { 271 base::TimeDelta seek_time) {
273 InSequence seq; 272 InSequence seq;
274 scoped_ptr<StrictMock<MockFilterCallback> > mock_callback(
275 new StrictMock<MockFilterCallback>(false));
276 273
277 EXPECT_CALL(*mock_filter_host_, SetError(PIPELINE_ERROR_INVALID_STATE)) 274 EXPECT_CALL(*mock_filter_host_, SetError(PIPELINE_ERROR_INVALID_STATE))
278 .WillOnce(Return()); 275 .WillOnce(Return());
279 EXPECT_CALL(*mock_callback, OnFilterCallback());
280 276
281 DoFilterCall(method_to_call, composite_, seek_time, 277 DoFilterCall(method_to_call, composite_, seek_time, NewExpectedCallback());
282 mock_callback->NewCallback());
283 278
284 // Make sure that neither of the filters were called by 279 // Make sure that neither of the filters were called by
285 // verifying that the callback pointers weren't set. 280 // verifying that the callback pointers weren't set.
286 EXPECT_EQ((FilterCallback*)NULL, filter_1_callback_); 281 EXPECT_EQ((FilterCallback*)NULL, filter_1_callback_);
287 EXPECT_EQ((FilterCallback*)NULL, filter_2_callback_); 282 EXPECT_EQ((FilterCallback*)NULL, filter_2_callback_);
288 } 283 }
289 284
290 void CompositeFilterTest::RunFilter1Callback() { 285 void CompositeFilterTest::RunFilter1Callback() {
291 EXPECT_TRUE(filter_1_callback_ != NULL); 286 EXPECT_TRUE(filter_1_callback_ != NULL);
292 FilterCallback* callback = filter_1_callback_; 287 FilterCallback* callback = filter_1_callback_;
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after
357 352
358 TEST_F(CompositeFilterTest, TestPlay) { 353 TEST_F(CompositeFilterTest, TestPlay) {
359 InSequence sequence; 354 InSequence sequence;
360 355
361 SetupAndAdd2Filters(); 356 SetupAndAdd2Filters();
362 357
363 // Verify successful call to Play(). 358 // Verify successful call to Play().
364 DoPlay(); 359 DoPlay();
365 360
366 // At this point we are now in the kPlaying state. 361 // At this point we are now in the kPlaying state.
367 scoped_ptr<StrictMock<MockFilterCallback> > mock_callback(
368 new StrictMock<MockFilterCallback>(false));
369 362
370 // Try calling Play() again to make sure that we simply get a callback. 363 // 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 364 // We are already in the Play() state so there is no point calling the
372 // filters. 365 // filters.
373 EXPECT_CALL(*mock_callback, OnFilterCallback()); 366 composite_->Play(NewExpectedCallback());
374
375 composite_->Play(mock_callback->NewCallback());
376 367
377 // Verify that neither of the filter callbacks were set. 368 // Verify that neither of the filter callbacks were set.
378 EXPECT_EQ((FilterCallback*)NULL, filter_1_callback_); 369 EXPECT_EQ((FilterCallback*)NULL, filter_1_callback_);
379 EXPECT_EQ((FilterCallback*)NULL, filter_2_callback_); 370 EXPECT_EQ((FilterCallback*)NULL, filter_2_callback_);
380 371
381 // Stop playback. 372 // Stop playback.
382 DoStop(); 373 DoStop();
383 374
384 // At this point we should be in the kStopped state. 375 // At this point we should be in the kStopped state.
385 376
386 // Try calling Stop() again to make sure neither filter is called. 377 // Try calling Stop() again to make sure neither filter is called.
387 EXPECT_CALL(*mock_callback, OnFilterCallback()); 378 composite_->Stop(NewExpectedCallback());
388
389 composite_->Stop(mock_callback->NewCallback());
390 379
391 // Verify that neither of the filter callbacks were set. 380 // Verify that neither of the filter callbacks were set.
392 EXPECT_EQ((FilterCallback*)NULL, filter_1_callback_); 381 EXPECT_EQ((FilterCallback*)NULL, filter_1_callback_);
393 EXPECT_EQ((FilterCallback*)NULL, filter_2_callback_); 382 EXPECT_EQ((FilterCallback*)NULL, filter_2_callback_);
394 383
395 // Try calling Play() again to make sure we get an error. 384 // Try calling Play() again to make sure we get an error.
396 ExpectInvalidStateFail(PLAY); 385 ExpectInvalidStateFail(PLAY);
397 } 386 }
398 387
399 // Test errors in the middle of a serial call sequence like Play(). 388 // Test errors in the middle of a serial call sequence like Play().
400 TEST_F(CompositeFilterTest, TestPlayErrors) { 389 TEST_F(CompositeFilterTest, TestPlayErrors) {
401 InSequence sequence; 390 InSequence sequence;
402 391
403 SetupAndAdd2Filters(); 392 SetupAndAdd2Filters();
404 393
405 scoped_ptr<StrictMock<MockFilterCallback> > mock_callback(
406 new StrictMock<MockFilterCallback>(false));
407
408 EXPECT_CALL(*filter_1_, Play(_)); 394 EXPECT_CALL(*filter_1_, Play(_));
409 395
410 // Call Play() on the composite. 396 // Call Play() on the composite.
411 composite_->Play(mock_callback->NewCallback()); 397 StrictMock<MockCallback>* callback = new StrictMock<MockCallback>();
398 composite_->Play(callback);
412 399
413 EXPECT_CALL(*filter_2_, Play(_)); 400 EXPECT_CALL(*filter_2_, Play(_));
414 401
415 // Run callback to indicate that |filter_1_|'s Play() has completed. 402 // Run callback to indicate that |filter_1_|'s Play() has completed.
416 RunFilter1Callback(); 403 RunFilter1Callback();
417 404
418 // At this point Play() has been called on |filter_2_|. Simulate an 405 // At this point Play() has been called on |filter_2_|. Simulate an
419 // error by calling SetError() on its FilterHost interface. 406 // error by calling SetError() on its FilterHost interface.
420 filter_2_->host()->SetError(PIPELINE_ERROR_OUT_OF_MEMORY); 407 filter_2_->host()->SetError(PIPELINE_ERROR_OUT_OF_MEMORY);
421 408
422 // Expect error to be reported and "play done" callback to be called. 409 // Expect error to be reported and "play done" callback to be called.
423 EXPECT_CALL(*mock_filter_host_, SetError(PIPELINE_ERROR_OUT_OF_MEMORY)); 410 EXPECT_CALL(*mock_filter_host_, SetError(PIPELINE_ERROR_OUT_OF_MEMORY));
424 EXPECT_CALL(*mock_callback, OnFilterCallback()); 411 EXPECT_CALL(*callback, RunWithParams(_));
412 EXPECT_CALL(*callback, Destructor());
425 413
426 // Run callback to indicate that |filter_2_|'s Play() has completed. 414 // Run callback to indicate that |filter_2_|'s Play() has completed.
427 RunFilter2Callback(); 415 RunFilter2Callback();
428 416
429 // Verify that Play/Pause/Flush/Seek fail now that an error occured. 417 // Verify that Play/Pause/Flush/Seek fail now that an error occured.
430 ExpectInvalidStateFail(PLAY); 418 ExpectInvalidStateFail(PLAY);
431 ExpectInvalidStateFail(PAUSE); 419 ExpectInvalidStateFail(PAUSE);
432 ExpectInvalidStateFail(FLUSH); 420 ExpectInvalidStateFail(FLUSH);
433 ExpectInvalidStateFail(SEEK); 421 ExpectInvalidStateFail(SEEK);
434 422
435 // Make sure you can still Stop(). 423 // Make sure you can still Stop().
436 DoStop(); 424 DoStop();
437 } 425 }
438 426
439 TEST_F(CompositeFilterTest, TestPause) { 427 TEST_F(CompositeFilterTest, TestPause) {
440 InSequence sequence; 428 InSequence sequence;
441 429
442 SetupAndAdd2Filters(); 430 SetupAndAdd2Filters();
443 431
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 432 // Try calling Pause() to make sure we get an error because we aren't in
448 // the playing state. 433 // the playing state.
449 ExpectInvalidStateFail(PAUSE); 434 ExpectInvalidStateFail(PAUSE);
450 435
451 // Transition to playing state. 436 // Transition to playing state.
452 DoPlay(); 437 DoPlay();
453 438
454 // Issue a successful Pause(). 439 // Issue a successful Pause().
455 DoPause(); 440 DoPause();
456 441
457 // At this point we are paused. 442 // At this point we are paused.
458 443
459 // Try calling Pause() again to make sure that the filters aren't called 444 // Try calling Pause() again to make sure that the filters aren't called
460 // because we are already in the paused state. 445 // because we are already in the paused state.
461 EXPECT_CALL(*mock_callback, OnFilterCallback()); 446 composite_->Pause(NewExpectedCallback());
462
463 composite_->Pause(mock_callback->NewCallback());
464 447
465 // Verify that neither of the filter callbacks were set. 448 // Verify that neither of the filter callbacks were set.
466 EXPECT_EQ((FilterCallback*)NULL, filter_1_callback_); 449 EXPECT_EQ((FilterCallback*)NULL, filter_1_callback_);
467 EXPECT_EQ((FilterCallback*)NULL, filter_2_callback_); 450 EXPECT_EQ((FilterCallback*)NULL, filter_2_callback_);
468 451
469 // Verify that we can transition pack to the play state. 452 // Verify that we can transition pack to the play state.
470 DoPlay(); 453 DoPlay();
471 454
472 // Go back to the pause state. 455 // Go back to the pause state.
473 DoPause(); 456 DoPause();
474 457
475 // Transition to the stop state. 458 // Transition to the stop state.
476 DoStop(); 459 DoStop();
477 460
478 // Try calling Pause() to make sure we get an error because we aren't in 461 // Try calling Pause() to make sure we get an error because we aren't in
479 // the playing state. 462 // the playing state.
480 ExpectInvalidStateFail(PAUSE); 463 ExpectInvalidStateFail(PAUSE);
481 } 464 }
482 465
483 // Test errors in the middle of a serial call sequence like Pause(). 466 // Test errors in the middle of a serial call sequence like Pause().
484 TEST_F(CompositeFilterTest, TestPauseErrors) { 467 TEST_F(CompositeFilterTest, TestPauseErrors) {
485 InSequence sequence; 468 InSequence sequence;
486 469
487 SetupAndAdd2Filters(); 470 SetupAndAdd2Filters();
488 471
489 DoPlay(); 472 DoPlay();
490 473
491 scoped_ptr<StrictMock<MockFilterCallback> > mock_callback(
492 new StrictMock<MockFilterCallback>(false));
493
494 EXPECT_CALL(*filter_1_, Pause(_)); 474 EXPECT_CALL(*filter_1_, Pause(_));
495 475
496 // Call Pause() on the composite. 476 // Call Pause() on the composite.
497 composite_->Pause(mock_callback->NewCallback()); 477 StrictMock<MockCallback>* callback = new StrictMock<MockCallback>();
478 composite_->Pause(callback);
498 479
499 // Simulate an error by calling SetError() on |filter_1_|'s FilterHost 480 // Simulate an error by calling SetError() on |filter_1_|'s FilterHost
500 // interface. 481 // interface.
501 filter_1_->host()->SetError(PIPELINE_ERROR_OUT_OF_MEMORY); 482 filter_1_->host()->SetError(PIPELINE_ERROR_OUT_OF_MEMORY);
502 483
503 // Expect error to be reported and "pause done" callback to be called. 484 // Expect error to be reported and "pause done" callback to be called.
504 EXPECT_CALL(*mock_filter_host_, SetError(PIPELINE_ERROR_OUT_OF_MEMORY)); 485 EXPECT_CALL(*mock_filter_host_, SetError(PIPELINE_ERROR_OUT_OF_MEMORY));
505 EXPECT_CALL(*mock_callback, OnFilterCallback()); 486 EXPECT_CALL(*callback, RunWithParams(_));
487 EXPECT_CALL(*callback, Destructor());
506 488
507 RunFilter1Callback(); 489 RunFilter1Callback();
508 490
509 // Make sure |filter_2_callback_| was not set. 491 // Make sure |filter_2_callback_| was not set.
510 EXPECT_EQ((FilterCallback*)NULL, filter_2_callback_); 492 EXPECT_EQ((FilterCallback*)NULL, filter_2_callback_);
511 493
512 // Verify that Play/Pause/Flush/Seek fail now that an error occured. 494 // Verify that Play/Pause/Flush/Seek fail now that an error occured.
513 ExpectInvalidStateFail(PLAY); 495 ExpectInvalidStateFail(PLAY);
514 ExpectInvalidStateFail(PAUSE); 496 ExpectInvalidStateFail(PAUSE);
515 ExpectInvalidStateFail(FLUSH); 497 ExpectInvalidStateFail(FLUSH);
516 ExpectInvalidStateFail(SEEK); 498 ExpectInvalidStateFail(SEEK);
517 499
518 // Make sure you can still Stop(). 500 // Make sure you can still Stop().
519 DoStop(); 501 DoStop();
520 } 502 }
521 503
522 TEST_F(CompositeFilterTest, TestFlush) { 504 TEST_F(CompositeFilterTest, TestFlush) {
523 InSequence sequence; 505 InSequence sequence;
524 506
525 SetupAndAdd2Filters(); 507 SetupAndAdd2Filters();
526 508
527 scoped_ptr<StrictMock<MockFilterCallback> > mock_callback(
528 new StrictMock<MockFilterCallback>(false));
529
530 // Make sure Flush() works before calling Play(). 509 // Make sure Flush() works before calling Play().
531 DoFlush(); 510 DoFlush();
532 511
533 // Transition to playing state. 512 // Transition to playing state.
534 DoPlay(); 513 DoPlay();
535 514
536 // Call Flush() to make sure we get an error because we are in 515 // Call Flush() to make sure we get an error because we are in
537 // the playing state. 516 // the playing state.
538 ExpectInvalidStateFail(FLUSH); 517 ExpectInvalidStateFail(FLUSH);
539 518
(...skipping 12 matching lines...) Expand all
552 // Try calling Flush() to make sure we get an error because we are stopped. 531 // Try calling Flush() to make sure we get an error because we are stopped.
553 ExpectInvalidStateFail(FLUSH); 532 ExpectInvalidStateFail(FLUSH);
554 } 533 }
555 534
556 // Test errors in the middle of a parallel call sequence like Flush(). 535 // Test errors in the middle of a parallel call sequence like Flush().
557 TEST_F(CompositeFilterTest, TestFlushErrors) { 536 TEST_F(CompositeFilterTest, TestFlushErrors) {
558 InSequence sequence; 537 InSequence sequence;
559 538
560 SetupAndAdd2Filters(); 539 SetupAndAdd2Filters();
561 540
562 scoped_ptr<StrictMock<MockFilterCallback> > mock_callback(
563 new StrictMock<MockFilterCallback>(false));
564
565 EXPECT_CALL(*filter_1_, Flush(_)); 541 EXPECT_CALL(*filter_1_, Flush(_));
566 EXPECT_CALL(*filter_2_, Flush(_)); 542 EXPECT_CALL(*filter_2_, Flush(_));
567 543
568 // Call Flush() on the composite. 544 // Call Flush() on the composite.
569 composite_->Flush(mock_callback->NewCallback()); 545 StrictMock<MockCallback>* callback = new StrictMock<MockCallback>();
546 composite_->Flush(callback);
570 547
571 // Simulate an error by calling SetError() on |filter_1_|'s FilterHost 548 // Simulate an error by calling SetError() on |filter_1_|'s FilterHost
572 // interface. 549 // interface.
573 filter_1_->host()->SetError(PIPELINE_ERROR_OUT_OF_MEMORY); 550 filter_1_->host()->SetError(PIPELINE_ERROR_OUT_OF_MEMORY);
574 551
575 RunFilter1Callback(); 552 RunFilter1Callback();
576 553
577 // Expect error to be reported and "pause done" callback to be called. 554 // Expect error to be reported and "pause done" callback to be called.
578 EXPECT_CALL(*mock_filter_host_, SetError(PIPELINE_ERROR_OUT_OF_MEMORY)); 555 EXPECT_CALL(*mock_filter_host_, SetError(PIPELINE_ERROR_OUT_OF_MEMORY));
579 EXPECT_CALL(*mock_callback, OnFilterCallback()); 556 EXPECT_CALL(*callback, RunWithParams(_));
557 EXPECT_CALL(*callback, Destructor());
580 558
581 RunFilter2Callback(); 559 RunFilter2Callback();
582 560
583 // Verify that Play/Pause/Flush/Seek fail now that an error occured. 561 // Verify that Play/Pause/Flush/Seek fail now that an error occured.
584 ExpectInvalidStateFail(PLAY); 562 ExpectInvalidStateFail(PLAY);
585 ExpectInvalidStateFail(PAUSE); 563 ExpectInvalidStateFail(PAUSE);
586 ExpectInvalidStateFail(FLUSH); 564 ExpectInvalidStateFail(FLUSH);
587 ExpectInvalidStateFail(SEEK); 565 ExpectInvalidStateFail(SEEK);
588 566
589 // Make sure you can still Stop(). 567 // Make sure you can still Stop().
590 DoStop(); 568 DoStop();
591 } 569 }
592 570
593 TEST_F(CompositeFilterTest, TestSeek) { 571 TEST_F(CompositeFilterTest, TestSeek) {
594 InSequence sequence; 572 InSequence sequence;
595 573
596 SetupAndAdd2Filters(); 574 SetupAndAdd2Filters();
597 575
598 // Verify that seek is allowed to be called before a Play() call. 576 // Verify that seek is allowed to be called before a Play() call.
599 DoSeek(base::TimeDelta::FromSeconds(5)); 577 DoSeek(base::TimeDelta::FromSeconds(5));
600 578
601 // Verify we can issue a Play() after the Seek(). 579 // Verify we can issue a Play() after the Seek().
602 DoPlay(); 580 DoPlay();
603 581
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. 582 // Try calling Seek() while playing to make sure we get an error.
608 ExpectInvalidStateFail(SEEK); 583 ExpectInvalidStateFail(SEEK);
609 584
610 // Transition to paused state. 585 // Transition to paused state.
611 DoPause(); 586 DoPause();
612 587
613 // Verify that seek is allowed after pausing. 588 // Verify that seek is allowed after pausing.
614 DoSeek(base::TimeDelta::FromSeconds(5)); 589 DoSeek(base::TimeDelta::FromSeconds(5));
615 590
616 // Verify we can still play again. 591 // Verify we can still play again.
617 DoPlay(); 592 DoPlay();
618 593
619 // Stop playback. 594 // Stop playback.
620 DoStop(); 595 DoStop();
621 596
622 // Try calling Seek() to make sure we get an error. 597 // Try calling Seek() to make sure we get an error.
623 ExpectInvalidStateFail(SEEK); 598 ExpectInvalidStateFail(SEEK);
624 } 599 }
625 600
626 TEST_F(CompositeFilterTest, TestStop) { 601 TEST_F(CompositeFilterTest, TestStop) {
627 InSequence sequence; 602 InSequence sequence;
628 603
629 // Test Stop() before any other call. 604 // Test Stop() before any other call.
630 SetupAndAdd2Filters(); 605 SetupAndAdd2Filters();
631 DoStop(); 606 DoStop();
632 607
633 // Test error during Stop() sequence. 608 // Test error during Stop() sequence.
634 SetupAndAdd2Filters(); 609 SetupAndAdd2Filters();
635 scoped_ptr<StrictMock<MockFilterCallback> > mock_callback(
636 new StrictMock<MockFilterCallback>(false));
637 610
638 EXPECT_CALL(*filter_1_, Stop(_)); 611 EXPECT_CALL(*filter_1_, Stop(_));
639 612
640 composite_->Stop(mock_callback->NewCallback()); 613 StrictMock<MockCallback>* callback = new StrictMock<MockCallback>();
614 composite_->Stop(callback);
641 615
642 // Have |filter_1_| signal an error. 616 // Have |filter_1_| signal an error.
643 filter_1_->host()->SetError(PIPELINE_ERROR_READ); 617 filter_1_->host()->SetError(PIPELINE_ERROR_READ);
644 618
645 EXPECT_CALL(*filter_2_, Stop(_)); 619 EXPECT_CALL(*filter_2_, Stop(_));
646 620
647 RunFilter1Callback(); 621 RunFilter1Callback();
648 622
649 EXPECT_CALL(*mock_callback, OnFilterCallback()); 623 EXPECT_CALL(*callback, RunWithParams(_));
624 EXPECT_CALL(*callback, Destructor());
650 625
651 RunFilter2Callback(); 626 RunFilter2Callback();
652 } 627 }
653 628
654 // Test stopping in the middle of a serial call sequence. 629 // Test stopping in the middle of a serial call sequence.
655 TEST_F(CompositeFilterTest, TestStopWhilePlayPending) { 630 TEST_F(CompositeFilterTest, TestStopWhilePlayPending) {
656 InSequence sequence; 631 InSequence sequence;
657 632
658 SetupAndAdd2Filters(); 633 SetupAndAdd2Filters();
659 634
660 scoped_ptr<StrictMock<MockFilterCallback> > mock_callback(
661 new StrictMock<MockFilterCallback>());
662
663 EXPECT_CALL(*filter_1_, Play(_)); 635 EXPECT_CALL(*filter_1_, Play(_));
664 636
665 composite_->Play(mock_callback->NewCallback()); 637 StrictMock<MockCallback>* callback = new StrictMock<MockCallback>();
638 composite_->Play(callback);
666 639
667 // Note: Play() is pending on |filter_1_| right now. 640 // Note: Play() is pending on |filter_1_| right now.
668 641
669 scoped_ptr<StrictMock<MockFilterCallback> > mock_callback_2( 642 EXPECT_CALL(*callback, Destructor());
670 new StrictMock<MockFilterCallback>(false));
671 643
672 EXPECT_CALL(*mock_callback, OnCallbackDestroyed()); 644 callback = new StrictMock<MockCallback>();
673 645 composite_->Stop(callback);
674 composite_->Stop(mock_callback_2->NewCallback());
675 646
676 EXPECT_CALL(*filter_1_, Stop(_)); 647 EXPECT_CALL(*filter_1_, Stop(_));
677 648
678 // Run |filter_1_|'s callback again to indicate Play() has completed. 649 // Run |filter_1_|'s callback again to indicate Play() has completed.
679 RunFilter1Callback(); 650 RunFilter1Callback();
680 651
681 EXPECT_CALL(*filter_2_, Stop(_)); 652 EXPECT_CALL(*filter_2_, Stop(_));
682 653
683 // Run |filter_1_|'s callback again to indicate Stop() has completed. 654 // Run |filter_1_|'s callback again to indicate Stop() has completed.
684 RunFilter1Callback(); 655 RunFilter1Callback();
685 656
686 EXPECT_CALL(*mock_callback_2, OnFilterCallback()); 657 EXPECT_CALL(*callback, RunWithParams(_));
658 EXPECT_CALL(*callback, Destructor());
687 659
688 // Run |filter_2_|'s callback to indicate Stop() has completed. 660 // Run |filter_2_|'s callback to indicate Stop() has completed.
689 RunFilter2Callback(); 661 RunFilter2Callback();
690 } 662 }
691 663
692 // Test stopping in the middle of a parallel call sequence. 664 // Test stopping in the middle of a parallel call sequence.
693 TEST_F(CompositeFilterTest, TestStopWhileFlushPending) { 665 TEST_F(CompositeFilterTest, TestStopWhileFlushPending) {
694 InSequence sequence; 666 InSequence sequence;
695 667
696 SetupAndAdd2Filters(); 668 SetupAndAdd2Filters();
697 669
698 scoped_ptr<StrictMock<MockFilterCallback> > mock_callback(
699 new StrictMock<MockFilterCallback>());
700
701 EXPECT_CALL(*filter_1_, Flush(_)); 670 EXPECT_CALL(*filter_1_, Flush(_));
702 EXPECT_CALL(*filter_2_, Flush(_)); 671 EXPECT_CALL(*filter_2_, Flush(_));
703 672
704 composite_->Flush(mock_callback->NewCallback()); 673 StrictMock<MockCallback>* callback = new StrictMock<MockCallback>();
674 composite_->Flush(callback);
705 675
706 // Note: |filter_1_| and |filter_2_| have pending Flush() calls at this point. 676 // Note: |filter_1_| and |filter_2_| have pending Flush() calls at this point.
707 677
708 scoped_ptr<StrictMock<MockFilterCallback> > mock_callback_2( 678 EXPECT_CALL(*callback, Destructor());
709 new StrictMock<MockFilterCallback>(false));
710 679
711 EXPECT_CALL(*mock_callback, OnCallbackDestroyed()); 680 callback = new StrictMock<MockCallback>();
712 681 composite_->Stop(callback);
713 composite_->Stop(mock_callback_2->NewCallback());
714 682
715 // Run callback to indicate that |filter_1_|'s Flush() has completed. 683 // Run callback to indicate that |filter_1_|'s Flush() has completed.
716 RunFilter1Callback(); 684 RunFilter1Callback();
717 685
718 EXPECT_CALL(*filter_1_, Stop(_)); 686 EXPECT_CALL(*filter_1_, Stop(_));
719 687
720 // Run callback to indicate that |filter_2_|'s Flush() has completed. 688 // Run callback to indicate that |filter_2_|'s Flush() has completed.
721 RunFilter2Callback(); 689 RunFilter2Callback();
722 690
723 EXPECT_CALL(*filter_2_, Stop(_)); 691 EXPECT_CALL(*filter_2_, Stop(_));
724 692
725 // Run callback to indicate that |filter_1_|'s Stop() has completed. 693 // Run callback to indicate that |filter_1_|'s Stop() has completed.
726 RunFilter1Callback(); 694 RunFilter1Callback();
727 695
728 EXPECT_CALL(*mock_callback_2, OnFilterCallback()); 696 EXPECT_CALL(*callback, RunWithParams(_));
697 EXPECT_CALL(*callback, Destructor());
729 698
730 // Run callback to indicate that |filter_2_|'s Stop() has completed. 699 // Run callback to indicate that |filter_2_|'s Stop() has completed.
731 RunFilter2Callback(); 700 RunFilter2Callback();
732 } 701 }
733 702
734 TEST_F(CompositeFilterTest, TestErrorWhilePlaying) { 703 TEST_F(CompositeFilterTest, TestErrorWhilePlaying) {
735 InSequence sequence; 704 InSequence sequence;
736 705
737 SetupAndAdd2Filters(); 706 SetupAndAdd2Filters();
738 707
(...skipping 21 matching lines...) Expand all
760 filter_2_->host()->SetError(PIPELINE_ERROR_NETWORK); 729 filter_2_->host()->SetError(PIPELINE_ERROR_NETWORK);
761 } 730 }
762 731
763 // Make sure that state transitions act as expected even 732 // Make sure that state transitions act as expected even
764 // if the composite doesn't contain any filters. 733 // if the composite doesn't contain any filters.
765 TEST_F(CompositeFilterTest, TestEmptyComposite) { 734 TEST_F(CompositeFilterTest, TestEmptyComposite) {
766 InSequence sequence; 735 InSequence sequence;
767 736
768 composite_->set_host(mock_filter_host_.get()); 737 composite_->set_host(mock_filter_host_.get());
769 738
770 scoped_ptr<StrictMock<MockFilterCallback> > mock_callback( 739 // Issue a Play() and expect no errors.
771 new StrictMock<MockFilterCallback>(false)); 740 composite_->Play(NewExpectedCallback());
741
742 // Issue a Pause() and expect no errors.
743 composite_->Pause(NewExpectedCallback());
744
745 // Issue a Flush() and expect no errors.
746 composite_->Flush(NewExpectedCallback());
747
748 // Issue a Seek() and expect no errors.
749 composite_->Seek(base::TimeDelta::FromSeconds(5),
750 NewExpectedCallback());
772 751
773 // Issue a Play() and expect no errors. 752 // Issue a Play() and expect no errors.
774 EXPECT_CALL(*mock_callback, OnFilterCallback()); 753 composite_->Play(NewExpectedCallback());
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 754
794 // Issue a Stop() and expect no errors. 755 // Issue a Stop() and expect no errors.
795 EXPECT_CALL(*mock_callback, OnFilterCallback()); 756 composite_->Stop(NewExpectedCallback());
796 composite_->Stop(mock_callback->NewCallback());
797 } 757 }
798 758
799 } // namespace media 759 } // namespace media
OLDNEW
« no previous file with comments | « no previous file | media/base/mock_callback.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698