OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "base/basictypes.h" | 5 #include "base/basictypes.h" |
6 #include "base/logging.h" | 6 #include "base/logging.h" |
7 #include "media/base/android/media_drm_bridge.h" | 7 #include "media/base/android/media_drm_bridge.h" |
8 #include "testing/gtest/include/gtest/gtest.h" | 8 #include "testing/gtest/include/gtest/gtest.h" |
9 | 9 |
10 #include "widevine_cdm_version.h" // In SHARED_INTERMEDIATE_DIR. | 10 #include "widevine_cdm_version.h" // In SHARED_INTERMEDIATE_DIR. |
11 | 11 |
12 namespace media { | 12 namespace media { |
13 | 13 |
14 #define EXPECT_TRUE_IF_AVAILABLE(a) \ | 14 #define EXPECT_TRUE_IF_AVAILABLE(a) \ |
15 do { \ | 15 do { \ |
16 if (!MediaDrmBridge::IsAvailable()) { \ | 16 if (!MediaDrmBridge::IsAvailable()) { \ |
17 VLOG(0) << "MediaDrm not supported on device."; \ | 17 VLOG(0) << "MediaDrm not supported on device."; \ |
18 EXPECT_FALSE(a); \ | 18 EXPECT_FALSE(a); \ |
19 } else { \ | 19 } else { \ |
20 EXPECT_TRUE(a); \ | 20 EXPECT_TRUE(a); \ |
21 } \ | 21 } \ |
22 } while (0) | 22 } while (0) |
23 | 23 |
24 const char kAudioMp4[] = "audio/mp4"; | 24 const char kAudioMp4[] = "audio/mp4"; |
25 const char kVideoMp4[] = "video/mp4"; | 25 const char kVideoMp4[] = "video/mp4"; |
26 const char kAudioWebM[] = "audio/webm"; | 26 const char kAudioWebM[] = "audio/webm"; |
27 const char kVideoWebM[] = "video/webm"; | 27 const char kVideoWebM[] = "video/webm"; |
28 const char kInvalidKeySystem[] = "invalid.keysystem"; | 28 const char kInvalidKeySystem[] = "invalid.keysystem"; |
29 const char kFooKeySystem[] = "com.foo.keysystem"; | |
30 const uint8 kWidevineUuid[16] = { | |
31 0xED, 0xEF, 0x8B, 0xA9, 0x79, 0xD6, 0x4A, 0xCE, | |
32 0xA3, 0xC8, 0x27, 0xDC, 0xD5, 0x1D, 0x21, 0xED }; | |
33 const MediaDrmBridge::SecurityLevel kLNone = | 29 const MediaDrmBridge::SecurityLevel kLNone = |
34 MediaDrmBridge::SECURITY_LEVEL_NONE; | 30 MediaDrmBridge::SECURITY_LEVEL_NONE; |
35 const MediaDrmBridge::SecurityLevel kL1 = MediaDrmBridge::SECURITY_LEVEL_1; | 31 const MediaDrmBridge::SecurityLevel kL1 = MediaDrmBridge::SECURITY_LEVEL_1; |
36 const MediaDrmBridge::SecurityLevel kL3 = MediaDrmBridge::SECURITY_LEVEL_3; | 32 const MediaDrmBridge::SecurityLevel kL3 = MediaDrmBridge::SECURITY_LEVEL_3; |
37 | 33 |
38 // Helper functions to avoid typing "MediaDrmBridge::" in tests. | 34 // Helper functions to avoid typing "MediaDrmBridge::" in tests. |
39 | 35 |
40 static bool IsKeySystemSupported(const std::string& key_system) { | 36 static bool IsKeySystemSupported(const std::string& key_system) { |
41 return MediaDrmBridge::IsKeySystemSupported(key_system); | 37 return MediaDrmBridge::IsKeySystemSupported(key_system); |
42 } | 38 } |
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
90 EXPECT_FALSE(IsKeySystemSupported(kInvalidKeySystem)); | 86 EXPECT_FALSE(IsKeySystemSupported(kInvalidKeySystem)); |
91 EXPECT_FALSE(IsKeySystemSupportedWithType(kInvalidKeySystem, kAudioMp4)); | 87 EXPECT_FALSE(IsKeySystemSupportedWithType(kInvalidKeySystem, kAudioMp4)); |
92 EXPECT_FALSE(IsKeySystemSupportedWithType(kInvalidKeySystem, kVideoMp4)); | 88 EXPECT_FALSE(IsKeySystemSupportedWithType(kInvalidKeySystem, kVideoMp4)); |
93 EXPECT_FALSE(IsKeySystemSupportedWithType(kInvalidKeySystem, kAudioWebM)); | 89 EXPECT_FALSE(IsKeySystemSupportedWithType(kInvalidKeySystem, kAudioWebM)); |
94 EXPECT_FALSE(IsKeySystemSupportedWithType(kInvalidKeySystem, kVideoWebM)); | 90 EXPECT_FALSE(IsKeySystemSupportedWithType(kInvalidKeySystem, kVideoWebM)); |
95 EXPECT_FALSE(IsKeySystemSupportedWithType(kInvalidKeySystem, "unknown")); | 91 EXPECT_FALSE(IsKeySystemSupportedWithType(kInvalidKeySystem, "unknown")); |
96 EXPECT_FALSE(IsKeySystemSupportedWithType(kInvalidKeySystem, "video/avi")); | 92 EXPECT_FALSE(IsKeySystemSupportedWithType(kInvalidKeySystem, "video/avi")); |
97 EXPECT_FALSE(IsKeySystemSupportedWithType(kInvalidKeySystem, "audio/mp3")); | 93 EXPECT_FALSE(IsKeySystemSupportedWithType(kInvalidKeySystem, "audio/mp3")); |
98 } | 94 } |
99 | 95 |
100 TEST(MediaDrmBridgeTest, AddNewKeySystemMapping) { | |
101 EXPECT_FALSE(IsKeySystemSupported(kFooKeySystem)); | |
102 | |
103 // Use WV UUID for foo, because it is the only key system we can guarentee | |
104 // that it is installed in the test device. | |
105 std::vector<uint8> foo_uuid(kWidevineUuid, | |
106 kWidevineUuid + arraysize(kWidevineUuid)); | |
107 MediaDrmBridge::AddKeySystemUuidMapping(kFooKeySystem, foo_uuid); | |
108 | |
109 EXPECT_TRUE_IF_AVAILABLE(IsKeySystemSupported(kFooKeySystem)); | |
110 EXPECT_TRUE_IF_AVAILABLE( | |
111 IsKeySystemSupportedWithType(kFooKeySystem, kVideoMp4)); | |
112 } | |
113 | |
114 TEST(MediaDrmBridgeTest, ShouldNotOverwriteExistingKeySystem) { | |
115 EXPECT_TRUE_IF_AVAILABLE(IsKeySystemSupported(kWidevineKeySystem)); | |
116 std::vector<uint8> invalid_uuid = std::vector<uint8>(16, 99); | |
117 #if DCHECK_IS_ON | |
118 ASSERT_DEATH({ | |
119 MediaDrmBridge::AddKeySystemUuidMapping(kWidevineKeySystem, invalid_uuid); | |
120 }, ""); | |
121 #else | |
122 // Try to add WV keysystem with the invalid UUID. | |
123 MediaDrmBridge::AddKeySystemUuidMapping(kWidevineKeySystem, invalid_uuid); | |
124 | |
125 EXPECT_TRUE_IF_AVAILABLE(IsKeySystemSupported(kWidevineKeySystem)); | |
126 #endif | |
127 } | |
128 | |
129 } // namespace media | 96 } // namespace media |
OLD | NEW |