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"
24 // Local implementation of the TextTrack interface.
25 class FakeTextTrack
: public TextTrack
{
27 FakeTextTrack(const base::Closure
& destroy_cb
,
28 const TextTrackConfig
& config
)
29 : destroy_cb_(destroy_cb
),
32 virtual ~FakeTextTrack() {
36 MOCK_METHOD5(addWebVTTCue
, void(const base::TimeDelta
& start
,
37 const base::TimeDelta
& end
,
38 const std::string
& id
,
39 const std::string
& content
,
40 const std::string
& settings
));
42 const base::Closure destroy_cb_
;
43 const TextTrackConfig config_
;
46 DISALLOW_COPY_AND_ASSIGN(FakeTextTrack
);
49 class TextRendererTest
: public testing::Test
{
53 void CreateTextRenderer() {
54 DCHECK(!text_renderer_
);
57 new TextRenderer(message_loop_
.message_loop_proxy(),
58 base::Bind(&TextRendererTest::OnAddTextTrack
,
59 base::Unretained(this))));
60 text_renderer_
->Initialize(base::Bind(&TextRendererTest::OnEnd
,
61 base::Unretained(this)));
65 text_renderer_
.reset();
66 message_loop_
.RunUntilIdle();
69 void AddTextTrack(TextKind kind
,
70 const std::string
& name
,
71 const std::string
& language
,
73 const size_t idx
= text_track_streams_
.size();
74 text_track_streams_
.push_back(new FakeTextTrackStream
);
79 const TextTrackConfig
config(kind
, name
, language
, std::string());
80 text_renderer_
->AddTextStream(text_track_streams_
.back(), config
);
81 message_loop_
.RunUntilIdle();
83 EXPECT_EQ(text_tracks_
.size(), text_track_streams_
.size());
84 FakeTextTrack
* const text_track
= text_tracks_
.back();
85 EXPECT_TRUE(text_track
);
86 EXPECT_TRUE(text_track
->config_
.Matches(config
));
89 void OnAddTextTrack(const TextTrackConfig
& config
,
90 const AddTextTrackDoneCB
& done_cb
) {
91 base::Closure destroy_cb
=
92 base::Bind(&TextRendererTest::OnDestroyTextTrack
,
93 base::Unretained(this),
95 // Text track objects are owned by the text renderer, but we cache them
96 // here so we can inspect them. They get removed from our cache when the
97 // text renderer deallocates them.
98 text_tracks_
.push_back(new FakeTextTrack(destroy_cb
, config
));
99 scoped_ptr
<TextTrack
> text_track(text_tracks_
.back());
100 done_cb
.Run(text_track
.Pass());
103 void RemoveTextTrack(unsigned idx
) {
104 FakeTextTrackStream
* const stream
= text_track_streams_
[idx
];
105 text_renderer_
->RemoveTextStream(stream
);
106 EXPECT_FALSE(text_tracks_
[idx
]);
109 void SatisfyPendingReads(const base::TimeDelta
& start
,
110 const base::TimeDelta
& duration
,
111 const std::string
& id
,
112 const std::string
& content
,
113 const std::string
& settings
) {
114 for (TextTrackStreams::iterator itr
= text_track_streams_
.begin();
115 itr
!= text_track_streams_
.end(); ++itr
) {
116 (*itr
)->SatisfyPendingRead(start
, duration
, id
, content
, settings
);
120 void AbortPendingRead(unsigned idx
) {
121 FakeTextTrackStream
* const stream
= text_track_streams_
[idx
];
122 stream
->AbortPendingRead();
123 message_loop_
.RunUntilIdle();
126 void AbortPendingReads() {
127 for (size_t idx
= 0; idx
< text_track_streams_
.size(); ++idx
) {
128 AbortPendingRead(idx
);
132 void SendEosNotification(unsigned idx
) {
133 FakeTextTrackStream
* const stream
= text_track_streams_
[idx
];
134 stream
->SendEosNotification();
135 message_loop_
.RunUntilIdle();
138 void SendEosNotifications() {
139 for (size_t idx
= 0; idx
< text_track_streams_
.size(); ++idx
) {
140 SendEosNotification(idx
);
144 void SendCue(unsigned idx
, bool expect_cue
) {
145 FakeTextTrackStream
* const text_stream
= text_track_streams_
[idx
];
147 const base::TimeDelta start
;
148 const base::TimeDelta duration
= base::TimeDelta::FromSeconds(42);
149 const std::string id
= "id";
150 const std::string content
= "subtitle";
151 const std::string settings
;
154 FakeTextTrack
* const text_track
= text_tracks_
[idx
];
155 EXPECT_CALL(*text_track
, addWebVTTCue(start
,
162 text_stream
->SatisfyPendingRead(start
, duration
, id
, content
, settings
);
163 message_loop_
.RunUntilIdle();
166 void SendCues(bool expect_cue
) {
167 for (size_t idx
= 0; idx
< text_track_streams_
.size(); ++idx
) {
168 SendCue(idx
, expect_cue
);
172 void OnDestroyTextTrack(unsigned idx
) {
173 text_tracks_
[idx
] = NULL
;
177 text_renderer_
->StartPlaying();
181 text_renderer_
->Pause(base::Bind(&TextRendererTest::OnPause
,
182 base::Unretained(this)));
183 message_loop_
.RunUntilIdle();
187 EXPECT_CALL(*this, OnFlush());
188 text_renderer_
->Flush(base::Bind(&TextRendererTest::OnFlush
,
189 base::Unretained(this)));
192 void ExpectRead(size_t idx
) {
193 FakeTextTrackStream
* const stream
= text_track_streams_
[idx
];
194 EXPECT_CALL(*stream
, OnRead());
197 MOCK_METHOD0(OnEnd
, void());
198 MOCK_METHOD0(OnPause
, void());
199 MOCK_METHOD0(OnFlush
, void());
201 base::MessageLoop message_loop_
;
203 typedef ScopedVector
<FakeTextTrackStream
> TextTrackStreams
;
204 TextTrackStreams text_track_streams_
;
206 typedef std::vector
<FakeTextTrack
*> TextTracks
;
207 TextTracks text_tracks_
;
209 scoped_ptr
<TextRenderer
> text_renderer_
;
212 DISALLOW_COPY_AND_ASSIGN(TextRendererTest
);
215 TEST_F(TextRendererTest
, CreateTextRendererNoInit
) {
216 text_renderer_
.reset(
217 new TextRenderer(message_loop_
.message_loop_proxy(),
218 base::Bind(&TextRendererTest::OnAddTextTrack
,
219 base::Unretained(this))));
220 text_renderer_
.reset();
223 TEST_F(TextRendererTest
, Create
) {
224 CreateTextRenderer();
227 TEST_F(TextRendererTest
, AddTextTrackOnly_OneTrack
) {
228 CreateTextRenderer();
229 AddTextTrack(kTextSubtitles
, "", "", false);
232 TEST_F(TextRendererTest
, AddTextTrackOnly_TwoTracks
) {
233 CreateTextRenderer();
234 AddTextTrack(kTextSubtitles
, "track 1", "", false);
235 AddTextTrack(kTextSubtitles
, "track 2", "", false);
238 TEST_F(TextRendererTest
, PlayOnly
) {
239 CreateTextRenderer();
243 TEST_F(TextRendererTest
, AddTrackBeforePlay_OneTrack
) {
244 CreateTextRenderer();
245 AddTextTrack(kTextSubtitles
, "", "", true);
250 TEST_F(TextRendererTest
, AddTrackBeforePlay_TwoTracks
) {
251 CreateTextRenderer();
252 AddTextTrack(kTextSubtitles
, "1", "", true);
253 AddTextTrack(kTextSubtitles
, "2", "", true);
258 TEST_F(TextRendererTest
, AddTrackAfterPlay_OneTrackAfter
) {
259 CreateTextRenderer();
261 AddTextTrack(kTextSubtitles
, "", "", true);
265 TEST_F(TextRendererTest
, AddTrackAfterPlay_TwoTracksAfter
) {
266 CreateTextRenderer();
268 AddTextTrack(kTextSubtitles
, "1", "", true);
269 AddTextTrack(kTextSubtitles
, "2", "", true);
273 TEST_F(TextRendererTest
, AddTrackAfterPlay_OneTrackBeforeOneTrackAfter
) {
274 CreateTextRenderer();
275 AddTextTrack(kTextSubtitles
, "1", "", true);
277 AddTextTrack(kTextSubtitles
, "2", "", true);
281 TEST_F(TextRendererTest
, PlayAddCue_OneTrack
) {
282 CreateTextRenderer();
283 AddTextTrack(kTextSubtitles
, "", "", true);
290 TEST_F(TextRendererTest
, PlayAddCue_TwoTracks
) {
291 CreateTextRenderer();
292 AddTextTrack(kTextSubtitles
, "1", "", true);
293 AddTextTrack(kTextSubtitles
, "2", "", true);
301 TEST_F(TextRendererTest
, PlayEosOnly_OneTrack
) {
302 CreateTextRenderer();
303 AddTextTrack(kTextSubtitles
, "", "", true);
305 EXPECT_CALL(*this, OnEnd());
306 SendEosNotifications();
309 TEST_F(TextRendererTest
, PlayEosOnly_TwoTracks
) {
310 CreateTextRenderer();
311 AddTextTrack(kTextSubtitles
, "1", "", true);
312 AddTextTrack(kTextSubtitles
, "2", "", true);
314 EXPECT_CALL(*this, OnEnd());
315 SendEosNotifications();
318 TEST_F(TextRendererTest
, PlayCueEos_OneTrack
) {
319 CreateTextRenderer();
320 AddTextTrack(kTextSubtitles
, "", "", true);
324 EXPECT_CALL(*this, OnEnd());
325 SendEosNotifications();
328 TEST_F(TextRendererTest
, PlayCueEos_TwoTracks
) {
329 CreateTextRenderer();
330 AddTextTrack(kTextSubtitles
, "1", "", true);
331 AddTextTrack(kTextSubtitles
, "2", "", true);
336 EXPECT_CALL(*this, OnEnd());
337 SendEosNotifications();
340 TEST_F(TextRendererTest
, DestroyPending_OneTrack
) {
341 CreateTextRenderer();
342 AddTextTrack(kTextSubtitles
, "", "", true);
345 SendEosNotifications();
348 TEST_F(TextRendererTest
, DestroyPending_TwoTracks
) {
349 CreateTextRenderer();
350 AddTextTrack(kTextSubtitles
, "1", "", true);
351 AddTextTrack(kTextSubtitles
, "2", "", true);
354 SendEosNotifications();
357 TEST_F(TextRendererTest
, PlayPause_OneTrack
) {
358 CreateTextRenderer();
359 AddTextTrack(kTextSubtitles
, "", "", true);
362 EXPECT_CALL(*this, OnPause());
366 TEST_F(TextRendererTest
, PlayPause_TwoTracks
) {
367 CreateTextRenderer();
368 AddTextTrack(kTextSubtitles
, "1", "", true);
369 AddTextTrack(kTextSubtitles
, "2", "", true);
372 EXPECT_CALL(*this, OnPause());
376 TEST_F(TextRendererTest
, PlayEosPausePending_OneTrack
) {
377 CreateTextRenderer();
378 AddTextTrack(kTextSubtitles
, "", "", true);
381 EXPECT_CALL(*this, OnPause());
382 SendEosNotifications();
385 TEST_F(TextRendererTest
, PlayEosPausePending_TwoTracks
) {
386 CreateTextRenderer();
387 AddTextTrack(kTextSubtitles
, "1", "", true);
388 AddTextTrack(kTextSubtitles
, "2", "", true);
391 EXPECT_CALL(*this, OnPause());
392 SendEosNotifications();
395 TEST_F(TextRendererTest
, PlayCuePausePending_OneTrack
) {
396 CreateTextRenderer();
397 AddTextTrack(kTextSubtitles
, "", "", true);
400 EXPECT_CALL(*this, OnPause());
404 TEST_F(TextRendererTest
, PlayCuePausePending_TwoTracks
) {
405 CreateTextRenderer();
406 AddTextTrack(kTextSubtitles
, "1", "", true);
407 AddTextTrack(kTextSubtitles
, "2", "", true);
410 EXPECT_CALL(*this, OnPause());
414 TEST_F(TextRendererTest
, PlayEosPause_OneTrack
) {
415 CreateTextRenderer();
416 AddTextTrack(kTextSubtitles
, "", "", true);
418 EXPECT_CALL(*this, OnEnd());
419 SendEosNotifications();
420 EXPECT_CALL(*this, OnPause());
424 TEST_F(TextRendererTest
, PlayEosPause_TwoTracks
) {
425 CreateTextRenderer();
426 AddTextTrack(kTextSubtitles
, "1", "", true);
427 AddTextTrack(kTextSubtitles
, "2", "", true);
429 EXPECT_CALL(*this, OnEnd());
430 SendEosNotifications();
431 EXPECT_CALL(*this, OnPause());
435 TEST_F(TextRendererTest
, PlayEosPause_SplitEos
) {
436 CreateTextRenderer();
437 AddTextTrack(kTextSubtitles
, "1", "", true);
438 AddTextTrack(kTextSubtitles
, "2", "", true);
440 SendEosNotification(0);
441 EXPECT_CALL(*this, OnEnd());
442 SendEosNotification(1);
443 EXPECT_CALL(*this, OnPause());
447 TEST_F(TextRendererTest
, PlayEosFlush_OneTrack
) {
448 CreateTextRenderer();
449 AddTextTrack(kTextSubtitles
, "", "", true);
451 EXPECT_CALL(*this, OnEnd());
452 SendEosNotifications();
453 EXPECT_CALL(*this, OnPause());
458 EXPECT_CALL(*this, OnEnd());
459 SendEosNotifications();
462 TEST_F(TextRendererTest
, PlayEosFlush_TwoTracks
) {
463 CreateTextRenderer();
464 AddTextTrack(kTextSubtitles
, "1", "", true);
465 AddTextTrack(kTextSubtitles
, "2", "", true);
467 EXPECT_CALL(*this, OnEnd());
468 SendEosNotifications();
469 EXPECT_CALL(*this, OnPause());
475 EXPECT_CALL(*this, OnEnd());
476 SendEosNotifications();
479 TEST_F(TextRendererTest
, AddTextTrackOnlyRemove_OneTrack
) {
480 CreateTextRenderer();
481 AddTextTrack(kTextSubtitles
, "", "", false);
482 EXPECT_TRUE(text_renderer_
->HasTracks());
485 TEST_F(TextRendererTest
, AddTextTrackOnlyRemove_TwoTracks
) {
486 CreateTextRenderer();
487 AddTextTrack(kTextSubtitles
, "track 1", "", false);
488 AddTextTrack(kTextSubtitles
, "track 2", "", false);
490 EXPECT_TRUE(text_renderer_
->HasTracks());
492 EXPECT_FALSE(text_renderer_
->HasTracks());
495 TEST_F(TextRendererTest
, AddTrackBeforePlayRemove_OneTrack
) {
496 CreateTextRenderer();
497 AddTextTrack(kTextSubtitles
, "", "", true);
501 EXPECT_FALSE(text_renderer_
->HasTracks());
504 TEST_F(TextRendererTest
, AddTrackBeforePlayRemove_TwoTracks
) {
505 CreateTextRenderer();
506 AddTextTrack(kTextSubtitles
, "1", "", true);
507 AddTextTrack(kTextSubtitles
, "2", "", true);
511 EXPECT_TRUE(text_renderer_
->HasTracks());
513 EXPECT_FALSE(text_renderer_
->HasTracks());
516 TEST_F(TextRendererTest
, AddTrackBeforePlayRemove_SeparateCancel
) {
517 CreateTextRenderer();
518 AddTextTrack(kTextSubtitles
, "1", "", true);
519 AddTextTrack(kTextSubtitles
, "2", "", true);
523 EXPECT_TRUE(text_renderer_
->HasTracks());
526 EXPECT_FALSE(text_renderer_
->HasTracks());
529 TEST_F(TextRendererTest
, AddTrackBeforePlayRemove_RemoveOneThenPlay
) {
530 CreateTextRenderer();
531 AddTextTrack(kTextSubtitles
, "1", "", false);
532 AddTextTrack(kTextSubtitles
, "2", "", true);
534 EXPECT_TRUE(text_renderer_
->HasTracks());
538 EXPECT_FALSE(text_renderer_
->HasTracks());
541 TEST_F(TextRendererTest
, AddTrackBeforePlayRemove_RemoveTwoThenPlay
) {
542 CreateTextRenderer();
543 AddTextTrack(kTextSubtitles
, "1", "", false);
544 AddTextTrack(kTextSubtitles
, "2", "", false);
546 EXPECT_TRUE(text_renderer_
->HasTracks());
548 EXPECT_FALSE(text_renderer_
->HasTracks());
552 TEST_F(TextRendererTest
, AddTrackAfterPlayRemove_OneTrack
) {
553 CreateTextRenderer();
555 AddTextTrack(kTextSubtitles
, "", "", true);
558 EXPECT_FALSE(text_renderer_
->HasTracks());
561 TEST_F(TextRendererTest
, AddTrackAfterPlayRemove_TwoTracks
) {
562 CreateTextRenderer();
564 AddTextTrack(kTextSubtitles
, "1", "", true);
565 AddTextTrack(kTextSubtitles
, "2", "", true);
568 EXPECT_TRUE(text_renderer_
->HasTracks());
570 EXPECT_FALSE(text_renderer_
->HasTracks());
573 TEST_F(TextRendererTest
, AddTrackAfterPlayRemove_SplitCancel
) {
574 CreateTextRenderer();
576 AddTextTrack(kTextSubtitles
, "1", "", true);
577 AddTextTrack(kTextSubtitles
, "2", "", true);
580 EXPECT_TRUE(text_renderer_
->HasTracks());
583 EXPECT_FALSE(text_renderer_
->HasTracks());
586 TEST_F(TextRendererTest
, AddTrackAfterPlayRemove_SplitAdd
) {
587 CreateTextRenderer();
588 AddTextTrack(kTextSubtitles
, "1", "", true);
590 AddTextTrack(kTextSubtitles
, "2", "", true);
593 EXPECT_TRUE(text_renderer_
->HasTracks());
596 EXPECT_FALSE(text_renderer_
->HasTracks());
599 TEST_F(TextRendererTest
, PlayAddCueRemove_OneTrack
) {
600 CreateTextRenderer();
601 AddTextTrack(kTextSubtitles
, "", "", true);
607 EXPECT_FALSE(text_renderer_
->HasTracks());
610 TEST_F(TextRendererTest
, PlayAddCueRemove_TwoTracks
) {
611 CreateTextRenderer();
612 AddTextTrack(kTextSubtitles
, "1", "", true);
613 AddTextTrack(kTextSubtitles
, "2", "", true);
621 EXPECT_TRUE(text_renderer_
->HasTracks());
623 EXPECT_FALSE(text_renderer_
->HasTracks());
626 TEST_F(TextRendererTest
, PlayEosOnlyRemove_OneTrack
) {
627 CreateTextRenderer();
628 AddTextTrack(kTextSubtitles
, "", "", true);
630 EXPECT_CALL(*this, OnEnd());
631 SendEosNotifications();
633 EXPECT_FALSE(text_renderer_
->HasTracks());
636 TEST_F(TextRendererTest
, PlayEosOnlyRemove_TwoTracks
) {
637 CreateTextRenderer();
638 AddTextTrack(kTextSubtitles
, "1", "", true);
639 AddTextTrack(kTextSubtitles
, "2", "", true);
641 EXPECT_CALL(*this, OnEnd());
642 SendEosNotifications();
644 EXPECT_TRUE(text_renderer_
->HasTracks());
646 EXPECT_FALSE(text_renderer_
->HasTracks());
649 TEST_F(TextRendererTest
, PlayCueEosRemove_OneTrack
) {
650 CreateTextRenderer();
651 AddTextTrack(kTextSubtitles
, "", "", true);
655 EXPECT_CALL(*this, OnEnd());
656 SendEosNotifications();
658 EXPECT_FALSE(text_renderer_
->HasTracks());
661 TEST_F(TextRendererTest
, PlayCueEosRemove_TwoTracks
) {
662 CreateTextRenderer();
663 AddTextTrack(kTextSubtitles
, "1", "", true);
664 AddTextTrack(kTextSubtitles
, "2", "", true);
669 EXPECT_CALL(*this, OnEnd());
670 SendEosNotifications();
672 EXPECT_TRUE(text_renderer_
->HasTracks());
674 EXPECT_FALSE(text_renderer_
->HasTracks());
677 TEST_F(TextRendererTest
, PlayPauseRemove_PauseThenRemove
) {
678 CreateTextRenderer();
679 AddTextTrack(kTextSubtitles
, "", "", true);
682 EXPECT_CALL(*this, OnPause());
685 EXPECT_FALSE(text_renderer_
->HasTracks());
688 TEST_F(TextRendererTest
, PlayPauseRemove_RemoveThanPause
) {
689 CreateTextRenderer();
690 AddTextTrack(kTextSubtitles
, "", "", true);
694 EXPECT_FALSE(text_renderer_
->HasTracks());
695 EXPECT_CALL(*this, OnPause());
699 TEST_F(TextRendererTest
, PlayPause_PauseThenRemoveTwoTracks
) {
700 CreateTextRenderer();
701 AddTextTrack(kTextSubtitles
, "1", "", true);
702 AddTextTrack(kTextSubtitles
, "2", "", true);
705 EXPECT_CALL(*this, OnPause());
708 EXPECT_TRUE(text_renderer_
->HasTracks());
710 EXPECT_FALSE(text_renderer_
->HasTracks());
713 TEST_F(TextRendererTest
, PlayPauseRemove_RemoveThenPauseTwoTracks
) {
714 CreateTextRenderer();
715 AddTextTrack(kTextSubtitles
, "1", "", true);
716 AddTextTrack(kTextSubtitles
, "2", "", true);
720 EXPECT_TRUE(text_renderer_
->HasTracks());
721 EXPECT_CALL(*this, OnPause());
724 EXPECT_FALSE(text_renderer_
->HasTracks());
727 TEST_F(TextRendererTest
, PlayPauseRemove_SplitCancel
) {
728 CreateTextRenderer();
729 AddTextTrack(kTextSubtitles
, "1", "", true);
730 AddTextTrack(kTextSubtitles
, "2", "", true);
734 EXPECT_TRUE(text_renderer_
->HasTracks());
736 EXPECT_CALL(*this, OnPause());
739 EXPECT_FALSE(text_renderer_
->HasTracks());
743 TEST_F(TextRendererTest
, PlayPauseRemove_PauseLast
) {
744 CreateTextRenderer();
745 AddTextTrack(kTextSubtitles
, "1", "", true);
746 AddTextTrack(kTextSubtitles
, "2", "", true);
750 EXPECT_TRUE(text_renderer_
->HasTracks());
753 EXPECT_FALSE(text_renderer_
->HasTracks());
754 EXPECT_CALL(*this, OnPause());
758 TEST_F(TextRendererTest
, PlayEosPausePendingRemove_OneTrack
) {
759 CreateTextRenderer();
760 AddTextTrack(kTextSubtitles
, "", "", true);
763 EXPECT_CALL(*this, OnPause());
764 SendEosNotifications();
766 EXPECT_FALSE(text_renderer_
->HasTracks());
769 TEST_F(TextRendererTest
, PlayEosPausePendingRemove_TwoTracks
) {
770 CreateTextRenderer();
771 AddTextTrack(kTextSubtitles
, "1", "", true);
772 AddTextTrack(kTextSubtitles
, "2", "", true);
775 SendEosNotification(0);
776 EXPECT_CALL(*this, OnPause());
777 SendEosNotification(1);
779 EXPECT_TRUE(text_renderer_
->HasTracks());
781 EXPECT_FALSE(text_renderer_
->HasTracks());
784 TEST_F(TextRendererTest
, PlayEosPausePendingRemove_SplitEos
) {
785 CreateTextRenderer();
786 AddTextTrack(kTextSubtitles
, "1", "", true);
787 AddTextTrack(kTextSubtitles
, "2", "", true);
790 SendEosNotification(0);
792 EXPECT_TRUE(text_renderer_
->HasTracks());
793 EXPECT_CALL(*this, OnPause());
794 SendEosNotification(1);
796 EXPECT_FALSE(text_renderer_
->HasTracks());
799 TEST_F(TextRendererTest
, PlayCuePausePendingRemove_OneTrack
) {
800 CreateTextRenderer();
801 AddTextTrack(kTextSubtitles
, "", "", true);
804 EXPECT_CALL(*this, OnPause());
807 EXPECT_FALSE(text_renderer_
->HasTracks());
810 TEST_F(TextRendererTest
, PlayCuePausePendingRemove_TwoTracks
) {
811 CreateTextRenderer();
812 AddTextTrack(kTextSubtitles
, "1", "", true);
813 AddTextTrack(kTextSubtitles
, "2", "", true);
817 EXPECT_CALL(*this, OnPause());
820 EXPECT_TRUE(text_renderer_
->HasTracks());
822 EXPECT_FALSE(text_renderer_
->HasTracks());
825 TEST_F(TextRendererTest
, PlayCuePausePendingRemove_SplitSendCue
) {
826 CreateTextRenderer();
827 AddTextTrack(kTextSubtitles
, "1", "", true);
828 AddTextTrack(kTextSubtitles
, "2", "", true);
833 EXPECT_TRUE(text_renderer_
->HasTracks());
834 EXPECT_CALL(*this, OnPause());
837 EXPECT_FALSE(text_renderer_
->HasTracks());
840 TEST_F(TextRendererTest
, PlayEosPauseRemove_PauseThenRemove
) {
841 CreateTextRenderer();
842 AddTextTrack(kTextSubtitles
, "", "", true);
844 EXPECT_CALL(*this, OnEnd());
845 SendEosNotifications();
846 EXPECT_CALL(*this, OnPause());
849 EXPECT_FALSE(text_renderer_
->HasTracks());
852 TEST_F(TextRendererTest
, PlayEosPauseRemove_RemoveThenPause
) {
853 CreateTextRenderer();
854 AddTextTrack(kTextSubtitles
, "", "", true);
856 EXPECT_CALL(*this, OnEnd());
857 SendEosNotifications();
859 EXPECT_FALSE(text_renderer_
->HasTracks());
860 EXPECT_CALL(*this, OnPause());
864 TEST_F(TextRendererTest
, PlayEosPause_PauseThenRemoveTwoTracks
) {
865 CreateTextRenderer();
866 AddTextTrack(kTextSubtitles
, "1", "", true);
867 AddTextTrack(kTextSubtitles
, "2", "", true);
869 SendEosNotification(0);
870 EXPECT_CALL(*this, OnEnd());
871 SendEosNotification(1);
872 EXPECT_CALL(*this, OnPause());
875 EXPECT_TRUE(text_renderer_
->HasTracks());
877 EXPECT_FALSE(text_renderer_
->HasTracks());
880 TEST_F(TextRendererTest
, PlayEosPause_RemovePauseRemove
) {
881 CreateTextRenderer();
882 AddTextTrack(kTextSubtitles
, "1", "", true);
883 AddTextTrack(kTextSubtitles
, "2", "", true);
885 SendEosNotification(0);
886 EXPECT_CALL(*this, OnEnd());
887 SendEosNotification(1);
889 EXPECT_TRUE(text_renderer_
->HasTracks());
890 EXPECT_CALL(*this, OnPause());
893 EXPECT_FALSE(text_renderer_
->HasTracks());
896 TEST_F(TextRendererTest
, PlayEosPause_EosThenPause
) {
897 CreateTextRenderer();
898 AddTextTrack(kTextSubtitles
, "1", "", true);
899 AddTextTrack(kTextSubtitles
, "2", "", true);
901 SendEosNotification(0);
903 EXPECT_TRUE(text_renderer_
->HasTracks());
904 EXPECT_CALL(*this, OnEnd());
905 SendEosNotification(1);
906 EXPECT_CALL(*this, OnPause());
909 EXPECT_FALSE(text_renderer_
->HasTracks());
912 TEST_F(TextRendererTest
, PlayEosPause_PauseLast
) {
913 CreateTextRenderer();
914 AddTextTrack(kTextSubtitles
, "1", "", true);
915 AddTextTrack(kTextSubtitles
, "2", "", true);
917 SendEosNotification(0);
919 EXPECT_TRUE(text_renderer_
->HasTracks());
920 EXPECT_CALL(*this, OnEnd());
921 SendEosNotification(1);
923 EXPECT_FALSE(text_renderer_
->HasTracks());
924 EXPECT_CALL(*this, OnPause());
928 TEST_F(TextRendererTest
, PlayEosPause_EosPauseRemove
) {
929 CreateTextRenderer();
930 AddTextTrack(kTextSubtitles
, "1", "", true);
931 AddTextTrack(kTextSubtitles
, "2", "", true);
933 SendEosNotification(0);
934 EXPECT_CALL(*this, OnEnd());
935 SendEosNotification(1);
936 EXPECT_CALL(*this, OnPause());
939 EXPECT_TRUE(text_renderer_
->HasTracks());
941 EXPECT_FALSE(text_renderer_
->HasTracks());
944 TEST_F(TextRendererTest
, PlayEosPause_EosRemovePause
) {
945 CreateTextRenderer();
946 AddTextTrack(kTextSubtitles
, "1", "", true);
947 AddTextTrack(kTextSubtitles
, "2", "", true);
949 SendEosNotification(0);
950 EXPECT_CALL(*this, OnEnd());
951 SendEosNotification(1);
953 EXPECT_TRUE(text_renderer_
->HasTracks());
954 EXPECT_CALL(*this, OnPause());
957 EXPECT_FALSE(text_renderer_
->HasTracks());
960 TEST_F(TextRendererTest
, PlayEosPause_EosRemoveEosPause
) {
961 CreateTextRenderer();
962 AddTextTrack(kTextSubtitles
, "1", "", true);
963 AddTextTrack(kTextSubtitles
, "2", "", true);
965 SendEosNotification(0);
967 EXPECT_TRUE(text_renderer_
->HasTracks());
968 EXPECT_CALL(*this, OnEnd());
969 SendEosNotification(1);
970 EXPECT_CALL(*this, OnPause());
973 EXPECT_FALSE(text_renderer_
->HasTracks());
976 TEST_F(TextRendererTest
, PlayEosPause_EosRemoveEosRemovePause
) {
977 CreateTextRenderer();
978 AddTextTrack(kTextSubtitles
, "1", "", true);
979 AddTextTrack(kTextSubtitles
, "2", "", true);
981 SendEosNotification(0);
983 EXPECT_TRUE(text_renderer_
->HasTracks());
984 EXPECT_CALL(*this, OnEnd());
985 SendEosNotification(1);
987 EXPECT_FALSE(text_renderer_
->HasTracks());
988 EXPECT_CALL(*this, OnPause());
992 TEST_F(TextRendererTest
, PlayEosFlushRemove_OneTrack
) {
993 CreateTextRenderer();
994 AddTextTrack(kTextSubtitles
, "", "", true);
996 EXPECT_CALL(*this, OnEnd());
997 SendEosNotifications();
998 EXPECT_CALL(*this, OnPause());
1003 EXPECT_CALL(*this, OnEnd());
1004 SendEosNotifications();
1006 EXPECT_FALSE(text_renderer_
->HasTracks());
1009 TEST_F(TextRendererTest
, PlayEosFlushRemove_TwoTracks
) {
1010 CreateTextRenderer();
1011 AddTextTrack(kTextSubtitles
, "1", "", true);
1012 AddTextTrack(kTextSubtitles
, "2", "", true);
1014 EXPECT_CALL(*this, OnEnd());
1015 SendEosNotifications();
1016 EXPECT_CALL(*this, OnPause());
1022 SendEosNotification(0);
1023 EXPECT_CALL(*this, OnEnd());
1024 SendEosNotification(1);
1026 EXPECT_TRUE(text_renderer_
->HasTracks());
1028 EXPECT_FALSE(text_renderer_
->HasTracks());
1031 TEST_F(TextRendererTest
, PlayEosFlushRemove_EosRemove
) {
1032 CreateTextRenderer();
1033 AddTextTrack(kTextSubtitles
, "1", "", true);
1034 AddTextTrack(kTextSubtitles
, "2", "", true);
1036 EXPECT_CALL(*this, OnEnd());
1037 SendEosNotifications();
1038 EXPECT_CALL(*this, OnPause());
1044 SendEosNotification(0);
1046 EXPECT_TRUE(text_renderer_
->HasTracks());
1047 EXPECT_CALL(*this, OnEnd());
1048 SendEosNotification(1);
1050 EXPECT_FALSE(text_renderer_
->HasTracks());
1053 TEST_F(TextRendererTest
, PlayShort_SendCueThenEos
) {
1054 CreateTextRenderer();
1055 AddTextTrack(kTextSubtitles
, "1", "", true);
1056 AddTextTrack(kTextSubtitles
, "2", "", true);
1060 EXPECT_CALL(*this, OnPause());
1061 SendEosNotification(1);
1064 TEST_F(TextRendererTest
, PlayShort_EosThenSendCue
) {
1065 CreateTextRenderer();
1066 AddTextTrack(kTextSubtitles
, "1", "", true);
1067 AddTextTrack(kTextSubtitles
, "2", "", true);
1070 SendEosNotification(0);
1071 EXPECT_CALL(*this, OnPause());
1075 TEST_F(TextRendererTest
, PlayShortRemove_SendEosRemove
) {
1076 CreateTextRenderer();
1077 AddTextTrack(kTextSubtitles
, "1", "", true);
1078 AddTextTrack(kTextSubtitles
, "2", "", true);
1082 EXPECT_CALL(*this, OnPause());
1083 SendEosNotification(1);
1085 EXPECT_TRUE(text_renderer_
->HasTracks());
1087 EXPECT_FALSE(text_renderer_
->HasTracks());
1090 TEST_F(TextRendererTest
, PlayShortRemove_SendRemoveEos
) {
1091 CreateTextRenderer();
1092 AddTextTrack(kTextSubtitles
, "1", "", true);
1093 AddTextTrack(kTextSubtitles
, "2", "", true);
1098 EXPECT_TRUE(text_renderer_
->HasTracks());
1099 EXPECT_CALL(*this, OnPause());
1100 SendEosNotification(1);
1102 EXPECT_FALSE(text_renderer_
->HasTracks());
1105 TEST_F(TextRendererTest
, PlayCuePausePendingCancel_OneTrack
) {
1106 CreateTextRenderer();
1107 AddTextTrack(kTextSubtitles
, "", "", true);
1110 EXPECT_CALL(*this, OnPause());
1111 AbortPendingRead(0);
1114 TEST_F(TextRendererTest
, PlayCuePausePendingCancel_SendThenCancel
) {
1115 CreateTextRenderer();
1116 AddTextTrack(kTextSubtitles
, "1", "", true);
1117 AddTextTrack(kTextSubtitles
, "2", "", true);
1121 EXPECT_CALL(*this, OnPause());
1122 AbortPendingRead(1);
1125 TEST_F(TextRendererTest
, PlayCuePausePendingCancel_CancelThenSend
) {
1126 CreateTextRenderer();
1127 AddTextTrack(kTextSubtitles
, "1", "", true);
1128 AddTextTrack(kTextSubtitles
, "2", "", true);
1131 AbortPendingRead(0);
1132 EXPECT_CALL(*this, OnPause());
1136 TEST_F(TextRendererTest
, PlayCueDestroyPendingCancel_OneTrack
) {
1137 CreateTextRenderer();
1138 AddTextTrack(kTextSubtitles
, "", "", true);
1141 EXPECT_CALL(*this, OnPause());
1143 AbortPendingRead(0);
1146 TEST_F(TextRendererTest
, PlayCueDestroyPendingCancel_SendThenCancel
) {
1147 CreateTextRenderer();
1148 AddTextTrack(kTextSubtitles
, "1", "", true);
1149 AddTextTrack(kTextSubtitles
, "2", "", true);
1152 EXPECT_CALL(*this, OnPause());
1155 AbortPendingRead(1);
1158 TEST_F(TextRendererTest
, PlayCueDestroyPendingCancel_CancelThenSend
) {
1159 CreateTextRenderer();
1160 AddTextTrack(kTextSubtitles
, "1", "", true);
1161 AddTextTrack(kTextSubtitles
, "2", "", true);
1164 EXPECT_CALL(*this, OnPause());
1166 AbortPendingRead(0);
1170 TEST_F(TextRendererTest
, AddRemoveAdd
) {
1171 CreateTextRenderer();
1172 AddTextTrack(kTextSubtitles
, "", "", true);
1174 AbortPendingRead(0);
1176 EXPECT_CALL(*this, OnPause());
1178 AddTextTrack(kTextSubtitles
, "", "", true);
1180 EXPECT_CALL(*this, OnEnd());
1181 SendEosNotification(1);
1184 TEST_F(TextRendererTest
, AddRemoveEos
) {
1185 CreateTextRenderer();
1186 AddTextTrack(kTextSubtitles
, "1", "", true);
1187 AddTextTrack(kTextSubtitles
, "2", "", true);
1189 AbortPendingRead(0);
1191 EXPECT_TRUE(text_renderer_
->HasTracks());
1192 EXPECT_CALL(*this, OnEnd());
1193 SendEosNotification(1);
1196 TEST_F(TextRendererTest
, AddRemovePause
) {
1197 CreateTextRenderer();
1198 AddTextTrack(kTextSubtitles
, "1", "", true);
1199 AddTextTrack(kTextSubtitles
, "2", "", true);
1201 AbortPendingRead(0);
1203 EXPECT_TRUE(text_renderer_
->HasTracks());
1205 EXPECT_CALL(*this, OnPause());
1206 SendEosNotification(1);
1209 } // namespace media