1 // Copyright 2013 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.
8 #include "base/callback_helpers.h"
9 #include "base/memory/scoped_vector.h"
10 #include "base/message_loop/message_loop.h"
11 #include "media/base/audio_decoder_config.h"
12 #include "media/base/decoder_buffer.h"
13 #include "media/base/demuxer_stream.h"
14 #include "media/base/fake_text_track_stream.h"
15 #include "media/base/text_renderer.h"
16 #include "media/base/text_track_config.h"
17 #include "media/base/video_decoder_config.h"
18 #include "media/filters/webvtt_util.h"
19 #include "testing/gmock/include/gmock/gmock.h"
20 #include "testing/gtest/include/gtest/gtest.h"
23 using ::testing::Exactly
;
24 using ::testing::Invoke
;
29 // Local implementation of the TextTrack interface.
30 class FakeTextTrack
: public TextTrack
{
32 FakeTextTrack(const base::Closure
& destroy_cb
,
33 const TextTrackConfig
& config
)
34 : destroy_cb_(destroy_cb
),
37 virtual ~FakeTextTrack() {
41 MOCK_METHOD5(addWebVTTCue
, void(const base::TimeDelta
& start
,
42 const base::TimeDelta
& end
,
43 const std::string
& id
,
44 const std::string
& content
,
45 const std::string
& settings
));
47 const base::Closure destroy_cb_
;
48 const TextTrackConfig config_
;
51 DISALLOW_COPY_AND_ASSIGN(FakeTextTrack
);
54 class TextRendererTest
: public testing::Test
{
58 void CreateTextRenderer() {
59 DCHECK(!text_renderer_
);
62 new TextRenderer(message_loop_
.message_loop_proxy(),
63 base::Bind(&TextRendererTest::OnAddTextTrack
,
64 base::Unretained(this))));
65 text_renderer_
->Initialize(base::Bind(&TextRendererTest::OnEnd
,
66 base::Unretained(this)));
69 void DestroyTextRenderer() {
70 EXPECT_CALL(*this, OnStop());
71 text_renderer_
->Stop(base::Bind(&TextRendererTest::OnStop
,
72 base::Unretained(this)));
73 message_loop_
.RunUntilIdle();
75 text_renderer_
.reset();
76 text_track_streams_
.clear();
79 void AddTextTrack(TextKind kind
,
80 const std::string
& name
,
81 const std::string
& language
,
83 const size_t idx
= text_track_streams_
.size();
84 text_track_streams_
.push_back(new FakeTextTrackStream
);
89 const TextTrackConfig
config(kind
, name
, language
, std::string());
90 text_renderer_
->AddTextStream(text_track_streams_
.back(), config
);
91 message_loop_
.RunUntilIdle();
93 EXPECT_EQ(text_tracks_
.size(), text_track_streams_
.size());
94 FakeTextTrack
* const text_track
= text_tracks_
.back();
95 EXPECT_TRUE(text_track
);
96 EXPECT_TRUE(text_track
->config_
.Matches(config
));
99 void OnAddTextTrack(const TextTrackConfig
& config
,
100 const AddTextTrackDoneCB
& done_cb
) {
101 base::Closure destroy_cb
=
102 base::Bind(&TextRendererTest::OnDestroyTextTrack
,
103 base::Unretained(this),
104 text_tracks_
.size());
105 // Text track objects are owned by the text renderer, but we cache them
106 // here so we can inspect them. They get removed from our cache when the
107 // text renderer deallocates them.
108 text_tracks_
.push_back(new FakeTextTrack(destroy_cb
, config
));
109 scoped_ptr
<TextTrack
> text_track(text_tracks_
.back());
110 done_cb
.Run(text_track
.Pass());
113 void RemoveTextTrack(unsigned idx
) {
114 FakeTextTrackStream
* const stream
= text_track_streams_
[idx
];
115 text_renderer_
->RemoveTextStream(stream
);
116 EXPECT_FALSE(text_tracks_
[idx
]);
119 void SatisfyPendingReads(const base::TimeDelta
& start
,
120 const base::TimeDelta
& duration
,
121 const std::string
& id
,
122 const std::string
& content
,
123 const std::string
& settings
) {
124 for (TextTrackStreams::iterator itr
= text_track_streams_
.begin();
125 itr
!= text_track_streams_
.end(); ++itr
) {
126 (*itr
)->SatisfyPendingRead(start
, duration
, id
, content
, settings
);
130 void AbortPendingRead(unsigned idx
) {
131 FakeTextTrackStream
* const stream
= text_track_streams_
[idx
];
132 stream
->AbortPendingRead();
133 message_loop_
.RunUntilIdle();
136 void AbortPendingReads() {
137 for (size_t idx
= 0; idx
< text_track_streams_
.size(); ++idx
) {
138 AbortPendingRead(idx
);
142 void SendEosNotification(unsigned idx
) {
143 FakeTextTrackStream
* const stream
= text_track_streams_
[idx
];
144 stream
->SendEosNotification();
145 message_loop_
.RunUntilIdle();
148 void SendEosNotifications() {
149 for (size_t idx
= 0; idx
< text_track_streams_
.size(); ++idx
) {
150 SendEosNotification(idx
);
154 void SendCue(unsigned idx
, bool expect_cue
) {
155 FakeTextTrackStream
* const text_stream
= text_track_streams_
[idx
];
157 const base::TimeDelta start
;
158 const base::TimeDelta duration
= base::TimeDelta::FromSeconds(42);
159 const std::string id
= "id";
160 const std::string content
= "subtitle";
161 const std::string settings
;
164 FakeTextTrack
* const text_track
= text_tracks_
[idx
];
165 EXPECT_CALL(*text_track
, addWebVTTCue(start
,
172 text_stream
->SatisfyPendingRead(start
, duration
, id
, content
, settings
);
173 message_loop_
.RunUntilIdle();
176 void SendCues(bool expect_cue
) {
177 for (size_t idx
= 0; idx
< text_track_streams_
.size(); ++idx
) {
178 SendCue(idx
, expect_cue
);
182 void OnDestroyTextTrack(unsigned idx
) {
183 text_tracks_
[idx
] = NULL
;
187 EXPECT_CALL(*this, OnPlay());
188 text_renderer_
->Play(base::Bind(&TextRendererTest::OnPlay
,
189 base::Unretained(this)));
190 message_loop_
.RunUntilIdle();
194 text_renderer_
->Pause(base::Bind(&TextRendererTest::OnPause
,
195 base::Unretained(this)));
196 message_loop_
.RunUntilIdle();
200 EXPECT_CALL(*this, OnFlush());
201 text_renderer_
->Flush(base::Bind(&TextRendererTest::OnFlush
,
202 base::Unretained(this)));
206 text_renderer_
->Stop(base::Bind(&TextRendererTest::OnStop
,
207 base::Unretained(this)));
208 message_loop_
.RunUntilIdle();
211 void ExpectRead(size_t idx
) {
212 FakeTextTrackStream
* const stream
= text_track_streams_
[idx
];
213 EXPECT_CALL(*stream
, OnRead());
216 MOCK_METHOD0(OnEnd
, void());
217 MOCK_METHOD0(OnStop
, void());
218 MOCK_METHOD0(OnPlay
, void());
219 MOCK_METHOD0(OnPause
, void());
220 MOCK_METHOD0(OnFlush
, void());
222 scoped_ptr
<TextRenderer
> text_renderer_
;
223 base::MessageLoop message_loop_
;
225 typedef ScopedVector
<FakeTextTrackStream
> TextTrackStreams
;
226 TextTrackStreams text_track_streams_
;
228 typedef std::vector
<FakeTextTrack
*> TextTracks
;
229 TextTracks text_tracks_
;
232 DISALLOW_COPY_AND_ASSIGN(TextRendererTest
);
235 TEST_F(TextRendererTest
, CreateTextRendererNoInit
) {
236 text_renderer_
.reset(
237 new TextRenderer(message_loop_
.message_loop_proxy(),
238 base::Bind(&TextRendererTest::OnAddTextTrack
,
239 base::Unretained(this))));
240 text_renderer_
.reset();
243 TEST_F(TextRendererTest
, TestStop
) {
244 CreateTextRenderer();
245 DestroyTextRenderer();
248 TEST_F(TextRendererTest
, AddTextTrackOnly_OneTrack
) {
249 CreateTextRenderer();
250 AddTextTrack(kTextSubtitles
, "", "", false);
251 DestroyTextRenderer();
254 TEST_F(TextRendererTest
, AddTextTrackOnly_TwoTracks
) {
255 CreateTextRenderer();
256 AddTextTrack(kTextSubtitles
, "track 1", "", false);
257 AddTextTrack(kTextSubtitles
, "track 2", "", false);
258 DestroyTextRenderer();
261 TEST_F(TextRendererTest
, PlayOnly
) {
262 CreateTextRenderer();
264 DestroyTextRenderer();
267 TEST_F(TextRendererTest
, AddTrackBeforePlay_OneTrack
) {
268 CreateTextRenderer();
269 AddTextTrack(kTextSubtitles
, "", "", true);
272 DestroyTextRenderer();
275 TEST_F(TextRendererTest
, AddTrackBeforePlay_TwoTracks
) {
276 CreateTextRenderer();
277 AddTextTrack(kTextSubtitles
, "1", "", true);
278 AddTextTrack(kTextSubtitles
, "2", "", true);
281 DestroyTextRenderer();
284 TEST_F(TextRendererTest
, AddTrackAfterPlay_OneTrackAfter
) {
285 CreateTextRenderer();
287 AddTextTrack(kTextSubtitles
, "", "", true);
289 DestroyTextRenderer();
292 TEST_F(TextRendererTest
, AddTrackAfterPlay_TwoTracksAfter
) {
293 CreateTextRenderer();
295 AddTextTrack(kTextSubtitles
, "1", "", true);
296 AddTextTrack(kTextSubtitles
, "2", "", true);
298 DestroyTextRenderer();
301 TEST_F(TextRendererTest
, AddTrackAfterPlay_OneTrackBeforeOneTrackAfter
) {
302 CreateTextRenderer();
303 AddTextTrack(kTextSubtitles
, "1", "", true);
305 AddTextTrack(kTextSubtitles
, "2", "", true);
307 DestroyTextRenderer();
310 TEST_F(TextRendererTest
, PlayAddCue_OneTrack
) {
311 CreateTextRenderer();
312 AddTextTrack(kTextSubtitles
, "", "", true);
317 DestroyTextRenderer();
320 TEST_F(TextRendererTest
, PlayAddCue_TwoTracks
) {
321 CreateTextRenderer();
322 AddTextTrack(kTextSubtitles
, "1", "", true);
323 AddTextTrack(kTextSubtitles
, "2", "", true);
329 DestroyTextRenderer();
332 TEST_F(TextRendererTest
, PlayEosOnly_OneTrack
) {
333 CreateTextRenderer();
334 AddTextTrack(kTextSubtitles
, "", "", true);
336 EXPECT_CALL(*this, OnEnd());
337 SendEosNotifications();
338 DestroyTextRenderer();
341 TEST_F(TextRendererTest
, PlayEosOnly_TwoTracks
) {
342 CreateTextRenderer();
343 AddTextTrack(kTextSubtitles
, "1", "", true);
344 AddTextTrack(kTextSubtitles
, "2", "", true);
346 EXPECT_CALL(*this, OnEnd());
347 SendEosNotifications();
348 DestroyTextRenderer();
351 TEST_F(TextRendererTest
, PlayCueEos_OneTrack
) {
352 CreateTextRenderer();
353 AddTextTrack(kTextSubtitles
, "", "", true);
357 EXPECT_CALL(*this, OnEnd());
358 SendEosNotifications();
359 DestroyTextRenderer();
362 TEST_F(TextRendererTest
, PlayCueEos_TwoTracks
) {
363 CreateTextRenderer();
364 AddTextTrack(kTextSubtitles
, "1", "", true);
365 AddTextTrack(kTextSubtitles
, "2", "", true);
370 EXPECT_CALL(*this, OnEnd());
371 SendEosNotifications();
372 DestroyTextRenderer();
375 TEST_F(TextRendererTest
, StopPending_OneTrack
) {
376 CreateTextRenderer();
377 AddTextTrack(kTextSubtitles
, "", "", true);
380 EXPECT_CALL(*this, OnStop());
381 SendEosNotifications();
382 text_renderer_
.reset();
383 text_track_streams_
.clear();
386 TEST_F(TextRendererTest
, StopPending_TwoTracks
) {
387 CreateTextRenderer();
388 AddTextTrack(kTextSubtitles
, "1", "", true);
389 AddTextTrack(kTextSubtitles
, "2", "", true);
392 EXPECT_CALL(*this, OnStop());
393 SendEosNotifications();
394 text_renderer_
.reset();
395 text_track_streams_
.clear();
398 TEST_F(TextRendererTest
, PlayPause_OneTrack
) {
399 CreateTextRenderer();
400 AddTextTrack(kTextSubtitles
, "", "", true);
403 EXPECT_CALL(*this, OnPause());
405 DestroyTextRenderer();
408 TEST_F(TextRendererTest
, PlayPause_TwoTracks
) {
409 CreateTextRenderer();
410 AddTextTrack(kTextSubtitles
, "1", "", true);
411 AddTextTrack(kTextSubtitles
, "2", "", true);
414 EXPECT_CALL(*this, OnPause());
416 DestroyTextRenderer();
419 TEST_F(TextRendererTest
, PlayEosPausePending_OneTrack
) {
420 CreateTextRenderer();
421 AddTextTrack(kTextSubtitles
, "", "", true);
424 EXPECT_CALL(*this, OnPause());
425 SendEosNotifications();
426 DestroyTextRenderer();
429 TEST_F(TextRendererTest
, PlayEosPausePending_TwoTracks
) {
430 CreateTextRenderer();
431 AddTextTrack(kTextSubtitles
, "1", "", true);
432 AddTextTrack(kTextSubtitles
, "2", "", true);
435 EXPECT_CALL(*this, OnPause());
436 SendEosNotifications();
437 DestroyTextRenderer();
440 TEST_F(TextRendererTest
, PlayCuePausePending_OneTrack
) {
441 CreateTextRenderer();
442 AddTextTrack(kTextSubtitles
, "", "", true);
445 EXPECT_CALL(*this, OnPause());
447 DestroyTextRenderer();
450 TEST_F(TextRendererTest
, PlayCuePausePending_TwoTracks
) {
451 CreateTextRenderer();
452 AddTextTrack(kTextSubtitles
, "1", "", true);
453 AddTextTrack(kTextSubtitles
, "2", "", true);
456 EXPECT_CALL(*this, OnPause());
458 DestroyTextRenderer();
461 TEST_F(TextRendererTest
, PlayEosPause_OneTrack
) {
462 CreateTextRenderer();
463 AddTextTrack(kTextSubtitles
, "", "", true);
465 EXPECT_CALL(*this, OnEnd());
466 SendEosNotifications();
467 EXPECT_CALL(*this, OnPause());
469 DestroyTextRenderer();
472 TEST_F(TextRendererTest
, PlayEosPause_TwoTracks
) {
473 CreateTextRenderer();
474 AddTextTrack(kTextSubtitles
, "1", "", true);
475 AddTextTrack(kTextSubtitles
, "2", "", true);
477 EXPECT_CALL(*this, OnEnd());
478 SendEosNotifications();
479 EXPECT_CALL(*this, OnPause());
481 DestroyTextRenderer();
484 TEST_F(TextRendererTest
, PlayEosPause_SplitEos
) {
485 CreateTextRenderer();
486 AddTextTrack(kTextSubtitles
, "1", "", true);
487 AddTextTrack(kTextSubtitles
, "2", "", true);
489 SendEosNotification(0);
490 EXPECT_CALL(*this, OnEnd());
491 SendEosNotification(1);
492 EXPECT_CALL(*this, OnPause());
494 DestroyTextRenderer();
497 TEST_F(TextRendererTest
, PlayEosFlush_OneTrack
) {
498 CreateTextRenderer();
499 AddTextTrack(kTextSubtitles
, "", "", true);
501 EXPECT_CALL(*this, OnEnd());
502 SendEosNotifications();
503 EXPECT_CALL(*this, OnPause());
508 EXPECT_CALL(*this, OnEnd());
509 SendEosNotifications();
510 DestroyTextRenderer();
513 TEST_F(TextRendererTest
, PlayEosFlush_TwoTracks
) {
514 CreateTextRenderer();
515 AddTextTrack(kTextSubtitles
, "1", "", true);
516 AddTextTrack(kTextSubtitles
, "2", "", true);
518 EXPECT_CALL(*this, OnEnd());
519 SendEosNotifications();
520 EXPECT_CALL(*this, OnPause());
526 EXPECT_CALL(*this, OnEnd());
527 SendEosNotifications();
528 DestroyTextRenderer();
531 TEST_F(TextRendererTest
, AddTextTrackOnlyRemove_OneTrack
) {
532 CreateTextRenderer();
533 AddTextTrack(kTextSubtitles
, "", "", false);
534 EXPECT_TRUE(text_renderer_
->HasTracks());
535 DestroyTextRenderer();
538 TEST_F(TextRendererTest
, AddTextTrackOnlyRemove_TwoTracks
) {
539 CreateTextRenderer();
540 AddTextTrack(kTextSubtitles
, "track 1", "", false);
541 AddTextTrack(kTextSubtitles
, "track 2", "", false);
543 EXPECT_TRUE(text_renderer_
->HasTracks());
545 EXPECT_FALSE(text_renderer_
->HasTracks());
546 DestroyTextRenderer();
549 TEST_F(TextRendererTest
, AddTrackBeforePlayRemove_OneTrack
) {
550 CreateTextRenderer();
551 AddTextTrack(kTextSubtitles
, "", "", true);
555 EXPECT_FALSE(text_renderer_
->HasTracks());
556 DestroyTextRenderer();
559 TEST_F(TextRendererTest
, AddTrackBeforePlayRemove_TwoTracks
) {
560 CreateTextRenderer();
561 AddTextTrack(kTextSubtitles
, "1", "", true);
562 AddTextTrack(kTextSubtitles
, "2", "", true);
566 EXPECT_TRUE(text_renderer_
->HasTracks());
568 EXPECT_FALSE(text_renderer_
->HasTracks());
569 DestroyTextRenderer();
572 TEST_F(TextRendererTest
, AddTrackBeforePlayRemove_SeparateCancel
) {
573 CreateTextRenderer();
574 AddTextTrack(kTextSubtitles
, "1", "", true);
575 AddTextTrack(kTextSubtitles
, "2", "", true);
579 EXPECT_TRUE(text_renderer_
->HasTracks());
582 EXPECT_FALSE(text_renderer_
->HasTracks());
583 DestroyTextRenderer();
586 TEST_F(TextRendererTest
, AddTrackBeforePlayRemove_RemoveOneThenPlay
) {
587 CreateTextRenderer();
588 AddTextTrack(kTextSubtitles
, "1", "", false);
589 AddTextTrack(kTextSubtitles
, "2", "", true);
591 EXPECT_TRUE(text_renderer_
->HasTracks());
595 EXPECT_FALSE(text_renderer_
->HasTracks());
596 DestroyTextRenderer();
599 TEST_F(TextRendererTest
, AddTrackBeforePlayRemove_RemoveTwoThenPlay
) {
600 CreateTextRenderer();
601 AddTextTrack(kTextSubtitles
, "1", "", false);
602 AddTextTrack(kTextSubtitles
, "2", "", false);
604 EXPECT_TRUE(text_renderer_
->HasTracks());
606 EXPECT_FALSE(text_renderer_
->HasTracks());
608 DestroyTextRenderer();
611 TEST_F(TextRendererTest
, AddTrackAfterPlayRemove_OneTrack
) {
612 CreateTextRenderer();
614 AddTextTrack(kTextSubtitles
, "", "", true);
617 EXPECT_FALSE(text_renderer_
->HasTracks());
618 DestroyTextRenderer();
621 TEST_F(TextRendererTest
, AddTrackAfterPlayRemove_TwoTracks
) {
622 CreateTextRenderer();
624 AddTextTrack(kTextSubtitles
, "1", "", true);
625 AddTextTrack(kTextSubtitles
, "2", "", true);
628 EXPECT_TRUE(text_renderer_
->HasTracks());
630 EXPECT_FALSE(text_renderer_
->HasTracks());
631 DestroyTextRenderer();
634 TEST_F(TextRendererTest
, AddTrackAfterPlayRemove_SplitCancel
) {
635 CreateTextRenderer();
637 AddTextTrack(kTextSubtitles
, "1", "", true);
638 AddTextTrack(kTextSubtitles
, "2", "", true);
641 EXPECT_TRUE(text_renderer_
->HasTracks());
644 EXPECT_FALSE(text_renderer_
->HasTracks());
645 DestroyTextRenderer();
648 TEST_F(TextRendererTest
, AddTrackAfterPlayRemove_SplitAdd
) {
649 CreateTextRenderer();
650 AddTextTrack(kTextSubtitles
, "1", "", true);
652 AddTextTrack(kTextSubtitles
, "2", "", true);
655 EXPECT_TRUE(text_renderer_
->HasTracks());
658 EXPECT_FALSE(text_renderer_
->HasTracks());
659 DestroyTextRenderer();
662 TEST_F(TextRendererTest
, PlayAddCueRemove_OneTrack
) {
663 CreateTextRenderer();
664 AddTextTrack(kTextSubtitles
, "", "", true);
670 EXPECT_FALSE(text_renderer_
->HasTracks());
671 DestroyTextRenderer();
674 TEST_F(TextRendererTest
, PlayAddCueRemove_TwoTracks
) {
675 CreateTextRenderer();
676 AddTextTrack(kTextSubtitles
, "1", "", true);
677 AddTextTrack(kTextSubtitles
, "2", "", true);
685 EXPECT_TRUE(text_renderer_
->HasTracks());
687 EXPECT_FALSE(text_renderer_
->HasTracks());
688 DestroyTextRenderer();
691 TEST_F(TextRendererTest
, PlayEosOnlyRemove_OneTrack
) {
692 CreateTextRenderer();
693 AddTextTrack(kTextSubtitles
, "", "", true);
695 EXPECT_CALL(*this, OnEnd());
696 SendEosNotifications();
698 EXPECT_FALSE(text_renderer_
->HasTracks());
699 DestroyTextRenderer();
702 TEST_F(TextRendererTest
, PlayEosOnlyRemove_TwoTracks
) {
703 CreateTextRenderer();
704 AddTextTrack(kTextSubtitles
, "1", "", true);
705 AddTextTrack(kTextSubtitles
, "2", "", true);
707 EXPECT_CALL(*this, OnEnd());
708 SendEosNotifications();
710 EXPECT_TRUE(text_renderer_
->HasTracks());
712 EXPECT_FALSE(text_renderer_
->HasTracks());
713 DestroyTextRenderer();
716 TEST_F(TextRendererTest
, PlayCueEosRemove_OneTrack
) {
717 CreateTextRenderer();
718 AddTextTrack(kTextSubtitles
, "", "", true);
722 EXPECT_CALL(*this, OnEnd());
723 SendEosNotifications();
725 EXPECT_FALSE(text_renderer_
->HasTracks());
726 DestroyTextRenderer();
729 TEST_F(TextRendererTest
, PlayCueEosRemove_TwoTracks
) {
730 CreateTextRenderer();
731 AddTextTrack(kTextSubtitles
, "1", "", true);
732 AddTextTrack(kTextSubtitles
, "2", "", true);
737 EXPECT_CALL(*this, OnEnd());
738 SendEosNotifications();
740 EXPECT_TRUE(text_renderer_
->HasTracks());
742 EXPECT_FALSE(text_renderer_
->HasTracks());
743 DestroyTextRenderer();
746 TEST_F(TextRendererTest
, TestStopPendingRemove_OneTrack
) {
747 CreateTextRenderer();
748 AddTextTrack(kTextSubtitles
, "", "", true);
751 EXPECT_CALL(*this, OnStop());
752 SendEosNotifications();
754 EXPECT_FALSE(text_renderer_
->HasTracks());
755 text_renderer_
.reset();
756 text_track_streams_
.clear();
759 TEST_F(TextRendererTest
, TestStopPendingRemove_TwoTracks
) {
760 CreateTextRenderer();
761 AddTextTrack(kTextSubtitles
, "1", "", true);
762 AddTextTrack(kTextSubtitles
, "2", "", true);
765 SendEosNotification(0);
766 EXPECT_CALL(*this, OnStop());
767 SendEosNotification(1);
769 EXPECT_TRUE(text_renderer_
->HasTracks());
771 EXPECT_FALSE(text_renderer_
->HasTracks());
772 text_renderer_
.reset();
773 text_track_streams_
.clear();
776 TEST_F(TextRendererTest
, TestStopPendingRemove_RemoveThenSendEos
) {
777 CreateTextRenderer();
778 AddTextTrack(kTextSubtitles
, "1", "", true);
779 AddTextTrack(kTextSubtitles
, "2", "", true);
782 SendEosNotification(0);
784 EXPECT_TRUE(text_renderer_
->HasTracks());
785 EXPECT_CALL(*this, OnStop());
786 SendEosNotification(1);
788 EXPECT_FALSE(text_renderer_
->HasTracks());
789 text_renderer_
.reset();
790 text_track_streams_
.clear();
793 TEST_F(TextRendererTest
, PlayPauseRemove_PauseThenRemove
) {
794 CreateTextRenderer();
795 AddTextTrack(kTextSubtitles
, "", "", true);
798 EXPECT_CALL(*this, OnPause());
801 EXPECT_FALSE(text_renderer_
->HasTracks());
802 DestroyTextRenderer();
805 TEST_F(TextRendererTest
, PlayPauseRemove_RemoveThanPause
) {
806 CreateTextRenderer();
807 AddTextTrack(kTextSubtitles
, "", "", true);
811 EXPECT_FALSE(text_renderer_
->HasTracks());
812 EXPECT_CALL(*this, OnPause());
814 DestroyTextRenderer();
817 TEST_F(TextRendererTest
, PlayPause_PauseThenRemoveTwoTracks
) {
818 CreateTextRenderer();
819 AddTextTrack(kTextSubtitles
, "1", "", true);
820 AddTextTrack(kTextSubtitles
, "2", "", true);
823 EXPECT_CALL(*this, OnPause());
826 EXPECT_TRUE(text_renderer_
->HasTracks());
828 EXPECT_FALSE(text_renderer_
->HasTracks());
829 DestroyTextRenderer();
832 TEST_F(TextRendererTest
, PlayPauseRemove_RemoveThenPauseTwoTracks
) {
833 CreateTextRenderer();
834 AddTextTrack(kTextSubtitles
, "1", "", true);
835 AddTextTrack(kTextSubtitles
, "2", "", true);
839 EXPECT_TRUE(text_renderer_
->HasTracks());
840 EXPECT_CALL(*this, OnPause());
843 EXPECT_FALSE(text_renderer_
->HasTracks());
844 DestroyTextRenderer();
847 TEST_F(TextRendererTest
, PlayPauseRemove_SplitCancel
) {
848 CreateTextRenderer();
849 AddTextTrack(kTextSubtitles
, "1", "", true);
850 AddTextTrack(kTextSubtitles
, "2", "", true);
854 EXPECT_TRUE(text_renderer_
->HasTracks());
856 EXPECT_CALL(*this, OnPause());
859 EXPECT_FALSE(text_renderer_
->HasTracks());
860 DestroyTextRenderer();
864 TEST_F(TextRendererTest
, PlayPauseRemove_PauseLast
) {
865 CreateTextRenderer();
866 AddTextTrack(kTextSubtitles
, "1", "", true);
867 AddTextTrack(kTextSubtitles
, "2", "", true);
871 EXPECT_TRUE(text_renderer_
->HasTracks());
874 EXPECT_FALSE(text_renderer_
->HasTracks());
875 EXPECT_CALL(*this, OnPause());
877 DestroyTextRenderer();
880 TEST_F(TextRendererTest
, PlayEosPausePendingRemove_OneTrack
) {
881 CreateTextRenderer();
882 AddTextTrack(kTextSubtitles
, "", "", true);
885 EXPECT_CALL(*this, OnPause());
886 SendEosNotifications();
888 EXPECT_FALSE(text_renderer_
->HasTracks());
889 DestroyTextRenderer();
892 TEST_F(TextRendererTest
, PlayEosPausePendingRemove_TwoTracks
) {
893 CreateTextRenderer();
894 AddTextTrack(kTextSubtitles
, "1", "", true);
895 AddTextTrack(kTextSubtitles
, "2", "", true);
898 SendEosNotification(0);
899 EXPECT_CALL(*this, OnPause());
900 SendEosNotification(1);
902 EXPECT_TRUE(text_renderer_
->HasTracks());
904 EXPECT_FALSE(text_renderer_
->HasTracks());
905 DestroyTextRenderer();
908 TEST_F(TextRendererTest
, PlayEosPausePendingRemove_SplitEos
) {
909 CreateTextRenderer();
910 AddTextTrack(kTextSubtitles
, "1", "", true);
911 AddTextTrack(kTextSubtitles
, "2", "", true);
914 SendEosNotification(0);
916 EXPECT_TRUE(text_renderer_
->HasTracks());
917 EXPECT_CALL(*this, OnPause());
918 SendEosNotification(1);
920 EXPECT_FALSE(text_renderer_
->HasTracks());
921 DestroyTextRenderer();
924 TEST_F(TextRendererTest
, PlayCuePausePendingRemove_OneTrack
) {
925 CreateTextRenderer();
926 AddTextTrack(kTextSubtitles
, "", "", true);
929 EXPECT_CALL(*this, OnPause());
932 EXPECT_FALSE(text_renderer_
->HasTracks());
933 DestroyTextRenderer();
936 TEST_F(TextRendererTest
, PlayCuePausePendingRemove_TwoTracks
) {
937 CreateTextRenderer();
938 AddTextTrack(kTextSubtitles
, "1", "", true);
939 AddTextTrack(kTextSubtitles
, "2", "", true);
943 EXPECT_CALL(*this, OnPause());
946 EXPECT_TRUE(text_renderer_
->HasTracks());
948 EXPECT_FALSE(text_renderer_
->HasTracks());
949 DestroyTextRenderer();
952 TEST_F(TextRendererTest
, PlayCuePausePendingRemove_SplitSendCue
) {
953 CreateTextRenderer();
954 AddTextTrack(kTextSubtitles
, "1", "", true);
955 AddTextTrack(kTextSubtitles
, "2", "", true);
960 EXPECT_TRUE(text_renderer_
->HasTracks());
961 EXPECT_CALL(*this, OnPause());
964 EXPECT_FALSE(text_renderer_
->HasTracks());
965 DestroyTextRenderer();
968 TEST_F(TextRendererTest
, PlayEosPauseRemove_PauseThenRemove
) {
969 CreateTextRenderer();
970 AddTextTrack(kTextSubtitles
, "", "", true);
972 EXPECT_CALL(*this, OnEnd());
973 SendEosNotifications();
974 EXPECT_CALL(*this, OnPause());
977 EXPECT_FALSE(text_renderer_
->HasTracks());
978 DestroyTextRenderer();
981 TEST_F(TextRendererTest
, PlayEosPauseRemove_RemoveThenPause
) {
982 CreateTextRenderer();
983 AddTextTrack(kTextSubtitles
, "", "", true);
985 EXPECT_CALL(*this, OnEnd());
986 SendEosNotifications();
988 EXPECT_FALSE(text_renderer_
->HasTracks());
989 EXPECT_CALL(*this, OnPause());
991 DestroyTextRenderer();
994 TEST_F(TextRendererTest
, PlayEosPause_PauseThenRemoveTwoTracks
) {
995 CreateTextRenderer();
996 AddTextTrack(kTextSubtitles
, "1", "", true);
997 AddTextTrack(kTextSubtitles
, "2", "", true);
999 SendEosNotification(0);
1000 EXPECT_CALL(*this, OnEnd());
1001 SendEosNotification(1);
1002 EXPECT_CALL(*this, OnPause());
1005 EXPECT_TRUE(text_renderer_
->HasTracks());
1007 EXPECT_FALSE(text_renderer_
->HasTracks());
1008 DestroyTextRenderer();
1011 TEST_F(TextRendererTest
, PlayEosPause_RemovePauseRemove
) {
1012 CreateTextRenderer();
1013 AddTextTrack(kTextSubtitles
, "1", "", true);
1014 AddTextTrack(kTextSubtitles
, "2", "", true);
1016 SendEosNotification(0);
1017 EXPECT_CALL(*this, OnEnd());
1018 SendEosNotification(1);
1020 EXPECT_TRUE(text_renderer_
->HasTracks());
1021 EXPECT_CALL(*this, OnPause());
1024 EXPECT_FALSE(text_renderer_
->HasTracks());
1025 DestroyTextRenderer();
1028 TEST_F(TextRendererTest
, PlayEosPause_EosThenPause
) {
1029 CreateTextRenderer();
1030 AddTextTrack(kTextSubtitles
, "1", "", true);
1031 AddTextTrack(kTextSubtitles
, "2", "", true);
1033 SendEosNotification(0);
1035 EXPECT_TRUE(text_renderer_
->HasTracks());
1036 EXPECT_CALL(*this, OnEnd());
1037 SendEosNotification(1);
1038 EXPECT_CALL(*this, OnPause());
1041 EXPECT_FALSE(text_renderer_
->HasTracks());
1042 DestroyTextRenderer();
1045 TEST_F(TextRendererTest
, PlayEosPause_PauseLast
) {
1046 CreateTextRenderer();
1047 AddTextTrack(kTextSubtitles
, "1", "", true);
1048 AddTextTrack(kTextSubtitles
, "2", "", true);
1050 SendEosNotification(0);
1052 EXPECT_TRUE(text_renderer_
->HasTracks());
1053 EXPECT_CALL(*this, OnEnd());
1054 SendEosNotification(1);
1056 EXPECT_FALSE(text_renderer_
->HasTracks());
1057 EXPECT_CALL(*this, OnPause());
1059 DestroyTextRenderer();
1062 TEST_F(TextRendererTest
, PlayEosPause_EosPauseRemove
) {
1063 CreateTextRenderer();
1064 AddTextTrack(kTextSubtitles
, "1", "", true);
1065 AddTextTrack(kTextSubtitles
, "2", "", true);
1067 SendEosNotification(0);
1068 EXPECT_CALL(*this, OnEnd());
1069 SendEosNotification(1);
1070 EXPECT_CALL(*this, OnPause());
1073 EXPECT_TRUE(text_renderer_
->HasTracks());
1075 EXPECT_FALSE(text_renderer_
->HasTracks());
1076 DestroyTextRenderer();
1079 TEST_F(TextRendererTest
, PlayEosPause_EosRemovePause
) {
1080 CreateTextRenderer();
1081 AddTextTrack(kTextSubtitles
, "1", "", true);
1082 AddTextTrack(kTextSubtitles
, "2", "", true);
1084 SendEosNotification(0);
1085 EXPECT_CALL(*this, OnEnd());
1086 SendEosNotification(1);
1088 EXPECT_TRUE(text_renderer_
->HasTracks());
1089 EXPECT_CALL(*this, OnPause());
1092 EXPECT_FALSE(text_renderer_
->HasTracks());
1093 DestroyTextRenderer();
1096 TEST_F(TextRendererTest
, PlayEosPause_EosRemoveEosPause
) {
1097 CreateTextRenderer();
1098 AddTextTrack(kTextSubtitles
, "1", "", true);
1099 AddTextTrack(kTextSubtitles
, "2", "", true);
1101 SendEosNotification(0);
1103 EXPECT_TRUE(text_renderer_
->HasTracks());
1104 EXPECT_CALL(*this, OnEnd());
1105 SendEosNotification(1);
1106 EXPECT_CALL(*this, OnPause());
1109 EXPECT_FALSE(text_renderer_
->HasTracks());
1110 DestroyTextRenderer();
1113 TEST_F(TextRendererTest
, PlayEosPause_EosRemoveEosRemovePause
) {
1114 CreateTextRenderer();
1115 AddTextTrack(kTextSubtitles
, "1", "", true);
1116 AddTextTrack(kTextSubtitles
, "2", "", true);
1118 SendEosNotification(0);
1120 EXPECT_TRUE(text_renderer_
->HasTracks());
1121 EXPECT_CALL(*this, OnEnd());
1122 SendEosNotification(1);
1124 EXPECT_FALSE(text_renderer_
->HasTracks());
1125 EXPECT_CALL(*this, OnPause());
1127 DestroyTextRenderer();
1130 TEST_F(TextRendererTest
, PlayEosFlushRemove_OneTrack
) {
1131 CreateTextRenderer();
1132 AddTextTrack(kTextSubtitles
, "", "", true);
1134 EXPECT_CALL(*this, OnEnd());
1135 SendEosNotifications();
1136 EXPECT_CALL(*this, OnPause());
1141 EXPECT_CALL(*this, OnEnd());
1142 SendEosNotifications();
1144 EXPECT_FALSE(text_renderer_
->HasTracks());
1145 DestroyTextRenderer();
1148 TEST_F(TextRendererTest
, PlayEosFlushRemove_TwoTracks
) {
1149 CreateTextRenderer();
1150 AddTextTrack(kTextSubtitles
, "1", "", true);
1151 AddTextTrack(kTextSubtitles
, "2", "", true);
1153 EXPECT_CALL(*this, OnEnd());
1154 SendEosNotifications();
1155 EXPECT_CALL(*this, OnPause());
1161 SendEosNotification(0);
1162 EXPECT_CALL(*this, OnEnd());
1163 SendEosNotification(1);
1165 EXPECT_TRUE(text_renderer_
->HasTracks());
1167 EXPECT_FALSE(text_renderer_
->HasTracks());
1168 DestroyTextRenderer();
1171 TEST_F(TextRendererTest
, PlayEosFlushRemove_EosRemove
) {
1172 CreateTextRenderer();
1173 AddTextTrack(kTextSubtitles
, "1", "", true);
1174 AddTextTrack(kTextSubtitles
, "2", "", true);
1176 EXPECT_CALL(*this, OnEnd());
1177 SendEosNotifications();
1178 EXPECT_CALL(*this, OnPause());
1184 SendEosNotification(0);
1186 EXPECT_TRUE(text_renderer_
->HasTracks());
1187 EXPECT_CALL(*this, OnEnd());
1188 SendEosNotification(1);
1190 EXPECT_FALSE(text_renderer_
->HasTracks());
1191 DestroyTextRenderer();
1194 TEST_F(TextRendererTest
, PlayShort_SendCueThenEos
) {
1195 CreateTextRenderer();
1196 AddTextTrack(kTextSubtitles
, "1", "", true);
1197 AddTextTrack(kTextSubtitles
, "2", "", true);
1201 EXPECT_CALL(*this, OnPause());
1202 SendEosNotification(1);
1203 DestroyTextRenderer();
1206 TEST_F(TextRendererTest
, PlayShort_EosThenSendCue
) {
1207 CreateTextRenderer();
1208 AddTextTrack(kTextSubtitles
, "1", "", true);
1209 AddTextTrack(kTextSubtitles
, "2", "", true);
1212 SendEosNotification(0);
1213 EXPECT_CALL(*this, OnPause());
1215 DestroyTextRenderer();
1218 TEST_F(TextRendererTest
, PlayShortRemove_SendEosRemove
) {
1219 CreateTextRenderer();
1220 AddTextTrack(kTextSubtitles
, "1", "", true);
1221 AddTextTrack(kTextSubtitles
, "2", "", true);
1225 EXPECT_CALL(*this, OnPause());
1226 SendEosNotification(1);
1228 EXPECT_TRUE(text_renderer_
->HasTracks());
1230 EXPECT_FALSE(text_renderer_
->HasTracks());
1231 DestroyTextRenderer();
1234 TEST_F(TextRendererTest
, PlayShortRemove_SendRemoveEos
) {
1235 CreateTextRenderer();
1236 AddTextTrack(kTextSubtitles
, "1", "", true);
1237 AddTextTrack(kTextSubtitles
, "2", "", true);
1242 EXPECT_TRUE(text_renderer_
->HasTracks());
1243 EXPECT_CALL(*this, OnPause());
1244 SendEosNotification(1);
1246 EXPECT_FALSE(text_renderer_
->HasTracks());
1247 DestroyTextRenderer();
1250 TEST_F(TextRendererTest
, PlayCuePausePendingCancel_OneTrack
) {
1251 CreateTextRenderer();
1252 AddTextTrack(kTextSubtitles
, "", "", true);
1255 EXPECT_CALL(*this, OnPause());
1256 AbortPendingRead(0);
1257 DestroyTextRenderer();
1260 TEST_F(TextRendererTest
, PlayCuePausePendingCancel_SendThenCancel
) {
1261 CreateTextRenderer();
1262 AddTextTrack(kTextSubtitles
, "1", "", true);
1263 AddTextTrack(kTextSubtitles
, "2", "", true);
1267 EXPECT_CALL(*this, OnPause());
1268 AbortPendingRead(1);
1269 DestroyTextRenderer();
1272 TEST_F(TextRendererTest
, PlayCuePausePendingCancel_CancelThenSend
) {
1273 CreateTextRenderer();
1274 AddTextTrack(kTextSubtitles
, "1", "", true);
1275 AddTextTrack(kTextSubtitles
, "2", "", true);
1278 AbortPendingRead(0);
1279 EXPECT_CALL(*this, OnPause());
1281 DestroyTextRenderer();
1284 TEST_F(TextRendererTest
, PlayCueStopPendingCancel_OneTrack
) {
1285 CreateTextRenderer();
1286 AddTextTrack(kTextSubtitles
, "", "", true);
1290 EXPECT_CALL(*this, OnStop());
1291 AbortPendingRead(0);
1292 text_renderer_
.reset();
1293 text_track_streams_
.clear();
1296 TEST_F(TextRendererTest
, PlayCueStopPendingCancel_SendThenCancel
) {
1297 CreateTextRenderer();
1298 AddTextTrack(kTextSubtitles
, "1", "", true);
1299 AddTextTrack(kTextSubtitles
, "2", "", true);
1304 EXPECT_CALL(*this, OnStop());
1305 AbortPendingRead(1);
1306 text_renderer_
.reset();
1307 text_track_streams_
.clear();
1310 TEST_F(TextRendererTest
, PlayCueStopPendingCancel_CancelThenSend
) {
1311 CreateTextRenderer();
1312 AddTextTrack(kTextSubtitles
, "1", "", true);
1313 AddTextTrack(kTextSubtitles
, "2", "", true);
1317 AbortPendingRead(0);
1318 EXPECT_CALL(*this, OnStop());
1320 text_renderer_
.reset();
1321 text_track_streams_
.clear();
1324 TEST_F(TextRendererTest
, AddRemoveAdd
) {
1325 CreateTextRenderer();
1326 AddTextTrack(kTextSubtitles
, "", "", true);
1328 AbortPendingRead(0);
1330 EXPECT_CALL(*this, OnPause());
1332 AddTextTrack(kTextSubtitles
, "", "", true);
1334 EXPECT_CALL(*this, OnEnd());
1335 SendEosNotification(1);
1336 DestroyTextRenderer();
1339 TEST_F(TextRendererTest
, AddRemoveEos
) {
1340 CreateTextRenderer();
1341 AddTextTrack(kTextSubtitles
, "1", "", true);
1342 AddTextTrack(kTextSubtitles
, "2", "", true);
1344 AbortPendingRead(0);
1346 EXPECT_TRUE(text_renderer_
->HasTracks());
1347 EXPECT_CALL(*this, OnEnd());
1348 SendEosNotification(1);
1349 DestroyTextRenderer();
1352 TEST_F(TextRendererTest
, AddRemovePause
) {
1353 CreateTextRenderer();
1354 AddTextTrack(kTextSubtitles
, "1", "", true);
1355 AddTextTrack(kTextSubtitles
, "2", "", true);
1357 AbortPendingRead(0);
1359 EXPECT_TRUE(text_renderer_
->HasTracks());
1361 EXPECT_CALL(*this, OnPause());
1362 SendEosNotification(1);
1363 DestroyTextRenderer();
1366 TEST_F(TextRendererTest
, AddRemovePauseStop
) {
1367 CreateTextRenderer();
1368 AddTextTrack(kTextSubtitles
, "1", "", true);
1369 AddTextTrack(kTextSubtitles
, "2", "", true);
1371 AbortPendingRead(0);
1373 EXPECT_TRUE(text_renderer_
->HasTracks());
1376 EXPECT_CALL(*this, OnStop());
1377 SendEosNotification(1);
1378 text_renderer_
.reset();
1379 text_track_streams_
.clear();
1382 } // namespace media