OLD | NEW |
---|---|
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/public/renderer/key_system_info.h" |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
42 const char kUsesAesParent[] = "org.example"; // Not registered. | 42 const char kUsesAesParent[] = "org.example"; // Not registered. |
43 const char kExternal[] = "com.example.test"; | 43 const char kExternal[] = "com.example.test"; |
44 const char kExternalParent[] = "com.example"; | 44 const char kExternalParent[] = "com.example"; |
45 | 45 |
46 const char kClearKey[] = "org.w3.clearkey"; | 46 const char kClearKey[] = "org.w3.clearkey"; |
47 const char kPrefixedClearKey[] = "webkit-org.w3.clearkey"; | 47 const char kPrefixedClearKey[] = "webkit-org.w3.clearkey"; |
48 const char kExternalClearKey[] = "org.chromium.externalclearkey"; | 48 const char kExternalClearKey[] = "org.chromium.externalclearkey"; |
49 | 49 |
50 const char kAudioWebM[] = "audio/webm"; | 50 const char kAudioWebM[] = "audio/webm"; |
51 const char kVideoWebM[] = "video/webm"; | 51 const char kVideoWebM[] = "video/webm"; |
52 const char kVorbis[] = "vorbis"; | |
53 const char kVP8[] = "vp8"; | |
54 const char kVP80[] = "vp8.0"; | |
55 | |
56 const char kAudioFoo[] = "audio/foo"; | 52 const char kAudioFoo[] = "audio/foo"; |
57 const char kVideoFoo[] = "video/foo"; | 53 const char kVideoFoo[] = "video/foo"; |
58 const char kFooAudioCodec[] = "fooaudio"; | 54 |
59 const char kFooVideoCodec[] = "foovideo"; | 55 enum TestCodecMask { |
56 FOO_AUDIO_CODEC = 1 << 10, | |
ddorwin
2014/04/22 21:24:41
Is there significance to 10?
xhwang
2014/04/23 17:29:14
Added a comment.
| |
57 FOO_AUDIO = FOO_AUDIO_CODEC, | |
58 FOO_VIDEO_CODEC = 1 << 11, | |
59 FOO_VIDEO = FOO_VIDEO_CODEC, | |
60 FOO_CODECS = FOO_AUDIO | FOO_VIDEO | |
61 }; | |
62 | |
63 COMPILE_ASSERT((FOO_CODECS & media::ALL_CODECS) == media::NO_CODECS, | |
ddorwin
2014/04/22 21:24:41
Maybe we should just remove some PROPRIETARY_CODEC
xhwang
2014/04/23 17:29:14
I am not sure what you exactly mean...
| |
64 "Test codec masks should only use invalid codec masks."); | |
60 | 65 |
61 namespace content { | 66 namespace content { |
62 | 67 |
68 // Adds test container and codec masks. | |
69 // This function must be called after SetContentClient() is called. | |
70 // More details: AddXxxMask() will create KeySystems if it hasn't been created. | |
71 // During KeySystems's construction GetContentClient() will be used to add key | |
72 // systems. In test code, the content client is set by SetContentClient(). | |
73 // Therefore, SetContentClient() must be called before this function to avoid | |
74 // access violation. | |
75 static void AddContainerAndCodecMasksForTest() { | |
76 // Since KeySystems is a singleton. Make sure we only add test container and | |
77 // codec masks once per process. | |
78 static bool is_test_masks_added = false; | |
79 | |
80 if (is_test_masks_added) | |
81 return; | |
82 | |
83 AddContainerMask("audio/foo", FOO_AUDIO); | |
84 AddContainerMask("video/foo", FOO_CODECS); | |
85 AddCodecMask("fooaudio", FOO_AUDIO_CODEC); | |
86 AddCodecMask("foovideo", FOO_VIDEO_CODEC); | |
87 | |
88 is_test_masks_added = true; | |
89 } | |
90 | |
63 class TestContentRendererClient : public ContentRendererClient { | 91 class TestContentRendererClient : public ContentRendererClient { |
64 virtual void AddKeySystems( | 92 virtual void AddKeySystems( |
65 std::vector<content::KeySystemInfo>* key_systems) OVERRIDE; | 93 std::vector<content::KeySystemInfo>* key_systems) OVERRIDE; |
66 }; | 94 }; |
67 | 95 |
68 void TestContentRendererClient::AddKeySystems( | 96 void TestContentRendererClient::AddKeySystems( |
69 std::vector<content::KeySystemInfo>* key_systems) { | 97 std::vector<content::KeySystemInfo>* key_systems) { |
70 KeySystemInfo aes(kUsesAes); | 98 KeySystemInfo aes(kUsesAes); |
71 | 99 aes.supported_codecs = media::WEBM_CODECS; |
72 aes.supported_types[kAudioWebM].insert(kVorbis); | 100 aes.supported_codecs |= FOO_CODECS; |
73 aes.supported_types[kVideoWebM] = aes.supported_types[kAudioWebM]; | |
74 aes.supported_types[kVideoWebM].insert(kVP8); | |
75 aes.supported_types[kVideoWebM].insert(kVP80); | |
76 aes.supported_types[kAudioFoo].insert(kFooAudioCodec); | |
77 aes.supported_types[kVideoFoo] = aes.supported_types[kAudioFoo]; | |
78 aes.supported_types[kVideoFoo].insert(kFooVideoCodec); | |
79 | |
80 aes.use_aes_decryptor = true; | 101 aes.use_aes_decryptor = true; |
81 | |
82 key_systems->push_back(aes); | 102 key_systems->push_back(aes); |
83 | 103 |
84 KeySystemInfo ext(kExternal); | 104 KeySystemInfo ext(kExternal); |
85 | 105 ext.supported_codecs = media::WEBM_CODECS; |
86 ext.supported_types[kAudioWebM].insert(kVorbis); | 106 ext.supported_codecs |= FOO_CODECS; |
87 ext.supported_types[kVideoWebM] = ext.supported_types[kAudioWebM]; | |
88 ext.supported_types[kVideoWebM].insert(kVP8); | |
89 ext.supported_types[kVideoWebM].insert(kVP80); | |
90 ext.supported_types[kAudioFoo].insert(kFooAudioCodec); | |
91 ext.supported_types[kVideoFoo] = ext.supported_types[kAudioFoo]; | |
92 ext.supported_types[kVideoFoo].insert(kFooVideoCodec); | |
93 | |
94 ext.parent_key_system = kExternalParent; | 107 ext.parent_key_system = kExternalParent; |
95 | |
96 #if defined(ENABLE_PEPPER_CDMS) | 108 #if defined(ENABLE_PEPPER_CDMS) |
97 ext.pepper_type = "application/x-ppapi-external-cdm"; | 109 ext.pepper_type = "application/x-ppapi-external-cdm"; |
98 #endif // defined(ENABLE_PEPPER_CDMS) | 110 #endif // defined(ENABLE_PEPPER_CDMS) |
99 | |
100 key_systems->push_back(ext); | 111 key_systems->push_back(ext); |
101 } | 112 } |
102 | 113 |
103 class KeySystemsTest : public testing::Test { | 114 class KeySystemsTest : public testing::Test { |
104 protected: | 115 protected: |
105 KeySystemsTest() { | 116 KeySystemsTest() { |
106 vp8_codec_.push_back("vp8"); | 117 vp8_codec_.push_back("vp8"); |
107 | 118 |
108 vp80_codec_.push_back("vp8.0"); | 119 vp80_codec_.push_back("vp8.0"); |
109 | 120 |
(...skipping 22 matching lines...) Expand all Loading... | |
132 // The TestContentClient is not available inside Death Tests on some | 143 // The TestContentClient is not available inside Death Tests on some |
133 // platforms (see below). Therefore, always provide a TestContentClient. | 144 // platforms (see below). Therefore, always provide a TestContentClient. |
134 // Explanation: When Death Tests fork, there is a valid ContentClient. | 145 // Explanation: When Death Tests fork, there is a valid ContentClient. |
135 // However, when they launch a new process instead of forking, the global | 146 // However, when they launch a new process instead of forking, the global |
136 // variable is not copied and for some reason TestContentClientInitializer | 147 // variable is not copied and for some reason TestContentClientInitializer |
137 // does not get created to set the global variable in the new process. | 148 // does not get created to set the global variable in the new process. |
138 SetContentClient(&test_content_client_); | 149 SetContentClient(&test_content_client_); |
139 SetRendererClientForTesting(&content_renderer_client_); | 150 SetRendererClientForTesting(&content_renderer_client_); |
140 } | 151 } |
141 | 152 |
153 virtual void SetUp() OVERRIDE { | |
154 AddContainerAndCodecMasksForTest(); | |
155 } | |
156 | |
142 virtual ~KeySystemsTest() { | 157 virtual ~KeySystemsTest() { |
143 // Clear the use of content_client_, which was set in SetUp(). | 158 // Clear the use of content_client_, which was set in SetUp(). |
144 SetContentClient(NULL); | 159 SetContentClient(NULL); |
145 } | 160 } |
146 | 161 |
147 typedef std::vector<std::string> CodecVector; | 162 typedef std::vector<std::string> CodecVector; |
148 | 163 |
149 const CodecVector& no_codecs() const { return no_codecs_; } | 164 const CodecVector& no_codecs() const { return no_codecs_; } |
150 | 165 |
151 const CodecVector& vp8_codec() const { return vp8_codec_; } | 166 const CodecVector& vp8_codec() const { return vp8_codec_; } |
(...skipping 426 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
578 | 593 |
579 #if defined(WIDEVINE_CDM_AVAILABLE) | 594 #if defined(WIDEVINE_CDM_AVAILABLE) |
580 const char* const kTestWidevineUmaName = "Widevine"; | 595 const char* const kTestWidevineUmaName = "Widevine"; |
581 #else | 596 #else |
582 const char* const kTestWidevineUmaName = "Unknown"; | 597 const char* const kTestWidevineUmaName = "Unknown"; |
583 #endif | 598 #endif |
584 EXPECT_EQ(kTestWidevineUmaName, KeySystemNameForUMA("com.widevine.alpha")); | 599 EXPECT_EQ(kTestWidevineUmaName, KeySystemNameForUMA("com.widevine.alpha")); |
585 } | 600 } |
586 | 601 |
587 } // namespace content | 602 } // namespace content |
OLD | NEW |