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 <string> 6 #include <vector> 7 8 #include "base/base_switches.h" 9 #include "base/command_line.h" 10 #include "base/files/file_path.h" 11 #include "base/path_service.h" 12 #include "base/strings/utf_string_conversions.h" 13 #include "chrome/browser/ui/browser.h" 14 #include "chrome/browser/ui/tabs/tab_strip_model.h" 15 #include "chrome/common/chrome_paths.h" 16 #include "chrome/test/base/in_process_browser_test.h" 17 #include "chrome/test/base/ui_test_utils.h" 18 #include "content/public/common/content_switches.h" 19 #include "content/public/test/browser_test_utils.h" 20 #include "url/gurl.h" 21 22 #include "widevine_cdm_version.h" // In SHARED_INTERMEDIATE_DIR. 23 24 #if defined(OS_ANDROID) 25 #error This file needs to be updated to run on Android. 26 #endif 27 28 #if defined(USE_PROPRIETARY_CODECS) 29 #define EXPECT_PROPRIETARY EXPECT_TRUE 30 #else 31 #define EXPECT_PROPRIETARY EXPECT_FALSE 32 #endif 33 34 // Expectations for External Clear Key. 35 #if defined(ENABLE_PEPPER_CDMS) 36 #define EXPECT_ECK EXPECT_TRUE 37 #define EXPECT_ECKPROPRIETARY EXPECT_PROPRIETARY 38 #else 39 #define EXPECT_ECK EXPECT_FALSE 40 #define EXPECT_ECKPROPRIETARY EXPECT_FALSE 41 #endif // defined(ENABLE_PEPPER_CDMS) 42 43 // Expectations for Widevine. 44 // Note: Widevine is not available on platforms using components because 45 // RegisterPepperCdm() cannot set the codecs. 46 // TODO(ddorwin): Enable these tests after we have the ability to use the CUS 47 // in these tests. See http://crbug.com/311724. 48 #if defined(WIDEVINE_CDM_AVAILABLE) && !defined(WIDEVINE_CDM_IS_COMPONENT) 49 #define EXPECT_WV EXPECT_TRUE 50 51 #if defined(WIDEVINE_CDM_AVC1_SUPPORT_AVAILABLE) 52 #define EXPECT_WVMP4 EXPECT_TRUE 53 #define EXPECT_WVAVC1 EXPECT_TRUE 54 #if defined(WIDEVINE_CDM_AAC_SUPPORT_AVAILABLE) 55 #define EXPECT_WVAVC1AAC EXPECT_TRUE 56 #else 57 #define EXPECT_WVAVC1AAC EXPECT_FALSE 58 #endif // defined(WIDEVINE_CDM_AAC_SUPPORT_AVAILABLE) 59 #else // !defined(WIDEVINE_CDM_AVC1_SUPPORT_AVAILABLE) 60 #define EXPECT_WVMP4 EXPECT_FALSE 61 #define EXPECT_WVAVC1 EXPECT_FALSE 62 #define EXPECT_WVAVC1AAC EXPECT_FALSE 63 #endif // defined(WIDEVINE_CDM_AVC1_SUPPORT_AVAILABLE) 64 65 #if defined(WIDEVINE_CDM_AAC_SUPPORT_AVAILABLE) 66 #define EXPECT_WVAAC EXPECT_TRUE 67 #else 68 #define EXPECT_WVAAC EXPECT_FALSE 69 #endif 70 71 #else // defined(WIDEVINE_CDM_AVAILABLE) && !defined(WIDEVINE_CDM_IS_COMPONENT) 72 #define EXPECT_WV EXPECT_FALSE 73 #define EXPECT_WVMP4 EXPECT_FALSE 74 #define EXPECT_WVAVC1 EXPECT_FALSE 75 #define EXPECT_WVAVC1AAC EXPECT_FALSE 76 #define EXPECT_WVAAC EXPECT_FALSE 77 #endif // defined(WIDEVINE_CDM_AVAILABLE) && 78 // !defined(WIDEVINE_CDM_IS_COMPONENT) 79 80 namespace chrome { 81 82 const char kPrefixedClearKey[] = "webkit-org.w3.clearkey"; 83 const char kPrefixedClearKeyParent[] = "webkit-org.w3"; 84 // TODO(ddorwin): Duplicate prefixed tests for unprefixed. 85 const char kUnprefixedClearKey[] = "org.w3.clearkey"; 86 const char kExternalClearKey[] = "org.chromium.externalclearkey"; 87 const char kWidevineAlpha[] = "com.widevine.alpha"; 88 const char kWidevine[] = "com.widevine"; 89 const char kWidevineAlphaHr[] = "com.widevine.alpha.hr"; 90 const char kWidevineAlphaHrNonCompositing[] = 91 "com.widevine.alpha.hrnoncompositing"; 92 93 // TODO(xhwang): Simplify this test! See http://crbug.com/367158 94 95 class EncryptedMediaIsTypeSupportedTest : public InProcessBrowserTest { 96 protected: 97 EncryptedMediaIsTypeSupportedTest() 98 : is_test_page_loaded_(false), is_pepper_cdm_registered_(false) { 99 vp8_codec_.push_back("vp8"); 100 101 vp80_codec_.push_back("vp8.0"); 102 103 vp9_codec_.push_back("vp9"); 104 105 vp90_codec_.push_back("vp9.0"); 106 107 vorbis_codec_.push_back("vorbis"); 108 109 vp8_and_vorbis_codecs_.push_back("vp8"); 110 vp8_and_vorbis_codecs_.push_back("vorbis"); 111 112 vp9_and_vorbis_codecs_.push_back("vp9"); 113 vp9_and_vorbis_codecs_.push_back("vorbis"); 114 115 avc1_codec_.push_back("avc1"); 116 117 avc1_extended_codec_.push_back("avc1.4D400C"); 118 119 avc1_dot_codec_.push_back("avc1."); 120 121 avc2_codec_.push_back("avc2"); 122 123 avc3_codec_.push_back("avc3"); 124 125 avc3_extended_codec_.push_back("avc3.64001f"); 126 127 aac_codec_.push_back("mp4a"); 128 129 avc1_and_aac_codecs_.push_back("avc1"); 130 avc1_and_aac_codecs_.push_back("mp4a"); 131 132 unknown_codec_.push_back("foo"); 133 134 mixed_codecs_.push_back("vorbis"); 135 mixed_codecs_.push_back("avc1"); 136 } 137 138 typedef std::vector<std::string> CodecVector; 139 140 const CodecVector& no_codecs() const { return no_codecs_; } 141 const CodecVector& vp8_codec() const { return vp8_codec_; } 142 const CodecVector& vp80_codec() const { return vp80_codec_; } 143 const CodecVector& vp9_codec() const { return vp9_codec_; } 144 const CodecVector& vp90_codec() const { return vp90_codec_; } 145 const CodecVector& vorbis_codec() const { return vorbis_codec_; } 146 const CodecVector& vp8_and_vorbis_codecs() const { 147 return vp8_and_vorbis_codecs_; 148 } 149 const CodecVector& vp9_and_vorbis_codecs() const { 150 return vp9_and_vorbis_codecs_; 151 } 152 const CodecVector& avc1_codec() const { return avc1_codec_; } 153 const CodecVector& avc1_extended_codec() const { 154 return avc1_extended_codec_; 155 } 156 const CodecVector& avc1_dot_codec() const { return avc1_dot_codec_; } 157 const CodecVector& avc2_codec() const { return avc2_codec_; } 158 const CodecVector& avc3_codec() const { return avc3_codec_; } 159 const CodecVector& avc3_extended_codec() const { 160 return avc3_extended_codec_; 161 } 162 const CodecVector& aac_codec() const { return aac_codec_; } 163 const CodecVector& avc1_and_aac_codecs() const { 164 return avc1_and_aac_codecs_; 165 } 166 const CodecVector& unknown_codec() const { return unknown_codec_; } 167 const CodecVector& mixed_codecs() const { return mixed_codecs_; } 168 169 // Update the command line to load |adapter_name| for 170 // |pepper_type_for_key_system|. 171 void RegisterPepperCdm(CommandLine* command_line, 172 const std::string& adapter_name, 173 const std::string& pepper_type_for_key_system, 174 bool expect_adapter_exists = true) { 175 DCHECK(!is_pepper_cdm_registered_) 176 << "RegisterPepperCdm() can only be called once."; 177 is_pepper_cdm_registered_ = true; 178 179 // Append the switch to register the appropriate adapter. 180 base::FilePath plugin_dir; 181 EXPECT_TRUE(PathService::Get(base::DIR_MODULE, &plugin_dir)); 182 base::FilePath plugin_lib = plugin_dir.AppendASCII(adapter_name); 183 EXPECT_EQ(expect_adapter_exists, base::PathExists(plugin_lib)); 184 base::FilePath::StringType pepper_plugin = plugin_lib.value(); 185 pepper_plugin.append(FILE_PATH_LITERAL("#CDM#0.1.0.0;")); 186 #if defined(OS_WIN) 187 pepper_plugin.append(base::ASCIIToWide(pepper_type_for_key_system)); 188 #else 189 pepper_plugin.append(pepper_type_for_key_system); 190 #endif 191 command_line->AppendSwitchNative(switches::kRegisterPepperPlugins, 192 pepper_plugin); 193 } 194 195 void LoadTestPage() { 196 // Load the test page needed. IsConcreteSupportedKeySystem() needs some 197 // JavaScript and a video loaded in order to work. 198 if (!is_test_page_loaded_) { 199 ASSERT_TRUE(test_server()->Start()); 200 GURL gurl = test_server()->GetURL( 201 "files/media/test_key_system_instantiation.html"); 202 ui_test_utils::NavigateToURL(browser(), gurl); 203 is_test_page_loaded_ = true; 204 } 205 } 206 207 bool IsConcreteSupportedKeySystem(const std::string& key) { 208 std::string command( 209 "window.domAutomationController.send(testKeySystemInstantiation('"); 210 command.append(key); 211 command.append("'));"); 212 213 // testKeySystemInstantiation() is a JavaScript function which needs to 214 // be loaded. 215 LoadTestPage(); 216 217 std::string result; 218 EXPECT_TRUE(content::ExecuteScriptAndExtractString( 219 browser()->tab_strip_model()->GetActiveWebContents(), 220 command, 221 &result)); 222 CHECK(result == "success" || result == "NotSupportedError") << result; 223 return (result == "success"); 224 } 225 226 bool IsSupportedKeySystemWithMediaMimeType(const std::string& type, 227 const CodecVector& codecs, 228 const std::string& keySystem) { 229 std::string command("document.createElement('video').canPlayType("); 230 if (type.empty()) { 231 // Simple case, pass "null" as first argument. 232 command.append("null"); 233 DCHECK(codecs.empty()); 234 } else { 235 command.append("'"); 236 command.append(type); 237 if (!codecs.empty()) { 238 command.append("; codecs=\""); 239 for (CodecVector::const_iterator it = codecs.begin(); 240 it != codecs.end(); 241 ++it) { 242 command.append(*it); 243 command.append(","); 244 } 245 command.replace(command.length() - 1, 1, "\""); 246 } 247 command.append("'"); 248 } 249 command.append(",'"); 250 command.append(keySystem); 251 command.append("')"); 252 253 std::string result; 254 EXPECT_TRUE(content::ExecuteScriptAndExtractString( 255 browser()->tab_strip_model()->GetActiveWebContents(), 256 "window.domAutomationController.send(" + command + ");", 257 &result)); 258 return (result == "maybe" || result == "probably"); 259 } 260 261 private: 262 const CodecVector no_codecs_; 263 CodecVector vp8_codec_; 264 CodecVector vp80_codec_; 265 CodecVector vp9_codec_; 266 CodecVector vp90_codec_; 267 CodecVector vorbis_codec_; 268 CodecVector vp8_and_vorbis_codecs_; 269 CodecVector vp9_and_vorbis_codecs_; 270 CodecVector avc1_codec_; 271 CodecVector avc1_extended_codec_; 272 CodecVector avc1_dot_codec_; 273 CodecVector avc2_codec_; 274 CodecVector avc3_codec_; 275 CodecVector avc3_extended_codec_; 276 CodecVector aac_codec_; 277 CodecVector avc1_and_aac_codecs_; 278 CodecVector unknown_codec_; 279 CodecVector mixed_codecs_; 280 bool is_test_page_loaded_; 281 bool is_pepper_cdm_registered_; 282 }; 283 284 // For ExternalClearKey tests, ensure that the ClearKey adapter is loaded. 285 class EncryptedMediaIsTypeSupportedExternalClearKeyTest 286 : public EncryptedMediaIsTypeSupportedTest { 287 #if defined(ENABLE_PEPPER_CDMS) 288 protected: 289 virtual void SetUpCommandLine(CommandLine* command_line) OVERRIDE { 290 // Platform-specific filename relative to the chrome executable. 291 const char adapter_file_name[] = 292 #if defined(OS_MACOSX) 293 "clearkeycdmadapter.plugin"; 294 #elif defined(OS_WIN) 295 "clearkeycdmadapter.dll"; 296 #elif defined(OS_POSIX) 297 "libclearkeycdmadapter.so"; 298 #endif 299 300 const std::string pepper_name("application/x-ppapi-clearkey-cdm"); 301 RegisterPepperCdm(command_line, adapter_file_name, pepper_name); 302 } 303 #endif // defined(ENABLE_PEPPER_CDMS) 304 }; 305 306 // For Widevine tests, ensure that the Widevine adapter is loaded. 307 class EncryptedMediaIsTypeSupportedWidevineTest 308 : public EncryptedMediaIsTypeSupportedTest { 309 #if defined(WIDEVINE_CDM_AVAILABLE) && defined(ENABLE_PEPPER_CDMS) && \ 310 defined(WIDEVINE_CDM_IS_COMPONENT) 311 protected: 312 virtual void SetUpCommandLine(CommandLine* command_line) OVERRIDE { 313 // File name of the adapter on different platforms. 314 const char adapter_file_name[] = 315 #if defined(OS_MACOSX) 316 "widevinecdmadapter.plugin"; 317 #elif defined(OS_WIN) 318 "widevinecdmadapter.dll"; 319 #else // OS_LINUX, etc. 320 "libwidevinecdmadapter.so"; 321 #endif 322 323 const std::string pepper_name("application/x-ppapi-widevine-cdm"); 324 RegisterPepperCdm(command_line, adapter_file_name, pepper_name); 325 } 326 #endif // defined(WIDEVINE_CDM_AVAILABLE) && defined(ENABLE_PEPPER_CDMS) && 327 // defined(WIDEVINE_CDM_IS_COMPONENT) 328 }; 329 330 #if defined(ENABLE_PEPPER_CDMS) 331 // Registers ClearKey CDM with the wrong path (filename). 332 class EncryptedMediaIsTypeSupportedClearKeyCDMRegisteredWithWrongPathTest 333 : public EncryptedMediaIsTypeSupportedTest { 334 protected: 335 virtual void SetUpCommandLine(CommandLine* command_line) OVERRIDE { 336 RegisterPepperCdm(command_line, 337 "clearkeycdmadapterwrongname.dll", 338 "application/x-ppapi-clearkey-cdm", 339 false); 340 } 341 }; 342 343 // Registers Widevine CDM with the wrong path (filename). 344 class EncryptedMediaIsTypeSupportedWidevineCDMRegisteredWithWrongPathTest 345 : public EncryptedMediaIsTypeSupportedTest { 346 protected: 347 virtual void SetUpCommandLine(CommandLine* command_line) OVERRIDE { 348 RegisterPepperCdm(command_line, 349 "widevinecdmadapterwrongname.dll", 350 "application/x-ppapi-widevine-cdm", 351 false); 352 } 353 }; 354 #endif // defined(ENABLE_PEPPER_CDMS) 355 356 IN_PROC_BROWSER_TEST_F(EncryptedMediaIsTypeSupportedTest, ClearKey_Basic) { 357 EXPECT_TRUE(IsConcreteSupportedKeySystem(kPrefixedClearKey)); 358 EXPECT_TRUE(IsSupportedKeySystemWithMediaMimeType( 359 "video/webm", no_codecs(), kPrefixedClearKey)); 360 361 // Not yet out from behind the vendor prefix. 362 EXPECT_FALSE(IsConcreteSupportedKeySystem(kUnprefixedClearKey)); 363 EXPECT_FALSE(IsSupportedKeySystemWithMediaMimeType( 364 "video/webm", no_codecs(), kUnprefixedClearKey)); 365 } 366 367 IN_PROC_BROWSER_TEST_F(EncryptedMediaIsTypeSupportedTest, ClearKey_Parent) { 368 // The parent should be supported but is not. See http://crbug.com/164303. 369 EXPECT_FALSE(IsConcreteSupportedKeySystem(kPrefixedClearKeyParent)); 370 EXPECT_FALSE(IsSupportedKeySystemWithMediaMimeType( 371 "video/webm", no_codecs(), kPrefixedClearKeyParent)); 372 } 373 374 IN_PROC_BROWSER_TEST_F(EncryptedMediaIsTypeSupportedTest, 375 ClearKey_IsSupportedKeySystem_InvalidVariants) { 376 // Case sensitive. 377 EXPECT_FALSE(IsConcreteSupportedKeySystem("webkit-org.w3.ClEaRkEy")); 378 // This should fail, but currently canPlayType() converts it to lowercase. 379 // See http://crbug.com/286036. 380 EXPECT_TRUE(IsSupportedKeySystemWithMediaMimeType( 381 "video/webm", no_codecs(), "webkit-org.w3.ClEaRkEy")); 382 383 // TLDs are not allowed. 384 EXPECT_FALSE(IsConcreteSupportedKeySystem("webkit-org.")); 385 EXPECT_FALSE(IsSupportedKeySystemWithMediaMimeType( 386 "video/webm", no_codecs(), "webkit-org.")); 387 EXPECT_FALSE(IsConcreteSupportedKeySystem("webkit-org")); 388 EXPECT_FALSE(IsSupportedKeySystemWithMediaMimeType( 389 "video/webm", no_codecs(), "webkit-org")); 390 EXPECT_FALSE(IsConcreteSupportedKeySystem("org.")); 391 EXPECT_FALSE( 392 IsSupportedKeySystemWithMediaMimeType("video/webm", no_codecs(), "org.")); 393 EXPECT_FALSE(IsConcreteSupportedKeySystem("org")); 394 EXPECT_FALSE( 395 IsSupportedKeySystemWithMediaMimeType("video/webm", no_codecs(), "org")); 396 397 // Extra period. 398 EXPECT_FALSE(IsConcreteSupportedKeySystem("webkit-org.w3.")); 399 EXPECT_FALSE(IsSupportedKeySystemWithMediaMimeType( 400 "video/webm", no_codecs(), "webkit-org.w3.")); 401 402 // Incomplete. 403 EXPECT_FALSE(IsConcreteSupportedKeySystem("webkit-org.w3.clearke")); 404 EXPECT_FALSE(IsSupportedKeySystemWithMediaMimeType( 405 "video/webm", no_codecs(), "webkit-org.w3.clearke")); 406 407 // Extra character. 408 EXPECT_FALSE(IsConcreteSupportedKeySystem("webkit-org.w3.clearkeyz")); 409 EXPECT_FALSE(IsSupportedKeySystemWithMediaMimeType( 410 "video/webm", no_codecs(), "webkit-org.w3.clearkeyz")); 411 412 // There are no child key systems for Clear Key. 413 EXPECT_FALSE(IsConcreteSupportedKeySystem("webkit-org.w3.clearkey.foo")); 414 EXPECT_FALSE(IsSupportedKeySystemWithMediaMimeType( 415 "video/webm", no_codecs(), "webkit-org.w3.clearkey.foo")); 416 } 417 418 IN_PROC_BROWSER_TEST_F(EncryptedMediaIsTypeSupportedTest, 419 IsSupportedKeySystemWithMediaMimeType_ClearKey_NoType) { 420 // These two should be true. See http://crbug.com/164303. 421 EXPECT_FALSE(IsSupportedKeySystemWithMediaMimeType( 422 std::string(), no_codecs(), kPrefixedClearKey)); 423 EXPECT_FALSE(IsSupportedKeySystemWithMediaMimeType( 424 std::string(), no_codecs(), kPrefixedClearKeyParent)); 425 426 EXPECT_FALSE(IsSupportedKeySystemWithMediaMimeType( 427 std::string(), no_codecs(), "webkit-org.w3.foo")); 428 EXPECT_FALSE(IsSupportedKeySystemWithMediaMimeType( 429 std::string(), no_codecs(), "webkit-org.w3.clearkey.foo")); 430 } 431 432 IN_PROC_BROWSER_TEST_F(EncryptedMediaIsTypeSupportedTest, 433 IsSupportedKeySystemWithMediaMimeType_ClearKey_WebM) { 434 // Valid video types. 435 EXPECT_TRUE(IsSupportedKeySystemWithMediaMimeType( 436 "video/webm", no_codecs(), kPrefixedClearKey)); 437 // The parent should be supported but is not. See http://crbug.com/164303. 438 EXPECT_FALSE(IsSupportedKeySystemWithMediaMimeType( 439 "video/webm", no_codecs(), kPrefixedClearKeyParent)); 440 EXPECT_TRUE(IsSupportedKeySystemWithMediaMimeType( 441 "video/webm", vp8_codec(), kPrefixedClearKey)); 442 EXPECT_TRUE(IsSupportedKeySystemWithMediaMimeType( 443 "video/webm", vp80_codec(), kPrefixedClearKey)); 444 EXPECT_TRUE(IsSupportedKeySystemWithMediaMimeType( 445 "video/webm", vp8_and_vorbis_codecs(), kPrefixedClearKey)); 446 EXPECT_TRUE(IsSupportedKeySystemWithMediaMimeType( 447 "video/webm", vp9_codec(), kPrefixedClearKey)); 448 EXPECT_TRUE(IsSupportedKeySystemWithMediaMimeType( 449 "video/webm", vp90_codec(), kPrefixedClearKey)); 450 EXPECT_TRUE(IsSupportedKeySystemWithMediaMimeType( 451 "video/webm", vp9_and_vorbis_codecs(), kPrefixedClearKey)); 452 EXPECT_TRUE(IsSupportedKeySystemWithMediaMimeType( 453 "video/webm", vorbis_codec(), kPrefixedClearKey)); 454 455 // Non-Webm codecs. 456 EXPECT_FALSE(IsSupportedKeySystemWithMediaMimeType( 457 "video/webm", avc1_codec(), kPrefixedClearKey)); 458 EXPECT_FALSE(IsSupportedKeySystemWithMediaMimeType( 459 "video/webm", unknown_codec(), kPrefixedClearKey)); 460 EXPECT_FALSE(IsSupportedKeySystemWithMediaMimeType( 461 "video/webm", mixed_codecs(), kPrefixedClearKey)); 462 463 // Valid audio types. 464 EXPECT_TRUE(IsSupportedKeySystemWithMediaMimeType( 465 "audio/webm", no_codecs(), kPrefixedClearKey)); 466 EXPECT_TRUE(IsSupportedKeySystemWithMediaMimeType( 467 "audio/webm", vorbis_codec(), kPrefixedClearKey)); 468 469 // Non-audio codecs. 470 EXPECT_FALSE(IsSupportedKeySystemWithMediaMimeType( 471 "audio/webm", vp8_codec(), kPrefixedClearKey)); 472 EXPECT_FALSE(IsSupportedKeySystemWithMediaMimeType( 473 "audio/webm", vp8_and_vorbis_codecs(), kPrefixedClearKey)); 474 EXPECT_FALSE(IsSupportedKeySystemWithMediaMimeType( 475 "audio/webm", vp9_codec(), kPrefixedClearKey)); 476 EXPECT_FALSE(IsSupportedKeySystemWithMediaMimeType( 477 "audio/webm", vp9_and_vorbis_codecs(), kPrefixedClearKey)); 478 479 // Non-Webm codec. 480 EXPECT_FALSE(IsSupportedKeySystemWithMediaMimeType( 481 "audio/webm", aac_codec(), kPrefixedClearKey)); 482 } 483 484 IN_PROC_BROWSER_TEST_F(EncryptedMediaIsTypeSupportedTest, 485 IsSupportedKeySystemWithMediaMimeType_ClearKey_MP4) { 486 // Valid video types. 487 EXPECT_PROPRIETARY(IsSupportedKeySystemWithMediaMimeType( 488 "video/mp4", no_codecs(), kPrefixedClearKey)); 489 // The parent should be supported but is not. See http://crbug.com/164303. 490 EXPECT_FALSE(IsSupportedKeySystemWithMediaMimeType( 491 "video/mp4", no_codecs(), kPrefixedClearKeyParent)); 492 EXPECT_PROPRIETARY(IsSupportedKeySystemWithMediaMimeType( 493 "video/mp4", avc1_codec(), kPrefixedClearKey)); 494 EXPECT_PROPRIETARY(IsSupportedKeySystemWithMediaMimeType( 495 "video/mp4", avc1_and_aac_codecs(), kPrefixedClearKey)); 496 EXPECT_PROPRIETARY(IsSupportedKeySystemWithMediaMimeType( 497 "video/mp4", avc3_codec(), kPrefixedClearKey)); 498 EXPECT_PROPRIETARY(IsSupportedKeySystemWithMediaMimeType( 499 "video/mp4", aac_codec(), kPrefixedClearKey)); 500 501 // Extended codecs. 502 EXPECT_PROPRIETARY(IsSupportedKeySystemWithMediaMimeType( 503 "video/mp4", avc1_extended_codec(), kPrefixedClearKey)); 504 EXPECT_PROPRIETARY(IsSupportedKeySystemWithMediaMimeType( 505 "video/mp4", avc3_extended_codec(), kPrefixedClearKey)); 506 507 // Invalid codec format, but canPlayType() strips away the period. 508 EXPECT_PROPRIETARY(IsSupportedKeySystemWithMediaMimeType( 509 "video/mp4", avc1_dot_codec(), kPrefixedClearKey)); 510 511 // Non-MP4 codecs. 512 EXPECT_FALSE(IsSupportedKeySystemWithMediaMimeType( 513 "video/mp4", avc2_codec(), kPrefixedClearKey)); 514 EXPECT_FALSE(IsSupportedKeySystemWithMediaMimeType( 515 "video/mp4", vp8_codec(), kPrefixedClearKey)); 516 EXPECT_FALSE(IsSupportedKeySystemWithMediaMimeType( 517 "video/mp4", unknown_codec(), kPrefixedClearKey)); 518 EXPECT_FALSE(IsSupportedKeySystemWithMediaMimeType( 519 "video/mp4", mixed_codecs(), kPrefixedClearKey)); 520 521 // Valid audio types. 522 EXPECT_PROPRIETARY(IsSupportedKeySystemWithMediaMimeType( 523 "audio/mp4", no_codecs(), kPrefixedClearKey)); 524 EXPECT_PROPRIETARY(IsSupportedKeySystemWithMediaMimeType( 525 "audio/mp4", aac_codec(), kPrefixedClearKey)); 526 527 // Non-audio codecs. 528 EXPECT_FALSE(IsSupportedKeySystemWithMediaMimeType( 529 "audio/mp4", avc1_codec(), kPrefixedClearKey)); 530 EXPECT_FALSE(IsSupportedKeySystemWithMediaMimeType( 531 "audio/mp4", avc1_and_aac_codecs(), kPrefixedClearKey)); 532 EXPECT_FALSE(IsSupportedKeySystemWithMediaMimeType( 533 "audio/mp4", avc3_codec(), kPrefixedClearKey)); 534 535 // Non-MP4 codec. 536 EXPECT_FALSE(IsSupportedKeySystemWithMediaMimeType( 537 "audio/mp4", vorbis_codec(), kPrefixedClearKey)); 538 } 539 540 // 541 // External Clear Key 542 // 543 544 // When defined(ENABLE_PEPPER_CDMS), this also tests the Pepper CDM check. 545 IN_PROC_BROWSER_TEST_F(EncryptedMediaIsTypeSupportedExternalClearKeyTest, 546 ExternalClearKey_Basic) { 547 EXPECT_ECK(IsConcreteSupportedKeySystem(kExternalClearKey)); 548 EXPECT_ECK(IsSupportedKeySystemWithMediaMimeType( 549 "video/webm", no_codecs(), kExternalClearKey)); 550 } 551 552 IN_PROC_BROWSER_TEST_F(EncryptedMediaIsTypeSupportedExternalClearKeyTest, 553 ExternalClearKey_Parent) { 554 const char* const kExternalClearKeyParent = "org.chromium"; 555 556 // The parent should be supported but is not. See http://crbug.com/164303. 557 EXPECT_FALSE(IsConcreteSupportedKeySystem(kExternalClearKeyParent)); 558 EXPECT_FALSE(IsSupportedKeySystemWithMediaMimeType( 559 "video/webm", no_codecs(), kExternalClearKeyParent)); 560 } 561 562 IN_PROC_BROWSER_TEST_F(EncryptedMediaIsTypeSupportedExternalClearKeyTest, 563 ExternalClearKey_IsSupportedKeySystem_InvalidVariants) { 564 // Case sensitive. 565 EXPECT_FALSE(IsConcreteSupportedKeySystem("org.chromium.ExTeRnAlClEaRkEy")); 566 // This should fail, but currently canPlayType() converts it to lowercase. 567 // See http://crbug.com/286036. 568 EXPECT_TRUE(IsSupportedKeySystemWithMediaMimeType( 569 "video/webm", no_codecs(), "org.chromium.ExTeRnAlClEaRkEy")); 570 571 // TLDs are not allowed. 572 EXPECT_FALSE(IsConcreteSupportedKeySystem("org.")); 573 EXPECT_FALSE( 574 IsSupportedKeySystemWithMediaMimeType("video/webm", no_codecs(), "org.")); 575 EXPECT_FALSE(IsConcreteSupportedKeySystem("org")); 576 EXPECT_FALSE( 577 IsSupportedKeySystemWithMediaMimeType("video/webm", no_codecs(), "org")); 578 579 // Extra period. 580 EXPECT_FALSE(IsConcreteSupportedKeySystem("org.chromium.")); 581 EXPECT_FALSE(IsSupportedKeySystemWithMediaMimeType( 582 "video/webm", no_codecs(), "org.chromium.")); 583 584 // Incomplete. 585 EXPECT_FALSE(IsConcreteSupportedKeySystem("org.chromium.externalclearke")); 586 EXPECT_FALSE(IsSupportedKeySystemWithMediaMimeType( 587 "video/webm", no_codecs(), "org.chromium.externalclearke")); 588 589 // Extra character. 590 EXPECT_FALSE(IsConcreteSupportedKeySystem("org.chromium.externalclearkeyz")); 591 EXPECT_FALSE(IsSupportedKeySystemWithMediaMimeType( 592 "video/webm", no_codecs(), "org.chromium.externalclearkeyz")); 593 594 // There are no child key systems for Clear Key. 595 EXPECT_FALSE( 596 IsConcreteSupportedKeySystem("org.chromium.externalclearkey.foo")); 597 EXPECT_FALSE(IsSupportedKeySystemWithMediaMimeType( 598 "video/webm", no_codecs(), "org.chromium.externalclearkey.foo")); 599 } 600 601 IN_PROC_BROWSER_TEST_F( 602 EncryptedMediaIsTypeSupportedExternalClearKeyTest, 603 IsSupportedKeySystemWithMediaMimeType_ExternalClearKey_NoType) { 604 // These two should be true. See http://crbug.com/164303. 605 EXPECT_FALSE(IsSupportedKeySystemWithMediaMimeType( 606 std::string(), no_codecs(), kExternalClearKey)); 607 EXPECT_FALSE(IsSupportedKeySystemWithMediaMimeType( 608 std::string(), no_codecs(), "org.chromium")); 609 610 EXPECT_FALSE(IsSupportedKeySystemWithMediaMimeType( 611 std::string(), no_codecs(), "org.chromium.foo")); 612 EXPECT_FALSE(IsSupportedKeySystemWithMediaMimeType( 613 std::string(), no_codecs(), "org.chromium.externalclearkey.foo")); 614 } 615 616 IN_PROC_BROWSER_TEST_F( 617 EncryptedMediaIsTypeSupportedExternalClearKeyTest, 618 IsSupportedKeySystemWithMediaMimeType_ExternalClearKey_WebM) { 619 // Valid video types. 620 EXPECT_ECK(IsSupportedKeySystemWithMediaMimeType( 621 "video/webm", no_codecs(), kExternalClearKey)); 622 // The parent should be supported but is not. See http://crbug.com/164303. 623 EXPECT_FALSE(IsSupportedKeySystemWithMediaMimeType( 624 "video/webm", no_codecs(), "org.chromium")); 625 EXPECT_ECK(IsSupportedKeySystemWithMediaMimeType( 626 "video/webm", vp8_codec(), kExternalClearKey)); 627 EXPECT_ECK(IsSupportedKeySystemWithMediaMimeType( 628 "video/webm", vp80_codec(), kExternalClearKey)); 629 EXPECT_ECK(IsSupportedKeySystemWithMediaMimeType( 630 "video/webm", vp8_and_vorbis_codecs(), kExternalClearKey)); 631 EXPECT_ECK(IsSupportedKeySystemWithMediaMimeType( 632 "video/webm", vp9_codec(), kExternalClearKey)); 633 EXPECT_ECK(IsSupportedKeySystemWithMediaMimeType( 634 "video/webm", vp90_codec(), kExternalClearKey)); 635 EXPECT_ECK(IsSupportedKeySystemWithMediaMimeType( 636 "video/webm", vp9_and_vorbis_codecs(), kExternalClearKey)); 637 EXPECT_ECK(IsSupportedKeySystemWithMediaMimeType( 638 "video/webm", vorbis_codec(), kExternalClearKey)); 639 640 // Non-Webm codecs. 641 EXPECT_FALSE(IsSupportedKeySystemWithMediaMimeType( 642 "video/webm", avc1_codec(), kExternalClearKey)); 643 EXPECT_FALSE(IsSupportedKeySystemWithMediaMimeType( 644 "video/webm", unknown_codec(), kExternalClearKey)); 645 EXPECT_FALSE(IsSupportedKeySystemWithMediaMimeType( 646 "video/webm", mixed_codecs(), kExternalClearKey)); 647 648 // Valid audio types. 649 EXPECT_ECK(IsSupportedKeySystemWithMediaMimeType( 650 "audio/webm", no_codecs(), kExternalClearKey)); 651 EXPECT_ECK(IsSupportedKeySystemWithMediaMimeType( 652 "audio/webm", vorbis_codec(), kExternalClearKey)); 653 654 // Non-audio codecs. 655 EXPECT_FALSE(IsSupportedKeySystemWithMediaMimeType( 656 "audio/webm", vp8_codec(), kExternalClearKey)); 657 EXPECT_FALSE(IsSupportedKeySystemWithMediaMimeType( 658 "audio/webm", vp8_and_vorbis_codecs(), kExternalClearKey)); 659 EXPECT_FALSE(IsSupportedKeySystemWithMediaMimeType( 660 "audio/webm", vp9_codec(), kExternalClearKey)); 661 EXPECT_FALSE(IsSupportedKeySystemWithMediaMimeType( 662 "audio/webm", vp9_and_vorbis_codecs(), kExternalClearKey)); 663 664 // Non-Webm codec. 665 EXPECT_FALSE(IsSupportedKeySystemWithMediaMimeType( 666 "audio/webm", aac_codec(), kExternalClearKey)); 667 } 668 669 IN_PROC_BROWSER_TEST_F( 670 EncryptedMediaIsTypeSupportedExternalClearKeyTest, 671 IsSupportedKeySystemWithMediaMimeType_ExternalClearKey_MP4) { 672 // Valid video types. 673 EXPECT_ECKPROPRIETARY(IsSupportedKeySystemWithMediaMimeType( 674 "video/mp4", no_codecs(), kExternalClearKey)); 675 // The parent should be supported but is not. See http://crbug.com/164303. 676 EXPECT_FALSE(IsSupportedKeySystemWithMediaMimeType( 677 "video/mp4", no_codecs(), "org.chromium")); 678 EXPECT_ECKPROPRIETARY(IsSupportedKeySystemWithMediaMimeType( 679 "video/mp4", avc1_codec(), kExternalClearKey)); 680 EXPECT_ECKPROPRIETARY(IsSupportedKeySystemWithMediaMimeType( 681 "video/mp4", avc1_and_aac_codecs(), kExternalClearKey)); 682 EXPECT_ECKPROPRIETARY(IsSupportedKeySystemWithMediaMimeType( 683 "video/mp4", avc3_codec(), kExternalClearKey)); 684 EXPECT_ECKPROPRIETARY(IsSupportedKeySystemWithMediaMimeType( 685 "video/mp4", aac_codec(), kExternalClearKey)); 686 687 // Extended codecs. 688 EXPECT_ECKPROPRIETARY(IsSupportedKeySystemWithMediaMimeType( 689 "video/mp4", avc1_extended_codec(), kExternalClearKey)); 690 EXPECT_ECKPROPRIETARY(IsSupportedKeySystemWithMediaMimeType( 691 "video/mp4", avc3_extended_codec(), kExternalClearKey)); 692 693 // Invalid codec format, but canPlayType() strips away the period. 694 EXPECT_ECKPROPRIETARY(IsSupportedKeySystemWithMediaMimeType( 695 "video/mp4", avc1_dot_codec(), kExternalClearKey)); 696 697 // Non-MP4 codecs. 698 EXPECT_FALSE(IsSupportedKeySystemWithMediaMimeType( 699 "video/mp4", avc2_codec(), kExternalClearKey)); 700 EXPECT_FALSE(IsSupportedKeySystemWithMediaMimeType( 701 "video/mp4", vp8_codec(), kExternalClearKey)); 702 EXPECT_FALSE(IsSupportedKeySystemWithMediaMimeType( 703 "video/mp4", unknown_codec(), kExternalClearKey)); 704 EXPECT_FALSE(IsSupportedKeySystemWithMediaMimeType( 705 "video/mp4", mixed_codecs(), kExternalClearKey)); 706 707 // Valid audio types. 708 EXPECT_ECKPROPRIETARY(IsSupportedKeySystemWithMediaMimeType( 709 "audio/mp4", no_codecs(), kExternalClearKey)); 710 EXPECT_ECKPROPRIETARY(IsSupportedKeySystemWithMediaMimeType( 711 "audio/mp4", aac_codec(), kExternalClearKey)); 712 713 // Non-audio codecs. 714 EXPECT_FALSE(IsSupportedKeySystemWithMediaMimeType( 715 "audio/mp4", avc1_codec(), kExternalClearKey)); 716 EXPECT_FALSE(IsSupportedKeySystemWithMediaMimeType( 717 "audio/mp4", avc1_and_aac_codecs(), kExternalClearKey)); 718 EXPECT_FALSE(IsSupportedKeySystemWithMediaMimeType( 719 "audio/mp4", avc3_codec(), kExternalClearKey)); 720 721 // Non-MP4 codec. 722 EXPECT_FALSE(IsSupportedKeySystemWithMediaMimeType( 723 "audio/mp4", vorbis_codec(), kExternalClearKey)); 724 } 725 726 // 727 // Widevine 728 // 729 730 IN_PROC_BROWSER_TEST_F(EncryptedMediaIsTypeSupportedWidevineTest, 731 Widevine_Basic) { 732 #if defined(WIDEVINE_CDM_AVAILABLE) && defined(WIDEVINE_CDM_IS_COMPONENT) 733 EXPECT_TRUE(IsConcreteSupportedKeySystem(kWidevineAlpha)); 734 #else 735 EXPECT_WV(IsConcreteSupportedKeySystem(kWidevineAlpha)); 736 #endif 737 EXPECT_WV(IsSupportedKeySystemWithMediaMimeType( 738 "video/webm", no_codecs(), kWidevineAlpha)); 739 } 740 741 IN_PROC_BROWSER_TEST_F(EncryptedMediaIsTypeSupportedWidevineTest, 742 Widevine_Parent) { 743 // The parent system is not a concrete system but is supported. 744 EXPECT_FALSE(IsConcreteSupportedKeySystem(kWidevine)); 745 EXPECT_WV(IsSupportedKeySystemWithMediaMimeType( 746 "video/webm", no_codecs(), kWidevine)); 747 } 748 749 IN_PROC_BROWSER_TEST_F(EncryptedMediaIsTypeSupportedWidevineTest, 750 Widevine_IsSupportedKeySystem_InvalidVariants) { 751 // Case sensitive. 752 EXPECT_FALSE(IsConcreteSupportedKeySystem("com.widevine.AlPhA")); 753 // This should fail, but currently canPlayType() converts it to lowercase. 754 // See http://crbug.com/286036. 755 EXPECT_WV(IsSupportedKeySystemWithMediaMimeType( 756 "video/webm", no_codecs(), "com.widevine.AlPhA")); 757 758 // TLDs are not allowed. 759 EXPECT_FALSE(IsConcreteSupportedKeySystem("com.")); 760 EXPECT_FALSE( 761 IsSupportedKeySystemWithMediaMimeType("video/webm", no_codecs(), "com.")); 762 EXPECT_FALSE(IsConcreteSupportedKeySystem("com")); 763 EXPECT_FALSE( 764 IsSupportedKeySystemWithMediaMimeType("video/webm", no_codecs(), "com")); 765 766 // Extra period. 767 EXPECT_FALSE(IsConcreteSupportedKeySystem("com.widevine.")); 768 EXPECT_FALSE(IsSupportedKeySystemWithMediaMimeType( 769 "video/webm", no_codecs(), "com.widevine.")); 770 771 // Incomplete. 772 EXPECT_FALSE(IsConcreteSupportedKeySystem("com.widevine.alph")); 773 EXPECT_FALSE(IsSupportedKeySystemWithMediaMimeType( 774 "video/webm", no_codecs(), "com.widevine.alph")); 775 776 // Extra character. 777 EXPECT_FALSE(IsConcreteSupportedKeySystem("com.widevine.alphab")); 778 EXPECT_FALSE(IsSupportedKeySystemWithMediaMimeType( 779 "video/webm", no_codecs(), "com.widevine.alphab")); 780 781 // There are no child key systems for Widevine Alpha. 782 EXPECT_FALSE(IsConcreteSupportedKeySystem("com.widevine.alpha.foo")); 783 EXPECT_FALSE(IsSupportedKeySystemWithMediaMimeType( 784 "video/webm", no_codecs(), "com.widevine.alpha.foo")); 785 } 786 787 IN_PROC_BROWSER_TEST_F(EncryptedMediaIsTypeSupportedWidevineTest, 788 IsSupportedKeySystemWithMediaMimeType_Widevine_NoType) { 789 // These two should be true. See http://crbug.com/164303. 790 EXPECT_FALSE(IsSupportedKeySystemWithMediaMimeType( 791 std::string(), no_codecs(), kWidevineAlpha)); 792 EXPECT_FALSE(IsSupportedKeySystemWithMediaMimeType( 793 std::string(), no_codecs(), kWidevine)); 794 795 EXPECT_FALSE(IsSupportedKeySystemWithMediaMimeType( 796 std::string(), no_codecs(), "com.widevine.foo")); 797 EXPECT_FALSE(IsSupportedKeySystemWithMediaMimeType( 798 std::string(), no_codecs(), "com.widevine.alpha.foo")); 799 } 800 801 // TODO(xhwang): Add VP9 Widevine tests after VP9 is supported by Widevine CDM. 802 // See http://crbug.com/361318 803 804 IN_PROC_BROWSER_TEST_F(EncryptedMediaIsTypeSupportedWidevineTest, 805 IsSupportedKeySystemWithMediaMimeType_Widevine_WebM) { 806 // Valid video types. 807 EXPECT_WV(IsSupportedKeySystemWithMediaMimeType( 808 "video/webm", no_codecs(), kWidevineAlpha)); 809 EXPECT_WV(IsSupportedKeySystemWithMediaMimeType( 810 "video/webm", vp8_codec(), kWidevineAlpha)); 811 EXPECT_WV(IsSupportedKeySystemWithMediaMimeType( 812 "video/webm", vp80_codec(), kWidevineAlpha)); 813 EXPECT_WV(IsSupportedKeySystemWithMediaMimeType( 814 "video/webm", vp8_and_vorbis_codecs(), kWidevineAlpha)); 815 EXPECT_WV(IsSupportedKeySystemWithMediaMimeType( 816 "video/webm", vorbis_codec(), kWidevineAlpha)); 817 818 // Valid video types - parent key system. 819 EXPECT_WV(IsSupportedKeySystemWithMediaMimeType( 820 "video/webm", no_codecs(), kWidevine)); 821 EXPECT_WV(IsSupportedKeySystemWithMediaMimeType( 822 "video/webm", vp8_codec(), kWidevine)); 823 EXPECT_WV(IsSupportedKeySystemWithMediaMimeType( 824 "video/webm", vp80_codec(), kWidevine)); 825 EXPECT_WV(IsSupportedKeySystemWithMediaMimeType( 826 "video/webm", vp8_and_vorbis_codecs(), kWidevine)); 827 EXPECT_WV(IsSupportedKeySystemWithMediaMimeType( 828 "video/webm", vorbis_codec(), kWidevine)); 829 830 // Non-Webm codecs. 831 EXPECT_FALSE(IsSupportedKeySystemWithMediaMimeType( 832 "video/webm", avc1_codec(), kWidevineAlpha)); 833 EXPECT_FALSE(IsSupportedKeySystemWithMediaMimeType( 834 "video/webm", unknown_codec(), kWidevineAlpha)); 835 EXPECT_FALSE(IsSupportedKeySystemWithMediaMimeType( 836 "video/webm", mixed_codecs(), kWidevineAlpha)); 837 838 // Valid audio types. 839 EXPECT_WV(IsSupportedKeySystemWithMediaMimeType( 840 "audio/webm", no_codecs(), kWidevineAlpha)); 841 EXPECT_WV(IsSupportedKeySystemWithMediaMimeType( 842 "audio/webm", vorbis_codec(), kWidevineAlpha)); 843 844 // Valid audio types - parent key system. 845 EXPECT_WV(IsSupportedKeySystemWithMediaMimeType( 846 "audio/webm", no_codecs(), kWidevine)); 847 EXPECT_WV(IsSupportedKeySystemWithMediaMimeType( 848 "audio/webm", vorbis_codec(), kWidevine)); 849 850 // Non-audio codecs. 851 EXPECT_FALSE(IsSupportedKeySystemWithMediaMimeType( 852 "audio/webm", vp8_codec(), kWidevineAlpha)); 853 EXPECT_FALSE(IsSupportedKeySystemWithMediaMimeType( 854 "audio/webm", vp8_and_vorbis_codecs(), kWidevineAlpha)); 855 856 // Non-Webm codec. 857 EXPECT_FALSE(IsSupportedKeySystemWithMediaMimeType( 858 "audio/webm", aac_codec(), kWidevineAlpha)); 859 } 860 861 IN_PROC_BROWSER_TEST_F(EncryptedMediaIsTypeSupportedWidevineTest, 862 IsSupportedKeySystemWithMediaMimeType_Widevine_MP4) { 863 // Valid video types. 864 EXPECT_WVMP4(IsSupportedKeySystemWithMediaMimeType( 865 "video/mp4", no_codecs(), kWidevineAlpha)); 866 EXPECT_WVAVC1(IsSupportedKeySystemWithMediaMimeType( 867 "video/mp4", avc1_codec(), kWidevineAlpha)); 868 EXPECT_WVAVC1AAC(IsSupportedKeySystemWithMediaMimeType( 869 "video/mp4", avc1_and_aac_codecs(), kWidevineAlpha)); 870 EXPECT_WVAVC1(IsSupportedKeySystemWithMediaMimeType( 871 "video/mp4", avc3_codec(), kWidevineAlpha)); 872 EXPECT_WVAVC1AAC(IsSupportedKeySystemWithMediaMimeType( 873 "video/mp4", aac_codec(), kWidevineAlpha)); 874 875 // Valid video types - parent key system. 876 EXPECT_WVMP4(IsSupportedKeySystemWithMediaMimeType( 877 "video/mp4", no_codecs(), kWidevine)); 878 EXPECT_WVAVC1(IsSupportedKeySystemWithMediaMimeType( 879 "video/mp4", avc1_codec(), kWidevine)); 880 EXPECT_WVAVC1AAC(IsSupportedKeySystemWithMediaMimeType( 881 "video/mp4", avc1_and_aac_codecs(), kWidevine)); 882 EXPECT_WVAVC1AAC(IsSupportedKeySystemWithMediaMimeType( 883 "video/mp4", aac_codec(), kWidevine)); 884 885 // Extended codecs. 886 EXPECT_WVAVC1(IsSupportedKeySystemWithMediaMimeType( 887 "video/mp4", avc1_extended_codec(), kWidevineAlpha)); 888 EXPECT_WVAVC1(IsSupportedKeySystemWithMediaMimeType( 889 "video/mp4", avc3_extended_codec(), kWidevineAlpha)); 890 891 // Invalid codec format, but canPlayType() strips away the period. 892 EXPECT_WVAVC1(IsSupportedKeySystemWithMediaMimeType( 893 "video/mp4", avc1_dot_codec(), kWidevineAlpha)); 894 895 // Non-MP4 codecs. 896 EXPECT_FALSE(IsSupportedKeySystemWithMediaMimeType( 897 "video/mp4", avc2_codec(), kWidevineAlpha)); 898 EXPECT_FALSE(IsSupportedKeySystemWithMediaMimeType( 899 "video/mp4", vp8_codec(), kWidevineAlpha)); 900 EXPECT_FALSE(IsSupportedKeySystemWithMediaMimeType( 901 "video/mp4", unknown_codec(), kWidevineAlpha)); 902 EXPECT_FALSE(IsSupportedKeySystemWithMediaMimeType( 903 "video/mp4", mixed_codecs(), kWidevineAlpha)); 904 905 // Valid audio types. 906 EXPECT_WVMP4(IsSupportedKeySystemWithMediaMimeType( 907 "audio/mp4", no_codecs(), kWidevineAlpha)); 908 EXPECT_WVAAC(IsSupportedKeySystemWithMediaMimeType( 909 "audio/mp4", aac_codec(), kWidevineAlpha)); 910 911 // Valid audio types - parent key system. 912 EXPECT_WVMP4(IsSupportedKeySystemWithMediaMimeType( 913 "audio/mp4", no_codecs(), kWidevine)); 914 EXPECT_WVAAC(IsSupportedKeySystemWithMediaMimeType( 915 "audio/mp4", aac_codec(), kWidevine)); 916 917 // Non-audio codecs. 918 EXPECT_FALSE(IsSupportedKeySystemWithMediaMimeType( 919 "audio/mp4", avc1_codec(), kWidevineAlpha)); 920 EXPECT_FALSE(IsSupportedKeySystemWithMediaMimeType( 921 "audio/mp4", avc1_and_aac_codecs(), kWidevineAlpha)); 922 EXPECT_FALSE(IsSupportedKeySystemWithMediaMimeType( 923 "audio/mp4", avc3_codec(), kWidevineAlpha)); 924 925 // Non-MP4 codec. 926 EXPECT_FALSE(IsSupportedKeySystemWithMediaMimeType( 927 "audio/mp4", vorbis_codec(), kWidevineAlpha)); 928 } 929 930 IN_PROC_BROWSER_TEST_F(EncryptedMediaIsTypeSupportedWidevineTest, 931 Widevine_HR_Basic) { 932 // HR support cannot be detected in tests, so this is expected to fail 933 // everywhere. 934 EXPECT_FALSE(IsConcreteSupportedKeySystem(kWidevineAlphaHr)); 935 EXPECT_FALSE(IsSupportedKeySystemWithMediaMimeType( 936 "video/webm", no_codecs(), kWidevineAlphaHr)); 937 } 938 939 IN_PROC_BROWSER_TEST_F(EncryptedMediaIsTypeSupportedWidevineTest, 940 Widevine_HR_NonCompositing_Basic) { 941 // HR non-compositing support cannot be detected in tests, so this is expected 942 // to fail everywhere. 943 EXPECT_FALSE(IsConcreteSupportedKeySystem(kWidevineAlphaHrNonCompositing)); 944 EXPECT_FALSE(IsSupportedKeySystemWithMediaMimeType( 945 "video/webm", no_codecs(), kWidevineAlphaHrNonCompositing)); 946 } 947 948 #if defined(ENABLE_PEPPER_CDMS) 949 // Since this test fixture does not register the CDMs on the command line, the 950 // check for the CDMs in chrome_key_systems.cc should fail, and they should not 951 // be registered with KeySystems. 952 IN_PROC_BROWSER_TEST_F(EncryptedMediaIsTypeSupportedTest, 953 PepperCDMsNotRegistered) { 954 EXPECT_FALSE(IsConcreteSupportedKeySystem(kExternalClearKey)); 955 EXPECT_FALSE(IsSupportedKeySystemWithMediaMimeType( 956 "video/webm", no_codecs(), kExternalClearKey)); 957 958 // This will fail in all builds unless widevine is available but not a 959 // component, in which case it is registered internally 960 #if !defined(WIDEVINE_CDM_AVAILABLE) || defined(WIDEVINE_CDM_IS_COMPONENT) 961 EXPECT_FALSE(IsConcreteSupportedKeySystem(kWidevineAlpha)); 962 EXPECT_FALSE(IsSupportedKeySystemWithMediaMimeType( 963 "video/webm", no_codecs(), kWidevineAlpha)); 964 #endif 965 966 // Clear Key should still be registered. 967 EXPECT_TRUE(IsConcreteSupportedKeySystem(kPrefixedClearKey)); 968 EXPECT_TRUE(IsSupportedKeySystemWithMediaMimeType( 969 "video/webm", no_codecs(), kPrefixedClearKey)); 970 971 // Not yet out from behind the vendor prefix. 972 EXPECT_FALSE(IsConcreteSupportedKeySystem(kUnprefixedClearKey)); 973 EXPECT_FALSE(IsSupportedKeySystemWithMediaMimeType( 974 "video/webm", no_codecs(), kUnprefixedClearKey)); 975 } 976 977 // Since this test fixture does not register the CDMs on the command line, the 978 // check for the CDMs in chrome_key_systems.cc should fail, and they should not 979 // be registered with KeySystems. 980 IN_PROC_BROWSER_TEST_F( 981 EncryptedMediaIsTypeSupportedClearKeyCDMRegisteredWithWrongPathTest, 982 PepperCDMsRegisteredButAdapterNotPresent) { 983 EXPECT_FALSE(IsConcreteSupportedKeySystem(kExternalClearKey)); 984 EXPECT_FALSE(IsSupportedKeySystemWithMediaMimeType( 985 "video/webm", no_codecs(), kExternalClearKey)); 986 987 // Clear Key should still be registered. 988 EXPECT_TRUE(IsConcreteSupportedKeySystem(kPrefixedClearKey)); 989 EXPECT_TRUE(IsSupportedKeySystemWithMediaMimeType( 990 "video/webm", no_codecs(), kPrefixedClearKey)); 991 992 // Not yet out from behind the vendor prefix. 993 EXPECT_FALSE(IsConcreteSupportedKeySystem(kUnprefixedClearKey)); 994 EXPECT_FALSE(IsSupportedKeySystemWithMediaMimeType( 995 "video/webm", no_codecs(), kUnprefixedClearKey)); 996 } 997 998 // This will fail in all builds unless Widevine is available but not a 999 // component, in which case it is registered internally. 1000 // TODO(xhwang): Define EXPECT_WV and run this test in all cases. 1001 #if !defined(WIDEVINE_CDM_AVAILABLE) || defined(WIDEVINE_CDM_IS_COMPONENT) 1002 IN_PROC_BROWSER_TEST_F( 1003 EncryptedMediaIsTypeSupportedWidevineCDMRegisteredWithWrongPathTest, 1004 PepperCDMsRegisteredButAdapterNotPresent) { 1005 EXPECT_FALSE(IsConcreteSupportedKeySystem(kWidevineAlpha)); 1006 EXPECT_FALSE(IsSupportedKeySystemWithMediaMimeType( 1007 "video/webm", no_codecs(), kWidevineAlpha)); 1008 } 1009 #endif // !defined(WIDEVINE_CDM_AVAILABLE) || defined(WIDEVINE_CDM_IS_COMPONENT) 1010 #endif // defined(ENABLE_PEPPER_CDMS) 1011 1012 } // namespace chrome 1013