Rename GetIconID to GetIconId
[chromium-blink-merge.git] / chrome / browser / media / encrypted_media_browsertest.cc
blob93648a0ccec9e4a42db537b778a68d19da945926
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)
271 void SetUpCommandLineForKeySystem(const std::string& key_system,
272 base::CommandLine* command_line) {
273 if (GetServerConfig(key_system))
274 // Since the web and license servers listen on different ports, we need to
275 // disable web-security to send license requests to the license server.
276 // TODO(shadi): Add port forwarding to the test web server configuration.
277 command_line->AppendSwitch(switches::kDisableWebSecurity);
279 #if defined(ENABLE_PEPPER_CDMS)
280 if (IsExternalClearKey(key_system)) {
281 RegisterPepperCdm(command_line, kClearKeyCdmAdapterFileName, key_system);
283 #if defined(WIDEVINE_CDM_AVAILABLE) && defined(WIDEVINE_CDM_IS_COMPONENT)
284 else if (IsWidevine(key_system)) { // NOLINT
285 RegisterPepperCdm(command_line, kWidevineCdmAdapterFileName, key_system);
287 #endif // defined(WIDEVINE_CDM_AVAILABLE) && defined(WIDEVINE_CDM_IS_COMPONENT)
288 #endif // defined(ENABLE_PEPPER_CDMS)
291 private:
292 #if defined(ENABLE_PEPPER_CDMS)
293 void RegisterPepperCdm(base::CommandLine* command_line,
294 const std::string& adapter_name,
295 const std::string& key_system) {
296 DCHECK(!is_pepper_cdm_registered_)
297 << "RegisterPepperCdm() can only be called once.";
298 is_pepper_cdm_registered_ = true;
300 // Append the switch to register the Clear Key CDM Adapter.
301 base::FilePath plugin_dir;
302 EXPECT_TRUE(PathService::Get(base::DIR_MODULE, &plugin_dir));
303 base::FilePath plugin_lib = plugin_dir.AppendASCII(adapter_name);
304 EXPECT_TRUE(base::PathExists(plugin_lib)) << plugin_lib.value();
305 base::FilePath::StringType pepper_plugin = plugin_lib.value();
306 pepper_plugin.append(FILE_PATH_LITERAL("#CDM#0.1.0.0;"));
307 #if defined(OS_WIN)
308 pepper_plugin.append(base::ASCIIToUTF16(GetPepperType(key_system)));
309 #else
310 pepper_plugin.append(GetPepperType(key_system));
311 #endif
312 command_line->AppendSwitchNative(switches::kRegisterPepperPlugins,
313 pepper_plugin);
316 // Adapted from key_systems.cc.
317 std::string GetPepperType(const std::string& key_system) {
318 if (IsExternalClearKey(key_system))
319 return kClearKeyCdmPluginMimeType;
320 #if defined(WIDEVINE_CDM_AVAILABLE)
321 if (IsWidevine(key_system))
322 return kWidevineCdmPluginMimeType;
323 #endif // WIDEVINE_CDM_AVAILABLE
325 NOTREACHED();
326 return "";
328 #endif // defined(ENABLE_PEPPER_CDMS)
330 bool is_pepper_cdm_registered_;
333 #if defined(ENABLE_PEPPER_CDMS)
334 // Tests encrypted media playback using ExternalClearKey key system in
335 // decrypt-and-decode mode.
336 class ECKEncryptedMediaTest : public EncryptedMediaTestBase {
337 public:
338 // We use special |key_system| names to do non-playback related tests, e.g.
339 // kExternalClearKeyFileIOTestKeySystem is used to test file IO.
340 void TestNonPlaybackCases(const std::string& key_system,
341 const std::string& expected_title) {
342 // Since we do not test playback, arbitrarily choose a test file and source
343 // type.
344 RunEncryptedMediaTest(
345 kDefaultEmePlayer, "bear-a_enc-a.webm", kWebMAudioOnly, key_system, SRC,
346 UNPREFIXED, kNoSessionToLoad, false, PlayTwice::NO, expected_title);
349 void TestPlaybackCase(const std::string& session_to_load,
350 const std::string& expected_title) {
351 RunEncryptedMediaTest(kDefaultEmePlayer, "bear-320x240-v_enc-v.webm",
352 kWebMVideoOnly, kExternalClearKeyKeySystem, SRC,
353 UNPREFIXED, session_to_load, false, PlayTwice::NO,
354 expected_title);
357 protected:
358 void SetUpCommandLine(base::CommandLine* command_line) override {
359 EncryptedMediaTestBase::SetUpCommandLine(command_line);
360 SetUpCommandLineForKeySystem(kExternalClearKeyKeySystem, command_line);
364 // Tests encrypted media playback using ExternalClearKey key system in
365 // decrypt-and-decode mode for unprefixed EME.
366 class ECKPrefixedEncryptedMediaTest : public EncryptedMediaTestBase {
367 public:
368 // We use special |key_system| names to do non-playback related tests, e.g.
369 // kExternalClearKeyFileIOTestKeySystem is used to test file IO.
370 void TestNonPlaybackCases(const std::string& key_system,
371 const std::string& expected_title) {
372 // Since we do not test playback, arbitrarily choose a test file and source
373 // type.
374 RunEncryptedMediaTest(
375 kDefaultEmePlayer, "bear-a_enc-a.webm", kWebMAudioOnly, key_system, SRC,
376 PREFIXED, kNoSessionToLoad, false, PlayTwice::NO, expected_title);
379 void TestPlaybackCase(const std::string& session_to_load,
380 const std::string& expected_title) {
381 RunEncryptedMediaTest(kDefaultEmePlayer, "bear-320x240-v_enc-v.webm",
382 kWebMVideoOnly, kExternalClearKeyKeySystem, SRC,
383 PREFIXED, session_to_load, false, PlayTwice::NO,
384 expected_title);
387 protected:
388 void SetUpCommandLine(base::CommandLine* command_line) override {
389 EncryptedMediaTestBase::SetUpCommandLine(command_line);
390 SetUpCommandLineForKeySystem(kExternalClearKeyKeySystem, command_line);
394 #if defined(WIDEVINE_CDM_AVAILABLE)
395 // Tests encrypted media playback using Widevine key system.
396 class WVEncryptedMediaTest : public EncryptedMediaTestBase {
397 protected:
398 void SetUpCommandLine(base::CommandLine* command_line) override {
399 EncryptedMediaTestBase::SetUpCommandLine(command_line);
400 SetUpCommandLineForKeySystem(kWidevineKeySystem, command_line);
404 #endif // defined(WIDEVINE_CDM_AVAILABLE)
405 #endif // defined(ENABLE_PEPPER_CDMS)
407 // Tests encrypted media playback with a combination of parameters:
408 // - char*: Key system name.
409 // - SrcType: Use MSE or SRC.
410 // - EmeVersion: Use PREFIXED or UNPREFIXED EME.
412 // Note: Only parameterized (*_P) tests can be used. Non-parameterized (*_F)
413 // tests will crash at GetParam(). To add non-parameterized tests, use
414 // EncryptedMediaTestBase or one of its subclasses (e.g. WVEncryptedMediaTest).
415 class EncryptedMediaTest
416 : public EncryptedMediaTestBase,
417 public testing::WithParamInterface<
418 std::tr1::tuple<const char*, SrcType, EmeVersion> > {
419 public:
420 std::string CurrentKeySystem() {
421 return std::tr1::get<0>(GetParam());
424 SrcType CurrentSourceType() {
425 return std::tr1::get<1>(GetParam());
428 EmeVersion CurrentEmeVersion() {
429 return std::tr1::get<2>(GetParam());
432 void TestSimplePlayback(const std::string& encrypted_media,
433 const std::string& media_type) {
434 RunSimpleEncryptedMediaTest(encrypted_media,
435 media_type,
436 CurrentKeySystem(),
437 CurrentSourceType(),
438 CurrentEmeVersion());
441 void TestMultiplePlayback(const std::string& encrypted_media,
442 const std::string& media_type) {
443 DCHECK(IsPlayBackPossible(CurrentKeySystem()));
444 RunEncryptedMediaTest(kDefaultEmePlayer, encrypted_media, media_type,
445 CurrentKeySystem(), CurrentSourceType(),
446 CurrentEmeVersion(), kNoSessionToLoad, false,
447 PlayTwice::YES, kEnded);
450 void RunInvalidResponseTest() {
451 std::string expected_response =
452 (CurrentEmeVersion() == EmeVersion::UNPREFIXED)
453 ? kEmeUpdateFailed
454 : kPrefixedEmeErrorEvent;
455 RunEncryptedMediaTest(
456 kDefaultEmePlayer, "bear-320x240-av_enc-av.webm", kWebMAudioVideo,
457 CurrentKeySystem(), CurrentSourceType(), CurrentEmeVersion(),
458 kNoSessionToLoad, true, PlayTwice::NO, expected_response);
461 void TestFrameSizeChange() {
462 RunEncryptedMediaTest(
463 "encrypted_frame_size_change.html", "frame_size_change-av_enc-v.webm",
464 kWebMAudioVideo, CurrentKeySystem(), CurrentSourceType(),
465 CurrentEmeVersion(), kNoSessionToLoad, false, PlayTwice::NO, kEnded);
468 void TestConfigChange() {
469 DCHECK(IsMSESupported());
470 base::StringPairs query_params;
471 query_params.push_back(std::make_pair("keySystem", CurrentKeySystem()));
472 query_params.push_back(std::make_pair("runEncrypted", "1"));
473 if (CurrentEmeVersion() == PREFIXED)
474 query_params.push_back(std::make_pair("usePrefixedEME", "1"));
475 RunEncryptedMediaTestPage("mse_config_change.html",
476 CurrentKeySystem(),
477 query_params,
478 kEnded);
481 std::string ConvertContainerFormat(EncryptedContainer format) {
482 switch (format) {
483 case EncryptedContainer::CLEAR_MP4:
484 return "CLEAR_MP4";
485 case EncryptedContainer::CLEAR_WEBM:
486 return "CLEAR_WEBM";
487 case EncryptedContainer::ENCRYPTED_MP4:
488 return "ENCRYPTED_MP4";
489 case EncryptedContainer::ENCRYPTED_WEBM:
490 return "ENCRYPTED_WEBM";
492 NOTREACHED();
493 return "UNKNOWN";
496 void TestDifferentContainers(EncryptedContainer video_format,
497 EncryptedContainer audio_format) {
498 DCHECK(IsMSESupported());
499 DCHECK_NE(CurrentEmeVersion(), PREFIXED);
500 base::StringPairs query_params;
501 query_params.push_back(std::make_pair("keySystem", CurrentKeySystem()));
502 query_params.push_back(std::make_pair("runEncrypted", "1"));
503 query_params.push_back(
504 std::make_pair("videoFormat", ConvertContainerFormat(video_format)));
505 query_params.push_back(
506 std::make_pair("audioFormat", ConvertContainerFormat(audio_format)));
507 RunEncryptedMediaTestPage("mse_different_containers.html",
508 CurrentKeySystem(), query_params, kEnded);
511 protected:
512 void SetUpCommandLine(base::CommandLine* command_line) override {
513 EncryptedMediaTestBase::SetUpCommandLine(command_line);
514 SetUpCommandLineForKeySystem(CurrentKeySystem(), command_line);
518 using ::testing::Combine;
519 using ::testing::Values;
521 #if !defined(OS_ANDROID)
522 INSTANTIATE_TEST_CASE_P(SRC_ClearKey_Prefixed,
523 EncryptedMediaTest,
524 Combine(Values(kPrefixedClearKeyKeySystem),
525 Values(SRC),
526 Values(PREFIXED)));
528 INSTANTIATE_TEST_CASE_P(SRC_ClearKey,
529 EncryptedMediaTest,
530 Combine(Values(kClearKeyKeySystem),
531 Values(SRC),
532 Values(UNPREFIXED)));
533 #endif // !defined(OS_ANDROID)
535 INSTANTIATE_TEST_CASE_P(MSE_ClearKey_Prefixed,
536 EncryptedMediaTest,
537 Combine(Values(kPrefixedClearKeyKeySystem),
538 Values(MSE),
539 Values(PREFIXED)));
540 INSTANTIATE_TEST_CASE_P(MSE_ClearKey,
541 EncryptedMediaTest,
542 Combine(Values(kClearKeyKeySystem),
543 Values(MSE),
544 Values(UNPREFIXED)));
546 // External Clear Key is currently only used on platforms that use Pepper CDMs.
547 #if defined(ENABLE_PEPPER_CDMS)
548 INSTANTIATE_TEST_CASE_P(SRC_ExternalClearKey_Prefixed,
549 EncryptedMediaTest,
550 Combine(Values(kExternalClearKeyKeySystem),
551 Values(SRC),
552 Values(PREFIXED)));
553 INSTANTIATE_TEST_CASE_P(SRC_ExternalClearKey,
554 EncryptedMediaTest,
555 Combine(Values(kExternalClearKeyKeySystem),
556 Values(SRC),
557 Values(UNPREFIXED)));
559 const char kExternalClearKeyDecryptOnlyKeySystem[] =
560 "org.chromium.externalclearkey.decryptonly";
562 INSTANTIATE_TEST_CASE_P(MSE_ExternalClearKey_Prefixed,
563 EncryptedMediaTest,
564 Combine(Values(kExternalClearKeyKeySystem),
565 Values(MSE),
566 Values(PREFIXED)));
567 INSTANTIATE_TEST_CASE_P(MSE_ExternalClearKey,
568 EncryptedMediaTest,
569 Combine(Values(kExternalClearKeyKeySystem),
570 Values(MSE),
571 Values(UNPREFIXED)));
572 // To reduce test time, only run ExternalClearKeyDecryptOnly with MSE.
573 INSTANTIATE_TEST_CASE_P(MSE_ExternalClearKeyDecryptOnly_Prefixed,
574 EncryptedMediaTest,
575 Combine(Values(kExternalClearKeyDecryptOnlyKeySystem),
576 Values(MSE),
577 Values(PREFIXED)));
578 INSTANTIATE_TEST_CASE_P(MSE_ExternalClearKeyDecryptOnly,
579 EncryptedMediaTest,
580 Combine(Values(kExternalClearKeyDecryptOnlyKeySystem),
581 Values(MSE),
582 Values(UNPREFIXED)));
583 #endif // defined(ENABLE_PEPPER_CDMS)
585 #if defined(WIDEVINE_CDM_AVAILABLE)
587 // Prefixed Widevine tests fail in Chrome OS official builds due to the request
588 // for permissions. Since prefixed EME is deprecated and will be removed soon,
589 // don't run these tests. http://crbug.com/430711
590 #if !(defined(OS_CHROMEOS) && defined(OFFICIAL_BUILD))
592 // This test doesn't fully test playback with Widevine. So we only run Widevine
593 // test with MSE (no SRC) to reduce test time. Also, on Android EME only works
594 // with MSE and we cannot run this test with SRC.
595 INSTANTIATE_TEST_CASE_P(MSE_Widevine_Prefixed,
596 EncryptedMediaTest,
597 Combine(Values(kWidevineKeySystem),
598 Values(MSE),
599 Values(PREFIXED)));
600 #endif // !(defined(OS_CHROMEOS) && defined(OFFICIAL_BUILD))
602 INSTANTIATE_TEST_CASE_P(MSE_Widevine,
603 EncryptedMediaTest,
604 Combine(Values(kWidevineKeySystem),
605 Values(MSE),
606 Values(UNPREFIXED)));
607 #endif // defined(WIDEVINE_CDM_AVAILABLE)
609 IN_PROC_BROWSER_TEST_P(EncryptedMediaTest, Playback_AudioOnly_WebM) {
610 TestSimplePlayback("bear-a_enc-a.webm", kWebMAudioOnly);
613 IN_PROC_BROWSER_TEST_P(EncryptedMediaTest, Playback_AudioClearVideo_WebM) {
614 TestSimplePlayback("bear-320x240-av_enc-a.webm", kWebMAudioVideo);
617 IN_PROC_BROWSER_TEST_P(EncryptedMediaTest, Playback_VideoAudio_WebM) {
618 TestSimplePlayback("bear-320x240-av_enc-av.webm", kWebMAudioVideo);
621 IN_PROC_BROWSER_TEST_P(EncryptedMediaTest, Playback_VideoOnly_WebM) {
622 TestSimplePlayback("bear-320x240-v_enc-v.webm", kWebMVideoOnly);
625 IN_PROC_BROWSER_TEST_P(EncryptedMediaTest, Playback_VideoClearAudio_WebM) {
626 TestSimplePlayback("bear-320x240-av_enc-v.webm", kWebMAudioVideo);
629 IN_PROC_BROWSER_TEST_P(EncryptedMediaTest, Playback_VP9Video_WebM) {
630 TestSimplePlayback("bear-320x240-v-vp9_enc-v.webm", kWebMVP9VideoOnly);
633 IN_PROC_BROWSER_TEST_P(EncryptedMediaTest, Playback_AudioOnly_WebM_Opus) {
634 TestSimplePlayback("bear-320x240-opus-a_enc-a.webm", kWebMAudioOnly);
637 IN_PROC_BROWSER_TEST_P(EncryptedMediaTest, Playback_VideoAudio_WebM_Opus) {
638 TestSimplePlayback("bear-320x240-opus-av_enc-av.webm", kWebMAudioVideo);
641 IN_PROC_BROWSER_TEST_P(EncryptedMediaTest, Playback_VideoClearAudio_WebM_Opus) {
642 TestSimplePlayback("bear-320x240-opus-av_enc-v.webm", kWebMAudioVideo);
645 IN_PROC_BROWSER_TEST_P(EncryptedMediaTest, Playback_Multiple_VideoAudio_WebM) {
646 if (!IsPlayBackPossible(CurrentKeySystem())) {
647 DVLOG(0) << "Skipping test - Playback_Multiple test requires playback.";
648 return;
650 TestMultiplePlayback("bear-320x240-av_enc-av.webm", kWebMAudioVideo);
653 IN_PROC_BROWSER_TEST_P(EncryptedMediaTest, InvalidResponseKeyError) {
654 RunInvalidResponseTest();
657 IN_PROC_BROWSER_TEST_P(EncryptedMediaTest, ConfigChangeVideo) {
658 if (CurrentSourceType() != MSE || !IsMSESupported()) {
659 DVLOG(0) << "Skipping test - ConfigChange test requires MSE.";
660 return;
662 if (!IsPlayBackPossible(CurrentKeySystem())) {
663 DVLOG(0) << "Skipping test - ConfigChange test requires video playback.";
664 return;
666 TestConfigChange();
669 IN_PROC_BROWSER_TEST_P(EncryptedMediaTest, FrameSizeChangeVideo) {
670 // Times out on Windows XP. http://crbug.com/171937
671 #if defined(OS_WIN)
672 if (base::win::GetVersion() < base::win::VERSION_VISTA)
673 return;
674 #endif
675 if (!IsPlayBackPossible(CurrentKeySystem())) {
676 DVLOG(0) << "Skipping test - FrameSizeChange test requires video playback.";
677 return;
679 TestFrameSizeChange();
682 #if defined(USE_PROPRIETARY_CODECS)
683 IN_PROC_BROWSER_TEST_P(EncryptedMediaTest, Playback_VideoOnly_MP4) {
684 // MP4 without MSE is not support yet, http://crbug.com/170793.
685 if (CurrentSourceType() != MSE) {
686 DVLOG(0) << "Skipping test; Can only play MP4 encrypted streams by MSE.";
687 return;
689 TestSimplePlayback("bear-640x360-v_frag-cenc.mp4", kMP4VideoOnly);
692 IN_PROC_BROWSER_TEST_P(EncryptedMediaTest, Playback_AudioOnly_MP4) {
693 // MP4 without MSE is not support yet, http://crbug.com/170793.
694 if (CurrentSourceType() != MSE) {
695 DVLOG(0) << "Skipping test; Can only play MP4 encrypted streams by MSE.";
696 return;
698 TestSimplePlayback("bear-640x360-a_frag-cenc.mp4", kMP4AudioOnly);
701 IN_PROC_BROWSER_TEST_P(EncryptedMediaTest,
702 Playback_EncryptedVideo_MP4_ClearAudio_WEBM) {
703 // MP4 without MSE is not support yet, http://crbug.com/170793.
704 if (CurrentSourceType() != MSE) {
705 DVLOG(0) << "Skipping test; Can only play MP4 encrypted streams by MSE.";
706 return;
708 if (CurrentEmeVersion() != UNPREFIXED) {
709 DVLOG(0) << "Skipping test; Only supported by unprefixed EME";
710 return;
712 if (!IsPlayBackPossible(CurrentKeySystem())) {
713 DVLOG(0) << "Skipping test - Test requires video playback.";
714 return;
716 TestDifferentContainers(EncryptedContainer::ENCRYPTED_MP4,
717 EncryptedContainer::CLEAR_WEBM);
720 IN_PROC_BROWSER_TEST_P(EncryptedMediaTest,
721 Playback_ClearVideo_WEBM_EncryptedAudio_MP4) {
722 // MP4 without MSE is not support yet, http://crbug.com/170793.
723 if (CurrentSourceType() != MSE) {
724 DVLOG(0) << "Skipping test; Can only play MP4 encrypted streams by MSE.";
725 return;
727 if (CurrentEmeVersion() != UNPREFIXED) {
728 DVLOG(0) << "Skipping test; Only supported by unprefixed EME";
729 return;
731 if (!IsPlayBackPossible(CurrentKeySystem())) {
732 DVLOG(0) << "Skipping test - Test requires video playback.";
733 return;
735 TestDifferentContainers(EncryptedContainer::CLEAR_WEBM,
736 EncryptedContainer::ENCRYPTED_MP4);
739 IN_PROC_BROWSER_TEST_P(EncryptedMediaTest,
740 Playback_EncryptedVideo_WEBM_EncryptedAudio_MP4) {
741 // MP4 without MSE is not support yet, http://crbug.com/170793.
742 if (CurrentSourceType() != MSE) {
743 DVLOG(0) << "Skipping test; Can only play MP4 encrypted streams by MSE.";
744 return;
746 if (CurrentEmeVersion() != UNPREFIXED) {
747 DVLOG(0) << "Skipping test; Only supported by unprefixed EME";
748 return;
750 if (!IsPlayBackPossible(CurrentKeySystem())) {
751 DVLOG(0) << "Skipping test - Test requires video playback.";
752 return;
754 TestDifferentContainers(EncryptedContainer::ENCRYPTED_WEBM,
755 EncryptedContainer::ENCRYPTED_MP4);
757 #endif // defined(USE_PROPRIETARY_CODECS)
759 #if defined(WIDEVINE_CDM_AVAILABLE)
760 // The parent key system cannot be used in generateKeyRequest.
761 IN_PROC_BROWSER_TEST_F(WVEncryptedMediaTest, ParentThrowsException_Prefixed) {
762 RunEncryptedMediaTest(kDefaultEmePlayer, "bear-a_enc-a.webm", kWebMAudioOnly,
763 "com.widevine", MSE, PREFIXED, kNoSessionToLoad, false,
764 PlayTwice::NO, kEmeNotSupportedError);
767 // TODO(jrummell): http://crbug.com/349181
768 // The parent key system cannot be used when creating MediaKeys.
769 IN_PROC_BROWSER_TEST_F(WVEncryptedMediaTest, ParentThrowsException) {
770 RunEncryptedMediaTest(kDefaultEmePlayer, "bear-a_enc-a.webm", kWebMAudioOnly,
771 "com.widevine", MSE, UNPREFIXED, kNoSessionToLoad,
772 false, PlayTwice::NO, kEmeNotSupportedError);
774 #endif // defined(WIDEVINE_CDM_AVAILABLE)
776 #if defined(ENABLE_PEPPER_CDMS)
777 IN_PROC_BROWSER_TEST_F(ECKEncryptedMediaTest, InitializeCDMFail) {
778 TestNonPlaybackCases(kExternalClearKeyInitializeFailKeySystem,
779 kEmeNotSupportedError);
782 // When CDM crashes, we should still get a decode error. |kError| is reported
783 // when the HTMLVideoElement error event fires, indicating an error happened
784 // during playback.
785 IN_PROC_BROWSER_TEST_F(ECKEncryptedMediaTest, CDMCrashDuringDecode) {
786 IgnorePluginCrash();
787 TestNonPlaybackCases(kExternalClearKeyCrashKeySystem, kError);
790 // Testing that the media browser test does fail on plugin crash.
791 IN_PROC_BROWSER_TEST_F(ECKEncryptedMediaTest, CDMExpectedCrash) {
792 // Plugin crash is not ignored by default, the test is expected to fail.
793 EXPECT_NONFATAL_FAILURE(
794 TestNonPlaybackCases(kExternalClearKeyCrashKeySystem, kError),
795 "Failing test due to plugin crash.");
798 IN_PROC_BROWSER_TEST_F(ECKEncryptedMediaTest, FileIOTest) {
799 TestNonPlaybackCases(kExternalClearKeyFileIOTestKeySystem,
800 kFileIOTestSuccess);
803 IN_PROC_BROWSER_TEST_F(ECKEncryptedMediaTest, LoadLoadableSession) {
804 TestPlaybackCase(kLoadableSession, kEnded);
807 IN_PROC_BROWSER_TEST_F(ECKEncryptedMediaTest, LoadUnknownSession) {
808 TestPlaybackCase(kUnknownSession, kEmeSessionNotFound);
811 IN_PROC_BROWSER_TEST_F(ECKPrefixedEncryptedMediaTest, InitializeCDMFail) {
812 TestNonPlaybackCases(kExternalClearKeyInitializeFailKeySystem,
813 kPrefixedEmeErrorEvent);
816 // When CDM crashes, we should still get a decode error.
817 // crbug.com/386657
818 IN_PROC_BROWSER_TEST_F(ECKPrefixedEncryptedMediaTest,
819 DISABLED_CDMCrashDuringDecode) {
820 IgnorePluginCrash();
821 TestNonPlaybackCases(kExternalClearKeyCrashKeySystem, kError);
824 // Testing that the media browser test does fail on plugin crash.
825 // crbug.com/386657
826 IN_PROC_BROWSER_TEST_F(ECKPrefixedEncryptedMediaTest,
827 DISABLED_CDMExpectedCrash) {
828 // Plugin crash is not ignored by default, the test is expected to fail.
829 EXPECT_NONFATAL_FAILURE(
830 TestNonPlaybackCases(kExternalClearKeyCrashKeySystem, kError),
831 "plugin crash");
834 IN_PROC_BROWSER_TEST_F(ECKPrefixedEncryptedMediaTest, FileIOTest) {
835 TestNonPlaybackCases(kExternalClearKeyFileIOTestKeySystem,
836 kFileIOTestSuccess);
839 IN_PROC_BROWSER_TEST_F(ECKPrefixedEncryptedMediaTest, LoadLoadableSession) {
840 TestPlaybackCase(kLoadableSession, kEnded);
843 IN_PROC_BROWSER_TEST_F(ECKPrefixedEncryptedMediaTest, LoadUnknownSession) {
844 TestPlaybackCase(kUnknownSession, kPrefixedEmeErrorEvent);
846 #endif // defined(ENABLE_PEPPER_CDMS)