OLD | NEW |
(Empty) | |
| 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. |
| 4 |
| 5 #include <vector> |
| 6 |
| 7 #include "base/bind.h" |
| 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" |
| 21 |
| 22 using ::testing::Eq; |
| 23 using ::testing::Exactly; |
| 24 using ::testing::Invoke; |
| 25 using ::testing::_; |
| 26 |
| 27 namespace media { |
| 28 |
| 29 // Local implementation of the TextTrack interface. |
| 30 class FakeTextTrack : public TextTrack { |
| 31 public: |
| 32 FakeTextTrack(const base::Closure& destroy_cb, |
| 33 const TextTrackConfig& config) |
| 34 : destroy_cb_(destroy_cb), |
| 35 config_(config) { |
| 36 } |
| 37 virtual ~FakeTextTrack() { |
| 38 destroy_cb_.Run(); |
| 39 } |
| 40 |
| 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)); |
| 46 |
| 47 const base::Closure destroy_cb_; |
| 48 const TextTrackConfig config_; |
| 49 |
| 50 private: |
| 51 DISALLOW_COPY_AND_ASSIGN(FakeTextTrack); |
| 52 }; |
| 53 |
| 54 class TextRendererTest : public testing::Test { |
| 55 public: |
| 56 TextRendererTest() {} |
| 57 |
| 58 void CreateTextRenderer() { |
| 59 DCHECK(!text_renderer_); |
| 60 |
| 61 text_renderer_.reset( |
| 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))); |
| 67 } |
| 68 |
| 69 void DestroyTextRenderer() { |
| 70 EXPECT_CALL(*this, OnStop()); |
| 71 text_renderer_->Stop(base::Bind(&TextRendererTest::OnStop, |
| 72 base::Unretained(this))); |
| 73 message_loop_.RunUntilIdle(); |
| 74 |
| 75 text_renderer_.reset(); |
| 76 text_track_streams_.clear(); |
| 77 } |
| 78 |
| 79 void AddTextTrack(TextKind kind, |
| 80 const std::string& name, |
| 81 const std::string& language, |
| 82 bool expect_read) { |
| 83 const size_t idx = text_track_streams_.size(); |
| 84 text_track_streams_.push_back(new FakeTextTrackStream); |
| 85 |
| 86 if (expect_read) |
| 87 ExpectRead(idx); |
| 88 |
| 89 const TextTrackConfig config(kind, name, language); |
| 90 text_renderer_->AddTextStream(text_track_streams_.back(), config); |
| 91 message_loop_.RunUntilIdle(); |
| 92 |
| 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)); |
| 97 } |
| 98 |
| 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()); |
| 111 } |
| 112 |
| 113 void RemoveTextTrack(unsigned idx) { |
| 114 FakeTextTrackStream* const stream = text_track_streams_[idx]; |
| 115 text_renderer_->RemoveTextStream(stream); |
| 116 EXPECT_FALSE(text_tracks_[idx]); |
| 117 } |
| 118 |
| 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); |
| 127 } |
| 128 } |
| 129 |
| 130 void AbortPendingRead(unsigned idx) { |
| 131 FakeTextTrackStream* const stream = text_track_streams_[idx]; |
| 132 stream->AbortPendingRead(); |
| 133 message_loop_.RunUntilIdle(); |
| 134 } |
| 135 |
| 136 void AbortPendingReads() { |
| 137 for (size_t idx = 0; idx < text_track_streams_.size(); ++idx) { |
| 138 AbortPendingRead(idx); |
| 139 } |
| 140 } |
| 141 |
| 142 void SendEosNotification(unsigned idx) { |
| 143 FakeTextTrackStream* const stream = text_track_streams_[idx]; |
| 144 stream->SendEosNotification(); |
| 145 message_loop_.RunUntilIdle(); |
| 146 } |
| 147 |
| 148 void SendEosNotifications() { |
| 149 for (size_t idx = 0; idx < text_track_streams_.size(); ++idx) { |
| 150 SendEosNotification(idx); |
| 151 } |
| 152 } |
| 153 |
| 154 void SendCue(unsigned idx, bool expect_cue) { |
| 155 FakeTextTrackStream* const text_stream = text_track_streams_[idx]; |
| 156 |
| 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; |
| 162 |
| 163 if (expect_cue) { |
| 164 FakeTextTrack* const text_track = text_tracks_[idx]; |
| 165 EXPECT_CALL(*text_track, addWebVTTCue(start, |
| 166 start + duration, |
| 167 id, |
| 168 content, |
| 169 settings)); |
| 170 } |
| 171 |
| 172 text_stream->SatisfyPendingRead(start, duration, id, content, settings); |
| 173 message_loop_.RunUntilIdle(); |
| 174 } |
| 175 |
| 176 void SendCues(bool expect_cue) { |
| 177 for (size_t idx = 0; idx < text_track_streams_.size(); ++idx) { |
| 178 SendCue(idx, expect_cue); |
| 179 } |
| 180 } |
| 181 |
| 182 void OnDestroyTextTrack(unsigned idx) { |
| 183 text_tracks_[idx] = NULL; |
| 184 } |
| 185 |
| 186 void Play() { |
| 187 EXPECT_CALL(*this, OnPlay()); |
| 188 text_renderer_->Play(base::Bind(&TextRendererTest::OnPlay, |
| 189 base::Unretained(this))); |
| 190 message_loop_.RunUntilIdle(); |
| 191 } |
| 192 |
| 193 void Pause() { |
| 194 text_renderer_->Pause(base::Bind(&TextRendererTest::OnPause, |
| 195 base::Unretained(this))); |
| 196 message_loop_.RunUntilIdle(); |
| 197 } |
| 198 |
| 199 void Flush() { |
| 200 EXPECT_CALL(*this, OnFlush()); |
| 201 text_renderer_->Flush(base::Bind(&TextRendererTest::OnFlush, |
| 202 base::Unretained(this))); |
| 203 } |
| 204 |
| 205 void Stop() { |
| 206 text_renderer_->Stop(base::Bind(&TextRendererTest::OnStop, |
| 207 base::Unretained(this))); |
| 208 message_loop_.RunUntilIdle(); |
| 209 } |
| 210 |
| 211 void ExpectRead(size_t idx) { |
| 212 FakeTextTrackStream* const stream = text_track_streams_[idx]; |
| 213 EXPECT_CALL(*stream, OnRead()); |
| 214 } |
| 215 |
| 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()); |
| 221 |
| 222 scoped_ptr<TextRenderer> text_renderer_; |
| 223 base::MessageLoop message_loop_; |
| 224 |
| 225 typedef ScopedVector<FakeTextTrackStream> TextTrackStreams; |
| 226 TextTrackStreams text_track_streams_; |
| 227 |
| 228 typedef std::vector<FakeTextTrack*> TextTracks; |
| 229 TextTracks text_tracks_; |
| 230 |
| 231 private: |
| 232 DISALLOW_COPY_AND_ASSIGN(TextRendererTest); |
| 233 }; |
| 234 |
| 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(); |
| 241 } |
| 242 |
| 243 TEST_F(TextRendererTest, TestStop) { |
| 244 CreateTextRenderer(); |
| 245 DestroyTextRenderer(); |
| 246 } |
| 247 |
| 248 TEST_F(TextRendererTest, AddTextTrackOnly_OneTrack) { |
| 249 CreateTextRenderer(); |
| 250 AddTextTrack(kTextSubtitles, "", "", false); |
| 251 DestroyTextRenderer(); |
| 252 } |
| 253 |
| 254 TEST_F(TextRendererTest, AddTextTrackOnly_TwoTracks) { |
| 255 CreateTextRenderer(); |
| 256 AddTextTrack(kTextSubtitles, "track 1", "", false); |
| 257 AddTextTrack(kTextSubtitles, "track 2", "", false); |
| 258 DestroyTextRenderer(); |
| 259 } |
| 260 |
| 261 TEST_F(TextRendererTest, PlayOnly) { |
| 262 CreateTextRenderer(); |
| 263 Play(); |
| 264 DestroyTextRenderer(); |
| 265 } |
| 266 |
| 267 TEST_F(TextRendererTest, AddTrackBeforePlay_OneTrack) { |
| 268 CreateTextRenderer(); |
| 269 AddTextTrack(kTextSubtitles, "", "", true); |
| 270 Play(); |
| 271 AbortPendingReads(); |
| 272 DestroyTextRenderer(); |
| 273 } |
| 274 |
| 275 TEST_F(TextRendererTest, AddTrackBeforePlay_TwoTracks) { |
| 276 CreateTextRenderer(); |
| 277 AddTextTrack(kTextSubtitles, "1", "", true); |
| 278 AddTextTrack(kTextSubtitles, "2", "", true); |
| 279 Play(); |
| 280 AbortPendingReads(); |
| 281 DestroyTextRenderer(); |
| 282 } |
| 283 |
| 284 TEST_F(TextRendererTest, AddTrackAfterPlay_OneTrackAfter) { |
| 285 CreateTextRenderer(); |
| 286 Play(); |
| 287 AddTextTrack(kTextSubtitles, "", "", true); |
| 288 AbortPendingReads(); |
| 289 DestroyTextRenderer(); |
| 290 } |
| 291 |
| 292 TEST_F(TextRendererTest, AddTrackAfterPlay_TwoTracksAfter) { |
| 293 CreateTextRenderer(); |
| 294 Play(); |
| 295 AddTextTrack(kTextSubtitles, "1", "", true); |
| 296 AddTextTrack(kTextSubtitles, "2", "", true); |
| 297 AbortPendingReads(); |
| 298 DestroyTextRenderer(); |
| 299 } |
| 300 |
| 301 TEST_F(TextRendererTest, AddTrackAfterPlay_OneTrackBeforeOneTrackAfter) { |
| 302 CreateTextRenderer(); |
| 303 AddTextTrack(kTextSubtitles, "1", "", true); |
| 304 Play(); |
| 305 AddTextTrack(kTextSubtitles, "2", "", true); |
| 306 AbortPendingReads(); |
| 307 DestroyTextRenderer(); |
| 308 } |
| 309 |
| 310 TEST_F(TextRendererTest, PlayAddCue_OneTrack) { |
| 311 CreateTextRenderer(); |
| 312 AddTextTrack(kTextSubtitles, "", "", true); |
| 313 Play(); |
| 314 ExpectRead(0); |
| 315 SendCues(true); |
| 316 AbortPendingReads(); |
| 317 DestroyTextRenderer(); |
| 318 } |
| 319 |
| 320 TEST_F(TextRendererTest, PlayAddCue_TwoTracks) { |
| 321 CreateTextRenderer(); |
| 322 AddTextTrack(kTextSubtitles, "1", "", true); |
| 323 AddTextTrack(kTextSubtitles, "2", "", true); |
| 324 Play(); |
| 325 ExpectRead(0); |
| 326 ExpectRead(1); |
| 327 SendCues(true); |
| 328 AbortPendingReads(); |
| 329 DestroyTextRenderer(); |
| 330 } |
| 331 |
| 332 TEST_F(TextRendererTest, PlayEosOnly_OneTrack) { |
| 333 CreateTextRenderer(); |
| 334 AddTextTrack(kTextSubtitles, "", "", true); |
| 335 Play(); |
| 336 EXPECT_CALL(*this, OnEnd()); |
| 337 SendEosNotifications(); |
| 338 DestroyTextRenderer(); |
| 339 } |
| 340 |
| 341 TEST_F(TextRendererTest, PlayEosOnly_TwoTracks) { |
| 342 CreateTextRenderer(); |
| 343 AddTextTrack(kTextSubtitles, "1", "", true); |
| 344 AddTextTrack(kTextSubtitles, "2", "", true); |
| 345 Play(); |
| 346 EXPECT_CALL(*this, OnEnd()); |
| 347 SendEosNotifications(); |
| 348 DestroyTextRenderer(); |
| 349 } |
| 350 |
| 351 TEST_F(TextRendererTest, PlayCueEos_OneTrack) { |
| 352 CreateTextRenderer(); |
| 353 AddTextTrack(kTextSubtitles, "", "", true); |
| 354 Play(); |
| 355 ExpectRead(0); |
| 356 SendCues(true); |
| 357 EXPECT_CALL(*this, OnEnd()); |
| 358 SendEosNotifications(); |
| 359 DestroyTextRenderer(); |
| 360 } |
| 361 |
| 362 TEST_F(TextRendererTest, PlayCueEos_TwoTracks) { |
| 363 CreateTextRenderer(); |
| 364 AddTextTrack(kTextSubtitles, "1", "", true); |
| 365 AddTextTrack(kTextSubtitles, "2", "", true); |
| 366 Play(); |
| 367 ExpectRead(0); |
| 368 ExpectRead(1); |
| 369 SendCues(true); |
| 370 EXPECT_CALL(*this, OnEnd()); |
| 371 SendEosNotifications(); |
| 372 DestroyTextRenderer(); |
| 373 } |
| 374 |
| 375 TEST_F(TextRendererTest, StopPending_OneTrack) { |
| 376 CreateTextRenderer(); |
| 377 AddTextTrack(kTextSubtitles, "", "", true); |
| 378 Play(); |
| 379 Stop(); |
| 380 EXPECT_CALL(*this, OnStop()); |
| 381 SendEosNotifications(); |
| 382 text_renderer_.reset(); |
| 383 text_track_streams_.clear(); |
| 384 } |
| 385 |
| 386 TEST_F(TextRendererTest, StopPending_TwoTracks) { |
| 387 CreateTextRenderer(); |
| 388 AddTextTrack(kTextSubtitles, "1", "", true); |
| 389 AddTextTrack(kTextSubtitles, "2", "", true); |
| 390 Play(); |
| 391 Stop(); |
| 392 EXPECT_CALL(*this, OnStop()); |
| 393 SendEosNotifications(); |
| 394 text_renderer_.reset(); |
| 395 text_track_streams_.clear(); |
| 396 } |
| 397 |
| 398 TEST_F(TextRendererTest, PlayPause_OneTrack) { |
| 399 CreateTextRenderer(); |
| 400 AddTextTrack(kTextSubtitles, "", "", true); |
| 401 Play(); |
| 402 AbortPendingReads(); |
| 403 EXPECT_CALL(*this, OnPause()); |
| 404 Pause(); |
| 405 DestroyTextRenderer(); |
| 406 } |
| 407 |
| 408 TEST_F(TextRendererTest, PlayPause_TwoTracks) { |
| 409 CreateTextRenderer(); |
| 410 AddTextTrack(kTextSubtitles, "1", "", true); |
| 411 AddTextTrack(kTextSubtitles, "2", "", true); |
| 412 Play(); |
| 413 AbortPendingReads(); |
| 414 EXPECT_CALL(*this, OnPause()); |
| 415 Pause(); |
| 416 DestroyTextRenderer(); |
| 417 } |
| 418 |
| 419 TEST_F(TextRendererTest, PlayEosPausePending_OneTrack) { |
| 420 CreateTextRenderer(); |
| 421 AddTextTrack(kTextSubtitles, "", "", true); |
| 422 Play(); |
| 423 Pause(); |
| 424 EXPECT_CALL(*this, OnPause()); |
| 425 SendEosNotifications(); |
| 426 DestroyTextRenderer(); |
| 427 } |
| 428 |
| 429 TEST_F(TextRendererTest, PlayEosPausePending_TwoTracks) { |
| 430 CreateTextRenderer(); |
| 431 AddTextTrack(kTextSubtitles, "1", "", true); |
| 432 AddTextTrack(kTextSubtitles, "2", "", true); |
| 433 Play(); |
| 434 Pause(); |
| 435 EXPECT_CALL(*this, OnPause()); |
| 436 SendEosNotifications(); |
| 437 DestroyTextRenderer(); |
| 438 } |
| 439 |
| 440 TEST_F(TextRendererTest, PlayCuePausePending_OneTrack) { |
| 441 CreateTextRenderer(); |
| 442 AddTextTrack(kTextSubtitles, "", "", true); |
| 443 Play(); |
| 444 Pause(); |
| 445 EXPECT_CALL(*this, OnPause()); |
| 446 SendCues(true); |
| 447 DestroyTextRenderer(); |
| 448 } |
| 449 |
| 450 TEST_F(TextRendererTest, PlayCuePausePending_TwoTracks) { |
| 451 CreateTextRenderer(); |
| 452 AddTextTrack(kTextSubtitles, "1", "", true); |
| 453 AddTextTrack(kTextSubtitles, "2", "", true); |
| 454 Play(); |
| 455 Pause(); |
| 456 EXPECT_CALL(*this, OnPause()); |
| 457 SendCues(true); |
| 458 DestroyTextRenderer(); |
| 459 } |
| 460 |
| 461 TEST_F(TextRendererTest, PlayEosPause_OneTrack) { |
| 462 CreateTextRenderer(); |
| 463 AddTextTrack(kTextSubtitles, "", "", true); |
| 464 Play(); |
| 465 EXPECT_CALL(*this, OnEnd()); |
| 466 SendEosNotifications(); |
| 467 EXPECT_CALL(*this, OnPause()); |
| 468 Pause(); |
| 469 DestroyTextRenderer(); |
| 470 } |
| 471 |
| 472 TEST_F(TextRendererTest, PlayEosPause_TwoTracks) { |
| 473 CreateTextRenderer(); |
| 474 AddTextTrack(kTextSubtitles, "1", "", true); |
| 475 AddTextTrack(kTextSubtitles, "2", "", true); |
| 476 Play(); |
| 477 EXPECT_CALL(*this, OnEnd()); |
| 478 SendEosNotifications(); |
| 479 EXPECT_CALL(*this, OnPause()); |
| 480 Pause(); |
| 481 DestroyTextRenderer(); |
| 482 } |
| 483 |
| 484 TEST_F(TextRendererTest, PlayEosPause_SplitEos) { |
| 485 CreateTextRenderer(); |
| 486 AddTextTrack(kTextSubtitles, "1", "", true); |
| 487 AddTextTrack(kTextSubtitles, "2", "", true); |
| 488 Play(); |
| 489 SendEosNotification(0); |
| 490 EXPECT_CALL(*this, OnEnd()); |
| 491 SendEosNotification(1); |
| 492 EXPECT_CALL(*this, OnPause()); |
| 493 Pause(); |
| 494 DestroyTextRenderer(); |
| 495 } |
| 496 |
| 497 TEST_F(TextRendererTest, PlayEosFlush_OneTrack) { |
| 498 CreateTextRenderer(); |
| 499 AddTextTrack(kTextSubtitles, "", "", true); |
| 500 Play(); |
| 501 EXPECT_CALL(*this, OnEnd()); |
| 502 SendEosNotifications(); |
| 503 EXPECT_CALL(*this, OnPause()); |
| 504 Pause(); |
| 505 Flush(); |
| 506 ExpectRead(0); |
| 507 Play(); |
| 508 EXPECT_CALL(*this, OnEnd()); |
| 509 SendEosNotifications(); |
| 510 DestroyTextRenderer(); |
| 511 } |
| 512 |
| 513 TEST_F(TextRendererTest, PlayEosFlush_TwoTracks) { |
| 514 CreateTextRenderer(); |
| 515 AddTextTrack(kTextSubtitles, "1", "", true); |
| 516 AddTextTrack(kTextSubtitles, "2", "", true); |
| 517 Play(); |
| 518 EXPECT_CALL(*this, OnEnd()); |
| 519 SendEosNotifications(); |
| 520 EXPECT_CALL(*this, OnPause()); |
| 521 Pause(); |
| 522 Flush(); |
| 523 ExpectRead(0); |
| 524 ExpectRead(1); |
| 525 Play(); |
| 526 EXPECT_CALL(*this, OnEnd()); |
| 527 SendEosNotifications(); |
| 528 DestroyTextRenderer(); |
| 529 } |
| 530 |
| 531 TEST_F(TextRendererTest, AddTextTrackOnlyRemove_OneTrack) { |
| 532 CreateTextRenderer(); |
| 533 AddTextTrack(kTextSubtitles, "", "", false); |
| 534 EXPECT_TRUE(text_renderer_->HasTracks()); |
| 535 DestroyTextRenderer(); |
| 536 } |
| 537 |
| 538 TEST_F(TextRendererTest, AddTextTrackOnlyRemove_TwoTracks) { |
| 539 CreateTextRenderer(); |
| 540 AddTextTrack(kTextSubtitles, "track 1", "", false); |
| 541 AddTextTrack(kTextSubtitles, "track 2", "", false); |
| 542 RemoveTextTrack(0); |
| 543 EXPECT_TRUE(text_renderer_->HasTracks()); |
| 544 RemoveTextTrack(1); |
| 545 EXPECT_FALSE(text_renderer_->HasTracks()); |
| 546 DestroyTextRenderer(); |
| 547 } |
| 548 |
| 549 TEST_F(TextRendererTest, AddTrackBeforePlayRemove_OneTrack) { |
| 550 CreateTextRenderer(); |
| 551 AddTextTrack(kTextSubtitles, "", "", true); |
| 552 Play(); |
| 553 AbortPendingReads(); |
| 554 RemoveTextTrack(0); |
| 555 EXPECT_FALSE(text_renderer_->HasTracks()); |
| 556 DestroyTextRenderer(); |
| 557 } |
| 558 |
| 559 TEST_F(TextRendererTest, AddTrackBeforePlayRemove_TwoTracks) { |
| 560 CreateTextRenderer(); |
| 561 AddTextTrack(kTextSubtitles, "1", "", true); |
| 562 AddTextTrack(kTextSubtitles, "2", "", true); |
| 563 Play(); |
| 564 AbortPendingReads(); |
| 565 RemoveTextTrack(0); |
| 566 EXPECT_TRUE(text_renderer_->HasTracks()); |
| 567 RemoveTextTrack(1); |
| 568 EXPECT_FALSE(text_renderer_->HasTracks()); |
| 569 DestroyTextRenderer(); |
| 570 } |
| 571 |
| 572 TEST_F(TextRendererTest, AddTrackBeforePlayRemove_SeparateCancel) { |
| 573 CreateTextRenderer(); |
| 574 AddTextTrack(kTextSubtitles, "1", "", true); |
| 575 AddTextTrack(kTextSubtitles, "2", "", true); |
| 576 Play(); |
| 577 AbortPendingRead(0); |
| 578 RemoveTextTrack(0); |
| 579 EXPECT_TRUE(text_renderer_->HasTracks()); |
| 580 AbortPendingRead(1); |
| 581 RemoveTextTrack(1); |
| 582 EXPECT_FALSE(text_renderer_->HasTracks()); |
| 583 DestroyTextRenderer(); |
| 584 } |
| 585 |
| 586 TEST_F(TextRendererTest, AddTrackBeforePlayRemove_RemoveOneThenPlay) { |
| 587 CreateTextRenderer(); |
| 588 AddTextTrack(kTextSubtitles, "1", "", false); |
| 589 AddTextTrack(kTextSubtitles, "2", "", true); |
| 590 RemoveTextTrack(0); |
| 591 EXPECT_TRUE(text_renderer_->HasTracks()); |
| 592 Play(); |
| 593 AbortPendingRead(1); |
| 594 RemoveTextTrack(1); |
| 595 EXPECT_FALSE(text_renderer_->HasTracks()); |
| 596 DestroyTextRenderer(); |
| 597 } |
| 598 |
| 599 TEST_F(TextRendererTest, AddTrackBeforePlayRemove_RemoveTwoThenPlay) { |
| 600 CreateTextRenderer(); |
| 601 AddTextTrack(kTextSubtitles, "1", "", false); |
| 602 AddTextTrack(kTextSubtitles, "2", "", false); |
| 603 RemoveTextTrack(0); |
| 604 EXPECT_TRUE(text_renderer_->HasTracks()); |
| 605 RemoveTextTrack(1); |
| 606 EXPECT_FALSE(text_renderer_->HasTracks()); |
| 607 Play(); |
| 608 DestroyTextRenderer(); |
| 609 } |
| 610 |
| 611 TEST_F(TextRendererTest, AddTrackAfterPlayRemove_OneTrack) { |
| 612 CreateTextRenderer(); |
| 613 Play(); |
| 614 AddTextTrack(kTextSubtitles, "", "", true); |
| 615 AbortPendingReads(); |
| 616 RemoveTextTrack(0); |
| 617 EXPECT_FALSE(text_renderer_->HasTracks()); |
| 618 DestroyTextRenderer(); |
| 619 } |
| 620 |
| 621 TEST_F(TextRendererTest, AddTrackAfterPlayRemove_TwoTracks) { |
| 622 CreateTextRenderer(); |
| 623 Play(); |
| 624 AddTextTrack(kTextSubtitles, "1", "", true); |
| 625 AddTextTrack(kTextSubtitles, "2", "", true); |
| 626 AbortPendingReads(); |
| 627 RemoveTextTrack(0); |
| 628 EXPECT_TRUE(text_renderer_->HasTracks()); |
| 629 RemoveTextTrack(1); |
| 630 EXPECT_FALSE(text_renderer_->HasTracks()); |
| 631 DestroyTextRenderer(); |
| 632 } |
| 633 |
| 634 TEST_F(TextRendererTest, AddTrackAfterPlayRemove_SplitCancel) { |
| 635 CreateTextRenderer(); |
| 636 Play(); |
| 637 AddTextTrack(kTextSubtitles, "1", "", true); |
| 638 AddTextTrack(kTextSubtitles, "2", "", true); |
| 639 AbortPendingRead(0); |
| 640 RemoveTextTrack(0); |
| 641 EXPECT_TRUE(text_renderer_->HasTracks()); |
| 642 AbortPendingRead(1); |
| 643 RemoveTextTrack(1); |
| 644 EXPECT_FALSE(text_renderer_->HasTracks()); |
| 645 DestroyTextRenderer(); |
| 646 } |
| 647 |
| 648 TEST_F(TextRendererTest, AddTrackAfterPlayRemove_SplitAdd) { |
| 649 CreateTextRenderer(); |
| 650 AddTextTrack(kTextSubtitles, "1", "", true); |
| 651 Play(); |
| 652 AddTextTrack(kTextSubtitles, "2", "", true); |
| 653 AbortPendingRead(0); |
| 654 RemoveTextTrack(0); |
| 655 EXPECT_TRUE(text_renderer_->HasTracks()); |
| 656 AbortPendingRead(1); |
| 657 RemoveTextTrack(1); |
| 658 EXPECT_FALSE(text_renderer_->HasTracks()); |
| 659 DestroyTextRenderer(); |
| 660 } |
| 661 |
| 662 TEST_F(TextRendererTest, PlayAddCueRemove_OneTrack) { |
| 663 CreateTextRenderer(); |
| 664 AddTextTrack(kTextSubtitles, "", "", true); |
| 665 Play(); |
| 666 ExpectRead(0); |
| 667 SendCues(true); |
| 668 AbortPendingReads(); |
| 669 RemoveTextTrack(0); |
| 670 EXPECT_FALSE(text_renderer_->HasTracks()); |
| 671 DestroyTextRenderer(); |
| 672 } |
| 673 |
| 674 TEST_F(TextRendererTest, PlayAddCueRemove_TwoTracks) { |
| 675 CreateTextRenderer(); |
| 676 AddTextTrack(kTextSubtitles, "1", "", true); |
| 677 AddTextTrack(kTextSubtitles, "2", "", true); |
| 678 Play(); |
| 679 ExpectRead(0); |
| 680 ExpectRead(1); |
| 681 SendCues(true); |
| 682 AbortPendingRead(0); |
| 683 AbortPendingRead(1); |
| 684 RemoveTextTrack(0); |
| 685 EXPECT_TRUE(text_renderer_->HasTracks()); |
| 686 RemoveTextTrack(1); |
| 687 EXPECT_FALSE(text_renderer_->HasTracks()); |
| 688 DestroyTextRenderer(); |
| 689 } |
| 690 |
| 691 TEST_F(TextRendererTest, PlayEosOnlyRemove_OneTrack) { |
| 692 CreateTextRenderer(); |
| 693 AddTextTrack(kTextSubtitles, "", "", true); |
| 694 Play(); |
| 695 EXPECT_CALL(*this, OnEnd()); |
| 696 SendEosNotifications(); |
| 697 RemoveTextTrack(0); |
| 698 EXPECT_FALSE(text_renderer_->HasTracks()); |
| 699 DestroyTextRenderer(); |
| 700 } |
| 701 |
| 702 TEST_F(TextRendererTest, PlayEosOnlyRemove_TwoTracks) { |
| 703 CreateTextRenderer(); |
| 704 AddTextTrack(kTextSubtitles, "1", "", true); |
| 705 AddTextTrack(kTextSubtitles, "2", "", true); |
| 706 Play(); |
| 707 EXPECT_CALL(*this, OnEnd()); |
| 708 SendEosNotifications(); |
| 709 RemoveTextTrack(0); |
| 710 EXPECT_TRUE(text_renderer_->HasTracks()); |
| 711 RemoveTextTrack(1); |
| 712 EXPECT_FALSE(text_renderer_->HasTracks()); |
| 713 DestroyTextRenderer(); |
| 714 } |
| 715 |
| 716 TEST_F(TextRendererTest, PlayCueEosRemove_OneTrack) { |
| 717 CreateTextRenderer(); |
| 718 AddTextTrack(kTextSubtitles, "", "", true); |
| 719 Play(); |
| 720 ExpectRead(0); |
| 721 SendCues(true); |
| 722 EXPECT_CALL(*this, OnEnd()); |
| 723 SendEosNotifications(); |
| 724 RemoveTextTrack(0); |
| 725 EXPECT_FALSE(text_renderer_->HasTracks()); |
| 726 DestroyTextRenderer(); |
| 727 } |
| 728 |
| 729 TEST_F(TextRendererTest, PlayCueEosRemove_TwoTracks) { |
| 730 CreateTextRenderer(); |
| 731 AddTextTrack(kTextSubtitles, "1", "", true); |
| 732 AddTextTrack(kTextSubtitles, "2", "", true); |
| 733 Play(); |
| 734 ExpectRead(0); |
| 735 ExpectRead(1); |
| 736 SendCues(true); |
| 737 EXPECT_CALL(*this, OnEnd()); |
| 738 SendEosNotifications(); |
| 739 RemoveTextTrack(0); |
| 740 EXPECT_TRUE(text_renderer_->HasTracks()); |
| 741 RemoveTextTrack(1); |
| 742 EXPECT_FALSE(text_renderer_->HasTracks()); |
| 743 DestroyTextRenderer(); |
| 744 } |
| 745 |
| 746 TEST_F(TextRendererTest, TestStopPendingRemove_OneTrack) { |
| 747 CreateTextRenderer(); |
| 748 AddTextTrack(kTextSubtitles, "", "", true); |
| 749 Play(); |
| 750 Stop(); |
| 751 EXPECT_CALL(*this, OnStop()); |
| 752 SendEosNotifications(); |
| 753 RemoveTextTrack(0); |
| 754 EXPECT_FALSE(text_renderer_->HasTracks()); |
| 755 text_renderer_.reset(); |
| 756 text_track_streams_.clear(); |
| 757 } |
| 758 |
| 759 TEST_F(TextRendererTest, TestStopPendingRemove_TwoTracks) { |
| 760 CreateTextRenderer(); |
| 761 AddTextTrack(kTextSubtitles, "1", "", true); |
| 762 AddTextTrack(kTextSubtitles, "2", "", true); |
| 763 Play(); |
| 764 Stop(); |
| 765 SendEosNotification(0); |
| 766 EXPECT_CALL(*this, OnStop()); |
| 767 SendEosNotification(1); |
| 768 RemoveTextTrack(0); |
| 769 EXPECT_TRUE(text_renderer_->HasTracks()); |
| 770 RemoveTextTrack(1); |
| 771 EXPECT_FALSE(text_renderer_->HasTracks()); |
| 772 text_renderer_.reset(); |
| 773 text_track_streams_.clear(); |
| 774 } |
| 775 |
| 776 TEST_F(TextRendererTest, TestStopPendingRemove_RemoveThenSendEos) { |
| 777 CreateTextRenderer(); |
| 778 AddTextTrack(kTextSubtitles, "1", "", true); |
| 779 AddTextTrack(kTextSubtitles, "2", "", true); |
| 780 Play(); |
| 781 Stop(); |
| 782 SendEosNotification(0); |
| 783 RemoveTextTrack(0); |
| 784 EXPECT_TRUE(text_renderer_->HasTracks()); |
| 785 EXPECT_CALL(*this, OnStop()); |
| 786 SendEosNotification(1); |
| 787 RemoveTextTrack(1); |
| 788 EXPECT_FALSE(text_renderer_->HasTracks()); |
| 789 text_renderer_.reset(); |
| 790 text_track_streams_.clear(); |
| 791 } |
| 792 |
| 793 TEST_F(TextRendererTest, PlayPauseRemove_PauseThenRemove) { |
| 794 CreateTextRenderer(); |
| 795 AddTextTrack(kTextSubtitles, "", "", true); |
| 796 Play(); |
| 797 AbortPendingReads(); |
| 798 EXPECT_CALL(*this, OnPause()); |
| 799 Pause(); |
| 800 RemoveTextTrack(0); |
| 801 EXPECT_FALSE(text_renderer_->HasTracks()); |
| 802 DestroyTextRenderer(); |
| 803 } |
| 804 |
| 805 TEST_F(TextRendererTest, PlayPauseRemove_RemoveThanPause) { |
| 806 CreateTextRenderer(); |
| 807 AddTextTrack(kTextSubtitles, "", "", true); |
| 808 Play(); |
| 809 AbortPendingReads(); |
| 810 RemoveTextTrack(0); |
| 811 EXPECT_FALSE(text_renderer_->HasTracks()); |
| 812 EXPECT_CALL(*this, OnPause()); |
| 813 Pause(); |
| 814 DestroyTextRenderer(); |
| 815 } |
| 816 |
| 817 TEST_F(TextRendererTest, PlayPause_PauseThenRemoveTwoTracks) { |
| 818 CreateTextRenderer(); |
| 819 AddTextTrack(kTextSubtitles, "1", "", true); |
| 820 AddTextTrack(kTextSubtitles, "2", "", true); |
| 821 Play(); |
| 822 AbortPendingReads(); |
| 823 EXPECT_CALL(*this, OnPause()); |
| 824 Pause(); |
| 825 RemoveTextTrack(0); |
| 826 EXPECT_TRUE(text_renderer_->HasTracks()); |
| 827 RemoveTextTrack(1); |
| 828 EXPECT_FALSE(text_renderer_->HasTracks()); |
| 829 DestroyTextRenderer(); |
| 830 } |
| 831 |
| 832 TEST_F(TextRendererTest, PlayPauseRemove_RemoveThenPauseTwoTracks) { |
| 833 CreateTextRenderer(); |
| 834 AddTextTrack(kTextSubtitles, "1", "", true); |
| 835 AddTextTrack(kTextSubtitles, "2", "", true); |
| 836 Play(); |
| 837 AbortPendingReads(); |
| 838 RemoveTextTrack(0); |
| 839 EXPECT_TRUE(text_renderer_->HasTracks()); |
| 840 EXPECT_CALL(*this, OnPause()); |
| 841 Pause(); |
| 842 RemoveTextTrack(1); |
| 843 EXPECT_FALSE(text_renderer_->HasTracks()); |
| 844 DestroyTextRenderer(); |
| 845 } |
| 846 |
| 847 TEST_F(TextRendererTest, PlayPauseRemove_SplitCancel) { |
| 848 CreateTextRenderer(); |
| 849 AddTextTrack(kTextSubtitles, "1", "", true); |
| 850 AddTextTrack(kTextSubtitles, "2", "", true); |
| 851 Play(); |
| 852 AbortPendingRead(0); |
| 853 RemoveTextTrack(0); |
| 854 EXPECT_TRUE(text_renderer_->HasTracks()); |
| 855 AbortPendingRead(1); |
| 856 EXPECT_CALL(*this, OnPause()); |
| 857 Pause(); |
| 858 RemoveTextTrack(1); |
| 859 EXPECT_FALSE(text_renderer_->HasTracks()); |
| 860 DestroyTextRenderer(); |
| 861 } |
| 862 |
| 863 |
| 864 TEST_F(TextRendererTest, PlayPauseRemove_PauseLast) { |
| 865 CreateTextRenderer(); |
| 866 AddTextTrack(kTextSubtitles, "1", "", true); |
| 867 AddTextTrack(kTextSubtitles, "2", "", true); |
| 868 Play(); |
| 869 AbortPendingRead(0); |
| 870 RemoveTextTrack(0); |
| 871 EXPECT_TRUE(text_renderer_->HasTracks()); |
| 872 AbortPendingRead(1); |
| 873 RemoveTextTrack(1); |
| 874 EXPECT_FALSE(text_renderer_->HasTracks()); |
| 875 EXPECT_CALL(*this, OnPause()); |
| 876 Pause(); |
| 877 DestroyTextRenderer(); |
| 878 } |
| 879 |
| 880 TEST_F(TextRendererTest, PlayEosPausePendingRemove_OneTrack) { |
| 881 CreateTextRenderer(); |
| 882 AddTextTrack(kTextSubtitles, "", "", true); |
| 883 Play(); |
| 884 Pause(); |
| 885 EXPECT_CALL(*this, OnPause()); |
| 886 SendEosNotifications(); |
| 887 RemoveTextTrack(0); |
| 888 EXPECT_FALSE(text_renderer_->HasTracks()); |
| 889 DestroyTextRenderer(); |
| 890 } |
| 891 |
| 892 TEST_F(TextRendererTest, PlayEosPausePendingRemove_TwoTracks) { |
| 893 CreateTextRenderer(); |
| 894 AddTextTrack(kTextSubtitles, "1", "", true); |
| 895 AddTextTrack(kTextSubtitles, "2", "", true); |
| 896 Play(); |
| 897 Pause(); |
| 898 SendEosNotification(0); |
| 899 EXPECT_CALL(*this, OnPause()); |
| 900 SendEosNotification(1); |
| 901 RemoveTextTrack(0); |
| 902 EXPECT_TRUE(text_renderer_->HasTracks()); |
| 903 RemoveTextTrack(1); |
| 904 EXPECT_FALSE(text_renderer_->HasTracks()); |
| 905 DestroyTextRenderer(); |
| 906 } |
| 907 |
| 908 TEST_F(TextRendererTest, PlayEosPausePendingRemove_SplitEos) { |
| 909 CreateTextRenderer(); |
| 910 AddTextTrack(kTextSubtitles, "1", "", true); |
| 911 AddTextTrack(kTextSubtitles, "2", "", true); |
| 912 Play(); |
| 913 Pause(); |
| 914 SendEosNotification(0); |
| 915 RemoveTextTrack(0); |
| 916 EXPECT_TRUE(text_renderer_->HasTracks()); |
| 917 EXPECT_CALL(*this, OnPause()); |
| 918 SendEosNotification(1); |
| 919 RemoveTextTrack(1); |
| 920 EXPECT_FALSE(text_renderer_->HasTracks()); |
| 921 DestroyTextRenderer(); |
| 922 } |
| 923 |
| 924 TEST_F(TextRendererTest, PlayCuePausePendingRemove_OneTrack) { |
| 925 CreateTextRenderer(); |
| 926 AddTextTrack(kTextSubtitles, "", "", true); |
| 927 Play(); |
| 928 Pause(); |
| 929 EXPECT_CALL(*this, OnPause()); |
| 930 SendCues(true); |
| 931 RemoveTextTrack(0); |
| 932 EXPECT_FALSE(text_renderer_->HasTracks()); |
| 933 DestroyTextRenderer(); |
| 934 } |
| 935 |
| 936 TEST_F(TextRendererTest, PlayCuePausePendingRemove_TwoTracks) { |
| 937 CreateTextRenderer(); |
| 938 AddTextTrack(kTextSubtitles, "1", "", true); |
| 939 AddTextTrack(kTextSubtitles, "2", "", true); |
| 940 Play(); |
| 941 Pause(); |
| 942 SendCue(0, true); |
| 943 EXPECT_CALL(*this, OnPause()); |
| 944 SendCue(1, true); |
| 945 RemoveTextTrack(0); |
| 946 EXPECT_TRUE(text_renderer_->HasTracks()); |
| 947 RemoveTextTrack(1); |
| 948 EXPECT_FALSE(text_renderer_->HasTracks()); |
| 949 DestroyTextRenderer(); |
| 950 } |
| 951 |
| 952 TEST_F(TextRendererTest, PlayCuePausePendingRemove_SplitSendCue) { |
| 953 CreateTextRenderer(); |
| 954 AddTextTrack(kTextSubtitles, "1", "", true); |
| 955 AddTextTrack(kTextSubtitles, "2", "", true); |
| 956 Play(); |
| 957 Pause(); |
| 958 SendCue(0, true); |
| 959 RemoveTextTrack(0); |
| 960 EXPECT_TRUE(text_renderer_->HasTracks()); |
| 961 EXPECT_CALL(*this, OnPause()); |
| 962 SendCue(1, true); |
| 963 RemoveTextTrack(1); |
| 964 EXPECT_FALSE(text_renderer_->HasTracks()); |
| 965 DestroyTextRenderer(); |
| 966 } |
| 967 |
| 968 TEST_F(TextRendererTest, PlayEosPauseRemove_PauseThenRemove) { |
| 969 CreateTextRenderer(); |
| 970 AddTextTrack(kTextSubtitles, "", "", true); |
| 971 Play(); |
| 972 EXPECT_CALL(*this, OnEnd()); |
| 973 SendEosNotifications(); |
| 974 EXPECT_CALL(*this, OnPause()); |
| 975 Pause(); |
| 976 RemoveTextTrack(0); |
| 977 EXPECT_FALSE(text_renderer_->HasTracks()); |
| 978 DestroyTextRenderer(); |
| 979 } |
| 980 |
| 981 TEST_F(TextRendererTest, PlayEosPauseRemove_RemoveThenPause) { |
| 982 CreateTextRenderer(); |
| 983 AddTextTrack(kTextSubtitles, "", "", true); |
| 984 Play(); |
| 985 EXPECT_CALL(*this, OnEnd()); |
| 986 SendEosNotifications(); |
| 987 RemoveTextTrack(0); |
| 988 EXPECT_FALSE(text_renderer_->HasTracks()); |
| 989 EXPECT_CALL(*this, OnPause()); |
| 990 Pause(); |
| 991 DestroyTextRenderer(); |
| 992 } |
| 993 |
| 994 TEST_F(TextRendererTest, PlayEosPause_PauseThenRemoveTwoTracks) { |
| 995 CreateTextRenderer(); |
| 996 AddTextTrack(kTextSubtitles, "1", "", true); |
| 997 AddTextTrack(kTextSubtitles, "2", "", true); |
| 998 Play(); |
| 999 SendEosNotification(0); |
| 1000 EXPECT_CALL(*this, OnEnd()); |
| 1001 SendEosNotification(1); |
| 1002 EXPECT_CALL(*this, OnPause()); |
| 1003 Pause(); |
| 1004 RemoveTextTrack(0); |
| 1005 EXPECT_TRUE(text_renderer_->HasTracks()); |
| 1006 RemoveTextTrack(1); |
| 1007 EXPECT_FALSE(text_renderer_->HasTracks()); |
| 1008 DestroyTextRenderer(); |
| 1009 } |
| 1010 |
| 1011 TEST_F(TextRendererTest, PlayEosPause_RemovePauseRemove) { |
| 1012 CreateTextRenderer(); |
| 1013 AddTextTrack(kTextSubtitles, "1", "", true); |
| 1014 AddTextTrack(kTextSubtitles, "2", "", true); |
| 1015 Play(); |
| 1016 SendEosNotification(0); |
| 1017 EXPECT_CALL(*this, OnEnd()); |
| 1018 SendEosNotification(1); |
| 1019 RemoveTextTrack(0); |
| 1020 EXPECT_TRUE(text_renderer_->HasTracks()); |
| 1021 EXPECT_CALL(*this, OnPause()); |
| 1022 Pause(); |
| 1023 RemoveTextTrack(1); |
| 1024 EXPECT_FALSE(text_renderer_->HasTracks()); |
| 1025 DestroyTextRenderer(); |
| 1026 } |
| 1027 |
| 1028 TEST_F(TextRendererTest, PlayEosPause_EosThenPause) { |
| 1029 CreateTextRenderer(); |
| 1030 AddTextTrack(kTextSubtitles, "1", "", true); |
| 1031 AddTextTrack(kTextSubtitles, "2", "", true); |
| 1032 Play(); |
| 1033 SendEosNotification(0); |
| 1034 RemoveTextTrack(0); |
| 1035 EXPECT_TRUE(text_renderer_->HasTracks()); |
| 1036 EXPECT_CALL(*this, OnEnd()); |
| 1037 SendEosNotification(1); |
| 1038 EXPECT_CALL(*this, OnPause()); |
| 1039 Pause(); |
| 1040 RemoveTextTrack(1); |
| 1041 EXPECT_FALSE(text_renderer_->HasTracks()); |
| 1042 DestroyTextRenderer(); |
| 1043 } |
| 1044 |
| 1045 TEST_F(TextRendererTest, PlayEosPause_PauseLast) { |
| 1046 CreateTextRenderer(); |
| 1047 AddTextTrack(kTextSubtitles, "1", "", true); |
| 1048 AddTextTrack(kTextSubtitles, "2", "", true); |
| 1049 Play(); |
| 1050 SendEosNotification(0); |
| 1051 RemoveTextTrack(0); |
| 1052 EXPECT_TRUE(text_renderer_->HasTracks()); |
| 1053 EXPECT_CALL(*this, OnEnd()); |
| 1054 SendEosNotification(1); |
| 1055 RemoveTextTrack(1); |
| 1056 EXPECT_FALSE(text_renderer_->HasTracks()); |
| 1057 EXPECT_CALL(*this, OnPause()); |
| 1058 Pause(); |
| 1059 DestroyTextRenderer(); |
| 1060 } |
| 1061 |
| 1062 TEST_F(TextRendererTest, PlayEosPause_EosPauseRemove) { |
| 1063 CreateTextRenderer(); |
| 1064 AddTextTrack(kTextSubtitles, "1", "", true); |
| 1065 AddTextTrack(kTextSubtitles, "2", "", true); |
| 1066 Play(); |
| 1067 SendEosNotification(0); |
| 1068 EXPECT_CALL(*this, OnEnd()); |
| 1069 SendEosNotification(1); |
| 1070 EXPECT_CALL(*this, OnPause()); |
| 1071 Pause(); |
| 1072 RemoveTextTrack(0); |
| 1073 EXPECT_TRUE(text_renderer_->HasTracks()); |
| 1074 RemoveTextTrack(1); |
| 1075 EXPECT_FALSE(text_renderer_->HasTracks()); |
| 1076 DestroyTextRenderer(); |
| 1077 } |
| 1078 |
| 1079 TEST_F(TextRendererTest, PlayEosPause_EosRemovePause) { |
| 1080 CreateTextRenderer(); |
| 1081 AddTextTrack(kTextSubtitles, "1", "", true); |
| 1082 AddTextTrack(kTextSubtitles, "2", "", true); |
| 1083 Play(); |
| 1084 SendEosNotification(0); |
| 1085 EXPECT_CALL(*this, OnEnd()); |
| 1086 SendEosNotification(1); |
| 1087 RemoveTextTrack(0); |
| 1088 EXPECT_TRUE(text_renderer_->HasTracks()); |
| 1089 EXPECT_CALL(*this, OnPause()); |
| 1090 Pause(); |
| 1091 RemoveTextTrack(1); |
| 1092 EXPECT_FALSE(text_renderer_->HasTracks()); |
| 1093 DestroyTextRenderer(); |
| 1094 } |
| 1095 |
| 1096 TEST_F(TextRendererTest, PlayEosPause_EosRemoveEosPause) { |
| 1097 CreateTextRenderer(); |
| 1098 AddTextTrack(kTextSubtitles, "1", "", true); |
| 1099 AddTextTrack(kTextSubtitles, "2", "", true); |
| 1100 Play(); |
| 1101 SendEosNotification(0); |
| 1102 RemoveTextTrack(0); |
| 1103 EXPECT_TRUE(text_renderer_->HasTracks()); |
| 1104 EXPECT_CALL(*this, OnEnd()); |
| 1105 SendEosNotification(1); |
| 1106 EXPECT_CALL(*this, OnPause()); |
| 1107 Pause(); |
| 1108 RemoveTextTrack(1); |
| 1109 EXPECT_FALSE(text_renderer_->HasTracks()); |
| 1110 DestroyTextRenderer(); |
| 1111 } |
| 1112 |
| 1113 TEST_F(TextRendererTest, PlayEosPause_EosRemoveEosRemovePause) { |
| 1114 CreateTextRenderer(); |
| 1115 AddTextTrack(kTextSubtitles, "1", "", true); |
| 1116 AddTextTrack(kTextSubtitles, "2", "", true); |
| 1117 Play(); |
| 1118 SendEosNotification(0); |
| 1119 RemoveTextTrack(0); |
| 1120 EXPECT_TRUE(text_renderer_->HasTracks()); |
| 1121 EXPECT_CALL(*this, OnEnd()); |
| 1122 SendEosNotification(1); |
| 1123 RemoveTextTrack(1); |
| 1124 EXPECT_FALSE(text_renderer_->HasTracks()); |
| 1125 EXPECT_CALL(*this, OnPause()); |
| 1126 Pause(); |
| 1127 DestroyTextRenderer(); |
| 1128 } |
| 1129 |
| 1130 TEST_F(TextRendererTest, PlayEosFlushRemove_OneTrack) { |
| 1131 CreateTextRenderer(); |
| 1132 AddTextTrack(kTextSubtitles, "", "", true); |
| 1133 Play(); |
| 1134 EXPECT_CALL(*this, OnEnd()); |
| 1135 SendEosNotifications(); |
| 1136 EXPECT_CALL(*this, OnPause()); |
| 1137 Pause(); |
| 1138 Flush(); |
| 1139 ExpectRead(0); |
| 1140 Play(); |
| 1141 EXPECT_CALL(*this, OnEnd()); |
| 1142 SendEosNotifications(); |
| 1143 RemoveTextTrack(0); |
| 1144 EXPECT_FALSE(text_renderer_->HasTracks()); |
| 1145 DestroyTextRenderer(); |
| 1146 } |
| 1147 |
| 1148 TEST_F(TextRendererTest, PlayEosFlushRemove_TwoTracks) { |
| 1149 CreateTextRenderer(); |
| 1150 AddTextTrack(kTextSubtitles, "1", "", true); |
| 1151 AddTextTrack(kTextSubtitles, "2", "", true); |
| 1152 Play(); |
| 1153 EXPECT_CALL(*this, OnEnd()); |
| 1154 SendEosNotifications(); |
| 1155 EXPECT_CALL(*this, OnPause()); |
| 1156 Pause(); |
| 1157 Flush(); |
| 1158 ExpectRead(0); |
| 1159 ExpectRead(1); |
| 1160 Play(); |
| 1161 SendEosNotification(0); |
| 1162 EXPECT_CALL(*this, OnEnd()); |
| 1163 SendEosNotification(1); |
| 1164 RemoveTextTrack(0); |
| 1165 EXPECT_TRUE(text_renderer_->HasTracks()); |
| 1166 RemoveTextTrack(1); |
| 1167 EXPECT_FALSE(text_renderer_->HasTracks()); |
| 1168 DestroyTextRenderer(); |
| 1169 } |
| 1170 |
| 1171 TEST_F(TextRendererTest, PlayEosFlushRemove_EosRemove) { |
| 1172 CreateTextRenderer(); |
| 1173 AddTextTrack(kTextSubtitles, "1", "", true); |
| 1174 AddTextTrack(kTextSubtitles, "2", "", true); |
| 1175 Play(); |
| 1176 EXPECT_CALL(*this, OnEnd()); |
| 1177 SendEosNotifications(); |
| 1178 EXPECT_CALL(*this, OnPause()); |
| 1179 Pause(); |
| 1180 Flush(); |
| 1181 ExpectRead(0); |
| 1182 ExpectRead(1); |
| 1183 Play(); |
| 1184 SendEosNotification(0); |
| 1185 RemoveTextTrack(0); |
| 1186 EXPECT_TRUE(text_renderer_->HasTracks()); |
| 1187 EXPECT_CALL(*this, OnEnd()); |
| 1188 SendEosNotification(1); |
| 1189 RemoveTextTrack(1); |
| 1190 EXPECT_FALSE(text_renderer_->HasTracks()); |
| 1191 DestroyTextRenderer(); |
| 1192 } |
| 1193 |
| 1194 TEST_F(TextRendererTest, PlayShort_SendCueThenEos) { |
| 1195 CreateTextRenderer(); |
| 1196 AddTextTrack(kTextSubtitles, "1", "", true); |
| 1197 AddTextTrack(kTextSubtitles, "2", "", true); |
| 1198 Play(); |
| 1199 Pause(); |
| 1200 SendCue(0, true); |
| 1201 EXPECT_CALL(*this, OnPause()); |
| 1202 SendEosNotification(1); |
| 1203 DestroyTextRenderer(); |
| 1204 } |
| 1205 |
| 1206 TEST_F(TextRendererTest, PlayShort_EosThenSendCue) { |
| 1207 CreateTextRenderer(); |
| 1208 AddTextTrack(kTextSubtitles, "1", "", true); |
| 1209 AddTextTrack(kTextSubtitles, "2", "", true); |
| 1210 Play(); |
| 1211 Pause(); |
| 1212 SendEosNotification(0); |
| 1213 EXPECT_CALL(*this, OnPause()); |
| 1214 SendCue(1, true); |
| 1215 DestroyTextRenderer(); |
| 1216 } |
| 1217 |
| 1218 TEST_F(TextRendererTest, PlayShortRemove_SendEosRemove) { |
| 1219 CreateTextRenderer(); |
| 1220 AddTextTrack(kTextSubtitles, "1", "", true); |
| 1221 AddTextTrack(kTextSubtitles, "2", "", true); |
| 1222 Play(); |
| 1223 Pause(); |
| 1224 SendCue(0, true); |
| 1225 EXPECT_CALL(*this, OnPause()); |
| 1226 SendEosNotification(1); |
| 1227 RemoveTextTrack(0); |
| 1228 EXPECT_TRUE(text_renderer_->HasTracks()); |
| 1229 RemoveTextTrack(1); |
| 1230 EXPECT_FALSE(text_renderer_->HasTracks()); |
| 1231 DestroyTextRenderer(); |
| 1232 } |
| 1233 |
| 1234 TEST_F(TextRendererTest, PlayShortRemove_SendRemoveEos) { |
| 1235 CreateTextRenderer(); |
| 1236 AddTextTrack(kTextSubtitles, "1", "", true); |
| 1237 AddTextTrack(kTextSubtitles, "2", "", true); |
| 1238 Play(); |
| 1239 Pause(); |
| 1240 SendCue(0, true); |
| 1241 RemoveTextTrack(0); |
| 1242 EXPECT_TRUE(text_renderer_->HasTracks()); |
| 1243 EXPECT_CALL(*this, OnPause()); |
| 1244 SendEosNotification(1); |
| 1245 RemoveTextTrack(1); |
| 1246 EXPECT_FALSE(text_renderer_->HasTracks()); |
| 1247 DestroyTextRenderer(); |
| 1248 } |
| 1249 |
| 1250 TEST_F(TextRendererTest, PlayCuePausePendingCancel_OneTrack) { |
| 1251 CreateTextRenderer(); |
| 1252 AddTextTrack(kTextSubtitles, "", "", true); |
| 1253 Play(); |
| 1254 Pause(); |
| 1255 EXPECT_CALL(*this, OnPause()); |
| 1256 AbortPendingRead(0); |
| 1257 DestroyTextRenderer(); |
| 1258 } |
| 1259 |
| 1260 TEST_F(TextRendererTest, PlayCuePausePendingCancel_SendThenCancel) { |
| 1261 CreateTextRenderer(); |
| 1262 AddTextTrack(kTextSubtitles, "1", "", true); |
| 1263 AddTextTrack(kTextSubtitles, "2", "", true); |
| 1264 Play(); |
| 1265 Pause(); |
| 1266 SendCue(0, true); |
| 1267 EXPECT_CALL(*this, OnPause()); |
| 1268 AbortPendingRead(1); |
| 1269 DestroyTextRenderer(); |
| 1270 } |
| 1271 |
| 1272 TEST_F(TextRendererTest, PlayCuePausePendingCancel_CancelThenSend) { |
| 1273 CreateTextRenderer(); |
| 1274 AddTextTrack(kTextSubtitles, "1", "", true); |
| 1275 AddTextTrack(kTextSubtitles, "2", "", true); |
| 1276 Play(); |
| 1277 Pause(); |
| 1278 AbortPendingRead(0); |
| 1279 EXPECT_CALL(*this, OnPause()); |
| 1280 SendCue(1, true); |
| 1281 DestroyTextRenderer(); |
| 1282 } |
| 1283 |
| 1284 TEST_F(TextRendererTest, PlayCueStopPendingCancel_OneTrack) { |
| 1285 CreateTextRenderer(); |
| 1286 AddTextTrack(kTextSubtitles, "", "", true); |
| 1287 Play(); |
| 1288 Pause(); |
| 1289 Stop(); |
| 1290 EXPECT_CALL(*this, OnStop()); |
| 1291 AbortPendingRead(0); |
| 1292 text_renderer_.reset(); |
| 1293 text_track_streams_.clear(); |
| 1294 } |
| 1295 |
| 1296 TEST_F(TextRendererTest, PlayCueStopPendingCancel_SendThenCancel) { |
| 1297 CreateTextRenderer(); |
| 1298 AddTextTrack(kTextSubtitles, "1", "", true); |
| 1299 AddTextTrack(kTextSubtitles, "2", "", true); |
| 1300 Play(); |
| 1301 Pause(); |
| 1302 Stop(); |
| 1303 SendCue(0, false); |
| 1304 EXPECT_CALL(*this, OnStop()); |
| 1305 AbortPendingRead(1); |
| 1306 text_renderer_.reset(); |
| 1307 text_track_streams_.clear(); |
| 1308 } |
| 1309 |
| 1310 TEST_F(TextRendererTest, PlayCueStopPendingCancel_CancelThenSend) { |
| 1311 CreateTextRenderer(); |
| 1312 AddTextTrack(kTextSubtitles, "1", "", true); |
| 1313 AddTextTrack(kTextSubtitles, "2", "", true); |
| 1314 Play(); |
| 1315 Pause(); |
| 1316 Stop(); |
| 1317 AbortPendingRead(0); |
| 1318 EXPECT_CALL(*this, OnStop()); |
| 1319 SendCue(1, false); |
| 1320 text_renderer_.reset(); |
| 1321 text_track_streams_.clear(); |
| 1322 } |
| 1323 |
| 1324 TEST_F(TextRendererTest, AddRemoveAdd) { |
| 1325 CreateTextRenderer(); |
| 1326 AddTextTrack(kTextSubtitles, "", "", true); |
| 1327 Play(); |
| 1328 AbortPendingRead(0); |
| 1329 RemoveTextTrack(0); |
| 1330 EXPECT_CALL(*this, OnPause()); |
| 1331 Pause(); |
| 1332 AddTextTrack(kTextSubtitles, "", "", true); |
| 1333 Play(); |
| 1334 EXPECT_CALL(*this, OnEnd()); |
| 1335 SendEosNotification(1); |
| 1336 DestroyTextRenderer(); |
| 1337 } |
| 1338 |
| 1339 TEST_F(TextRendererTest, AddRemoveEos) { |
| 1340 CreateTextRenderer(); |
| 1341 AddTextTrack(kTextSubtitles, "1", "", true); |
| 1342 AddTextTrack(kTextSubtitles, "2", "", true); |
| 1343 Play(); |
| 1344 AbortPendingRead(0); |
| 1345 RemoveTextTrack(0); |
| 1346 EXPECT_TRUE(text_renderer_->HasTracks()); |
| 1347 EXPECT_CALL(*this, OnEnd()); |
| 1348 SendEosNotification(1); |
| 1349 DestroyTextRenderer(); |
| 1350 } |
| 1351 |
| 1352 TEST_F(TextRendererTest, AddRemovePause) { |
| 1353 CreateTextRenderer(); |
| 1354 AddTextTrack(kTextSubtitles, "1", "", true); |
| 1355 AddTextTrack(kTextSubtitles, "2", "", true); |
| 1356 Play(); |
| 1357 AbortPendingRead(0); |
| 1358 RemoveTextTrack(0); |
| 1359 EXPECT_TRUE(text_renderer_->HasTracks()); |
| 1360 Pause(); |
| 1361 EXPECT_CALL(*this, OnPause()); |
| 1362 SendEosNotification(1); |
| 1363 DestroyTextRenderer(); |
| 1364 } |
| 1365 |
| 1366 TEST_F(TextRendererTest, AddRemovePauseStop) { |
| 1367 CreateTextRenderer(); |
| 1368 AddTextTrack(kTextSubtitles, "1", "", true); |
| 1369 AddTextTrack(kTextSubtitles, "2", "", true); |
| 1370 Play(); |
| 1371 AbortPendingRead(0); |
| 1372 RemoveTextTrack(0); |
| 1373 EXPECT_TRUE(text_renderer_->HasTracks()); |
| 1374 Pause(); |
| 1375 Stop(); |
| 1376 EXPECT_CALL(*this, OnStop()); |
| 1377 SendEosNotification(1); |
| 1378 text_renderer_.reset(); |
| 1379 text_track_streams_.clear(); |
| 1380 } |
| 1381 |
| 1382 } // namespace media |
OLD | NEW |