encrypted_media_istypesupported_browsertest.cc revision 58537e28ecd584eab876aee8be7156509866d23a
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(WIDEVINE_CDM_AVAILABLE) && \ 25 defined(OS_LINUX) && !defined(OS_CHROMEOS) 26#include <gnu/libc-version.h> 27#endif 28 29#if defined(USE_PROPRIETARY_CODECS) 30#define EXPECT_PROPRIETARY EXPECT_TRUE 31#else 32#define EXPECT_PROPRIETARY EXPECT_FALSE 33#endif 34 35// Expectations for External Clear Key. 36#if defined(ENABLE_PEPPER_CDMS) 37#define EXPECT_ECK EXPECT_TRUE 38#define EXPECT_ECKPROPRIETARY EXPECT_PROPRIETARY 39#else 40#define EXPECT_ECK EXPECT_FALSE 41#define EXPECT_ECKPROPRIETARY EXPECT_FALSE 42#endif // defined(ENABLE_PEPPER_CDMS) 43 44// Expectations for Widevine. 45#if defined(WIDEVINE_CDM_AVAILABLE) 46#if defined(OS_LINUX) && !defined(OS_CHROMEOS) 47// TODO(ddorwin): Remove after bots switch to Precise. 48#define EXPECT_WV(a) \ 49 EXPECT_EQ((std::string(gnu_get_libc_version()) != "2.11.1"), (a)) 50#else 51// See http://crbug.com/237627. 52#if defined(DISABLE_WIDEVINE_CDM_CANPLAYTYPE) 53#define EXPECT_WV EXPECT_FALSE 54#else 55#define EXPECT_WV EXPECT_TRUE 56#endif // defined(DISABLE_WIDEVINE_CDM_CANPLAYTYPE) 57#endif // defined(OS_LINUX) && !defined(OS_CHROMEOS) 58 59#if defined(WIDEVINE_CDM_CENC_SUPPORT_AVAILABLE) 60#define EXPECT_WVCENC EXPECT_TRUE 61 62#if defined(WIDEVINE_CDM_AVC1_SUPPORT_AVAILABLE) 63#define EXPECT_WVAVC1 EXPECT_TRUE 64#if defined(WIDEVINE_CDM_AAC_SUPPORT_AVAILABLE) 65#define EXPECT_WVAVC1AAC EXPECT_TRUE 66#else 67#define EXPECT_WVAVC1AAC EXPECT_FALSE 68#endif // defined(WIDEVINE_CDM_AAC_SUPPORT_AVAILABLE) 69#else // !defined(WIDEVINE_CDM_AVC1_SUPPORT_AVAILABLE) 70#define EXPECT_WVAVC1 EXPECT_FALSE 71#define EXPECT_WVAVC1AAC EXPECT_FALSE 72#endif // defined(WIDEVINE_CDM_AVC1_SUPPORT_AVAILABLE) 73 74#if defined(WIDEVINE_CDM_AAC_SUPPORT_AVAILABLE) 75#define EXPECT_WVAAC EXPECT_TRUE 76#else 77#define EXPECT_WVAAC EXPECT_FALSE 78#endif 79 80#else // !defined(WIDEVINE_CDM_CENC_SUPPORT_AVAILABLE) 81#define EXPECT_WVCENC EXPECT_FALSE 82#define EXPECT_WVAVC1 EXPECT_FALSE 83#define EXPECT_WVAVC1AAC EXPECT_FALSE 84#define EXPECT_WVAAC EXPECT_FALSE 85#endif // defined(WIDEVINE_CDM_CENC_SUPPORT_AVAILABLE) 86 87#else // !defined(WIDEVINE_CDM_AVAILABLE) 88#define EXPECT_WV EXPECT_FALSE 89#define EXPECT_WVCENC EXPECT_FALSE 90#define EXPECT_WVAVC1 EXPECT_FALSE 91#define EXPECT_WVAVC1AAC EXPECT_FALSE 92#define EXPECT_WVAAC EXPECT_FALSE 93#endif // defined(WIDEVINE_CDM_AVAILABLE) 94 95namespace chrome { 96 97static const char* const kClearKey = "webkit-org.w3.clearkey"; 98static const char* const kExternalClearKey = "org.chromium.externalclearkey"; 99static const char* const kWidevine = "com.widevine"; 100static const char* const kWidevineAlpha = "com.widevine.alpha"; 101 102class EncryptedMediaIsTypeSupportedTest : public InProcessBrowserTest { 103 protected: 104 EncryptedMediaIsTypeSupportedTest() : is_test_page_loaded_(false) { 105 vp8_codec_.push_back("vp8"); 106 107 vp80_codec_.push_back("vp8.0"); 108 109 vorbis_codec_.push_back("vorbis"); 110 111 vp8_and_vorbis_codecs_.push_back("vp8"); 112 vp8_and_vorbis_codecs_.push_back("vorbis"); 113 114 avc1_codec_.push_back("avc1"); 115 116 avc1_extended_codec_.push_back("avc1.4D400C"); 117 118 avc1_dot_codec_.push_back("avc1."); 119 120 avc2_codec_.push_back("avc2"); 121 122 aac_codec_.push_back("mp4a"); 123 124 avc1_and_aac_codecs_.push_back("avc1"); 125 avc1_and_aac_codecs_.push_back("mp4a"); 126 127 unknown_codec_.push_back("foo"); 128 129 mixed_codecs_.push_back("vorbis"); 130 mixed_codecs_.push_back("avc1"); 131 } 132 133 typedef std::vector<std::string> CodecVector; 134 135 const CodecVector& no_codecs() const { return no_codecs_; } 136 const CodecVector& vp8_codec() const { return vp8_codec_; } 137 const CodecVector& vp80_codec() const { return vp80_codec_; } 138 const CodecVector& vorbis_codec() const { return vorbis_codec_; } 139 const CodecVector& vp8_and_vorbis_codecs() const { 140 return vp8_and_vorbis_codecs_; 141 } 142 const CodecVector& avc1_codec() const { return avc1_codec_; } 143 const CodecVector& avc1_extended_codec() const { 144 return avc1_extended_codec_; 145 } 146 const CodecVector& avc1_dot_codec() const { return avc1_dot_codec_; } 147 const CodecVector& avc2_codec() const { return avc2_codec_; } 148 const CodecVector& aac_codec() const { return aac_codec_; } 149 const CodecVector& avc1_and_aac_codecs() const { 150 return avc1_and_aac_codecs_; 151 } 152 const CodecVector& unknown_codec() const { return unknown_codec_; } 153 const CodecVector& mixed_codecs() const { return mixed_codecs_; } 154 155 // Update the command line to load |adapter_name| for 156 // |pepper_type_for_key_system|. 157 void RegisterPepperCdm(CommandLine* command_line, 158 const std::string& adapter_name, 159 const std::string& pepper_type_for_key_system) { 160 // Append the switch to register the appropriate adapter. 161 base::FilePath plugin_dir; 162 EXPECT_TRUE(PathService::Get(base::DIR_MODULE, &plugin_dir)); 163 base::FilePath plugin_lib = plugin_dir.AppendASCII(adapter_name); 164 EXPECT_TRUE(base::PathExists(plugin_lib)); 165 base::FilePath::StringType pepper_plugin = plugin_lib.value(); 166 pepper_plugin.append(FILE_PATH_LITERAL("#CDM#0.1.0.0;")); 167#if defined(OS_WIN) 168 pepper_plugin.append(ASCIIToWide(pepper_type_for_key_system)); 169#else 170 pepper_plugin.append(pepper_type_for_key_system); 171#endif 172 command_line->AppendSwitchNative(switches::kRegisterPepperPlugins, 173 pepper_plugin); 174 } 175 176 void LoadTestPage() { 177 // Load the test page needed. IsConcreteSupportedKeySystem() needs some 178 // JavaScript and a video loaded in order to work. 179 if (!is_test_page_loaded_) { 180 ASSERT_TRUE(test_server()->Start()); 181 GURL gurl = test_server()->GetURL( 182 "files/media/test_key_system_instantiation.html"); 183 ui_test_utils::NavigateToURL(browser(), gurl); 184 is_test_page_loaded_ = true; 185 } 186 } 187 188 bool IsConcreteSupportedKeySystem(const std::string& key) { 189 std::string command( 190 "window.domAutomationController.send(testKeySystemInstantiation('"); 191 command.append(key); 192 command.append("'));"); 193 194 // testKeySystemInstantiation() is a JavaScript function which needs to 195 // be loaded. 196 LoadTestPage(); 197 198 std::string result; 199 EXPECT_TRUE(content::ExecuteScriptAndExtractString( 200 browser()->tab_strip_model()->GetActiveWebContents(), 201 command, 202 &result)); 203 DCHECK(result == "success" || result == "NotSupportedError"); 204 return (result == "success"); 205 } 206 207 bool IsSupportedKeySystemWithMediaMimeType(const std::string& type, 208 const CodecVector& codecs, 209 const std::string& keySystem) { 210 std::string command("document.createElement('video').canPlayType("); 211 if (type.empty()) { 212 // Simple case, pass "null" as first argument. 213 command.append("null"); 214 DCHECK(codecs.empty()); 215 } else { 216 command.append("'"); 217 command.append(type); 218 if (!codecs.empty()) { 219 command.append("; codecs=\""); 220 for (CodecVector::const_iterator it = codecs.begin(); 221 it != codecs.end(); 222 ++it) { 223 command.append(*it); 224 command.append(","); 225 } 226 command.replace(command.length() - 1, 1, "\""); 227 } 228 command.append("'"); 229 } 230 command.append(",'"); 231 command.append(keySystem); 232 command.append("')"); 233 234 std::string result; 235 EXPECT_TRUE(content::ExecuteScriptAndExtractString( 236 browser()->tab_strip_model()->GetActiveWebContents(), 237 "window.domAutomationController.send(" + command + ");", 238 &result)); 239 return (result == "maybe" || result == "probably"); 240 } 241 242 private: 243 const CodecVector no_codecs_; 244 CodecVector vp8_codec_; 245 CodecVector vp80_codec_; 246 CodecVector vorbis_codec_; 247 CodecVector vp8_and_vorbis_codecs_; 248 CodecVector avc1_codec_; 249 CodecVector avc1_extended_codec_; 250 CodecVector avc1_dot_codec_; 251 CodecVector avc2_codec_; 252 CodecVector aac_codec_; 253 CodecVector avc1_and_aac_codecs_; 254 CodecVector unknown_codec_; 255 CodecVector mixed_codecs_; 256 bool is_test_page_loaded_; 257}; 258 259// For ExternalClearKey tests, ensure that the ClearKey adapter is loaded. 260class EncryptedMediaIsTypeSupportedExternalClearKeyTest 261 : public EncryptedMediaIsTypeSupportedTest { 262#if defined(ENABLE_PEPPER_CDMS) 263 protected: 264 virtual void SetUpCommandLine(CommandLine* command_line) OVERRIDE { 265 // Platform-specific filename relative to the chrome executable. 266 const char adapter_file_name[] = 267#if defined(OS_MACOSX) 268 "clearkeycdmadapter.plugin"; 269#elif defined(OS_WIN) 270 "clearkeycdmadapter.dll"; 271#elif defined(OS_POSIX) 272 "libclearkeycdmadapter.so"; 273#endif 274 275 const std::string pepper_name("application/x-ppapi-clearkey-cdm"); 276 RegisterPepperCdm(command_line, adapter_file_name, pepper_name); 277 } 278#endif // defined(ENABLE_PEPPER_CDMS) 279}; 280 281// For Widevine tests, ensure that the Widevine adapter is loaded. 282class EncryptedMediaIsTypeSupportedWidevineTest 283 : public EncryptedMediaIsTypeSupportedTest { 284#if defined(WIDEVINE_CDM_AVAILABLE) && defined(ENABLE_PEPPER_CDMS) 285 protected: 286 virtual void SetUpCommandLine(CommandLine* command_line) OVERRIDE { 287 // File name of the adapter on different platforms. 288 const char adapter_file_name[] = 289#if defined(OS_MACOSX) 290 "widevinecdmadapter.plugin"; 291#elif defined(OS_WIN) 292 "widevinecdmadapter.dll"; 293#else // OS_LINUX, etc. 294 "libwidevinecdmadapter.so"; 295#endif 296 297 const std::string pepper_name("application/x-ppapi-widevine-cdm"); 298 RegisterPepperCdm(command_line, adapter_file_name, pepper_name); 299 } 300#endif // defined(ENABLE_PEPPER_CDMS) 301}; 302 303IN_PROC_BROWSER_TEST_F(EncryptedMediaIsTypeSupportedTest, ClearKey_Basic) { 304 EXPECT_TRUE(IsConcreteSupportedKeySystem(kClearKey)); 305 EXPECT_TRUE(IsSupportedKeySystemWithMediaMimeType( 306 "video/webm", no_codecs(), kClearKey)); 307 308 // Not yet out from behind the vendor prefix. 309 EXPECT_FALSE(IsConcreteSupportedKeySystem("org.w3.clearkey")); 310 EXPECT_FALSE(IsSupportedKeySystemWithMediaMimeType( 311 "video/webm", no_codecs(), "org.w3.clearkey")); 312} 313 314IN_PROC_BROWSER_TEST_F(EncryptedMediaIsTypeSupportedTest, ClearKey_Parent) { 315 const char* const kClearKeyParent = "webkit-org.w3"; 316 317 // The parent should be supported but is not. See http://crbug.com/164303. 318 EXPECT_FALSE(IsConcreteSupportedKeySystem(kClearKeyParent)); 319 EXPECT_FALSE(IsSupportedKeySystemWithMediaMimeType( 320 "video/webm", no_codecs(), kClearKeyParent)); 321} 322 323IN_PROC_BROWSER_TEST_F(EncryptedMediaIsTypeSupportedTest, 324 ClearKey_IsSupportedKeySystem_InvalidVariants) { 325 // Case sensitive. 326 EXPECT_FALSE(IsConcreteSupportedKeySystem("webkit-org.w3.ClEaRkEy")); 327 // This should fail, but currently canPlayType() converts it to lowercase. 328 // See http://crbug.com/286036. 329 EXPECT_TRUE(IsSupportedKeySystemWithMediaMimeType( 330 "video/webm", no_codecs(), "webkit-org.w3.ClEaRkEy")); 331 332 // TLDs are not allowed. 333 EXPECT_FALSE(IsConcreteSupportedKeySystem("webkit-org.")); 334 EXPECT_FALSE(IsSupportedKeySystemWithMediaMimeType( 335 "video/webm", no_codecs(), "webkit-org.")); 336 EXPECT_FALSE(IsConcreteSupportedKeySystem("webkit-org")); 337 EXPECT_FALSE(IsSupportedKeySystemWithMediaMimeType( 338 "video/webm", no_codecs(), "webkit-org")); 339 EXPECT_FALSE(IsConcreteSupportedKeySystem("org.")); 340 EXPECT_FALSE( 341 IsSupportedKeySystemWithMediaMimeType("video/webm", no_codecs(), "org.")); 342 EXPECT_FALSE(IsConcreteSupportedKeySystem("org")); 343 EXPECT_FALSE( 344 IsSupportedKeySystemWithMediaMimeType("video/webm", no_codecs(), "org")); 345 346 // Extra period. 347 EXPECT_FALSE(IsConcreteSupportedKeySystem("webkit-org.w3.")); 348 EXPECT_FALSE(IsSupportedKeySystemWithMediaMimeType( 349 "video/webm", no_codecs(), "webkit-org.w3.")); 350 351 // Incomplete. 352 EXPECT_FALSE(IsConcreteSupportedKeySystem("webkit-org.w3.clearke")); 353 EXPECT_FALSE(IsSupportedKeySystemWithMediaMimeType( 354 "video/webm", no_codecs(), "webkit-org.w3.clearke")); 355 356 // Extra character. 357 EXPECT_FALSE(IsConcreteSupportedKeySystem("webkit-org.w3.clearkeyz")); 358 EXPECT_FALSE(IsSupportedKeySystemWithMediaMimeType( 359 "video/webm", no_codecs(), "webkit-org.w3.clearkeyz")); 360 361 // There are no child key systems for Clear Key. 362 EXPECT_FALSE(IsConcreteSupportedKeySystem("webkit-org.w3.clearkey.foo")); 363 EXPECT_FALSE(IsSupportedKeySystemWithMediaMimeType( 364 "video/webm", no_codecs(), "webkit-org.w3.clearkey.foo")); 365} 366 367IN_PROC_BROWSER_TEST_F(EncryptedMediaIsTypeSupportedTest, 368 IsSupportedKeySystemWithMediaMimeType_ClearKey_NoType) { 369 // These two should be true. See http://crbug.com/164303. 370 EXPECT_FALSE(IsSupportedKeySystemWithMediaMimeType( 371 std::string(), no_codecs(), kClearKey)); 372 EXPECT_FALSE(IsSupportedKeySystemWithMediaMimeType( 373 std::string(), no_codecs(), "webkit-org.w3")); 374 375 EXPECT_FALSE(IsSupportedKeySystemWithMediaMimeType( 376 std::string(), no_codecs(), "webkit-org.w3.foo")); 377 EXPECT_FALSE(IsSupportedKeySystemWithMediaMimeType( 378 std::string(), no_codecs(), "webkit-org.w3.clearkey.foo")); 379} 380 381IN_PROC_BROWSER_TEST_F(EncryptedMediaIsTypeSupportedTest, 382 IsSupportedKeySystemWithMediaMimeType_ClearKey_WebM) { 383 // Valid video types. 384 EXPECT_TRUE(IsSupportedKeySystemWithMediaMimeType( 385 "video/webm", no_codecs(), kClearKey)); 386 // The parent should be supported but is not. See http://crbug.com/164303. 387 EXPECT_FALSE(IsSupportedKeySystemWithMediaMimeType( 388 "video/webm", no_codecs(), "webkit-org.w3")); 389 EXPECT_TRUE(IsSupportedKeySystemWithMediaMimeType( 390 "video/webm", vp8_codec(), kClearKey)); 391 EXPECT_TRUE(IsSupportedKeySystemWithMediaMimeType( 392 "video/webm", vp80_codec(), kClearKey)); 393 EXPECT_TRUE(IsSupportedKeySystemWithMediaMimeType( 394 "video/webm", vp8_and_vorbis_codecs(), kClearKey)); 395 EXPECT_TRUE(IsSupportedKeySystemWithMediaMimeType( 396 "video/webm", vorbis_codec(), kClearKey)); 397 398 // Non-Webm codecs. 399 EXPECT_FALSE(IsSupportedKeySystemWithMediaMimeType( 400 "video/webm", avc1_codec(), kClearKey)); 401 EXPECT_FALSE(IsSupportedKeySystemWithMediaMimeType( 402 "video/webm", unknown_codec(), kClearKey)); 403 EXPECT_FALSE(IsSupportedKeySystemWithMediaMimeType( 404 "video/webm", mixed_codecs(), kClearKey)); 405 406 // Valid audio types. 407 EXPECT_TRUE(IsSupportedKeySystemWithMediaMimeType( 408 "audio/webm", no_codecs(), kClearKey)); 409 EXPECT_TRUE(IsSupportedKeySystemWithMediaMimeType( 410 "audio/webm", vorbis_codec(), kClearKey)); 411 412 // Non-audio codecs. 413 EXPECT_FALSE(IsSupportedKeySystemWithMediaMimeType( 414 "audio/webm", vp8_codec(), kClearKey)); 415 EXPECT_FALSE(IsSupportedKeySystemWithMediaMimeType( 416 "audio/webm", vp8_and_vorbis_codecs(), kClearKey)); 417 418 // Non-Webm codec. 419 EXPECT_FALSE(IsSupportedKeySystemWithMediaMimeType( 420 "audio/webm", aac_codec(), kClearKey)); 421} 422 423IN_PROC_BROWSER_TEST_F(EncryptedMediaIsTypeSupportedTest, 424 IsSupportedKeySystemWithMediaMimeType_ClearKey_MP4) { 425 // Valid video types. 426 EXPECT_PROPRIETARY(IsSupportedKeySystemWithMediaMimeType( 427 "video/mp4", no_codecs(), kClearKey)); 428 // The parent should be supported but is not. See http://crbug.com/164303. 429 EXPECT_FALSE(IsSupportedKeySystemWithMediaMimeType( 430 "video/mp4", no_codecs(), "webkit-org.w3")); 431 EXPECT_PROPRIETARY(IsSupportedKeySystemWithMediaMimeType( 432 "video/mp4", avc1_codec(), kClearKey)); 433 EXPECT_PROPRIETARY(IsSupportedKeySystemWithMediaMimeType( 434 "video/mp4", avc1_and_aac_codecs(), kClearKey)); 435 EXPECT_PROPRIETARY(IsSupportedKeySystemWithMediaMimeType( 436 "video/mp4", aac_codec(), kClearKey)); 437 438 // Extended codecs. 439 EXPECT_PROPRIETARY(IsSupportedKeySystemWithMediaMimeType( 440 "video/mp4", avc1_extended_codec(), kClearKey)); 441 442 // Invalid codec format, but canPlayType() strips away the period. 443 EXPECT_PROPRIETARY(IsSupportedKeySystemWithMediaMimeType( 444 "video/mp4", avc1_dot_codec(), kClearKey)); 445 446 // Non-MP4 codecs. 447 EXPECT_FALSE(IsSupportedKeySystemWithMediaMimeType( 448 "video/mp4", avc2_codec(), kClearKey)); 449 EXPECT_FALSE(IsSupportedKeySystemWithMediaMimeType( 450 "video/mp4", vp8_codec(), kClearKey)); 451 EXPECT_FALSE(IsSupportedKeySystemWithMediaMimeType( 452 "video/mp4", unknown_codec(), kClearKey)); 453 EXPECT_FALSE(IsSupportedKeySystemWithMediaMimeType( 454 "video/mp4", mixed_codecs(), kClearKey)); 455 456 // Valid audio types. 457 EXPECT_PROPRIETARY(IsSupportedKeySystemWithMediaMimeType( 458 "audio/mp4", no_codecs(), kClearKey)); 459 EXPECT_PROPRIETARY(IsSupportedKeySystemWithMediaMimeType( 460 "audio/mp4", aac_codec(), kClearKey)); 461 462 // Non-audio codecs. 463 EXPECT_FALSE(IsSupportedKeySystemWithMediaMimeType( 464 "audio/mp4", avc1_codec(), kClearKey)); 465 EXPECT_FALSE(IsSupportedKeySystemWithMediaMimeType( 466 "audio/mp4", avc1_and_aac_codecs(), kClearKey)); 467 468 // Non-MP4 codec. 469 EXPECT_FALSE(IsSupportedKeySystemWithMediaMimeType( 470 "audio/mp4", vorbis_codec(), kClearKey)); 471} 472 473// 474// External Clear Key 475// 476 477IN_PROC_BROWSER_TEST_F(EncryptedMediaIsTypeSupportedExternalClearKeyTest, 478 ExternalClearKey_Basic) { 479 EXPECT_ECK(IsConcreteSupportedKeySystem(kExternalClearKey)); 480 EXPECT_ECK(IsSupportedKeySystemWithMediaMimeType( 481 "video/webm", no_codecs(), kExternalClearKey)); 482} 483 484IN_PROC_BROWSER_TEST_F(EncryptedMediaIsTypeSupportedExternalClearKeyTest, 485 ExternalClearKey_Parent) { 486 const char* const kExternalClearKeyParent = "org.chromium"; 487 488 // The parent should be supported but is not. See http://crbug.com/164303. 489 EXPECT_FALSE(IsConcreteSupportedKeySystem(kExternalClearKeyParent)); 490 EXPECT_FALSE(IsSupportedKeySystemWithMediaMimeType( 491 "video/webm", no_codecs(), kExternalClearKeyParent)); 492} 493 494IN_PROC_BROWSER_TEST_F(EncryptedMediaIsTypeSupportedExternalClearKeyTest, 495 ExternalClearKey_IsSupportedKeySystem_InvalidVariants) { 496 // Case sensitive. 497 EXPECT_FALSE(IsConcreteSupportedKeySystem("org.chromium.ExTeRnAlClEaRkEy")); 498 // This should fail, but currently canPlayType() converts it to lowercase. 499 // See http://crbug.com/286036. 500 EXPECT_TRUE(IsSupportedKeySystemWithMediaMimeType( 501 "video/webm", no_codecs(), "org.chromium.ExTeRnAlClEaRkEy")); 502 503 // TLDs are not allowed. 504 EXPECT_FALSE(IsConcreteSupportedKeySystem("org.")); 505 EXPECT_FALSE( 506 IsSupportedKeySystemWithMediaMimeType("video/webm", no_codecs(), "org.")); 507 EXPECT_FALSE(IsConcreteSupportedKeySystem("org")); 508 EXPECT_FALSE( 509 IsSupportedKeySystemWithMediaMimeType("video/webm", no_codecs(), "org")); 510 511 // Extra period. 512 EXPECT_FALSE(IsConcreteSupportedKeySystem("org.chromium.")); 513 EXPECT_FALSE(IsSupportedKeySystemWithMediaMimeType( 514 "video/webm", no_codecs(), "org.chromium.")); 515 516 // Incomplete. 517 EXPECT_FALSE(IsConcreteSupportedKeySystem("org.chromium.externalclearke")); 518 EXPECT_FALSE(IsSupportedKeySystemWithMediaMimeType( 519 "video/webm", no_codecs(), "org.chromium.externalclearke")); 520 521 // Extra character. 522 EXPECT_FALSE(IsConcreteSupportedKeySystem("org.chromium.externalclearkeyz")); 523 EXPECT_FALSE(IsSupportedKeySystemWithMediaMimeType( 524 "video/webm", no_codecs(), "org.chromium.externalclearkeyz")); 525 526 // There are no child key systems for Clear Key. 527 EXPECT_FALSE( 528 IsConcreteSupportedKeySystem("org.chromium.externalclearkey.foo")); 529 EXPECT_FALSE(IsSupportedKeySystemWithMediaMimeType( 530 "video/webm", no_codecs(), "org.chromium.externalclearkey.foo")); 531} 532 533IN_PROC_BROWSER_TEST_F( 534 EncryptedMediaIsTypeSupportedExternalClearKeyTest, 535 IsSupportedKeySystemWithMediaMimeType_ExternalClearKey_NoType) { 536 // These two should be true. See http://crbug.com/164303. 537 EXPECT_FALSE(IsSupportedKeySystemWithMediaMimeType( 538 std::string(), no_codecs(), kExternalClearKey)); 539 EXPECT_FALSE(IsSupportedKeySystemWithMediaMimeType( 540 std::string(), no_codecs(), "org.chromium")); 541 542 EXPECT_FALSE(IsSupportedKeySystemWithMediaMimeType( 543 std::string(), no_codecs(), "org.chromium.foo")); 544 EXPECT_FALSE(IsSupportedKeySystemWithMediaMimeType( 545 std::string(), no_codecs(), "org.chromium.externalclearkey.foo")); 546} 547 548IN_PROC_BROWSER_TEST_F( 549 EncryptedMediaIsTypeSupportedExternalClearKeyTest, 550 IsSupportedKeySystemWithMediaMimeType_ExternalClearKey_WebM) { 551 // Valid video types. 552 EXPECT_ECK(IsSupportedKeySystemWithMediaMimeType( 553 "video/webm", no_codecs(), kExternalClearKey)); 554 // The parent should be supported but is not. See http://crbug.com/164303. 555 EXPECT_FALSE(IsSupportedKeySystemWithMediaMimeType( 556 "video/webm", no_codecs(), "org.chromium")); 557 EXPECT_ECK(IsSupportedKeySystemWithMediaMimeType( 558 "video/webm", vp8_codec(), kExternalClearKey)); 559 EXPECT_ECK(IsSupportedKeySystemWithMediaMimeType( 560 "video/webm", vp80_codec(), kExternalClearKey)); 561 EXPECT_ECK(IsSupportedKeySystemWithMediaMimeType( 562 "video/webm", vp8_and_vorbis_codecs(), kExternalClearKey)); 563 EXPECT_ECK(IsSupportedKeySystemWithMediaMimeType( 564 "video/webm", vorbis_codec(), kExternalClearKey)); 565 566 // Non-Webm codecs. 567 EXPECT_FALSE(IsSupportedKeySystemWithMediaMimeType( 568 "video/webm", avc1_codec(), kExternalClearKey)); 569 EXPECT_FALSE(IsSupportedKeySystemWithMediaMimeType( 570 "video/webm", unknown_codec(), kExternalClearKey)); 571 EXPECT_FALSE(IsSupportedKeySystemWithMediaMimeType( 572 "video/webm", mixed_codecs(), kExternalClearKey)); 573 574 // Valid audio types. 575 EXPECT_ECK(IsSupportedKeySystemWithMediaMimeType( 576 "audio/webm", no_codecs(), kExternalClearKey)); 577 EXPECT_ECK(IsSupportedKeySystemWithMediaMimeType( 578 "audio/webm", vorbis_codec(), kExternalClearKey)); 579 580 // Non-audio codecs. 581 EXPECT_FALSE(IsSupportedKeySystemWithMediaMimeType( 582 "audio/webm", vp8_codec(), kExternalClearKey)); 583 EXPECT_FALSE(IsSupportedKeySystemWithMediaMimeType( 584 "audio/webm", vp8_and_vorbis_codecs(), kExternalClearKey)); 585 586 // Non-Webm codec. 587 EXPECT_FALSE(IsSupportedKeySystemWithMediaMimeType( 588 "audio/webm", aac_codec(), kExternalClearKey)); 589} 590 591IN_PROC_BROWSER_TEST_F( 592 EncryptedMediaIsTypeSupportedExternalClearKeyTest, 593 IsSupportedKeySystemWithMediaMimeType_ExternalClearKey_MP4) { 594 // Valid video types. 595 EXPECT_ECKPROPRIETARY(IsSupportedKeySystemWithMediaMimeType( 596 "video/mp4", no_codecs(), kExternalClearKey)); 597 // The parent should be supported but is not. See http://crbug.com/164303. 598 EXPECT_FALSE(IsSupportedKeySystemWithMediaMimeType( 599 "video/mp4", no_codecs(), "org.chromium")); 600 EXPECT_ECKPROPRIETARY(IsSupportedKeySystemWithMediaMimeType( 601 "video/mp4", avc1_codec(), kExternalClearKey)); 602 EXPECT_ECKPROPRIETARY(IsSupportedKeySystemWithMediaMimeType( 603 "video/mp4", avc1_and_aac_codecs(), kExternalClearKey)); 604 EXPECT_ECKPROPRIETARY(IsSupportedKeySystemWithMediaMimeType( 605 "video/mp4", aac_codec(), kExternalClearKey)); 606 607 // Extended codecs. 608 EXPECT_ECKPROPRIETARY(IsSupportedKeySystemWithMediaMimeType( 609 "video/mp4", avc1_extended_codec(), kExternalClearKey)); 610 611 // Invalid codec format, but canPlayType() strips away the period. 612 EXPECT_ECKPROPRIETARY(IsSupportedKeySystemWithMediaMimeType( 613 "video/mp4", avc1_dot_codec(), kExternalClearKey)); 614 615 // Non-MP4 codecs. 616 EXPECT_FALSE(IsSupportedKeySystemWithMediaMimeType( 617 "video/mp4", avc2_codec(), kExternalClearKey)); 618 EXPECT_FALSE(IsSupportedKeySystemWithMediaMimeType( 619 "video/mp4", vp8_codec(), kExternalClearKey)); 620 EXPECT_FALSE(IsSupportedKeySystemWithMediaMimeType( 621 "video/mp4", unknown_codec(), kExternalClearKey)); 622 EXPECT_FALSE(IsSupportedKeySystemWithMediaMimeType( 623 "video/mp4", mixed_codecs(), kExternalClearKey)); 624 625 // Valid audio types. 626 EXPECT_ECKPROPRIETARY(IsSupportedKeySystemWithMediaMimeType( 627 "audio/mp4", no_codecs(), kExternalClearKey)); 628 EXPECT_ECKPROPRIETARY(IsSupportedKeySystemWithMediaMimeType( 629 "audio/mp4", aac_codec(), kExternalClearKey)); 630 631 // Non-audio codecs. 632 EXPECT_FALSE(IsSupportedKeySystemWithMediaMimeType( 633 "audio/mp4", avc1_codec(), kExternalClearKey)); 634 EXPECT_FALSE(IsSupportedKeySystemWithMediaMimeType( 635 "audio/mp4", avc1_and_aac_codecs(), kExternalClearKey)); 636 637 // Non-MP4 codec. 638 EXPECT_FALSE(IsSupportedKeySystemWithMediaMimeType( 639 "audio/mp4", vorbis_codec(), kExternalClearKey)); 640} 641 642// 643// Widevine 644// 645 646IN_PROC_BROWSER_TEST_F(EncryptedMediaIsTypeSupportedWidevineTest, 647 Widevine_Basic) { 648#if defined(WIDEVINE_CDM_AVAILABLE) && defined(DISABLE_WIDEVINE_CDM_CANPLAYTYPE) 649 EXPECT_TRUE(IsConcreteSupportedKeySystem(kWidevineAlpha)); 650#else 651 EXPECT_WV(IsConcreteSupportedKeySystem(kWidevineAlpha)); 652#endif 653 EXPECT_WV(IsSupportedKeySystemWithMediaMimeType( 654 "video/webm", no_codecs(), kWidevineAlpha)); 655} 656 657IN_PROC_BROWSER_TEST_F(EncryptedMediaIsTypeSupportedWidevineTest, 658 Widevine_Parent) { 659 // The parent system is not a concrete system but is supported. 660 EXPECT_FALSE(IsConcreteSupportedKeySystem(kWidevine)); 661 EXPECT_WV(IsSupportedKeySystemWithMediaMimeType( 662 "video/webm", no_codecs(), kWidevine)); 663} 664 665IN_PROC_BROWSER_TEST_F(EncryptedMediaIsTypeSupportedWidevineTest, 666 Widevine_IsSupportedKeySystem_InvalidVariants) { 667 // Case sensitive. 668 EXPECT_FALSE(IsConcreteSupportedKeySystem("com.widevine.AlPhA")); 669 // This should fail, but currently canPlayType() converts it to lowercase. 670 // See http://crbug.com/286036. 671 EXPECT_WV(IsSupportedKeySystemWithMediaMimeType( 672 "video/webm", no_codecs(), "com.widevine.AlPhA")); 673 674 // TLDs are not allowed. 675 EXPECT_FALSE(IsConcreteSupportedKeySystem("com.")); 676 EXPECT_FALSE( 677 IsSupportedKeySystemWithMediaMimeType("video/webm", no_codecs(), "com.")); 678 EXPECT_FALSE(IsConcreteSupportedKeySystem("com")); 679 EXPECT_FALSE( 680 IsSupportedKeySystemWithMediaMimeType("video/webm", no_codecs(), "com")); 681 682 // Extra period. 683 EXPECT_FALSE(IsConcreteSupportedKeySystem("com.widevine.")); 684 EXPECT_FALSE(IsSupportedKeySystemWithMediaMimeType( 685 "video/webm", no_codecs(), "com.widevine.")); 686 687 // Incomplete. 688 EXPECT_FALSE(IsConcreteSupportedKeySystem("com.widevine.alph")); 689 EXPECT_FALSE(IsSupportedKeySystemWithMediaMimeType( 690 "video/webm", no_codecs(), "com.widevine.alph")); 691 692 // Extra character. 693 EXPECT_FALSE(IsConcreteSupportedKeySystem("com.widevine.alphab")); 694 EXPECT_FALSE(IsSupportedKeySystemWithMediaMimeType( 695 "video/webm", no_codecs(), "com.widevine.alphab")); 696 697 // There are no child key systems for Widevine Alpha. 698 EXPECT_FALSE(IsConcreteSupportedKeySystem("com.widevine.alpha.foo")); 699 EXPECT_FALSE(IsSupportedKeySystemWithMediaMimeType( 700 "video/webm", no_codecs(), "com.widevine.alpha.foo")); 701} 702 703IN_PROC_BROWSER_TEST_F(EncryptedMediaIsTypeSupportedWidevineTest, 704 IsSupportedKeySystemWithMediaMimeType_Widevine_NoType) { 705 // These two should be true. See http://crbug.com/164303. 706 EXPECT_FALSE(IsSupportedKeySystemWithMediaMimeType( 707 std::string(), no_codecs(), kWidevineAlpha)); 708 EXPECT_FALSE(IsSupportedKeySystemWithMediaMimeType( 709 std::string(), no_codecs(), kWidevine)); 710 711 EXPECT_FALSE(IsSupportedKeySystemWithMediaMimeType( 712 std::string(), no_codecs(), "com.widevine.foo")); 713 EXPECT_FALSE(IsSupportedKeySystemWithMediaMimeType( 714 std::string(), no_codecs(), "com.widevine.alpha.foo")); 715} 716 717IN_PROC_BROWSER_TEST_F(EncryptedMediaIsTypeSupportedWidevineTest, 718 IsSupportedKeySystemWithMediaMimeType_Widevine_WebM) { 719 // Valid video types. 720 EXPECT_WV(IsSupportedKeySystemWithMediaMimeType( 721 "video/webm", no_codecs(), kWidevineAlpha)); 722 EXPECT_WV(IsSupportedKeySystemWithMediaMimeType( 723 "video/webm", vp8_codec(), kWidevineAlpha)); 724 EXPECT_WV(IsSupportedKeySystemWithMediaMimeType( 725 "video/webm", vp80_codec(), kWidevineAlpha)); 726 EXPECT_WV(IsSupportedKeySystemWithMediaMimeType( 727 "video/webm", vp8_and_vorbis_codecs(), kWidevineAlpha)); 728 EXPECT_WV(IsSupportedKeySystemWithMediaMimeType( 729 "video/webm", vorbis_codec(), kWidevineAlpha)); 730 731 // Valid video types - parent key system. 732 EXPECT_WV(IsSupportedKeySystemWithMediaMimeType( 733 "video/webm", no_codecs(), kWidevine)); 734 EXPECT_WV(IsSupportedKeySystemWithMediaMimeType( 735 "video/webm", vp8_codec(), kWidevine)); 736 EXPECT_WV(IsSupportedKeySystemWithMediaMimeType( 737 "video/webm", vp80_codec(), kWidevine)); 738 EXPECT_WV(IsSupportedKeySystemWithMediaMimeType( 739 "video/webm", vp8_and_vorbis_codecs(), kWidevine)); 740 EXPECT_WV(IsSupportedKeySystemWithMediaMimeType( 741 "video/webm", vorbis_codec(), kWidevine)); 742 743 // Non-Webm codecs. 744 EXPECT_FALSE(IsSupportedKeySystemWithMediaMimeType( 745 "video/webm", avc1_codec(), kWidevineAlpha)); 746 EXPECT_FALSE(IsSupportedKeySystemWithMediaMimeType( 747 "video/webm", unknown_codec(), kWidevineAlpha)); 748 EXPECT_FALSE(IsSupportedKeySystemWithMediaMimeType( 749 "video/webm", mixed_codecs(), kWidevineAlpha)); 750 751 // Valid audio types. 752 EXPECT_WV(IsSupportedKeySystemWithMediaMimeType( 753 "audio/webm", no_codecs(), kWidevineAlpha)); 754 EXPECT_WV(IsSupportedKeySystemWithMediaMimeType( 755 "audio/webm", vorbis_codec(), kWidevineAlpha)); 756 757 // Valid audio types - parent key system. 758 EXPECT_WV(IsSupportedKeySystemWithMediaMimeType( 759 "audio/webm", no_codecs(), kWidevine)); 760 EXPECT_WV(IsSupportedKeySystemWithMediaMimeType( 761 "audio/webm", vorbis_codec(), kWidevine)); 762 763 // Non-audio codecs. 764 EXPECT_FALSE(IsSupportedKeySystemWithMediaMimeType( 765 "audio/webm", vp8_codec(), kWidevineAlpha)); 766 EXPECT_FALSE(IsSupportedKeySystemWithMediaMimeType( 767 "audio/webm", vp8_and_vorbis_codecs(), kWidevineAlpha)); 768 769 // Non-Webm codec. 770 EXPECT_FALSE(IsSupportedKeySystemWithMediaMimeType( 771 "audio/webm", aac_codec(), kWidevineAlpha)); 772} 773 774IN_PROC_BROWSER_TEST_F(EncryptedMediaIsTypeSupportedWidevineTest, 775 IsSupportedKeySystemWithMediaMimeType_Widevine_MP4) { 776 // Valid video types. 777 EXPECT_WVCENC(IsSupportedKeySystemWithMediaMimeType( 778 "video/mp4", no_codecs(), kWidevineAlpha)); 779 EXPECT_WVAVC1(IsSupportedKeySystemWithMediaMimeType( 780 "video/mp4", avc1_codec(), kWidevineAlpha)); 781 EXPECT_WVAVC1AAC(IsSupportedKeySystemWithMediaMimeType( 782 "video/mp4", avc1_and_aac_codecs(), kWidevineAlpha)); 783 EXPECT_WVAAC(IsSupportedKeySystemWithMediaMimeType( 784 "video/mp4", aac_codec(), kWidevineAlpha)); 785 786 // Valid video types - parent key system. 787 EXPECT_WVCENC(IsSupportedKeySystemWithMediaMimeType( 788 "video/mp4", no_codecs(), kWidevine)); 789 EXPECT_WVAVC1(IsSupportedKeySystemWithMediaMimeType( 790 "video/mp4", avc1_codec(), kWidevine)); 791 EXPECT_WVAVC1AAC(IsSupportedKeySystemWithMediaMimeType( 792 "video/mp4", avc1_and_aac_codecs(), kWidevine)); 793 EXPECT_WVAAC(IsSupportedKeySystemWithMediaMimeType( 794 "video/mp4", aac_codec(), kWidevine)); 795 796 // Extended codecs. 797 EXPECT_WVAVC1(IsSupportedKeySystemWithMediaMimeType( 798 "video/mp4", avc1_extended_codec(), kWidevineAlpha)); 799 800 // Invalid codec format, but canPlayType() strips away the period. 801 EXPECT_WVAVC1(IsSupportedKeySystemWithMediaMimeType( 802 "video/mp4", avc1_dot_codec(), kWidevineAlpha)); 803 804 // Non-MP4 codecs. 805 EXPECT_FALSE(IsSupportedKeySystemWithMediaMimeType( 806 "video/mp4", avc2_codec(), kWidevineAlpha)); 807 EXPECT_FALSE(IsSupportedKeySystemWithMediaMimeType( 808 "video/mp4", vp8_codec(), kWidevineAlpha)); 809 EXPECT_FALSE(IsSupportedKeySystemWithMediaMimeType( 810 "video/mp4", unknown_codec(), kWidevineAlpha)); 811 EXPECT_FALSE(IsSupportedKeySystemWithMediaMimeType( 812 "video/mp4", mixed_codecs(), kWidevineAlpha)); 813 814 // Valid audio types. 815 EXPECT_WVCENC(IsSupportedKeySystemWithMediaMimeType( 816 "audio/mp4", no_codecs(), kWidevineAlpha)); 817 EXPECT_WVAAC(IsSupportedKeySystemWithMediaMimeType( 818 "audio/mp4", aac_codec(), kWidevineAlpha)); 819 820 // Valid audio types - parent key system. 821 EXPECT_WVCENC(IsSupportedKeySystemWithMediaMimeType( 822 "audio/mp4", no_codecs(), kWidevine)); 823 EXPECT_WVAAC(IsSupportedKeySystemWithMediaMimeType( 824 "audio/mp4", aac_codec(), kWidevine)); 825 826 // Non-audio codecs. 827 EXPECT_FALSE(IsSupportedKeySystemWithMediaMimeType( 828 "audio/mp4", avc1_codec(), kWidevineAlpha)); 829 EXPECT_FALSE(IsSupportedKeySystemWithMediaMimeType( 830 "audio/mp4", avc1_and_aac_codecs(), kWidevineAlpha)); 831 832 // Non-MP4 codec. 833 EXPECT_FALSE(IsSupportedKeySystemWithMediaMimeType( 834 "audio/mp4", vorbis_codec(), kWidevineAlpha)); 835} 836 837} // namespace chrome 838