Blink roll 25b6bd3a7a131ffe68d809546ad1a20707915cdc:3a503f41ae42e5b79cfcd2ff10e65afde...
[chromium-blink-merge.git] / media / base / android / media_drm_bridge_unittest.cc
blob1a4c01426ae76af8ffccf8b644717a4913422656
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.
13 namespace media {
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)
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 IsKeySystemSupported(const std::string& key_system) {
38 return MediaDrmBridge::IsKeySystemSupported(key_system);
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);
48 static bool IsSecurityLevelSupported(
49 const std::string& key_system,
50 MediaDrmBridge::SecurityLevel security_level) {
51 return MediaDrmBridge::IsSecurityLevelSupported(key_system, security_level);
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);
62 // Invalid keysytem is NOT supported regardless whether MediaDrm is available.
63 TEST(MediaDrmBridgeTest, IsSecurityLevelSupported_InvalidKeySystem) {
64 EXPECT_FALSE(IsSecurityLevelSupported(kInvalidKeySystem, kLNone));
65 EXPECT_FALSE(IsSecurityLevelSupported(kInvalidKeySystem, kL1));
66 EXPECT_FALSE(IsSecurityLevelSupported(kInvalidKeySystem, kL3));
69 TEST(MediaDrmBridgeTest, IsKeySystemSupported_Widevine) {
70 EXPECT_TRUE_IF_AVAILABLE(IsKeySystemSupported(kWidevineKeySystem));
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));
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));
86 EXPECT_FALSE(IsKeySystemSupportedWithType(kWidevineKeySystem, "unknown"));
87 EXPECT_FALSE(IsKeySystemSupportedWithType(kWidevineKeySystem, "video/avi"));
88 EXPECT_FALSE(IsKeySystemSupportedWithType(kWidevineKeySystem, "audio/mp3"));
91 // Invalid keysytem is NOT supported regardless whether MediaDrm is available.
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"));
103 } // namespace media