chromium/content/browser/media/cdm_registry_impl_unittest.cc

// Copyright 2016 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#ifdef UNSAFE_BUFFERS_BUILD
// TODO(crbug.com/342213636): Remove this and spanify to fix the errors.
#pragma allow_unsafe_buffers
#endif

#include "content/browser/media/cdm_registry_impl.h"

#include <algorithm>
#include <string>
#include <vector>

#include "base/base_paths.h"
#include "base/command_line.h"
#include "base/containers/contains.h"
#include "base/containers/flat_set.h"
#include "base/files/file_path.h"
#include "base/functional/callback_helpers.h"
#include "base/strings/string_split.h"
#include "base/strings/string_util.h"
#include "base/strings/utf_string_conversions.h"
#include "base/test/gmock_callback_support.h"
#include "base/test/gmock_move_support.h"
#include "base/test/mock_callback.h"
#include "base/test/scoped_feature_list.h"
#include "base/version.h"
#include "build/chromeos_buildflags.h"
#include "content/browser/gpu/gpu_data_manager_impl.h"
#include "content/public/common/cdm_info.h"
#include "content/public/test/browser_task_environment.h"
#include "gpu/config/gpu_feature_info.h"
#include "media/base/cdm_capability.h"
#include "media/base/media_switches.h"
#include "media/base/video_codecs.h"
#include "media/cdm/cdm_type.h"
#include "testing/gmock/include/gmock/gmock.h"
#include "testing/gtest/include/gtest/gtest.h"

