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 15 matching lines...) Expand all Loading... |
26 #define EXPECT_DEBUG_DEATH_PORTABLE(statement, regex) \ | 26 #define EXPECT_DEBUG_DEATH_PORTABLE(statement, regex) \ |
27 do { statement; } while (false) | 27 do { statement; } while (false) |
28 #else | 28 #else |
29 #include "base/logging.h" | 29 #include "base/logging.h" |
30 #define EXPECT_DEBUG_DEATH_PORTABLE(statement, regex) \ | 30 #define EXPECT_DEBUG_DEATH_PORTABLE(statement, regex) \ |
31 LOG(WARNING) << "Death tests are not supported on this platform.\n" \ | 31 LOG(WARNING) << "Death tests are not supported on this platform.\n" \ |
32 << "Statement '" #statement "' cannot be verified."; | 32 << "Statement '" #statement "' cannot be verified."; |
33 #endif // defined(NDEBUG) | 33 #endif // defined(NDEBUG) |
34 #endif // defined(GTEST_HAS_DEATH_TEST) && !defined(OS_ANDROID) | 34 #endif // defined(GTEST_HAS_DEATH_TEST) && !defined(OS_ANDROID) |
35 | 35 |
| 36 namespace content { |
| 37 |
36 using blink::WebString; | 38 using blink::WebString; |
37 | 39 |
38 // These are the (fake) key systems that are registered for these tests. | 40 // These are the (fake) key systems that are registered for these tests. |
39 // kUsesAes uses the AesDecryptor like Clear Key. | 41 // kUsesAes uses the AesDecryptor like Clear Key. |
40 // kExternal uses an external CDM, such as Pepper-based or Android platform CDM. | 42 // kExternal uses an external CDM, such as Pepper-based or Android platform CDM. |
41 const char kUsesAes[] = "org.example.clear"; | 43 const char kUsesAes[] = "org.example.clear"; |
42 const char kUsesAesParent[] = "org.example"; // Not registered. | 44 const char kUsesAesParent[] = "org.example"; // Not registered. |
43 const char kExternal[] = "com.example.test"; | 45 const char kExternal[] = "com.example.test"; |
44 const char kExternalParent[] = "com.example"; | 46 const char kExternalParent[] = "com.example"; |
45 | 47 |
46 const char kClearKey[] = "org.w3.clearkey"; | 48 const char kClearKey[] = "org.w3.clearkey"; |
47 const char kPrefixedClearKey[] = "webkit-org.w3.clearkey"; | 49 const char kPrefixedClearKey[] = "webkit-org.w3.clearkey"; |
48 const char kExternalClearKey[] = "org.chromium.externalclearkey"; | 50 const char kExternalClearKey[] = "org.chromium.externalclearkey"; |
49 | 51 |
50 const char kAudioWebM[] = "audio/webm"; | 52 const char kAudioWebM[] = "audio/webm"; |
51 const char kVideoWebM[] = "video/webm"; | 53 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"; | 54 const char kAudioFoo[] = "audio/foo"; |
57 const char kVideoFoo[] = "video/foo"; | 55 const char kVideoFoo[] = "video/foo"; |
58 const char kFooAudioCodec[] = "fooaudio"; | |
59 const char kFooVideoCodec[] = "foovideo"; | |
60 | 56 |
61 namespace content { | 57 // Pick some arbitrary bit fields as long as they are not in conflict with the |
| 58 // real ones. |
| 59 enum TestCodecMask { |
| 60 FOO_AUDIO = 1 << 10, // An audio codec for foo container. |
| 61 FOO_AUDIO_CODECS = FOO_AUDIO, |
| 62 FOO_VIDEO = 1 << 11, // A video codec for foo container. |
| 63 FOO_VIDEO_CODECS = FOO_VIDEO, |
| 64 FOO_ALL_CODECS = FOO_AUDIO_CODECS | FOO_VIDEO_CODECS |
| 65 }; |
| 66 |
| 67 COMPILE_ASSERT((FOO_ALL_CODECS & ALL_CODECS) == NO_CODECS, |
| 68 test_codec_masks_should_only_use_invalid_codec_masks); |
| 69 |
| 70 // Adds test container and codec masks. |
| 71 // This function must be called after SetContentClient() is called. |
| 72 // More details: AddXxxMask() will create KeySystems if it hasn't been created. |
| 73 // During KeySystems's construction GetContentClient() will be used to add key |
| 74 // systems. In test code, the content client is set by SetContentClient(). |
| 75 // Therefore, SetContentClient() must be called before this function to avoid |
| 76 // access violation. |
| 77 static void AddContainerAndCodecMasksForTest() { |
| 78 // Since KeySystems is a singleton. Make sure we only add test container and |
| 79 // codec masks once per process. |
| 80 static bool is_test_masks_added = false; |
| 81 |
| 82 if (is_test_masks_added) |
| 83 return; |
| 84 |
| 85 AddContainerMask("audio/foo", FOO_AUDIO_CODECS); |
| 86 AddContainerMask("video/foo", FOO_ALL_CODECS); |
| 87 AddCodecMask("fooaudio", FOO_AUDIO); |
| 88 AddCodecMask("foovideo", FOO_VIDEO); |
| 89 |
| 90 is_test_masks_added = true; |
| 91 } |
62 | 92 |
63 class TestContentRendererClient : public ContentRendererClient { | 93 class TestContentRendererClient : public ContentRendererClient { |
64 virtual void AddKeySystems( | 94 virtual void AddKeySystems( |
65 std::vector<content::KeySystemInfo>* key_systems) OVERRIDE; | 95 std::vector<content::KeySystemInfo>* key_systems) OVERRIDE; |
66 }; | 96 }; |
67 | 97 |
68 void TestContentRendererClient::AddKeySystems( | 98 void TestContentRendererClient::AddKeySystems( |
69 std::vector<content::KeySystemInfo>* key_systems) { | 99 std::vector<content::KeySystemInfo>* key_systems) { |
70 KeySystemInfo aes(kUsesAes); | 100 KeySystemInfo aes(kUsesAes); |
71 | 101 aes.supported_codecs = WEBM_ALL_CODECS; |
72 aes.supported_types[kAudioWebM].insert(kVorbis); | 102 aes.supported_codecs |= FOO_ALL_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; | 103 aes.use_aes_decryptor = true; |
81 | |
82 key_systems->push_back(aes); | 104 key_systems->push_back(aes); |
83 | 105 |
84 KeySystemInfo ext(kExternal); | 106 KeySystemInfo ext(kExternal); |
85 | 107 ext.supported_codecs = WEBM_ALL_CODECS; |
86 ext.supported_types[kAudioWebM].insert(kVorbis); | 108 ext.supported_codecs |= FOO_ALL_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; | 109 ext.parent_key_system = kExternalParent; |
95 | |
96 #if defined(ENABLE_PEPPER_CDMS) | 110 #if defined(ENABLE_PEPPER_CDMS) |
97 ext.pepper_type = "application/x-ppapi-external-cdm"; | 111 ext.pepper_type = "application/x-ppapi-external-cdm"; |
98 #endif // defined(ENABLE_PEPPER_CDMS) | 112 #endif // defined(ENABLE_PEPPER_CDMS) |
99 | |
100 key_systems->push_back(ext); | 113 key_systems->push_back(ext); |
101 } | 114 } |
102 | 115 |
103 class KeySystemsTest : public testing::Test { | 116 class KeySystemsTest : public testing::Test { |
104 protected: | 117 protected: |
105 KeySystemsTest() { | 118 KeySystemsTest() { |
106 vp8_codec_.push_back("vp8"); | 119 vp8_codec_.push_back("vp8"); |
107 | 120 |
108 vp80_codec_.push_back("vp8.0"); | 121 vp80_codec_.push_back("vp8.0"); |
109 | 122 |
(...skipping 22 matching lines...) Expand all Loading... |
132 // The TestContentClient is not available inside Death Tests on some | 145 // The TestContentClient is not available inside Death Tests on some |
133 // platforms (see below). Therefore, always provide a TestContentClient. | 146 // platforms (see below). Therefore, always provide a TestContentClient. |
134 // Explanation: When Death Tests fork, there is a valid ContentClient. | 147 // Explanation: When Death Tests fork, there is a valid ContentClient. |
135 // However, when they launch a new process instead of forking, the global | 148 // However, when they launch a new process instead of forking, the global |
136 // variable is not copied and for some reason TestContentClientInitializer | 149 // variable is not copied and for some reason TestContentClientInitializer |
137 // does not get created to set the global variable in the new process. | 150 // does not get created to set the global variable in the new process. |
138 SetContentClient(&test_content_client_); | 151 SetContentClient(&test_content_client_); |
139 SetRendererClientForTesting(&content_renderer_client_); | 152 SetRendererClientForTesting(&content_renderer_client_); |
140 } | 153 } |
141 | 154 |
| 155 virtual void SetUp() OVERRIDE { |
| 156 AddContainerAndCodecMasksForTest(); |
| 157 } |
| 158 |
142 virtual ~KeySystemsTest() { | 159 virtual ~KeySystemsTest() { |
143 // Clear the use of content_client_, which was set in SetUp(). | 160 // Clear the use of content_client_, which was set in SetUp(). |
144 SetContentClient(NULL); | 161 SetContentClient(NULL); |
145 } | 162 } |
146 | 163 |
147 typedef std::vector<std::string> CodecVector; | 164 typedef std::vector<std::string> CodecVector; |
148 | 165 |
149 const CodecVector& no_codecs() const { return no_codecs_; } | 166 const CodecVector& no_codecs() const { return no_codecs_; } |
150 | 167 |
151 const CodecVector& vp8_codec() const { return vp8_codec_; } | 168 const CodecVector& vp8_codec() const { return vp8_codec_; } |
(...skipping 426 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
578 | 595 |
579 #if defined(WIDEVINE_CDM_AVAILABLE) | 596 #if defined(WIDEVINE_CDM_AVAILABLE) |
580 const char* const kTestWidevineUmaName = "Widevine"; | 597 const char* const kTestWidevineUmaName = "Widevine"; |
581 #else | 598 #else |
582 const char* const kTestWidevineUmaName = "Unknown"; | 599 const char* const kTestWidevineUmaName = "Unknown"; |
583 #endif | 600 #endif |
584 EXPECT_EQ(kTestWidevineUmaName, KeySystemNameForUMA("com.widevine.alpha")); | 601 EXPECT_EQ(kTestWidevineUmaName, KeySystemNameForUMA("com.widevine.alpha")); |
585 } | 602 } |
586 | 603 |
587 } // namespace content | 604 } // namespace content |
OLD | NEW |