1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
|
// Copyright 2014 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "base/basictypes.h"
#include "base/logging.h"
#include "media/base/android/media_drm_bridge.h"
#include "testing/gtest/include/gtest/gtest.h"
#include "widevine_cdm_version.h" // In SHARED_INTERMEDIATE_DIR.
namespace media {
#define EXPECT_TRUE_IF_AVAILABLE(a) \
do { \
if (!MediaDrmBridge::IsAvailable()) { \
VLOG(0) << "MediaDrm not supported on device."; \
EXPECT_FALSE(a); \
} else { \
EXPECT_TRUE(a); \
} \
} while (0)
const char kAudioMp4[] = "audio/mp4";
const char kVideoMp4[] = "video/mp4";
const char kAudioWebM[] = "audio/webm";
const char kVideoWebM[] = "video/webm";
const char kInvalidKeySystem[] = "invalid.keysystem";
const char kFooKeySystem[] = "com.foo.keysystem";
const uint8 kWidevineUuid[16] = {
0xED, 0xEF, 0x8B, 0xA9, 0x79, 0xD6, 0x4A, 0xCE,
0xA3, 0xC8, 0x27, 0xDC, 0xD5, 0x1D, 0x21, 0xED };
const MediaDrmBridge::SecurityLevel kLNone =
MediaDrmBridge::SECURITY_LEVEL_NONE;
const MediaDrmBridge::SecurityLevel kL1 = MediaDrmBridge::SECURITY_LEVEL_1;
const MediaDrmBridge::SecurityLevel kL3 = MediaDrmBridge::SECURITY_LEVEL_3;
// Helper functions to avoid typing "MediaDrmBridge::" in tests.
static bool IsKeySystemSupported(const std::string& key_system) {
return MediaDrmBridge::IsKeySystemSupported(key_system);
}
static bool IsKeySystemSupportedWithType(
const std::string& key_system,
const std::string& container_mime_type) {
return MediaDrmBridge::IsKeySystemSupportedWithType(key_system,
container_mime_type);
}
static bool IsSecurityLevelSupported(
const std::string& key_system,
MediaDrmBridge::SecurityLevel security_level) {
return MediaDrmBridge::IsSecurityLevelSupported(key_system, security_level);
}
TEST(MediaDrmBridgeTest, IsSecurityLevelSupported_Widevine) {
EXPECT_FALSE(IsSecurityLevelSupported(kWidevineKeySystem, kLNone));
// We test "L3" fully. But for "L1" we don't check the result as it depends on
// whether the test device supports "L1".
EXPECT_TRUE_IF_AVAILABLE(IsSecurityLevelSupported(kWidevineKeySystem, kL3));
IsSecurityLevelSupported(kWidevineKeySystem, kL1);
}
// Invalid keysytem is NOT supported regardless whether MediaDrm is available.
TEST(MediaDrmBridgeTest, IsSecurityLevelSupported_InvalidKeySystem) {
EXPECT_FALSE(IsSecurityLevelSupported(kInvalidKeySystem, kLNone));
EXPECT_FALSE(IsSecurityLevelSupported(kInvalidKeySystem, kL1));
EXPECT_FALSE(IsSecurityLevelSupported(kInvalidKeySystem, kL3));
}
TEST(MediaDrmBridgeTest, IsKeySystemSupported_Widevine) {
EXPECT_TRUE_IF_AVAILABLE(IsKeySystemSupported(kWidevineKeySystem));
// TODO(xhwang): Enable when b/13564917 is fixed.
// EXPECT_TRUE_IF_AVAILABLE(
// IsKeySystemSupportedWithType(kWidevineKeySystem, kAudioMp4));
EXPECT_TRUE_IF_AVAILABLE(
IsKeySystemSupportedWithType(kWidevineKeySystem, kVideoMp4));
EXPECT_FALSE(IsKeySystemSupportedWithType(kWidevineKeySystem, kAudioWebM));
EXPECT_FALSE(IsKeySystemSupportedWithType(kWidevineKeySystem, kVideoWebM));
EXPECT_FALSE(IsKeySystemSupportedWithType(kWidevineKeySystem, "unknown"));
EXPECT_FALSE(IsKeySystemSupportedWithType(kWidevineKeySystem, "video/avi"));
EXPECT_FALSE(IsKeySystemSupportedWithType(kWidevineKeySystem, "audio/mp3"));
}
// Invalid keysytem is NOT supported regardless whether MediaDrm is available.
TEST(MediaDrmBridgeTest, IsKeySystemSupported_InvalidKeySystem) {
EXPECT_FALSE(IsKeySystemSupported(kInvalidKeySystem));
EXPECT_FALSE(IsKeySystemSupportedWithType(kInvalidKeySystem, kAudioMp4));
EXPECT_FALSE(IsKeySystemSupportedWithType(kInvalidKeySystem, kVideoMp4));
EXPECT_FALSE(IsKeySystemSupportedWithType(kInvalidKeySystem, kAudioWebM));
EXPECT_FALSE(IsKeySystemSupportedWithType(kInvalidKeySystem, kVideoWebM));
EXPECT_FALSE(IsKeySystemSupportedWithType(kInvalidKeySystem, "unknown"));
EXPECT_FALSE(IsKeySystemSupportedWithType(kInvalidKeySystem, "video/avi"));
EXPECT_FALSE(IsKeySystemSupportedWithType(kInvalidKeySystem, "audio/mp3"));
}
TEST(MediaDrmBridgeTest, AddNewKeySystemMapping) {
EXPECT_FALSE(IsKeySystemSupported(kFooKeySystem));
// Use WV UUID for foo, because it is the only key system we can guarentee
// that it is installed in the test device.
std::vector<uint8> foo_uuid(kWidevineUuid,
kWidevineUuid + arraysize(kWidevineUuid));
MediaDrmBridge::AddKeySystemUuidMapping(kFooKeySystem, foo_uuid);
EXPECT_TRUE_IF_AVAILABLE(IsKeySystemSupported(kFooKeySystem));
EXPECT_TRUE_IF_AVAILABLE(
IsKeySystemSupportedWithType(kFooKeySystem, kVideoMp4));
}
TEST(MediaDrmBridgeTest, ShouldNotOverwriteExistingKeySystem) {
EXPECT_TRUE_IF_AVAILABLE(IsKeySystemSupported(kWidevineKeySystem));
std::vector<uint8> invalid_uuid = std::vector<uint8>(16, 99);
#if DCHECK_IS_ON
ASSERT_DEATH({
MediaDrmBridge::AddKeySystemUuidMapping(kWidevineKeySystem, invalid_uuid);
}, "");
#else
// Try to add WV keysystem with the invalid UUID.
MediaDrmBridge::AddKeySystemUuidMapping(kWidevineKeySystem, invalid_uuid);
EXPECT_TRUE_IF_AVAILABLE(IsKeySystemSupported(kWidevineKeySystem));
#endif
}
} // namespace media
|