chromium/media/cdm/cdm_adapter_unittest.cc

// Copyright 2015 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/40285824): Remove this and convert code to safer constructs.
#pragma allow_unsafe_buffers
#endif

#include "media/cdm/cdm_adapter.h"

#include <stdint.h>

#include <memory>

#include "base/check.h"
#include "base/command_line.h"
#include "base/functional/bind.h"
#include "base/memory/raw_ptr.h"
#include "base/run_loop.h"
#include "base/strings/string_number_conversions.h"
#include "base/test/task_environment.h"
#include "media/base/cdm_callback_promise.h"
#include "media/base/cdm_factory.h"
#include "media/base/cdm_key_information.h"
#include "media/base/content_decryption_module.h"
#include "media/base/media_switches.h"
#include "media/base/mock_filters.h"
#include "media/cdm/api/content_decryption_module.h"
#include "media/cdm/cdm_module.h"
#include "media/cdm/external_clear_key_test_helper.h"
#include "media/cdm/library_cdm/cdm_host_proxy.h"
#include "media/cdm/library_cdm/mock_library_cdm.h"
#include "media/cdm/mock_helpers.h"
#include "media/cdm/simple_cdm_allocator.h"
#include "media/media_buildflags.h"
#include "testing/gmock/include/gmock/gmock.h"
#include "testing/gtest/include/gtest/gtest.h"

Invoke;
IsNull;
NotNull;
Return;
Values;
SaveArg;
StrictMock;
_;

MATCHER(IsNotEmpty, "") {}

MATCHER(IsNullTime, "") {}

MATCHER(IsNullPlatformChallengeResponse, "") {}

// TODO(jrummell): These tests are a subset of those in aes_decryptor_unittest.
// Refactor aes_decryptor_unittest.cc to handle AesDecryptor directly and
// via CdmAdapter once CdmAdapter supports decrypting functionality. There
// will also be tests that only CdmAdapter supports, like file IO, which
// will need to be handled separately.

namespace media {

namespace {

// Random key ID used to create a session.
const uint8_t kKeyId[] =;

const char kKeyIdAsJWK[] =;

const uint8_t kKeyIdAsPssh[] =;

// Key is 0x0405060708090a0b0c0d0e0f10111213,
// base64 equivalent is BAUGBwgJCgsMDQ4PEBESEw.
const char kKeyAsJWK[] =;

class MockFileIOClient : public cdm::FileIOClient {};

}  // namespace

// Tests CdmAdapter with the following parameter:
// - int: CDM interface version to test.
class CdmAdapterTestBase : public testing::Test,
                           public testing::WithParamInterface<int> {};

class CdmAdapterTestWithClearKeyCdm : public CdmAdapterTestBase {};

class CdmAdapterTestWithMockCdm : public CdmAdapterTestBase {};

// Instantiate test cases

INSTANTIATE_TEST_SUITE_P();
INSTANTIATE_TEST_SUITE_P();

INSTANTIATE_TEST_SUITE_P();
INSTANTIATE_TEST_SUITE_P();

// CdmAdapterTestWithClearKeyCdm Tests

TEST_P(CdmAdapterTestWithClearKeyCdm, Initialize) {}

// TODO(xhwang): This belongs to CdmModuleTest.
TEST_P(CdmAdapterTestWithClearKeyCdm, BadLibraryPath) {}

TEST_P(CdmAdapterTestWithClearKeyCdm, CreateWebmSession) {}

TEST_P(CdmAdapterTestWithClearKeyCdm, CreateKeyIdsSession) {}

TEST_P(CdmAdapterTestWithClearKeyCdm, CreateCencSession) {}

TEST_P(CdmAdapterTestWithClearKeyCdm, CreateSessionWithBadData) {}

TEST_P(CdmAdapterTestWithClearKeyCdm, LoadSession) {}

TEST_P(CdmAdapterTestWithClearKeyCdm, UpdateSession) {}

TEST_P(CdmAdapterTestWithClearKeyCdm, UpdateSessionWithBadData) {}

// CdmAdapterTestWithMockCdm Tests

// ChallengePlatform() will ask the helper to send platform challenge.
TEST_P(CdmAdapterTestWithMockCdm, ChallengePlatform) {}

// ChallengePlatform() will always fail if |allow_distinctive_identifier| is
// false.
TEST_P(CdmAdapterTestWithMockCdm,
       ChallengePlatform_DistinctiveIdentifierNotAllowed) {}

// CreateFileIO() will ask helper to create FileIO.
TEST_P(CdmAdapterTestWithMockCdm, CreateFileIO) {}

// CreateFileIO() will always fail if |allow_persistent_state| is false.
TEST_P(CdmAdapterTestWithMockCdm, CreateFileIO_PersistentStateNotAllowed) {}

// RequestStorageId() with version 0 (latest) is supported.
TEST_P(CdmAdapterTestWithMockCdm, RequestStorageId_Version_0) {}

// RequestStorageId() with version 1 is supported.
TEST_P(CdmAdapterTestWithMockCdm, RequestStorageId_Version_1) {}

// RequestStorageId() with version 2 is not supported.
TEST_P(CdmAdapterTestWithMockCdm, RequestStorageId_Version_2) {}

// RequestStorageId() will always fail if |allow_persistent_state| is false.
TEST_P(CdmAdapterTestWithMockCdm, RequestStorageId_PersistentStateNotAllowed) {}

TEST_P(CdmAdapterTestWithMockCdm, GetDecryptor) {}

}  // namespace media