| OLD | NEW |
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 // TODO(sandersd): Refactor to remove recomputed codec arrays, and generally | 5 // TODO(sandersd): Refactor to remove recomputed codec arrays, and generally |
| 6 // shorten and improve coverage. | 6 // shorten and improve coverage. |
| 7 // - http://crbug.com/417444 | 7 // - http://crbug.com/417444 |
| 8 // - http://crbug.com/457438 | 8 // - http://crbug.com/457438 |
| 9 // TODO(sandersd): Add tests to cover codec vectors with empty items. | 9 // TODO(sandersd): Add tests to cover codec vectors with empty items. |
| 10 // http://crbug.com/417461 | 10 // http://crbug.com/417461 |
| 11 | 11 |
| 12 #include <string> | 12 #include <string> |
| 13 #include <vector> | 13 #include <vector> |
| 14 | 14 |
| 15 #include "base/logging.h" | 15 #include "base/logging.h" |
| 16 #include "media/base/eme_constants.h" | 16 #include "media/base/eme_constants.h" |
| 17 #include "media/base/key_systems.h" | 17 #include "media/base/key_systems.h" |
| 18 #include "media/base/media.h" | 18 #include "media/base/media.h" |
| 19 #include "media/base/media_client.h" | 19 #include "media/base/media_client.h" |
| 20 #include "ppapi/features/features.h" | 20 #include "ppapi/features/features.h" |
| 21 #include "testing/gtest/include/gtest/gtest.h" | 21 #include "testing/gtest/include/gtest/gtest.h" |
| 22 #include "third_party/widevine/cdm/widevine_cdm_common.h" |
| 22 | 23 |
| 23 namespace media { | 24 namespace media { |
| 24 | 25 |
| 25 // These are the (fake) key systems that are registered for these tests. | 26 // These are the (fake) key systems that are registered for these tests. |
| 26 // kUsesAes uses the AesDecryptor like Clear Key. | 27 // kUsesAes uses the AesDecryptor like Clear Key. |
| 27 // kExternal uses an external CDM, such as Pepper-based or Android platform CDM. | 28 // kExternal uses an external CDM, such as Pepper-based or Android platform CDM. |
| 28 const char kUsesAes[] = "x-org.example.clear"; | 29 const char kUsesAes[] = "x-org.example.clear"; |
| 29 const char kUseAesNameForUMA[] = "UseAes"; | |
| 30 const char kExternal[] = "x-com.example.test"; | 30 const char kExternal[] = "x-com.example.test"; |
| 31 const char kExternalNameForUMA[] = "External"; | |
| 32 | 31 |
| 33 const char kClearKey[] = "org.w3.clearkey"; | 32 const char kClearKey[] = "org.w3.clearkey"; |
| 34 const char kExternalClearKey[] = "org.chromium.externalclearkey"; | 33 const char kExternalClearKey[] = "org.chromium.externalclearkey"; |
| 35 | 34 |
| 36 const char kAudioWebM[] = "audio/webm"; | 35 const char kAudioWebM[] = "audio/webm"; |
| 37 const char kVideoWebM[] = "video/webm"; | 36 const char kVideoWebM[] = "video/webm"; |
| 38 const char kAudioFoo[] = "audio/foo"; | 37 const char kAudioFoo[] = "audio/foo"; |
| 39 const char kVideoFoo[] = "video/foo"; | 38 const char kVideoFoo[] = "video/foo"; |
| 40 | 39 |
| 41 // Pick some arbitrary bit fields as long as they are not in conflict with the | 40 // Pick some arbitrary bit fields as long as they are not in conflict with the |
| (...skipping 125 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 167 return true; | 166 return true; |
| 168 #endif | 167 #endif |
| 169 } | 168 } |
| 170 | 169 |
| 171 class TestMediaClient : public MediaClient { | 170 class TestMediaClient : public MediaClient { |
| 172 public: | 171 public: |
| 173 TestMediaClient(); | 172 TestMediaClient(); |
| 174 ~TestMediaClient() override; | 173 ~TestMediaClient() override; |
| 175 | 174 |
| 176 // MediaClient implementation. | 175 // MediaClient implementation. |
| 177 void AddKeySystemsInfoForUMA( | |
| 178 std::vector<KeySystemInfoForUMA>* key_systems_info_for_uma) final; | |
| 179 bool IsKeySystemsUpdateNeeded() final; | 176 bool IsKeySystemsUpdateNeeded() final; |
| 180 void AddSupportedKeySystems(std::vector<std::unique_ptr<KeySystemProperties>>* | 177 void AddSupportedKeySystems(std::vector<std::unique_ptr<KeySystemProperties>>* |
| 181 key_systems_properties) override; | 178 key_systems_properties) override; |
| 182 void RecordRapporURL(const std::string& metric, const GURL& url) final; | |
| 183 bool IsSupportedAudioConfig(const media::AudioConfig& config) final; | 179 bool IsSupportedAudioConfig(const media::AudioConfig& config) final; |
| 184 bool IsSupportedVideoConfig(const media::VideoConfig& config) final; | 180 bool IsSupportedVideoConfig(const media::VideoConfig& config) final; |
| 185 | 181 |
| 186 // Helper function to test the case where IsKeySystemsUpdateNeeded() is true | 182 // Helper function to test the case where IsKeySystemsUpdateNeeded() is true |
| 187 // after AddSupportedKeySystems() is called. | 183 // after AddSupportedKeySystems() is called. |
| 188 void SetKeySystemsUpdateNeeded(); | 184 void SetKeySystemsUpdateNeeded(); |
| 189 | 185 |
| 190 // Helper function to disable "kExternal" key system support so that we can | 186 // Helper function to disable "kExternal" key system support so that we can |
| 191 // test the key system update case. | 187 // test the key system update case. |
| 192 void DisableExternalKeySystemSupport(); | 188 void DisableExternalKeySystemSupport(); |
| 193 | 189 |
| 194 private: | 190 private: |
| 195 bool is_update_needed_; | 191 bool is_update_needed_; |
| 196 bool supports_external_key_system_; | 192 bool supports_external_key_system_; |
| 197 }; | 193 }; |
| 198 | 194 |
| 199 TestMediaClient::TestMediaClient() | 195 TestMediaClient::TestMediaClient() |
| 200 : is_update_needed_(true), supports_external_key_system_(true) { | 196 : is_update_needed_(true), supports_external_key_system_(true) { |
| 201 } | 197 } |
| 202 | 198 |
| 203 TestMediaClient::~TestMediaClient() { | 199 TestMediaClient::~TestMediaClient() { |
| 204 } | 200 } |
| 205 | 201 |
| 206 void TestMediaClient::AddKeySystemsInfoForUMA( | |
| 207 std::vector<KeySystemInfoForUMA>* key_systems_info_for_uma) { | |
| 208 key_systems_info_for_uma->push_back( | |
| 209 media::KeySystemInfoForUMA(kUsesAes, kUseAesNameForUMA)); | |
| 210 key_systems_info_for_uma->push_back( | |
| 211 media::KeySystemInfoForUMA(kExternal, kExternalNameForUMA)); | |
| 212 } | |
| 213 | |
| 214 bool TestMediaClient::IsKeySystemsUpdateNeeded() { | 202 bool TestMediaClient::IsKeySystemsUpdateNeeded() { |
| 215 return is_update_needed_; | 203 return is_update_needed_; |
| 216 } | 204 } |
| 217 | 205 |
| 218 void TestMediaClient::AddSupportedKeySystems( | 206 void TestMediaClient::AddSupportedKeySystems( |
| 219 std::vector<std::unique_ptr<KeySystemProperties>>* key_systems) { | 207 std::vector<std::unique_ptr<KeySystemProperties>>* key_systems) { |
| 220 DCHECK(is_update_needed_); | 208 DCHECK(is_update_needed_); |
| 221 | 209 |
| 222 key_systems->emplace_back(new AesKeySystemProperties(kUsesAes)); | 210 key_systems->emplace_back(new AesKeySystemProperties(kUsesAes)); |
| 223 | 211 |
| 224 if (supports_external_key_system_) | 212 if (supports_external_key_system_) |
| 225 key_systems->emplace_back(new ExternalKeySystemProperties()); | 213 key_systems->emplace_back(new ExternalKeySystemProperties()); |
| 226 | 214 |
| 227 is_update_needed_ = false; | 215 is_update_needed_ = false; |
| 228 } | 216 } |
| 229 | 217 |
| 230 void TestMediaClient::RecordRapporURL(const std::string& /* metric */, | |
| 231 const GURL& /* url */) { | |
| 232 NOTIMPLEMENTED(); | |
| 233 } | |
| 234 | |
| 235 bool TestMediaClient::IsSupportedAudioConfig(const media::AudioConfig& config) { | 218 bool TestMediaClient::IsSupportedAudioConfig(const media::AudioConfig& config) { |
| 236 return true; | 219 return true; |
| 237 } | 220 } |
| 238 | 221 |
| 239 bool TestMediaClient::IsSupportedVideoConfig(const media::VideoConfig& config) { | 222 bool TestMediaClient::IsSupportedVideoConfig(const media::VideoConfig& config) { |
| 240 return true; | 223 return true; |
| 241 } | 224 } |
| 242 | 225 |
| 243 void TestMediaClient::SetKeySystemsUpdateNeeded() { | 226 void TestMediaClient::SetKeySystemsUpdateNeeded() { |
| 244 is_update_needed_ = true; | 227 is_update_needed_ = true; |
| 245 } | 228 } |
| 246 | 229 |
| 247 void TestMediaClient::DisableExternalKeySystemSupport() { | 230 void TestMediaClient::DisableExternalKeySystemSupport() { |
| 248 supports_external_key_system_ = false; | 231 supports_external_key_system_ = false; |
| 249 } | 232 } |
| 250 | 233 |
| 251 class PotentiallySupportedNamesTestMediaClient : public TestMediaClient { | |
| 252 void AddSupportedKeySystems(std::vector<std::unique_ptr<KeySystemProperties>>* | |
| 253 key_systems_properties) final; | |
| 254 }; | |
| 255 | |
| 256 void PotentiallySupportedNamesTestMediaClient::AddSupportedKeySystems( | |
| 257 std::vector<std::unique_ptr<KeySystemProperties>>* key_systems) { | |
| 258 // org.w3.clearkey is automatically registered. | |
| 259 key_systems->emplace_back(new AesKeySystemProperties("com.widevine.alpha")); | |
| 260 key_systems->emplace_back( | |
| 261 new AesKeySystemProperties("org.chromium.externalclearkey")); | |
| 262 key_systems->emplace_back( | |
| 263 new AesKeySystemProperties("org.chromium.externalclearkey.something")); | |
| 264 key_systems->emplace_back( | |
| 265 new AesKeySystemProperties("com.chromecast.something")); | |
| 266 key_systems->emplace_back(new AesKeySystemProperties("x-something")); | |
| 267 } | |
| 268 | |
| 269 class KeySystemsPotentiallySupportedNamesTest : public testing::Test { | |
| 270 protected: | |
| 271 KeySystemsPotentiallySupportedNamesTest() { | |
| 272 SetMediaClient(&test_media_client_); | |
| 273 } | |
| 274 | |
| 275 ~KeySystemsPotentiallySupportedNamesTest() override { | |
| 276 // Clear the use of |test_media_client_|, which was set in SetUp(). | |
| 277 SetMediaClient(nullptr); | |
| 278 } | |
| 279 | |
| 280 private: | |
| 281 PotentiallySupportedNamesTestMediaClient test_media_client_; | |
| 282 }; | |
| 283 | |
| 284 class KeySystemsTest : public testing::Test { | 234 class KeySystemsTest : public testing::Test { |
| 285 protected: | 235 protected: |
| 286 KeySystemsTest() { | 236 KeySystemsTest() { |
| 287 vp8_codec_.push_back("vp8"); | 237 vp8_codec_.push_back("vp8"); |
| 288 | 238 |
| 289 vp80_codec_.push_back("vp8.0"); | 239 vp80_codec_.push_back("vp8.0"); |
| 290 | 240 |
| 291 vp9_codec_.push_back("vp9"); | 241 vp9_codec_.push_back("vp9"); |
| 292 | 242 |
| 293 vp90_codec_.push_back("vp9.0"); | 243 vp90_codec_.push_back("vp9.0"); |
| (...skipping 24 matching lines...) Expand all Loading... |
| 318 | 268 |
| 319 SetMediaClient(&test_media_client_); | 269 SetMediaClient(&test_media_client_); |
| 320 } | 270 } |
| 321 | 271 |
| 322 void SetUp() override { | 272 void SetUp() override { |
| 323 AddContainerAndCodecMasksForTest(); | 273 AddContainerAndCodecMasksForTest(); |
| 324 } | 274 } |
| 325 | 275 |
| 326 ~KeySystemsTest() override { | 276 ~KeySystemsTest() override { |
| 327 // Clear the use of |test_media_client_|, which was set in SetUp(). | 277 // Clear the use of |test_media_client_|, which was set in SetUp(). |
| 278 // NOTE: This does not clear any cached KeySystemProperties in the global |
| 279 // KeySystems instance. |
| 328 SetMediaClient(nullptr); | 280 SetMediaClient(nullptr); |
| 329 } | 281 } |
| 330 | 282 |
| 331 void UpdateClientKeySystems() { | 283 void UpdateClientKeySystems() { |
| 332 test_media_client_.SetKeySystemsUpdateNeeded(); | 284 test_media_client_.SetKeySystemsUpdateNeeded(); |
| 333 test_media_client_.DisableExternalKeySystemSupport(); | 285 test_media_client_.DisableExternalKeySystemSupport(); |
| 334 } | 286 } |
| 335 | 287 |
| 336 typedef std::vector<std::string> CodecVector; | 288 typedef std::vector<std::string> CodecVector; |
| 337 | 289 |
| (...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 434 EXPECT_TRUE(type.empty()); | 386 EXPECT_TRUE(type.empty()); |
| 435 #endif | 387 #endif |
| 436 } | 388 } |
| 437 | 389 |
| 438 TEST_F(KeySystemsTest, Basic_UsesAesDecryptor) { | 390 TEST_F(KeySystemsTest, Basic_UsesAesDecryptor) { |
| 439 EXPECT_TRUE(IsSupportedKeySystem(kUsesAes)); | 391 EXPECT_TRUE(IsSupportedKeySystem(kUsesAes)); |
| 440 EXPECT_TRUE(IsSupportedKeySystemWithMediaMimeType( | 392 EXPECT_TRUE(IsSupportedKeySystemWithMediaMimeType( |
| 441 kVideoWebM, no_codecs(), kUsesAes)); | 393 kVideoWebM, no_codecs(), kUsesAes)); |
| 442 | 394 |
| 443 // No UMA value for this test key system. | 395 // No UMA value for this test key system. |
| 444 EXPECT_EQ("UseAes", GetKeySystemNameForUMA(kUsesAes)); | 396 EXPECT_EQ("Unknown", GetKeySystemNameForUMA(kUsesAes)); |
| 445 | 397 |
| 446 EXPECT_TRUE(CanUseAesDecryptor(kUsesAes)); | 398 EXPECT_TRUE(CanUseAesDecryptor(kUsesAes)); |
| 447 #if BUILDFLAG(ENABLE_PEPPER_CDMS) | 399 #if BUILDFLAG(ENABLE_PEPPER_CDMS) |
| 448 std::string type; | 400 std::string type; |
| 449 #if !defined(NDEBUG) || defined(DCHECK_ALWAYS_ON) | 401 #if !defined(NDEBUG) || defined(DCHECK_ALWAYS_ON) |
| 450 EXPECT_DEATH(type = GetPepperType(kUsesAes), | 402 EXPECT_DEATH(type = GetPepperType(kUsesAes), |
| 451 "x-org.example.clear is not Pepper-based"); | 403 "x-org.example.clear is not Pepper-based"); |
| 452 #endif | 404 #endif |
| 453 EXPECT_TRUE(type.empty()); | 405 EXPECT_TRUE(type.empty()); |
| 454 #endif | 406 #endif |
| (...skipping 253 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 708 EXPECT_FALSE(IsSupportedKeySystemWithAudioMimeType( | 660 EXPECT_FALSE(IsSupportedKeySystemWithAudioMimeType( |
| 709 kAudioFoo, foovideo_and_fooaudio_codecs(), kExternal)); | 661 kAudioFoo, foovideo_and_fooaudio_codecs(), kExternal)); |
| 710 | 662 |
| 711 // Non-container2 codec. | 663 // Non-container2 codec. |
| 712 EXPECT_FALSE(IsSupportedKeySystemWithAudioMimeType( | 664 EXPECT_FALSE(IsSupportedKeySystemWithAudioMimeType( |
| 713 kAudioFoo, vorbis_codec(), kExternal)); | 665 kAudioFoo, vorbis_codec(), kExternal)); |
| 714 } | 666 } |
| 715 | 667 |
| 716 TEST_F(KeySystemsTest, KeySystemNameForUMA) { | 668 TEST_F(KeySystemsTest, KeySystemNameForUMA) { |
| 717 EXPECT_EQ("ClearKey", GetKeySystemNameForUMA(kClearKey)); | 669 EXPECT_EQ("ClearKey", GetKeySystemNameForUMA(kClearKey)); |
| 670 EXPECT_EQ("Widevine", GetKeySystemNameForUMA(kWidevineKeySystem)); |
| 671 EXPECT_EQ("Unknown", GetKeySystemNameForUMA("Foo")); |
| 718 | 672 |
| 719 // External Clear Key never has a UMA name. | 673 // External Clear Key never has a UMA name. |
| 720 if (CanRunExternalKeySystemTests()) | 674 if (CanRunExternalKeySystemTests()) |
| 721 EXPECT_EQ("Unknown", GetKeySystemNameForUMA(kExternalClearKey)); | 675 EXPECT_EQ("Unknown", GetKeySystemNameForUMA(kExternalClearKey)); |
| 722 } | 676 } |
| 723 | 677 |
| 724 TEST_F(KeySystemsTest, KeySystemsUpdate) { | 678 TEST_F(KeySystemsTest, KeySystemsUpdate) { |
| 725 EXPECT_TRUE(IsSupportedKeySystem(kUsesAes)); | 679 EXPECT_TRUE(IsSupportedKeySystem(kUsesAes)); |
| 726 EXPECT_TRUE(IsSupportedKeySystemWithMediaMimeType( | 680 EXPECT_TRUE(IsSupportedKeySystemWithMediaMimeType( |
| 727 kVideoWebM, no_codecs(), kUsesAes)); | 681 kVideoWebM, no_codecs(), kUsesAes)); |
| 728 | 682 |
| 729 if (CanRunExternalKeySystemTests()) { | 683 if (CanRunExternalKeySystemTests()) { |
| 730 EXPECT_TRUE(IsSupportedKeySystem(kExternal)); | 684 EXPECT_TRUE(IsSupportedKeySystem(kExternal)); |
| 731 EXPECT_TRUE(IsSupportedKeySystemWithMediaMimeType(kVideoWebM, no_codecs(), | 685 EXPECT_TRUE(IsSupportedKeySystemWithMediaMimeType(kVideoWebM, no_codecs(), |
| 732 kExternal)); | 686 kExternal)); |
| 733 } | 687 } |
| 734 | 688 |
| 735 UpdateClientKeySystems(); | 689 UpdateClientKeySystems(); |
| 736 | 690 |
| 737 EXPECT_TRUE(IsSupportedKeySystem(kUsesAes)); | 691 EXPECT_TRUE(IsSupportedKeySystem(kUsesAes)); |
| 738 EXPECT_TRUE(IsSupportedKeySystemWithMediaMimeType( | 692 EXPECT_TRUE(IsSupportedKeySystemWithMediaMimeType( |
| 739 kVideoWebM, no_codecs(), kUsesAes)); | 693 kVideoWebM, no_codecs(), kUsesAes)); |
| 740 if (CanRunExternalKeySystemTests()) | 694 if (CanRunExternalKeySystemTests()) |
| 741 EXPECT_FALSE(IsSupportedKeySystem(kExternal)); | 695 EXPECT_FALSE(IsSupportedKeySystem(kExternal)); |
| 742 } | 696 } |
| 743 | 697 |
| 744 TEST_F(KeySystemsPotentiallySupportedNamesTest, PotentiallySupportedNames) { | |
| 745 EXPECT_FALSE(IsSupportedKeySystem("org.w3")); | |
| 746 EXPECT_FALSE(IsSupportedKeySystem("org.w3.")); | |
| 747 EXPECT_FALSE(IsSupportedKeySystem("org.w3.clearke")); | |
| 748 EXPECT_TRUE(IsSupportedKeySystem("org.w3.clearkey")); | |
| 749 EXPECT_FALSE(IsSupportedKeySystem("org.w3.clearkeys")); | |
| 750 | |
| 751 EXPECT_FALSE(IsSupportedKeySystem("com.widevine")); | |
| 752 EXPECT_FALSE(IsSupportedKeySystem("com.widevine.")); | |
| 753 EXPECT_FALSE(IsSupportedKeySystem("com.widevine.alph")); | |
| 754 EXPECT_TRUE(IsSupportedKeySystem("com.widevine.alpha")); | |
| 755 EXPECT_FALSE(IsSupportedKeySystem("com.widevine.beta")); | |
| 756 EXPECT_FALSE(IsSupportedKeySystem("com.widevine.alphabeta")); | |
| 757 EXPECT_FALSE(IsSupportedKeySystem("com.widevine.alpha.beta")); | |
| 758 | |
| 759 EXPECT_FALSE(IsSupportedKeySystem("org.chromium")); | |
| 760 EXPECT_FALSE(IsSupportedKeySystem("org.chromium.")); | |
| 761 EXPECT_FALSE(IsSupportedKeySystem("org.chromium.externalclearke")); | |
| 762 EXPECT_TRUE(IsSupportedKeySystem("org.chromium.externalclearkey")); | |
| 763 EXPECT_FALSE(IsSupportedKeySystem("org.chromium.externalclearkeys")); | |
| 764 EXPECT_FALSE(IsSupportedKeySystem("org.chromium.externalclearkey.")); | |
| 765 EXPECT_TRUE(IsSupportedKeySystem("org.chromium.externalclearkey.something")); | |
| 766 EXPECT_FALSE( | |
| 767 IsSupportedKeySystem("org.chromium.externalclearkey.something.else")); | |
| 768 EXPECT_FALSE(IsSupportedKeySystem("org.chromium.externalclearkey.other")); | |
| 769 EXPECT_FALSE(IsSupportedKeySystem("org.chromium.other")); | |
| 770 | |
| 771 EXPECT_FALSE(IsSupportedKeySystem("com.chromecast")); | |
| 772 EXPECT_FALSE(IsSupportedKeySystem("com.chromecast.")); | |
| 773 EXPECT_TRUE(IsSupportedKeySystem("com.chromecast.something")); | |
| 774 EXPECT_FALSE(IsSupportedKeySystem("com.chromecast.something.else")); | |
| 775 EXPECT_FALSE(IsSupportedKeySystem("com.chromecast.other")); | |
| 776 | |
| 777 EXPECT_FALSE(IsSupportedKeySystem("x-")); | |
| 778 EXPECT_TRUE(IsSupportedKeySystem("x-something")); | |
| 779 EXPECT_FALSE(IsSupportedKeySystem("x-something.else")); | |
| 780 EXPECT_FALSE(IsSupportedKeySystem("x-other")); | |
| 781 } | |
| 782 | |
| 783 } // namespace media | 698 } // namespace media |
| OLD | NEW |