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.
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"
11 #include "widevine_cdm_version.h" // In SHARED_INTERMEDIATE_DIR.
15 #define EXPECT_TRUE_IF_AVAILABLE(a) \
17 if (!MediaDrmBridge::IsAvailable()) { \
18 VLOG(0) << "MediaDrm not supported on device."; \
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
;
35 // Helper functions to avoid typing "MediaDrmBridge::" in tests.
37 static bool IsKeySystemSupportedWithType(
38 const std::string
& key_system
,
39 const std::string
& container_mime_type
) {
40 return MediaDrmBridge::IsKeySystemSupportedWithType(key_system
,
44 TEST(MediaDrmBridgeTest
, IsKeySystemSupported_Widevine
) {
45 EXPECT_TRUE_IF_AVAILABLE(
46 MediaDrmBridge::IsKeySystemSupported(kWidevineKeySystem
));
48 // TODO(xhwang): Enable when b/13564917 is fixed.
49 // EXPECT_TRUE_IF_AVAILABLE(
50 // IsKeySystemSupportedWithType(kWidevineKeySystem, kAudioMp4));
51 EXPECT_TRUE_IF_AVAILABLE(
52 IsKeySystemSupportedWithType(kWidevineKeySystem
, kVideoMp4
));
54 if (base::android::BuildInfo::GetInstance()->sdk_int() <= 19) {
55 EXPECT_FALSE(IsKeySystemSupportedWithType(kWidevineKeySystem
, kAudioWebM
));
56 EXPECT_FALSE(IsKeySystemSupportedWithType(kWidevineKeySystem
, kVideoWebM
));
58 EXPECT_TRUE(IsKeySystemSupportedWithType(kWidevineKeySystem
, kAudioWebM
));
59 EXPECT_TRUE(IsKeySystemSupportedWithType(kWidevineKeySystem
, kVideoWebM
));
62 EXPECT_FALSE(IsKeySystemSupportedWithType(kWidevineKeySystem
, "unknown"));
63 EXPECT_FALSE(IsKeySystemSupportedWithType(kWidevineKeySystem
, "video/avi"));
64 EXPECT_FALSE(IsKeySystemSupportedWithType(kWidevineKeySystem
, "audio/mp3"));
67 // Invalid key system is NOT supported regardless whether MediaDrm is available.
68 TEST(MediaDrmBridgeTest
, IsKeySystemSupported_InvalidKeySystem
) {
69 EXPECT_FALSE(MediaDrmBridge::IsKeySystemSupported(kInvalidKeySystem
));
70 EXPECT_FALSE(IsKeySystemSupportedWithType(kInvalidKeySystem
, kAudioMp4
));
71 EXPECT_FALSE(IsKeySystemSupportedWithType(kInvalidKeySystem
, kVideoMp4
));
72 EXPECT_FALSE(IsKeySystemSupportedWithType(kInvalidKeySystem
, kAudioWebM
));
73 EXPECT_FALSE(IsKeySystemSupportedWithType(kInvalidKeySystem
, kVideoWebM
));
74 EXPECT_FALSE(IsKeySystemSupportedWithType(kInvalidKeySystem
, "unknown"));
75 EXPECT_FALSE(IsKeySystemSupportedWithType(kInvalidKeySystem
, "video/avi"));
76 EXPECT_FALSE(IsKeySystemSupportedWithType(kInvalidKeySystem
, "audio/mp3"));
79 TEST(MediaDrmBridgeTest
, CreateWithoutSessionSupport_Widevine
) {
80 EXPECT_TRUE_IF_AVAILABLE(
81 MediaDrmBridge::CreateWithoutSessionSupport(kWidevineKeySystem
));
84 // Invalid key system is NOT supported regardless whether MediaDrm is available.
85 TEST(MediaDrmBridgeTest
, CreateWithoutSessionSupport_InvalidKeySystem
) {
86 EXPECT_FALSE(MediaDrmBridge::CreateWithoutSessionSupport(kInvalidKeySystem
));
89 TEST(MediaDrmBridgeTest
, SetSecurityLevel_Widevine
) {
90 scoped_ptr
<MediaDrmBridge
> media_drm_bridge
=
91 MediaDrmBridge::CreateWithoutSessionSupport(kWidevineKeySystem
);
92 EXPECT_TRUE_IF_AVAILABLE(media_drm_bridge
);
93 if (!media_drm_bridge
)
96 EXPECT_FALSE(media_drm_bridge
->SetSecurityLevel(kLNone
));
97 // We test "L3" fully. But for "L1" we don't check the result as it depends on
98 // whether the test device supports "L1".
99 EXPECT_TRUE(media_drm_bridge
->SetSecurityLevel(kL3
));
100 media_drm_bridge
->SetSecurityLevel(kL1
);