Upload upstream chromium 108.0.5359.1
[platform/framework/web/chromium-efl.git] / media / filters / decrypting_audio_decoder_unittest.cc
index b2836c3..190007e 100644 (file)
@@ -1,7 +1,9 @@
-// Copyright (c) 2012 The Chromium Authors. All rights reserved.
+// Copyright 2012 The Chromium Authors
 // Use of this source code is governed by a BSD-style license that can be
 // found in the LICENSE file.
 
+#include "media/filters/decrypting_audio_decoder.h"
+
 #include <stdint.h>
 
 #include <string>
@@ -9,7 +11,6 @@
 
 #include "base/bind.h"
 #include "base/callback_helpers.h"
-#include "base/cxx17_backports.h"
 #include "base/run_loop.h"
 #include "base/test/gmock_callback_support.h"
 #include "base/test/gmock_move_support.h"
@@ -21,7 +22,6 @@
 #include "media/base/mock_filters.h"
 #include "media/base/test_helpers.h"
 #include "media/base/timestamp_constants.h"
-#include "media/filters/decrypting_audio_decoder.h"
 #include "testing/gmock/include/gmock/gmock.h"
 
 using ::base::test::RunOnceCallback;
@@ -47,8 +47,8 @@ static scoped_refptr<DecoderBuffer> CreateFakeEncryptedBuffer() {
   scoped_refptr<DecoderBuffer> buffer(new DecoderBuffer(buffer_size));
   buffer->set_decrypt_config(DecryptConfig::CreateCencConfig(
       std::string(reinterpret_cast<const char*>(kFakeKeyId),
-                  base::size(kFakeKeyId)),
-      std::string(reinterpret_cast<const char*>(kFakeIv), base::size(kFakeIv)),
+                  std::size(kFakeKeyId)),
+      std::string(reinterpret_cast<const char*>(kFakeIv), std::size(kFakeIv)),
       std::vector<SubsampleEntry>()));
   return buffer;
 }
