[go: nahoru, domu]

Allow setContentDecryptionModule() to get called when setting is done.

Decoders can register to get notified when a Decryptor is set.
setContentDecryptionModule() provides a new Decryptor to
WebMediaPlayer. Since the decoders run on the media thread, it may
take some time for the old Decryptor to get detached and a new one
connected. Adding a callback to be used so that
setContentDecryptionModule() knows when the Decoders are done with
the notification. The additional callback is optional. This will be
used to resolve the setMediaKeys() promise on the blink side.

BUG=358271
TEST=media unittests and EME layout tests pass

Review URL: https://codereview.chromium.org/416333011

Cr-Commit-Position: refs/heads/master@{#289197}
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@289197 0039d316-1c4b-4281-b951-d872f2087c98
diff --git a/media/filters/decrypting_audio_decoder_unittest.cc b/media/filters/decrypting_audio_decoder_unittest.cc
index 83d7f5f..f6acc1b 100644
--- a/media/filters/decrypting_audio_decoder_unittest.cc
+++ b/media/filters/decrypting_audio_decoder_unittest.cc
@@ -54,11 +54,6 @@
   return buffer;
 }
 
-ACTION_P(RunCallbackIfNotNull, param) {
-  if (!arg0.is_null())
-    arg0.Run(param);
-}
-
 }  // namespace
 
 class DecryptingAudioDecoderTest : public testing::Test {
@@ -103,12 +98,19 @@
     message_loop_.RunUntilIdle();
   }
 
+  void ExpectDecryptorNotification(Decryptor* decryptor, bool expected_result) {
+    EXPECT_CALL(*this, RequestDecryptorNotification(_)).WillOnce(
+        RunCallback<0>(decryptor,
+                       base::Bind(&DecryptingAudioDecoderTest::DecryptorSet,
+                                  base::Unretained(this))));
+    EXPECT_CALL(*this, DecryptorSet(expected_result));
+  }
+
   void Initialize() {
     EXPECT_CALL(*decryptor_, InitializeAudioDecoder(_, _))
         .Times(AtMost(1))
         .WillOnce(RunCallback<1>(true));
-    EXPECT_CALL(*this, RequestDecryptorNotification(_))
-        .WillOnce(RunCallbackIfNotNull(decryptor_.get()));
+    ExpectDecryptorNotification(decryptor_.get(), true);
     EXPECT_CALL(*decryptor_, RegisterNewKeyCB(Decryptor::kAudio, _))
         .WillOnce(SaveArg<1>(&key_added_cb_));
 
@@ -248,6 +250,8 @@
   MOCK_METHOD1(FrameReady, void(const scoped_refptr<AudioBuffer>&));
   MOCK_METHOD1(DecodeDone, void(AudioDecoder::Status));
 
+  MOCK_METHOD1(DecryptorSet, void(bool));
+
   base::MessageLoop message_loop_;
   scoped_ptr<DecryptingAudioDecoder> decoder_;
   scoped_ptr<StrictMock<MockDecryptor> > decryptor_;
@@ -294,8 +298,7 @@
 TEST_F(DecryptingAudioDecoderTest, Initialize_UnsupportedAudioConfig) {
   EXPECT_CALL(*decryptor_, InitializeAudioDecoder(_, _))
       .WillOnce(RunCallback<1>(false));
-  EXPECT_CALL(*this, RequestDecryptorNotification(_))
-      .WillOnce(RunCallbackIfNotNull(decryptor_.get()));
+  ExpectDecryptorNotification(decryptor_.get(), true);
 
   AudioDecoderConfig config(kCodecVorbis, kSampleFormatPlanarF32,
                             CHANNEL_LAYOUT_STEREO, kSampleRate, NULL, 0, true);
@@ -303,9 +306,7 @@
 }
 
 TEST_F(DecryptingAudioDecoderTest, Initialize_NullDecryptor) {
-  EXPECT_CALL(*this, RequestDecryptorNotification(_))
-      .WillRepeatedly(RunCallbackIfNotNull(static_cast<Decryptor*>(NULL)));
-
+  ExpectDecryptorNotification(NULL, false);
   AudioDecoderConfig config(kCodecVorbis, kSampleFormatPlanarF32,
                             CHANNEL_LAYOUT_STEREO, kSampleRate, NULL, 0, true);
   InitializeAndExpectStatus(config, DECODER_ERROR_NOT_SUPPORTED);