Upstream version 9.38.198.0
[platform/framework/web/crosswalk.git] / src / media / filters / decrypting_demuxer_stream_unittest.cc
1 // Copyright (c) 2012 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 <string>
6 #include <vector>
7
8 #include "base/bind.h"
9 #include "base/callback_helpers.h"
10 #include "base/message_loop/message_loop.h"
11 #include "media/base/decoder_buffer.h"
12 #include "media/base/decrypt_config.h"
13 #include "media/base/gmock_callback_support.h"
14 #include "media/base/mock_filters.h"
15 #include "media/base/test_helpers.h"
16 #include "media/filters/decrypting_demuxer_stream.h"
17 #include "testing/gmock/include/gmock/gmock.h"
18
19 using ::testing::_;
20 using ::testing::IsNull;
21 using ::testing::Return;
22 using ::testing::SaveArg;
23 using ::testing::StrictMock;
24
25 namespace media {
26
27 static const int kFakeBufferSize = 16;
28 static const uint8 kFakeKeyId[] = { 0x4b, 0x65, 0x79, 0x20, 0x49, 0x44 };
29 static const uint8 kFakeIv[DecryptConfig::kDecryptionKeySize] = { 0 };
30
31 // Create a fake non-empty buffer in an encrypted stream. When |is_clear| is
32 // ture, the buffer is not encrypted (signaled by an empty IV).
33 static scoped_refptr<DecoderBuffer> CreateFakeEncryptedStreamBuffer(
34     bool is_clear) {
35   scoped_refptr<DecoderBuffer> buffer(new DecoderBuffer(kFakeBufferSize));
36   std::string iv = is_clear ? std::string() :
37       std::string(reinterpret_cast<const char*>(kFakeIv), arraysize(kFakeIv));
38   buffer->set_decrypt_config(scoped_ptr<DecryptConfig>(new DecryptConfig(
39       std::string(reinterpret_cast<const char*>(kFakeKeyId),
40                   arraysize(kFakeKeyId)),
41       iv, std::vector<SubsampleEntry>())));
42   return buffer;
43 }
44
45 // Use anonymous namespace here to prevent the actions to be defined multiple
46 // times across multiple test files. Sadly we can't use static for them.
47 namespace {
48
49 ACTION_P(ReturnBuffer, buffer) {
50   arg0.Run(buffer.get() ? DemuxerStream::kOk : DemuxerStream::kAborted, buffer);
51 }
52
53 // Sets the |decryptor| if the DecryptorReadyCB (arg0) is not null. Sets
54 // |is_decryptor_set| to true if a non-NULL |decryptor| has been set through the
55 // callback.
56 ACTION_P3(SetDecryptorIfNotNull, decryptor, done_cb, is_decryptor_set) {
57   if (!arg0.is_null())
58     arg0.Run(decryptor, done_cb);
59
60   *is_decryptor_set = !arg0.is_null() && decryptor;
61 }
62
63 ACTION_P2(ResetAndRunCallback, callback, param) {
64   base::ResetAndReturn(callback).Run(param);
65 }
66
67 MATCHER(IsEndOfStream, "end of stream") {
68   return arg->end_of_stream();
69 }
70
71 }  // namespace
72
73 class DecryptingDemuxerStreamTest : public testing::Test {
74  public:
75   DecryptingDemuxerStreamTest()
76       : demuxer_stream_(new DecryptingDemuxerStream(
77             message_loop_.message_loop_proxy(),
78             base::Bind(
79                 &DecryptingDemuxerStreamTest::RequestDecryptorNotification,
80                 base::Unretained(this)))),
81         decryptor_(new StrictMock<MockDecryptor>()),
82         is_decryptor_set_(false),
83         input_audio_stream_(
84             new StrictMock<MockDemuxerStream>(DemuxerStream::AUDIO)),
85         input_video_stream_(
86             new StrictMock<MockDemuxerStream>(DemuxerStream::VIDEO)),
87         clear_buffer_(CreateFakeEncryptedStreamBuffer(true)),
88         encrypted_buffer_(CreateFakeEncryptedStreamBuffer(false)),
89         decrypted_buffer_(new DecoderBuffer(kFakeBufferSize)) {
90   }
91
92   virtual ~DecryptingDemuxerStreamTest() {
93     if (is_decryptor_set_)
94       EXPECT_CALL(*decryptor_, CancelDecrypt(_));
95     demuxer_stream_.reset();
96     message_loop_.RunUntilIdle();
97   }
98
99   void InitializeAudioAndExpectStatus(const AudioDecoderConfig& config,
100                                       PipelineStatus status) {
101     input_audio_stream_->set_audio_decoder_config(config);
102     demuxer_stream_->Initialize(input_audio_stream_.get(),
103                                 NewExpectedStatusCB(status));
104     message_loop_.RunUntilIdle();
105   }
106
107   void InitializeVideoAndExpectStatus(const VideoDecoderConfig& config,
108                                       PipelineStatus status) {
109     input_video_stream_->set_video_decoder_config(config);
110     demuxer_stream_->Initialize(input_video_stream_.get(),
111                                 NewExpectedStatusCB(status));
112     message_loop_.RunUntilIdle();
113   }
114
115   void ExpectDecryptorNotification(Decryptor* decryptor, bool expected_result) {
116     EXPECT_CALL(*this, RequestDecryptorNotification(_))
117         .WillOnce(SetDecryptorIfNotNull(
118             decryptor,
119             base::Bind(&DecryptingDemuxerStreamTest::DecryptorSet,
120                        base::Unretained(this)),
121             &is_decryptor_set_));
122     EXPECT_CALL(*this, DecryptorSet(expected_result));
123   }
124
125   // The following functions are used to test stream-type-neutral logic in
126   // DecryptingDemuxerStream. Therefore, we don't specify audio or video in the
127   // function names. But for testing purpose, they all use an audio input
128   // demuxer stream.
129
130   void Initialize() {
131     ExpectDecryptorNotification(decryptor_.get(), true);
132     EXPECT_CALL(*decryptor_, RegisterNewKeyCB(Decryptor::kAudio, _))
133         .WillOnce(SaveArg<1>(&key_added_cb_));
134
135     AudioDecoderConfig input_config(
136         kCodecVorbis, kSampleFormatPlanarF32, CHANNEL_LAYOUT_STEREO, 44100,
137         NULL, 0, true);
138     InitializeAudioAndExpectStatus(input_config, PIPELINE_OK);
139
140     const AudioDecoderConfig& output_config =
141         demuxer_stream_->audio_decoder_config();
142     EXPECT_EQ(DemuxerStream::AUDIO, demuxer_stream_->type());
143     EXPECT_FALSE(output_config.is_encrypted());
144     EXPECT_EQ(input_config.bits_per_channel(),
145               output_config.bits_per_channel());
146     EXPECT_EQ(input_config.channel_layout(), output_config.channel_layout());
147     EXPECT_EQ(input_config.sample_format(), output_config.sample_format());
148     EXPECT_EQ(input_config.samples_per_second(),
149               output_config.samples_per_second());
150   }
151
152   void ReadAndExpectBufferReadyWith(
153       DemuxerStream::Status status,
154       const scoped_refptr<DecoderBuffer>& decrypted_buffer) {
155     if (status != DemuxerStream::kOk)
156       EXPECT_CALL(*this, BufferReady(status, IsNull()));
157     else if (decrypted_buffer->end_of_stream())
158       EXPECT_CALL(*this, BufferReady(status, IsEndOfStream()));
159     else
160       EXPECT_CALL(*this, BufferReady(status, decrypted_buffer));
161
162     demuxer_stream_->Read(base::Bind(&DecryptingDemuxerStreamTest::BufferReady,
163                                      base::Unretained(this)));
164     message_loop_.RunUntilIdle();
165   }
166
167   void EnterClearReadingState() {
168     EXPECT_TRUE(clear_buffer_->decrypt_config());
169     EXPECT_CALL(*input_audio_stream_, Read(_))
170         .WillOnce(ReturnBuffer(clear_buffer_));
171
172     // For clearbuffer, decryptor->Decrypt() will not be called.
173
174     scoped_refptr<DecoderBuffer> decrypted_buffer;
175     EXPECT_CALL(*this, BufferReady(DemuxerStream::kOk, _))
176         .WillOnce(SaveArg<1>(&decrypted_buffer));
177     demuxer_stream_->Read(base::Bind(&DecryptingDemuxerStreamTest::BufferReady,
178                                      base::Unretained(this)));
179     message_loop_.RunUntilIdle();
180
181     EXPECT_FALSE(decrypted_buffer->decrypt_config());
182   }
183
184   // Sets up expectations and actions to put DecryptingDemuxerStream in an
185   // active normal reading state.
186   void EnterNormalReadingState() {
187     EXPECT_CALL(*input_audio_stream_, Read(_))
188         .WillOnce(ReturnBuffer(encrypted_buffer_));
189     EXPECT_CALL(*decryptor_, Decrypt(_, _, _))
190         .WillOnce(RunCallback<2>(Decryptor::kSuccess, decrypted_buffer_));
191
192     ReadAndExpectBufferReadyWith(DemuxerStream::kOk, decrypted_buffer_);
193   }
194
195   // Make the read callback pending by saving and not firing it.
196   void EnterPendingReadState() {
197     EXPECT_TRUE(pending_demuxer_read_cb_.is_null());
198     EXPECT_CALL(*input_audio_stream_, Read(_))
199         .WillOnce(SaveArg<0>(&pending_demuxer_read_cb_));
200     demuxer_stream_->Read(base::Bind(&DecryptingDemuxerStreamTest::BufferReady,
201                                      base::Unretained(this)));
202     message_loop_.RunUntilIdle();
203     // Make sure the Read() triggers a Read() on the input demuxer stream.
204     EXPECT_FALSE(pending_demuxer_read_cb_.is_null());
205   }
206
207   // Make the decrypt callback pending by saving and not firing it.
208   void EnterPendingDecryptState() {
209     EXPECT_TRUE(pending_decrypt_cb_.is_null());
210     EXPECT_CALL(*input_audio_stream_, Read(_))
211         .WillRepeatedly(ReturnBuffer(encrypted_buffer_));
212     EXPECT_CALL(*decryptor_, Decrypt(_, encrypted_buffer_, _))
213         .WillOnce(SaveArg<2>(&pending_decrypt_cb_));
214
215     demuxer_stream_->Read(base::Bind(&DecryptingDemuxerStreamTest::BufferReady,
216                                      base::Unretained(this)));
217     message_loop_.RunUntilIdle();
218     // Make sure Read() triggers a Decrypt() on the decryptor.
219     EXPECT_FALSE(pending_decrypt_cb_.is_null());
220   }
221
222   void EnterWaitingForKeyState() {
223     EXPECT_CALL(*input_audio_stream_, Read(_))
224         .WillRepeatedly(ReturnBuffer(encrypted_buffer_));
225     EXPECT_CALL(*decryptor_, Decrypt(_, encrypted_buffer_, _))
226         .WillRepeatedly(RunCallback<2>(Decryptor::kNoKey,
227                                        scoped_refptr<DecoderBuffer>()));
228     demuxer_stream_->Read(base::Bind(&DecryptingDemuxerStreamTest::BufferReady,
229                                      base::Unretained(this)));
230     message_loop_.RunUntilIdle();
231   }
232
233   void AbortPendingDecryptCB() {
234     if (!pending_decrypt_cb_.is_null()) {
235       base::ResetAndReturn(&pending_decrypt_cb_).Run(Decryptor::kSuccess, NULL);
236     }
237   }
238
239   void SatisfyPendingDemuxerReadCB(DemuxerStream::Status status) {
240     scoped_refptr<DecoderBuffer> buffer =
241         (status == DemuxerStream::kOk) ? encrypted_buffer_ : NULL;
242     base::ResetAndReturn(&pending_demuxer_read_cb_).Run(status, buffer);
243   }
244
245   void Reset() {
246     if (is_decryptor_set_) {
247       EXPECT_CALL(*decryptor_, CancelDecrypt(Decryptor::kAudio))
248           .WillRepeatedly(InvokeWithoutArgs(
249               this, &DecryptingDemuxerStreamTest::AbortPendingDecryptCB));
250     }
251
252     demuxer_stream_->Reset(NewExpectedClosure());
253     message_loop_.RunUntilIdle();
254   }
255
256   MOCK_METHOD1(RequestDecryptorNotification, void(const DecryptorReadyCB&));
257
258   MOCK_METHOD2(BufferReady, void(DemuxerStream::Status,
259                                  const scoped_refptr<DecoderBuffer>&));
260
261   MOCK_METHOD1(DecryptorSet, void(bool));
262
263   base::MessageLoop message_loop_;
264   scoped_ptr<DecryptingDemuxerStream> demuxer_stream_;
265   scoped_ptr<StrictMock<MockDecryptor> > decryptor_;
266   // Whether a valid Decryptor has been set in the |demuxer_stream_|.
267   bool is_decryptor_set_;
268   scoped_ptr<StrictMock<MockDemuxerStream> > input_audio_stream_;
269   scoped_ptr<StrictMock<MockDemuxerStream> > input_video_stream_;
270
271   DemuxerStream::ReadCB pending_demuxer_read_cb_;
272   Decryptor::NewKeyCB key_added_cb_;
273   Decryptor::DecryptCB pending_decrypt_cb_;
274
275   // Constant buffers to be returned by the input demuxer streams and the
276   // |decryptor_|.
277   scoped_refptr<DecoderBuffer> clear_buffer_;
278   scoped_refptr<DecoderBuffer> encrypted_buffer_;
279   scoped_refptr<DecoderBuffer> decrypted_buffer_;
280
281  private:
282   DISALLOW_COPY_AND_ASSIGN(DecryptingDemuxerStreamTest);
283 };
284
285 TEST_F(DecryptingDemuxerStreamTest, Initialize_NormalAudio) {
286   Initialize();
287 }
288
289 TEST_F(DecryptingDemuxerStreamTest, Initialize_NormalVideo) {
290   ExpectDecryptorNotification(decryptor_.get(), true);
291   EXPECT_CALL(*decryptor_, RegisterNewKeyCB(Decryptor::kVideo, _))
292       .WillOnce(SaveArg<1>(&key_added_cb_));
293
294   VideoDecoderConfig input_config = TestVideoConfig::NormalEncrypted();
295   InitializeVideoAndExpectStatus(input_config, PIPELINE_OK);
296
297   const VideoDecoderConfig& output_config =
298       demuxer_stream_->video_decoder_config();
299   EXPECT_EQ(DemuxerStream::VIDEO, demuxer_stream_->type());
300   EXPECT_FALSE(output_config.is_encrypted());
301   EXPECT_EQ(input_config.codec(), output_config.codec());
302   EXPECT_EQ(input_config.format(), output_config.format());
303   EXPECT_EQ(input_config.profile(), output_config.profile());
304   EXPECT_EQ(input_config.coded_size(), output_config.coded_size());
305   EXPECT_EQ(input_config.visible_rect(), output_config.visible_rect());
306   EXPECT_EQ(input_config.natural_size(), output_config.natural_size());
307   ASSERT_EQ(input_config.extra_data_size(), output_config.extra_data_size());
308   if (input_config.extra_data_size() > 0) {
309     EXPECT_FALSE(output_config.extra_data());
310     EXPECT_EQ(0, memcmp(output_config.extra_data(), input_config.extra_data(),
311                         input_config.extra_data_size()));
312   }
313 }
314
315 TEST_F(DecryptingDemuxerStreamTest, Initialize_NullDecryptor) {
316   ExpectDecryptorNotification(NULL, false);
317   AudioDecoderConfig input_config(kCodecVorbis, kSampleFormatPlanarF32,
318                                   CHANNEL_LAYOUT_STEREO, 44100, NULL, 0, true);
319   InitializeAudioAndExpectStatus(input_config, DECODER_ERROR_NOT_SUPPORTED);
320 }
321
322 // Test normal read case where the buffer is encrypted.
323 TEST_F(DecryptingDemuxerStreamTest, Read_Normal) {
324   Initialize();
325   EnterNormalReadingState();
326 }
327
328 // Test normal read case where the buffer is clear.
329 TEST_F(DecryptingDemuxerStreamTest, Read_Clear) {
330   Initialize();
331   EnterClearReadingState();
332 }
333
334 // Test the case where the decryptor returns error during read.
335 TEST_F(DecryptingDemuxerStreamTest, Read_DecryptError) {
336   Initialize();
337
338   EXPECT_CALL(*input_audio_stream_, Read(_))
339       .WillRepeatedly(ReturnBuffer(encrypted_buffer_));
340   EXPECT_CALL(*decryptor_, Decrypt(_, encrypted_buffer_, _))
341       .WillRepeatedly(RunCallback<2>(Decryptor::kError,
342                                      scoped_refptr<DecoderBuffer>()));
343   ReadAndExpectBufferReadyWith(DemuxerStream::kAborted, NULL);
344 }
345
346 // Test the case where the input is an end-of-stream buffer.
347 TEST_F(DecryptingDemuxerStreamTest, Read_EndOfStream) {
348   Initialize();
349   EnterNormalReadingState();
350
351   // No Decryptor::Decrypt() call is expected for EOS buffer.
352   EXPECT_CALL(*input_audio_stream_, Read(_))
353       .WillOnce(ReturnBuffer(DecoderBuffer::CreateEOSBuffer()));
354
355   ReadAndExpectBufferReadyWith(DemuxerStream::kOk,
356                                DecoderBuffer::CreateEOSBuffer());
357 }
358
359 // Test the case where the a key is added when the decryptor is in
360 // kWaitingForKey state.
361 TEST_F(DecryptingDemuxerStreamTest, KeyAdded_DuringWaitingForKey) {
362   Initialize();
363   EnterWaitingForKeyState();
364
365   EXPECT_CALL(*decryptor_, Decrypt(_, encrypted_buffer_, _))
366       .WillRepeatedly(RunCallback<2>(Decryptor::kSuccess, decrypted_buffer_));
367   EXPECT_CALL(*this, BufferReady(DemuxerStream::kOk, decrypted_buffer_));
368   key_added_cb_.Run();
369   message_loop_.RunUntilIdle();
370 }
371
372 // Test the case where the a key is added when the decryptor is in
373 // kPendingDecrypt state.
374 TEST_F(DecryptingDemuxerStreamTest, KeyAdded_DruingPendingDecrypt) {
375   Initialize();
376   EnterPendingDecryptState();
377
378   EXPECT_CALL(*decryptor_, Decrypt(_, encrypted_buffer_, _))
379       .WillRepeatedly(RunCallback<2>(Decryptor::kSuccess, decrypted_buffer_));
380   EXPECT_CALL(*this, BufferReady(DemuxerStream::kOk, decrypted_buffer_));
381   // The decrypt callback is returned after the correct decryption key is added.
382   key_added_cb_.Run();
383   base::ResetAndReturn(&pending_decrypt_cb_).Run(Decryptor::kNoKey, NULL);
384   message_loop_.RunUntilIdle();
385 }
386
387 // Test resetting in kDecryptorRequested state.
388 TEST_F(DecryptingDemuxerStreamTest, Reset_DuringDecryptorRequested) {
389   // One for decryptor request, one for canceling request during Reset().
390   EXPECT_CALL(*this, RequestDecryptorNotification(_))
391       .Times(2);
392   AudioDecoderConfig input_config(
393       kCodecVorbis, kSampleFormatPlanarF32, CHANNEL_LAYOUT_STEREO, 44100,
394       NULL, 0, true);
395   InitializeAudioAndExpectStatus(input_config, PIPELINE_ERROR_ABORT);
396   Reset();
397 }
398
399 // Test resetting in kIdle state but has not returned any buffer.
400 TEST_F(DecryptingDemuxerStreamTest, Reset_DuringIdleAfterInitialization) {
401   Initialize();
402   Reset();
403 }
404
405 // Test resetting in kIdle state after having returned one buffer.
406 TEST_F(DecryptingDemuxerStreamTest, Reset_DuringIdleAfterReadOneBuffer) {
407   Initialize();
408   EnterNormalReadingState();
409   Reset();
410 }
411
412 // Test resetting in kPendingDemuxerRead state.
413 TEST_F(DecryptingDemuxerStreamTest, Reset_DuringPendingDemuxerRead) {
414   Initialize();
415   EnterPendingReadState();
416
417   EXPECT_CALL(*this, BufferReady(DemuxerStream::kAborted, IsNull()));
418
419   Reset();
420   SatisfyPendingDemuxerReadCB(DemuxerStream::kOk);
421   message_loop_.RunUntilIdle();
422 }
423
424 // Test resetting in kPendingDecrypt state.
425 TEST_F(DecryptingDemuxerStreamTest, Reset_DuringPendingDecrypt) {
426   Initialize();
427   EnterPendingDecryptState();
428
429   EXPECT_CALL(*this, BufferReady(DemuxerStream::kAborted, IsNull()));
430
431   Reset();
432 }
433
434 // Test resetting in kWaitingForKey state.
435 TEST_F(DecryptingDemuxerStreamTest, Reset_DuringWaitingForKey) {
436   Initialize();
437   EnterWaitingForKeyState();
438
439   EXPECT_CALL(*this, BufferReady(DemuxerStream::kAborted, IsNull()));
440
441   Reset();
442 }
443
444 // Test resetting after reset.
445 TEST_F(DecryptingDemuxerStreamTest, Reset_AfterReset) {
446   Initialize();
447   EnterNormalReadingState();
448   Reset();
449   Reset();
450 }
451
452 // Test aborted read on the demuxer stream.
453 TEST_F(DecryptingDemuxerStreamTest, DemuxerRead_Aborted) {
454   Initialize();
455
456   // ReturnBuffer() with NULL triggers aborted demuxer read.
457   EXPECT_CALL(*input_audio_stream_, Read(_))
458       .WillOnce(ReturnBuffer(scoped_refptr<DecoderBuffer>()));
459
460   ReadAndExpectBufferReadyWith(DemuxerStream::kAborted, NULL);
461 }
462
463 // Test resetting when waiting for an aborted read.
464 TEST_F(DecryptingDemuxerStreamTest, Reset_DuringAbortedDemuxerRead) {
465   Initialize();
466   EnterPendingReadState();
467
468   // Make sure we get a NULL audio frame returned.
469   EXPECT_CALL(*this, BufferReady(DemuxerStream::kAborted, IsNull()));
470
471   Reset();
472   SatisfyPendingDemuxerReadCB(DemuxerStream::kAborted);
473   message_loop_.RunUntilIdle();
474 }
475
476 // Test config change on the input demuxer stream.
477 TEST_F(DecryptingDemuxerStreamTest, DemuxerRead_ConfigChanged) {
478   Initialize();
479
480   AudioDecoderConfig new_config(
481       kCodecVorbis, kSampleFormatPlanarF32, CHANNEL_LAYOUT_STEREO, 88200, NULL,
482       0, true);
483   input_audio_stream_->set_audio_decoder_config(new_config);
484
485   EXPECT_CALL(*input_audio_stream_, Read(_))
486       .WillOnce(RunCallback<0>(DemuxerStream::kConfigChanged,
487                                scoped_refptr<DecoderBuffer>()));
488
489   ReadAndExpectBufferReadyWith(DemuxerStream::kConfigChanged, NULL);
490 }
491
492 // Test resetting when waiting for a config changed read.
493 TEST_F(DecryptingDemuxerStreamTest, Reset_DuringConfigChangedDemuxerRead) {
494   Initialize();
495   EnterPendingReadState();
496
497   // Make sure we get a |kConfigChanged| instead of a |kAborted|.
498   EXPECT_CALL(*this, BufferReady(DemuxerStream::kConfigChanged, IsNull()));
499
500   Reset();
501   SatisfyPendingDemuxerReadCB(DemuxerStream::kConfigChanged);
502   message_loop_.RunUntilIdle();
503 }
504
505 // The following tests test destruction in various scenarios. The destruction
506 // happens in DecryptingDemuxerStreamTest's dtor.
507
508 // Test destruction in kDecryptorRequested state.
509 TEST_F(DecryptingDemuxerStreamTest, Destroy_DuringDecryptorRequested) {
510   // One for decryptor request, one for canceling request during Reset().
511   EXPECT_CALL(*this, RequestDecryptorNotification(_))
512       .Times(2);
513   AudioDecoderConfig input_config(
514       kCodecVorbis, kSampleFormatPlanarF32, CHANNEL_LAYOUT_STEREO, 44100,
515       NULL, 0, true);
516   InitializeAudioAndExpectStatus(input_config, PIPELINE_ERROR_ABORT);
517 }
518
519 // Test destruction in kIdle state but has not returned any buffer.
520 TEST_F(DecryptingDemuxerStreamTest, Destroy_DuringIdleAfterInitialization) {
521   Initialize();
522 }
523
524 // Test destruction in kIdle state after having returned one buffer.
525 TEST_F(DecryptingDemuxerStreamTest, Destroy_DuringIdleAfterReadOneBuffer) {
526   Initialize();
527   EnterNormalReadingState();
528 }
529
530 // Test destruction in kPendingDemuxerRead state.
531 TEST_F(DecryptingDemuxerStreamTest, Destroy_DuringPendingDemuxerRead) {
532   Initialize();
533   EnterPendingReadState();
534
535   EXPECT_CALL(*this, BufferReady(DemuxerStream::kAborted, IsNull()));
536 }
537
538 // Test destruction in kPendingDecrypt state.
539 TEST_F(DecryptingDemuxerStreamTest, Destroy_DuringPendingDecrypt) {
540   Initialize();
541   EnterPendingDecryptState();
542
543   EXPECT_CALL(*this, BufferReady(DemuxerStream::kAborted, IsNull()));
544 }
545
546 // Test destruction in kWaitingForKey state.
547 TEST_F(DecryptingDemuxerStreamTest, Destroy_DuringWaitingForKey) {
548   Initialize();
549   EnterWaitingForKeyState();
550
551   EXPECT_CALL(*this, BufferReady(DemuxerStream::kAborted, IsNull()));
552 }
553
554 // Test destruction after reset.
555 TEST_F(DecryptingDemuxerStreamTest, Destroy_AfterReset) {
556   Initialize();
557   EnterNormalReadingState();
558   Reset();
559 }
560
561 }  // namespace media