@@ -67,6 +67,10 @@ class DecryptingAudioDecoderTest : public testing::Test {
         decoded_frame_(nullptr),
         decoded_frame_list_() {}
 
+  DecryptingAudioDecoderTest(const DecryptingAudioDecoderTest&) = delete;
+  DecryptingAudioDecoderTest& operator=(const DecryptingAudioDecoderTest&) =
+      delete;
+
   ~DecryptingAudioDecoderTest() override { Destroy(); }
 
   void InitializeAndExpectResult(const AudioDecoderConfig& config,
@@ -85,7 +89,7 @@ class DecryptingAudioDecoderTest : public testing::Test {
     decoder_->Initialize(
         config, cdm_context_.get(),
         base::BindOnce(
-            [](bool success, Status status) {
+            [](bool success, DecoderStatus status) {
               EXPECT_EQ(status.is_ok(), success);
             },
             success),
@@ -114,7 +118,7 @@ class DecryptingAudioDecoderTest : public testing::Test {
       return std::make_unique<CallbackRegistration>();
     });
 
-    config_.Initialize(kCodecVorbis, kSampleFormatPlanarF32,
+    config_.Initialize(AudioCodec::kVorbis, kSampleFormatPlanarF32,
                        CHANNEL_LAYOUT_STEREO, kSampleRate, EmptyExtraData(),
                        EncryptionScheme::kCenc, base::TimeDelta(), 0);
     InitializeAndExpectResult(config_, true);
@@ -128,7 +132,8 @@ class DecryptingAudioDecoderTest : public testing::Test {
         .WillOnce(RunOnceCallback<1>(true));
     decoder_->Initialize(
         new_config, cdm_context_.get(),
-        base::BindOnce([](Status status) { EXPECT_TRUE(status.is_ok()); }),
+        base::BindOnce(
+            [](DecoderStatus status) { EXPECT_TRUE(status.is_ok()); }),
         base::BindRepeating(&DecryptingAudioDecoderTest::FrameReady,
                             base::Unretained(this)),
         base::BindRepeating(&DecryptingAudioDecoderTest::OnWaiting,
@@ -136,7 +141,8 @@ class DecryptingAudioDecoderTest : public testing::Test {
   }
 
   // Decode |buffer| and expect DecodeDone to get called with |status|.
-  void DecodeAndExpect(scoped_refptr<DecoderBuffer> buffer, StatusCode status) {
+  void DecodeAndExpect(scoped_refptr<DecoderBuffer> buffer,
+                       DecoderStatus status) {
     EXPECT_CALL(*this, DecodeDone(HasStatusCode(status)));
     decoder_->Decode(buffer,
                      base::BindOnce(&DecryptingAudioDecoderTest::DecodeDone,
@@ -172,7 +178,7 @@ class DecryptingAudioDecoderTest : public testing::Test {
             Invoke(this, &DecryptingAudioDecoderTest::DecryptAndDecodeAudio));
     EXPECT_CALL(*this, FrameReady(decoded_frame_));
     for (int i = 0; i < kDecodingDelay + 1; ++i)
-      DecodeAndExpect(encrypted_buffer_, DecodeStatus::OK);
+      DecodeAndExpect(encrypted_buffer_, DecoderStatus::Codes::kOk);
   }
 
   // Sets up expectations and actions to put DecryptingAudioDecoder in an end
@@ -181,7 +187,8 @@ class DecryptingAudioDecoderTest : public testing::Test {
   void EnterEndOfStreamState() {
     // The codec in the |decryptor_| will be flushed.
     EXPECT_CALL(*this, FrameReady(decoded_frame_)).Times(kDecodingDelay);
-    DecodeAndExpect(DecoderBuffer::CreateEOSBuffer(), DecodeStatus::OK);
+    DecodeAndExpect(DecoderBuffer::CreateEOSBuffer(),
+                    DecoderStatus::Codes::kOk);
     EXPECT_EQ(0, num_frames_in_decryptor_);
   }
 
@@ -248,7 +255,7 @@ class DecryptingAudioDecoderTest : public testing::Test {
   }
 
   MOCK_METHOD1(FrameReady, void(scoped_refptr<AudioBuffer>));
-  MOCK_METHOD1(DecodeDone, void(Status));
+  MOCK_METHOD1(DecodeDone, void(DecoderStatus));
 
   MOCK_METHOD1(OnWaiting, void(WaitingReason));
 
@@ -271,9 +278,6 @@ class DecryptingAudioDecoderTest : public testing::Test {
   scoped_refptr<DecoderBuffer> encrypted_buffer_;
   scoped_refptr<AudioBuffer> decoded_frame_;
   Decryptor::AudioFrames decoded_frame_list_;
-
- private:
-  DISALLOW_COPY_AND_ASSIGN(DecryptingAudioDecoderTest);
 };
 
 TEST_F(DecryptingAudioDecoderTest, Initialize_Normal) {
@@ -282,7 +286,7 @@ TEST_F(DecryptingAudioDecoderTest, Initialize_Normal) {
 
 // Ensure decoder handles invalid audio configs without crashing.
 TEST_F(DecryptingAudioDecoderTest, Initialize_InvalidAudioConfig) {
-  AudioDecoderConfig config(kUnknownAudioCodec, kUnknownSampleFormat,
+  AudioDecoderConfig config(AudioCodec::kUnknown, kUnknownSampleFormat,
                             CHANNEL_LAYOUT_STEREO, 0, EmptyExtraData(),
                             EncryptionScheme::kCenc);
 
@@ -299,7 +303,7 @@ TEST_F(DecryptingAudioDecoderTest, Initialize_UnsupportedAudioConfig) {
   EXPECT_CALL(*decryptor_, InitializeAudioDecoder(_, _))
       .WillOnce(RunOnceCallback<1>(false));
 
-  AudioDecoderConfig config(kCodecVorbis, kSampleFormatPlanarF32,
+  AudioDecoderConfig config(AudioCodec::kVorbis, kSampleFormatPlanarF32,
                             CHANNEL_LAYOUT_STEREO, kSampleRate,
                             EmptyExtraData(), EncryptionScheme::kCenc);
   InitializeAndExpectResult(config, false);
@@ -307,7 +311,7 @@ TEST_F(DecryptingAudioDecoderTest, Initialize_UnsupportedAudioConfig) {
 
 TEST_F(DecryptingAudioDecoderTest, Initialize_CdmWithoutDecryptor) {
   SetCdmType(CDM_WITHOUT_DECRYPTOR);
-  AudioDecoderConfig config(kCodecVorbis, kSampleFormatPlanarF32,
+  AudioDecoderConfig config(AudioCodec::kVorbis, kSampleFormatPlanarF32,
                             CHANNEL_LAYOUT_STEREO, kSampleRate,
                             EmptyExtraData(), EncryptionScheme::kCenc);
   InitializeAndExpectResult(config, false);
@@ -328,7 +332,7 @@ TEST_F(DecryptingAudioDecoderTest, DecryptAndDecode_DecodeError) {
       .WillRepeatedly(
           RunOnceCallback<1>(Decryptor::kError, Decryptor::AudioFrames()));
 
-  DecodeAndExpect(encrypted_buffer_, DecodeStatus::DECODE_ERROR);
+  DecodeAndExpect(encrypted_buffer_, DecoderStatus::Codes::kFailed);
 }
 
 // Test the case where the decryptor returns multiple decoded frames.
@@ -352,7 +356,7 @@ TEST_F(DecryptingAudioDecoderTest, DecryptAndDecode_MultipleFrames) {
   EXPECT_CALL(*this, FrameReady(decoded_frame_));
   EXPECT_CALL(*this, FrameReady(frame_a));
   EXPECT_CALL(*this, FrameReady(frame_b));
-  DecodeAndExpect(encrypted_buffer_, DecodeStatus::OK);
+  DecodeAndExpect(encrypted_buffer_, DecoderStatus::Codes::kOk);
 }
 
 // Test the case where the decryptor receives end-of-stream buffer.
@@ -372,7 +376,7 @@ TEST_F(DecryptingAudioDecoderTest, Reinitialize_EncryptedToEncrypted) {
 
   // The new config is different from the initial config in bits-per-channel,
   // channel layout and samples_per_second.
-  AudioDecoderConfig new_config(kCodecVorbis, kSampleFormatPlanarS16,
+  AudioDecoderConfig new_config(AudioCodec::kVorbis, kSampleFormatPlanarS16,
                                 CHANNEL_LAYOUT_5_1, 88200, EmptyExtraData(),
                                 EncryptionScheme::kCenc);
   EXPECT_NE(new_config.bits_per_channel(), config_.bits_per_channel());
@@ -394,7 +398,7 @@ TEST_F(DecryptingAudioDecoderTest, Reinitialize_EncryptedToClear) {
 
   // The new config is different from the initial config in bits-per-channel,
   // channel layout and samples_per_second.
-  AudioDecoderConfig new_config(kCodecVorbis, kSampleFormatPlanarS16,
+  AudioDecoderConfig new_config(AudioCodec::kVorbis, kSampleFormatPlanarS16,
                                 CHANNEL_LAYOUT_5_1, 88200, EmptyExtraData(),
                                 EncryptionScheme::kUnencrypted);
   EXPECT_NE(new_config.bits_per_channel(), config_.bits_per_channel());
@@ -460,7 +464,7 @@ TEST_F(DecryptingAudioDecoderTest, Reset_DuringPendingDecode) {
   Initialize();
   EnterPendingDecodeState();
 
-  EXPECT_CALL(*this, DecodeDone(HasStatusCode(StatusCode::kAborted)));
+  EXPECT_CALL(*this, DecodeDone(HasStatusCode(DecoderStatus::Codes::kAborted)));
 
   Reset();
 }
@@ -470,7 +474,7 @@ TEST_F(DecryptingAudioDecoderTest, Reset_DuringWaitingForKey) {
   Initialize();
   EnterWaitingForKeyState();
 
-  EXPECT_CALL(*this, DecodeDone(HasStatusCode(StatusCode::kAborted)));
+  EXPECT_CALL(*this, DecodeDone(HasStatusCode(DecoderStatus::Codes::kAborted)));
 
   Reset();
 }