1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217
|
// Copyright (c) 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 "base/command_line.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
// Available key systems.
const char kClearKeyKeySystem[] = "webkit-org.w3.clearkey";
// Supported media types.
const char kWebMAudioOnly[] = "audio/webm; codecs=\"vorbis\"";
const char kWebMVideoOnly[] = "video/webm; codecs=\"vp8\"";
const char kWebMAudioVideo[] = "video/webm; codecs=\"vorbis, vp8\"";
// EME-specific test results and errors.
const char kEmeKeyError[] = "KEYERROR";
const char kEmeNotSupportedError[] = "NOTSUPPORTEDERROR";
const char kDefaultEmePlayer[] = "eme_player.html";
// The type of video src used to load media.
enum SrcType {
SRC,
MSE
};
namespace content {
// MSE is available on all desktop platforms and on Android 4.1 and later.
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 // defined(OS_ANDROID)
return true;
}
// Tests encrypted media playback with a combination of parameters:
// - char*: Key system name.
// - bool: True to load media using MSE, otherwise use src.
class EncryptedMediaTest : public content::MediaBrowserTest,
public testing::WithParamInterface<std::tr1::tuple<const char*, SrcType> > {
public:
// Can only be used in parameterized (*_P) tests.
const std::string CurrentKeySystem() {
return std::tr1::get<0>(GetParam());
}
// Can only be used in parameterized (*_P) tests.
SrcType CurrentSourceType() {
return std::tr1::get<1>(GetParam());
}
void TestSimplePlayback(const std::string& encrypted_media,
const std::string& 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;
}
base::StringPairs query_params;
query_params.push_back(std::make_pair("keySystem", CurrentKeySystem()));
query_params.push_back(std::make_pair("runEncrypted", "1"));
query_params.push_back(std::make_pair("usePrefixedEME", "1"));
RunMediaTestPage("mse_config_change.html", query_params, kEnded, true);
}
void RunEncryptedMediaTest(const std::string& html_page,
const std::string& media_file,
const std::string& media_type,
const std::string& key_system,
SrcType src_type,
const std::string& expectation) {
if (src_type == MSE && !IsMSESupported()) {
VLOG(0) << "Skipping test - MSE not supported.";
return;
}
base::StringPairs 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"));
query_params.push_back(std::make_pair("usePrefixedEME", "1"));
RunMediaTestPage(html_page, query_params, expectation, true);
}
void RunSimpleEncryptedMediaTest(const std::string& media_file,
const std::string& media_type,
const std::string& key_system,
SrcType src_type) {
RunEncryptedMediaTest(kDefaultEmePlayer,
media_file,
media_type,
key_system,
src_type,
kEnded);
}
protected:
// We want to fail quickly when a test fails because an error is encountered.
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(base::CommandLine* command_line) override {
command_line->AppendSwitch(
switches::kDisableGestureRequirementForMediaPlayback);
}
#endif
};
using ::testing::Combine;
using ::testing::Values;
#if !defined(OS_ANDROID)
// Encrypted media playback with SRC is not supported on Android.
INSTANTIATE_TEST_CASE_P(SRC_ClearKey, EncryptedMediaTest,
Combine(Values(kClearKeyKeySystem), Values(SRC)));
#endif // !defined(OS_ANDROID)
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, Playback_AudioOnly_WebM_Opus) {
// Opus is not supported on Android. http://crbug.com/318436
#if defined(OS_ANDROID)
return;
#endif
TestSimplePlayback("bear-320x240-opus-a_enc-a.webm", kWebMAudioOnly);
}
IN_PROC_BROWSER_TEST_P(EncryptedMediaTest, Playback_VideoAudio_WebM_Opus) {
// Opus is not supported on Android. http://crbug.com/318436
#if defined(OS_ANDROID)
return;
#endif
TestSimplePlayback("bear-320x240-opus-av_enc-av.webm", kWebMAudioVideo);
}
IN_PROC_BROWSER_TEST_P(EncryptedMediaTest, Playback_VideoClearAudio_WebM_Opus) {
// Opus is not supported on Android. http://crbug.com/318436
#if defined(OS_ANDROID)
return;
#endif
TestSimplePlayback("bear-320x240-opus-av_enc-v.webm", kWebMAudioVideo);
}
IN_PROC_BROWSER_TEST_P(EncryptedMediaTest, ConfigChangeVideo) {
TestConfigChange();
}
IN_PROC_BROWSER_TEST_P(EncryptedMediaTest, FrameSizeChangeVideo) {
// Times out on Windows XP. http://crbug.com/171937
#if defined(OS_WIN)
if (base::win::GetVersion() < base::win::VERSION_VISTA)
return;
#endif
TestFrameSizeChange();
}
IN_PROC_BROWSER_TEST_F(EncryptedMediaTest, UnknownKeySystemThrowsException) {
RunEncryptedMediaTest(kDefaultEmePlayer,
"bear-a_enc-a.webm",
kWebMAudioOnly,
"com.example.foo",
MSE,
kEmeNotSupportedError);
}
} // namespace content
|