OLD | NEW |
(Empty) | |
| 1 // Copyright (c) 2012 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 "testing/gtest/include/gtest/gtest.h" |
| 9 #include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebString.h" |
| 10 #include "webkit/media/crypto/key_systems.h" |
| 11 |
| 12 #include "widevine_cdm_version.h" // In SHARED_INTERMEDIATE_DIR. |
| 13 |
| 14 using WebKit::WebString; |
| 15 |
| 16 #if defined(GOOGLE_CHROME_BUILD) || defined(USE_PROPRIETARY_CODECS) |
| 17 #define EXPECT_PROPRIETARY EXPECT_TRUE |
| 18 #else |
| 19 #define EXPECT_PROPRIETARY EXPECT_FALSE |
| 20 #endif |
| 21 |
| 22 #if defined(WIDEVINE_CDM_AVAILABLE) |
| 23 #define EXPECT_WV EXPECT_TRUE |
| 24 #else |
| 25 #define EXPECT_WV EXPECT_FALSE |
| 26 #endif |
| 27 |
| 28 #if defined(WIDEVINE_CDM_AVAILABLE) && \ |
| 29 defined(WIDEVINE_CDM_CENC_SUPPORT_AVAILABLE) |
| 30 #define EXPECT_WVISO EXPECT_TRUE |
| 31 #else |
| 32 #define EXPECT_WVISO EXPECT_FALSE |
| 33 #endif |
| 34 |
| 35 namespace webkit_media { |
| 36 |
| 37 static const char* const kClearKey = "webkit-org.w3.clearkey"; |
| 38 static const char* const kExternalClearKey = "org.chromium.externalclearkey"; |
| 39 static const char* const kWidevineAlpha = "com.widevine.alpha"; |
| 40 |
| 41 class KeySystemsTest : public testing::Test { |
| 42 protected: |
| 43 KeySystemsTest() { |
| 44 vp8_codec_.push_back("vp8"); |
| 45 |
| 46 vp80_codec_.push_back("vp8.0"); |
| 47 |
| 48 vorbis_codec_.push_back("vorbis"); |
| 49 |
| 50 vp8_and_vorbis_codecs_.push_back("vp8"); |
| 51 vp8_and_vorbis_codecs_.push_back("vorbis"); |
| 52 |
| 53 avc1_codec_.push_back("avc1"); |
| 54 |
| 55 avc1_extended_codec_.push_back("avc1.4D400C"); |
| 56 |
| 57 avc1_dot_codec_.push_back("avc1."); |
| 58 |
| 59 avc2_codec_.push_back("avc2"); |
| 60 |
| 61 aac_codec_.push_back("mp4a"); |
| 62 |
| 63 avc1_and_aac_codecs_.push_back("avc1"); |
| 64 avc1_and_aac_codecs_.push_back("mp4a"); |
| 65 |
| 66 unknown_codec_.push_back("foo"); |
| 67 |
| 68 mixed_codecs_.push_back("vorbis"); |
| 69 mixed_codecs_.push_back("avc1"); |
| 70 } |
| 71 |
| 72 typedef std::vector<std::string> CodecVector; |
| 73 |
| 74 const CodecVector& no_codecs() const { return no_codecs_; } |
| 75 |
| 76 const CodecVector& vp8_codec() const { return vp8_codec_; } |
| 77 const CodecVector& vp80_codec() const { return vp80_codec_; } |
| 78 const CodecVector& vorbis_codec() const { return vorbis_codec_; } |
| 79 const CodecVector& vp8_and_vorbis_codecs() const { |
| 80 return vp8_and_vorbis_codecs_; |
| 81 } |
| 82 |
| 83 const CodecVector& avc1_codec() const { return avc1_codec_; } |
| 84 const CodecVector& avc1_extended_codec() const { |
| 85 return avc1_extended_codec_; |
| 86 } |
| 87 const CodecVector& avc1_dot_codec() const { return avc1_dot_codec_; } |
| 88 const CodecVector& avc2_codec() const { return avc2_codec_; } |
| 89 const CodecVector& aac_codec() const { return aac_codec_; } |
| 90 const CodecVector& avc1_and_aac_codecs() const { |
| 91 return avc1_and_aac_codecs_; |
| 92 } |
| 93 |
| 94 const CodecVector& unknown_codec() const { return unknown_codec_; } |
| 95 |
| 96 const CodecVector& mixed_codecs() const { return mixed_codecs_; } |
| 97 |
| 98 private: |
| 99 const CodecVector no_codecs_; |
| 100 |
| 101 CodecVector vp8_codec_; |
| 102 CodecVector vp80_codec_; |
| 103 CodecVector vorbis_codec_; |
| 104 CodecVector vp8_and_vorbis_codecs_; |
| 105 |
| 106 CodecVector avc1_codec_; |
| 107 CodecVector avc1_extended_codec_; |
| 108 CodecVector avc1_dot_codec_; |
| 109 CodecVector avc2_codec_; |
| 110 CodecVector aac_codec_; |
| 111 CodecVector avc1_and_aac_codecs_; |
| 112 |
| 113 CodecVector unknown_codec_; |
| 114 |
| 115 CodecVector mixed_codecs_; |
| 116 |
| 117 }; |
| 118 |
| 119 TEST_F(KeySystemsTest, ClearKey_Basic) { |
| 120 EXPECT_TRUE(IsSupportedKeySystem(WebString::fromUTF8(kClearKey))); |
| 121 EXPECT_TRUE(IsSupportedKeySystemWithMediaMimeType( |
| 122 "video/webm", no_codecs(), kClearKey)); |
| 123 |
| 124 // Not yet out from behind the vendor prefix. |
| 125 EXPECT_FALSE(IsSupportedKeySystem("org.w3.clearkey")); |
| 126 EXPECT_FALSE(IsSupportedKeySystemWithMediaMimeType( |
| 127 "video/webm", no_codecs(), "org.w3.clearkey")); |
| 128 |
| 129 EXPECT_STREQ("ClearKey", KeySystemNameForUMA(std::string(kClearKey)).c_str()); |
| 130 EXPECT_STREQ("ClearKey", |
| 131 KeySystemNameForUMA(WebString::fromUTF8(kClearKey)).c_str()); |
| 132 |
| 133 EXPECT_TRUE(CanUseAesDecryptor(kClearKey)); |
| 134 EXPECT_TRUE(GetPluginType(kClearKey).empty()); // Does not use plugin. |
| 135 } |
| 136 |
| 137 TEST_F(KeySystemsTest, ClearKey_Parent) { |
| 138 const char* const kClearKeyParent = "webkit-org.w3"; |
| 139 |
| 140 // The parent should be supported but is not. See http://crbug.com/164303. |
| 141 EXPECT_FALSE(IsSupportedKeySystem(WebString::fromUTF8(kClearKeyParent))); |
| 142 EXPECT_FALSE(IsSupportedKeySystemWithMediaMimeType( |
| 143 "video/webm", no_codecs(), kClearKeyParent)); |
| 144 |
| 145 // The parent is not supported for most things. |
| 146 EXPECT_STREQ("Unknown", |
| 147 KeySystemNameForUMA(std::string(kClearKeyParent)).c_str()); |
| 148 EXPECT_STREQ("Unknown", |
| 149 KeySystemNameForUMA(WebString::fromUTF8(kClearKeyParent)).c_str()); |
| 150 EXPECT_FALSE(CanUseAesDecryptor(kClearKeyParent)); |
| 151 EXPECT_TRUE(GetPluginType(kClearKeyParent).empty()); |
| 152 } |
| 153 |
| 154 TEST_F(KeySystemsTest, ClearKey_IsSupportedKeySystem_InvalidVariants) { |
| 155 // Case sensitive. |
| 156 EXPECT_FALSE(IsSupportedKeySystem("webkit-org.w3.ClEaRkEy")); |
| 157 EXPECT_FALSE(IsSupportedKeySystemWithMediaMimeType( |
| 158 "video/webm", no_codecs(), "webkit-org.w3.ClEaRkEy")); |
| 159 |
| 160 // TLDs are not allowed. |
| 161 EXPECT_FALSE(IsSupportedKeySystem("webkit-org.")); |
| 162 EXPECT_FALSE(IsSupportedKeySystemWithMediaMimeType( |
| 163 "video/webm", no_codecs(), "webkit-org.")); |
| 164 EXPECT_FALSE(IsSupportedKeySystem("webkit-org")); |
| 165 EXPECT_FALSE(IsSupportedKeySystemWithMediaMimeType( |
| 166 "video/webm", no_codecs(), "webkit-org")); |
| 167 EXPECT_FALSE(IsSupportedKeySystem("org.")); |
| 168 EXPECT_FALSE(IsSupportedKeySystemWithMediaMimeType( |
| 169 "video/webm", no_codecs(), "org.")); |
| 170 EXPECT_FALSE(IsSupportedKeySystem("org")); |
| 171 EXPECT_FALSE(IsSupportedKeySystemWithMediaMimeType( |
| 172 "video/webm", no_codecs(), "org")); |
| 173 |
| 174 // Extra period. |
| 175 EXPECT_FALSE(IsSupportedKeySystem("webkit-org.w3.")); |
| 176 EXPECT_FALSE(IsSupportedKeySystemWithMediaMimeType( |
| 177 "video/webm", no_codecs(), "webkit-org.w3.")); |
| 178 |
| 179 // Incomplete. |
| 180 EXPECT_FALSE(IsSupportedKeySystem("webkit-org.w3.clearke")); |
| 181 EXPECT_FALSE(IsSupportedKeySystemWithMediaMimeType( |
| 182 "video/webm", no_codecs(), "webkit-org.w3.clearke")); |
| 183 |
| 184 // Extra character. |
| 185 EXPECT_FALSE(IsSupportedKeySystem("webkit-org.w3.clearkeyz")); |
| 186 EXPECT_FALSE(IsSupportedKeySystemWithMediaMimeType( |
| 187 "video/webm", no_codecs(), "webkit-org.w3.clearkeyz")); |
| 188 |
| 189 // There are no child key systems for Clear Key. |
| 190 EXPECT_FALSE(IsSupportedKeySystem("webkit-org.w3.clearkey.foo")); |
| 191 EXPECT_FALSE(IsSupportedKeySystemWithMediaMimeType( |
| 192 "video/webm", no_codecs(), "webkit-org.w3.clearkey.foo")); |
| 193 } |
| 194 |
| 195 TEST_F(KeySystemsTest, IsSupportedKeySystemWithMediaMimeType_ClearKey_NoType) { |
| 196 // These two should be true. See http://crbug.com/164303. |
| 197 EXPECT_FALSE(IsSupportedKeySystemWithMediaMimeType( |
| 198 "", no_codecs(), kClearKey)); |
| 199 EXPECT_FALSE(IsSupportedKeySystemWithMediaMimeType( |
| 200 "", no_codecs(), "webkit-org.w3")); |
| 201 |
| 202 EXPECT_FALSE(IsSupportedKeySystemWithMediaMimeType( |
| 203 "", no_codecs(), "webkit-org.w3.foo")); |
| 204 EXPECT_FALSE(IsSupportedKeySystemWithMediaMimeType( |
| 205 "", no_codecs(), "webkit-org.w3.clearkey.foo")); |
| 206 } |
| 207 |
| 208 TEST_F(KeySystemsTest, IsSupportedKeySystemWithMediaMimeType_ClearKey_WebM) { |
| 209 // Valid video types. |
| 210 EXPECT_TRUE(IsSupportedKeySystemWithMediaMimeType( |
| 211 "video/webm", no_codecs(), kClearKey)); |
| 212 // The parent should be supported but is not. See http://crbug.com/164303. |
| 213 EXPECT_FALSE(IsSupportedKeySystemWithMediaMimeType( |
| 214 "video/webm", no_codecs(), "webkit-org.w3")); |
| 215 EXPECT_TRUE(IsSupportedKeySystemWithMediaMimeType( |
| 216 "video/webm", vp8_codec(), kClearKey)); |
| 217 EXPECT_TRUE(IsSupportedKeySystemWithMediaMimeType( |
| 218 "video/webm", vp80_codec(), kClearKey)); |
| 219 // These two should be true. See http://crbug.com/123421. |
| 220 EXPECT_FALSE(IsSupportedKeySystemWithMediaMimeType( |
| 221 "video/webm", vp8_and_vorbis_codecs(), kClearKey)); |
| 222 EXPECT_FALSE(IsSupportedKeySystemWithMediaMimeType( |
| 223 "video/webm", vorbis_codec(), kClearKey)); |
| 224 |
| 225 // Non-Webm codecs. |
| 226 EXPECT_FALSE(IsSupportedKeySystemWithMediaMimeType( |
| 227 "video/webm", avc1_codec(), kClearKey)); |
| 228 EXPECT_FALSE(IsSupportedKeySystemWithMediaMimeType( |
| 229 "video/webm", unknown_codec(), kClearKey)); |
| 230 EXPECT_FALSE(IsSupportedKeySystemWithMediaMimeType( |
| 231 "video/webm", mixed_codecs(), kClearKey)); |
| 232 |
| 233 // Valid audio types. |
| 234 // Should be true. See http://crbug.com/123421. |
| 235 EXPECT_FALSE(IsSupportedKeySystemWithMediaMimeType( |
| 236 "audio/webm", no_codecs(), kClearKey)); |
| 237 EXPECT_FALSE(IsSupportedKeySystemWithMediaMimeType( |
| 238 "audio/webm", vorbis_codec(), kClearKey)); |
| 239 |
| 240 // Non-audio codecs. |
| 241 EXPECT_FALSE(IsSupportedKeySystemWithMediaMimeType( |
| 242 "audio/webm", vp8_codec(), kClearKey)); |
| 243 EXPECT_FALSE(IsSupportedKeySystemWithMediaMimeType( |
| 244 "audio/webm", vp8_and_vorbis_codecs(), kClearKey)); |
| 245 |
| 246 // Non-Webm codec. |
| 247 EXPECT_FALSE(IsSupportedKeySystemWithMediaMimeType( |
| 248 "audio/webm", aac_codec(), kClearKey)); |
| 249 } |
| 250 |
| 251 TEST_F(KeySystemsTest, IsSupportedKeySystemWithMediaMimeType_ClearKey_MP4) { |
| 252 // Valid video types. |
| 253 EXPECT_PROPRIETARY(IsSupportedKeySystemWithMediaMimeType( |
| 254 "video/mp4", no_codecs(), kClearKey)); |
| 255 // The parent should be supported but is not. See http://crbug.com/164303. |
| 256 EXPECT_FALSE(IsSupportedKeySystemWithMediaMimeType( |
| 257 "video/mp4", no_codecs(), "webkit-org.w3")); |
| 258 EXPECT_PROPRIETARY(IsSupportedKeySystemWithMediaMimeType( |
| 259 "video/mp4", avc1_codec(), kClearKey)); |
| 260 // These two should be true. See http://crbug.com/123421. |
| 261 EXPECT_FALSE(IsSupportedKeySystemWithMediaMimeType( |
| 262 "video/mp4", avc1_and_aac_codecs(), kClearKey)); |
| 263 EXPECT_FALSE(IsSupportedKeySystemWithMediaMimeType( |
| 264 "video/mp4", aac_codec(), kClearKey)); |
| 265 |
| 266 // Extended codecs fail because this is handled by SimpleWebMimeRegistryImpl. |
| 267 // They should really pass canPlayType(). |
| 268 EXPECT_FALSE(IsSupportedKeySystemWithMediaMimeType( |
| 269 "video/mp4", avc1_extended_codec(), kClearKey)); |
| 270 |
| 271 // Invalid codec format. |
| 272 EXPECT_FALSE(IsSupportedKeySystemWithMediaMimeType( |
| 273 "video/mp4", avc1_dot_codec(), kClearKey)); |
| 274 |
| 275 // Non-MP4 codecs. |
| 276 EXPECT_FALSE(IsSupportedKeySystemWithMediaMimeType( |
| 277 "video/mp4", avc2_codec(), kClearKey)); |
| 278 EXPECT_FALSE(IsSupportedKeySystemWithMediaMimeType( |
| 279 "video/mp4", vp8_codec(), kClearKey)); |
| 280 EXPECT_FALSE(IsSupportedKeySystemWithMediaMimeType( |
| 281 "video/mp4", unknown_codec(), kClearKey)); |
| 282 EXPECT_FALSE(IsSupportedKeySystemWithMediaMimeType( |
| 283 "video/mp4", mixed_codecs(), kClearKey)); |
| 284 |
| 285 // Valid audio types. |
| 286 // Should be true. See http://crbug.com/123421. |
| 287 EXPECT_FALSE(IsSupportedKeySystemWithMediaMimeType( |
| 288 "audio/mp4", no_codecs(), kClearKey)); |
| 289 EXPECT_FALSE(IsSupportedKeySystemWithMediaMimeType( |
| 290 "audio/mp4", aac_codec(), kClearKey)); |
| 291 |
| 292 // Non-audio codecs. |
| 293 EXPECT_FALSE(IsSupportedKeySystemWithMediaMimeType( |
| 294 "audio/mp4", avc1_codec(), kClearKey)); |
| 295 EXPECT_FALSE(IsSupportedKeySystemWithMediaMimeType( |
| 296 "audio/mp4", avc1_and_aac_codecs(), kClearKey)); |
| 297 |
| 298 // Non-MP4 codec. |
| 299 EXPECT_FALSE(IsSupportedKeySystemWithMediaMimeType( |
| 300 "audio/mp4", vorbis_codec(), kClearKey)); |
| 301 } |
| 302 |
| 303 // |
| 304 // External Clear Key |
| 305 // |
| 306 |
| 307 TEST_F(KeySystemsTest, ExternalClearKey_Basic) { |
| 308 EXPECT_TRUE(IsSupportedKeySystem(WebString::fromUTF8(kExternalClearKey))); |
| 309 EXPECT_TRUE(IsSupportedKeySystemWithMediaMimeType( |
| 310 "video/webm", no_codecs(), kExternalClearKey)); |
| 311 |
| 312 // External Clear Key does not have a UMA name because it is for testing. |
| 313 EXPECT_STREQ( |
| 314 "Unknown", |
| 315 KeySystemNameForUMA(std::string(kExternalClearKey)).c_str()); |
| 316 EXPECT_STREQ( |
| 317 "Unknown", |
| 318 KeySystemNameForUMA(WebString::fromUTF8(kExternalClearKey)).c_str()); |
| 319 |
| 320 EXPECT_FALSE(CanUseAesDecryptor(kExternalClearKey)); |
| 321 EXPECT_STREQ("application/x-ppapi-clearkey-cdm", |
| 322 GetPluginType(kExternalClearKey).c_str()); |
| 323 } |
| 324 |
| 325 TEST_F(KeySystemsTest, ExternalClearKey_Parent) { |
| 326 const char* const kExternalClearKeyParent = "org.chromium"; |
| 327 |
| 328 // The parent should be supported but is not. See http://crbug.com/164303. |
| 329 EXPECT_FALSE( |
| 330 IsSupportedKeySystem(WebString::fromUTF8(kExternalClearKeyParent))); |
| 331 EXPECT_FALSE(IsSupportedKeySystemWithMediaMimeType( |
| 332 "video/webm", no_codecs(), kExternalClearKeyParent)); |
| 333 |
| 334 // The parent is not supported for most things. |
| 335 EXPECT_STREQ( |
| 336 "Unknown", |
| 337 KeySystemNameForUMA(std::string(kExternalClearKeyParent)).c_str()); |
| 338 EXPECT_STREQ("Unknown", |
| 339 KeySystemNameForUMA( |
| 340 WebString::fromUTF8(kExternalClearKeyParent)).c_str()); |
| 341 EXPECT_FALSE(CanUseAesDecryptor(kExternalClearKeyParent)); |
| 342 EXPECT_TRUE(GetPluginType(kExternalClearKeyParent).empty()); |
| 343 } |
| 344 |
| 345 TEST_F(KeySystemsTest, ExternalClearKey_IsSupportedKeySystem_InvalidVariants) { |
| 346 // Case sensitive. |
| 347 EXPECT_FALSE(IsSupportedKeySystem("org.chromium.ExTeRnAlClEaRkEy")); |
| 348 EXPECT_FALSE(IsSupportedKeySystemWithMediaMimeType( |
| 349 "video/webm", no_codecs(), |
| 350 "org.chromium.ExTeRnAlClEaRkEy")); |
| 351 |
| 352 // TLDs are not allowed. |
| 353 EXPECT_FALSE(IsSupportedKeySystem("org.")); |
| 354 EXPECT_FALSE(IsSupportedKeySystemWithMediaMimeType( |
| 355 "video/webm", no_codecs(), "org.")); |
| 356 EXPECT_FALSE(IsSupportedKeySystem("org")); |
| 357 EXPECT_FALSE(IsSupportedKeySystemWithMediaMimeType( |
| 358 "video/webm", no_codecs(), "org")); |
| 359 |
| 360 // Extra period. |
| 361 EXPECT_FALSE(IsSupportedKeySystem("org.chromium.")); |
| 362 EXPECT_FALSE(IsSupportedKeySystemWithMediaMimeType( |
| 363 "video/webm", no_codecs(), "org.chromium.")); |
| 364 |
| 365 // Incomplete. |
| 366 EXPECT_FALSE(IsSupportedKeySystem("org.chromium.externalclearke")); |
| 367 EXPECT_FALSE(IsSupportedKeySystemWithMediaMimeType( |
| 368 "video/webm", no_codecs(), |
| 369 "org.chromium.externalclearke")); |
| 370 |
| 371 // Extra character. |
| 372 EXPECT_FALSE(IsSupportedKeySystem("org.chromium.externalclearkeyz")); |
| 373 EXPECT_FALSE(IsSupportedKeySystemWithMediaMimeType( |
| 374 "video/webm", no_codecs(), |
| 375 "org.chromium.externalclearkeyz")); |
| 376 |
| 377 // There are no child key systems for Clear Key. |
| 378 EXPECT_FALSE(IsSupportedKeySystem("org.chromium.externalclearkey.foo")); |
| 379 EXPECT_FALSE(IsSupportedKeySystemWithMediaMimeType( |
| 380 "video/webm", no_codecs(), |
| 381 "org.chromium.externalclearkey.foo")); |
| 382 } |
| 383 |
| 384 TEST_F(KeySystemsTest, |
| 385 IsSupportedKeySystemWithMediaMimeType_ExternalClearKey_NoType) { |
| 386 // These two should be true. See http://crbug.com/164303. |
| 387 EXPECT_FALSE(IsSupportedKeySystemWithMediaMimeType( |
| 388 "", no_codecs(), kExternalClearKey)); |
| 389 EXPECT_FALSE(IsSupportedKeySystemWithMediaMimeType( |
| 390 "", no_codecs(), "org.chromium")); |
| 391 |
| 392 EXPECT_FALSE(IsSupportedKeySystemWithMediaMimeType( |
| 393 "", no_codecs(), "org.chromium.foo")); |
| 394 EXPECT_FALSE(IsSupportedKeySystemWithMediaMimeType( |
| 395 "", no_codecs(), "org.chromium.externalclearkey.foo")); |
| 396 } |
| 397 |
| 398 TEST_F(KeySystemsTest, |
| 399 IsSupportedKeySystemWithMediaMimeType_ExternalClearKey_WebM) { |
| 400 // Valid video types. |
| 401 EXPECT_TRUE(IsSupportedKeySystemWithMediaMimeType( |
| 402 "video/webm", no_codecs(), kExternalClearKey)); |
| 403 // The parent should be supported but is not. See http://crbug.com/164303. |
| 404 EXPECT_FALSE(IsSupportedKeySystemWithMediaMimeType( |
| 405 "video/webm", no_codecs(), "org.chromium")); |
| 406 EXPECT_TRUE(IsSupportedKeySystemWithMediaMimeType( |
| 407 "video/webm", vp8_codec(), kExternalClearKey)); |
| 408 EXPECT_TRUE(IsSupportedKeySystemWithMediaMimeType( |
| 409 "video/webm", vp80_codec(), kExternalClearKey)); |
| 410 EXPECT_TRUE(IsSupportedKeySystemWithMediaMimeType( |
| 411 "video/webm", vp8_and_vorbis_codecs(), kExternalClearKey)); |
| 412 EXPECT_TRUE(IsSupportedKeySystemWithMediaMimeType( |
| 413 "video/webm", vorbis_codec(), kExternalClearKey)); |
| 414 |
| 415 // Non-Webm codecs. |
| 416 EXPECT_FALSE(IsSupportedKeySystemWithMediaMimeType( |
| 417 "video/webm", avc1_codec(), kExternalClearKey)); |
| 418 EXPECT_FALSE(IsSupportedKeySystemWithMediaMimeType( |
| 419 "video/webm", unknown_codec(), kExternalClearKey)); |
| 420 EXPECT_FALSE(IsSupportedKeySystemWithMediaMimeType( |
| 421 "video/webm", mixed_codecs(), kExternalClearKey)); |
| 422 |
| 423 // Valid audio types. |
| 424 EXPECT_TRUE(IsSupportedKeySystemWithMediaMimeType( |
| 425 "audio/webm", no_codecs(), kExternalClearKey)); |
| 426 EXPECT_TRUE(IsSupportedKeySystemWithMediaMimeType( |
| 427 "audio/webm", vorbis_codec(), kExternalClearKey)); |
| 428 |
| 429 // Non-audio codecs. |
| 430 EXPECT_FALSE(IsSupportedKeySystemWithMediaMimeType( |
| 431 "audio/webm", vp8_codec(), kExternalClearKey)); |
| 432 EXPECT_FALSE(IsSupportedKeySystemWithMediaMimeType( |
| 433 "audio/webm", vp8_and_vorbis_codecs(), kExternalClearKey)); |
| 434 |
| 435 // Non-Webm codec. |
| 436 EXPECT_FALSE(IsSupportedKeySystemWithMediaMimeType( |
| 437 "audio/webm", aac_codec(), kExternalClearKey)); |
| 438 } |
| 439 |
| 440 TEST_F(KeySystemsTest, |
| 441 IsSupportedKeySystemWithMediaMimeType_ExternalClearKey_MP4) { |
| 442 // Valid video types. |
| 443 EXPECT_PROPRIETARY(IsSupportedKeySystemWithMediaMimeType( |
| 444 "video/mp4", no_codecs(), kExternalClearKey)); |
| 445 // The parent should be supported but is not. See http://crbug.com/164303. |
| 446 EXPECT_FALSE(IsSupportedKeySystemWithMediaMimeType( |
| 447 "video/mp4", no_codecs(), "org.chromium")); |
| 448 EXPECT_PROPRIETARY(IsSupportedKeySystemWithMediaMimeType( |
| 449 "video/mp4", avc1_codec(), kExternalClearKey)); |
| 450 EXPECT_PROPRIETARY(IsSupportedKeySystemWithMediaMimeType( |
| 451 "video/mp4", avc1_and_aac_codecs(), kExternalClearKey)); |
| 452 EXPECT_PROPRIETARY(IsSupportedKeySystemWithMediaMimeType( |
| 453 "video/mp4", aac_codec(), kExternalClearKey)); |
| 454 |
| 455 // Extended codecs fail because this is handled by SimpleWebMimeRegistryImpl. |
| 456 // They should really pass canPlayType(). |
| 457 EXPECT_FALSE(IsSupportedKeySystemWithMediaMimeType( |
| 458 "video/mp4", avc1_extended_codec(), kExternalClearKey)); |
| 459 |
| 460 // Invalid codec format. |
| 461 EXPECT_FALSE(IsSupportedKeySystemWithMediaMimeType( |
| 462 "video/mp4", avc1_dot_codec(), kExternalClearKey)); |
| 463 |
| 464 // Non-MP4 codecs. |
| 465 EXPECT_FALSE(IsSupportedKeySystemWithMediaMimeType( |
| 466 "video/mp4", avc2_codec(), kExternalClearKey)); |
| 467 EXPECT_FALSE(IsSupportedKeySystemWithMediaMimeType( |
| 468 "video/mp4", vp8_codec(), kExternalClearKey)); |
| 469 EXPECT_FALSE(IsSupportedKeySystemWithMediaMimeType( |
| 470 "video/mp4", unknown_codec(), kExternalClearKey)); |
| 471 EXPECT_FALSE(IsSupportedKeySystemWithMediaMimeType( |
| 472 "video/mp4", mixed_codecs(), kExternalClearKey)); |
| 473 |
| 474 // Valid audio types. |
| 475 EXPECT_PROPRIETARY(IsSupportedKeySystemWithMediaMimeType( |
| 476 "audio/mp4", no_codecs(), kExternalClearKey)); |
| 477 EXPECT_PROPRIETARY(IsSupportedKeySystemWithMediaMimeType( |
| 478 "audio/mp4", aac_codec(), kExternalClearKey)); |
| 479 |
| 480 // Non-audio codecs. |
| 481 EXPECT_FALSE(IsSupportedKeySystemWithMediaMimeType( |
| 482 "audio/mp4", avc1_codec(), kExternalClearKey)); |
| 483 EXPECT_FALSE(IsSupportedKeySystemWithMediaMimeType( |
| 484 "audio/mp4", avc1_and_aac_codecs(), kExternalClearKey)); |
| 485 |
| 486 // Non-MP4 codec. |
| 487 EXPECT_FALSE(IsSupportedKeySystemWithMediaMimeType( |
| 488 "audio/mp4", vorbis_codec(), kExternalClearKey)); |
| 489 } |
| 490 |
| 491 // |
| 492 // Widevine |
| 493 // |
| 494 |
| 495 TEST_F(KeySystemsTest, Widevine_Basic) { |
| 496 EXPECT_WV(IsSupportedKeySystem(WebString::fromUTF8(kWidevineAlpha))); |
| 497 EXPECT_WV(IsSupportedKeySystemWithMediaMimeType( |
| 498 "video/webm", no_codecs(), kWidevineAlpha)); |
| 499 |
| 500 #if defined(WIDEVINE_CDM_AVAILABLE) |
| 501 const char* const kWidevineUmaName = "Widevine"; |
| 502 #else |
| 503 const char* const kWidevineUmaName = "Unknown"; |
| 504 #endif |
| 505 EXPECT_STREQ( |
| 506 kWidevineUmaName, |
| 507 KeySystemNameForUMA(std::string(kWidevineAlpha)).c_str()); |
| 508 EXPECT_STREQ( |
| 509 kWidevineUmaName, |
| 510 KeySystemNameForUMA(WebString::fromUTF8(kWidevineAlpha)).c_str()); |
| 511 |
| 512 EXPECT_FALSE(CanUseAesDecryptor(kWidevineAlpha)); |
| 513 #if defined(WIDEVINE_CDM_AVAILABLE) |
| 514 EXPECT_STREQ("application/x-ppapi-widevine-cdm", |
| 515 GetPluginType(kWidevineAlpha).c_str()); |
| 516 #else |
| 517 EXPECT_TRUE(GetPluginType(kWidevineAlpha).empty()); |
| 518 #endif |
| 519 } |
| 520 |
| 521 TEST_F(KeySystemsTest, Widevine_Parent) { |
| 522 const char* const kWidevineParent = "com.widevine"; |
| 523 |
| 524 EXPECT_WV(IsSupportedKeySystem(WebString::fromUTF8(kWidevineParent))); |
| 525 EXPECT_WV(IsSupportedKeySystemWithMediaMimeType( |
| 526 "video/webm", no_codecs(), kWidevineParent)); |
| 527 |
| 528 // The parent is not supported for most things. |
| 529 EXPECT_STREQ("Unknown", |
| 530 KeySystemNameForUMA(std::string(kWidevineParent)).c_str()); |
| 531 EXPECT_STREQ("Unknown", |
| 532 KeySystemNameForUMA(WebString::fromUTF8(kWidevineParent)).c_str()); |
| 533 EXPECT_FALSE(CanUseAesDecryptor(kWidevineParent)); |
| 534 EXPECT_TRUE(GetPluginType(kWidevineParent).empty()); |
| 535 } |
| 536 |
| 537 TEST_F(KeySystemsTest, Widevine_IsSupportedKeySystem_InvalidVariants) { |
| 538 // Case sensitive. |
| 539 EXPECT_FALSE(IsSupportedKeySystem("com.widevine.AlPhA")); |
| 540 EXPECT_FALSE(IsSupportedKeySystemWithMediaMimeType( |
| 541 "video/webm", no_codecs(), "com.widevine.AlPhA")); |
| 542 |
| 543 // TLDs are not allowed. |
| 544 EXPECT_FALSE(IsSupportedKeySystem("com.")); |
| 545 EXPECT_FALSE(IsSupportedKeySystemWithMediaMimeType( |
| 546 "video/webm", no_codecs(), "com.")); |
| 547 EXPECT_FALSE(IsSupportedKeySystem("com")); |
| 548 EXPECT_FALSE(IsSupportedKeySystemWithMediaMimeType( |
| 549 "video/webm", no_codecs(), "com")); |
| 550 |
| 551 // Extra period. |
| 552 EXPECT_FALSE(IsSupportedKeySystem("com.widevine.")); |
| 553 EXPECT_FALSE(IsSupportedKeySystemWithMediaMimeType( |
| 554 "video/webm", no_codecs(), "com.widevine.")); |
| 555 |
| 556 // Incomplete. |
| 557 EXPECT_FALSE(IsSupportedKeySystem("com.widevine.alph")); |
| 558 EXPECT_FALSE(IsSupportedKeySystemWithMediaMimeType( |
| 559 "video/webm", no_codecs(), "com.widevine.alph")); |
| 560 |
| 561 // Extra character. |
| 562 EXPECT_FALSE(IsSupportedKeySystem("com.widevine.alphab")); |
| 563 EXPECT_FALSE(IsSupportedKeySystemWithMediaMimeType( |
| 564 "video/webm", no_codecs(), "com.widevine.alphab")); |
| 565 |
| 566 // There are no child key systems for Widevine Alpha. |
| 567 EXPECT_FALSE(IsSupportedKeySystem("com.widevine.alpha.foo")); |
| 568 EXPECT_FALSE(IsSupportedKeySystemWithMediaMimeType( |
| 569 "video/webm", no_codecs(), "com.widevine.alpha.foo")); |
| 570 } |
| 571 |
| 572 TEST_F(KeySystemsTest, IsSupportedKeySystemWithMediaMimeType_Widevine_NoType) { |
| 573 // These two should be true. See http://crbug.com/164303. |
| 574 EXPECT_FALSE(IsSupportedKeySystemWithMediaMimeType( |
| 575 "", no_codecs(), "com.widevine.alpha")); |
| 576 EXPECT_FALSE(IsSupportedKeySystemWithMediaMimeType( |
| 577 "", no_codecs(), "com.widevine")); |
| 578 |
| 579 EXPECT_FALSE(IsSupportedKeySystemWithMediaMimeType( |
| 580 "", no_codecs(), "com.widevine.foo")); |
| 581 EXPECT_FALSE(IsSupportedKeySystemWithMediaMimeType( |
| 582 "", no_codecs(), "com.widevine.alpha.foo")); |
| 583 } |
| 584 |
| 585 TEST_F(KeySystemsTest, IsSupportedKeySystemWithMediaMimeType_Widevine_WebM) { |
| 586 // Valid video types. |
| 587 EXPECT_WV(IsSupportedKeySystemWithMediaMimeType( |
| 588 "video/webm", no_codecs(), kWidevineAlpha)); |
| 589 EXPECT_WV(IsSupportedKeySystemWithMediaMimeType( |
| 590 "video/webm", no_codecs(), "com.widevine")); |
| 591 EXPECT_WV(IsSupportedKeySystemWithMediaMimeType( |
| 592 "video/webm", vp8_codec(), kWidevineAlpha)); |
| 593 EXPECT_WV(IsSupportedKeySystemWithMediaMimeType( |
| 594 "video/webm", vp80_codec(), kWidevineAlpha)); |
| 595 EXPECT_WV(IsSupportedKeySystemWithMediaMimeType( |
| 596 "video/webm", vp8_and_vorbis_codecs(), kWidevineAlpha)); |
| 597 EXPECT_WV(IsSupportedKeySystemWithMediaMimeType( |
| 598 "video/webm", vorbis_codec(), kWidevineAlpha)); |
| 599 |
| 600 // Non-Webm codecs. |
| 601 EXPECT_FALSE(IsSupportedKeySystemWithMediaMimeType( |
| 602 "video/webm", avc1_codec(), kWidevineAlpha)); |
| 603 EXPECT_FALSE(IsSupportedKeySystemWithMediaMimeType( |
| 604 "video/webm", unknown_codec(), kWidevineAlpha)); |
| 605 EXPECT_FALSE(IsSupportedKeySystemWithMediaMimeType( |
| 606 "video/webm", mixed_codecs(), kWidevineAlpha)); |
| 607 |
| 608 // Valid audio types. |
| 609 EXPECT_WV(IsSupportedKeySystemWithMediaMimeType( |
| 610 "audio/webm", no_codecs(), kWidevineAlpha)); |
| 611 EXPECT_WV(IsSupportedKeySystemWithMediaMimeType( |
| 612 "audio/webm", vorbis_codec(), kWidevineAlpha)); |
| 613 |
| 614 // Non-audio codecs. |
| 615 EXPECT_FALSE(IsSupportedKeySystemWithMediaMimeType( |
| 616 "audio/webm", vp8_codec(), kWidevineAlpha)); |
| 617 EXPECT_FALSE(IsSupportedKeySystemWithMediaMimeType( |
| 618 "audio/webm", vp8_and_vorbis_codecs(), kWidevineAlpha)); |
| 619 |
| 620 // Non-Webm codec. |
| 621 EXPECT_FALSE(IsSupportedKeySystemWithMediaMimeType( |
| 622 "audio/webm", aac_codec(), kWidevineAlpha)); |
| 623 } |
| 624 |
| 625 TEST_F(KeySystemsTest, IsSupportedKeySystemWithMediaMimeType_Widevine_MP4) { |
| 626 // Valid video types. |
| 627 EXPECT_WVISO(IsSupportedKeySystemWithMediaMimeType( |
| 628 "video/mp4", no_codecs(), kWidevineAlpha)); |
| 629 EXPECT_WVISO(IsSupportedKeySystemWithMediaMimeType( |
| 630 "video/mp4", no_codecs(), "com.widevine")); |
| 631 EXPECT_WVISO(IsSupportedKeySystemWithMediaMimeType( |
| 632 "video/mp4", avc1_codec(), kWidevineAlpha)); |
| 633 EXPECT_WVISO(IsSupportedKeySystemWithMediaMimeType( |
| 634 "video/mp4", avc1_and_aac_codecs(), kWidevineAlpha)); |
| 635 EXPECT_WVISO(IsSupportedKeySystemWithMediaMimeType( |
| 636 "video/mp4", aac_codec(), kWidevineAlpha)); |
| 637 |
| 638 // Extended codecs fail because this is handled by SimpleWebMimeRegistryImpl. |
| 639 // They should really pass canPlayType(). |
| 640 EXPECT_FALSE(IsSupportedKeySystemWithMediaMimeType( |
| 641 "video/mp4", avc1_extended_codec(), kWidevineAlpha)); |
| 642 |
| 643 // Invalid codec format. |
| 644 EXPECT_FALSE(IsSupportedKeySystemWithMediaMimeType( |
| 645 "video/mp4", avc1_dot_codec(), kWidevineAlpha)); |
| 646 |
| 647 // Non-MP4 codecs. |
| 648 EXPECT_FALSE(IsSupportedKeySystemWithMediaMimeType( |
| 649 "video/mp4", avc2_codec(), kWidevineAlpha)); |
| 650 EXPECT_FALSE(IsSupportedKeySystemWithMediaMimeType( |
| 651 "video/mp4", vp8_codec(), kWidevineAlpha)); |
| 652 EXPECT_FALSE(IsSupportedKeySystemWithMediaMimeType( |
| 653 "video/mp4", unknown_codec(), kWidevineAlpha)); |
| 654 EXPECT_FALSE(IsSupportedKeySystemWithMediaMimeType( |
| 655 "video/mp4", mixed_codecs(), kWidevineAlpha)); |
| 656 |
| 657 // Valid audio types. |
| 658 EXPECT_WVISO(IsSupportedKeySystemWithMediaMimeType( |
| 659 "audio/mp4", no_codecs(), kWidevineAlpha)); |
| 660 EXPECT_WVISO(IsSupportedKeySystemWithMediaMimeType( |
| 661 "audio/mp4", aac_codec(), kWidevineAlpha)); |
| 662 |
| 663 // Non-audio codecs. |
| 664 EXPECT_FALSE(IsSupportedKeySystemWithMediaMimeType( |
| 665 "audio/mp4", avc1_codec(), kWidevineAlpha)); |
| 666 EXPECT_FALSE(IsSupportedKeySystemWithMediaMimeType( |
| 667 "audio/mp4", avc1_and_aac_codecs(), kWidevineAlpha)); |
| 668 |
| 669 // Non-MP4 codec. |
| 670 EXPECT_FALSE(IsSupportedKeySystemWithMediaMimeType( |
| 671 "audio/mp4", vorbis_codec(), kWidevineAlpha)); |
| 672 } |
| 673 |
| 674 } // namespace webkit_media |
OLD | NEW |