Refactor WebsiteSettings to operate on a SecurityInfo
[chromium-blink-merge.git] / chrome / browser / media / encrypted_media_browsertest.cc
blobe56c65f33b3e55af49c09c8cbc499042132c1197
1 // 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.
5 #include "base/command_line.h"
6 #include "base/memory/scoped_ptr.h"
7 #include "base/path_service.h"
8 #include "base/strings/utf_string_conversions.h"
9 #include "base/win/windows_version.h"
10 #include "chrome/browser/media/media_browsertest.h"
11 #include "chrome/browser/media/test_license_server.h"
12 #include "chrome/browser/media/wv_test_license_server_config.h"
13 #include "chrome/browser/ui/browser.h"
14 #include "chrome/browser/ui/tabs/tab_strip_model.h"
15 #include "chrome/common/chrome_switches.h"
16 #include "content/public/test/browser_test_utils.h"
17 #include "testing/gtest/include/gtest/gtest-spi.h"
18 #if defined(OS_ANDROID)
19 #include "base/android/build_info.h"
20 #endif
22 #include "widevine_cdm_version.h" // In SHARED_INTERMEDIATE_DIR.
24 #if defined(ENABLE_PEPPER_CDMS)
25 // Platform-specific filename relative to the chrome executable.
26 const char kClearKeyCdmAdapterFileName[] =
27 #if defined(OS_MACOSX)
28 "clearkeycdmadapter.plugin";
29 #elif defined(OS_WIN)
30 "clearkeycdmadapter.dll";
31 #elif defined(OS_POSIX)
32 "libclearkeycdmadapter.so";
33 #endif
35 const char kClearKeyCdmPluginMimeType[] = "application/x-ppapi-clearkey-cdm";
36 #endif // defined(ENABLE_PEPPER_CDMS)
38 // Available key systems.
39 const char kClearKeyKeySystem[] = "org.w3.clearkey";
40 const char kPrefixedClearKeyKeySystem[] = "webkit-org.w3.clearkey";
41 const char kExternalClearKeyKeySystem[] = "org.chromium.externalclearkey";
42 const char kExternalClearKeyFileIOTestKeySystem[] =
43 "org.chromium.externalclearkey.fileiotest";
44 const char kExternalClearKeyInitializeFailKeySystem[] =
45 "org.chromium.externalclearkey.initializefail";
46 const char kExternalClearKeyCrashKeySystem[] =
47 "org.chromium.externalclearkey.crash";
49 // Supported media types.
50 const char kWebMAudioOnly[] = "audio/webm; codecs=\"vorbis\"";
51 const char kWebMVideoOnly[] = "video/webm; codecs=\"vp8\"";
52 const char kWebMAudioVideo[] = "video/webm; codecs=\"vorbis, vp8\"";
53 const char kWebMVP9VideoOnly[] = "video/webm; codecs=\"vp9\"";
54 #if defined(USE_PROPRIETARY_CODECS)
55 const char kMP4AudioOnly[] = "audio/mp4; codecs=\"mp4a.40.2\"";
56 const char kMP4VideoOnly[] = "video/mp4; codecs=\"avc1.4D4041\"";
57 #endif // defined(USE_PROPRIETARY_CODECS)
59 // Sessions to load.
60 const char kNoSessionToLoad[] = "";
61 const char kLoadableSession[] = "LoadableSession";
62 const char kUnknownSession[] = "UnknownSession";
64 // EME-specific test results and errors.
65 const char kFileIOTestSuccess[] = "FILE_IO_TEST_SUCCESS";
66 const char kEmeNotSupportedError[] = "NOTSUPPORTEDERROR";
67 const char kEmeGenerateRequestFailed[] = "EME_GENERATEREQUEST_FAILED";
68 const char kEmeSessionNotFound[] = "EME_SESSION_NOT_FOUND";
69 const char kEmeLoadFailed[] = "EME_LOAD_FAILED";
70 const char kEmeUpdateFailed[] = "EME_UPDATE_FAILED";
71 const char kEmeErrorEvent[] = "EME_ERROR_EVENT";
72 const char kEmeMessageUnexpectedType[] = "EME_MESSAGE_UNEXPECTED_TYPE";
73 const char kPrefixedEmeRenewalMissingHeader[] =
74 "PREFIXED_EME_RENEWAL_MISSING_HEADER";
75 const char kPrefixedEmeErrorEvent[] = "PREFIXED_EME_ERROR_EVENT";
77 const char kDefaultEmePlayer[] = "eme_player.html";
79 // The type of video src used to load media.
80 enum SrcType {
81 SRC,
82 MSE
85 // Whether to use prefixed or unprefixed EME.
86 enum EmeVersion {
87 PREFIXED,
88 UNPREFIXED
91 // Whether the video should be played once or twice.
92 enum class PlayTwice { NO, YES };
94 // Format of a container when testing different streams.
95 enum class EncryptedContainer {
96 CLEAR_WEBM,
97 CLEAR_MP4,
98 ENCRYPTED_WEBM,
99 ENCRYPTED_MP4
102 // MSE is available on all desktop platforms and on Android 4.1 and later.
103 static bool IsMSESupported() {
104 #if defined(OS_ANDROID)
105 if (base::android::BuildInfo::GetInstance()->sdk_int() < 16) {
106 DVLOG(0) << "MSE is only supported in Android 4.1 and later.";
107 return false;
109 #endif // defined(OS_ANDROID)
110 return true;
113 static bool IsParentKeySystemOf(const std::string& parent_key_system,
114 const std::string& key_system) {
115 std::string prefix = parent_key_system + '.';
116 return key_system.substr(0, prefix.size()) == prefix;
119 // Base class for encrypted media tests.
120 class EncryptedMediaTestBase : public MediaBrowserTest {
121 public:
122 EncryptedMediaTestBase() : is_pepper_cdm_registered_(false) {}
124 bool IsExternalClearKey(const std::string& key_system) {
125 return key_system == kExternalClearKeyKeySystem ||
126 IsParentKeySystemOf(kExternalClearKeyKeySystem, key_system);
129 #if defined(WIDEVINE_CDM_AVAILABLE)
130 bool IsWidevine(const std::string& key_system) {
131 return key_system == kWidevineKeySystem;
133 #endif // defined(WIDEVINE_CDM_AVAILABLE)
135 void RunEncryptedMediaTestPage(
136 const std::string& html_page,
137 const std::string& key_system,
138 base::StringPairs& query_params,
139 const std::string& expected_title) {
140 base::StringPairs new_query_params = query_params;
141 StartLicenseServerIfNeeded(key_system, &new_query_params);
142 RunMediaTestPage(html_page, new_query_params, expected_title, true);
145 // Tests |html_page| using |media_file| (with |media_type|) and |key_system|.
146 // When |session_to_load| is not empty, the test will try to load
147 // |session_to_load| with stored keys, instead of creating a new session
148 // and trying to update it with licenses.
149 // When |force_invalid_response| is true, the test will provide invalid
150 // responses, which should trigger errors.
151 // TODO(xhwang): Find an easier way to pass multiple configuration test
152 // options.
153 void RunEncryptedMediaTest(const std::string& html_page,
154 const std::string& media_file,
155 const std::string& media_type,
156 const std::string& key_system,
157 SrcType src_type,
158 EmeVersion eme_version,
159 const std::string& session_to_load,
160 bool force_invalid_response,
161 PlayTwice play_twice,
162 const std::string& expected_title) {
163 if (src_type == MSE && !IsMSESupported()) {
164 DVLOG(0) << "Skipping test - MSE not supported.";
165 return;
167 base::StringPairs query_params;
168 query_params.push_back(std::make_pair("mediaFile", media_file));
169 query_params.push_back(std::make_pair("mediaType", media_type));
170 query_params.push_back(std::make_pair("keySystem", key_system));
171 if (src_type == MSE)
172 query_params.push_back(std::make_pair("useMSE", "1"));
173 if (eme_version == PREFIXED)
174 query_params.push_back(std::make_pair("usePrefixedEME", "1"));
175 if (force_invalid_response)
176 query_params.push_back(std::make_pair("forceInvalidResponse", "1"));
177 if (!session_to_load.empty())
178 query_params.push_back(std::make_pair("sessionToLoad", session_to_load));
179 if (play_twice == PlayTwice::YES)
180 query_params.push_back(std::make_pair("playTwice", "1"));
181 RunEncryptedMediaTestPage(html_page, key_system, query_params,
182 expected_title);
185 void RunSimpleEncryptedMediaTest(const std::string& media_file,
186 const std::string& media_type,
187 const std::string& key_system,
188 SrcType src_type,
189 EmeVersion eme_version) {
190 std::string expected_title = kEnded;
191 if (!IsPlayBackPossible(key_system)) {
192 expected_title = (eme_version == EmeVersion::UNPREFIXED)
193 ? kEmeUpdateFailed
194 : kPrefixedEmeErrorEvent;
197 RunEncryptedMediaTest(kDefaultEmePlayer, media_file, media_type, key_system,
198 src_type, eme_version, kNoSessionToLoad, false,
199 PlayTwice::NO, expected_title);
200 // Check KeyMessage received for all key systems.
201 bool receivedKeyMessage = false;
202 EXPECT_TRUE(content::ExecuteScriptAndExtractBool(
203 browser()->tab_strip_model()->GetActiveWebContents(),
204 "window.domAutomationController.send("
205 "document.querySelector('video').receivedKeyMessage);",
206 &receivedKeyMessage));
207 EXPECT_TRUE(receivedKeyMessage);
210 // Starts a license server if available for the |key_system| and adds a
211 // 'licenseServerURL' query parameter to |query_params|.
212 void StartLicenseServerIfNeeded(const std::string& key_system,
213 base::StringPairs* query_params) {
214 scoped_ptr<TestLicenseServerConfig> config = GetServerConfig(key_system);
215 if (!config)
216 return;
217 license_server_.reset(new TestLicenseServer(config.Pass()));
218 EXPECT_TRUE(license_server_->Start());
219 query_params->push_back(
220 std::make_pair("licenseServerURL", license_server_->GetServerURL()));
223 bool IsPlayBackPossible(const std::string& key_system) {
224 #if defined(WIDEVINE_CDM_AVAILABLE)
225 if (IsWidevine(key_system) && !GetServerConfig(key_system))
226 return false;
227 #endif // defined(WIDEVINE_CDM_AVAILABLE)
228 return true;
231 scoped_ptr<TestLicenseServerConfig> GetServerConfig(
232 const std::string& key_system) {
233 #if defined(WIDEVINE_CDM_AVAILABLE)
234 if (IsWidevine(key_system)) {
235 scoped_ptr<TestLicenseServerConfig> config =
236 scoped_ptr<TestLicenseServerConfig>(new WVTestLicenseServerConfig());
237 if (config->IsPlatformSupported())
238 return config.Pass();
240 #endif // defined(WIDEVINE_CDM_AVAILABLE)
241 return scoped_ptr<TestLicenseServerConfig>();
244 protected:
245 scoped_ptr<TestLicenseServer> license_server_;
247 // We want to fail quickly when a test fails because an error is encountered.
248 void AddWaitForTitles(content::TitleWatcher* title_watcher) override {
249 MediaBrowserTest::AddWaitForTitles(title_watcher);
250 title_watcher->AlsoWaitForTitle(base::ASCIIToUTF16(kEmeNotSupportedError));
251 title_watcher->AlsoWaitForTitle(
252 base::ASCIIToUTF16(kEmeGenerateRequestFailed));
253 title_watcher->AlsoWaitForTitle(base::ASCIIToUTF16(kEmeSessionNotFound));
254 title_watcher->AlsoWaitForTitle(base::ASCIIToUTF16(kEmeLoadFailed));
255 title_watcher->AlsoWaitForTitle(base::ASCIIToUTF16(kEmeUpdateFailed));
256 title_watcher->AlsoWaitForTitle(base::ASCIIToUTF16(kEmeErrorEvent));
257 title_watcher->AlsoWaitForTitle(
258 base::ASCIIToUTF16(kEmeMessageUnexpectedType));
259 title_watcher->AlsoWaitForTitle(
260 base::ASCIIToUTF16(kPrefixedEmeRenewalMissingHeader));
261 title_watcher->AlsoWaitForTitle(base::ASCIIToUTF16(kPrefixedEmeErrorEvent));
264 void SetUpCommandLine(base::CommandLine* command_line) override {
265 #if defined(OS_ANDROID)
266 command_line->AppendSwitch(
267 switches::kDisableGestureRequirementForMediaPlayback);
268 #endif // defined(OS_ANDROID)
269 // For simplicity with respect to parameterized tests, enable for all tests.
270 command_line->AppendSwitch(switches::kEnablePrefixedEncryptedMedia);
273 void SetUpCommandLineForKeySystem(const std::string& key_system,
274 base::CommandLine* command_line) {
275 if (GetServerConfig(key_system))
276 // Since the web and license servers listen on different ports, we need to
277 // disable web-security to send license requests to the license server.
278 // TODO(shadi): Add port forwarding to the test web server configuration.
279 command_line->AppendSwitch(switches::kDisableWebSecurity);
281 #if defined(ENABLE_PEPPER_CDMS)
282 if (IsExternalClearKey(key_system)) {
283 RegisterPepperCdm(command_line, kClearKeyCdmAdapterFileName, key_system);
285 #if defined(WIDEVINE_CDM_AVAILABLE) && defined(WIDEVINE_CDM_IS_COMPONENT)
286 else if (IsWidevine(key_system)) { // NOLINT
287 RegisterPepperCdm(command_line, kWidevineCdmAdapterFileName, key_system);
289 #endif // defined(WIDEVINE_CDM_AVAILABLE) && defined(WIDEVINE_CDM_IS_COMPONENT)
290 #endif // defined(ENABLE_PEPPER_CDMS)
293 private:
294 #if defined(ENABLE_PEPPER_CDMS)
295 void RegisterPepperCdm(base::CommandLine* command_line,
296 const std::string& adapter_name,
297 const std::string& key_system) {
298 DCHECK(!is_pepper_cdm_registered_)
299 << "RegisterPepperCdm() can only be called once.";
300 is_pepper_cdm_registered_ = true;
302 // Append the switch to register the Clear Key CDM Adapter.
303 base::FilePath plugin_dir;
304 EXPECT_TRUE(PathService::Get(base::DIR_MODULE, &plugin_dir));
305 base::FilePath plugin_lib = plugin_dir.AppendASCII(adapter_name);
306 EXPECT_TRUE(base::PathExists(plugin_lib)) << plugin_lib.value();
307 base::FilePath::StringType pepper_plugin = plugin_lib.value();
308 pepper_plugin.append(FILE_PATH_LITERAL("#CDM#0.1.0.0;"));
309 #if defined(OS_WIN)
310 pepper_plugin.append(base::ASCIIToUTF16(GetPepperType(key_system)));
311 #else
312 pepper_plugin.append(GetPepperType(key_system));
313 #endif
314 command_line->AppendSwitchNative(switches::kRegisterPepperPlugins,
315 pepper_plugin);
318 // Adapted from key_systems.cc.
319 std::string GetPepperType(const std::string& key_system) {
320 if (IsExternalClearKey(key_system))
321 return kClearKeyCdmPluginMimeType;
322 #if defined(WIDEVINE_CDM_AVAILABLE)
323 if (IsWidevine(key_system))
324 return kWidevineCdmPluginMimeType;
325 #endif // WIDEVINE_CDM_AVAILABLE
327 NOTREACHED();
328 return "";
330 #endif // defined(ENABLE_PEPPER_CDMS)
332 bool is_pepper_cdm_registered_;
335 #if defined(ENABLE_PEPPER_CDMS)
336 // Tests encrypted media playback using ExternalClearKey key system in
337 // decrypt-and-decode mode.
338 class ECKEncryptedMediaTest : public EncryptedMediaTestBase {
339 public:
340 // We use special |key_system| names to do non-playback related tests, e.g.
341 // kExternalClearKeyFileIOTestKeySystem is used to test file IO.
342 void TestNonPlaybackCases(const std::string& key_system,
343 const std::string& expected_title) {
344 // Since we do not test playback, arbitrarily choose a test file and source
345 // type.
346 RunEncryptedMediaTest(
347 kDefaultEmePlayer, "bear-a_enc-a.webm", kWebMAudioOnly, key_system, SRC,
348 UNPREFIXED, kNoSessionToLoad, false, PlayTwice::NO, expected_title);
351 void TestPlaybackCase(const std::string& session_to_load,
352 const std::string& expected_title) {
353 RunEncryptedMediaTest(kDefaultEmePlayer, "bear-320x240-v_enc-v.webm",
354 kWebMVideoOnly, kExternalClearKeyKeySystem, SRC,
355 UNPREFIXED, session_to_load, false, PlayTwice::NO,
356 expected_title);
359 protected:
360 void SetUpCommandLine(base::CommandLine* command_line) override {
361 EncryptedMediaTestBase::SetUpCommandLine(command_line);
362 SetUpCommandLineForKeySystem(kExternalClearKeyKeySystem, command_line);
366 // Tests encrypted media playback using ExternalClearKey key system in
367 // decrypt-and-decode mode for prefixed EME.
368 class ECKPrefixedEncryptedMediaTest : public EncryptedMediaTestBase {
369 public:
370 // We use special |key_system| names to do non-playback related tests, e.g.
371 // kExternalClearKeyFileIOTestKeySystem is used to test file IO.
372 void TestNonPlaybackCases(const std::string& key_system,
373 const std::string& expected_title) {
374 // Since we do not test playback, arbitrarily choose a test file and source
375 // type.
376 RunEncryptedMediaTest(
377 kDefaultEmePlayer, "bear-a_enc-a.webm", kWebMAudioOnly, key_system, SRC,
378 PREFIXED, kNoSessionToLoad, false, PlayTwice::NO, expected_title);
381 void TestPlaybackCase(const std::string& session_to_load,
382 const std::string& expected_title) {
383 RunEncryptedMediaTest(kDefaultEmePlayer, "bear-320x240-v_enc-v.webm",
384 kWebMVideoOnly, kExternalClearKeyKeySystem, SRC,
385 PREFIXED, session_to_load, false, PlayTwice::NO,
386 expected_title);
389 protected:
390 void SetUpCommandLine(base::CommandLine* command_line) override {
391 EncryptedMediaTestBase::SetUpCommandLine(command_line);
392 SetUpCommandLineForKeySystem(kExternalClearKeyKeySystem, command_line);
396 #if defined(WIDEVINE_CDM_AVAILABLE)
397 // Tests encrypted media playback using Widevine key system.
398 class WVEncryptedMediaTest : public EncryptedMediaTestBase {
399 protected:
400 void SetUpCommandLine(base::CommandLine* command_line) override {
401 EncryptedMediaTestBase::SetUpCommandLine(command_line);
402 SetUpCommandLineForKeySystem(kWidevineKeySystem, command_line);
406 #endif // defined(WIDEVINE_CDM_AVAILABLE)
407 #endif // defined(ENABLE_PEPPER_CDMS)
409 // Tests encrypted media playback with a combination of parameters:
410 // - char*: Key system name.
411 // - SrcType: Use MSE or SRC.
412 // - EmeVersion: Use PREFIXED or UNPREFIXED EME.
414 // Note: Only parameterized (*_P) tests can be used. Non-parameterized (*_F)
415 // tests will crash at GetParam(). To add non-parameterized tests, use
416 // EncryptedMediaTestBase or one of its subclasses (e.g. WVEncryptedMediaTest).
417 class EncryptedMediaTest
418 : public EncryptedMediaTestBase,
419 public testing::WithParamInterface<
420 std::tr1::tuple<const char*, SrcType, EmeVersion> > {
421 public:
422 std::string CurrentKeySystem() {
423 return std::tr1::get<0>(GetParam());
426 SrcType CurrentSourceType() {
427 return std::tr1::get<1>(GetParam());
430 EmeVersion CurrentEmeVersion() {
431 return std::tr1::get<2>(GetParam());
434 void TestSimplePlayback(const std::string& encrypted_media,
435 const std::string& media_type) {
436 RunSimpleEncryptedMediaTest(encrypted_media,
437 media_type,
438 CurrentKeySystem(),
439 CurrentSourceType(),
440 CurrentEmeVersion());
443 void TestMultiplePlayback(const std::string& encrypted_media,
444 const std::string& media_type) {
445 DCHECK(IsPlayBackPossible(CurrentKeySystem()));
446 RunEncryptedMediaTest(kDefaultEmePlayer, encrypted_media, media_type,
447 CurrentKeySystem(), CurrentSourceType(),
448 CurrentEmeVersion(), kNoSessionToLoad, false,
449 PlayTwice::YES, kEnded);
452 void RunInvalidResponseTest() {
453 std::string expected_response =
454 (CurrentEmeVersion() == EmeVersion::UNPREFIXED)
455 ? kEmeUpdateFailed
456 : kPrefixedEmeErrorEvent;
457 RunEncryptedMediaTest(
458 kDefaultEmePlayer, "bear-320x240-av_enc-av.webm", kWebMAudioVideo,
459 CurrentKeySystem(), CurrentSourceType(), CurrentEmeVersion(),
460 kNoSessionToLoad, true, PlayTwice::NO, expected_response);
463 void TestFrameSizeChange() {
464 RunEncryptedMediaTest(
465 "encrypted_frame_size_change.html", "frame_size_change-av_enc-v.webm",
466 kWebMAudioVideo, CurrentKeySystem(), CurrentSourceType(),
467 CurrentEmeVersion(), kNoSessionToLoad, false, PlayTwice::NO, kEnded);
470 void TestConfigChange() {
471 DCHECK(IsMSESupported());
472 base::StringPairs query_params;
473 query_params.push_back(std::make_pair("keySystem", CurrentKeySystem()));
474 query_params.push_back(std::make_pair("runEncrypted", "1"));
475 if (CurrentEmeVersion() == PREFIXED)
476 query_params.push_back(std::make_pair("usePrefixedEME", "1"));
477 RunEncryptedMediaTestPage("mse_config_change.html",
478 CurrentKeySystem(),
479 query_params,
480 kEnded);
483 std::string ConvertContainerFormat(EncryptedContainer format) {
484 switch (format) {
485 case EncryptedContainer::CLEAR_MP4:
486 return "CLEAR_MP4";
487 case EncryptedContainer::CLEAR_WEBM:
488 return "CLEAR_WEBM";
489 case EncryptedContainer::ENCRYPTED_MP4:
490 return "ENCRYPTED_MP4";
491 case EncryptedContainer::ENCRYPTED_WEBM:
492 return "ENCRYPTED_WEBM";
494 NOTREACHED();
495 return "UNKNOWN";
498 void TestDifferentContainers(EncryptedContainer video_format,
499 EncryptedContainer audio_format) {
500 DCHECK(IsMSESupported());
501 DCHECK_NE(CurrentEmeVersion(), PREFIXED);
502 base::StringPairs query_params;
503 query_params.push_back(std::make_pair("keySystem", CurrentKeySystem()));
504 query_params.push_back(std::make_pair("runEncrypted", "1"));
505 query_params.push_back(
506 std::make_pair("videoFormat", ConvertContainerFormat(video_format)));
507 query_params.push_back(
508 std::make_pair("audioFormat", ConvertContainerFormat(audio_format)));
509 RunEncryptedMediaTestPage("mse_different_containers.html",
510 CurrentKeySystem(), query_params, kEnded);
513 protected:
514 void SetUpCommandLine(base::CommandLine* command_line) override {
515 EncryptedMediaTestBase::SetUpCommandLine(command_line);
516 SetUpCommandLineForKeySystem(CurrentKeySystem(), command_line);
520 using ::testing::Combine;
521 using ::testing::Values;
523 #if !defined(OS_ANDROID)
524 INSTANTIATE_TEST_CASE_P(SRC_ClearKey_Prefixed,
525 EncryptedMediaTest,
526 Combine(Values(kPrefixedClearKeyKeySystem),
527 Values(SRC),
528 Values(PREFIXED)));
530 INSTANTIATE_TEST_CASE_P(SRC_ClearKey,
531 EncryptedMediaTest,
532 Combine(Values(kClearKeyKeySystem),
533 Values(SRC),
534 Values(UNPREFIXED)));
535 #endif // !defined(OS_ANDROID)
537 INSTANTIATE_TEST_CASE_P(MSE_ClearKey_Prefixed,
538 EncryptedMediaTest,
539 Combine(Values(kPrefixedClearKeyKeySystem),
540 Values(MSE),
541 Values(PREFIXED)));
542 INSTANTIATE_TEST_CASE_P(MSE_ClearKey,
543 EncryptedMediaTest,
544 Combine(Values(kClearKeyKeySystem),
545 Values(MSE),
546 Values(UNPREFIXED)));
548 // External Clear Key is currently only used on platforms that use Pepper CDMs.
549 #if defined(ENABLE_PEPPER_CDMS)
550 INSTANTIATE_TEST_CASE_P(SRC_ExternalClearKey_Prefixed,
551 EncryptedMediaTest,
552 Combine(Values(kExternalClearKeyKeySystem),
553 Values(SRC),
554 Values(PREFIXED)));
555 INSTANTIATE_TEST_CASE_P(SRC_ExternalClearKey,
556 EncryptedMediaTest,
557 Combine(Values(kExternalClearKeyKeySystem),
558 Values(SRC),
559 Values(UNPREFIXED)));
561 const char kExternalClearKeyDecryptOnlyKeySystem[] =
562 "org.chromium.externalclearkey.decryptonly";
564 INSTANTIATE_TEST_CASE_P(MSE_ExternalClearKey_Prefixed,
565 EncryptedMediaTest,
566 Combine(Values(kExternalClearKeyKeySystem),
567 Values(MSE),
568 Values(PREFIXED)));
569 INSTANTIATE_TEST_CASE_P(MSE_ExternalClearKey,
570 EncryptedMediaTest,
571 Combine(Values(kExternalClearKeyKeySystem),
572 Values(MSE),
573 Values(UNPREFIXED)));
574 // To reduce test time, only run ExternalClearKeyDecryptOnly with MSE.
575 INSTANTIATE_TEST_CASE_P(MSE_ExternalClearKeyDecryptOnly_Prefixed,
576 EncryptedMediaTest,
577 Combine(Values(kExternalClearKeyDecryptOnlyKeySystem),
578 Values(MSE),
579 Values(PREFIXED)));
580 INSTANTIATE_TEST_CASE_P(MSE_ExternalClearKeyDecryptOnly,
581 EncryptedMediaTest,
582 Combine(Values(kExternalClearKeyDecryptOnlyKeySystem),
583 Values(MSE),
584 Values(UNPREFIXED)));
585 #endif // defined(ENABLE_PEPPER_CDMS)
587 #if defined(WIDEVINE_CDM_AVAILABLE)
589 // Prefixed Widevine tests fail in Chrome OS official builds due to the request
590 // for permissions. Since prefixed EME is deprecated and will be removed soon,
591 // don't run these tests. http://crbug.com/430711
592 #if !(defined(OS_CHROMEOS) && defined(OFFICIAL_BUILD))
594 // This test doesn't fully test playback with Widevine. So we only run Widevine
595 // test with MSE (no SRC) to reduce test time. Also, on Android EME only works
596 // with MSE and we cannot run this test with SRC.
597 INSTANTIATE_TEST_CASE_P(MSE_Widevine_Prefixed,
598 EncryptedMediaTest,
599 Combine(Values(kWidevineKeySystem),
600 Values(MSE),
601 Values(PREFIXED)));
602 #endif // !(defined(OS_CHROMEOS) && defined(OFFICIAL_BUILD))
604 INSTANTIATE_TEST_CASE_P(MSE_Widevine,
605 EncryptedMediaTest,
606 Combine(Values(kWidevineKeySystem),
607 Values(MSE),
608 Values(UNPREFIXED)));
609 #endif // defined(WIDEVINE_CDM_AVAILABLE)
611 IN_PROC_BROWSER_TEST_P(EncryptedMediaTest, Playback_AudioOnly_WebM) {
612 TestSimplePlayback("bear-a_enc-a.webm", kWebMAudioOnly);
615 IN_PROC_BROWSER_TEST_P(EncryptedMediaTest, Playback_AudioClearVideo_WebM) {
616 TestSimplePlayback("bear-320x240-av_enc-a.webm", kWebMAudioVideo);
619 IN_PROC_BROWSER_TEST_P(EncryptedMediaTest, Playback_VideoAudio_WebM) {
620 TestSimplePlayback("bear-320x240-av_enc-av.webm", kWebMAudioVideo);
623 IN_PROC_BROWSER_TEST_P(EncryptedMediaTest, Playback_VideoOnly_WebM) {
624 TestSimplePlayback("bear-320x240-v_enc-v.webm", kWebMVideoOnly);
627 IN_PROC_BROWSER_TEST_P(EncryptedMediaTest, Playback_VideoClearAudio_WebM) {
628 TestSimplePlayback("bear-320x240-av_enc-v.webm", kWebMAudioVideo);
631 IN_PROC_BROWSER_TEST_P(EncryptedMediaTest, Playback_VP9Video_WebM) {
632 TestSimplePlayback("bear-320x240-v-vp9_enc-v.webm", kWebMVP9VideoOnly);
635 IN_PROC_BROWSER_TEST_P(EncryptedMediaTest, Playback_AudioOnly_WebM_Opus) {
636 TestSimplePlayback("bear-320x240-opus-a_enc-a.webm", kWebMAudioOnly);
639 IN_PROC_BROWSER_TEST_P(EncryptedMediaTest, Playback_VideoAudio_WebM_Opus) {
640 TestSimplePlayback("bear-320x240-opus-av_enc-av.webm", kWebMAudioVideo);
643 IN_PROC_BROWSER_TEST_P(EncryptedMediaTest, Playback_VideoClearAudio_WebM_Opus) {
644 TestSimplePlayback("bear-320x240-opus-av_enc-v.webm", kWebMAudioVideo);
647 IN_PROC_BROWSER_TEST_P(EncryptedMediaTest, Playback_Multiple_VideoAudio_WebM) {
648 if (!IsPlayBackPossible(CurrentKeySystem())) {
649 DVLOG(0) << "Skipping test - Playback_Multiple test requires playback.";
650 return;
652 TestMultiplePlayback("bear-320x240-av_enc-av.webm", kWebMAudioVideo);
655 IN_PROC_BROWSER_TEST_P(EncryptedMediaTest, InvalidResponseKeyError) {
656 RunInvalidResponseTest();
659 IN_PROC_BROWSER_TEST_P(EncryptedMediaTest, ConfigChangeVideo) {
660 if (CurrentSourceType() != MSE || !IsMSESupported()) {
661 DVLOG(0) << "Skipping test - ConfigChange test requires MSE.";
662 return;
664 if (!IsPlayBackPossible(CurrentKeySystem())) {
665 DVLOG(0) << "Skipping test - ConfigChange test requires video playback.";
666 return;
668 TestConfigChange();
671 IN_PROC_BROWSER_TEST_P(EncryptedMediaTest, FrameSizeChangeVideo) {
672 // Times out on Windows XP. http://crbug.com/171937
673 #if defined(OS_WIN)
674 if (base::win::GetVersion() < base::win::VERSION_VISTA)
675 return;
676 #endif
677 if (!IsPlayBackPossible(CurrentKeySystem())) {
678 DVLOG(0) << "Skipping test - FrameSizeChange test requires video playback.";
679 return;
681 TestFrameSizeChange();
684 #if defined(USE_PROPRIETARY_CODECS)
685 IN_PROC_BROWSER_TEST_P(EncryptedMediaTest, Playback_VideoOnly_MP4) {
686 // MP4 without MSE is not support yet, http://crbug.com/170793.
687 if (CurrentSourceType() != MSE) {
688 DVLOG(0) << "Skipping test; Can only play MP4 encrypted streams by MSE.";
689 return;
691 TestSimplePlayback("bear-640x360-v_frag-cenc.mp4", kMP4VideoOnly);
694 IN_PROC_BROWSER_TEST_P(EncryptedMediaTest, Playback_AudioOnly_MP4) {
695 // MP4 without MSE is not support yet, http://crbug.com/170793.
696 if (CurrentSourceType() != MSE) {
697 DVLOG(0) << "Skipping test; Can only play MP4 encrypted streams by MSE.";
698 return;
700 TestSimplePlayback("bear-640x360-a_frag-cenc.mp4", kMP4AudioOnly);
703 IN_PROC_BROWSER_TEST_P(EncryptedMediaTest,
704 Playback_EncryptedVideo_MP4_ClearAudio_WEBM) {
705 // MP4 without MSE is not support yet, http://crbug.com/170793.
706 if (CurrentSourceType() != MSE) {
707 DVLOG(0) << "Skipping test; Can only play MP4 encrypted streams by MSE.";
708 return;
710 if (CurrentEmeVersion() != UNPREFIXED) {
711 DVLOG(0) << "Skipping test; Only supported by unprefixed EME";
712 return;
714 if (!IsPlayBackPossible(CurrentKeySystem())) {
715 DVLOG(0) << "Skipping test - Test requires video playback.";
716 return;
718 TestDifferentContainers(EncryptedContainer::ENCRYPTED_MP4,
719 EncryptedContainer::CLEAR_WEBM);
722 IN_PROC_BROWSER_TEST_P(EncryptedMediaTest,
723 Playback_ClearVideo_WEBM_EncryptedAudio_MP4) {
724 // MP4 without MSE is not support yet, http://crbug.com/170793.
725 if (CurrentSourceType() != MSE) {
726 DVLOG(0) << "Skipping test; Can only play MP4 encrypted streams by MSE.";
727 return;
729 if (CurrentEmeVersion() != UNPREFIXED) {
730 DVLOG(0) << "Skipping test; Only supported by unprefixed EME";
731 return;
733 if (!IsPlayBackPossible(CurrentKeySystem())) {
734 DVLOG(0) << "Skipping test - Test requires video playback.";
735 return;
737 TestDifferentContainers(EncryptedContainer::CLEAR_WEBM,
738 EncryptedContainer::ENCRYPTED_MP4);
741 IN_PROC_BROWSER_TEST_P(EncryptedMediaTest,
742 Playback_EncryptedVideo_WEBM_EncryptedAudio_MP4) {
743 // MP4 without MSE is not support yet, http://crbug.com/170793.
744 if (CurrentSourceType() != MSE) {
745 DVLOG(0) << "Skipping test; Can only play MP4 encrypted streams by MSE.";
746 return;
748 if (CurrentEmeVersion() != UNPREFIXED) {
749 DVLOG(0) << "Skipping test; Only supported by unprefixed EME";
750 return;
752 if (!IsPlayBackPossible(CurrentKeySystem())) {
753 DVLOG(0) << "Skipping test - Test requires video playback.";
754 return;
756 TestDifferentContainers(EncryptedContainer::ENCRYPTED_WEBM,
757 EncryptedContainer::ENCRYPTED_MP4);
759 #endif // defined(USE_PROPRIETARY_CODECS)
761 #if defined(WIDEVINE_CDM_AVAILABLE)
762 // The parent key system cannot be used in generateKeyRequest.
763 IN_PROC_BROWSER_TEST_F(WVEncryptedMediaTest, ParentThrowsException_Prefixed) {
764 RunEncryptedMediaTest(kDefaultEmePlayer, "bear-a_enc-a.webm", kWebMAudioOnly,
765 "com.widevine", MSE, PREFIXED, kNoSessionToLoad, false,
766 PlayTwice::NO, kEmeNotSupportedError);
769 // The parent key system cannot be used when creating MediaKeys.
770 IN_PROC_BROWSER_TEST_F(WVEncryptedMediaTest, ParentThrowsException) {
771 RunEncryptedMediaTest(kDefaultEmePlayer, "bear-a_enc-a.webm", kWebMAudioOnly,
772 "com.widevine", MSE, UNPREFIXED, kNoSessionToLoad,
773 false, PlayTwice::NO, kEmeNotSupportedError);
775 #endif // defined(WIDEVINE_CDM_AVAILABLE)
777 #if defined(ENABLE_PEPPER_CDMS)
778 IN_PROC_BROWSER_TEST_F(ECKEncryptedMediaTest, InitializeCDMFail) {
779 TestNonPlaybackCases(kExternalClearKeyInitializeFailKeySystem,
780 kEmeNotSupportedError);
783 // When CDM crashes, we should still get a decode error. |kError| is reported
784 // when the HTMLVideoElement error event fires, indicating an error happened
785 // during playback.
786 IN_PROC_BROWSER_TEST_F(ECKEncryptedMediaTest, CDMCrashDuringDecode) {
787 IgnorePluginCrash();
788 TestNonPlaybackCases(kExternalClearKeyCrashKeySystem, kError);
791 // Testing that the media browser test does fail on plugin crash.
792 IN_PROC_BROWSER_TEST_F(ECKEncryptedMediaTest, CDMExpectedCrash) {
793 // Plugin crash is not ignored by default, the test is expected to fail.
794 EXPECT_NONFATAL_FAILURE(
795 TestNonPlaybackCases(kExternalClearKeyCrashKeySystem, kError),
796 "Failing test due to plugin crash.");
799 IN_PROC_BROWSER_TEST_F(ECKEncryptedMediaTest, FileIOTest) {
800 TestNonPlaybackCases(kExternalClearKeyFileIOTestKeySystem,
801 kFileIOTestSuccess);
804 IN_PROC_BROWSER_TEST_F(ECKEncryptedMediaTest, LoadLoadableSession) {
805 TestPlaybackCase(kLoadableSession, kEnded);
808 IN_PROC_BROWSER_TEST_F(ECKEncryptedMediaTest, LoadUnknownSession) {
809 TestPlaybackCase(kUnknownSession, kEmeSessionNotFound);
812 IN_PROC_BROWSER_TEST_F(ECKPrefixedEncryptedMediaTest, InitializeCDMFail) {
813 TestNonPlaybackCases(kExternalClearKeyInitializeFailKeySystem,
814 kPrefixedEmeErrorEvent);
817 // When CDM crashes, we should still get a decode error.
818 // crbug.com/386657
819 IN_PROC_BROWSER_TEST_F(ECKPrefixedEncryptedMediaTest,
820 DISABLED_CDMCrashDuringDecode) {
821 IgnorePluginCrash();
822 TestNonPlaybackCases(kExternalClearKeyCrashKeySystem, kError);
825 // Testing that the media browser test does fail on plugin crash.
826 // crbug.com/386657
827 IN_PROC_BROWSER_TEST_F(ECKPrefixedEncryptedMediaTest,
828 DISABLED_CDMExpectedCrash) {
829 // Plugin crash is not ignored by default, the test is expected to fail.
830 EXPECT_NONFATAL_FAILURE(
831 TestNonPlaybackCases(kExternalClearKeyCrashKeySystem, kError),
832 "plugin crash");
835 IN_PROC_BROWSER_TEST_F(ECKPrefixedEncryptedMediaTest, FileIOTest) {
836 TestNonPlaybackCases(kExternalClearKeyFileIOTestKeySystem,
837 kFileIOTestSuccess);
840 IN_PROC_BROWSER_TEST_F(ECKPrefixedEncryptedMediaTest, LoadLoadableSession) {
841 TestPlaybackCase(kLoadableSession, kEnded);
844 IN_PROC_BROWSER_TEST_F(ECKPrefixedEncryptedMediaTest, LoadUnknownSession) {
845 TestPlaybackCase(kUnknownSession, kPrefixedEmeErrorEvent);
847 #endif // defined(ENABLE_PEPPER_CDMS)