blob: 2f32e874189add38d9b510e4716a88ee8feda2d3 [file] [log] [blame]
// Copyright 2013 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include <stddef.h>
#include <string>
#include <vector>
#include "base/base_switches.h"
#include "base/files/file_path.h"
#include "base/path_service.h"
#include "base/strings/stringprintf.h"
#include "base/strings/utf_string_conversions.h"
#include "base/test/scoped_feature_list.h"
#include "base/threading/platform_thread.h"
#include "base/time/time.h"
#include "build/build_config.h"
#include "chrome/browser/ui/browser.h"
#include "chrome/browser/ui/tabs/tab_strip_model.h"
#include "chrome/common/chrome_paths.h"
#include "chrome/common/chrome_switches.h"
#include "chrome/test/base/in_process_browser_test.h"
#include "chrome/test/base/test_launcher_utils.h"
#include "chrome/test/base/ui_test_utils.h"
#include "content/public/test/browser_test_utils.h"
#include "media/base/media_switches.h"
#include "media/base/test_data_util.h"
#include "media/media_features.h"
#include "net/test/embedded_test_server/embedded_test_server.h"
#include "url/gurl.h"
#if BUILDFLAG(ENABLE_LIBRARY_CDMS)
#include "chrome/browser/media/library_cdm_test_helper.h"
#include "media/cdm/cdm_paths.h"
#endif
#if defined(OS_ANDROID)
#error This file needs to be updated to run on Android.
#endif
#include "widevine_cdm_version.h" // In SHARED_INTERMEDIATE_DIR.
namespace {
const char kClearKey[] = "org.w3.clearkey";
const char kExternalClearKey[] = "org.chromium.externalclearkey";
const char kWidevine[] = "com.widevine.alpha";
const char kAudioWebMMimeType[] = "audio/webm";
const char kVideoWebMMimeType[] = "video/webm";
const char kAudioMP4MimeType[] = "audio/mp4";
const char kVideoMP4MimeType[] = "video/mp4";
// These are the expected titles set by checkKeySystemWithMediaMimeType()
// in test_key_system_instantiation.html. Other titles are possible, but
// they are unexpected and will be logged with the failure. kUnsupportedResult
// is the actual message generated by navigator.requestMediaKeySystemAccess(),
// and will need to be updated if that code is modified.
const char kSuccessResult[] = "success";
const char kUnsupportedResult[] =
"Unsupported keySystem or supportedConfigurations.";
const char kUnexpectedResult[] = "unexpected result";
#define EXPECT_SUCCESS(test) EXPECT_EQ(kSuccessResult, test)
#define EXPECT_UNSUPPORTED(test) EXPECT_EQ(kUnsupportedResult, test)
#if BUILDFLAG(USE_PROPRIETARY_CODECS)
#define EXPECT_PROPRIETARY EXPECT_SUCCESS
#else
#define EXPECT_PROPRIETARY EXPECT_UNSUPPORTED
#endif
// Expectations for External Clear Key.
#if BUILDFLAG(ENABLE_LIBRARY_CDMS)
#define EXPECT_ECK EXPECT_SUCCESS
#define EXPECT_ECK_PROPRIETARY EXPECT_PROPRIETARY
#else
#define EXPECT_ECK EXPECT_UNSUPPORTED
#define EXPECT_ECK_PROPRIETARY EXPECT_UNSUPPORTED
#endif // BUILDFLAG(ENABLE_LIBRARY_CDMS)
// Expectations for Widevine.
#if defined(WIDEVINE_CDM_AVAILABLE)
#define EXPECT_WV_SUCCESS EXPECT_SUCCESS
#define EXPECT_WV_PROPRIETARY EXPECT_PROPRIETARY
#else // defined(WIDEVINE_CDM_AVAILABLE)
#define EXPECT_WV_SUCCESS EXPECT_UNSUPPORTED
#define EXPECT_WV_PROPRIETARY EXPECT_UNSUPPORTED
#endif // defined(WIDEVINE_CDM_AVAILABLE)
}; // namespace
class EncryptedMediaSupportedTypesTest : public InProcessBrowserTest {
protected:
EncryptedMediaSupportedTypesTest() {
audio_webm_codecs_.push_back("opus");
audio_webm_codecs_.push_back("vorbis");
video_webm_codecs_.push_back("vp8");
video_webm_codecs_.push_back("vp8.0");
video_webm_codecs_.push_back("vp9");
video_webm_codecs_.push_back("vp9.0");
audio_mp4_codecs_.push_back("mp4a.40.2");
video_mp4_codecs_.push_back("avc1.42001E"); // Baseline profile.
video_mp4_codecs_.push_back("avc1.4D000C"); // Main profile.
video_mp4_codecs_.push_back("avc3.64001F"); // High profile.
video_mp4_hi10p_codecs_.push_back("avc1.6E001E"); // Hi10P profile
#if BUILDFLAG(ENABLE_HEVC_DEMUXING)
video_mp4_codecs_.push_back("hvc1.1.6.L93.B0");
video_mp4_codecs_.push_back("hev1.1.6.L93.B0");
#else
invalid_codecs_.push_back("hvc1.1.6.L93.B0");
invalid_codecs_.push_back("hev1.1.6.L93.B0");
#endif
// Codecs allowed by both MP4 and WebM.
// For vp9 codec string format, see https://www.webmproject.org/vp9/mp4/
video_common_codecs_.push_back("vp09.00.10.08");
// Extended codecs are used, so make sure generic ones fail. These will be
// tested against all init data types as they should always fail to be
// supported.
invalid_codecs_.push_back("avc1");
invalid_codecs_.push_back("avc1.");
invalid_codecs_.push_back("avc3");
// Other invalid codecs.
invalid_codecs_.push_back("vp8.1");
invalid_codecs_.push_back("mp4a");
invalid_codecs_.push_back("avc2");
invalid_codecs_.push_back("foo");
// We only support proper long-form HEVC codec ids.
invalid_codecs_.push_back("hev1");
invalid_codecs_.push_back("hev1.");
invalid_codecs_.push_back("hvc1");
invalid_codecs_.push_back("hvc1.");
// Non-zero VP9 profiles are supported in WebM and MP4 with ClearKey.
// Widevine support will eventually be added. See http://crbug.com/707128
clear_key_exclusive_video_common_codecs_.push_back("vp09.01.10.08");
clear_key_exclusive_video_common_codecs_.push_back("vp09.02.10.10");
clear_key_exclusive_video_common_codecs_.push_back("vp09.03.10.10");
}
typedef std::vector<std::string> CodecVector;
const CodecVector& no_codecs() const { return no_codecs_; }
const CodecVector& video_common_codecs() const {
return video_common_codecs_;
}
const CodecVector& audio_webm_codecs() const { return audio_webm_codecs_; }
const CodecVector& video_webm_codecs() const { return video_webm_codecs_; }
const CodecVector& audio_mp4_codecs() const { return audio_mp4_codecs_; }
const CodecVector& video_mp4_codecs() const { return video_mp4_codecs_; }
const CodecVector& video_mp4_hi10p_codecs() const {
return video_mp4_hi10p_codecs_;
}
const CodecVector& invalid_codecs() const { return invalid_codecs_; }
const CodecVector& clear_key_exclusive_video_common_codecs() const {
return clear_key_exclusive_video_common_codecs_;
}
#if BUILDFLAG(ENABLE_LIBRARY_CDMS)
void SetUpDefaultCommandLine(base::CommandLine* command_line) override {
base::CommandLine default_command_line(base::CommandLine::NO_PROGRAM);
InProcessBrowserTest::SetUpDefaultCommandLine(&default_command_line);
test_launcher_utils::RemoveCommandLineSwitch(
default_command_line, switches::kDisableComponentUpdate, command_line);
}
#endif // BUILDFLAG(ENABLE_LIBRARY_CDMS)
void SetUpOnMainThread() override {
// Load the test page needed so that checkKeySystemWithMediaMimeType()
// is available.
net::EmbeddedTestServer* http_test_server = embedded_test_server();
http_test_server->ServeFilesFromSourceDirectory(media::GetTestDataPath());
CHECK(http_test_server->Start());
GURL gurl = http_test_server->GetURL("/test_key_system_instantiation.html");
ui_test_utils::NavigateToURL(browser(), gurl);
}
// Create a valid JavaScript string for the content type. Format is
// |mime_type|; codecs="|codec|", where codecs= is omitted if there
// is no codec.
static std::string MakeContentType(const std::string& mime_type,
const std::string& codec) {
std::string content_type(mime_type);
if (!codec.empty())
content_type += base::StringPrintf("; codecs=\"%s\"", codec.c_str());
return content_type;
}
// Format: {contentType: |content_type|, robustness: |robustness|}, or
// {contentType: |content_type|} if |robustness| is null.
static std::string MakeMediaCapability(const std::string& content_type,
const char* robustness) {
if (!robustness)
return base::StringPrintf("{contentType: '%s'}", content_type.c_str());
return base::StringPrintf("{contentType: '%s', robustness: '%s'}",
content_type.c_str(), robustness);
}
static std::string MakeMediaCapabilities(const std::string& mime_type,
const CodecVector& codecs,
const char* robustness) {
std::string capabilities("[");
if (codecs.empty()) {
capabilities += MakeMediaCapability(
MakeContentType(mime_type, std::string()), robustness);
} else {
for (auto codec : codecs) {
capabilities +=
MakeMediaCapability(MakeContentType(mime_type, codec), robustness) +
",";
}
// Remove trailing comma.
capabilities.erase(capabilities.length() - 1);
}
capabilities += ("]");
return capabilities;
}
static std::string ExecuteCommand(content::WebContents* contents,
const std::string& command) {
content::TitleWatcher title_watcher(contents,
base::ASCIIToUTF16(kSuccessResult));
title_watcher.AlsoWaitForTitle(base::ASCIIToUTF16(kUnsupportedResult));
title_watcher.AlsoWaitForTitle(base::ASCIIToUTF16(kUnexpectedResult));
EXPECT_TRUE(content::ExecuteScript(contents, command));
base::string16 result = title_watcher.WaitAndGetTitle();
return base::UTF16ToASCII(result);
}
enum class SessionType {
kTemporary, // Temporary session
kPersistentLicense // Persistent license session
};
std::string GetSessionTypeString(SessionType session_type) {
switch (session_type) {
case SessionType::kTemporary:
return "temporary";
case SessionType::kPersistentLicense:
return "persistent-license";
}
NOTREACHED();
return "";
}
std::string IsSupportedByKeySystem(
const std::string& key_system,
const std::string& mime_type,
const CodecVector& codecs,
SessionType session_type = SessionType::kTemporary,
const char* robustness = nullptr) {
// Choose the appropriate init data type for the sub type.
size_t pos = mime_type.find('/');
DCHECK(pos > 0);
std::string sub_type(mime_type.substr(pos + 1));
std::string init_data_type;
if (sub_type == "mp4") {
init_data_type = "cenc";
} else {
DCHECK(sub_type == "webm");
init_data_type = "webm";
}
bool is_audio = mime_type.compare(0, 5, "audio") == 0;
DCHECK(is_audio || mime_type.compare(0, 5, "video") == 0);
auto capabilities = MakeMediaCapabilities(mime_type, codecs, robustness);
auto audio_capabilities = is_audio ? capabilities : "null";
auto video_capabilities = !is_audio ? capabilities : "null";
auto session_type_string = GetSessionTypeString(session_type);
std::string command = base::StringPrintf(
"checkKeySystemWithMediaMimeType('%s', '%s', %s, %s, '%s')",
key_system.c_str(), init_data_type.c_str(), audio_capabilities.c_str(),
video_capabilities.c_str(), session_type_string.c_str());
DVLOG(1) << "command: " << command;
return ExecuteCommand(browser()->tab_strip_model()->GetActiveWebContents(),
command);
}
std::string IsSessionTypeSupported(const std::string& key_system,
SessionType session_type) {
return IsSupportedByKeySystem(key_system, kVideoWebMMimeType,
video_webm_codecs(), session_type);
}
std::string IsAudioRobustnessSupported(const std::string& key_system,
const char* robustness) {
return IsSupportedByKeySystem(key_system, kAudioWebMMimeType,
audio_webm_codecs(), SessionType::kTemporary,
robustness);
}
std::string IsVideoRobustnessSupported(const std::string& key_system,
const char* robustness) {
return IsSupportedByKeySystem(key_system, kVideoWebMMimeType,
video_webm_codecs(), SessionType::kTemporary,
robustness);
}
private:
const CodecVector no_codecs_;
CodecVector audio_webm_codecs_;
CodecVector video_webm_codecs_;
CodecVector audio_mp4_codecs_;
CodecVector video_mp4_codecs_;
CodecVector video_mp4_hi10p_codecs_;
CodecVector video_common_codecs_;
CodecVector invalid_codecs_;
CodecVector clear_key_exclusive_video_common_codecs_;
};
// For ClearKey, nothing additional is required.
class EncryptedMediaSupportedTypesClearKeyTest
: public EncryptedMediaSupportedTypesTest {
};
// For ExternalClearKey tests, ensure that the ClearKey adapter is loaded.
class EncryptedMediaSupportedTypesExternalClearKeyTest
: public EncryptedMediaSupportedTypesTest {
#if BUILDFLAG(ENABLE_LIBRARY_CDMS)
protected:
EncryptedMediaSupportedTypesExternalClearKeyTest() {
scoped_feature_list_.InitAndEnableFeature(
media::kExternalClearKeyForTesting);
}
~EncryptedMediaSupportedTypesExternalClearKeyTest() override {}
void SetUpCommandLine(base::CommandLine* command_line) override {
EncryptedMediaSupportedTypesTest::SetUpCommandLine(command_line);
RegisterClearKeyCdm(command_line);
}
private:
base::test::ScopedFeatureList scoped_feature_list_;
#endif // BUILDFLAG(ENABLE_LIBRARY_CDMS)
DISALLOW_COPY_AND_ASSIGN(EncryptedMediaSupportedTypesExternalClearKeyTest);
};
// By default, the External Clear Key (ECK) key system is not supported even if
// present. This test case tests this behavior by not enabling
// kExternalClearKeyForTesting. Even registering the Clear Key CDM does not
// enable the ECK key system support.
class EncryptedMediaSupportedTypesExternalClearKeyNotEnabledTest
: public EncryptedMediaSupportedTypesTest {
protected:
void SetUpCommandLine(base::CommandLine* command_line) override {
EncryptedMediaSupportedTypesTest::SetUpCommandLine(command_line);
#if BUILDFLAG(ENABLE_LIBRARY_CDMS)
RegisterClearKeyCdm(command_line);
#endif // BUILDFLAG(ENABLE_LIBRARY_CDMS)
}
};
class EncryptedMediaSupportedTypesWidevineTest
: public EncryptedMediaSupportedTypesTest {
protected:
void SetUpCommandLine(base::CommandLine* command_line) override {
EncryptedMediaSupportedTypesTest::SetUpCommandLine(command_line);
// Persistent license is supported on ChromeOS when protected media
// identifier is allowed which involves a user action. Use this switch to
// always allow the identifier for testing purpose. Note that the test page
// is hosted on "127.0.0.1". See net::EmbeddedTestServer for details.
command_line->AppendSwitchASCII(
switches::kUnsafelyAllowProtectedMediaIdentifierForDomain, "127.0.0.1");
}
};
#if BUILDFLAG(ENABLE_LIBRARY_CDMS)
// Registers ClearKey CDM with the wrong path (filename).
class EncryptedMediaSupportedTypesClearKeyCdmRegisteredWithWrongPathTest
: public EncryptedMediaSupportedTypesTest {
protected:
EncryptedMediaSupportedTypesClearKeyCdmRegisteredWithWrongPathTest() {
scoped_feature_list_.InitAndEnableFeature(
media::kExternalClearKeyForTesting);
}
~EncryptedMediaSupportedTypesClearKeyCdmRegisteredWithWrongPathTest()
override {}
void SetUpCommandLine(base::CommandLine* command_line) override {
EncryptedMediaSupportedTypesTest::SetUpCommandLine(command_line);
RegisterClearKeyCdm(command_line, true /* use_wrong_cdm_path */);
}
private:
base::test::ScopedFeatureList scoped_feature_list_;
DISALLOW_COPY_AND_ASSIGN(
EncryptedMediaSupportedTypesClearKeyCdmRegisteredWithWrongPathTest);
};
#endif // BUILDFLAG(ENABLE_LIBRARY_CDMS)
IN_PROC_BROWSER_TEST_F(EncryptedMediaSupportedTypesClearKeyTest, Basic) {
EXPECT_SUCCESS(IsSupportedByKeySystem(kClearKey, kVideoWebMMimeType,
video_webm_codecs()));
EXPECT_SUCCESS(IsSupportedByKeySystem(kClearKey, kAudioWebMMimeType,
audio_webm_codecs()));
EXPECT_PROPRIETARY(
IsSupportedByKeySystem(kClearKey, kVideoMP4MimeType, video_mp4_codecs()));
EXPECT_PROPRIETARY(
IsSupportedByKeySystem(kClearKey, kAudioMP4MimeType, audio_mp4_codecs()));
}
IN_PROC_BROWSER_TEST_F(EncryptedMediaSupportedTypesClearKeyTest, NoCodecs) {
EXPECT_UNSUPPORTED(
IsSupportedByKeySystem(kClearKey, kVideoWebMMimeType, no_codecs()));
EXPECT_UNSUPPORTED(
IsSupportedByKeySystem(kClearKey, kAudioWebMMimeType, no_codecs()));
EXPECT_UNSUPPORTED(
IsSupportedByKeySystem(kClearKey, kVideoMP4MimeType, no_codecs()));
EXPECT_UNSUPPORTED(
IsSupportedByKeySystem(kClearKey, kAudioMP4MimeType, no_codecs()));
}
IN_PROC_BROWSER_TEST_F(EncryptedMediaSupportedTypesClearKeyTest,
InvalidKeySystems) {
// Case sensitive.
EXPECT_UNSUPPORTED(IsSupportedByKeySystem(
"org.w3.ClEaRkEy", kVideoWebMMimeType, video_webm_codecs()));
// Prefixed Clear Key key system.
EXPECT_UNSUPPORTED(IsSupportedByKeySystem(
"webkit-org.w3.clearkey", kVideoWebMMimeType, video_webm_codecs()));
// TLDs are not allowed.
EXPECT_UNSUPPORTED(
IsSupportedByKeySystem("org.", kVideoWebMMimeType, video_webm_codecs()));
EXPECT_UNSUPPORTED(
IsSupportedByKeySystem("org", kVideoWebMMimeType, video_webm_codecs()));
EXPECT_UNSUPPORTED(IsSupportedByKeySystem("org.w3.", kVideoWebMMimeType,
video_webm_codecs()));
EXPECT_UNSUPPORTED(IsSupportedByKeySystem("org.w3", kVideoWebMMimeType,
video_webm_codecs()));
// Incomplete.
EXPECT_UNSUPPORTED(IsSupportedByKeySystem(
"org.w3.clearke", kVideoWebMMimeType, video_webm_codecs()));
// Extra character.
EXPECT_UNSUPPORTED(IsSupportedByKeySystem(
"org.w3.clearkeyz", kVideoWebMMimeType, video_webm_codecs()));
// There are no child key systems for Clear Key.
EXPECT_UNSUPPORTED(IsSupportedByKeySystem(
"org.w3.clearkey.foo", kVideoWebMMimeType, video_webm_codecs()));
}
IN_PROC_BROWSER_TEST_F(EncryptedMediaSupportedTypesClearKeyTest, Video_WebM) {
// Valid video types.
EXPECT_SUCCESS(IsSupportedByKeySystem(kClearKey, kVideoWebMMimeType,
video_webm_codecs()));
EXPECT_SUCCESS(IsSupportedByKeySystem(kClearKey, kVideoWebMMimeType,
video_common_codecs()));
EXPECT_SUCCESS(
IsSupportedByKeySystem(kClearKey, kVideoWebMMimeType,
clear_key_exclusive_video_common_codecs()));
// Non-video WebM codecs.
EXPECT_UNSUPPORTED(IsSupportedByKeySystem(kClearKey, kVideoWebMMimeType,
audio_webm_codecs()));
// Invalid or non-Webm video codecs.
EXPECT_UNSUPPORTED(
IsSupportedByKeySystem(kClearKey, kVideoWebMMimeType, invalid_codecs()));
EXPECT_UNSUPPORTED(IsSupportedByKeySystem(kClearKey, kVideoWebMMimeType,
audio_mp4_codecs()));
EXPECT_UNSUPPORTED(IsSupportedByKeySystem(kClearKey, kVideoWebMMimeType,
video_mp4_codecs()));
}
IN_PROC_BROWSER_TEST_F(EncryptedMediaSupportedTypesClearKeyTest, Audio_WebM) {
// Valid audio types.
EXPECT_SUCCESS(IsSupportedByKeySystem(kClearKey, kAudioWebMMimeType,
audio_webm_codecs()));
// Non-audio WebM codecs.
EXPECT_UNSUPPORTED(IsSupportedByKeySystem(kClearKey, kAudioWebMMimeType,
video_webm_codecs()));
// Invalid or Non-Webm codecs.
EXPECT_UNSUPPORTED(
IsSupportedByKeySystem(kClearKey, kAudioWebMMimeType, invalid_codecs()));
EXPECT_UNSUPPORTED(IsSupportedByKeySystem(kClearKey, kAudioWebMMimeType,
audio_mp4_codecs()));
EXPECT_UNSUPPORTED(IsSupportedByKeySystem(kClearKey, kAudioWebMMimeType,
video_mp4_codecs()));
}
IN_PROC_BROWSER_TEST_F(EncryptedMediaSupportedTypesClearKeyTest, Video_MP4) {
// Valid video types.
EXPECT_PROPRIETARY(
IsSupportedByKeySystem(kClearKey, kVideoMP4MimeType, video_mp4_codecs()));
EXPECT_PROPRIETARY(IsSupportedByKeySystem(kClearKey, kVideoMP4MimeType,
video_common_codecs()));
EXPECT_PROPRIETARY(IsSupportedByKeySystem(
kClearKey, kVideoMP4MimeType, clear_key_exclusive_video_common_codecs()));
// High 10-bit Profile is supported when using ClearKey if
// it is supported for clear content on this platform.
#if BUILDFLAG(ENABLE_FFMPEG_VIDEO_DECODERS)
EXPECT_PROPRIETARY(IsSupportedByKeySystem(kClearKey, kVideoMP4MimeType,
video_mp4_hi10p_codecs()));
#else
EXPECT_UNSUPPORTED(IsSupportedByKeySystem(kClearKey, kVideoMP4MimeType,
video_mp4_hi10p_codecs()));
#endif
// Non-video MP4 codecs.
EXPECT_UNSUPPORTED(
IsSupportedByKeySystem(kClearKey, kVideoMP4MimeType, audio_mp4_codecs()));
// Invalid or non-MP4 codecs.
EXPECT_UNSUPPORTED(
IsSupportedByKeySystem(kClearKey, kVideoMP4MimeType, invalid_codecs()));
EXPECT_UNSUPPORTED(IsSupportedByKeySystem(kClearKey, kVideoMP4MimeType,
audio_webm_codecs()));
EXPECT_UNSUPPORTED(IsSupportedByKeySystem(kClearKey, kVideoMP4MimeType,
video_webm_codecs()));
}
IN_PROC_BROWSER_TEST_F(EncryptedMediaSupportedTypesClearKeyTest, Audio_MP4) {
// Valid audio types.
EXPECT_PROPRIETARY(
IsSupportedByKeySystem(kClearKey, kAudioMP4MimeType, audio_mp4_codecs()));
// Non-audio MP4 codecs.
EXPECT_UNSUPPORTED(
IsSupportedByKeySystem(kClearKey, kAudioMP4MimeType, video_mp4_codecs()));
// Invalid or non-MP4 codec.
EXPECT_UNSUPPORTED(
IsSupportedByKeySystem(kClearKey, kAudioMP4MimeType, invalid_codecs()));
EXPECT_UNSUPPORTED(IsSupportedByKeySystem(kClearKey, kAudioMP4MimeType,
audio_webm_codecs()));
EXPECT_UNSUPPORTED(IsSupportedByKeySystem(kClearKey, kAudioMP4MimeType,
video_webm_codecs()));
}
IN_PROC_BROWSER_TEST_F(EncryptedMediaSupportedTypesClearKeyTest, SessionType) {
// Temporary session always supported.
EXPECT_SUCCESS(IsSessionTypeSupported(kClearKey, SessionType::kTemporary));
// Persistent license session not supported by Clear Key key system.
EXPECT_UNSUPPORTED(
IsSessionTypeSupported(kClearKey, SessionType::kPersistentLicense));
}
IN_PROC_BROWSER_TEST_F(EncryptedMediaSupportedTypesClearKeyTest, Robustness) {
// External Clear Key doesn't require a robustness string.
EXPECT_SUCCESS(IsVideoRobustnessSupported(kClearKey, nullptr));
EXPECT_SUCCESS(IsVideoRobustnessSupported(kClearKey, ""));
EXPECT_SUCCESS(IsAudioRobustnessSupported(kClearKey, nullptr));
EXPECT_SUCCESS(IsAudioRobustnessSupported(kClearKey, ""));
// Non-empty robustness string will be rejected, including valid Widevine
// robustness strings.
EXPECT_UNSUPPORTED(IsVideoRobustnessSupported(kClearKey, "Invalid String"));
EXPECT_UNSUPPORTED(IsVideoRobustnessSupported(kClearKey, "SW_SECURE_CRYPTO"));
EXPECT_UNSUPPORTED(IsAudioRobustnessSupported(kClearKey, "Invalid String"));
EXPECT_UNSUPPORTED(IsAudioRobustnessSupported(kClearKey, "SW_SECURE_CRYPTO"));
}
//
// External Clear Key
//
// When BUILDFLAG(ENABLE_LIBRARY_CDMS), this also tests the Pepper CDM check.
IN_PROC_BROWSER_TEST_F(EncryptedMediaSupportedTypesExternalClearKeyTest,
Basic) {
EXPECT_ECK(IsSupportedByKeySystem(kExternalClearKey, kVideoWebMMimeType,
video_webm_codecs()));
EXPECT_ECK(IsSupportedByKeySystem(kExternalClearKey, kAudioWebMMimeType,
audio_webm_codecs()));
EXPECT_ECK_PROPRIETARY(IsSupportedByKeySystem(
kExternalClearKey, kVideoMP4MimeType, video_mp4_codecs()));
EXPECT_ECK_PROPRIETARY(IsSupportedByKeySystem(
kExternalClearKey, kAudioMP4MimeType, audio_mp4_codecs()));
}
IN_PROC_BROWSER_TEST_F(EncryptedMediaSupportedTypesExternalClearKeyTest,
NoCodecs) {
EXPECT_UNSUPPORTED(IsSupportedByKeySystem(kExternalClearKey,
kVideoWebMMimeType, no_codecs()));
EXPECT_UNSUPPORTED(IsSupportedByKeySystem(kExternalClearKey,
kAudioWebMMimeType, no_codecs()));
EXPECT_UNSUPPORTED(IsSupportedByKeySystem(kExternalClearKey,
kVideoMP4MimeType, no_codecs()));
EXPECT_UNSUPPORTED(IsSupportedByKeySystem(kExternalClearKey,
kAudioMP4MimeType, no_codecs()));
}
IN_PROC_BROWSER_TEST_F(EncryptedMediaSupportedTypesExternalClearKeyTest,
InvalidKeySystems) {
// Case sensitive.
EXPECT_UNSUPPORTED(IsSupportedByKeySystem("org.chromium.ExTeRnAlClEaRkEy",
kVideoWebMMimeType,
video_webm_codecs()));
// TLDs are not allowed.
EXPECT_UNSUPPORTED(
IsSupportedByKeySystem("org.", kVideoWebMMimeType, video_webm_codecs()));
EXPECT_UNSUPPORTED(
IsSupportedByKeySystem("org", kVideoWebMMimeType, video_webm_codecs()));
EXPECT_UNSUPPORTED(IsSupportedByKeySystem("org.chromium", kVideoWebMMimeType,
video_webm_codecs()));
EXPECT_UNSUPPORTED(IsSupportedByKeySystem("org.chromium.", kVideoWebMMimeType,
video_webm_codecs()));
// Incomplete.
EXPECT_UNSUPPORTED(IsSupportedByKeySystem(
"org.chromium.externalclearke", kVideoWebMMimeType, video_webm_codecs()));
// Extra character.
EXPECT_UNSUPPORTED(IsSupportedByKeySystem("org.chromium.externalclearkeyz",
kVideoWebMMimeType,
video_webm_codecs()));
// There are no child key systems for External Clear Key.
EXPECT_UNSUPPORTED(IsSupportedByKeySystem("org.chromium.externalclearkey.foo",
kVideoWebMMimeType,
video_webm_codecs()));
}
IN_PROC_BROWSER_TEST_F(EncryptedMediaSupportedTypesExternalClearKeyTest,
Video_WebM) {
// Valid video types.
EXPECT_ECK(IsSupportedByKeySystem(kExternalClearKey, kVideoWebMMimeType,
video_webm_codecs()));
EXPECT_ECK(IsSupportedByKeySystem(kExternalClearKey, kVideoWebMMimeType,
video_common_codecs()));
EXPECT_ECK(IsSupportedByKeySystem(kClearKey, kVideoWebMMimeType,
clear_key_exclusive_video_common_codecs()));
// Non-video WebM codecs.
EXPECT_UNSUPPORTED(IsSupportedByKeySystem(
kExternalClearKey, kVideoWebMMimeType, audio_webm_codecs()));
// Invalid or non-Webm codecs.
EXPECT_UNSUPPORTED(IsSupportedByKeySystem(
kExternalClearKey, kVideoWebMMimeType, invalid_codecs()));
EXPECT_UNSUPPORTED(IsSupportedByKeySystem(
kExternalClearKey, kVideoWebMMimeType, audio_mp4_codecs()));
EXPECT_UNSUPPORTED(IsSupportedByKeySystem(
kExternalClearKey, kVideoWebMMimeType, video_mp4_codecs()));
}
IN_PROC_BROWSER_TEST_F(EncryptedMediaSupportedTypesExternalClearKeyTest,
Audio_WebM) {
// Valid audio types.
EXPECT_ECK(IsSupportedByKeySystem(kExternalClearKey, kAudioWebMMimeType,
audio_webm_codecs()));
// Non-audio WebM codecs.
EXPECT_UNSUPPORTED(IsSupportedByKeySystem(
kExternalClearKey, kAudioWebMMimeType, video_webm_codecs()));
// Invalid or non-Webm codecs.
EXPECT_UNSUPPORTED(IsSupportedByKeySystem(
kExternalClearKey, kAudioWebMMimeType, invalid_codecs()));
EXPECT_UNSUPPORTED(IsSupportedByKeySystem(
kExternalClearKey, kAudioWebMMimeType, audio_mp4_codecs()));
EXPECT_UNSUPPORTED(IsSupportedByKeySystem(
kExternalClearKey, kAudioWebMMimeType, video_mp4_codecs()));
}
IN_PROC_BROWSER_TEST_F(EncryptedMediaSupportedTypesExternalClearKeyTest,
Video_MP4) {
// Valid video types.
EXPECT_ECK_PROPRIETARY(IsSupportedByKeySystem(
kExternalClearKey, kVideoMP4MimeType, video_mp4_codecs()));
EXPECT_ECK_PROPRIETARY(IsSupportedByKeySystem(
kExternalClearKey, kVideoMP4MimeType, video_common_codecs()));
EXPECT_ECK_PROPRIETARY(IsSupportedByKeySystem(
kClearKey, kVideoMP4MimeType, clear_key_exclusive_video_common_codecs()));
// High 10-bit Profile is not supported when using ExternalClearKey.
EXPECT_UNSUPPORTED(IsSupportedByKeySystem(
kExternalClearKey, kVideoMP4MimeType, video_mp4_hi10p_codecs()));
// Non-video MP4 codecs.
EXPECT_UNSUPPORTED(IsSupportedByKeySystem(
kExternalClearKey, kVideoMP4MimeType, audio_mp4_codecs()));
// Invalid or non-MP4 codecs.
EXPECT_UNSUPPORTED(IsSupportedByKeySystem(
kExternalClearKey, kVideoMP4MimeType, invalid_codecs()));
EXPECT_UNSUPPORTED(IsSupportedByKeySystem(
kExternalClearKey, kVideoMP4MimeType, audio_webm_codecs()));
EXPECT_UNSUPPORTED(IsSupportedByKeySystem(
kExternalClearKey, kVideoMP4MimeType, video_webm_codecs()));
}
IN_PROC_BROWSER_TEST_F(EncryptedMediaSupportedTypesExternalClearKeyTest,
Audio_MP4) {
// Valid audio types.
EXPECT_ECK_PROPRIETARY(IsSupportedByKeySystem(
kExternalClearKey, kAudioMP4MimeType, audio_mp4_codecs()));
// Non-audio MP4 codecs.
EXPECT_UNSUPPORTED(IsSupportedByKeySystem(
kExternalClearKey, kAudioMP4MimeType, video_mp4_codecs()));
// Invalid or Non-MP4 codec.
EXPECT_UNSUPPORTED(IsSupportedByKeySystem(
kExternalClearKey, kAudioMP4MimeType, invalid_codecs()));
EXPECT_UNSUPPORTED(IsSupportedByKeySystem(
kExternalClearKey, kAudioMP4MimeType, audio_webm_codecs()));
EXPECT_UNSUPPORTED(IsSupportedByKeySystem(
kExternalClearKey, kAudioMP4MimeType, video_webm_codecs()));
}
IN_PROC_BROWSER_TEST_F(EncryptedMediaSupportedTypesExternalClearKeyTest,
SessionType) {
// Temporary session always supported.
EXPECT_SUCCESS(
IsSessionTypeSupported(kExternalClearKey, SessionType::kTemporary));
// Persistent license session always supported by External Clear Key.
EXPECT_SUCCESS(IsSessionTypeSupported(kExternalClearKey,
SessionType::kPersistentLicense));
}
IN_PROC_BROWSER_TEST_F(EncryptedMediaSupportedTypesExternalClearKeyTest,
Robustness) {
// External Clear Key doesn't require a robustness string.
EXPECT_SUCCESS(IsVideoRobustnessSupported(kExternalClearKey, nullptr));
EXPECT_SUCCESS(IsVideoRobustnessSupported(kExternalClearKey, ""));
EXPECT_SUCCESS(IsAudioRobustnessSupported(kExternalClearKey, nullptr));
EXPECT_SUCCESS(IsAudioRobustnessSupported(kExternalClearKey, ""));
// Non-empty robustness string will be rejected, including valid Widevine
// robustness strings.
EXPECT_UNSUPPORTED(
IsVideoRobustnessSupported(kExternalClearKey, "Invalid String"));
EXPECT_UNSUPPORTED(
IsVideoRobustnessSupported(kExternalClearKey, "SW_SECURE_CRYPTO"));
EXPECT_UNSUPPORTED(
IsAudioRobustnessSupported(kExternalClearKey, "Invalid String"));
EXPECT_UNSUPPORTED(
IsAudioRobustnessSupported(kExternalClearKey, "SW_SECURE_CRYPTO"));
}
// External Clear Key is disabled by default.
IN_PROC_BROWSER_TEST_F(
EncryptedMediaSupportedTypesExternalClearKeyNotEnabledTest,
Basic) {
EXPECT_UNSUPPORTED(IsSupportedByKeySystem(
kExternalClearKey, kVideoWebMMimeType, video_webm_codecs()));
// Clear Key should still be registered.
EXPECT_SUCCESS(IsSupportedByKeySystem(kClearKey, kVideoWebMMimeType,
video_webm_codecs()));
}
//
// Widevine
//
IN_PROC_BROWSER_TEST_F(EncryptedMediaSupportedTypesWidevineTest, Basic) {
EXPECT_WV_SUCCESS(IsSupportedByKeySystem(kWidevine, kVideoWebMMimeType,
video_webm_codecs()));
EXPECT_WV_SUCCESS(IsSupportedByKeySystem(kWidevine, kAudioWebMMimeType,
audio_webm_codecs()));
EXPECT_WV_PROPRIETARY(
IsSupportedByKeySystem(kWidevine, kVideoMP4MimeType, video_mp4_codecs()));
EXPECT_WV_PROPRIETARY(
IsSupportedByKeySystem(kWidevine, kAudioMP4MimeType, audio_mp4_codecs()));
}
IN_PROC_BROWSER_TEST_F(EncryptedMediaSupportedTypesWidevineTest,
InvalidKeySystems) {
// Case sensitive.
EXPECT_UNSUPPORTED(IsSupportedByKeySystem(
"com.widevine.WideVine", kVideoWebMMimeType, video_webm_codecs()));
// TLDs are not allowed.
EXPECT_UNSUPPORTED(
IsSupportedByKeySystem("com.", kVideoWebMMimeType, video_webm_codecs()));
EXPECT_UNSUPPORTED(
IsSupportedByKeySystem("com", kVideoWebMMimeType, video_webm_codecs()));
EXPECT_UNSUPPORTED(IsSupportedByKeySystem("com.widevine.", kVideoWebMMimeType,
video_webm_codecs()));
EXPECT_UNSUPPORTED(IsSupportedByKeySystem("com.widevine", kVideoWebMMimeType,
video_webm_codecs()));
// Incomplete.
EXPECT_UNSUPPORTED(IsSupportedByKeySystem(
"com.widevine.alp", kVideoWebMMimeType, video_webm_codecs()));
// Extra character.
EXPECT_UNSUPPORTED(IsSupportedByKeySystem(
"com.widevine.alphab", kVideoWebMMimeType, video_webm_codecs()));
// There are no child key systems for Widevine.
EXPECT_UNSUPPORTED(IsSupportedByKeySystem(
"com.widevine.alpha.child", kVideoWebMMimeType, video_webm_codecs()));
}
IN_PROC_BROWSER_TEST_F(EncryptedMediaSupportedTypesWidevineTest, NoCodecs) {
EXPECT_UNSUPPORTED(
IsSupportedByKeySystem(kWidevine, kVideoWebMMimeType, no_codecs()));
EXPECT_UNSUPPORTED(
IsSupportedByKeySystem(kWidevine, kAudioWebMMimeType, no_codecs()));
EXPECT_UNSUPPORTED(
IsSupportedByKeySystem(kWidevine, kVideoMP4MimeType, no_codecs()));
EXPECT_UNSUPPORTED(
IsSupportedByKeySystem(kWidevine, kAudioMP4MimeType, no_codecs()));
}
IN_PROC_BROWSER_TEST_F(EncryptedMediaSupportedTypesWidevineTest, Video_WebM) {
// Valid video types.
EXPECT_WV_SUCCESS(IsSupportedByKeySystem(kWidevine, kVideoWebMMimeType,
video_webm_codecs()));
EXPECT_WV_SUCCESS(IsSupportedByKeySystem(kWidevine, kVideoWebMMimeType,
video_common_codecs()));
// Non-video WebM codecs.
EXPECT_UNSUPPORTED(IsSupportedByKeySystem(kWidevine, kVideoWebMMimeType,
audio_webm_codecs()));
// Invalid or non-Webm codecs.
EXPECT_UNSUPPORTED(
IsSupportedByKeySystem(kWidevine, kVideoWebMMimeType,
clear_key_exclusive_video_common_codecs()));
EXPECT_UNSUPPORTED(
IsSupportedByKeySystem(kWidevine, kVideoWebMMimeType, invalid_codecs()));
EXPECT_UNSUPPORTED(IsSupportedByKeySystem(kWidevine, kVideoWebMMimeType,
audio_mp4_codecs()));
EXPECT_UNSUPPORTED(IsSupportedByKeySystem(kWidevine, kVideoWebMMimeType,
video_mp4_codecs()));
}
IN_PROC_BROWSER_TEST_F(EncryptedMediaSupportedTypesWidevineTest, Audio_WebM) {
// Valid audio types.
EXPECT_WV_SUCCESS(IsSupportedByKeySystem(kWidevine, kAudioWebMMimeType,
audio_webm_codecs()));
// Non-audio WebM codecs.
EXPECT_UNSUPPORTED(IsSupportedByKeySystem(kWidevine, kAudioWebMMimeType,
video_webm_codecs()));
// Invalid or non-Webm codecs.
EXPECT_UNSUPPORTED(
IsSupportedByKeySystem(kWidevine, kAudioWebMMimeType, invalid_codecs()));
EXPECT_UNSUPPORTED(IsSupportedByKeySystem(kWidevine, kAudioWebMMimeType,
audio_mp4_codecs()));
EXPECT_UNSUPPORTED(IsSupportedByKeySystem(kWidevine, kAudioWebMMimeType,
video_mp4_codecs()));
}
IN_PROC_BROWSER_TEST_F(EncryptedMediaSupportedTypesWidevineTest, Video_MP4) {
// Valid video types.
EXPECT_WV_PROPRIETARY(
IsSupportedByKeySystem(kWidevine, kVideoMP4MimeType, video_mp4_codecs()));
EXPECT_WV_PROPRIETARY(IsSupportedByKeySystem(kWidevine, kVideoMP4MimeType,
video_common_codecs()));
// High 10-bit Profile is not supported when using Widevine.
EXPECT_UNSUPPORTED(IsSupportedByKeySystem(kWidevine, kVideoMP4MimeType,
video_mp4_hi10p_codecs()));
// Non-video MP4 codecs.
EXPECT_UNSUPPORTED(
IsSupportedByKeySystem(kWidevine, kVideoMP4MimeType, audio_mp4_codecs()));
// Invalid or non-MP4 codecs.
EXPECT_UNSUPPORTED(IsSupportedByKeySystem(
kWidevine, kVideoMP4MimeType, clear_key_exclusive_video_common_codecs()));
EXPECT_UNSUPPORTED(
IsSupportedByKeySystem(kWidevine, kVideoMP4MimeType, invalid_codecs()));
EXPECT_UNSUPPORTED(IsSupportedByKeySystem(kWidevine, kVideoMP4MimeType,
audio_webm_codecs()));
EXPECT_UNSUPPORTED(IsSupportedByKeySystem(kWidevine, kVideoMP4MimeType,
video_webm_codecs()));
}
IN_PROC_BROWSER_TEST_F(EncryptedMediaSupportedTypesWidevineTest, Audio_MP4) {
// Valid audio types.
EXPECT_WV_PROPRIETARY(
IsSupportedByKeySystem(kWidevine, kAudioMP4MimeType, audio_mp4_codecs()));
// Non-audio MP4 codecs.
EXPECT_UNSUPPORTED(
IsSupportedByKeySystem(kWidevine, kAudioMP4MimeType, video_mp4_codecs()));
// Invalid or Non-MP4 codec.
EXPECT_UNSUPPORTED(
IsSupportedByKeySystem(kWidevine, kAudioMP4MimeType, invalid_codecs()));
EXPECT_UNSUPPORTED(IsSupportedByKeySystem(kWidevine, kAudioMP4MimeType,
audio_webm_codecs()));
EXPECT_UNSUPPORTED(IsSupportedByKeySystem(kWidevine, kAudioMP4MimeType,
video_webm_codecs()));
}
IN_PROC_BROWSER_TEST_F(EncryptedMediaSupportedTypesWidevineTest, SessionType) {
// Temporary session always supported.
EXPECT_WV_SUCCESS(IsSessionTypeSupported(kWidevine, SessionType::kTemporary));
// Persistent license session support varies by platform.
auto result =
IsSessionTypeSupported(kWidevine, SessionType::kPersistentLicense);
#if defined(OS_CHROMEOS) || defined(OS_WIN) || defined(OS_MACOSX)
// Persistent license session supported by Widevine key system on Windows and
// Mac. On ChromeOS, it is supported when the protected media identifier
// permission is allowed. See kUnsafelyAllowProtectedMediaIdentifierForDomain
// used above.
EXPECT_WV_SUCCESS(result);
#else
EXPECT_UNSUPPORTED(result);
#endif
}
IN_PROC_BROWSER_TEST_F(EncryptedMediaSupportedTypesWidevineTest, Robustness) {
// Robustness is recommended but not required.
EXPECT_WV_SUCCESS(IsVideoRobustnessSupported(kWidevine, nullptr));
EXPECT_WV_SUCCESS(IsVideoRobustnessSupported(kWidevine, ""));
EXPECT_UNSUPPORTED(IsVideoRobustnessSupported(kWidevine, "Invalid String"));
EXPECT_WV_SUCCESS(IsVideoRobustnessSupported(kWidevine, "SW_SECURE_DECODE"));
EXPECT_WV_SUCCESS(IsVideoRobustnessSupported(kWidevine, "SW_SECURE_CRYPTO"));
#if defined(OS_CHROMEOS)
// "HW_SECURE_ALL" supported on ChromeOS when the protected media identifier
// permission is allowed. See kUnsafelyAllowProtectedMediaIdentifierForDomain
// used above.
EXPECT_WV_SUCCESS(IsVideoRobustnessSupported(kWidevine, "HW_SECURE_ALL"));
#else
EXPECT_UNSUPPORTED(IsVideoRobustnessSupported(kWidevine, "HW_SECURE_ALL"));
#endif
// Robustness is recommended but not required.
EXPECT_WV_SUCCESS(IsAudioRobustnessSupported(kWidevine, nullptr));
EXPECT_WV_SUCCESS(IsAudioRobustnessSupported(kWidevine, ""));
EXPECT_UNSUPPORTED(IsAudioRobustnessSupported(kWidevine, "Invalid String"));
EXPECT_WV_SUCCESS(IsAudioRobustnessSupported(kWidevine, "SW_SECURE_CRYPTO"));
#if defined(OS_CHROMEOS)
// "SW_SECURE_DECODE" and "HW_SECURE_ALL" supported on ChromeOS when the
// protected media identifier permission is allowed. See
// kUnsafelyAllowProtectedMediaIdentifierForDomain used above.
EXPECT_WV_SUCCESS(IsAudioRobustnessSupported(kWidevine, "SW_SECURE_DECODE"));
EXPECT_WV_SUCCESS(IsAudioRobustnessSupported(kWidevine, "HW_SECURE_ALL"));
#else
EXPECT_UNSUPPORTED(IsAudioRobustnessSupported(kWidevine, "SW_SECURE_DECODE"));
EXPECT_UNSUPPORTED(IsAudioRobustnessSupported(kWidevine, "HW_SECURE_ALL"));
#endif
}
//
// Misc failure test cases.
//
#if BUILDFLAG(ENABLE_LIBRARY_CDMS)
IN_PROC_BROWSER_TEST_F(EncryptedMediaSupportedTypesTest,
ClearKeyCdmNotRegistered) {
// External Clear Key will not be supported because Clear Key CDM is not
// registered on the command line.
EXPECT_UNSUPPORTED(IsSupportedByKeySystem(
kExternalClearKey, kVideoWebMMimeType, video_webm_codecs()));
// Clear Key should always be supported.
EXPECT_SUCCESS(IsSupportedByKeySystem(kClearKey, kVideoWebMMimeType,
video_webm_codecs()));
}
IN_PROC_BROWSER_TEST_F(
EncryptedMediaSupportedTypesClearKeyCdmRegisteredWithWrongPathTest,
Basic) {
// External Clear Key will not be supported because Clear Key CDM is
// registered with the wrong path.
EXPECT_UNSUPPORTED(IsSupportedByKeySystem(
kExternalClearKey, kVideoWebMMimeType, video_webm_codecs()));
// Clear Key should always be supported.
EXPECT_SUCCESS(IsSupportedByKeySystem(kClearKey, kVideoWebMMimeType,
video_webm_codecs()));
}
#endif // BUILDFLAG(ENABLE_LIBRARY_CDMS)