OLD | NEW |
---|---|
(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); | |
scherkus (not reviewing)
2010/12/20 20:36:21
you can even do without the != NULL part if you wa
| |
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 static bool g_thread_cleanup_called_ = false; | |
359 class CompositeFilterThread : public base::Thread { | |
360 public: | |
361 CompositeFilterThread(const char* name) : base::Thread(name) {} | |
362 virtual void CleanUp() { | |
363 g_thread_cleanup_called_ = true; | |
364 base::Thread::CleanUp(); | |
365 } | |
366 }; | |
367 | |
368 TEST_F(CompositeFilterTest, TestPlay) { | |
369 InSequence sequence; | |
370 | |
371 SetupAndAdd2Filters(); | |
372 | |
373 // Verify successful call to Play(). | |
374 DoPlay(); | |
375 | |
376 // At this point we are now in the kPlaying state. | |
377 scoped_ptr<StrictMock<MockFilterCallback> > mock_callback( | |
378 new StrictMock<MockFilterCallback>(false)); | |
379 | |
380 // Try calling Play() again to make sure that we simply get a callback. | |
381 // We are already in the Play() state so there is no point calling the | |
382 // filters. | |
383 EXPECT_CALL(*mock_callback, OnFilterCallback()); | |
384 | |
385 composite_->Play(mock_callback->NewCallback()); | |
386 | |
387 // Verify that neither of the filter callbacks were set. | |
388 EXPECT_EQ((FilterCallback*)NULL, filter_1_callback_); | |
389 EXPECT_EQ((FilterCallback*)NULL, filter_2_callback_); | |
390 | |
391 // Stop playback. | |
392 DoStop(); | |
393 | |
394 // At this point we should be in the kStopped state. | |
395 | |
396 // Try calling Stop() again to make sure neither filter is called. | |
397 EXPECT_CALL(*mock_callback, OnFilterCallback()); | |
398 | |
399 composite_->Stop(mock_callback->NewCallback()); | |
400 | |
401 // Verify that neither of the filter callbacks were set. | |
402 EXPECT_EQ((FilterCallback*)NULL, filter_1_callback_); | |
403 EXPECT_EQ((FilterCallback*)NULL, filter_2_callback_); | |
404 | |
405 // Try calling Play() again to make sure we get an error. | |
406 ExpectInvalidStateFail(PLAY); | |
407 } | |
408 | |
409 // Test errors in the middle of a serial call sequence like Play(). | |
410 TEST_F(CompositeFilterTest, TestPlayErrors) { | |
411 InSequence sequence; | |
412 | |
413 SetupAndAdd2Filters(); | |
414 | |
415 scoped_ptr<StrictMock<MockFilterCallback> > mock_callback( | |
416 new StrictMock<MockFilterCallback>(false)); | |
417 | |
418 EXPECT_CALL(*filter_1_, Play(_)); | |
419 | |
420 // Call Play() on the composite. | |
421 composite_->Play(mock_callback->NewCallback()); | |
422 | |
423 EXPECT_CALL(*filter_2_, Play(_)); | |
424 | |
425 // Run callback to indicate that |filter_1_|'s Play() has completed. | |
426 RunFilter1Callback(); | |
427 | |
428 // At this point Play() has been called on |filter_2_|. Simulate an | |
429 // error by calling SetError() on its FilterHost interface. | |
430 filter_2_->host()->SetError(PIPELINE_ERROR_OUT_OF_MEMORY); | |
431 | |
432 // Expect error to be reported and "play done" callback to be called. | |
433 EXPECT_CALL(*mock_filter_host_, SetError(PIPELINE_ERROR_OUT_OF_MEMORY)); | |
434 EXPECT_CALL(*mock_callback, OnFilterCallback()); | |
435 | |
436 // Run callback to indicate that |filter_2_|'s Play() has completed. | |
437 RunFilter2Callback(); | |
438 | |
439 // Verify that Play/Pause/Flush/Seek fail now that an error occured. | |
440 ExpectInvalidStateFail(PLAY); | |
441 ExpectInvalidStateFail(PAUSE); | |
442 ExpectInvalidStateFail(FLUSH); | |
443 ExpectInvalidStateFail(SEEK); | |
444 | |
445 // Make sure you can still Stop(). | |
446 DoStop(); | |
447 } | |
448 | |
449 TEST_F(CompositeFilterTest, TestPause) { | |
450 InSequence sequence; | |
451 | |
452 SetupAndAdd2Filters(); | |
453 | |
454 scoped_ptr<StrictMock<MockFilterCallback> > mock_callback( | |
455 new StrictMock<MockFilterCallback>(false)); | |
456 | |
457 // Try calling Pause() to make sure we get an error because we aren't in | |
458 // the playing state. | |
459 ExpectInvalidStateFail(PAUSE); | |
460 | |
461 // Transition to playing state. | |
462 DoPlay(); | |
463 | |
464 // Issue a successful Pause(). | |
465 DoPause(); | |
466 | |
467 // At this point we are paused. | |
468 | |
469 // Try calling Pause() again to make sure that the filters aren't called | |
470 // because we are already in the paused state. | |
471 EXPECT_CALL(*mock_callback, OnFilterCallback()); | |
472 | |
473 composite_->Pause(mock_callback->NewCallback()); | |
474 | |
475 // Verify that neither of the filter callbacks were set. | |
476 EXPECT_EQ((FilterCallback*)NULL, filter_1_callback_); | |
477 EXPECT_EQ((FilterCallback*)NULL, filter_2_callback_); | |
478 | |
479 // Verify that we can transition pack to the play state. | |
480 DoPlay(); | |
481 | |
482 // Go back to the pause state. | |
483 DoPause(); | |
484 | |
485 // Transition to the stop state. | |
486 DoStop(); | |
487 | |
488 // Try calling Pause() to make sure we get an error because we aren't in | |
489 // the playing state. | |
490 ExpectInvalidStateFail(PAUSE); | |
491 } | |
492 | |
493 // Test errors in the middle of a serial call sequence like Pause(). | |
494 TEST_F(CompositeFilterTest, TestPauseErrors) { | |
495 InSequence sequence; | |
496 | |
497 SetupAndAdd2Filters(); | |
498 | |
499 DoPlay(); | |
500 | |
501 scoped_ptr<StrictMock<MockFilterCallback> > mock_callback( | |
502 new StrictMock<MockFilterCallback>(false)); | |
503 | |
504 EXPECT_CALL(*filter_1_, Pause(_)); | |
505 | |
506 // Call Pause() on the composite. | |
507 composite_->Pause(mock_callback->NewCallback()); | |
508 | |
509 // Simulate an error by calling SetError() on |filter_1_|'s FilterHost | |
510 // interface. | |
511 filter_1_->host()->SetError(PIPELINE_ERROR_OUT_OF_MEMORY); | |
512 | |
513 // Expect error to be reported and "pause done" callback to be called. | |
514 EXPECT_CALL(*mock_filter_host_, SetError(PIPELINE_ERROR_OUT_OF_MEMORY)); | |
515 EXPECT_CALL(*mock_callback, OnFilterCallback()); | |
516 | |
517 RunFilter1Callback(); | |
518 | |
519 // Make sure |filter_2_callback_| was not set. | |
520 EXPECT_EQ((FilterCallback*)NULL, filter_2_callback_); | |
521 | |
522 // Verify that Play/Pause/Flush/Seek fail now that an error occured. | |
523 ExpectInvalidStateFail(PLAY); | |
524 ExpectInvalidStateFail(PAUSE); | |
525 ExpectInvalidStateFail(FLUSH); | |
526 ExpectInvalidStateFail(SEEK); | |
527 | |
528 // Make sure you can still Stop(). | |
529 DoStop(); | |
530 } | |
531 | |
532 TEST_F(CompositeFilterTest, TestFlush) { | |
533 InSequence sequence; | |
534 | |
535 SetupAndAdd2Filters(); | |
536 | |
537 scoped_ptr<StrictMock<MockFilterCallback> > mock_callback( | |
538 new StrictMock<MockFilterCallback>(false)); | |
539 | |
540 // Make sure Flush() works before calling Play(). | |
541 DoFlush(); | |
542 | |
543 // Transition to playing state. | |
544 DoPlay(); | |
545 | |
546 // Call Flush() to make sure we get an error because we are in | |
547 // the playing state. | |
548 ExpectInvalidStateFail(FLUSH); | |
549 | |
550 // Issue a successful Pause(). | |
551 DoPause(); | |
552 | |
553 // Make sure Flush() works after pausing. | |
554 DoFlush(); | |
555 | |
556 // Verify that we can transition back to the play state. | |
557 DoPlay(); | |
558 | |
559 // Transition to the stop state. | |
560 DoStop(); | |
561 | |
562 // Try calling Flush() to make sure we get an error because we are stopped. | |
563 ExpectInvalidStateFail(FLUSH); | |
564 } | |
565 | |
566 // Test errors in the middle of a parallel call sequence like Flush(). | |
567 TEST_F(CompositeFilterTest, TestFlushErrors) { | |
568 InSequence sequence; | |
569 | |
570 SetupAndAdd2Filters(); | |
571 | |
572 scoped_ptr<StrictMock<MockFilterCallback> > mock_callback( | |
573 new StrictMock<MockFilterCallback>(false)); | |
574 | |
575 EXPECT_CALL(*filter_1_, Flush(_)); | |
576 EXPECT_CALL(*filter_2_, Flush(_)); | |
577 | |
578 // Call Flush() on the composite. | |
579 composite_->Flush(mock_callback->NewCallback()); | |
580 | |
581 // Simulate an error by calling SetError() on |filter_1_|'s FilterHost | |
582 // interface. | |
583 filter_1_->host()->SetError(PIPELINE_ERROR_OUT_OF_MEMORY); | |
584 | |
585 RunFilter1Callback(); | |
586 | |
587 // Expect error to be reported and "pause done" callback to be called. | |
588 EXPECT_CALL(*mock_filter_host_, SetError(PIPELINE_ERROR_OUT_OF_MEMORY)); | |
589 EXPECT_CALL(*mock_callback, OnFilterCallback()); | |
590 | |
591 RunFilter2Callback(); | |
592 | |
593 // Verify that Play/Pause/Flush/Seek fail now that an error occured. | |
594 ExpectInvalidStateFail(PLAY); | |
595 ExpectInvalidStateFail(PAUSE); | |
596 ExpectInvalidStateFail(FLUSH); | |
597 ExpectInvalidStateFail(SEEK); | |
598 | |
599 // Make sure you can still Stop(). | |
600 DoStop(); | |
601 } | |
602 | |
603 TEST_F(CompositeFilterTest, TestSeek) { | |
604 InSequence sequence; | |
605 | |
606 SetupAndAdd2Filters(); | |
607 | |
608 // Verify that seek is allowed to be called before a Play() call. | |
609 DoSeek(base::TimeDelta::FromSeconds(5)); | |
610 | |
611 // Verify we can issue a Play() after the Seek(). | |
612 DoPlay(); | |
613 | |
614 scoped_ptr<StrictMock<MockFilterCallback> > mock_callback( | |
615 new StrictMock<MockFilterCallback>(false)); | |
616 | |
617 // Try calling Seek() while playing to make sure we get an error. | |
618 ExpectInvalidStateFail(SEEK); | |
619 | |
620 // Transition to paused state. | |
621 DoPause(); | |
622 | |
623 // Verify that seek is allowed after pausing. | |
624 DoSeek(base::TimeDelta::FromSeconds(5)); | |
625 | |
626 // Verify we can still play again. | |
627 DoPlay(); | |
628 | |
629 // Stop playback. | |
630 DoStop(); | |
631 | |
632 // Try calling Seek() to make sure we get an error. | |
633 ExpectInvalidStateFail(SEEK); | |
634 } | |
635 | |
636 TEST_F(CompositeFilterTest, TestStop) { | |
637 InSequence sequence; | |
638 | |
639 // Test Stop() before any other call. | |
640 SetupAndAdd2Filters(); | |
641 DoStop(); | |
642 | |
643 // Test error during Stop() sequence. | |
644 SetupAndAdd2Filters(); | |
645 scoped_ptr<StrictMock<MockFilterCallback> > mock_callback( | |
646 new StrictMock<MockFilterCallback>(false)); | |
647 | |
648 EXPECT_CALL(*filter_1_, Stop(_)); | |
649 | |
650 composite_->Stop(mock_callback->NewCallback()); | |
651 | |
652 // Have |filter_1_| signal an error. | |
653 filter_1_->host()->SetError(PIPELINE_ERROR_READ); | |
654 | |
655 EXPECT_CALL(*filter_2_, Stop(_)); | |
656 | |
657 RunFilter1Callback(); | |
658 | |
659 EXPECT_CALL(*mock_callback, OnFilterCallback()); | |
660 | |
661 RunFilter2Callback(); | |
662 } | |
663 | |
664 // Test stopping in the middle of a serial call sequence. | |
665 TEST_F(CompositeFilterTest, TestStopWhilePlayPending) { | |
666 InSequence sequence; | |
667 | |
668 SetupAndAdd2Filters(); | |
669 | |
670 scoped_ptr<StrictMock<MockFilterCallback> > mock_callback( | |
671 new StrictMock<MockFilterCallback>()); | |
672 | |
673 EXPECT_CALL(*filter_1_, Play(_)); | |
674 | |
675 composite_->Play(mock_callback->NewCallback()); | |
676 | |
677 // Note: Play() is pending on |filter_1_| right now. | |
678 | |
679 scoped_ptr<StrictMock<MockFilterCallback> > mock_callback_2( | |
680 new StrictMock<MockFilterCallback>(false)); | |
681 | |
682 EXPECT_CALL(*mock_callback, OnCallbackDestroyed()); | |
683 | |
684 composite_->Stop(mock_callback_2->NewCallback()); | |
685 | |
686 EXPECT_CALL(*filter_1_, Stop(_)); | |
687 | |
688 // Run |filter_1_|'s callback again to indicate Play() has completed. | |
689 RunFilter1Callback(); | |
690 | |
691 EXPECT_CALL(*filter_2_, Stop(_)); | |
692 | |
693 // Run |filter_1_|'s callback again to indicate Stop() has completed. | |
694 RunFilter1Callback(); | |
695 | |
696 EXPECT_CALL(*mock_callback_2, OnFilterCallback()); | |
697 | |
698 // Run |filter_2_|'s callback to indicate Stop() has completed. | |
699 RunFilter2Callback(); | |
700 } | |
701 | |
702 // Test stopping in the middle of a parallel call sequence. | |
703 TEST_F(CompositeFilterTest, TestStopWhileFlushPending) { | |
704 InSequence sequence; | |
705 | |
706 SetupAndAdd2Filters(); | |
707 | |
708 scoped_ptr<StrictMock<MockFilterCallback> > mock_callback( | |
709 new StrictMock<MockFilterCallback>()); | |
710 | |
711 EXPECT_CALL(*filter_1_, Flush(_)); | |
712 EXPECT_CALL(*filter_2_, Flush(_)); | |
713 | |
714 composite_->Flush(mock_callback->NewCallback()); | |
715 | |
716 // Note: |filter_1_| and |filter_2_| have pending Flush() calls at this point. | |
717 | |
718 scoped_ptr<StrictMock<MockFilterCallback> > mock_callback_2( | |
719 new StrictMock<MockFilterCallback>(false)); | |
720 | |
721 EXPECT_CALL(*mock_callback, OnCallbackDestroyed()); | |
722 | |
723 composite_->Stop(mock_callback_2->NewCallback()); | |
724 | |
725 // Run callback to indicate that |filter_1_|'s Flush() has completed. | |
726 RunFilter1Callback(); | |
727 | |
728 EXPECT_CALL(*filter_1_, Stop(_)); | |
729 | |
730 // Run callback to indicate that |filter_2_|'s Flush() has completed. | |
731 RunFilter2Callback(); | |
732 | |
733 EXPECT_CALL(*filter_2_, Stop(_)); | |
734 | |
735 // Run callback to indicate that |filter_1_|'s Stop() has completed. | |
736 RunFilter1Callback(); | |
737 | |
738 EXPECT_CALL(*mock_callback_2, OnFilterCallback()); | |
739 | |
740 // Run callback to indicate that |filter_2_|'s Stop() has completed. | |
741 RunFilter2Callback(); | |
742 } | |
743 | |
744 TEST_F(CompositeFilterTest, TestErrorWhilePlaying) { | |
745 InSequence sequence; | |
746 | |
747 SetupAndAdd2Filters(); | |
748 | |
749 // Simulate an error on |filter_2_| while in kCreated state. This | |
750 // can happen if an error occurs during filter initialization. | |
751 EXPECT_CALL(*mock_filter_host_, SetError(PIPELINE_ERROR_OUT_OF_MEMORY)); | |
752 filter_2_->host()->SetError(PIPELINE_ERROR_OUT_OF_MEMORY); | |
753 | |
754 DoPlay(); | |
755 | |
756 // Simulate an error on |filter_2_| while playing. | |
757 EXPECT_CALL(*mock_filter_host_, SetError(PIPELINE_ERROR_OUT_OF_MEMORY)); | |
758 filter_2_->host()->SetError(PIPELINE_ERROR_OUT_OF_MEMORY); | |
759 | |
760 DoPause(); | |
761 | |
762 // Simulate an error on |filter_2_| while paused. | |
763 EXPECT_CALL(*mock_filter_host_, SetError(PIPELINE_ERROR_NETWORK)); | |
764 filter_2_->host()->SetError(PIPELINE_ERROR_NETWORK); | |
765 | |
766 DoStop(); | |
767 | |
768 // Verify that errors are not passed to |mock_filter_host_| | |
769 // after Stop() has been called. | |
770 filter_2_->host()->SetError(PIPELINE_ERROR_NETWORK); | |
771 } | |
772 | |
773 // Make sure that state transitions act as expected even | |
774 // if the composite doesn't contain any filters. | |
775 TEST_F(CompositeFilterTest, TestEmptyComposite) { | |
776 InSequence sequence; | |
777 | |
778 composite_->set_host(mock_filter_host_.get()); | |
779 | |
780 scoped_ptr<StrictMock<MockFilterCallback> > mock_callback( | |
781 new StrictMock<MockFilterCallback>(false)); | |
782 | |
783 // Issue a Play() and expect no errors. | |
784 EXPECT_CALL(*mock_callback, OnFilterCallback()); | |
785 composite_->Play(mock_callback->NewCallback()); | |
786 | |
787 // Issue a Pause() and expect no errors. | |
788 EXPECT_CALL(*mock_callback, OnFilterCallback()); | |
789 composite_->Pause(mock_callback->NewCallback()); | |
790 | |
791 // Issue a Flush() and expect no errors. | |
792 EXPECT_CALL(*mock_callback, OnFilterCallback()); | |
793 composite_->Flush(mock_callback->NewCallback()); | |
794 | |
795 // Issue a Seek() and expect no errors. | |
796 EXPECT_CALL(*mock_callback, OnFilterCallback()); | |
797 composite_->Seek(base::TimeDelta::FromSeconds(5), | |
798 mock_callback->NewCallback()); | |
799 | |
800 // Issue a Play() and expect no errors. | |
801 EXPECT_CALL(*mock_callback, OnFilterCallback()); | |
802 composite_->Play(mock_callback->NewCallback()); | |
803 | |
804 // Issue a Stop() and expect no errors. | |
805 EXPECT_CALL(*mock_callback, OnFilterCallback()); | |
806 composite_->Stop(mock_callback->NewCallback()); | |
807 } | |
808 | |
809 } // namespace media | |
OLD | NEW |