1 // Copyright 2014 The Chromium Authors. All rights reserved. 2 // Use of this source code is governed by a BSD-style license that can be 3 // found in the LICENSE file. 4 5 #include "base/basictypes.h" 6 #include "base/logging.h" 7 #include "media/base/android/media_drm_bridge.h" 8 #include "testing/gtest/include/gtest/gtest.h" 9 10 #include "widevine_cdm_version.h" // In SHARED_INTERMEDIATE_DIR. 11 12 namespace media { 13 14 #define EXPECT_TRUE_IF_AVAILABLE(a) \ 15 do { \ 16 if (!MediaDrmBridge::IsAvailable()) { \ 17 VLOG(0) << "MediaDrm not supported on device."; \ 18 EXPECT_FALSE(a); \ 19 } else { \ 20 EXPECT_TRUE(a); \ 21 } \ 22 } while (0) 23 24 const char kAudioMp4[] = "audio/mp4"; 25 const char kVideoMp4[] = "video/mp4"; 26 const char kAudioWebM[] = "audio/webm"; 27 const char kVideoWebM[] = "video/webm"; 28 const char kInvalidKeySystem[] = "invalid.keysystem"; 29 const MediaDrmBridge::SecurityLevel kLNone = 30 MediaDrmBridge::SECURITY_LEVEL_NONE; 31 const MediaDrmBridge::SecurityLevel kL1 = MediaDrmBridge::SECURITY_LEVEL_1; 32 const MediaDrmBridge::SecurityLevel kL3 = MediaDrmBridge::SECURITY_LEVEL_3; 33 34 // Helper functions to avoid typing "MediaDrmBridge::" in tests. 35 36 static bool IsKeySystemSupported(const std::string& key_system) { 37 return MediaDrmBridge::IsKeySystemSupported(key_system); 38 } 39 40 static bool IsKeySystemSupportedWithType( 41 const std::string& key_system, 42 const std::string& container_mime_type) { 43 return MediaDrmBridge::IsKeySystemSupportedWithType(key_system, 44 container_mime_type); 45 } 46 47 static bool IsSecurityLevelSupported( 48 const std::string& key_system, 49 MediaDrmBridge::SecurityLevel security_level) { 50 return MediaDrmBridge::IsSecurityLevelSupported(key_system, security_level); 51 } 52 53 TEST(MediaDrmBridgeTest, IsSecurityLevelSupported_Widevine) { 54 EXPECT_FALSE(IsSecurityLevelSupported(kWidevineKeySystem, kLNone)); 55 // We test "L3" fully. But for "L1" we don't check the result as it depends on 56 // whether the test device supports "L1". 57 EXPECT_TRUE_IF_AVAILABLE(IsSecurityLevelSupported(kWidevineKeySystem, kL3)); 58 IsSecurityLevelSupported(kWidevineKeySystem, kL1); 59 } 60 61 // Invalid keysytem is NOT supported regardless whether MediaDrm is available. 62 TEST(MediaDrmBridgeTest, IsSecurityLevelSupported_InvalidKeySystem) { 63 EXPECT_FALSE(IsSecurityLevelSupported(kInvalidKeySystem, kLNone)); 64 EXPECT_FALSE(IsSecurityLevelSupported(kInvalidKeySystem, kL1)); 65 EXPECT_FALSE(IsSecurityLevelSupported(kInvalidKeySystem, kL3)); 66 } 67 68 TEST(MediaDrmBridgeTest, IsKeySystemSupported_Widevine) { 69 EXPECT_TRUE_IF_AVAILABLE(IsKeySystemSupported(kWidevineKeySystem)); 70 71 // TODO(xhwang): Enable when b/13564917 is fixed. 72 // EXPECT_TRUE_IF_AVAILABLE( 73 // IsKeySystemSupportedWithType(kWidevineKeySystem, kAudioMp4)); 74 EXPECT_TRUE_IF_AVAILABLE( 75 IsKeySystemSupportedWithType(kWidevineKeySystem, kVideoMp4)); 76 77 EXPECT_FALSE(IsKeySystemSupportedWithType(kWidevineKeySystem, kAudioWebM)); 78 EXPECT_FALSE(IsKeySystemSupportedWithType(kWidevineKeySystem, kVideoWebM)); 79 EXPECT_FALSE(IsKeySystemSupportedWithType(kWidevineKeySystem, "unknown")); 80 EXPECT_FALSE(IsKeySystemSupportedWithType(kWidevineKeySystem, "video/avi")); 81 EXPECT_FALSE(IsKeySystemSupportedWithType(kWidevineKeySystem, "audio/mp3")); 82 } 83 84 // Invalid keysytem is NOT supported regardless whether MediaDrm is available. 85 TEST(MediaDrmBridgeTest, IsKeySystemSupported_InvalidKeySystem) { 86 EXPECT_FALSE(IsKeySystemSupported(kInvalidKeySystem)); 87 EXPECT_FALSE(IsKeySystemSupportedWithType(kInvalidKeySystem, kAudioMp4)); 88 EXPECT_FALSE(IsKeySystemSupportedWithType(kInvalidKeySystem, kVideoMp4)); 89 EXPECT_FALSE(IsKeySystemSupportedWithType(kInvalidKeySystem, kAudioWebM)); 90 EXPECT_FALSE(IsKeySystemSupportedWithType(kInvalidKeySystem, kVideoWebM)); 91 EXPECT_FALSE(IsKeySystemSupportedWithType(kInvalidKeySystem, "unknown")); 92 EXPECT_FALSE(IsKeySystemSupportedWithType(kInvalidKeySystem, "video/avi")); 93 EXPECT_FALSE(IsKeySystemSupportedWithType(kInvalidKeySystem, "audio/mp3")); 94 } 95 96 } // namespace media 97