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_WIDEVINE_AVAILABLE(a) \
17 if (!MediaDrmBridge::IsKeySystemSupported(kWidevineKeySystem)) { \
18 VLOG(0) << "Widevine 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 // TODO(xhwang): Enable when b/13564917 is fixed.
46 // EXPECT_TRUE_IF_AVAILABLE(
47 // IsKeySystemSupportedWithType(kWidevineKeySystem, kAudioMp4));
48 EXPECT_TRUE_IF_WIDEVINE_AVAILABLE(
49 IsKeySystemSupportedWithType(kWidevineKeySystem
, kVideoMp4
));
51 if (base::android::BuildInfo::GetInstance()->sdk_int() <= 19) {
52 EXPECT_FALSE(IsKeySystemSupportedWithType(kWidevineKeySystem
, kAudioWebM
));
53 EXPECT_FALSE(IsKeySystemSupportedWithType(kWidevineKeySystem
, kVideoWebM
));
55 EXPECT_TRUE_IF_WIDEVINE_AVAILABLE(
56 IsKeySystemSupportedWithType(kWidevineKeySystem
, kAudioWebM
));
57 EXPECT_TRUE_IF_WIDEVINE_AVAILABLE(
58 IsKeySystemSupportedWithType(kWidevineKeySystem
, kVideoWebM
));
61 EXPECT_FALSE(IsKeySystemSupportedWithType(kWidevineKeySystem
, "unknown"));
62 EXPECT_FALSE(IsKeySystemSupportedWithType(kWidevineKeySystem
, "video/avi"));
63 EXPECT_FALSE(IsKeySystemSupportedWithType(kWidevineKeySystem
, "audio/mp3"));
66 // Invalid key system is NOT supported regardless whether MediaDrm is available.
67 TEST(MediaDrmBridgeTest
, IsKeySystemSupported_InvalidKeySystem
) {
68 EXPECT_FALSE(MediaDrmBridge::IsKeySystemSupported(kInvalidKeySystem
));
69 EXPECT_FALSE(IsKeySystemSupportedWithType(kInvalidKeySystem
, kAudioMp4
));
70 EXPECT_FALSE(IsKeySystemSupportedWithType(kInvalidKeySystem
, kVideoMp4
));
71 EXPECT_FALSE(IsKeySystemSupportedWithType(kInvalidKeySystem
, kAudioWebM
));
72 EXPECT_FALSE(IsKeySystemSupportedWithType(kInvalidKeySystem
, kVideoWebM
));
73 EXPECT_FALSE(IsKeySystemSupportedWithType(kInvalidKeySystem
, "unknown"));
74 EXPECT_FALSE(IsKeySystemSupportedWithType(kInvalidKeySystem
, "video/avi"));
75 EXPECT_FALSE(IsKeySystemSupportedWithType(kInvalidKeySystem
, "audio/mp3"));
78 TEST(MediaDrmBridgeTest
, CreateWithoutSessionSupport_Widevine
) {
79 EXPECT_TRUE_IF_WIDEVINE_AVAILABLE(
80 MediaDrmBridge::CreateWithoutSessionSupport(kWidevineKeySystem
));
83 // Invalid key system is NOT supported regardless whether MediaDrm is available.
84 TEST(MediaDrmBridgeTest
, CreateWithoutSessionSupport_InvalidKeySystem
) {
85 EXPECT_FALSE(MediaDrmBridge::CreateWithoutSessionSupport(kInvalidKeySystem
));
88 TEST(MediaDrmBridgeTest
, SetSecurityLevel_Widevine
) {
89 scoped_ptr
<MediaDrmBridge
> media_drm_bridge
=
90 MediaDrmBridge::CreateWithoutSessionSupport(kWidevineKeySystem
);
91 EXPECT_TRUE_IF_WIDEVINE_AVAILABLE(media_drm_bridge
);
92 if (!media_drm_bridge
)
95 EXPECT_FALSE(media_drm_bridge
->SetSecurityLevel(kLNone
));
96 // We test "L3" fully. But for "L1" we don't check the result as it depends on
97 // whether the test device supports "L1".
98 EXPECT_TRUE(media_drm_bridge
->SetSecurityLevel(kL3
));
99 media_drm_bridge
->SetSecurityLevel(kL1
);