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. 4 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 21 22 #include "widevine_cdm_version.h" // In SHARED_INTERMEDIATE_DIR. 23 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 34 35 const char kClearKeyCdmPluginMimeType[] = "application/x-ppapi-clearkey-cdm"; 36 #endif // defined(ENABLE_PEPPER_CDMS) 37 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 kExternalClearKeyDecryptOnlyKeySystem[] = 43 "org.chromium.externalclearkey.decryptonly"; 44 const char kExternalClearKeyFileIOTestKeySystem[] = 45 "org.chromium.externalclearkey.fileiotest"; 46 const char kExternalClearKeyInitializeFailKeySystem[] = 47 "org.chromium.externalclearkey.initializefail"; 48 const char kExternalClearKeyCrashKeySystem[] = 49 "org.chromium.externalclearkey.crash"; 50 51 // Supported media types. 52 const char kWebMAudioOnly[] = "audio/webm; codecs=\"vorbis\""; 53 const char kWebMVideoOnly[] = "video/webm; codecs=\"vp8\""; 54 const char kWebMVP9VideoOnly[] = "video/webm; codecs=\"vp9\""; 55 const char kWebMAudioVideo[] = "video/webm; codecs=\"vorbis, vp8\""; 56 #if defined(USE_PROPRIETARY_CODECS) 57 const char kMP4AudioOnly[] = "audio/mp4; codecs=\"mp4a.40.2\""; 58 const char kMP4VideoOnly[] = "video/mp4; codecs=\"avc1.4D4041\""; 59 #endif // defined(USE_PROPRIETARY_CODECS) 60 61 // Sessions to load. 62 const char kNoSessionToLoad[] = ""; 63 const char kLoadableSession[] = "LoadableSession"; 64 const char kUnknownSession[] = "UnknownSession"; 65 66 // EME-specific test results and errors. 67 const char kEmeKeyError[] = "KEY_ERROR"; 68 const char kEmeNotSupportedError[] = "NOTSUPPORTEDERROR"; 69 const char kFileIOTestSuccess[] = "FILE_IO_TEST_SUCCESS"; 70 71 const char kDefaultEmePlayer[] = "eme_player.html"; 72 73 // The type of video src used to load media. 74 enum SrcType { 75 SRC, 76 MSE 77 }; 78 79 // Whether to use prefixed or unprefixed EME. 80 enum EmeVersion { 81 PREFIXED, 82 UNPREFIXED 83 }; 84 85 // MSE is available on all desktop platforms and on Android 4.1 and later. 86 static bool IsMSESupported() { 87 #if defined(OS_ANDROID) 88 if (base::android::BuildInfo::GetInstance()->sdk_int() < 16) { 89 VLOG(0) << "MSE is only supported in Android 4.1 and later."; 90 return false; 91 } 92 #endif // defined(OS_ANDROID) 93 return true; 94 } 95 96 static bool IsParentKeySystemOf(const std::string& parent_key_system, 97 const std::string& key_system) { 98 std::string prefix = parent_key_system + '.'; 99 return key_system.substr(0, prefix.size()) == prefix; 100 } 101 102 // Base class for encrypted media tests. 103 class EncryptedMediaTestBase : public MediaBrowserTest { 104 public: 105 EncryptedMediaTestBase() : is_pepper_cdm_registered_(false) {} 106 107 bool IsExternalClearKey(const std::string& key_system) { 108 return key_system == kExternalClearKeyKeySystem || 109 IsParentKeySystemOf(kExternalClearKeyKeySystem, key_system); 110 } 111 112 #if defined(WIDEVINE_CDM_AVAILABLE) 113 bool IsWidevine(const std::string& key_system) { 114 return key_system == kWidevineKeySystem; 115 } 116 #endif // defined(WIDEVINE_CDM_AVAILABLE) 117 118 void RunEncryptedMediaTestPage(const std::string& html_page, 119 const std::string& key_system, 120 std::vector<StringPair>* query_params, 121 const std::string& expected_title) { 122 StartLicenseServerIfNeeded(key_system, query_params); 123 RunMediaTestPage(html_page, query_params, expected_title, true); 124 } 125 126 // Tests |html_page| using |media_file| (with |media_type|) and |key_system|. 127 // When |session_to_load| is not empty, the test will try to load 128 // |session_to_load| with stored keys, instead of creating a new session 129 // and trying to update it with licenses. 130 // When |force_invalid_response| is true, the test will provide invalid 131 // responses, which should trigger errors. 132 // TODO(xhwang): Find an easier way to pass multiple configuration test 133 // options. 134 void RunEncryptedMediaTest(const std::string& html_page, 135 const std::string& media_file, 136 const std::string& media_type, 137 const std::string& key_system, 138 SrcType src_type, 139 EmeVersion eme_version, 140 const std::string& session_to_load, 141 bool force_invalid_response, 142 const std::string& expected_title) { 143 if (src_type == MSE && !IsMSESupported()) { 144 VLOG(0) << "Skipping test - MSE not supported."; 145 return; 146 } 147 std::vector<StringPair> query_params; 148 query_params.push_back(std::make_pair("mediaFile", media_file)); 149 query_params.push_back(std::make_pair("mediaType", media_type)); 150 query_params.push_back(std::make_pair("keySystem", key_system)); 151 if (src_type == MSE) 152 query_params.push_back(std::make_pair("useMSE", "1")); 153 if (eme_version == PREFIXED) 154 query_params.push_back(std::make_pair("usePrefixedEME", "1")); 155 if (force_invalid_response) 156 query_params.push_back(std::make_pair("forceInvalidResponse", "1")); 157 if (!session_to_load.empty()) 158 query_params.push_back(std::make_pair("sessionToLoad", session_to_load)); 159 RunEncryptedMediaTestPage(html_page, key_system, &query_params, 160 expected_title); 161 } 162 163 void RunSimpleEncryptedMediaTest(const std::string& media_file, 164 const std::string& media_type, 165 const std::string& key_system, 166 SrcType src_type, 167 EmeVersion eme_version) { 168 std::string expected_title = kEnded; 169 if (!IsPlayBackPossible(key_system)) 170 expected_title = kEmeKeyError; 171 172 RunEncryptedMediaTest(kDefaultEmePlayer, 173 media_file, 174 media_type, 175 key_system, 176 src_type, 177 eme_version, 178 kNoSessionToLoad, 179 false, 180 expected_title); 181 // Check KeyMessage received for all key systems. 182 bool receivedKeyMessage = false; 183 EXPECT_TRUE(content::ExecuteScriptAndExtractBool( 184 browser()->tab_strip_model()->GetActiveWebContents(), 185 "window.domAutomationController.send(" 186 "document.querySelector('video').receivedKeyMessage);", 187 &receivedKeyMessage)); 188 EXPECT_TRUE(receivedKeyMessage); 189 } 190 191 192 void StartLicenseServerIfNeeded(const std::string& key_system, 193 std::vector<StringPair>* query_params) { 194 scoped_ptr<TestLicenseServerConfig> config = GetServerConfig(key_system); 195 if (!config) 196 return; 197 license_server_.reset(new TestLicenseServer(config.Pass())); 198 EXPECT_TRUE(license_server_->Start()); 199 query_params->push_back(std::make_pair("licenseServerURL", 200 license_server_->GetServerURL())); 201 } 202 203 bool IsPlayBackPossible(const std::string& key_system) { 204 #if defined(WIDEVINE_CDM_AVAILABLE) 205 if (IsWidevine(key_system) && !GetServerConfig(key_system)) 206 return false; 207 #endif // defined(WIDEVINE_CDM_AVAILABLE) 208 return true; 209 } 210 211 scoped_ptr<TestLicenseServerConfig> GetServerConfig( 212 const std::string& key_system) { 213 #if defined(WIDEVINE_CDM_AVAILABLE) 214 if (IsWidevine(key_system)) { 215 scoped_ptr<TestLicenseServerConfig> config = 216 scoped_ptr<TestLicenseServerConfig>(new WVTestLicenseServerConfig()); 217 if (config->IsPlatformSupported()) 218 return config.Pass(); 219 } 220 #endif // defined(WIDEVINE_CDM_AVAILABLE) 221 return scoped_ptr<TestLicenseServerConfig>(); 222 } 223 224 protected: 225 scoped_ptr<TestLicenseServer> license_server_; 226 227 // We want to fail quickly when a test fails because an error is encountered. 228 virtual void AddWaitForTitles(content::TitleWatcher* title_watcher) OVERRIDE { 229 MediaBrowserTest::AddWaitForTitles(title_watcher); 230 title_watcher->AlsoWaitForTitle(base::ASCIIToUTF16(kEmeNotSupportedError)); 231 title_watcher->AlsoWaitForTitle(base::ASCIIToUTF16(kEmeKeyError)); 232 } 233 234 virtual void SetUpCommandLine(CommandLine* command_line) OVERRIDE { 235 #if defined(OS_ANDROID) 236 command_line->AppendSwitch( 237 switches::kDisableGestureRequirementForMediaPlayback); 238 #endif // defined(OS_ANDROID) 239 } 240 241 void SetUpCommandLineForKeySystem(const std::string& key_system, 242 CommandLine* command_line) { 243 if (GetServerConfig(key_system)) 244 // Since the web and license servers listen on different ports, we need to 245 // disable web-security to send license requests to the license server. 246 // TODO(shadi): Add port forwarding to the test web server configuration. 247 command_line->AppendSwitch(switches::kDisableWebSecurity); 248 249 #if defined(ENABLE_PEPPER_CDMS) 250 if (IsExternalClearKey(key_system)) { 251 RegisterPepperCdm(command_line, kClearKeyCdmAdapterFileName, key_system); 252 } 253 #if defined(WIDEVINE_CDM_AVAILABLE) && defined(WIDEVINE_CDM_IS_COMPONENT) 254 else if (IsWidevine(key_system)) { 255 RegisterPepperCdm(command_line, kWidevineCdmAdapterFileName, key_system); 256 } 257 #endif // defined(WIDEVINE_CDM_AVAILABLE) && defined(WIDEVINE_CDM_IS_COMPONENT) 258 #endif // defined(ENABLE_PEPPER_CDMS) 259 } 260 261 private: 262 #if defined(ENABLE_PEPPER_CDMS) 263 void RegisterPepperCdm(CommandLine* command_line, 264 const std::string& adapter_name, 265 const std::string& key_system) { 266 DCHECK(!is_pepper_cdm_registered_) 267 << "RegisterPepperCdm() can only be called once."; 268 is_pepper_cdm_registered_ = true; 269 270 // Append the switch to register the Clear Key CDM Adapter. 271 base::FilePath plugin_dir; 272 EXPECT_TRUE(PathService::Get(base::DIR_MODULE, &plugin_dir)); 273 base::FilePath plugin_lib = plugin_dir.AppendASCII(adapter_name); 274 EXPECT_TRUE(base::PathExists(plugin_lib)) << plugin_lib.value(); 275 base::FilePath::StringType pepper_plugin = plugin_lib.value(); 276 pepper_plugin.append(FILE_PATH_LITERAL("#CDM#0.1.0.0;")); 277 #if defined(OS_WIN) 278 pepper_plugin.append(base::ASCIIToWide(GetPepperType(key_system))); 279 #else 280 pepper_plugin.append(GetPepperType(key_system)); 281 #endif 282 command_line->AppendSwitchNative(switches::kRegisterPepperPlugins, 283 pepper_plugin); 284 } 285 286 // Adapted from key_systems.cc. 287 std::string GetPepperType(const std::string& key_system) { 288 if (IsExternalClearKey(key_system)) 289 return kClearKeyCdmPluginMimeType; 290 #if defined(WIDEVINE_CDM_AVAILABLE) 291 if (IsWidevine(key_system)) 292 return kWidevineCdmPluginMimeType; 293 #endif // WIDEVINE_CDM_AVAILABLE 294 295 NOTREACHED(); 296 return ""; 297 } 298 #endif // defined(ENABLE_PEPPER_CDMS) 299 300 bool is_pepper_cdm_registered_; 301 }; 302 303 #if defined(ENABLE_PEPPER_CDMS) 304 // Tests encrypted media playback using ExternalClearKey key system in 305 // decrypt-and-decode mode. 306 class ECKEncryptedMediaTest : public EncryptedMediaTestBase { 307 public: 308 // We use special |key_system| names to do non-playback related tests, e.g. 309 // kExternalClearKeyFileIOTestKeySystem is used to test file IO. 310 void TestNonPlaybackCases(const std::string& key_system, 311 const std::string& expected_title) { 312 // Since we do not test playback, arbitrarily choose a test file and source 313 // type. 314 RunEncryptedMediaTest(kDefaultEmePlayer, 315 "bear-a-enc_a.webm", 316 kWebMAudioOnly, 317 key_system, 318 SRC, 319 PREFIXED, 320 kNoSessionToLoad, 321 false, 322 expected_title); 323 } 324 325 protected: 326 virtual void SetUpCommandLine(CommandLine* command_line) OVERRIDE { 327 EncryptedMediaTestBase::SetUpCommandLine(command_line); 328 SetUpCommandLineForKeySystem(kExternalClearKeyKeySystem, command_line); 329 } 330 }; 331 332 #if defined(WIDEVINE_CDM_AVAILABLE) 333 // Tests encrypted media playback using Widevine key system. 334 class WVEncryptedMediaTest : public EncryptedMediaTestBase { 335 protected: 336 virtual void SetUpCommandLine(CommandLine* command_line) OVERRIDE { 337 EncryptedMediaTestBase::SetUpCommandLine(command_line); 338 command_line->AppendSwitch(switches::kEnableEncryptedMedia); 339 SetUpCommandLineForKeySystem(kWidevineKeySystem, command_line); 340 } 341 }; 342 343 #endif // defined(WIDEVINE_CDM_AVAILABLE) 344 #endif // defined(ENABLE_PEPPER_CDMS) 345 346 // Tests encrypted media playback with a combination of parameters: 347 // - char*: Key system name. 348 // - bool: True to load media using MSE, otherwise use src. 349 // - bool: True to use unprefixed EME, otherwise use prefixed EME. 350 // 351 // Note: Only parameterized (*_P) tests can be used. Non-parameterized (*_F) 352 // tests will crash at GetParam(). To add non-parameterized tests, use 353 // EncryptedMediaTestBase or one of its subclasses (e.g. WVEncryptedMediaTest). 354 class EncryptedMediaTest 355 : public EncryptedMediaTestBase, 356 public testing::WithParamInterface< 357 std::tr1::tuple<const char*, SrcType, EmeVersion> > { 358 public: 359 std::string CurrentKeySystem() { 360 return std::tr1::get<0>(GetParam()); 361 } 362 363 SrcType CurrentSourceType() { 364 return std::tr1::get<1>(GetParam()); 365 } 366 367 EmeVersion CurrentEmeVersion() { 368 return std::tr1::get<2>(GetParam()); 369 } 370 371 void TestSimplePlayback(const std::string& encrypted_media, 372 const std::string& media_type) { 373 RunSimpleEncryptedMediaTest(encrypted_media, 374 media_type, 375 CurrentKeySystem(), 376 CurrentSourceType(), 377 CurrentEmeVersion()); 378 } 379 380 void RunInvalidResponseTest() { 381 RunEncryptedMediaTest(kDefaultEmePlayer, 382 "bear-320x240-av-enc_av.webm", 383 kWebMAudioVideo, 384 CurrentKeySystem(), 385 CurrentSourceType(), 386 CurrentEmeVersion(), 387 kNoSessionToLoad, 388 true, 389 kEmeKeyError); 390 } 391 392 void TestFrameSizeChange() { 393 RunEncryptedMediaTest("encrypted_frame_size_change.html", 394 "frame_size_change-av-enc-v.webm", 395 kWebMAudioVideo, 396 CurrentKeySystem(), 397 CurrentSourceType(), 398 CurrentEmeVersion(), 399 kNoSessionToLoad, 400 false, 401 kEnded); 402 } 403 404 void TestConfigChange() { 405 DCHECK(IsMSESupported()); 406 std::vector<StringPair> query_params; 407 query_params.push_back(std::make_pair("keySystem", CurrentKeySystem())); 408 query_params.push_back(std::make_pair("runEncrypted", "1")); 409 if (CurrentEmeVersion() == PREFIXED) 410 query_params.push_back(std::make_pair("usePrefixedEME", "1")); 411 RunEncryptedMediaTestPage("mse_config_change.html", 412 CurrentKeySystem(), 413 &query_params, 414 kEnded); 415 } 416 417 protected: 418 virtual void SetUpCommandLine(CommandLine* command_line) OVERRIDE { 419 EncryptedMediaTestBase::SetUpCommandLine(command_line); 420 SetUpCommandLineForKeySystem(CurrentKeySystem(), command_line); 421 422 if (CurrentEmeVersion() == UNPREFIXED) 423 command_line->AppendSwitch(switches::kEnableEncryptedMedia); 424 } 425 }; 426 427 using ::testing::Combine; 428 using ::testing::Values; 429 430 #if !defined(OS_ANDROID) 431 INSTANTIATE_TEST_CASE_P(SRC_ClearKey_Prefixed, 432 EncryptedMediaTest, 433 Combine(Values(kPrefixedClearKeyKeySystem), 434 Values(SRC), 435 Values(PREFIXED))); 436 437 // TODO(jrummell): Enable unprefixed tests before shipping unprefixed EME. 438 // Disabled now as they don't provide much additional coverage, but do take a 439 // bit of time to execute. 440 INSTANTIATE_TEST_CASE_P(DISABLED_SRC_ClearKey, 441 EncryptedMediaTest, 442 Combine(Values(kClearKeyKeySystem), 443 Values(SRC), 444 Values(UNPREFIXED))); 445 #endif // !defined(OS_ANDROID) 446 447 INSTANTIATE_TEST_CASE_P(MSE_ClearKey_Prefixed, 448 EncryptedMediaTest, 449 Combine(Values(kPrefixedClearKeyKeySystem), 450 Values(MSE), 451 Values(PREFIXED))); 452 INSTANTIATE_TEST_CASE_P(MSE_ClearKey, 453 EncryptedMediaTest, 454 Combine(Values(kClearKeyKeySystem), 455 Values(MSE), 456 Values(UNPREFIXED))); 457 458 // External Clear Key is currently only used on platforms that use Pepper CDMs. 459 #if defined(ENABLE_PEPPER_CDMS) 460 INSTANTIATE_TEST_CASE_P(SRC_ExternalClearKey_Prefixed, 461 EncryptedMediaTest, 462 Combine(Values(kExternalClearKeyKeySystem), 463 Values(SRC), 464 Values(PREFIXED))); 465 INSTANTIATE_TEST_CASE_P(SRC_ExternalClearKey, 466 EncryptedMediaTest, 467 Combine(Values(kExternalClearKeyKeySystem), 468 Values(SRC), 469 Values(UNPREFIXED))); 470 INSTANTIATE_TEST_CASE_P(MSE_ExternalClearKey_Prefixed, 471 EncryptedMediaTest, 472 Combine(Values(kExternalClearKeyKeySystem), 473 Values(MSE), 474 Values(PREFIXED))); 475 INSTANTIATE_TEST_CASE_P(MSE_ExternalClearKey, 476 EncryptedMediaTest, 477 Combine(Values(kExternalClearKeyKeySystem), 478 Values(MSE), 479 Values(UNPREFIXED))); 480 // To reduce test time, only run ExternalClearKeyDecryptOnly with MSE. 481 INSTANTIATE_TEST_CASE_P(MSE_ExternalClearKeyDecryptOnly_Prefixed, 482 EncryptedMediaTest, 483 Combine(Values(kExternalClearKeyDecryptOnlyKeySystem), 484 Values(MSE), 485 Values(PREFIXED))); 486 INSTANTIATE_TEST_CASE_P(MSE_ExternalClearKeyDecryptOnly, 487 EncryptedMediaTest, 488 Combine(Values(kExternalClearKeyDecryptOnlyKeySystem), 489 Values(MSE), 490 Values(UNPREFIXED))); 491 #endif // defined(ENABLE_PEPPER_CDMS) 492 493 #if defined(WIDEVINE_CDM_AVAILABLE) 494 // This test doesn't fully test playback with Widevine. So we only run Widevine 495 // test with MSE (no SRC) to reduce test time. Also, on Android EME only works 496 // with MSE and we cannot run this test with SRC. 497 INSTANTIATE_TEST_CASE_P(MSE_Widevine_Prefixed, 498 EncryptedMediaTest, 499 Combine(Values(kWidevineKeySystem), 500 Values(MSE), 501 Values(PREFIXED))); 502 503 // Following tests fail if Widevine is loaded as a component, crbug.com/356833. 504 #if !defined(WIDEVINE_CDM_IS_COMPONENT) 505 INSTANTIATE_TEST_CASE_P(MSE_Widevine, 506 EncryptedMediaTest, 507 Combine(Values(kWidevineKeySystem), 508 Values(MSE), 509 Values(UNPREFIXED))); 510 #endif // !defined(WIDEVINE_CDM_IS_COMPONENT) 511 #endif // defined(WIDEVINE_CDM_AVAILABLE) 512 513 IN_PROC_BROWSER_TEST_P(EncryptedMediaTest, Playback_AudioOnly_WebM) { 514 TestSimplePlayback("bear-a-enc_a.webm", kWebMAudioOnly); 515 } 516 517 IN_PROC_BROWSER_TEST_P(EncryptedMediaTest, Playback_AudioClearVideo_WebM) { 518 TestSimplePlayback("bear-320x240-av-enc_a.webm", kWebMAudioVideo); 519 } 520 521 IN_PROC_BROWSER_TEST_P(EncryptedMediaTest, Playback_VideoAudio_WebM) { 522 TestSimplePlayback("bear-320x240-av-enc_av.webm", kWebMAudioVideo); 523 } 524 525 IN_PROC_BROWSER_TEST_P(EncryptedMediaTest, Playback_VideoOnly_WebM) { 526 TestSimplePlayback("bear-320x240-v-enc_v.webm", kWebMVideoOnly); 527 } 528 529 IN_PROC_BROWSER_TEST_P(EncryptedMediaTest, Playback_VideoClearAudio_WebM) { 530 TestSimplePlayback("bear-320x240-av-enc_v.webm", kWebMAudioVideo); 531 } 532 533 IN_PROC_BROWSER_TEST_P(EncryptedMediaTest, Playback_VP9Video_WebM) { 534 #if defined(WIDEVINE_CDM_AVAILABLE) 535 // TODO(xhwang): Remove this once VP9 is supported by Widevine CDM. 536 // See http://crbug.com/361318. 537 if (IsWidevine(CurrentKeySystem())) { 538 VLOG(0) << "VP9 not supported in Widevine CDM."; 539 return; 540 } 541 #endif 542 TestSimplePlayback("bear-320x240-v-vp9-enc_v.webm", kWebMVP9VideoOnly); 543 } 544 545 IN_PROC_BROWSER_TEST_P(EncryptedMediaTest, InvalidResponseKeyError) { 546 RunInvalidResponseTest(); 547 } 548 549 IN_PROC_BROWSER_TEST_P(EncryptedMediaTest, ConfigChangeVideo) { 550 if (CurrentSourceType() != MSE || !IsMSESupported()) { 551 VLOG(0) << "Skipping test - ConfigChange test requires MSE."; 552 return; 553 } 554 if (!IsPlayBackPossible(CurrentKeySystem())) { 555 VLOG(0) << "Skipping test - ConfigChange test requires video playback."; 556 return; 557 } 558 TestConfigChange(); 559 } 560 561 IN_PROC_BROWSER_TEST_P(EncryptedMediaTest, FrameSizeChangeVideo) { 562 // Times out on Windows XP. http://crbug.com/171937 563 #if defined(OS_WIN) 564 if (base::win::GetVersion() < base::win::VERSION_VISTA) 565 return; 566 #endif 567 if (!IsPlayBackPossible(CurrentKeySystem())) { 568 VLOG(0) << "Skipping test - FrameSizeChange test requires video playback."; 569 return; 570 } 571 TestFrameSizeChange(); 572 } 573 574 #if defined(USE_PROPRIETARY_CODECS) 575 IN_PROC_BROWSER_TEST_P(EncryptedMediaTest, Playback_VideoOnly_MP4) { 576 // MP4 without MSE is not support yet, http://crbug.com/170793. 577 if (CurrentSourceType() != MSE) { 578 VLOG(0) << "Skipping test; Can only play MP4 encrypted streams by MSE."; 579 return; 580 } 581 TestSimplePlayback("bear-640x360-v_frag-cenc.mp4", kMP4VideoOnly); 582 } 583 584 IN_PROC_BROWSER_TEST_P(EncryptedMediaTest, Playback_AudioOnly_MP4) { 585 // MP4 without MSE is not support yet, http://crbug.com/170793. 586 if (CurrentSourceType() != MSE) { 587 VLOG(0) << "Skipping test; Can only play MP4 encrypted streams by MSE."; 588 return; 589 } 590 TestSimplePlayback("bear-640x360-a_frag-cenc.mp4", kMP4AudioOnly); 591 } 592 #endif // defined(USE_PROPRIETARY_CODECS) 593 594 #if defined(WIDEVINE_CDM_AVAILABLE) 595 // The parent key system cannot be used in generateKeyRequest. 596 IN_PROC_BROWSER_TEST_F(WVEncryptedMediaTest, ParentThrowsException_Prefixed) { 597 RunEncryptedMediaTest(kDefaultEmePlayer, 598 "bear-a-enc_a.webm", 599 kWebMAudioOnly, 600 "com.widevine", 601 MSE, 602 PREFIXED, 603 kNoSessionToLoad, 604 false, 605 kEmeNotSupportedError); 606 } 607 608 // TODO(jrummell): http://crbug.com/349181 609 // The parent key system cannot be used when creating MediaKeys. 610 IN_PROC_BROWSER_TEST_F(WVEncryptedMediaTest, ParentThrowsException) { 611 RunEncryptedMediaTest(kDefaultEmePlayer, 612 "bear-a-enc_a.webm", 613 kWebMAudioOnly, 614 "com.widevine", 615 MSE, 616 UNPREFIXED, 617 kNoSessionToLoad, 618 false, 619 kEmeNotSupportedError); 620 } 621 #endif // defined(WIDEVINE_CDM_AVAILABLE) 622 623 #if defined(ENABLE_PEPPER_CDMS) 624 IN_PROC_BROWSER_TEST_F(ECKEncryptedMediaTest, InitializeCDMFail) { 625 TestNonPlaybackCases(kExternalClearKeyInitializeFailKeySystem, kEmeKeyError); 626 } 627 628 // When CDM crashes, we should still get a decode error. 629 // crbug.com/386657 630 IN_PROC_BROWSER_TEST_F(ECKEncryptedMediaTest, DISABLED_CDMCrashDuringDecode) { 631 IgnorePluginCrash(); 632 TestNonPlaybackCases(kExternalClearKeyCrashKeySystem, kError); 633 } 634 635 // Testing that the media browser test does fail on plugin crash. 636 // crbug.com/386657 637 IN_PROC_BROWSER_TEST_F(ECKEncryptedMediaTest, DISABLED_CDMExpectedCrash) { 638 // Plugin crash is not ignored by default, the test is expected to fail. 639 EXPECT_NONFATAL_FAILURE( 640 TestNonPlaybackCases(kExternalClearKeyCrashKeySystem, kError), 641 "plugin crash"); 642 } 643 644 IN_PROC_BROWSER_TEST_F(ECKEncryptedMediaTest, FileIOTest) { 645 TestNonPlaybackCases(kExternalClearKeyFileIOTestKeySystem, 646 kFileIOTestSuccess); 647 } 648 649 IN_PROC_BROWSER_TEST_F(ECKEncryptedMediaTest, LoadLoadableSession) { 650 RunEncryptedMediaTest(kDefaultEmePlayer, 651 "bear-320x240-v-enc_v.webm", 652 kWebMVideoOnly, 653 kExternalClearKeyKeySystem, 654 SRC, 655 PREFIXED, 656 kLoadableSession, 657 false, 658 kEnded); 659 } 660 661 IN_PROC_BROWSER_TEST_F(ECKEncryptedMediaTest, LoadUnknownSession) { 662 // TODO(xhwang): Add a specific error for this failure, e.g. kSessionNotFound. 663 RunEncryptedMediaTest(kDefaultEmePlayer, 664 "bear-320x240-v-enc_v.webm", 665 kWebMVideoOnly, 666 kExternalClearKeyKeySystem, 667 SRC, 668 PREFIXED, 669 kUnknownSession, 670 false, 671 kEmeKeyError); 672 } 673 #endif // defined(ENABLE_PEPPER_CDMS) 674