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