blob: 42c8e9dcf246d8b44ac2e63975c0f7c213b4b3bb [file] [log] [blame]
[email protected]63dc9072013-09-12 06:20:471// Copyright 2013 The Chromium Authors. All rights reserved.
2// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
dchengc16dc8092016-04-08 23:12:565#include <memory>
dchenge73d8520c2015-12-27 01:19:096#include <utility>
7
[email protected]63dc9072013-09-12 06:20:478#include "base/command_line.h"
9#include "base/path_service.h"
10#include "base/strings/utf_string_conversions.h"
11#include "base/win/windows_version.h"
avi6846aef2015-12-26 01:09:3812#include "build/build_config.h"
[email protected]63dc9072013-09-12 06:20:4713#include "chrome/browser/media/media_browsertest.h"
[email protected]df06a3e2014-01-31 21:36:5914#include "chrome/browser/media/test_license_server.h"
15#include "chrome/browser/media/wv_test_license_server_config.h"
[email protected]63dc9072013-09-12 06:20:4716#include "chrome/browser/ui/browser.h"
17#include "chrome/browser/ui/tabs/tab_strip_model.h"
18#include "chrome/common/chrome_switches.h"
xhwang3be44be2016-05-25 17:24:4919#include "chrome/test/base/test_launcher_utils.h"
brettw90e92602015-10-10 00:12:4020#include "content/public/common/content_switches.h"
[email protected]63dc9072013-09-12 06:20:4721#include "content/public/test/browser_test_utils.h"
[email protected]1be9fa072014-03-21 22:50:2922#include "testing/gtest/include/gtest/gtest-spi.h"
[email protected]6479b192013-10-19 18:28:0423#if defined(OS_ANDROID)
24#include "base/android/build_info.h"
25#endif
[email protected]63dc9072013-09-12 06:20:4726
[email protected]63dc9072013-09-12 06:20:4727#if defined(ENABLE_PEPPER_CDMS)
brettwf5431b3d2016-06-07 23:14:3728#include "chrome/browser/media/pepper_cdm_test_constants.h"
xhwangb9417142016-05-18 22:23:3629#include "chrome/browser/media/pepper_cdm_test_helper.h"
[email protected]63dc9072013-09-12 06:20:4730#endif
[email protected]1825e772013-10-08 06:39:1131
xhwangb9417142016-05-18 22:23:3632#include "widevine_cdm_version.h" // In SHARED_INTERMEDIATE_DIR.
[email protected]63dc9072013-09-12 06:20:4733
34// Available key systems.
[email protected]a32ef592014-03-07 19:11:1535const char kClearKeyKeySystem[] = "org.w3.clearkey";
[email protected]ab998e82013-11-22 20:31:3536const char kExternalClearKeyKeySystem[] = "org.chromium.externalclearkey";
xhwang640ef5d2016-08-17 16:46:0837
38// Variants of External Clear Key key system to test different scenarios.
39// To add a new variant, make sure you also update:
40// - media/test/data/eme_player_js/globals.js
41// - AddExternalClearKey() in chrome_key_systems.cc
42// - CreateCdmInstance() in clear_key_cdm.cc
xhwang0cfb5282016-08-25 03:33:2543const char kExternalClearKeyRenewalKeySystem[] =
44 "org.chromium.externalclearkey.renewal";
[email protected]34afd582013-12-20 07:26:1845const char kExternalClearKeyFileIOTestKeySystem[] =
46 "org.chromium.externalclearkey.fileiotest";
[email protected]ab998e82013-11-22 20:31:3547const char kExternalClearKeyInitializeFailKeySystem[] =
48 "org.chromium.externalclearkey.initializefail";
xhwang640ef5d2016-08-17 16:46:0849const char kExternalClearKeyOutputProtectionTestKeySystem[] =
50 "org.chromium.externalclearkey.outputprotectiontest";
[email protected]a27d34ab2014-01-09 04:23:2951const char kExternalClearKeyCrashKeySystem[] =
52 "org.chromium.externalclearkey.crash";
[email protected]63dc9072013-09-12 06:20:4753
54// Supported media types.
[email protected]095ccbe42013-09-26 00:06:4255const char kWebMAudioOnly[] = "audio/webm; codecs=\"vorbis\"";
56const char kWebMVideoOnly[] = "video/webm; codecs=\"vp8\"";
57const char kWebMAudioVideo[] = "video/webm; codecs=\"vorbis, vp8\"";
jamescook6107ed82014-11-06 06:59:2158const char kWebMVP9VideoOnly[] = "video/webm; codecs=\"vp9\"";
[email protected]095ccbe42013-09-26 00:06:4259#if defined(USE_PROPRIETARY_CODECS)
60const char kMP4AudioOnly[] = "audio/mp4; codecs=\"mp4a.40.2\"";
61const char kMP4VideoOnly[] = "video/mp4; codecs=\"avc1.4D4041\"";
62#endif // defined(USE_PROPRIETARY_CODECS)
[email protected]63dc9072013-09-12 06:20:4763
[email protected]0af5dfa2014-02-07 22:33:4464// Sessions to load.
65const char kNoSessionToLoad[] = "";
66const char kLoadableSession[] = "LoadableSession";
67const char kUnknownSession[] = "UnknownSession";
68
[email protected]2e850f12013-09-18 01:27:2969// EME-specific test results and errors.
xhwang640ef5d2016-08-17 16:46:0870const char kUnitTestSuccess[] = "UNIT_TEST_SUCCESS";
jrummell0c6ba542015-07-08 18:04:4471const char kEmeNotSupportedError[] = "NOTSUPPORTEDERROR";
72const char kEmeGenerateRequestFailed[] = "EME_GENERATEREQUEST_FAILED";
jrummell14fae6f2015-07-10 20:40:1573const char kEmeSessionNotFound[] = "EME_SESSION_NOT_FOUND";
jrummell0c6ba542015-07-08 18:04:4474const char kEmeLoadFailed[] = "EME_LOAD_FAILED";
75const char kEmeUpdateFailed[] = "EME_UPDATE_FAILED";
76const char kEmeErrorEvent[] = "EME_ERROR_EVENT";
77const char kEmeMessageUnexpectedType[] = "EME_MESSAGE_UNEXPECTED_TYPE";
ddorwinfdb9a2b2016-02-22 22:25:1078const char kEmeRenewalMissingHeader[] = "EME_RENEWAL_MISSING_HEADER";
[email protected]e11d89d2014-06-19 11:36:3179
80const char kDefaultEmePlayer[] = "eme_player.html";
[email protected]63dc9072013-09-12 06:20:4781
82// The type of video src used to load media.
83enum SrcType {
84 SRC,
85 MSE
86};
87
jrummellb3944632015-03-14 00:19:4288// Whether the video should be played once or twice.
89enum class PlayTwice { NO, YES };
90
jrummellc015cb962015-07-17 00:41:3091// Format of a container when testing different streams.
92enum class EncryptedContainer {
93 CLEAR_WEBM,
94 CLEAR_MP4,
95 ENCRYPTED_WEBM,
96 ENCRYPTED_MP4
97};
98
[email protected]6479b192013-10-19 18:28:0499// MSE is available on all desktop platforms and on Android 4.1 and later.
100static bool IsMSESupported() {
101#if defined(OS_ANDROID)
102 if (base::android::BuildInfo::GetInstance()->sdk_int() < 16) {
anujk.sharma9da298e12014-11-07 04:48:43103 DVLOG(0) << "MSE is only supported in Android 4.1 and later.";
[email protected]6479b192013-10-19 18:28:04104 return false;
105 }
106#endif // defined(OS_ANDROID)
107 return true;
108}
109
[email protected]e6bf64142013-10-18 23:07:54110// Base class for encrypted media tests.
111class EncryptedMediaTestBase : public MediaBrowserTest {
[email protected]63dc9072013-09-12 06:20:47112 public:
[email protected]ab998e82013-11-22 20:31:35113 bool IsExternalClearKey(const std::string& key_system) {
ddorwin40312df2016-02-26 01:25:01114 if (key_system == kExternalClearKeyKeySystem)
115 return true;
116 std::string prefix = std::string(kExternalClearKeyKeySystem) + '.';
117 return key_system.substr(0, prefix.size()) == prefix;
[email protected]63dc9072013-09-12 06:20:47118 }
119
[email protected]1825e772013-10-08 06:39:11120#if defined(WIDEVINE_CDM_AVAILABLE)
[email protected]ab998e82013-11-22 20:31:35121 bool IsWidevine(const std::string& key_system) {
122 return key_system == kWidevineKeySystem;
[email protected]1825e772013-10-08 06:39:11123 }
124#endif // defined(WIDEVINE_CDM_AVAILABLE)
125
[email protected]8a229322014-07-22 23:33:07126 void RunEncryptedMediaTestPage(
127 const std::string& html_page,
128 const std::string& key_system,
anand.ratn2636d972014-09-30 04:06:58129 base::StringPairs& query_params,
[email protected]8a229322014-07-22 23:33:07130 const std::string& expected_title) {
anand.ratn2636d972014-09-30 04:06:58131 base::StringPairs new_query_params = query_params;
[email protected]8a229322014-07-22 23:33:07132 StartLicenseServerIfNeeded(key_system, &new_query_params);
133 RunMediaTestPage(html_page, new_query_params, expected_title, true);
[email protected]df06a3e2014-01-31 21:36:59134 }
135
[email protected]0af5dfa2014-02-07 22:33:44136 // Tests |html_page| using |media_file| (with |media_type|) and |key_system|.
137 // When |session_to_load| is not empty, the test will try to load
138 // |session_to_load| with stored keys, instead of creating a new session
139 // and trying to update it with licenses.
140 // When |force_invalid_response| is true, the test will provide invalid
141 // responses, which should trigger errors.
142 // TODO(xhwang): Find an easier way to pass multiple configuration test
143 // options.
[email protected]df06a3e2014-01-31 21:36:59144 void RunEncryptedMediaTest(const std::string& html_page,
145 const std::string& media_file,
146 const std::string& media_type,
147 const std::string& key_system,
[email protected]1825e772013-10-08 06:39:11148 SrcType src_type,
[email protected]0af5dfa2014-02-07 22:33:44149 const std::string& session_to_load,
[email protected]df06a3e2014-01-31 21:36:59150 bool force_invalid_response,
jrummellb3944632015-03-14 00:19:42151 PlayTwice play_twice,
[email protected]df06a3e2014-01-31 21:36:59152 const std::string& expected_title) {
[email protected]6479b192013-10-19 18:28:04153 if (src_type == MSE && !IsMSESupported()) {
anujk.sharma9da298e12014-11-07 04:48:43154 DVLOG(0) << "Skipping test - MSE not supported.";
[email protected]6479b192013-10-19 18:28:04155 return;
156 }
anand.ratn2636d972014-09-30 04:06:58157 base::StringPairs query_params;
[email protected]df06a3e2014-01-31 21:36:59158 query_params.push_back(std::make_pair("mediaFile", media_file));
159 query_params.push_back(std::make_pair("mediaType", media_type));
160 query_params.push_back(std::make_pair("keySystem", key_system));
[email protected]63dc9072013-09-12 06:20:47161 if (src_type == MSE)
[email protected]df06a3e2014-01-31 21:36:59162 query_params.push_back(std::make_pair("useMSE", "1"));
163 if (force_invalid_response)
164 query_params.push_back(std::make_pair("forceInvalidResponse", "1"));
[email protected]0af5dfa2014-02-07 22:33:44165 if (!session_to_load.empty())
166 query_params.push_back(std::make_pair("sessionToLoad", session_to_load));
jrummellb3944632015-03-14 00:19:42167 if (play_twice == PlayTwice::YES)
168 query_params.push_back(std::make_pair("playTwice", "1"));
[email protected]8a229322014-07-22 23:33:07169 RunEncryptedMediaTestPage(html_page, key_system, query_params,
[email protected]df06a3e2014-01-31 21:36:59170 expected_title);
[email protected]63dc9072013-09-12 06:20:47171 }
172
[email protected]df06a3e2014-01-31 21:36:59173 void RunSimpleEncryptedMediaTest(const std::string& media_file,
174 const std::string& media_type,
175 const std::string& key_system,
ddorwinfdb9a2b2016-02-22 22:25:10176 SrcType src_type) {
[email protected]df06a3e2014-01-31 21:36:59177 std::string expected_title = kEnded;
jrummell0c6ba542015-07-08 18:04:44178 if (!IsPlayBackPossible(key_system)) {
ddorwinfdb9a2b2016-02-22 22:25:10179 expected_title = kEmeUpdateFailed;
jrummell0c6ba542015-07-08 18:04:44180 }
[email protected]1825e772013-10-08 06:39:11181
jrummellb3944632015-03-14 00:19:42182 RunEncryptedMediaTest(kDefaultEmePlayer, media_file, media_type, key_system,
ddorwinfdb9a2b2016-02-22 22:25:10183 src_type, kNoSessionToLoad, false, PlayTwice::NO,
184 expected_title);
[email protected]df06a3e2014-01-31 21:36:59185 // Check KeyMessage received for all key systems.
186 bool receivedKeyMessage = false;
187 EXPECT_TRUE(content::ExecuteScriptAndExtractBool(
188 browser()->tab_strip_model()->GetActiveWebContents(),
[email protected]e11d89d2014-06-19 11:36:31189 "window.domAutomationController.send("
190 "document.querySelector('video').receivedKeyMessage);",
[email protected]df06a3e2014-01-31 21:36:59191 &receivedKeyMessage));
192 EXPECT_TRUE(receivedKeyMessage);
193 }
194
[email protected]8a229322014-07-22 23:33:07195 // Starts a license server if available for the |key_system| and adds a
196 // 'licenseServerURL' query parameter to |query_params|.
[email protected]df06a3e2014-01-31 21:36:59197 void StartLicenseServerIfNeeded(const std::string& key_system,
anand.ratn2636d972014-09-30 04:06:58198 base::StringPairs* query_params) {
dchengc16dc8092016-04-08 23:12:56199 std::unique_ptr<TestLicenseServerConfig> config =
200 GetServerConfig(key_system);
[email protected]df06a3e2014-01-31 21:36:59201 if (!config)
202 return;
dchenge73d8520c2015-12-27 01:19:09203 license_server_.reset(new TestLicenseServer(std::move(config)));
[email protected]df06a3e2014-01-31 21:36:59204 EXPECT_TRUE(license_server_->Start());
[email protected]8a229322014-07-22 23:33:07205 query_params->push_back(
206 std::make_pair("licenseServerURL", license_server_->GetServerURL()));
[email protected]df06a3e2014-01-31 21:36:59207 }
208
209 bool IsPlayBackPossible(const std::string& key_system) {
210#if defined(WIDEVINE_CDM_AVAILABLE)
211 if (IsWidevine(key_system) && !GetServerConfig(key_system))
212 return false;
213#endif // defined(WIDEVINE_CDM_AVAILABLE)
214 return true;
215 }
216
dchengc16dc8092016-04-08 23:12:56217 std::unique_ptr<TestLicenseServerConfig> GetServerConfig(
[email protected]df06a3e2014-01-31 21:36:59218 const std::string& key_system) {
219#if defined(WIDEVINE_CDM_AVAILABLE)
220 if (IsWidevine(key_system)) {
dchengc16dc8092016-04-08 23:12:56221 std::unique_ptr<TestLicenseServerConfig> config(
222 new WVTestLicenseServerConfig);
[email protected]df06a3e2014-01-31 21:36:59223 if (config->IsPlatformSupported())
dcheng7c133cc2015-12-31 06:57:59224 return config;
[email protected]df06a3e2014-01-31 21:36:59225 }
226#endif // defined(WIDEVINE_CDM_AVAILABLE)
dcheng7c133cc2015-12-31 06:57:59227 return nullptr;
[email protected]1825e772013-10-08 06:39:11228 }
229
[email protected]63dc9072013-09-12 06:20:47230 protected:
dchengc16dc8092016-04-08 23:12:56231 std::unique_ptr<TestLicenseServer> license_server_;
[email protected]df06a3e2014-01-31 21:36:59232
[email protected]2e850f12013-09-18 01:27:29233 // We want to fail quickly when a test fails because an error is encountered.
dchengd7e84a052014-10-22 00:18:51234 void AddWaitForTitles(content::TitleWatcher* title_watcher) override {
[email protected]2e850f12013-09-18 01:27:29235 MediaBrowserTest::AddWaitForTitles(title_watcher);
[email protected]6778fed2013-12-24 20:09:37236 title_watcher->AlsoWaitForTitle(base::ASCIIToUTF16(kEmeNotSupportedError));
jrummell0c6ba542015-07-08 18:04:44237 title_watcher->AlsoWaitForTitle(
238 base::ASCIIToUTF16(kEmeGenerateRequestFailed));
jrummell14fae6f2015-07-10 20:40:15239 title_watcher->AlsoWaitForTitle(base::ASCIIToUTF16(kEmeSessionNotFound));
jrummell0c6ba542015-07-08 18:04:44240 title_watcher->AlsoWaitForTitle(base::ASCIIToUTF16(kEmeLoadFailed));
241 title_watcher->AlsoWaitForTitle(base::ASCIIToUTF16(kEmeUpdateFailed));
242 title_watcher->AlsoWaitForTitle(base::ASCIIToUTF16(kEmeErrorEvent));
243 title_watcher->AlsoWaitForTitle(
244 base::ASCIIToUTF16(kEmeMessageUnexpectedType));
245 title_watcher->AlsoWaitForTitle(
ddorwinfdb9a2b2016-02-22 22:25:10246 base::ASCIIToUTF16(kEmeRenewalMissingHeader));
[email protected]2e850f12013-09-18 01:27:29247 }
248
avi556c05022014-12-22 23:31:43249 void SetUpCommandLine(base::CommandLine* command_line) override {
[email protected]2289b432014-08-08 17:52:11250 command_line->AppendSwitch(
251 switches::kDisableGestureRequirementForMediaPlayback);
[email protected]2289b432014-08-08 17:52:11252 }
253
xhwang3be44be2016-05-25 17:24:49254#if defined(ENABLE_PEPPER_CDMS)
255 void SetUpDefaultCommandLine(base::CommandLine* command_line) override {
256 base::CommandLine default_command_line(base::CommandLine::NO_PROGRAM);
257 InProcessBrowserTest::SetUpDefaultCommandLine(&default_command_line);
258 test_launcher_utils::RemoveCommandLineSwitch(
259 default_command_line, switches::kDisableComponentUpdate, command_line);
260 }
261#endif // defined(ENABLE_PEPPER_CDMS)
262
[email protected]df06a3e2014-01-31 21:36:59263 void SetUpCommandLineForKeySystem(const std::string& key_system,
avi556c05022014-12-22 23:31:43264 base::CommandLine* command_line) {
[email protected]df06a3e2014-01-31 21:36:59265 if (GetServerConfig(key_system))
266 // Since the web and license servers listen on different ports, we need to
267 // disable web-security to send license requests to the license server.
268 // TODO(shadi): Add port forwarding to the test web server configuration.
269 command_line->AppendSwitch(switches::kDisableWebSecurity);
270
[email protected]e6bf64142013-10-18 23:07:54271#if defined(ENABLE_PEPPER_CDMS)
272 if (IsExternalClearKey(key_system)) {
xhwangc3a252b2016-05-23 02:35:48273 RegisterPepperCdm(command_line, kClearKeyCdmBaseDirectory,
274 kClearKeyCdmAdapterFileName, kClearKeyCdmDisplayName,
275 kClearKeyCdmPepperMimeType);
[email protected]e6bf64142013-10-18 23:07:54276 }
[email protected]e6bf64142013-10-18 23:07:54277#endif // defined(ENABLE_PEPPER_CDMS)
278 }
[email protected]e6bf64142013-10-18 23:07:54279};
280
281#if defined(ENABLE_PEPPER_CDMS)
[email protected]ab998e82013-11-22 20:31:35282// Tests encrypted media playback using ExternalClearKey key system in
283// decrypt-and-decode mode.
[email protected]e6bf64142013-10-18 23:07:54284class ECKEncryptedMediaTest : public EncryptedMediaTestBase {
[email protected]0af5dfa2014-02-07 22:33:44285 public:
286 // We use special |key_system| names to do non-playback related tests, e.g.
287 // kExternalClearKeyFileIOTestKeySystem is used to test file IO.
288 void TestNonPlaybackCases(const std::string& key_system,
289 const std::string& expected_title) {
290 // Since we do not test playback, arbitrarily choose a test file and source
291 // type.
ddorwinfdb9a2b2016-02-22 22:25:10292 RunEncryptedMediaTest(kDefaultEmePlayer, "bear-a_enc-a.webm",
293 kWebMAudioOnly, key_system, SRC, kNoSessionToLoad,
294 false, PlayTwice::NO, expected_title);
jrummell19f2c902015-02-11 01:17:50295 }
296
xhwang0cfb5282016-08-25 03:33:25297 void TestPlaybackCase(const std::string& key_system,
298 const std::string& session_to_load,
jrummell19f2c902015-02-11 01:17:50299 const std::string& expected_title) {
300 RunEncryptedMediaTest(kDefaultEmePlayer, "bear-320x240-v_enc-v.webm",
xhwang0cfb5282016-08-25 03:33:25301 kWebMVideoOnly, key_system, SRC, session_to_load,
302 false, PlayTwice::NO, expected_title);
jrummell19f2c902015-02-11 01:17:50303 }
304
jrummellc467d232014-10-21 17:55:22305 protected:
avi556c05022014-12-22 23:31:43306 void SetUpCommandLine(base::CommandLine* command_line) override {
jrummellc467d232014-10-21 17:55:22307 EncryptedMediaTestBase::SetUpCommandLine(command_line);
jrummellc467d232014-10-21 17:55:22308 SetUpCommandLineForKeySystem(kExternalClearKeyKeySystem, command_line);
309 }
310};
311
[email protected]e6bf64142013-10-18 23:07:54312#if defined(WIDEVINE_CDM_AVAILABLE)
313// Tests encrypted media playback using Widevine key system.
314class WVEncryptedMediaTest : public EncryptedMediaTestBase {
315 protected:
Daniel Cheng43ba4a0122014-12-31 06:30:35316 void SetUpCommandLine(base::CommandLine* command_line) override {
[email protected]e6bf64142013-10-18 23:07:54317 EncryptedMediaTestBase::SetUpCommandLine(command_line);
318 SetUpCommandLineForKeySystem(kWidevineKeySystem, command_line);
319 }
320};
[email protected]df06a3e2014-01-31 21:36:59321
[email protected]e6bf64142013-10-18 23:07:54322#endif // defined(WIDEVINE_CDM_AVAILABLE)
323#endif // defined(ENABLE_PEPPER_CDMS)
324
325// Tests encrypted media playback with a combination of parameters:
326// - char*: Key system name.
jrummell19f2c902015-02-11 01:17:50327// - SrcType: Use MSE or SRC.
[email protected]e6bf64142013-10-18 23:07:54328//
329// Note: Only parameterized (*_P) tests can be used. Non-parameterized (*_F)
330// tests will crash at GetParam(). To add non-parameterized tests, use
331// EncryptedMediaTestBase or one of its subclasses (e.g. WVEncryptedMediaTest).
ddorwinfdb9a2b2016-02-22 22:25:10332class EncryptedMediaTest : public EncryptedMediaTestBase,
333 public testing::WithParamInterface<
334 std::tr1::tuple<const char*, SrcType>> {
[email protected]e6bf64142013-10-18 23:07:54335 public:
[email protected]df06a3e2014-01-31 21:36:59336 std::string CurrentKeySystem() {
[email protected]e6bf64142013-10-18 23:07:54337 return std::tr1::get<0>(GetParam());
338 }
339
340 SrcType CurrentSourceType() {
341 return std::tr1::get<1>(GetParam());
342 }
343
[email protected]df06a3e2014-01-31 21:36:59344 void TestSimplePlayback(const std::string& encrypted_media,
345 const std::string& media_type) {
ddorwinfdb9a2b2016-02-22 22:25:10346 RunSimpleEncryptedMediaTest(encrypted_media, media_type, CurrentKeySystem(),
347 CurrentSourceType());
[email protected]e6bf64142013-10-18 23:07:54348 }
349
jrummellb3944632015-03-14 00:19:42350 void TestMultiplePlayback(const std::string& encrypted_media,
351 const std::string& media_type) {
jrummelld9dc7902015-03-16 20:59:28352 DCHECK(IsPlayBackPossible(CurrentKeySystem()));
jrummellb3944632015-03-14 00:19:42353 RunEncryptedMediaTest(kDefaultEmePlayer, encrypted_media, media_type,
354 CurrentKeySystem(), CurrentSourceType(),
ddorwinfdb9a2b2016-02-22 22:25:10355 kNoSessionToLoad, false, PlayTwice::YES, kEnded);
jrummellb3944632015-03-14 00:19:42356 }
357
[email protected]df06a3e2014-01-31 21:36:59358 void RunInvalidResponseTest() {
ddorwinfdb9a2b2016-02-22 22:25:10359 RunEncryptedMediaTest(kDefaultEmePlayer, "bear-320x240-av_enc-av.webm",
360 kWebMAudioVideo, CurrentKeySystem(),
361 CurrentSourceType(), kNoSessionToLoad, true,
362 PlayTwice::NO, kEmeUpdateFailed);
[email protected]df06a3e2014-01-31 21:36:59363 }
364
[email protected]e6bf64142013-10-18 23:07:54365 void TestFrameSizeChange() {
ddorwinfdb9a2b2016-02-22 22:25:10366 RunEncryptedMediaTest("encrypted_frame_size_change.html",
367 "frame_size_change-av_enc-v.webm", kWebMAudioVideo,
368 CurrentKeySystem(), CurrentSourceType(),
369 kNoSessionToLoad, false, PlayTwice::NO, kEnded);
[email protected]e6bf64142013-10-18 23:07:54370 }
371
372 void TestConfigChange() {
[email protected]df06a3e2014-01-31 21:36:59373 DCHECK(IsMSESupported());
anand.ratn2636d972014-09-30 04:06:58374 base::StringPairs query_params;
[email protected]df06a3e2014-01-31 21:36:59375 query_params.push_back(std::make_pair("keySystem", CurrentKeySystem()));
376 query_params.push_back(std::make_pair("runEncrypted", "1"));
377 RunEncryptedMediaTestPage("mse_config_change.html",
378 CurrentKeySystem(),
[email protected]8a229322014-07-22 23:33:07379 query_params,
[email protected]df06a3e2014-01-31 21:36:59380 kEnded);
[email protected]e6bf64142013-10-18 23:07:54381 }
382
jrummellc015cb962015-07-17 00:41:30383 std::string ConvertContainerFormat(EncryptedContainer format) {
384 switch (format) {
385 case EncryptedContainer::CLEAR_MP4:
386 return "CLEAR_MP4";
387 case EncryptedContainer::CLEAR_WEBM:
388 return "CLEAR_WEBM";
389 case EncryptedContainer::ENCRYPTED_MP4:
390 return "ENCRYPTED_MP4";
391 case EncryptedContainer::ENCRYPTED_WEBM:
392 return "ENCRYPTED_WEBM";
393 }
394 NOTREACHED();
395 return "UNKNOWN";
396 }
397
398 void TestDifferentContainers(EncryptedContainer video_format,
399 EncryptedContainer audio_format) {
400 DCHECK(IsMSESupported());
jrummellc015cb962015-07-17 00:41:30401 base::StringPairs query_params;
402 query_params.push_back(std::make_pair("keySystem", CurrentKeySystem()));
403 query_params.push_back(std::make_pair("runEncrypted", "1"));
404 query_params.push_back(
405 std::make_pair("videoFormat", ConvertContainerFormat(video_format)));
406 query_params.push_back(
407 std::make_pair("audioFormat", ConvertContainerFormat(audio_format)));
408 RunEncryptedMediaTestPage("mse_different_containers.html",
409 CurrentKeySystem(), query_params, kEnded);
410 }
411
[email protected]e6bf64142013-10-18 23:07:54412 protected:
avi556c05022014-12-22 23:31:43413 void SetUpCommandLine(base::CommandLine* command_line) override {
[email protected]e6bf64142013-10-18 23:07:54414 EncryptedMediaTestBase::SetUpCommandLine(command_line);
415 SetUpCommandLineForKeySystem(CurrentKeySystem(), command_line);
416 }
[email protected]63dc9072013-09-12 06:20:47417};
418
[email protected]6479b192013-10-19 18:28:04419using ::testing::Combine;
420using ::testing::Values;
421
422#if !defined(OS_ANDROID)
jrummell19f2c902015-02-11 01:17:50423INSTANTIATE_TEST_CASE_P(SRC_ClearKey,
[email protected]a32ef592014-03-07 19:11:15424 EncryptedMediaTest,
ddorwinfdb9a2b2016-02-22 22:25:10425 Combine(Values(kClearKeyKeySystem), Values(SRC)));
[email protected]6479b192013-10-19 18:28:04426#endif // !defined(OS_ANDROID)
427
jrummell77419192014-10-31 21:40:44428INSTANTIATE_TEST_CASE_P(MSE_ClearKey,
[email protected]a32ef592014-03-07 19:11:15429 EncryptedMediaTest,
ddorwinfdb9a2b2016-02-22 22:25:10430 Combine(Values(kClearKeyKeySystem), Values(MSE)));
[email protected]63dc9072013-09-12 06:20:47431
432// External Clear Key is currently only used on platforms that use Pepper CDMs.
433#if defined(ENABLE_PEPPER_CDMS)
[email protected]1ab297a2014-03-26 04:52:12434INSTANTIATE_TEST_CASE_P(SRC_ExternalClearKey,
[email protected]a32ef592014-03-07 19:11:15435 EncryptedMediaTest,
436 Combine(Values(kExternalClearKeyKeySystem),
ddorwinfdb9a2b2016-02-22 22:25:10437 Values(SRC)));
jam79bf1f6c2015-08-13 20:46:04438
[email protected]1ab297a2014-03-26 04:52:12439INSTANTIATE_TEST_CASE_P(MSE_ExternalClearKey,
[email protected]a32ef592014-03-07 19:11:15440 EncryptedMediaTest,
441 Combine(Values(kExternalClearKeyKeySystem),
ddorwinfdb9a2b2016-02-22 22:25:10442 Values(MSE)));
mnissler27025372015-10-19 14:26:23443
mnissler27025372015-10-19 14:26:23444const char kExternalClearKeyDecryptOnlyKeySystem[] =
445 "org.chromium.externalclearkey.decryptonly";
446
[email protected]ab998e82013-11-22 20:31:35447// To reduce test time, only run ExternalClearKeyDecryptOnly with MSE.
[email protected]1ab297a2014-03-26 04:52:12448INSTANTIATE_TEST_CASE_P(MSE_ExternalClearKeyDecryptOnly,
[email protected]a32ef592014-03-07 19:11:15449 EncryptedMediaTest,
450 Combine(Values(kExternalClearKeyDecryptOnlyKeySystem),
ddorwinfdb9a2b2016-02-22 22:25:10451 Values(MSE)));
[email protected]8a229322014-07-22 23:33:07452#endif // defined(ENABLE_PEPPER_CDMS)
[email protected]63dc9072013-09-12 06:20:47453
[email protected]1825e772013-10-08 06:39:11454#if defined(WIDEVINE_CDM_AVAILABLE)
jonross5785b8662015-10-22 21:12:53455#if !defined(OS_CHROMEOS)
[email protected]1ab297a2014-03-26 04:52:12456INSTANTIATE_TEST_CASE_P(MSE_Widevine,
[email protected]a32ef592014-03-07 19:11:15457 EncryptedMediaTest,
ddorwinfdb9a2b2016-02-22 22:25:10458 Combine(Values(kWidevineKeySystem), Values(MSE)));
jonross5785b8662015-10-22 21:12:53459#endif // !defined(OS_CHROMEOS)
[email protected]1825e772013-10-08 06:39:11460#endif // defined(WIDEVINE_CDM_AVAILABLE)
[email protected]63dc9072013-09-12 06:20:47461
[email protected]626e517c2014-08-19 00:49:46462IN_PROC_BROWSER_TEST_P(EncryptedMediaTest, Playback_AudioOnly_WebM) {
[email protected]8a229322014-07-22 23:33:07463 TestSimplePlayback("bear-a_enc-a.webm", kWebMAudioOnly);
[email protected]63dc9072013-09-12 06:20:47464}
465
[email protected]626e517c2014-08-19 00:49:46466IN_PROC_BROWSER_TEST_P(EncryptedMediaTest, Playback_AudioClearVideo_WebM) {
[email protected]8a229322014-07-22 23:33:07467 TestSimplePlayback("bear-320x240-av_enc-a.webm", kWebMAudioVideo);
[email protected]63dc9072013-09-12 06:20:47468}
469
[email protected]626e517c2014-08-19 00:49:46470IN_PROC_BROWSER_TEST_P(EncryptedMediaTest, Playback_VideoAudio_WebM) {
[email protected]8a229322014-07-22 23:33:07471 TestSimplePlayback("bear-320x240-av_enc-av.webm", kWebMAudioVideo);
[email protected]63dc9072013-09-12 06:20:47472}
473
[email protected]626e517c2014-08-19 00:49:46474IN_PROC_BROWSER_TEST_P(EncryptedMediaTest, Playback_VideoOnly_WebM) {
[email protected]8a229322014-07-22 23:33:07475 TestSimplePlayback("bear-320x240-v_enc-v.webm", kWebMVideoOnly);
[email protected]63dc9072013-09-12 06:20:47476}
477
[email protected]626e517c2014-08-19 00:49:46478IN_PROC_BROWSER_TEST_P(EncryptedMediaTest, Playback_VideoClearAudio_WebM) {
[email protected]8a229322014-07-22 23:33:07479 TestSimplePlayback("bear-320x240-av_enc-v.webm", kWebMAudioVideo);
[email protected]63dc9072013-09-12 06:20:47480}
481
jrummell2fe87672015-01-02 19:13:51482IN_PROC_BROWSER_TEST_P(EncryptedMediaTest, Playback_VP9Video_WebM) {
[email protected]8a229322014-07-22 23:33:07483 TestSimplePlayback("bear-320x240-v-vp9_enc-v.webm", kWebMVP9VideoOnly);
[email protected]2b197ac72014-04-11 23:33:52484}
485
jrummell2fe87672015-01-02 19:13:51486IN_PROC_BROWSER_TEST_P(EncryptedMediaTest, Playback_AudioOnly_WebM_Opus) {
sandersd5ec6dcf2014-11-26 20:39:38487 TestSimplePlayback("bear-320x240-opus-a_enc-a.webm", kWebMAudioOnly);
488}
489
490IN_PROC_BROWSER_TEST_P(EncryptedMediaTest, Playback_VideoAudio_WebM_Opus) {
491 TestSimplePlayback("bear-320x240-opus-av_enc-av.webm", kWebMAudioVideo);
492}
493
494IN_PROC_BROWSER_TEST_P(EncryptedMediaTest, Playback_VideoClearAudio_WebM_Opus) {
495 TestSimplePlayback("bear-320x240-opus-av_enc-v.webm", kWebMAudioVideo);
496}
497
jrummellb3944632015-03-14 00:19:42498IN_PROC_BROWSER_TEST_P(EncryptedMediaTest, Playback_Multiple_VideoAudio_WebM) {
jrummelld9dc7902015-03-16 20:59:28499 if (!IsPlayBackPossible(CurrentKeySystem())) {
500 DVLOG(0) << "Skipping test - Playback_Multiple test requires playback.";
501 return;
502 }
jrummellb3944632015-03-14 00:19:42503 TestMultiplePlayback("bear-320x240-av_enc-av.webm", kWebMAudioVideo);
504}
505
[email protected]626e517c2014-08-19 00:49:46506IN_PROC_BROWSER_TEST_P(EncryptedMediaTest, InvalidResponseKeyError) {
[email protected]df06a3e2014-01-31 21:36:59507 RunInvalidResponseTest();
508}
509
[email protected]1825e772013-10-08 06:39:11510IN_PROC_BROWSER_TEST_P(EncryptedMediaTest, ConfigChangeVideo) {
[email protected]df06a3e2014-01-31 21:36:59511 if (CurrentSourceType() != MSE || !IsMSESupported()) {
anujk.sharma9da298e12014-11-07 04:48:43512 DVLOG(0) << "Skipping test - ConfigChange test requires MSE.";
[email protected]df06a3e2014-01-31 21:36:59513 return;
514 }
515 if (!IsPlayBackPossible(CurrentKeySystem())) {
anujk.sharma9da298e12014-11-07 04:48:43516 DVLOG(0) << "Skipping test - ConfigChange test requires video playback.";
[email protected]df06a3e2014-01-31 21:36:59517 return;
518 }
[email protected]1825e772013-10-08 06:39:11519 TestConfigChange();
520}
521
jrummell2fe87672015-01-02 19:13:51522IN_PROC_BROWSER_TEST_P(EncryptedMediaTest, FrameSizeChangeVideo) {
[email protected]63dc9072013-09-12 06:20:47523 // Times out on Windows XP. http://crbug.com/171937
524#if defined(OS_WIN)
525 if (base::win::GetVersion() < base::win::VERSION_VISTA)
526 return;
527#endif
[email protected]df06a3e2014-01-31 21:36:59528 if (!IsPlayBackPossible(CurrentKeySystem())) {
anujk.sharma9da298e12014-11-07 04:48:43529 DVLOG(0) << "Skipping test - FrameSizeChange test requires video playback.";
[email protected]df06a3e2014-01-31 21:36:59530 return;
531 }
[email protected]1825e772013-10-08 06:39:11532 TestFrameSizeChange();
[email protected]63dc9072013-09-12 06:20:47533}
534
535#if defined(USE_PROPRIETARY_CODECS)
Vasilii Sukhanova6b5cff2016-06-21 11:04:37536// Crashes on Mac only. http://crbug.com/621857
537#if defined(OS_MACOSX)
538#define MAYBE_Playback_VideoOnly_MP4 DISABLED_Playback_VideoOnly_MP4
539#else
540#define MAYBE_Playback_VideoOnly_MP4 Playback_VideoOnly_MP4
541#endif
542IN_PROC_BROWSER_TEST_P(EncryptedMediaTest, MAYBE_Playback_VideoOnly_MP4) {
[email protected]63dc9072013-09-12 06:20:47543 // MP4 without MSE is not support yet, http://crbug.com/170793.
[email protected]1825e772013-10-08 06:39:11544 if (CurrentSourceType() != MSE) {
anujk.sharma9da298e12014-11-07 04:48:43545 DVLOG(0) << "Skipping test; Can only play MP4 encrypted streams by MSE.";
[email protected]63dc9072013-09-12 06:20:47546 return;
547 }
[email protected]1825e772013-10-08 06:39:11548 TestSimplePlayback("bear-640x360-v_frag-cenc.mp4", kMP4VideoOnly);
[email protected]63dc9072013-09-12 06:20:47549}
550
551IN_PROC_BROWSER_TEST_P(EncryptedMediaTest, Playback_AudioOnly_MP4) {
[email protected]63dc9072013-09-12 06:20:47552 // MP4 without MSE is not support yet, http://crbug.com/170793.
[email protected]1825e772013-10-08 06:39:11553 if (CurrentSourceType() != MSE) {
anujk.sharma9da298e12014-11-07 04:48:43554 DVLOG(0) << "Skipping test; Can only play MP4 encrypted streams by MSE.";
[email protected]63dc9072013-09-12 06:20:47555 return;
556 }
[email protected]1825e772013-10-08 06:39:11557 TestSimplePlayback("bear-640x360-a_frag-cenc.mp4", kMP4AudioOnly);
[email protected]63dc9072013-09-12 06:20:47558}
jrummellc015cb962015-07-17 00:41:30559
560IN_PROC_BROWSER_TEST_P(EncryptedMediaTest,
561 Playback_EncryptedVideo_MP4_ClearAudio_WEBM) {
562 // MP4 without MSE is not support yet, http://crbug.com/170793.
563 if (CurrentSourceType() != MSE) {
564 DVLOG(0) << "Skipping test; Can only play MP4 encrypted streams by MSE.";
565 return;
566 }
jrummellc015cb962015-07-17 00:41:30567 if (!IsPlayBackPossible(CurrentKeySystem())) {
568 DVLOG(0) << "Skipping test - Test requires video playback.";
569 return;
570 }
571 TestDifferentContainers(EncryptedContainer::ENCRYPTED_MP4,
572 EncryptedContainer::CLEAR_WEBM);
573}
574
575IN_PROC_BROWSER_TEST_P(EncryptedMediaTest,
576 Playback_ClearVideo_WEBM_EncryptedAudio_MP4) {
577 // MP4 without MSE is not support yet, http://crbug.com/170793.
578 if (CurrentSourceType() != MSE) {
579 DVLOG(0) << "Skipping test; Can only play MP4 encrypted streams by MSE.";
580 return;
581 }
jrummellc015cb962015-07-17 00:41:30582 if (!IsPlayBackPossible(CurrentKeySystem())) {
583 DVLOG(0) << "Skipping test - Test requires video playback.";
584 return;
585 }
586 TestDifferentContainers(EncryptedContainer::CLEAR_WEBM,
587 EncryptedContainer::ENCRYPTED_MP4);
588}
589
590IN_PROC_BROWSER_TEST_P(EncryptedMediaTest,
591 Playback_EncryptedVideo_WEBM_EncryptedAudio_MP4) {
592 // MP4 without MSE is not support yet, http://crbug.com/170793.
593 if (CurrentSourceType() != MSE) {
594 DVLOG(0) << "Skipping test; Can only play MP4 encrypted streams by MSE.";
595 return;
596 }
jrummellc015cb962015-07-17 00:41:30597 if (!IsPlayBackPossible(CurrentKeySystem())) {
598 DVLOG(0) << "Skipping test - Test requires video playback.";
599 return;
600 }
601 TestDifferentContainers(EncryptedContainer::ENCRYPTED_WEBM,
602 EncryptedContainer::ENCRYPTED_MP4);
603}
[email protected]63dc9072013-09-12 06:20:47604#endif // defined(USE_PROPRIETARY_CODECS)
605
[email protected]63dc9072013-09-12 06:20:47606#if defined(WIDEVINE_CDM_AVAILABLE)
[email protected]a32ef592014-03-07 19:11:15607// The parent key system cannot be used when creating MediaKeys.
[email protected]b1620732014-04-01 23:17:18608IN_PROC_BROWSER_TEST_F(WVEncryptedMediaTest, ParentThrowsException) {
jrummellb3944632015-03-14 00:19:42609 RunEncryptedMediaTest(kDefaultEmePlayer, "bear-a_enc-a.webm", kWebMAudioOnly,
ddorwinfdb9a2b2016-02-22 22:25:10610 "com.widevine", MSE, kNoSessionToLoad, false,
611 PlayTwice::NO, kEmeNotSupportedError);
[email protected]63dc9072013-09-12 06:20:47612}
[email protected]63dc9072013-09-12 06:20:47613#endif // defined(WIDEVINE_CDM_AVAILABLE)
[email protected]a941d4e572013-10-14 21:22:05614
615#if defined(ENABLE_PEPPER_CDMS)
[email protected]34afd582013-12-20 07:26:18616IN_PROC_BROWSER_TEST_F(ECKEncryptedMediaTest, InitializeCDMFail) {
jrummell87a2db52015-05-05 22:27:18617 TestNonPlaybackCases(kExternalClearKeyInitializeFailKeySystem,
618 kEmeNotSupportedError);
[email protected]a941d4e572013-10-14 21:22:05619}
[email protected]34afd582013-12-20 07:26:18620
jrummellfed298d22015-07-01 00:26:51621// When CDM crashes, we should still get a decode error. |kError| is reported
622// when the HTMLVideoElement error event fires, indicating an error happened
623// during playback.
624IN_PROC_BROWSER_TEST_F(ECKEncryptedMediaTest, CDMCrashDuringDecode) {
[email protected]1be9fa072014-03-21 22:50:29625 IgnorePluginCrash();
[email protected]0af5dfa2014-02-07 22:33:44626 TestNonPlaybackCases(kExternalClearKeyCrashKeySystem, kError);
[email protected]a27d34ab2014-01-09 04:23:29627}
628
[email protected]1be9fa072014-03-21 22:50:29629// Testing that the media browser test does fail on plugin crash.
jrummellfed298d22015-07-01 00:26:51630IN_PROC_BROWSER_TEST_F(ECKEncryptedMediaTest, CDMExpectedCrash) {
[email protected]1be9fa072014-03-21 22:50:29631 // Plugin crash is not ignored by default, the test is expected to fail.
632 EXPECT_NONFATAL_FAILURE(
633 TestNonPlaybackCases(kExternalClearKeyCrashKeySystem, kError),
jrummellfed298d22015-07-01 00:26:51634 "Failing test due to plugin crash.");
[email protected]1be9fa072014-03-21 22:50:29635}
636
xhwang0c617e112014-09-19 17:33:24637IN_PROC_BROWSER_TEST_F(ECKEncryptedMediaTest, FileIOTest) {
xhwang640ef5d2016-08-17 16:46:08638 TestNonPlaybackCases(kExternalClearKeyFileIOTestKeySystem, kUnitTestSuccess);
639}
640
641// TODO(xhwang): Investigate how to fake capturing activities to test the
642// network link detection logic in OutputProtectionProxy.
643IN_PROC_BROWSER_TEST_F(ECKEncryptedMediaTest, OutputProtectionTest) {
644 TestNonPlaybackCases(kExternalClearKeyOutputProtectionTestKeySystem,
645 kUnitTestSuccess);
[email protected]0af5dfa2014-02-07 22:33:44646}
647
xhwang0cfb5282016-08-25 03:33:25648IN_PROC_BROWSER_TEST_F(ECKEncryptedMediaTest, Renewal) {
649 TestPlaybackCase(kExternalClearKeyRenewalKeySystem, kNoSessionToLoad, kEnded);
650}
651
[email protected]0af5dfa2014-02-07 22:33:44652IN_PROC_BROWSER_TEST_F(ECKEncryptedMediaTest, LoadLoadableSession) {
xhwang0cfb5282016-08-25 03:33:25653 TestPlaybackCase(kExternalClearKeyKeySystem, kLoadableSession, kEnded);
[email protected]0af5dfa2014-02-07 22:33:44654}
655
656IN_PROC_BROWSER_TEST_F(ECKEncryptedMediaTest, LoadUnknownSession) {
xhwang0cfb5282016-08-25 03:33:25657 TestPlaybackCase(kExternalClearKeyKeySystem, kUnknownSession,
658 kEmeSessionNotFound);
[email protected]34afd582013-12-20 07:26:18659}
jrummellc467d232014-10-21 17:55:22660
[email protected]a941d4e572013-10-14 21:22:05661#endif // defined(ENABLE_PEPPER_CDMS)