Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(264)

Side by Side Diff: media/filters/decrypting_video_decoder_unittest.cc

Issue 2086353002: Remove calls to deprecated MessageLoop methods in media. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: rebase Created 4 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 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 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include <stdint.h> 5 #include <stdint.h>
6 6
7 #include <string> 7 #include <string>
8 #include <vector> 8 #include <vector>
9 9
10 #include "base/bind.h" 10 #include "base/bind.h"
11 #include "base/callback_helpers.h" 11 #include "base/callback_helpers.h"
12 #include "base/macros.h" 12 #include "base/macros.h"
13 #include "base/message_loop/message_loop.h" 13 #include "base/message_loop/message_loop.h"
14 #include "base/run_loop.h"
14 #include "media/base/decoder_buffer.h" 15 #include "media/base/decoder_buffer.h"
15 #include "media/base/decrypt_config.h" 16 #include "media/base/decrypt_config.h"
16 #include "media/base/gmock_callback_support.h" 17 #include "media/base/gmock_callback_support.h"
17 #include "media/base/mock_filters.h" 18 #include "media/base/mock_filters.h"
18 #include "media/base/test_helpers.h" 19 #include "media/base/test_helpers.h"
19 #include "media/base/video_frame.h" 20 #include "media/base/video_frame.h"
20 #include "media/filters/decrypting_video_decoder.h" 21 #include "media/filters/decrypting_video_decoder.h"
21 #include "testing/gmock/include/gmock/gmock.h" 22 #include "testing/gmock/include/gmock/gmock.h"
22 23
23 using ::testing::_; 24 using ::testing::_;
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after
84 } 85 }
85 86
86 // Initializes the |decoder_| and expects |success|. Note the initialization 87 // Initializes the |decoder_| and expects |success|. Note the initialization
87 // can succeed or fail. 88 // can succeed or fail.
88 void InitializeAndExpectResult(const VideoDecoderConfig& config, 89 void InitializeAndExpectResult(const VideoDecoderConfig& config,
89 bool success) { 90 bool success) {
90 decoder_->Initialize(config, false, cdm_context_.get(), 91 decoder_->Initialize(config, false, cdm_context_.get(),
91 NewExpectedBoolCB(success), 92 NewExpectedBoolCB(success),
92 base::Bind(&DecryptingVideoDecoderTest::FrameReady, 93 base::Bind(&DecryptingVideoDecoderTest::FrameReady,
93 base::Unretained(this))); 94 base::Unretained(this)));
94 message_loop_.RunUntilIdle(); 95 base::RunLoop().RunUntilIdle();
95 } 96 }
96 97
97 // Initialize the |decoder_| and expects it to succeed. 98 // Initialize the |decoder_| and expects it to succeed.
98 void Initialize() { 99 void Initialize() {
99 SetCdmType(CDM_WITH_DECRYPTOR); 100 SetCdmType(CDM_WITH_DECRYPTOR);
100 EXPECT_CALL(*decryptor_, InitializeVideoDecoder(_, _)) 101 EXPECT_CALL(*decryptor_, InitializeVideoDecoder(_, _))
101 .WillOnce(RunCallback<1>(true)); 102 .WillOnce(RunCallback<1>(true));
102 EXPECT_CALL(*decryptor_, RegisterNewKeyCB(Decryptor::kVideo, _)) 103 EXPECT_CALL(*decryptor_, RegisterNewKeyCB(Decryptor::kVideo, _))
103 .WillOnce(SaveArg<1>(&key_added_cb_)); 104 .WillOnce(SaveArg<1>(&key_added_cb_));
104 105
(...skipping 11 matching lines...) Expand all
116 InitializeAndExpectResult(TestVideoConfig::LargeEncrypted(), true); 117 InitializeAndExpectResult(TestVideoConfig::LargeEncrypted(), true);
117 } 118 }
118 119
119 // Decode |buffer| and expect DecodeDone to get called with |status|. 120 // Decode |buffer| and expect DecodeDone to get called with |status|.
120 void DecodeAndExpect(const scoped_refptr<DecoderBuffer>& buffer, 121 void DecodeAndExpect(const scoped_refptr<DecoderBuffer>& buffer,
121 DecodeStatus status) { 122 DecodeStatus status) {
122 EXPECT_CALL(*this, DecodeDone(status)); 123 EXPECT_CALL(*this, DecodeDone(status));
123 decoder_->Decode(buffer, 124 decoder_->Decode(buffer,
124 base::Bind(&DecryptingVideoDecoderTest::DecodeDone, 125 base::Bind(&DecryptingVideoDecoderTest::DecodeDone,
125 base::Unretained(this))); 126 base::Unretained(this)));
126 message_loop_.RunUntilIdle(); 127 base::RunLoop().RunUntilIdle();
127 } 128 }
128 129
129 // Helper function to simulate the decrypting and decoding process in the 130 // Helper function to simulate the decrypting and decoding process in the
130 // |decryptor_| with a decoding delay of kDecodingDelay buffers. 131 // |decryptor_| with a decoding delay of kDecodingDelay buffers.
131 void DecryptAndDecodeVideo(const scoped_refptr<DecoderBuffer>& encrypted, 132 void DecryptAndDecodeVideo(const scoped_refptr<DecoderBuffer>& encrypted,
132 const Decryptor::VideoDecodeCB& video_decode_cb) { 133 const Decryptor::VideoDecodeCB& video_decode_cb) {
133 num_decrypt_and_decode_calls_++; 134 num_decrypt_and_decode_calls_++;
134 if (!encrypted->end_of_stream()) 135 if (!encrypted->end_of_stream())
135 num_frames_in_decryptor_++; 136 num_frames_in_decryptor_++;
136 137
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
168 169
169 // Make the video decode callback pending by saving and not firing it. 170 // Make the video decode callback pending by saving and not firing it.
170 void EnterPendingDecodeState() { 171 void EnterPendingDecodeState() {
171 EXPECT_TRUE(pending_video_decode_cb_.is_null()); 172 EXPECT_TRUE(pending_video_decode_cb_.is_null());
172 EXPECT_CALL(*decryptor_, DecryptAndDecodeVideo(encrypted_buffer_, _)) 173 EXPECT_CALL(*decryptor_, DecryptAndDecodeVideo(encrypted_buffer_, _))
173 .WillOnce(SaveArg<1>(&pending_video_decode_cb_)); 174 .WillOnce(SaveArg<1>(&pending_video_decode_cb_));
174 175
175 decoder_->Decode(encrypted_buffer_, 176 decoder_->Decode(encrypted_buffer_,
176 base::Bind(&DecryptingVideoDecoderTest::DecodeDone, 177 base::Bind(&DecryptingVideoDecoderTest::DecodeDone,
177 base::Unretained(this))); 178 base::Unretained(this)));
178 message_loop_.RunUntilIdle(); 179 base::RunLoop().RunUntilIdle();
179 // Make sure the Decode() on the decoder triggers a DecryptAndDecode() on 180 // Make sure the Decode() on the decoder triggers a DecryptAndDecode() on
180 // the decryptor. 181 // the decryptor.
181 EXPECT_FALSE(pending_video_decode_cb_.is_null()); 182 EXPECT_FALSE(pending_video_decode_cb_.is_null());
182 } 183 }
183 184
184 void EnterWaitingForKeyState() { 185 void EnterWaitingForKeyState() {
185 EXPECT_CALL(*decryptor_, DecryptAndDecodeVideo(_, _)) 186 EXPECT_CALL(*decryptor_, DecryptAndDecodeVideo(_, _))
186 .WillRepeatedly(RunCallback<1>(Decryptor::kNoKey, null_video_frame_)); 187 .WillRepeatedly(RunCallback<1>(Decryptor::kNoKey, null_video_frame_));
187 EXPECT_CALL(*this, OnWaitingForDecryptionKey()); 188 EXPECT_CALL(*this, OnWaitingForDecryptionKey());
188 decoder_->Decode(encrypted_buffer_, 189 decoder_->Decode(encrypted_buffer_,
189 base::Bind(&DecryptingVideoDecoderTest::DecodeDone, 190 base::Bind(&DecryptingVideoDecoderTest::DecodeDone,
190 base::Unretained(this))); 191 base::Unretained(this)));
191 message_loop_.RunUntilIdle(); 192 base::RunLoop().RunUntilIdle();
192 } 193 }
193 194
194 void AbortPendingVideoDecodeCB() { 195 void AbortPendingVideoDecodeCB() {
195 if (!pending_video_decode_cb_.is_null()) { 196 if (!pending_video_decode_cb_.is_null()) {
196 base::ResetAndReturn(&pending_video_decode_cb_).Run( 197 base::ResetAndReturn(&pending_video_decode_cb_).Run(
197 Decryptor::kSuccess, scoped_refptr<VideoFrame>(NULL)); 198 Decryptor::kSuccess, scoped_refptr<VideoFrame>(NULL));
198 } 199 }
199 } 200 }
200 201
201 void AbortAllPendingCBs() { 202 void AbortAllPendingCBs() {
202 if (!pending_init_cb_.is_null()) { 203 if (!pending_init_cb_.is_null()) {
203 ASSERT_TRUE(pending_video_decode_cb_.is_null()); 204 ASSERT_TRUE(pending_video_decode_cb_.is_null());
204 base::ResetAndReturn(&pending_init_cb_).Run(false); 205 base::ResetAndReturn(&pending_init_cb_).Run(false);
205 return; 206 return;
206 } 207 }
207 208
208 AbortPendingVideoDecodeCB(); 209 AbortPendingVideoDecodeCB();
209 } 210 }
210 211
211 void Reset() { 212 void Reset() {
212 EXPECT_CALL(*decryptor_, ResetDecoder(Decryptor::kVideo)) 213 EXPECT_CALL(*decryptor_, ResetDecoder(Decryptor::kVideo))
213 .WillRepeatedly(InvokeWithoutArgs( 214 .WillRepeatedly(InvokeWithoutArgs(
214 this, &DecryptingVideoDecoderTest::AbortPendingVideoDecodeCB)); 215 this, &DecryptingVideoDecoderTest::AbortPendingVideoDecodeCB));
215 216
216 decoder_->Reset(NewExpectedClosure()); 217 decoder_->Reset(NewExpectedClosure());
217 message_loop_.RunUntilIdle(); 218 base::RunLoop().RunUntilIdle();
218 } 219 }
219 220
220 void Destroy() { 221 void Destroy() {
221 EXPECT_CALL(*decryptor_, DeinitializeDecoder(Decryptor::kVideo)) 222 EXPECT_CALL(*decryptor_, DeinitializeDecoder(Decryptor::kVideo))
222 .WillRepeatedly(InvokeWithoutArgs( 223 .WillRepeatedly(InvokeWithoutArgs(
223 this, &DecryptingVideoDecoderTest::AbortAllPendingCBs)); 224 this, &DecryptingVideoDecoderTest::AbortAllPendingCBs));
224 225
225 decoder_.reset(); 226 decoder_.reset();
226 message_loop_.RunUntilIdle(); 227 base::RunLoop().RunUntilIdle();
227 } 228 }
228 229
229 MOCK_METHOD1(FrameReady, void(const scoped_refptr<VideoFrame>&)); 230 MOCK_METHOD1(FrameReady, void(const scoped_refptr<VideoFrame>&));
230 MOCK_METHOD1(DecodeDone, void(DecodeStatus)); 231 MOCK_METHOD1(DecodeDone, void(DecodeStatus));
231 232
232 MOCK_METHOD0(OnWaitingForDecryptionKey, void(void)); 233 MOCK_METHOD0(OnWaitingForDecryptionKey, void(void));
233 234
234 base::MessageLoop message_loop_; 235 base::MessageLoop message_loop_;
235 std::unique_ptr<DecryptingVideoDecoder> decoder_; 236 std::unique_ptr<DecryptingVideoDecoder> decoder_;
236 std::unique_ptr<StrictMock<MockCdmContext>> cdm_context_; 237 std::unique_ptr<StrictMock<MockCdmContext>> cdm_context_;
(...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after
324 TEST_F(DecryptingVideoDecoderTest, KeyAdded_DuringWaitingForKey) { 325 TEST_F(DecryptingVideoDecoderTest, KeyAdded_DuringWaitingForKey) {
325 Initialize(); 326 Initialize();
326 EnterWaitingForKeyState(); 327 EnterWaitingForKeyState();
327 328
328 EXPECT_CALL(*decryptor_, DecryptAndDecodeVideo(_, _)) 329 EXPECT_CALL(*decryptor_, DecryptAndDecodeVideo(_, _))
329 .WillRepeatedly(RunCallback<1>(Decryptor::kSuccess, 330 .WillRepeatedly(RunCallback<1>(Decryptor::kSuccess,
330 decoded_video_frame_)); 331 decoded_video_frame_));
331 EXPECT_CALL(*this, FrameReady(decoded_video_frame_)); 332 EXPECT_CALL(*this, FrameReady(decoded_video_frame_));
332 EXPECT_CALL(*this, DecodeDone(DecodeStatus::OK)); 333 EXPECT_CALL(*this, DecodeDone(DecodeStatus::OK));
333 key_added_cb_.Run(); 334 key_added_cb_.Run();
334 message_loop_.RunUntilIdle(); 335 base::RunLoop().RunUntilIdle();
335 } 336 }
336 337
337 // Test the case where the a key is added when the decryptor is in 338 // Test the case where the a key is added when the decryptor is in
338 // kPendingDecode state. 339 // kPendingDecode state.
339 TEST_F(DecryptingVideoDecoderTest, KeyAdded_DuringPendingDecode) { 340 TEST_F(DecryptingVideoDecoderTest, KeyAdded_DuringPendingDecode) {
340 Initialize(); 341 Initialize();
341 EnterPendingDecodeState(); 342 EnterPendingDecodeState();
342 343
343 EXPECT_CALL(*decryptor_, DecryptAndDecodeVideo(_, _)) 344 EXPECT_CALL(*decryptor_, DecryptAndDecodeVideo(_, _))
344 .WillRepeatedly(RunCallback<1>(Decryptor::kSuccess, 345 .WillRepeatedly(RunCallback<1>(Decryptor::kSuccess,
345 decoded_video_frame_)); 346 decoded_video_frame_));
346 EXPECT_CALL(*this, FrameReady(decoded_video_frame_)); 347 EXPECT_CALL(*this, FrameReady(decoded_video_frame_));
347 EXPECT_CALL(*this, DecodeDone(DecodeStatus::OK)); 348 EXPECT_CALL(*this, DecodeDone(DecodeStatus::OK));
348 // The video decode callback is returned after the correct decryption key is 349 // The video decode callback is returned after the correct decryption key is
349 // added. 350 // added.
350 key_added_cb_.Run(); 351 key_added_cb_.Run();
351 base::ResetAndReturn(&pending_video_decode_cb_).Run(Decryptor::kNoKey, 352 base::ResetAndReturn(&pending_video_decode_cb_).Run(Decryptor::kNoKey,
352 null_video_frame_); 353 null_video_frame_);
353 message_loop_.RunUntilIdle(); 354 base::RunLoop().RunUntilIdle();
354 } 355 }
355 356
356 // Test resetting when the decoder is in kIdle state but has not decoded any 357 // Test resetting when the decoder is in kIdle state but has not decoded any
357 // frame. 358 // frame.
358 TEST_F(DecryptingVideoDecoderTest, Reset_DuringIdleAfterInitialization) { 359 TEST_F(DecryptingVideoDecoderTest, Reset_DuringIdleAfterInitialization) {
359 Initialize(); 360 Initialize();
360 Reset(); 361 Reset();
361 } 362 }
362 363
363 // Test resetting when the decoder is in kIdle state after it has decoded one 364 // Test resetting when the decoder is in kIdle state after it has decoded one
(...skipping 113 matching lines...) Expand 10 before | Expand all | Expand 10 after
477 478
478 // Test destruction after the decoder has been reset. 479 // Test destruction after the decoder has been reset.
479 TEST_F(DecryptingVideoDecoderTest, Destroy_AfterReset) { 480 TEST_F(DecryptingVideoDecoderTest, Destroy_AfterReset) {
480 Initialize(); 481 Initialize();
481 EnterNormalDecodingState(); 482 EnterNormalDecodingState();
482 Reset(); 483 Reset();
483 Destroy(); 484 Destroy();
484 } 485 }
485 486
486 } // namespace media 487 } // namespace media
OLDNEW
« no previous file with comments | « media/filters/decrypting_demuxer_stream_unittest.cc ('k') | media/filters/fake_video_decoder_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698