namespace content {

namespace {

AudioCodec;
VideoCodec;
EncryptionScheme;
CdmSessionType;
Robustness;
RunOnceCallback;
_;

const char kTestCdmName[] =;
const char kAlternateCdmName[] =;
const media::CdmType kTestCdmType{};
const char kTestPath[] =;
const char kVersion1[] =;
const char kVersion2[] =;
const char kTestKeySystem[] =;
const char kOtherKeySystem[] =;
const int kObserver1 =;
const int kObserver2 =;

#if BUILDFLAG(IS_WIN)
// 0x1234 is randomly picked as a non-software emulated vendor ID.
constexpr uint32_t kNonSoftwareEmulatedVendorId = 0x1234;
// 0x0000 is one of the software emulated vendor IDs.
constexpr uint32_t kSoftwareEmulatedVendorId = 0x0000;
#endif  // BUILDFLAG(IS_WIN)

// Helper function to convert a VideoCodecMap to a list of VideoCodec values
// so that they can be compared. VideoCodecProfiles are ignored.
std::vector<media::VideoCodec> VideoCodecMapToList(
    const media::CdmCapability::VideoCodecMap& map) {}

#define EXPECT_STL_EQ(container, ...)

#define EXPECT_AUDIO_CODECS(...)

#define EXPECT_VIDEO_CODECS(...)

#define EXPECT_ENCRYPTION_SCHEMES(...)

#define EXPECT_SESSION_TYPES(...)

}  // namespace

// TODO(crbug.com/347991515): Add browser tests to test protected content id
// settings.
// For simplicity and to make failures easier to diagnose, this test uses
// std::string instead of base::FilePath and std::vector<std::string>.
class CdmRegistryImplTest : public testing::Test {};

TEST_F(CdmRegistryImplTest, Register) {}

TEST_F(CdmRegistryImplTest, ReRegister) {}

TEST_F(CdmRegistryImplTest, MultipleVersions) {}

TEST_F(CdmRegistryImplTest, NewVersionInsertedLast) {}

TEST_F(CdmRegistryImplTest, DifferentNames) {}

TEST_F(CdmRegistryImplTest, Profiles) {}

TEST_F(CdmRegistryImplTest, SupportedEncryptionSchemes) {}

TEST_F(CdmRegistryImplTest, GetCdmInfo_Success) {}

TEST_F(CdmRegistryImplTest, GetCdmInfo_Fail) {}

TEST_F(CdmRegistryImplTest, KeySystemCapabilities_SoftwareSecure) {}

TEST_F(CdmRegistryImplTest, KeySystemCapabilities_HardwareSecure) {}

TEST_F(CdmRegistryImplTest,
       KeySystemCapabilities_LazySoftwareSecureInitialize_Supported) {}

TEST_F(CdmRegistryImplTest,
       KeySystemCapabilities_LazyHardwareSecureInitialize_Supported) {}

TEST_F(CdmRegistryImplTest,
       KeySystemCapabilities_LazySoftwareSecureInitialize_NotSupported) {}

TEST_F(CdmRegistryImplTest,
       KeySystemCapabilities_LazyHardwareSecureInitialize_NotSupported) {}

TEST_F(CdmRegistryImplTest, KeySystemCapabilities_HardwareSecureDisabled) {}

TEST_F(CdmRegistryImplTest, KeySystemCapabilities_SoftwareAndHardwareSecure) {}

TEST_F(CdmRegistryImplTest, KeySystemCapabilities_MultipleObservers) {}

TEST_F(
    CdmRegistryImplTest,
    KeySystemCapabilities_MultipleObservers_PendingLazySoftwareSecureInitialize) {}

TEST_F(
    CdmRegistryImplTest,
    KeySystemCapabilities_MultipleObservers_PendingLazyHardwareSecureInitialize) {}

TEST_F(
    CdmRegistryImplTest,
    KeySystemCapabilities_MultipleObservers_AfterLazyHardwareSecureInitialize) {}

TEST_F(CdmRegistryImplTest, KeySystemCapabilities_RegisterCdmAfterObserving) {}

TEST_F(CdmRegistryImplTest,
       KeySystemCapabilities_RegisterCdmPendingLazyInitialize) {}

TEST_F(CdmRegistryImplTest, KeySystemCapabilities_DisableHardwareSecureCdms) {}

#if BUILDFLAG(IS_WIN)
TEST_F(CdmRegistryImplTest, KeySystemCapabilities_DirectCompositionDisabled) {
  // Simulate disabling direct composition.
  gpu::GPUInfo gpu_info;
  gpu_info.overlay_info.direct_composition = false;
  GpuDataManagerImpl::GetInstance()->UpdateGpuInfo(gpu_info, std::nullopt);

  RegisterForLazyHardwareSecureInitialization();
  SelectHardwareSecureDecryption(true);
  GetKeySystemCapabilities();

  ASSERT_TRUE(results_.count(kObserver1));
  ASSERT_EQ(results_[kObserver1].size(), 1u);
  auto& key_system_capabilities = results_[kObserver1][0];
  ASSERT_TRUE(key_system_capabilities.empty());

  auto cdm_info = cdm_registry_.GetCdmInfo(
      kTestKeySystem, CdmInfo::Robustness::kHardwareSecure);
  ASSERT_EQ(cdm_info->status, CdmInfo::Status::kGpuCompositionDisabled);
  ASSERT_FALSE(cdm_info->capability);
}

TEST_F(CdmRegistryImplTest,
       KeySystemCapabilities_DisabledBySoftwareEmulatedGpu) {
  // Simulate enabling direct composition and software emulated GPU.
  gpu::GPUInfo gpu_info;
  gpu_info.overlay_info.direct_composition = true;
  gpu_info.gpu.vendor_id = kSoftwareEmulatedVendorId;
  GpuDataManagerImpl::GetInstance()->UpdateGpuInfo(gpu_info, std::nullopt);

  RegisterForLazyHardwareSecureInitialization();
  SelectHardwareSecureDecryption(true);
  GetKeySystemCapabilities();

  ASSERT_TRUE(results_.count(kObserver1));
  ASSERT_EQ(results_[kObserver1].size(), 1u);
  auto& key_system_capabilities = results_[kObserver1][0];
  ASSERT_TRUE(key_system_capabilities.empty());

  auto cdm_info = cdm_registry_.GetCdmInfo(
      kTestKeySystem, CdmInfo::Robustness::kHardwareSecure);
  ASSERT_EQ(cdm_info->status, CdmInfo::Status::kDisabledBySoftwareEmulatedGpu);
  ASSERT_FALSE(cdm_info->capability);
}
#endif  // BUILDFLAG(IS_WIN)

TEST_F(CdmRegistryImplTest,
       KeySystemCapabilities_HwCapabilityNotAllowedToAllowed) {}

TEST_F(CdmRegistryImplTest,
       KeySystemCapabilities_HwCapabilityAllowedToNotAllowed) {}

TEST_F(CdmRegistryImplTest,
       KeySystemCapabilities_HwCapabilityTwoObserverNotAllowedAndAllowed) {}

TEST_F(
    CdmRegistryImplTest,
    KeySystemCapabilities_MultipleObservers_NotAllowedAndAllowedHwCapabilityCheck) {}

TEST_F(CdmRegistryImplTest, KeySystemCapabilities_NoOverride) {}

}  // namespace content