This source file includes following definitions.
- IsMSESupported
- CurrentKeySystem
- CurrentSourceType
- TestSimplePlayback
- TestFrameSizeChange
- TestConfigChange
- RunEncryptedMediaTest
- RunSimpleEncryptedMediaTest
- AddWaitForTitles
- SetUpCommandLine
- IN_PROC_BROWSER_TEST_P
- IN_PROC_BROWSER_TEST_P
- IN_PROC_BROWSER_TEST_P
- IN_PROC_BROWSER_TEST_P
- IN_PROC_BROWSER_TEST_P
- IN_PROC_BROWSER_TEST_P
- IN_PROC_BROWSER_TEST_P
- IN_PROC_BROWSER_TEST_F
#include "base/command_line.h"
#include "base/path_service.h"
#include "base/strings/utf_string_conversions.h"
#include "base/win/windows_version.h"
#include "content/browser/media/media_browsertest.h"
#include "content/public/common/content_switches.h"
#include "content/public/test/browser_test_utils.h"
#include "content/shell/browser/shell.h"
#if defined(OS_ANDROID)
#include "base/android/build_info.h"
#endif
const char kClearKeyKeySystem[] = "webkit-org.w3.clearkey";
const char kWebMAudioOnly[] = "audio/webm; codecs=\"vorbis\"";
const char kWebMVideoOnly[] = "video/webm; codecs=\"vp8\"";
const char kWebMAudioVideo[] = "video/webm; codecs=\"vorbis, vp8\"";
const char kEmeKeyError[] = "KEYERROR";
const char kEmeNotSupportedError[] = "NOTSUPPORTEDERROR";
enum SrcType {
SRC,
MSE
};
namespace content {
static bool IsMSESupported() {
#if defined(OS_ANDROID)
if (base::android::BuildInfo::GetInstance()->sdk_int() < 16) {
VLOG(0) << "MSE is only supported in Android 4.1 and later.";
return false;
}
#endif
return true;
}
class EncryptedMediaTest : public content::MediaBrowserTest,
public testing::WithParamInterface<std::tr1::tuple<const char*, SrcType> > {
public:
const char* CurrentKeySystem() {
return std::tr1::get<0>(GetParam());
}
SrcType CurrentSourceType() {
return std::tr1::get<1>(GetParam());
}
void TestSimplePlayback(const char* encrypted_media, const char* media_type) {
RunSimpleEncryptedMediaTest(
encrypted_media, media_type, CurrentKeySystem(), CurrentSourceType());
}
void TestFrameSizeChange() {
RunEncryptedMediaTest("encrypted_frame_size_change.html",
"frame_size_change-av-enc-v.webm", kWebMAudioVideo,
CurrentKeySystem(), CurrentSourceType(), kEnded);
}
void TestConfigChange() {
if (CurrentSourceType() != MSE || !IsMSESupported()) {
VLOG(0) << "Skipping test - config change test requires MSE.";
return;
}
std::vector<StringPair> query_params;
query_params.push_back(std::make_pair("keysystem", CurrentKeySystem()));
query_params.push_back(std::make_pair("runencrypted", "1"));
RunMediaTestPage("mse_config_change.html", &query_params, kEnded, true);
}
void RunEncryptedMediaTest(const char* html_page,
const char* media_file,
const char* media_type,
const char* key_system,
SrcType src_type,
const char* expectation) {
if (src_type == MSE && !IsMSESupported()) {
VLOG(0) << "Skipping test - MSE not supported.";
return;
}
std::vector<StringPair> query_params;
query_params.push_back(std::make_pair("mediafile", media_file));
query_params.push_back(std::make_pair("mediatype", media_type));
query_params.push_back(std::make_pair("keysystem", key_system));
if (src_type == MSE)
query_params.push_back(std::make_pair("usemse", "1"));
RunMediaTestPage(html_page, &query_params, expectation, true);
}
void RunSimpleEncryptedMediaTest(const char* media_file,
const char* media_type,
const char* key_system,
SrcType src_type) {
RunEncryptedMediaTest("encrypted_media_player.html", media_file,
media_type, key_system, src_type, kEnded);
}
protected:
virtual void AddWaitForTitles(content::TitleWatcher* title_watcher) OVERRIDE {
MediaBrowserTest::AddWaitForTitles(title_watcher);
title_watcher->AlsoWaitForTitle(base::ASCIIToUTF16(kEmeNotSupportedError));
title_watcher->AlsoWaitForTitle(base::ASCIIToUTF16(kEmeKeyError));
}
#if defined(OS_ANDROID)
virtual void SetUpCommandLine(CommandLine* command_line) OVERRIDE {
command_line->AppendSwitch(
switches::kDisableGestureRequirementForMediaPlayback);
}
#endif
};
using ::testing::Combine;
using ::testing::Values;
#if !defined(OS_ANDROID)
INSTANTIATE_TEST_CASE_P(SRC_ClearKey, EncryptedMediaTest,
Combine(Values(kClearKeyKeySystem), Values(SRC)));
#endif
INSTANTIATE_TEST_CASE_P(MSE_ClearKey, EncryptedMediaTest,
Combine(Values(kClearKeyKeySystem), Values(MSE)));
IN_PROC_BROWSER_TEST_P(EncryptedMediaTest, Playback_AudioOnly_WebM) {
TestSimplePlayback("bear-a-enc_a.webm", kWebMAudioOnly);
}
IN_PROC_BROWSER_TEST_P(EncryptedMediaTest, Playback_AudioClearVideo_WebM) {
TestSimplePlayback("bear-320x240-av-enc_a.webm", kWebMAudioVideo);
}
IN_PROC_BROWSER_TEST_P(EncryptedMediaTest, Playback_VideoAudio_WebM) {
TestSimplePlayback("bear-320x240-av-enc_av.webm", kWebMAudioVideo);
}
IN_PROC_BROWSER_TEST_P(EncryptedMediaTest, Playback_VideoOnly_WebM) {
TestSimplePlayback("bear-320x240-v-enc_v.webm", kWebMVideoOnly);
}
IN_PROC_BROWSER_TEST_P(EncryptedMediaTest, Playback_VideoClearAudio_WebM) {
TestSimplePlayback("bear-320x240-av-enc_v.webm", kWebMAudioVideo);
}
IN_PROC_BROWSER_TEST_P(EncryptedMediaTest, ConfigChangeVideo) {
TestConfigChange();
}
IN_PROC_BROWSER_TEST_P(EncryptedMediaTest, FrameSizeChangeVideo) {
#if defined(OS_WIN)
if (base::win::GetVersion() < base::win::VERSION_VISTA)
return;
#endif
TestFrameSizeChange();
}
IN_PROC_BROWSER_TEST_F(EncryptedMediaTest, UnknownKeySystemThrowsException) {
RunEncryptedMediaTest("encrypted_media_player.html", "bear-a-enc_a.webm",
kWebMAudioOnly, "com.example.foo", MSE,
kEmeNotSupportedError);
}
}