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