Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1333)

Side by Side Diff: content/renderer/media/crypto/key_systems_unittest.cc

Issue 23452025: Move EME key system knowledge from content/ to chrome/. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: review feedback and disabled mosts tests in encrypted_media_browsertest.cc Created 7 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright 2013 The Chromium Authors. All rights reserved. 1 // Copyright 2013 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 <string> 5 #include <string>
6 #include <vector> 6 #include <vector>
7 7
8 #include "content/public/common/content_client.h" 8 #include "content/public/common/content_client.h"
9 #include "content/public/renderer/content_renderer_client.h" 9 #include "content/public/renderer/content_renderer_client.h"
10 #include "content/public/renderer/key_system_info.h"
10 #include "content/renderer/media/crypto/key_systems.h" 11 #include "content/renderer/media/crypto/key_systems.h"
11 #include "content/test/test_content_client.h" 12 #include "content/test/test_content_client.h"
12 #include "testing/gtest/include/gtest/gtest.h" 13 #include "testing/gtest/include/gtest/gtest.h"
13 #include "third_party/WebKit/public/platform/WebString.h" 14 #include "third_party/WebKit/public/platform/WebString.h"
14 15
15 #include "widevine_cdm_version.h" // In SHARED_INTERMEDIATE_DIR. 16 #include "widevine_cdm_version.h" // In SHARED_INTERMEDIATE_DIR.
16 17
17 // Death tests are not always available, including on Android. 18 // Death tests are not always available, including on Android.
18 // EXPECT_DEBUG_DEATH_PORTABLE executes tests correctly except in the case that 19 // EXPECT_DEBUG_DEATH_PORTABLE executes tests correctly except in the case that
19 // death tests are not available and NDEBUG is not defined. 20 // death tests are not available and NDEBUG is not defined.
20 #if defined(GTEST_HAS_DEATH_TEST) && !defined(OS_ANDROID) 21 #if defined(GTEST_HAS_DEATH_TEST) && !defined(OS_ANDROID)
21 #define EXPECT_DEBUG_DEATH_PORTABLE(statement, regex) \ 22 #define EXPECT_DEBUG_DEATH_PORTABLE(statement, regex) \
22 EXPECT_DEBUG_DEATH(statement, regex) 23 EXPECT_DEBUG_DEATH(statement, regex)
23 #else 24 #else
24 #if defined(NDEBUG) 25 #if defined(NDEBUG)
25 #define EXPECT_DEBUG_DEATH_PORTABLE(statement, regex) \ 26 #define EXPECT_DEBUG_DEATH_PORTABLE(statement, regex) \
26 do { statement; } while (false) 27 do { statement; } while (false)
27 #else 28 #else
28 #include "base/logging.h" 29 #include "base/logging.h"
29 #define EXPECT_DEBUG_DEATH_PORTABLE(statement, regex) \ 30 #define EXPECT_DEBUG_DEATH_PORTABLE(statement, regex) \
30 LOG(WARNING) << "Death tests are not supported on this platform.\n" \ 31 LOG(WARNING) << "Death tests are not supported on this platform.\n" \
31 << "Statement '" #statement "' cannot be verified."; 32 << "Statement '" #statement "' cannot be verified.";
32 #endif // defined(NDEBUG) 33 #endif // defined(NDEBUG)
33 #endif // defined(GTEST_HAS_DEATH_TEST) && !defined(OS_ANDROID) 34 #endif // defined(GTEST_HAS_DEATH_TEST) && !defined(OS_ANDROID)
34 35
35 #if defined(WIDEVINE_CDM_AVAILABLE) && \
36 defined(OS_LINUX) && !defined(OS_CHROMEOS)
37 #include <gnu/libc-version.h>
38 #endif
39
40 using WebKit::WebString; 36 using WebKit::WebString;
41 37
42 #if defined(USE_PROPRIETARY_CODECS) 38 // These are the (fake) key systems that are registered for these tests.
43 #define EXPECT_PROPRIETARY EXPECT_TRUE 39 // kUsesAes uses the AesDecryptor like Clear Key.
44 #else 40 // kExternal uses an external CDM, such as Pepper-based or Android platform CDM.
45 #define EXPECT_PROPRIETARY EXPECT_FALSE 41 static const char kUsesAes[] = "org.example.clear";
46 #endif 42 static const char kUsesAesParent[] = "org.example"; // Not registered.
43 static const char kExternal[] = "com.example.test";
44 static const char kExternalParent[] = "com.example";
47 45
48 // Expectations for External Clear Key. 46 static const char kPrefixedClearKey[] = "webkit-org.w3.clearkey";
49 #if defined(ENABLE_PEPPER_CDMS) 47 static const char kUnprefixedClearKey[] = "org.w3.clearkey";
50 #define EXPECT_ECK EXPECT_TRUE 48 static const char kExternalClearKey[] = "org.chromium.externalclearkey";
51 #define EXPECT_ECKPROPRIETARY EXPECT_PROPRIETARY
52 #else
53 #define EXPECT_ECK EXPECT_FALSE
54 #define EXPECT_ECKPROPRIETARY EXPECT_FALSE
55 #endif // defined(ENABLE_PEPPER_CDMS)
56 49
57 // Expectations for Widevine. 50 static const char kAudioWebM[] = "audio/webm";
58 #if defined(WIDEVINE_CDM_AVAILABLE) 51 static const char kVideoWebM[] = "video/webm";
59 #if defined(OS_LINUX) && !defined(OS_CHROMEOS) 52 static const char kWebMAudioCodecs[] = "vorbis";
60 // TODO(ddorwin): Remove after bots switch to Precise. 53 static const char kWebMVideoCodecs[] = "vorbis,vp8,vp8.0";
61 #define EXPECT_WV(a) \
62 EXPECT_EQ((std::string(gnu_get_libc_version()) != "2.11.1"), (a))
63 #else
64 // See http://crbug.com/237627.
65 #if defined(DISABLE_WIDEVINE_CDM_CANPLAYTYPE)
66 #define EXPECT_WV EXPECT_FALSE
67 #else
68 #define EXPECT_WV EXPECT_TRUE
69 #endif // defined(DISABLE_WIDEVINE_CDM_CANPLAYTYPE)
70 #endif // defined(OS_LINUX) && !defined(OS_CHROMEOS)
71 54
72 #if defined(WIDEVINE_CDM_CENC_SUPPORT_AVAILABLE) 55 static const char kAudioFoo[] = "audio/foo";
73 56 static const char kVideoFoo[] = "video/foo";
74 #if defined(WIDEVINE_CDM_AVC1_SUPPORT_AVAILABLE) 57 static const char kFooAudioCodecs[] = "fooaudio";
75 #define EXPECT_WVAVC1 EXPECT_TRUE 58 static const char kFooVideoCodecs[] = "fooaudio,foovideo";
76 #if defined(WIDEVINE_CDM_AAC_SUPPORT_AVAILABLE)
77 #define EXPECT_WVAVC1AAC EXPECT_TRUE
78 #else
79 #define EXPECT_WVAVC1AAC EXPECT_FALSE
80 #endif // defined(WIDEVINE_CDM_AAC_SUPPORT_AVAILABLE)
81 #else // !defined(WIDEVINE_CDM_AVC1_SUPPORT_AVAILABLE)
82 #define EXPECT_WVAVC1 EXPECT_FALSE
83 #define EXPECT_WVAVC1AAC EXPECT_FALSE
84 #endif // defined(WIDEVINE_CDM_AVC1_SUPPORT_AVAILABLE)
85
86 #if defined(WIDEVINE_CDM_AAC_SUPPORT_AVAILABLE)
87 #define EXPECT_WVAAC EXPECT_TRUE
88 #else
89 #define EXPECT_WVAAC EXPECT_FALSE
90 #endif
91
92 #else // !defined(WIDEVINE_CDM_CENC_SUPPORT_AVAILABLE)
93 #define EXPECT_WVAVC1 EXPECT_FALSE
94 #define EXPECT_WVAVC1AAC EXPECT_FALSE
95 #define EXPECT_WVAAC EXPECT_FALSE
96 #endif // defined(WIDEVINE_CDM_CENC_SUPPORT_AVAILABLE)
97
98 #else // !defined(WIDEVINE_CDM_AVAILABLE)
99 #define EXPECT_WV EXPECT_FALSE
100 #define EXPECT_WVAVC1 EXPECT_FALSE
101 #define EXPECT_WVAVC1AAC EXPECT_FALSE
102 #define EXPECT_WVAAC EXPECT_FALSE
103 #endif // defined(WIDEVINE_CDM_AVAILABLE)
104 59
105 namespace content { 60 namespace content {
106 61
107 static const char* const kClearKey = "webkit-org.w3.clearkey"; 62 // Helper functions that handle the WebString conversion to simplify tests.
108 static const char* const kExternalClearKey = "org.chromium.externalclearkey"; 63 static std::string KeySystemNameForUMAUTF8(const std::string& key_system) {
109 static const char* const kWidevine = "com.widevine"; 64 return KeySystemNameForUMA(WebString::fromUTF8(key_system));
110 static const char* const kWidevineAlpha = "com.widevine.alpha"; 65 }
66
67 static bool IsConcreteSupportedKeySystemUTF8(const std::string& key_system) {
68 return IsConcreteSupportedKeySystem(WebString::fromUTF8(key_system));
69 }
70
71 class TestContentRendererClient : public ContentRendererClient {
72 virtual void AddKeySystems(
73 std::vector<content::KeySystemInfo>* key_systems) OVERRIDE;
74 };
75
76 void TestContentRendererClient::AddKeySystems(
77 std::vector<content::KeySystemInfo>* key_systems) {
78 #if defined(OS_ANDROID)
79 static const uint8 kExternalUuid[16] = {
80 0x01, 0x23, 0x45, 0x67, 0x89, 0xAB, 0xCD, 0xEF,
81 0x01, 0x23, 0x45, 0x67, 0x89, 0xAB, 0xCD, 0xEF };
82 #endif
83
84 KeySystemInfo aes(kUsesAes);
85
86 aes.supported_types.push_back(std::make_pair(kAudioWebM, kWebMAudioCodecs));
87 aes.supported_types.push_back(std::make_pair(kVideoWebM, kWebMVideoCodecs));
88
89 aes.supported_types.push_back(std::make_pair(kAudioFoo, kFooAudioCodecs));
90 aes.supported_types.push_back(std::make_pair(kVideoFoo, kFooVideoCodecs));
91
92 aes.use_aes_decryptor = true;
93
94 key_systems->push_back(aes);
95
96 KeySystemInfo ext(kExternal);
ddorwin 2013/09/13 00:33:42 "ext" isn't a good name, but it keeps 98-102,109 o
97
98 ext.supported_types.push_back(std::make_pair(kAudioWebM, kWebMAudioCodecs));
99 ext.supported_types.push_back(std::make_pair(kVideoWebM, kWebMVideoCodecs));
100
101 ext.supported_types.push_back(std::make_pair(kAudioFoo, kFooAudioCodecs));
102 ext.supported_types.push_back(std::make_pair(kVideoFoo, kFooVideoCodecs));
103
104 ext.parent_key_system = kExternalParent;
105
106 #if defined(ENABLE_PEPPER_CDMS)
107 ext.pepper_type = "application/x-ppapi-external-cdm";
108 #elif defined(OS_ANDROID)
109 ext.uuid.assign(kExternalUuid, kExternalUuid + arraysize(kExternalUuid));
110 #endif // defined(ENABLE_PEPPER_CDMS)
111
112 key_systems->push_back(ext);
113 }
111 114
112 class KeySystemsTest : public testing::Test { 115 class KeySystemsTest : public testing::Test {
113 protected: 116 protected:
114 KeySystemsTest() { 117 KeySystemsTest() {
115 vp8_codec_.push_back("vp8"); 118 vp8_codec_.push_back("vp8");
116 119
117 vp80_codec_.push_back("vp8.0"); 120 vp80_codec_.push_back("vp8.0");
118 121
119 vorbis_codec_.push_back("vorbis"); 122 vorbis_codec_.push_back("vorbis");
120 123
121 vp8_and_vorbis_codecs_.push_back("vp8"); 124 vp8_and_vorbis_codecs_.push_back("vp8");
122 vp8_and_vorbis_codecs_.push_back("vorbis"); 125 vp8_and_vorbis_codecs_.push_back("vorbis");
123 126
124 avc1_codec_.push_back("avc1"); 127 foovideo_codec_.push_back("foovideo");
125 128
126 avc1_extended_codec_.push_back("avc1.4D400C"); 129 foovideo_extended_codec_.push_back("foovideo.4D400C");
127 130
128 avc1_dot_codec_.push_back("avc1."); 131 foovideo_dot_codec_.push_back("foovideo.");
129 132
130 avc2_codec_.push_back("avc2"); 133 fooaudio_codec_.push_back("fooaudio");
131 134
132 aac_codec_.push_back("mp4a"); 135 foovideo_and_fooaudio_codecs_.push_back("foovideo");
136 foovideo_and_fooaudio_codecs_.push_back("fooaudio");
133 137
134 avc1_and_aac_codecs_.push_back("avc1"); 138 unknown_codec_.push_back("unknown");
135 avc1_and_aac_codecs_.push_back("mp4a");
136
137 unknown_codec_.push_back("foo");
138 139
139 mixed_codecs_.push_back("vorbis"); 140 mixed_codecs_.push_back("vorbis");
140 mixed_codecs_.push_back("avc1"); 141 mixed_codecs_.push_back("foovideo");
141 142
142 // KeySystems requires a valid ContentRendererClient and thus ContentClient. 143 // KeySystems requires a valid ContentRendererClient and thus ContentClient.
143 // The TestContentClient is not available inside Death Tests on some 144 // The TestContentClient is not available inside Death Tests on some
144 // platforms (see below). Therefore, always provide a TestContentClient. 145 // platforms (see below). Therefore, always provide a TestContentClient.
145 // Explanation: When Death Tests fork, there is a valid ContentClient. 146 // Explanation: When Death Tests fork, there is a valid ContentClient.
146 // However, when they launch a new process instead of forking, the global 147 // However, when they launch a new process instead of forking, the global
147 // variable is not copied and for some reason TestContentClientInitializer 148 // variable is not copied and for some reason TestContentClientInitializer
148 // does not get created to set the global variable in the new process. 149 // does not get created to set the global variable in the new process.
149 SetContentClient(&test_content_client_); 150 SetContentClient(&test_content_client_);
150 SetRendererClientForTesting(&content_renderer_client_); 151 SetRendererClientForTesting(&content_renderer_client_);
151 } 152 }
152 153
153 virtual ~KeySystemsTest() { 154 virtual ~KeySystemsTest() {
154 // Clear the use of content_client_, which was set in SetUp(). 155 // Clear the use of content_client_, which was set in SetUp().
155 SetContentClient(NULL); 156 SetContentClient(NULL);
156 } 157 }
157 158
158 typedef std::vector<std::string> CodecVector; 159 typedef std::vector<std::string> CodecVector;
159 160
160 const CodecVector& no_codecs() const { return no_codecs_; } 161 const CodecVector& no_codecs() const { return no_codecs_; }
161 162
162 const CodecVector& vp8_codec() const { return vp8_codec_; } 163 const CodecVector& vp8_codec() const { return vp8_codec_; }
163 const CodecVector& vp80_codec() const { return vp80_codec_; } 164 const CodecVector& vp80_codec() const { return vp80_codec_; }
164 const CodecVector& vorbis_codec() const { return vorbis_codec_; } 165 const CodecVector& vorbis_codec() const { return vorbis_codec_; }
165 const CodecVector& vp8_and_vorbis_codecs() const { 166 const CodecVector& vp8_and_vorbis_codecs() const {
166 return vp8_and_vorbis_codecs_; 167 return vp8_and_vorbis_codecs_;
167 } 168 }
168 169
169 const CodecVector& avc1_codec() const { return avc1_codec_; } 170 const CodecVector& foovideo_codec() const { return foovideo_codec_; }
170 const CodecVector& avc1_extended_codec() const { 171 const CodecVector& foovideo_extended_codec() const {
171 return avc1_extended_codec_; 172 return foovideo_extended_codec_;
172 } 173 }
173 const CodecVector& avc1_dot_codec() const { return avc1_dot_codec_; } 174 const CodecVector& foovideo_dot_codec() const { return foovideo_dot_codec_; }
174 const CodecVector& avc2_codec() const { return avc2_codec_; } 175 const CodecVector& fooaudio_codec() const { return fooaudio_codec_; }
175 const CodecVector& aac_codec() const { return aac_codec_; } 176 const CodecVector& foovideo_and_fooaudio_codecs() const {
176 const CodecVector& avc1_and_aac_codecs() const { 177 return foovideo_and_fooaudio_codecs_;
177 return avc1_and_aac_codecs_;
178 } 178 }
179 179
180 const CodecVector& unknown_codec() const { return unknown_codec_; } 180 const CodecVector& unknown_codec() const { return unknown_codec_; }
181 181
182 const CodecVector& mixed_codecs() const { return mixed_codecs_; } 182 const CodecVector& mixed_codecs() const { return mixed_codecs_; }
183 183
184 private: 184 private:
185 const CodecVector no_codecs_; 185 const CodecVector no_codecs_;
186 186
187 CodecVector vp8_codec_; 187 CodecVector vp8_codec_;
188 CodecVector vp80_codec_; 188 CodecVector vp80_codec_;
189 CodecVector vorbis_codec_; 189 CodecVector vorbis_codec_;
190 CodecVector vp8_and_vorbis_codecs_; 190 CodecVector vp8_and_vorbis_codecs_;
191 191
192 CodecVector avc1_codec_; 192 CodecVector foovideo_codec_;
193 CodecVector avc1_extended_codec_; 193 CodecVector foovideo_extended_codec_;
194 CodecVector avc1_dot_codec_; 194 CodecVector foovideo_dot_codec_;
195 CodecVector avc2_codec_; 195 CodecVector fooaudio_codec_;
196 CodecVector aac_codec_; 196 CodecVector foovideo_and_fooaudio_codecs_;
197 CodecVector avc1_and_aac_codecs_;
198 197
199 CodecVector unknown_codec_; 198 CodecVector unknown_codec_;
200 199
201 CodecVector mixed_codecs_; 200 CodecVector mixed_codecs_;
202 201
203 TestContentClient test_content_client_; 202 TestContentClient test_content_client_;
204 ContentRendererClient content_renderer_client_; 203 TestContentRendererClient content_renderer_client_;
205 }; 204 };
206 205
207 TEST_F(KeySystemsTest, ClearKey_Basic) { 206 // TODO(ddorwin): Consider moving GetUUID() into these tests or moving
208 EXPECT_TRUE(IsConcreteSupportedKeySystem(WebString::fromUTF8(kClearKey))); 207 // GetPepperType() calls out to their own test.
209 EXPECT_TRUE(IsSupportedKeySystemWithMediaMimeType( 208
210 "video/webm", no_codecs(), kClearKey)); 209 TEST_F(KeySystemsTest, ClearKeyNotRegistered) {
210 // Not registered in content.
211 EXPECT_FALSE(IsConcreteSupportedKeySystemUTF8(kPrefixedClearKey));
212 EXPECT_FALSE(IsSupportedKeySystemWithMediaMimeType(
213 kVideoWebM, no_codecs(), kPrefixedClearKey));
214
215 EXPECT_EQ("ClearKey", KeySystemNameForUMAUTF8(kPrefixedClearKey));
211 216
212 // Not yet out from behind the vendor prefix. 217 // Not yet out from behind the vendor prefix.
213 EXPECT_FALSE(IsConcreteSupportedKeySystem("org.w3.clearkey")); 218 EXPECT_FALSE(IsConcreteSupportedKeySystem(kUnprefixedClearKey));
214 EXPECT_FALSE(IsSupportedKeySystemWithMediaMimeType( 219 EXPECT_FALSE(IsSupportedKeySystemWithMediaMimeType(
215 "video/webm", no_codecs(), "org.w3.clearkey")); 220 kVideoWebM, no_codecs(), kUnprefixedClearKey));
216 221 EXPECT_EQ("Unknown", KeySystemNameForUMAUTF8(kUnprefixedClearKey));
217 EXPECT_STREQ("ClearKey", 222 }
218 KeySystemNameForUMA(WebString::fromUTF8(kClearKey)).c_str()); 223
219 224 // The key system is not registered and therefore is unrecognized.
220 EXPECT_TRUE(CanUseAesDecryptor(kClearKey)); 225 TEST_F(KeySystemsTest, Basic_UnrecognizedKeySystem) {
226 static const char* const kUnrecognized = "org.example.unrecognized";
227
228 EXPECT_FALSE(IsConcreteSupportedKeySystemUTF8(kUnrecognized));
229 EXPECT_FALSE(IsSupportedKeySystemWithMediaMimeType(
230 kVideoWebM, no_codecs(), kUnrecognized));
231
232 EXPECT_EQ("Unknown", KeySystemNameForUMAUTF8(kUnrecognized));
233
234 bool can_use = false;
235 EXPECT_DEBUG_DEATH(can_use = CanUseAesDecryptor(kUnrecognized),
236 "org.example.unrecognized is not a known concrete system");
237 EXPECT_FALSE(can_use);
238
221 #if defined(ENABLE_PEPPER_CDMS) 239 #if defined(ENABLE_PEPPER_CDMS)
222 std::string type; 240 std::string type;
223 EXPECT_DEBUG_DEATH(type = GetPepperType(kClearKey), 241 EXPECT_DEBUG_DEATH(type = GetPepperType(kUnrecognized),
224 "webkit-org.w3.clearkey is not Pepper-based"); 242 "org.example.unrecognized is not a known concrete system");
225 EXPECT_TRUE(type.empty()); 243 EXPECT_TRUE(type.empty());
226 #endif 244 #endif
227 } 245 }
228 246
229 TEST_F(KeySystemsTest, ClearKey_Parent) { 247 TEST_F(KeySystemsTest, Basic_UsesAesDecryptor) {
230 const char* const kClearKeyParent = "webkit-org.w3"; 248 EXPECT_TRUE(IsConcreteSupportedKeySystemUTF8(kUsesAes));
231 249 EXPECT_TRUE(IsSupportedKeySystemWithMediaMimeType(
232 // The parent should be supported but is not. See http://crbug.com/164303. 250 kVideoWebM, no_codecs(), kUsesAes));
233 EXPECT_FALSE( 251
234 IsConcreteSupportedKeySystem(WebString::fromUTF8(kClearKeyParent))); 252 // No UMA value for this test key system.
235 EXPECT_FALSE(IsSupportedKeySystemWithMediaMimeType( 253 EXPECT_EQ("Unknown", KeySystemNameForUMAUTF8(kUsesAes));
236 "video/webm", no_codecs(), kClearKeyParent)); 254
255 EXPECT_TRUE(CanUseAesDecryptor(kUsesAes));
256 #if defined(ENABLE_PEPPER_CDMS)
257 std::string type;
258 EXPECT_DEBUG_DEATH(type = GetPepperType(kUsesAes),
259 "org.example.clear is not Pepper-based");
260 EXPECT_TRUE(type.empty());
261 #endif
262 }
263
264 TEST_F(KeySystemsTest,
265 IsSupportedKeySystemWithMediaMimeType_UsesAesDecryptor_TypesContainer1) {
266 // Valid video types.
267 EXPECT_TRUE(IsSupportedKeySystemWithMediaMimeType(
268 kVideoWebM, vp8_codec(), kUsesAes));
269 EXPECT_TRUE(IsSupportedKeySystemWithMediaMimeType(
270 kVideoWebM, vp80_codec(), kUsesAes));
271 EXPECT_TRUE(IsSupportedKeySystemWithMediaMimeType(
272 kVideoWebM, vp8_and_vorbis_codecs(), kUsesAes));
273 EXPECT_TRUE(IsSupportedKeySystemWithMediaMimeType(
274 kVideoWebM, vorbis_codec(), kUsesAes));
275
276 // Non-Webm codecs.
277 EXPECT_FALSE(IsSupportedKeySystemWithMediaMimeType(
278 kVideoWebM, foovideo_codec(), kUsesAes));
279 EXPECT_FALSE(IsSupportedKeySystemWithMediaMimeType(
280 kVideoWebM, unknown_codec(), kUsesAes));
281 EXPECT_FALSE(IsSupportedKeySystemWithMediaMimeType(
282 kVideoWebM, mixed_codecs(), kUsesAes));
283
284 // Valid audio types.
285 EXPECT_TRUE(IsSupportedKeySystemWithMediaMimeType(
286 kAudioWebM, no_codecs(), kUsesAes));
287 EXPECT_TRUE(IsSupportedKeySystemWithMediaMimeType(
288 kAudioWebM, vorbis_codec(), kUsesAes));
289
290 // Non-audio codecs.
291 EXPECT_FALSE(IsSupportedKeySystemWithMediaMimeType(
292 kAudioWebM, vp8_codec(), kUsesAes));
293 EXPECT_FALSE(IsSupportedKeySystemWithMediaMimeType(
294 kAudioWebM, vp8_and_vorbis_codecs(), kUsesAes));
295
296 // Non-Webm codec.
297 EXPECT_FALSE(IsSupportedKeySystemWithMediaMimeType(
298 kAudioWebM, fooaudio_codec(), kUsesAes));
299 }
300
301 // No parent is registered for Clear.
302 TEST_F(KeySystemsTest, Parent_NoParentRegistered) {
303 EXPECT_FALSE(IsConcreteSupportedKeySystemUTF8(kUsesAesParent));
304 EXPECT_FALSE(IsSupportedKeySystemWithMediaMimeType(
305 kVideoWebM, no_codecs(), kUsesAesParent));
237 306
238 // The parent is not supported for most things. 307 // The parent is not supported for most things.
239 EXPECT_STREQ("Unknown", 308 EXPECT_EQ("Unknown", KeySystemNameForUMAUTF8(kUsesAesParent));
240 KeySystemNameForUMA(WebString::fromUTF8(kClearKeyParent)).c_str());
241 bool result = false; 309 bool result = false;
242 EXPECT_DEBUG_DEATH_PORTABLE(result = CanUseAesDecryptor(kClearKeyParent), 310 EXPECT_DEBUG_DEATH_PORTABLE(result = CanUseAesDecryptor(kUsesAesParent),
243 "webkit-org.w3 is not a known concrete system"); 311 "org.example is not a known concrete system");
244 EXPECT_FALSE(result); 312 EXPECT_FALSE(result);
245 #if defined(ENABLE_PEPPER_CDMS) 313 #if defined(ENABLE_PEPPER_CDMS)
246 std::string type; 314 std::string type;
247 EXPECT_DEBUG_DEATH(type = GetPepperType(kClearKeyParent), 315 EXPECT_DEBUG_DEATH(type = GetPepperType(kUsesAesParent),
248 "webkit-org.w3 is not a known concrete system"); 316 "org.example is not a known concrete system");
249 EXPECT_TRUE(type.empty()); 317 EXPECT_TRUE(type.empty());
250 #endif 318 #endif
251 } 319 }
252 320
253 TEST_F(KeySystemsTest, ClearKey_IsSupportedKeySystem_InvalidVariants) { 321 TEST_F(KeySystemsTest, IsSupportedKeySystem_InvalidVariants) {
254 // Case sensitive. 322 // Case sensitive.
255 EXPECT_FALSE(IsConcreteSupportedKeySystem("webkit-org.w3.ClEaRkEy")); 323 EXPECT_FALSE(IsConcreteSupportedKeySystemUTF8("org.example.ClEaR"));
256 EXPECT_FALSE(IsSupportedKeySystemWithMediaMimeType( 324 EXPECT_FALSE(IsSupportedKeySystemWithMediaMimeType(
257 "video/webm", no_codecs(), "webkit-org.w3.ClEaRkEy")); 325 kVideoWebM, no_codecs(), "org.example.ClEaR"));
258 326
259 // TLDs are not allowed. 327 // TLDs are not allowed.
260 EXPECT_FALSE(IsConcreteSupportedKeySystem("webkit-org."));
261 EXPECT_FALSE(IsSupportedKeySystemWithMediaMimeType(
262 "video/webm", no_codecs(), "webkit-org."));
263 EXPECT_FALSE(IsConcreteSupportedKeySystem("webkit-org"));
264 EXPECT_FALSE(IsSupportedKeySystemWithMediaMimeType(
265 "video/webm", no_codecs(), "webkit-org"));
266 EXPECT_FALSE(IsConcreteSupportedKeySystem("org.")); 328 EXPECT_FALSE(IsConcreteSupportedKeySystem("org."));
267 EXPECT_FALSE(IsSupportedKeySystemWithMediaMimeType( 329 EXPECT_FALSE(IsSupportedKeySystemWithMediaMimeType(
268 "video/webm", no_codecs(), "org.")); 330 kVideoWebM, no_codecs(), "org."));
269 EXPECT_FALSE(IsConcreteSupportedKeySystem("org")); 331 EXPECT_FALSE(IsConcreteSupportedKeySystem("com"));
270 EXPECT_FALSE(IsSupportedKeySystemWithMediaMimeType( 332 EXPECT_FALSE(IsSupportedKeySystemWithMediaMimeType(
271 "video/webm", no_codecs(), "org")); 333 kVideoWebM, no_codecs(), "com"));
272 334
273 // Extra period. 335 // Extra period.
274 EXPECT_FALSE(IsConcreteSupportedKeySystem("webkit-org.w3.")); 336 EXPECT_FALSE(IsConcreteSupportedKeySystem("org.example."));
275 EXPECT_FALSE(IsSupportedKeySystemWithMediaMimeType( 337 EXPECT_FALSE(IsSupportedKeySystemWithMediaMimeType(
276 "video/webm", no_codecs(), "webkit-org.w3.")); 338 kVideoWebM, no_codecs(), "org.example."));
277 339
278 // Incomplete. 340 // Incomplete.
279 EXPECT_FALSE(IsConcreteSupportedKeySystem("webkit-org.w3.clearke")); 341 EXPECT_FALSE(IsConcreteSupportedKeySystem("org.example.clea"));
280 EXPECT_FALSE(IsSupportedKeySystemWithMediaMimeType( 342 EXPECT_FALSE(IsSupportedKeySystemWithMediaMimeType(
281 "video/webm", no_codecs(), "webkit-org.w3.clearke")); 343 kVideoWebM, no_codecs(), "org.example.clea"));
282 344
283 // Extra character. 345 // Extra character.
284 EXPECT_FALSE(IsConcreteSupportedKeySystem("webkit-org.w3.clearkeyz")); 346 EXPECT_FALSE(IsConcreteSupportedKeySystem("org.example.clearz"));
285 EXPECT_FALSE(IsSupportedKeySystemWithMediaMimeType( 347 EXPECT_FALSE(IsSupportedKeySystemWithMediaMimeType(
286 "video/webm", no_codecs(), "webkit-org.w3.clearkeyz")); 348 kVideoWebM, no_codecs(), "org.example.clearz"));
287 349
288 // There are no child key systems for Clear Key. 350 // There are no child key systems for Clear Key.
289 EXPECT_FALSE(IsConcreteSupportedKeySystem("webkit-org.w3.clearkey.foo")); 351 EXPECT_FALSE(IsConcreteSupportedKeySystem("org.example.clear.foo"));
290 EXPECT_FALSE(IsSupportedKeySystemWithMediaMimeType( 352 EXPECT_FALSE(IsSupportedKeySystemWithMediaMimeType(
291 "video/webm", no_codecs(), "webkit-org.w3.clearkey.foo")); 353 kVideoWebM, no_codecs(), "org.example.clear.foo"));
292 } 354 }
293 355
294 TEST_F(KeySystemsTest, IsSupportedKeySystemWithMediaMimeType_ClearKey_NoType) { 356 TEST_F(KeySystemsTest, IsSupportedKeySystemWithMediaMimeType_NoType) {
295 // These two should be true. See http://crbug.com/164303. 357 // These two should be true. See http://crbug.com/164303.
296 EXPECT_FALSE(IsSupportedKeySystemWithMediaMimeType( 358 EXPECT_FALSE(IsSupportedKeySystemWithMediaMimeType(
297 std::string(), no_codecs(), kClearKey)); 359 std::string(), no_codecs(), kUsesAes));
298 EXPECT_FALSE(IsSupportedKeySystemWithMediaMimeType( 360 EXPECT_FALSE(IsSupportedKeySystemWithMediaMimeType(
299 std::string(), no_codecs(), "webkit-org.w3")); 361 std::string(), no_codecs(), kUsesAesParent));
300 362
301 EXPECT_FALSE(IsSupportedKeySystemWithMediaMimeType( 363 EXPECT_FALSE(IsSupportedKeySystemWithMediaMimeType(
302 std::string(), no_codecs(), "webkit-org.w3.foo")); 364 std::string(), no_codecs(), "org.example.foo"));
303 EXPECT_FALSE(IsSupportedKeySystemWithMediaMimeType( 365 EXPECT_FALSE(IsSupportedKeySystemWithMediaMimeType(
304 std::string(), no_codecs(), "webkit-org.w3.clearkey.foo")); 366 std::string(), no_codecs(), "org.example.clear.foo"));
305 } 367 }
306 368
307 TEST_F(KeySystemsTest, IsSupportedKeySystemWithMediaMimeType_ClearKey_WebM) { 369 // Tests the second registered container type.
370 // TODO(ddorwin): Combined with TypesContainer1 in a future CL.
371 TEST_F(KeySystemsTest,
372 IsSupportedKeySystemWithMediaMimeType_UsesAesDecryptor_TypesContainer2) {
308 // Valid video types. 373 // Valid video types.
309 EXPECT_TRUE(IsSupportedKeySystemWithMediaMimeType( 374 EXPECT_TRUE(IsSupportedKeySystemWithMediaMimeType(
310 "video/webm", no_codecs(), kClearKey)); 375 kVideoFoo, no_codecs(), kUsesAes));
311 // The parent should be supported but is not. See http://crbug.com/164303. 376 // The parent should be supported but is not. See http://crbug.com/164303.
312 EXPECT_FALSE(IsSupportedKeySystemWithMediaMimeType( 377 EXPECT_FALSE(IsSupportedKeySystemWithMediaMimeType(
313 "video/webm", no_codecs(), "webkit-org.w3")); 378 kVideoFoo, no_codecs(), kUsesAesParent));
314 EXPECT_TRUE(IsSupportedKeySystemWithMediaMimeType( 379 EXPECT_TRUE(IsSupportedKeySystemWithMediaMimeType(
315 "video/webm", vp8_codec(), kClearKey)); 380 kVideoFoo, foovideo_codec(), kUsesAes));
316 EXPECT_TRUE(IsSupportedKeySystemWithMediaMimeType( 381 EXPECT_TRUE(IsSupportedKeySystemWithMediaMimeType(
317 "video/webm", vp80_codec(), kClearKey)); 382 kVideoFoo, foovideo_and_fooaudio_codecs(), kUsesAes));
318 EXPECT_TRUE(IsSupportedKeySystemWithMediaMimeType( 383 EXPECT_TRUE(IsSupportedKeySystemWithMediaMimeType(
319 "video/webm", vp8_and_vorbis_codecs(), kClearKey)); 384 kVideoFoo, fooaudio_codec(), kUsesAes));
320 EXPECT_TRUE(IsSupportedKeySystemWithMediaMimeType(
321 "video/webm", vorbis_codec(), kClearKey));
322
323 // Non-Webm codecs.
324 EXPECT_FALSE(IsSupportedKeySystemWithMediaMimeType(
325 "video/webm", avc1_codec(), kClearKey));
326 EXPECT_FALSE(IsSupportedKeySystemWithMediaMimeType(
327 "video/webm", unknown_codec(), kClearKey));
328 EXPECT_FALSE(IsSupportedKeySystemWithMediaMimeType(
329 "video/webm", mixed_codecs(), kClearKey));
330
331 // Valid audio types.
332 EXPECT_TRUE(IsSupportedKeySystemWithMediaMimeType(
333 "audio/webm", no_codecs(), kClearKey));
334 EXPECT_TRUE(IsSupportedKeySystemWithMediaMimeType(
335 "audio/webm", vorbis_codec(), kClearKey));
336
337 // Non-audio codecs.
338 EXPECT_FALSE(IsSupportedKeySystemWithMediaMimeType(
339 "audio/webm", vp8_codec(), kClearKey));
340 EXPECT_FALSE(IsSupportedKeySystemWithMediaMimeType(
341 "audio/webm", vp8_and_vorbis_codecs(), kClearKey));
342
343 // Non-Webm codec.
344 EXPECT_FALSE(IsSupportedKeySystemWithMediaMimeType(
345 "audio/webm", aac_codec(), kClearKey));
346 }
347
348 TEST_F(KeySystemsTest, IsSupportedKeySystemWithMediaMimeType_ClearKey_MP4) {
349 // Valid video types.
350 EXPECT_PROPRIETARY(IsSupportedKeySystemWithMediaMimeType(
351 "video/mp4", no_codecs(), kClearKey));
352 // The parent should be supported but is not. See http://crbug.com/164303.
353 EXPECT_FALSE(IsSupportedKeySystemWithMediaMimeType(
354 "video/mp4", no_codecs(), "webkit-org.w3"));
355 EXPECT_PROPRIETARY(IsSupportedKeySystemWithMediaMimeType(
356 "video/mp4", avc1_codec(), kClearKey));
357 EXPECT_PROPRIETARY(IsSupportedKeySystemWithMediaMimeType(
358 "video/mp4", avc1_and_aac_codecs(), kClearKey));
359 EXPECT_PROPRIETARY(IsSupportedKeySystemWithMediaMimeType(
360 "video/mp4", aac_codec(), kClearKey));
361 385
362 // Extended codecs fail because this is handled by SimpleWebMimeRegistryImpl. 386 // Extended codecs fail because this is handled by SimpleWebMimeRegistryImpl.
363 // They should really pass canPlayType(). 387 // They should really pass canPlayType().
364 EXPECT_FALSE(IsSupportedKeySystemWithMediaMimeType( 388 EXPECT_FALSE(IsSupportedKeySystemWithMediaMimeType(
365 "video/mp4", avc1_extended_codec(), kClearKey)); 389 kVideoFoo, foovideo_extended_codec(), kUsesAes));
366 390
367 // Invalid codec format. 391 // Invalid codec format.
368 EXPECT_FALSE(IsSupportedKeySystemWithMediaMimeType( 392 EXPECT_FALSE(IsSupportedKeySystemWithMediaMimeType(
369 "video/mp4", avc1_dot_codec(), kClearKey)); 393 kVideoFoo, foovideo_dot_codec(), kUsesAes));
370 394
371 // Non-MP4 codecs. 395 // Non-container2 codec.
372 EXPECT_FALSE(IsSupportedKeySystemWithMediaMimeType( 396 EXPECT_FALSE(IsSupportedKeySystemWithMediaMimeType(
373 "video/mp4", avc2_codec(), kClearKey)); 397 kVideoFoo, vp8_codec(), kUsesAes));
374 EXPECT_FALSE(IsSupportedKeySystemWithMediaMimeType( 398 EXPECT_FALSE(IsSupportedKeySystemWithMediaMimeType(
375 "video/mp4", vp8_codec(), kClearKey)); 399 kVideoFoo, unknown_codec(), kUsesAes));
376 EXPECT_FALSE(IsSupportedKeySystemWithMediaMimeType( 400 EXPECT_FALSE(IsSupportedKeySystemWithMediaMimeType(
377 "video/mp4", unknown_codec(), kClearKey)); 401 kVideoFoo, mixed_codecs(), kUsesAes));
378 EXPECT_FALSE(IsSupportedKeySystemWithMediaMimeType(
379 "video/mp4", mixed_codecs(), kClearKey));
380 402
381 // Valid audio types. 403 // Valid audio types.
382 EXPECT_PROPRIETARY(IsSupportedKeySystemWithMediaMimeType( 404 EXPECT_TRUE(IsSupportedKeySystemWithMediaMimeType(
383 "audio/mp4", no_codecs(), kClearKey)); 405 kAudioFoo, no_codecs(), kUsesAes));
384 EXPECT_PROPRIETARY(IsSupportedKeySystemWithMediaMimeType( 406 EXPECT_TRUE(IsSupportedKeySystemWithMediaMimeType(
385 "audio/mp4", aac_codec(), kClearKey)); 407 kAudioFoo, fooaudio_codec(), kUsesAes));
386 408
387 // Non-audio codecs. 409 // Non-audio codecs.
388 EXPECT_FALSE(IsSupportedKeySystemWithMediaMimeType( 410 EXPECT_FALSE(IsSupportedKeySystemWithMediaMimeType(
389 "audio/mp4", avc1_codec(), kClearKey)); 411 kAudioFoo, foovideo_codec(), kUsesAes));
390 EXPECT_FALSE(IsSupportedKeySystemWithMediaMimeType( 412 EXPECT_FALSE(IsSupportedKeySystemWithMediaMimeType(
391 "audio/mp4", avc1_and_aac_codecs(), kClearKey)); 413 kAudioFoo, foovideo_and_fooaudio_codecs(), kUsesAes));
392 414
393 // Non-MP4 codec. 415 // Non-container2 codec.
394 EXPECT_FALSE(IsSupportedKeySystemWithMediaMimeType( 416 EXPECT_FALSE(IsSupportedKeySystemWithMediaMimeType(
395 "audio/mp4", vorbis_codec(), kClearKey)); 417 kAudioFoo, vorbis_codec(), kUsesAes));
396 } 418 }
397 419
398 // 420 //
399 // External Clear Key 421 // Non-AesDecryptor-based key system.
400 // 422 //
401 423
402 TEST_F(KeySystemsTest, ExternalClearKey_Basic) { 424 TEST_F(KeySystemsTest, Basic_ExternalDecryptor) {
403 EXPECT_ECK( 425 EXPECT_TRUE(IsConcreteSupportedKeySystemUTF8(kExternal));
404 IsConcreteSupportedKeySystem(WebString::fromUTF8(kExternalClearKey))); 426 EXPECT_TRUE(IsSupportedKeySystemWithMediaMimeType(
405 EXPECT_ECK(IsSupportedKeySystemWithMediaMimeType( 427 kVideoWebM, no_codecs(), kExternal));
406 "video/webm", no_codecs(), kExternalClearKey)); 428
407 429 EXPECT_FALSE(CanUseAesDecryptor(kExternal));
408 // External Clear Key does not have a UMA name because it is for testing.
409 EXPECT_STREQ(
410 "Unknown",
411 KeySystemNameForUMA(WebString::fromUTF8(kExternalClearKey)).c_str());
412
413 #if defined(ENABLE_PEPPER_CDMS) 430 #if defined(ENABLE_PEPPER_CDMS)
414 EXPECT_FALSE(CanUseAesDecryptor(kExternalClearKey)); 431 EXPECT_EQ("application/x-ppapi-external-cdm", GetPepperType(kExternal));
415 EXPECT_STREQ("application/x-ppapi-clearkey-cdm", 432 #endif // defined(ENABLE_PEPPER_CDMS)
416 GetPepperType(kExternalClearKey).c_str()); 433
417 #else 434 }
435
436 TEST_F(KeySystemsTest, Parent_ParentRegistered) {
437 // The parent system is not a concrete system but is supported.
438 EXPECT_FALSE(IsConcreteSupportedKeySystemUTF8(kExternalParent));
439 EXPECT_TRUE(IsSupportedKeySystemWithMediaMimeType(
440 kVideoWebM, no_codecs(), kExternalParent));
441
442 // The parent is not supported for most things.
443 EXPECT_EQ("Unknown", KeySystemNameForUMAUTF8(kExternalParent));
418 bool result = false; 444 bool result = false;
419 EXPECT_DEBUG_DEATH_PORTABLE( 445 EXPECT_DEBUG_DEATH_PORTABLE(result = CanUseAesDecryptor(kExternalParent),
420 result = CanUseAesDecryptor(kExternalClearKey), 446 "com.example is not a known concrete system");
421 "org.chromium.externalclearkey is not a known concrete system");
422 EXPECT_FALSE(result);
423 #endif
424 }
425
426 TEST_F(KeySystemsTest, ExternalClearKey_Parent) {
427 const char* const kExternalClearKeyParent = "org.chromium";
428
429 // The parent should be supported but is not. See http://crbug.com/164303.
430 EXPECT_FALSE(IsConcreteSupportedKeySystem(
431 WebString::fromUTF8(kExternalClearKeyParent)));
432 EXPECT_FALSE(IsSupportedKeySystemWithMediaMimeType(
433 "video/webm", no_codecs(), kExternalClearKeyParent));
434
435 // The parent is not supported for most things.
436 EXPECT_STREQ("Unknown",
437 KeySystemNameForUMA(
438 WebString::fromUTF8(kExternalClearKeyParent)).c_str());
439 bool result = false;
440 EXPECT_DEBUG_DEATH_PORTABLE(
441 result = CanUseAesDecryptor(kExternalClearKeyParent),
442 "org.chromium is not a known concrete system");
443 EXPECT_FALSE(result); 447 EXPECT_FALSE(result);
444 #if defined(ENABLE_PEPPER_CDMS) 448 #if defined(ENABLE_PEPPER_CDMS)
445 std::string type; 449 std::string type;
446 EXPECT_DEBUG_DEATH(type = GetPepperType(kExternalClearKeyParent), 450 EXPECT_DEBUG_DEATH(type = GetPepperType(kExternalParent),
447 "org.chromium is not a known concrete system"); 451 "com.example is not a known concrete system");
448 EXPECT_TRUE(type.empty()); 452 EXPECT_TRUE(type.empty());
449 #endif 453 #endif
450 } 454 }
451 455
452 TEST_F(KeySystemsTest, ExternalClearKey_IsSupportedKeySystem_InvalidVariants) { 456 TEST_F(
453 // Case sensitive. 457 KeySystemsTest,
454 EXPECT_FALSE(IsConcreteSupportedKeySystem("org.chromium.ExTeRnAlClEaRkEy")); 458 IsSupportedKeySystemWithMediaMimeType_ExternalDecryptor_TypesContainer1) {
455 EXPECT_FALSE(IsSupportedKeySystemWithMediaMimeType(
456 "video/webm", no_codecs(),
457 "org.chromium.ExTeRnAlClEaRkEy"));
458
459 // TLDs are not allowed.
460 EXPECT_FALSE(IsConcreteSupportedKeySystem("org."));
461 EXPECT_FALSE(IsSupportedKeySystemWithMediaMimeType(
462 "video/webm", no_codecs(), "org."));
463 EXPECT_FALSE(IsConcreteSupportedKeySystem("org"));
464 EXPECT_FALSE(IsSupportedKeySystemWithMediaMimeType(
465 "video/webm", no_codecs(), "org"));
466
467 // Extra period.
468 EXPECT_FALSE(IsConcreteSupportedKeySystem("org.chromium."));
469 EXPECT_FALSE(IsSupportedKeySystemWithMediaMimeType(
470 "video/webm", no_codecs(), "org.chromium."));
471
472 // Incomplete.
473 EXPECT_FALSE(IsConcreteSupportedKeySystem("org.chromium.externalclearke"));
474 EXPECT_FALSE(IsSupportedKeySystemWithMediaMimeType(
475 "video/webm", no_codecs(),
476 "org.chromium.externalclearke"));
477
478 // Extra character.
479 EXPECT_FALSE(IsConcreteSupportedKeySystem("org.chromium.externalclearkeyz"));
480 EXPECT_FALSE(IsSupportedKeySystemWithMediaMimeType(
481 "video/webm", no_codecs(),
482 "org.chromium.externalclearkeyz"));
483
484 // There are no child key systems for Clear Key.
485 EXPECT_FALSE(
486 IsConcreteSupportedKeySystem("org.chromium.externalclearkey.foo"));
487 EXPECT_FALSE(IsSupportedKeySystemWithMediaMimeType(
488 "video/webm", no_codecs(),
489 "org.chromium.externalclearkey.foo"));
490 }
491
492 TEST_F(KeySystemsTest,
493 IsSupportedKeySystemWithMediaMimeType_ExternalClearKey_NoType) {
494 // These two should be true. See http://crbug.com/164303.
495 EXPECT_FALSE(IsSupportedKeySystemWithMediaMimeType(
496 std::string(), no_codecs(), kExternalClearKey));
497 EXPECT_FALSE(IsSupportedKeySystemWithMediaMimeType(
498 std::string(), no_codecs(), "org.chromium"));
499
500 EXPECT_FALSE(IsSupportedKeySystemWithMediaMimeType(
501 std::string(), no_codecs(), "org.chromium.foo"));
502 EXPECT_FALSE(IsSupportedKeySystemWithMediaMimeType(
503 std::string(), no_codecs(), "org.chromium.externalclearkey.foo"));
504 }
505
506 TEST_F(KeySystemsTest,
507 IsSupportedKeySystemWithMediaMimeType_ExternalClearKey_WebM) {
508 // Valid video types. 459 // Valid video types.
509 EXPECT_ECK(IsSupportedKeySystemWithMediaMimeType( 460 EXPECT_TRUE(IsSupportedKeySystemWithMediaMimeType(
510 "video/webm", no_codecs(), kExternalClearKey)); 461 kVideoWebM, no_codecs(), kExternal));
511 // The parent should be supported but is not. See http://crbug.com/164303. 462 EXPECT_TRUE(IsSupportedKeySystemWithMediaMimeType(
512 EXPECT_FALSE(IsSupportedKeySystemWithMediaMimeType( 463 kVideoWebM, vp8_codec(), kExternal));
513 "video/webm", no_codecs(), "org.chromium")); 464 EXPECT_TRUE(IsSupportedKeySystemWithMediaMimeType(
514 EXPECT_ECK(IsSupportedKeySystemWithMediaMimeType( 465 kVideoWebM, vp80_codec(), kExternal));
515 "video/webm", vp8_codec(), kExternalClearKey)); 466 EXPECT_TRUE(IsSupportedKeySystemWithMediaMimeType(
516 EXPECT_ECK(IsSupportedKeySystemWithMediaMimeType( 467 kVideoWebM, vp8_and_vorbis_codecs(), kExternal));
517 "video/webm", vp80_codec(), kExternalClearKey)); 468 EXPECT_TRUE(IsSupportedKeySystemWithMediaMimeType(
518 EXPECT_ECK(IsSupportedKeySystemWithMediaMimeType( 469 kVideoWebM, vorbis_codec(), kExternal));
519 "video/webm", vp8_and_vorbis_codecs(), kExternalClearKey)); 470
520 EXPECT_ECK(IsSupportedKeySystemWithMediaMimeType( 471 // Valid video types - parent key system.
521 "video/webm", vorbis_codec(), kExternalClearKey)); 472 EXPECT_TRUE(IsSupportedKeySystemWithMediaMimeType(
473 kVideoWebM, no_codecs(), kExternalParent));
474 EXPECT_TRUE(IsSupportedKeySystemWithMediaMimeType(
475 kVideoWebM, vp8_codec(), kExternalParent));
476 EXPECT_TRUE(IsSupportedKeySystemWithMediaMimeType(
477 kVideoWebM, vp80_codec(), kExternalParent));
478 EXPECT_TRUE(IsSupportedKeySystemWithMediaMimeType(
479 kVideoWebM, vp8_and_vorbis_codecs(), kExternalParent));
480 EXPECT_TRUE(IsSupportedKeySystemWithMediaMimeType(
481 kVideoWebM, vorbis_codec(), kExternalParent));
522 482
523 // Non-Webm codecs. 483 // Non-Webm codecs.
524 EXPECT_FALSE(IsSupportedKeySystemWithMediaMimeType( 484 EXPECT_FALSE(IsSupportedKeySystemWithMediaMimeType(
525 "video/webm", avc1_codec(), kExternalClearKey)); 485 kVideoWebM, foovideo_codec(), kExternal));
526 EXPECT_FALSE(IsSupportedKeySystemWithMediaMimeType( 486 EXPECT_FALSE(IsSupportedKeySystemWithMediaMimeType(
527 "video/webm", unknown_codec(), kExternalClearKey)); 487 kVideoWebM, unknown_codec(), kExternal));
528 EXPECT_FALSE(IsSupportedKeySystemWithMediaMimeType( 488 EXPECT_FALSE(IsSupportedKeySystemWithMediaMimeType(
529 "video/webm", mixed_codecs(), kExternalClearKey)); 489 kVideoWebM, mixed_codecs(), kExternal));
530 490
531 // Valid audio types. 491 // Valid audio types.
532 EXPECT_ECK(IsSupportedKeySystemWithMediaMimeType( 492 EXPECT_TRUE(IsSupportedKeySystemWithMediaMimeType(
533 "audio/webm", no_codecs(), kExternalClearKey)); 493 kAudioWebM, no_codecs(), kExternal));
534 EXPECT_ECK(IsSupportedKeySystemWithMediaMimeType( 494 EXPECT_TRUE(IsSupportedKeySystemWithMediaMimeType(
535 "audio/webm", vorbis_codec(), kExternalClearKey)); 495 kAudioWebM, vorbis_codec(), kExternal));
496
497 // Valid audio types - parent key system.
498 EXPECT_TRUE(IsSupportedKeySystemWithMediaMimeType(
499 kAudioWebM, no_codecs(), kExternalParent));
500 EXPECT_TRUE(IsSupportedKeySystemWithMediaMimeType(
501 kAudioWebM, vorbis_codec(), kExternalParent));
536 502
537 // Non-audio codecs. 503 // Non-audio codecs.
538 EXPECT_FALSE(IsSupportedKeySystemWithMediaMimeType( 504 EXPECT_FALSE(IsSupportedKeySystemWithMediaMimeType(
539 "audio/webm", vp8_codec(), kExternalClearKey)); 505 kAudioWebM, vp8_codec(), kExternal));
540 EXPECT_FALSE(IsSupportedKeySystemWithMediaMimeType( 506 EXPECT_FALSE(IsSupportedKeySystemWithMediaMimeType(
541 "audio/webm", vp8_and_vorbis_codecs(), kExternalClearKey)); 507 kAudioWebM, vp8_and_vorbis_codecs(), kExternal));
542 508
543 // Non-Webm codec. 509 // Non-Webm codec.
544 EXPECT_FALSE(IsSupportedKeySystemWithMediaMimeType( 510 EXPECT_FALSE(IsSupportedKeySystemWithMediaMimeType(
545 "audio/webm", aac_codec(), kExternalClearKey)); 511 kAudioWebM, fooaudio_codec(), kExternal));
546 } 512 }
547 513
548 TEST_F(KeySystemsTest, 514 TEST_F(
549 IsSupportedKeySystemWithMediaMimeType_ExternalClearKey_MP4) { 515 KeySystemsTest,
516 IsSupportedKeySystemWithMediaMimeType_ExternalDecryptor_TypesContainer2) {
550 // Valid video types. 517 // Valid video types.
551 EXPECT_ECKPROPRIETARY(IsSupportedKeySystemWithMediaMimeType( 518 EXPECT_TRUE(IsSupportedKeySystemWithMediaMimeType(
552 "video/mp4", no_codecs(), kExternalClearKey)); 519 kVideoFoo, no_codecs(), kExternal));
553 // The parent should be supported but is not. See http://crbug.com/164303. 520 EXPECT_TRUE(IsSupportedKeySystemWithMediaMimeType(
554 EXPECT_FALSE(IsSupportedKeySystemWithMediaMimeType( 521 kVideoFoo, foovideo_codec(), kExternal));
555 "video/mp4", no_codecs(), "org.chromium")); 522 EXPECT_TRUE(IsSupportedKeySystemWithMediaMimeType(
556 EXPECT_ECKPROPRIETARY(IsSupportedKeySystemWithMediaMimeType( 523 kVideoFoo, foovideo_and_fooaudio_codecs(), kExternal));
557 "video/mp4", avc1_codec(), kExternalClearKey)); 524 EXPECT_TRUE(IsSupportedKeySystemWithMediaMimeType(
558 EXPECT_ECKPROPRIETARY(IsSupportedKeySystemWithMediaMimeType( 525 kVideoFoo, fooaudio_codec(), kExternal));
559 "video/mp4", avc1_and_aac_codecs(), kExternalClearKey)); 526
560 EXPECT_ECKPROPRIETARY(IsSupportedKeySystemWithMediaMimeType( 527 // Valid video types - parent key system.
561 "video/mp4", aac_codec(), kExternalClearKey)); 528 EXPECT_TRUE(IsSupportedKeySystemWithMediaMimeType(
529 kVideoFoo, no_codecs(), kExternalParent));
530 EXPECT_TRUE(IsSupportedKeySystemWithMediaMimeType(
531 kVideoFoo, foovideo_codec(), kExternalParent));
532 EXPECT_TRUE(IsSupportedKeySystemWithMediaMimeType(
533 kVideoFoo, foovideo_and_fooaudio_codecs(), kExternalParent));
534 EXPECT_TRUE(IsSupportedKeySystemWithMediaMimeType(
535 kVideoFoo, fooaudio_codec(), kExternalParent));
562 536
563 // Extended codecs fail because this is handled by SimpleWebMimeRegistryImpl. 537 // Extended codecs fail because this is handled by SimpleWebMimeRegistryImpl.
564 // They should really pass canPlayType(). 538 // They should really pass canPlayType().
565 EXPECT_FALSE(IsSupportedKeySystemWithMediaMimeType( 539 EXPECT_FALSE(IsSupportedKeySystemWithMediaMimeType(
566 "video/mp4", avc1_extended_codec(), kExternalClearKey)); 540 kVideoFoo, foovideo_extended_codec(), kExternal));
567 541
568 // Invalid codec format. 542 // Invalid codec format.
569 EXPECT_FALSE(IsSupportedKeySystemWithMediaMimeType( 543 EXPECT_FALSE(IsSupportedKeySystemWithMediaMimeType(
570 "video/mp4", avc1_dot_codec(), kExternalClearKey)); 544 kVideoFoo, foovideo_dot_codec(), kExternal));
571 545
572 // Non-MP4 codecs. 546 // Non-container2 codecs.
573 EXPECT_FALSE(IsSupportedKeySystemWithMediaMimeType( 547 EXPECT_FALSE(IsSupportedKeySystemWithMediaMimeType(
574 "video/mp4", avc2_codec(), kExternalClearKey)); 548 kVideoFoo, vp8_codec(), kExternal));
575 EXPECT_FALSE(IsSupportedKeySystemWithMediaMimeType( 549 EXPECT_FALSE(IsSupportedKeySystemWithMediaMimeType(
576 "video/mp4", vp8_codec(), kExternalClearKey)); 550 kVideoFoo, unknown_codec(), kExternal));
577 EXPECT_FALSE(IsSupportedKeySystemWithMediaMimeType( 551 EXPECT_FALSE(IsSupportedKeySystemWithMediaMimeType(
578 "video/mp4", unknown_codec(), kExternalClearKey)); 552 kVideoFoo, mixed_codecs(), kExternal));
579 EXPECT_FALSE(IsSupportedKeySystemWithMediaMimeType(
580 "video/mp4", mixed_codecs(), kExternalClearKey));
581 553
582 // Valid audio types. 554 // Valid audio types.
583 EXPECT_ECKPROPRIETARY(IsSupportedKeySystemWithMediaMimeType( 555 EXPECT_TRUE(IsSupportedKeySystemWithMediaMimeType(
584 "audio/mp4", no_codecs(), kExternalClearKey)); 556 kAudioFoo, no_codecs(), kExternal));
585 EXPECT_ECKPROPRIETARY(IsSupportedKeySystemWithMediaMimeType( 557 EXPECT_TRUE(IsSupportedKeySystemWithMediaMimeType(
586 "audio/mp4", aac_codec(), kExternalClearKey)); 558 kAudioFoo, fooaudio_codec(), kExternal));
559
560 // Valid audio types - parent key system.
561 EXPECT_TRUE(IsSupportedKeySystemWithMediaMimeType(
562 kAudioFoo, no_codecs(), kExternalParent));
563 EXPECT_TRUE(IsSupportedKeySystemWithMediaMimeType(
564 kAudioFoo, fooaudio_codec(), kExternalParent));
587 565
588 // Non-audio codecs. 566 // Non-audio codecs.
589 EXPECT_FALSE(IsSupportedKeySystemWithMediaMimeType( 567 EXPECT_FALSE(IsSupportedKeySystemWithMediaMimeType(
590 "audio/mp4", avc1_codec(), kExternalClearKey)); 568 kAudioFoo, foovideo_codec(), kExternal));
591 EXPECT_FALSE(IsSupportedKeySystemWithMediaMimeType( 569 EXPECT_FALSE(IsSupportedKeySystemWithMediaMimeType(
592 "audio/mp4", avc1_and_aac_codecs(), kExternalClearKey)); 570 kAudioFoo, foovideo_and_fooaudio_codecs(), kExternal));
593 571
594 // Non-MP4 codec. 572 // Non-container2 codec.
595 EXPECT_FALSE(IsSupportedKeySystemWithMediaMimeType( 573 EXPECT_FALSE(IsSupportedKeySystemWithMediaMimeType(
596 "audio/mp4", vorbis_codec(), kExternalClearKey)); 574 kAudioFoo, vorbis_codec(), kExternal));
597 }
598
599 //
600 // Widevine
601 //
602
603 TEST_F(KeySystemsTest, Widevine_Basic) {
604 #if defined(WIDEVINE_CDM_AVAILABLE) && \
605 defined(DISABLE_WIDEVINE_CDM_CANPLAYTYPE)
606 EXPECT_TRUE(
607 IsConcreteSupportedKeySystem(WebString::fromUTF8(kWidevineAlpha)));
608 #else
609 EXPECT_WV(IsConcreteSupportedKeySystem(WebString::fromUTF8(kWidevineAlpha)));
610 #endif
611
612 EXPECT_WV(IsSupportedKeySystemWithMediaMimeType(
613 "video/webm", no_codecs(), kWidevineAlpha));
614
615 #if defined(WIDEVINE_CDM_AVAILABLE)
616 const char* const kWidevineUmaName = "Widevine";
617 #else
618 const char* const kWidevineUmaName = "Unknown";
619 #endif
620 EXPECT_STREQ(
621 kWidevineUmaName,
622 KeySystemNameForUMA(WebString::fromUTF8(kWidevineAlpha)).c_str());
623
624 #if defined(WIDEVINE_CDM_AVAILABLE)
625 EXPECT_FALSE(CanUseAesDecryptor(kWidevineAlpha));
626 #else
627 bool result = false;
628 EXPECT_DEBUG_DEATH_PORTABLE(
629 result = CanUseAesDecryptor(kWidevineAlpha),
630 "com.widevine.alpha is not a known concrete system");
631 EXPECT_FALSE(result);
632 #endif // defined(WIDEVINE_CDM_AVAILABLE)
633
634 #if defined(ENABLE_PEPPER_CDMS)
635 #if defined(WIDEVINE_CDM_AVAILABLE)
636 EXPECT_STREQ("application/x-ppapi-widevine-cdm",
637 GetPepperType(kWidevineAlpha).c_str());
638 #else
639 std::string type;
640 EXPECT_DEBUG_DEATH(type = GetPepperType(kWidevineAlpha),
641 "com.widevine.alpha is not a known concrete system");
642 EXPECT_TRUE(type.empty());
643 #endif // defined(WIDEVINE_CDM_AVAILABLE)
644 #endif // defined(ENABLE_PEPPER_CDMS)
645
646 }
647
648 TEST_F(KeySystemsTest, Widevine_Parent) {
649 // The parent system is not a concrete system but is supported.
650 EXPECT_FALSE(IsConcreteSupportedKeySystem(WebString::fromUTF8(kWidevine)));
651 EXPECT_WV(IsSupportedKeySystemWithMediaMimeType(
652 "video/webm", no_codecs(), kWidevine));
653
654 // The parent is not supported for most things.
655 EXPECT_STREQ("Unknown",
656 KeySystemNameForUMA(WebString::fromUTF8(kWidevine)).c_str());
657 bool result = false;
658 EXPECT_DEBUG_DEATH_PORTABLE(result = CanUseAesDecryptor(kWidevine),
659 "com.widevine is not a known concrete system");
660 EXPECT_FALSE(result);
661 #if defined(ENABLE_PEPPER_CDMS)
662 std::string type;
663 EXPECT_DEBUG_DEATH(type = GetPepperType(kWidevine),
664 "com.widevine is not a known concrete system");
665 EXPECT_TRUE(type.empty());
666 #endif
667 }
668
669 TEST_F(KeySystemsTest, Widevine_IsSupportedKeySystem_InvalidVariants) {
670 // Case sensitive.
671 EXPECT_FALSE(IsConcreteSupportedKeySystem("com.widevine.AlPhA"));
672 EXPECT_FALSE(IsSupportedKeySystemWithMediaMimeType(
673 "video/webm", no_codecs(), "com.widevine.AlPhA"));
674
675 // TLDs are not allowed.
676 EXPECT_FALSE(IsConcreteSupportedKeySystem("com."));
677 EXPECT_FALSE(IsSupportedKeySystemWithMediaMimeType(
678 "video/webm", no_codecs(), "com."));
679 EXPECT_FALSE(IsConcreteSupportedKeySystem("com"));
680 EXPECT_FALSE(IsSupportedKeySystemWithMediaMimeType(
681 "video/webm", no_codecs(), "com"));
682
683 // Extra period.
684 EXPECT_FALSE(IsConcreteSupportedKeySystem("com.widevine."));
685 EXPECT_FALSE(IsSupportedKeySystemWithMediaMimeType(
686 "video/webm", no_codecs(), "com.widevine."));
687
688 // Incomplete.
689 EXPECT_FALSE(IsConcreteSupportedKeySystem("com.widevine.alph"));
690 EXPECT_FALSE(IsSupportedKeySystemWithMediaMimeType(
691 "video/webm", no_codecs(), "com.widevine.alph"));
692
693 // Extra character.
694 EXPECT_FALSE(IsConcreteSupportedKeySystem("com.widevine.alphab"));
695 EXPECT_FALSE(IsSupportedKeySystemWithMediaMimeType(
696 "video/webm", no_codecs(), "com.widevine.alphab"));
697
698 // There are no child key systems for Widevine Alpha.
699 EXPECT_FALSE(IsConcreteSupportedKeySystem("com.widevine.alpha.foo"));
700 EXPECT_FALSE(IsSupportedKeySystemWithMediaMimeType(
701 "video/webm", no_codecs(), "com.widevine.alpha.foo"));
702 }
703
704 TEST_F(KeySystemsTest, IsSupportedKeySystemWithMediaMimeType_Widevine_NoType) {
705 // These two should be true. See http://crbug.com/164303.
706 EXPECT_FALSE(IsSupportedKeySystemWithMediaMimeType(
707 std::string(), no_codecs(), kWidevineAlpha));
708 EXPECT_FALSE(IsSupportedKeySystemWithMediaMimeType(
709 std::string(), no_codecs(), kWidevine));
710
711 EXPECT_FALSE(IsSupportedKeySystemWithMediaMimeType(
712 std::string(), no_codecs(), "com.widevine.foo"));
713 EXPECT_FALSE(IsSupportedKeySystemWithMediaMimeType(
714 std::string(), no_codecs(), "com.widevine.alpha.foo"));
715 }
716
717 TEST_F(KeySystemsTest, IsSupportedKeySystemWithMediaMimeType_Widevine_WebM) {
718 // Valid video types.
719 EXPECT_WV(IsSupportedKeySystemWithMediaMimeType(
720 "video/webm", no_codecs(), kWidevineAlpha));
721 EXPECT_WV(IsSupportedKeySystemWithMediaMimeType(
722 "video/webm", vp8_codec(), kWidevineAlpha));
723 EXPECT_WV(IsSupportedKeySystemWithMediaMimeType(
724 "video/webm", vp80_codec(), kWidevineAlpha));
725 EXPECT_WV(IsSupportedKeySystemWithMediaMimeType(
726 "video/webm", vp8_and_vorbis_codecs(), kWidevineAlpha));
727 EXPECT_WV(IsSupportedKeySystemWithMediaMimeType(
728 "video/webm", vorbis_codec(), kWidevineAlpha));
729
730 // Valid video types - parent key system.
731 EXPECT_WV(IsSupportedKeySystemWithMediaMimeType(
732 "video/webm", no_codecs(), kWidevine));
733 EXPECT_WV(IsSupportedKeySystemWithMediaMimeType(
734 "video/webm", vp8_codec(), kWidevine));
735 EXPECT_WV(IsSupportedKeySystemWithMediaMimeType(
736 "video/webm", vp80_codec(), kWidevine));
737 EXPECT_WV(IsSupportedKeySystemWithMediaMimeType(
738 "video/webm", vp8_and_vorbis_codecs(), kWidevine));
739 EXPECT_WV(IsSupportedKeySystemWithMediaMimeType(
740 "video/webm", vorbis_codec(), kWidevine));
741
742 // Non-Webm codecs.
743 EXPECT_FALSE(IsSupportedKeySystemWithMediaMimeType(
744 "video/webm", avc1_codec(), kWidevineAlpha));
745 EXPECT_FALSE(IsSupportedKeySystemWithMediaMimeType(
746 "video/webm", unknown_codec(), kWidevineAlpha));
747 EXPECT_FALSE(IsSupportedKeySystemWithMediaMimeType(
748 "video/webm", mixed_codecs(), kWidevineAlpha));
749
750 // Valid audio types.
751 EXPECT_WV(IsSupportedKeySystemWithMediaMimeType(
752 "audio/webm", no_codecs(), kWidevineAlpha));
753 EXPECT_WV(IsSupportedKeySystemWithMediaMimeType(
754 "audio/webm", vorbis_codec(), kWidevineAlpha));
755
756 // Valid audio types - parent key system.
757 EXPECT_WV(IsSupportedKeySystemWithMediaMimeType(
758 "audio/webm", no_codecs(), kWidevine));
759 EXPECT_WV(IsSupportedKeySystemWithMediaMimeType(
760 "audio/webm", vorbis_codec(), kWidevine));
761
762 // Non-audio codecs.
763 EXPECT_FALSE(IsSupportedKeySystemWithMediaMimeType(
764 "audio/webm", vp8_codec(), kWidevineAlpha));
765 EXPECT_FALSE(IsSupportedKeySystemWithMediaMimeType(
766 "audio/webm", vp8_and_vorbis_codecs(), kWidevineAlpha));
767
768 // Non-Webm codec.
769 EXPECT_FALSE(IsSupportedKeySystemWithMediaMimeType(
770 "audio/webm", aac_codec(), kWidevineAlpha));
771 }
772
773 TEST_F(KeySystemsTest, IsSupportedKeySystemWithMediaMimeType_Widevine_MP4) {
774 // Valid video types.
775 EXPECT_WVAVC1(IsSupportedKeySystemWithMediaMimeType(
776 "video/mp4", no_codecs(), kWidevineAlpha));
777 EXPECT_WVAVC1(IsSupportedKeySystemWithMediaMimeType(
778 "video/mp4", avc1_codec(), kWidevineAlpha));
779 EXPECT_WVAVC1AAC(IsSupportedKeySystemWithMediaMimeType(
780 "video/mp4", avc1_and_aac_codecs(), kWidevineAlpha));
781 EXPECT_WVAVC1AAC(IsSupportedKeySystemWithMediaMimeType(
782 "video/mp4", aac_codec(), kWidevineAlpha));
783
784 // Valid video types - parent key system.
785 EXPECT_WVAVC1(IsSupportedKeySystemWithMediaMimeType(
786 "video/mp4", no_codecs(), kWidevine));
787 EXPECT_WVAVC1(IsSupportedKeySystemWithMediaMimeType(
788 "video/mp4", avc1_codec(), kWidevine));
789 EXPECT_WVAVC1AAC(IsSupportedKeySystemWithMediaMimeType(
790 "video/mp4", avc1_and_aac_codecs(), kWidevine));
791 EXPECT_WVAVC1AAC(IsSupportedKeySystemWithMediaMimeType(
792 "video/mp4", aac_codec(), kWidevine));
793
794 // Extended codecs fail because this is handled by SimpleWebMimeRegistryImpl.
795 // They should really pass canPlayType().
796 EXPECT_FALSE(IsSupportedKeySystemWithMediaMimeType(
797 "video/mp4", avc1_extended_codec(), kWidevineAlpha));
798
799 // Invalid codec format.
800 EXPECT_FALSE(IsSupportedKeySystemWithMediaMimeType(
801 "video/mp4", avc1_dot_codec(), kWidevineAlpha));
802
803 // Non-MP4 codecs.
804 EXPECT_FALSE(IsSupportedKeySystemWithMediaMimeType(
805 "video/mp4", avc2_codec(), kWidevineAlpha));
806 EXPECT_FALSE(IsSupportedKeySystemWithMediaMimeType(
807 "video/mp4", vp8_codec(), kWidevineAlpha));
808 EXPECT_FALSE(IsSupportedKeySystemWithMediaMimeType(
809 "video/mp4", unknown_codec(), kWidevineAlpha));
810 EXPECT_FALSE(IsSupportedKeySystemWithMediaMimeType(
811 "video/mp4", mixed_codecs(), kWidevineAlpha));
812
813 // Valid audio types.
814 EXPECT_WVAAC(IsSupportedKeySystemWithMediaMimeType(
815 "audio/mp4", no_codecs(), kWidevineAlpha));
816 EXPECT_WVAAC(IsSupportedKeySystemWithMediaMimeType(
817 "audio/mp4", aac_codec(), kWidevineAlpha));
818
819 // Valid audio types - parent key system.
820 EXPECT_WVAAC(IsSupportedKeySystemWithMediaMimeType(
821 "audio/mp4", no_codecs(), kWidevine));
822 EXPECT_WVAAC(IsSupportedKeySystemWithMediaMimeType(
823 "audio/mp4", aac_codec(), kWidevine));
824
825 // Non-audio codecs.
826 EXPECT_FALSE(IsSupportedKeySystemWithMediaMimeType(
827 "audio/mp4", avc1_codec(), kWidevineAlpha));
828 EXPECT_FALSE(IsSupportedKeySystemWithMediaMimeType(
829 "audio/mp4", avc1_and_aac_codecs(), kWidevineAlpha));
830
831 // Non-MP4 codec.
832 EXPECT_FALSE(IsSupportedKeySystemWithMediaMimeType(
833 "audio/mp4", vorbis_codec(), kWidevineAlpha));
834 } 575 }
835 576
836 #if defined(OS_ANDROID) 577 #if defined(OS_ANDROID)
837 TEST_F(KeySystemsTest, GetUUID_Widevine) { 578 TEST_F(KeySystemsTest, GetUUID_RegisteredExternalDecryptor) {
838 #if defined(WIDEVINE_CDM_AVAILABLE) 579 std::vector<uint8> uuid = GetUUID(kExternal);
839 std::vector<uint8> uuid = GetUUID(kWidevineAlpha);
840 EXPECT_EQ(16u, uuid.size()); 580 EXPECT_EQ(16u, uuid.size());
841 EXPECT_EQ(0xED, uuid[15]); 581 EXPECT_EQ(0xef, uuid[15]);
842 #else 582 }
843 std::vector<uint8> uuid; 583
844 EXPECT_DEBUG_DEATH_PORTABLE( 584 TEST_F(KeySystemsTest, GetUUID_RegisteredAesDecryptor) {
845 uuid = GetUUID(kWidevineAlpha), 585 EXPECT_TRUE(GetUUID(kUsesAes).empty());
846 "com.widevine.alpha is not a known concrete system");
847 EXPECT_TRUE(uuid.empty());
848 #endif
849 } 586 }
850 587
851 TEST_F(KeySystemsTest, GetUUID_Unrecognized) { 588 TEST_F(KeySystemsTest, GetUUID_Unrecognized) {
852 std::vector<uint8> uuid; 589 std::vector<uint8> uuid;
853 EXPECT_DEBUG_DEATH_PORTABLE(uuid = GetUUID(kWidevine), 590 EXPECT_DEBUG_DEATH_PORTABLE(uuid = GetUUID(kExternalParent),
854 "com.widevine is not a known concrete system"); 591 "com.example is not a known concrete system");
855 EXPECT_TRUE(uuid.empty()); 592 EXPECT_TRUE(uuid.empty());
856 593
857 EXPECT_TRUE(GetUUID(kClearKey).empty());
858
859 EXPECT_DEBUG_DEATH_PORTABLE(uuid = GetUUID(""), " is not a concrete system"); 594 EXPECT_DEBUG_DEATH_PORTABLE(uuid = GetUUID(""), " is not a concrete system");
860 EXPECT_TRUE(uuid.empty()); 595 EXPECT_TRUE(uuid.empty());
861 } 596 }
862 #endif // defined(OS_ANDROID) 597 #endif // defined(OS_ANDROID)
863 598
599 TEST_F(KeySystemsTest, KeySystemNameForUMA) {
600 EXPECT_EQ("ClearKey", KeySystemNameForUMAUTF8(kPrefixedClearKey));
601 // Unprefixed is not yet supported.
602 EXPECT_EQ("Unknown", KeySystemNameForUMAUTF8(kUnprefixedClearKey));
603
604 // External Clear Key never has a UMA name.
605 EXPECT_EQ("Unknown", KeySystemNameForUMAUTF8(kExternalClearKey));
606
607 #if defined(WIDEVINE_CDM_AVAILABLE)
608 const char* const kTestWidevineUmaName = "Widevine";
609 #else
610 const char* const kTestWidevineUmaName = "Unknown";
611 #endif
612 EXPECT_EQ(kTestWidevineUmaName,
613 KeySystemNameForUMAUTF8("com.widevine.alpha"));
614 }
615
864 } // namespace content 616 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698