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

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

Issue 665343002: Move KeySystemInfo to media. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: rebase only Created 6 years, 1 month 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
« no previous file with comments | « content/renderer/media/crypto/key_systems.cc ('k') | media/base/BUILD.gn » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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/common/eme_constants.h"
10 #include "content/public/renderer/content_renderer_client.h" 9 #include "content/public/renderer/content_renderer_client.h"
11 #include "content/public/renderer/key_system_info.h"
12 #include "content/renderer/media/crypto/key_systems.h" 10 #include "content/renderer/media/crypto/key_systems.h"
13 #include "content/test/test_content_client.h" 11 #include "content/test/test_content_client.h"
12 #include "media/base/eme_constants.h"
13 #include "media/base/key_system_info.h"
14 #include "testing/gtest/include/gtest/gtest.h" 14 #include "testing/gtest/include/gtest/gtest.h"
15 #include "third_party/WebKit/public/platform/WebString.h" 15 #include "third_party/WebKit/public/platform/WebString.h"
16 16
17 #include "widevine_cdm_version.h" // In SHARED_INTERMEDIATE_DIR. 17 #include "widevine_cdm_version.h" // In SHARED_INTERMEDIATE_DIR.
18 18
19 // Death tests are not always available, including on Android. 19 // Death tests are not always available, including on Android.
20 // EXPECT_DEBUG_DEATH_PORTABLE executes tests correctly except in the case that 20 // EXPECT_DEBUG_DEATH_PORTABLE executes tests correctly except in the case that
21 // death tests are not available and NDEBUG is not defined. 21 // death tests are not available and NDEBUG is not defined.
22 #if defined(GTEST_HAS_DEATH_TEST) && !defined(OS_ANDROID) 22 #if defined(GTEST_HAS_DEATH_TEST) && !defined(OS_ANDROID)
23 #define EXPECT_DEBUG_DEATH_PORTABLE(statement, regex) \ 23 #define EXPECT_DEBUG_DEATH_PORTABLE(statement, regex) \
24 EXPECT_DEBUG_DEATH(statement, regex) 24 EXPECT_DEBUG_DEATH(statement, regex)
25 #else 25 #else
26 #if defined(NDEBUG) 26 #if defined(NDEBUG)
27 #define EXPECT_DEBUG_DEATH_PORTABLE(statement, regex) \ 27 #define EXPECT_DEBUG_DEATH_PORTABLE(statement, regex) \
28 do { statement; } while (false) 28 do { statement; } while (false)
29 #else 29 #else
30 #include "base/logging.h" 30 #include "base/logging.h"
31 #define EXPECT_DEBUG_DEATH_PORTABLE(statement, regex) \ 31 #define EXPECT_DEBUG_DEATH_PORTABLE(statement, regex) \
32 LOG(WARNING) << "Death tests are not supported on this platform.\n" \ 32 LOG(WARNING) << "Death tests are not supported on this platform.\n" \
33 << "Statement '" #statement "' cannot be verified."; 33 << "Statement '" #statement "' cannot be verified.";
34 #endif // defined(NDEBUG) 34 #endif // defined(NDEBUG)
35 #endif // defined(GTEST_HAS_DEATH_TEST) && !defined(OS_ANDROID) 35 #endif // defined(GTEST_HAS_DEATH_TEST) && !defined(OS_ANDROID)
36 36
37 namespace content { 37 namespace content {
38 38
39 using blink::WebString; 39 using blink::WebString;
40 using media::KeySystemInfo;
40 41
41 // These are the (fake) key systems that are registered for these tests. 42 // These are the (fake) key systems that are registered for these tests.
42 // kUsesAes uses the AesDecryptor like Clear Key. 43 // kUsesAes uses the AesDecryptor like Clear Key.
43 // kExternal uses an external CDM, such as Pepper-based or Android platform CDM. 44 // kExternal uses an external CDM, such as Pepper-based or Android platform CDM.
44 const char kUsesAes[] = "org.example.clear"; 45 const char kUsesAes[] = "org.example.clear";
45 const char kUsesAesParent[] = "org.example"; // Not registered. 46 const char kUsesAesParent[] = "org.example"; // Not registered.
46 const char kExternal[] = "com.example.test"; 47 const char kExternal[] = "com.example.test";
47 const char kExternalParent[] = "com.example"; 48 const char kExternalParent[] = "com.example";
48 49
49 const char kClearKey[] = "org.w3.clearkey"; 50 const char kClearKey[] = "org.w3.clearkey";
50 const char kPrefixedClearKey[] = "webkit-org.w3.clearkey"; 51 const char kPrefixedClearKey[] = "webkit-org.w3.clearkey";
51 const char kExternalClearKey[] = "org.chromium.externalclearkey"; 52 const char kExternalClearKey[] = "org.chromium.externalclearkey";
52 53
53 const char kAudioWebM[] = "audio/webm"; 54 const char kAudioWebM[] = "audio/webm";
54 const char kVideoWebM[] = "video/webm"; 55 const char kVideoWebM[] = "video/webm";
55 const char kAudioFoo[] = "audio/foo"; 56 const char kAudioFoo[] = "audio/foo";
56 const char kVideoFoo[] = "video/foo"; 57 const char kVideoFoo[] = "video/foo";
57 58
58 // Pick some arbitrary bit fields as long as they are not in conflict with the 59 // Pick some arbitrary bit fields as long as they are not in conflict with the
59 // real ones. 60 // real ones.
60 enum TestCodec { 61 enum TestCodec {
61 TEST_CODEC_FOO_AUDIO = 1 << 10, // An audio codec for foo container. 62 TEST_CODEC_FOO_AUDIO = 1 << 10, // An audio codec for foo container.
62 TEST_CODEC_FOO_AUDIO_ALL = TEST_CODEC_FOO_AUDIO, 63 TEST_CODEC_FOO_AUDIO_ALL = TEST_CODEC_FOO_AUDIO,
63 TEST_CODEC_FOO_VIDEO = 1 << 11, // A video codec for foo container. 64 TEST_CODEC_FOO_VIDEO = 1 << 11, // A video codec for foo container.
64 TEST_CODEC_FOO_VIDEO_ALL = TEST_CODEC_FOO_VIDEO, 65 TEST_CODEC_FOO_VIDEO_ALL = TEST_CODEC_FOO_VIDEO,
65 TEST_CODEC_FOO_ALL = TEST_CODEC_FOO_AUDIO_ALL | TEST_CODEC_FOO_VIDEO_ALL 66 TEST_CODEC_FOO_ALL = TEST_CODEC_FOO_AUDIO_ALL | TEST_CODEC_FOO_VIDEO_ALL
66 }; 67 };
67 68
68 COMPILE_ASSERT((TEST_CODEC_FOO_ALL & EME_CODEC_ALL) == EME_CODEC_NONE, 69 COMPILE_ASSERT((TEST_CODEC_FOO_ALL & media::EME_CODEC_ALL) ==
69 test_codec_masks_should_only_use_invalid_codec_masks); 70 media::EME_CODEC_NONE,
71 test_codec_masks_should_only_use_invalid_codec_masks);
70 72
71 // Adds test container and codec masks. 73 // Adds test container and codec masks.
72 // This function must be called after SetContentClient() is called. 74 // This function must be called after SetContentClient() is called.
73 // More details: AddXxxMask() will create KeySystems if it hasn't been created. 75 // More details: AddXxxMask() will create KeySystems if it hasn't been created.
74 // During KeySystems's construction GetContentClient() will be used to add key 76 // During KeySystems's construction GetContentClient() will be used to add key
75 // systems. In test code, the content client is set by SetContentClient(). 77 // systems. In test code, the content client is set by SetContentClient().
76 // Therefore, SetContentClient() must be called before this function to avoid 78 // Therefore, SetContentClient() must be called before this function to avoid
77 // access violation. 79 // access violation.
78 static void AddContainerAndCodecMasksForTest() { 80 static void AddContainerAndCodecMasksForTest() {
79 // Since KeySystems is a singleton. Make sure we only add test container and 81 // Since KeySystems is a singleton. Make sure we only add test container and
80 // codec masks once per process. 82 // codec masks once per process.
81 static bool is_test_masks_added = false; 83 static bool is_test_masks_added = false;
82 84
83 if (is_test_masks_added) 85 if (is_test_masks_added)
84 return; 86 return;
85 87
86 AddContainerMask("audio/foo", TEST_CODEC_FOO_AUDIO_ALL); 88 AddContainerMask("audio/foo", TEST_CODEC_FOO_AUDIO_ALL);
87 AddContainerMask("video/foo", TEST_CODEC_FOO_ALL); 89 AddContainerMask("video/foo", TEST_CODEC_FOO_ALL);
88 AddCodecMask("fooaudio", TEST_CODEC_FOO_AUDIO); 90 AddCodecMask("fooaudio", TEST_CODEC_FOO_AUDIO);
89 AddCodecMask("foovideo", TEST_CODEC_FOO_VIDEO); 91 AddCodecMask("foovideo", TEST_CODEC_FOO_VIDEO);
90 92
91 is_test_masks_added = true; 93 is_test_masks_added = true;
92 } 94 }
93 95
94 class TestContentRendererClient : public ContentRendererClient { 96 class TestContentRendererClient : public ContentRendererClient {
95 void AddKeySystems(std::vector<content::KeySystemInfo>* key_systems) override; 97 void AddKeySystems(std::vector<media::KeySystemInfo>* key_systems) override;
96 }; 98 };
97 99
98 void TestContentRendererClient::AddKeySystems( 100 void TestContentRendererClient::AddKeySystems(
99 std::vector<content::KeySystemInfo>* key_systems) { 101 std::vector<media::KeySystemInfo>* key_systems) {
100 KeySystemInfo aes(kUsesAes); 102 KeySystemInfo aes(kUsesAes);
101 aes.supported_codecs = EME_CODEC_WEBM_ALL; 103 aes.supported_codecs = media::EME_CODEC_WEBM_ALL;
102 aes.supported_codecs |= TEST_CODEC_FOO_ALL; 104 aes.supported_codecs |= TEST_CODEC_FOO_ALL;
103 aes.supported_init_data_types = EME_INIT_DATA_TYPE_WEBM; 105 aes.supported_init_data_types = media::EME_INIT_DATA_TYPE_WEBM;
104 aes.use_aes_decryptor = true; 106 aes.use_aes_decryptor = true;
105 key_systems->push_back(aes); 107 key_systems->push_back(aes);
106 108
107 KeySystemInfo ext(kExternal); 109 KeySystemInfo ext(kExternal);
108 ext.supported_codecs = EME_CODEC_WEBM_ALL; 110 ext.supported_codecs = media::EME_CODEC_WEBM_ALL;
109 ext.supported_codecs |= TEST_CODEC_FOO_ALL; 111 ext.supported_codecs |= TEST_CODEC_FOO_ALL;
110 ext.supported_init_data_types = EME_INIT_DATA_TYPE_WEBM; 112 ext.supported_init_data_types = media::EME_INIT_DATA_TYPE_WEBM;
111 ext.parent_key_system = kExternalParent; 113 ext.parent_key_system = kExternalParent;
112 #if defined(ENABLE_PEPPER_CDMS) 114 #if defined(ENABLE_PEPPER_CDMS)
113 ext.pepper_type = "application/x-ppapi-external-cdm"; 115 ext.pepper_type = "application/x-ppapi-external-cdm";
114 #endif // defined(ENABLE_PEPPER_CDMS) 116 #endif // defined(ENABLE_PEPPER_CDMS)
115 key_systems->push_back(ext); 117 key_systems->push_back(ext);
116 } 118 }
117 119
118 // TODO(sandersd): Refactor. http://crbug.com/417444 120 // TODO(sandersd): Refactor. http://crbug.com/417444
119 class KeySystemsTest : public testing::Test { 121 class KeySystemsTest : public testing::Test {
120 protected: 122 protected:
(...skipping 519 matching lines...) Expand 10 before | Expand all | Expand 10 after
640 642
641 #if defined(WIDEVINE_CDM_AVAILABLE) 643 #if defined(WIDEVINE_CDM_AVAILABLE)
642 const char* const kTestWidevineUmaName = "Widevine"; 644 const char* const kTestWidevineUmaName = "Widevine";
643 #else 645 #else
644 const char* const kTestWidevineUmaName = "Unknown"; 646 const char* const kTestWidevineUmaName = "Unknown";
645 #endif 647 #endif
646 EXPECT_EQ(kTestWidevineUmaName, KeySystemNameForUMA("com.widevine.alpha")); 648 EXPECT_EQ(kTestWidevineUmaName, KeySystemNameForUMA("com.widevine.alpha"));
647 } 649 }
648 650
649 } // namespace content 651 } // namespace content
OLDNEW
« no previous file with comments | « content/renderer/media/crypto/key_systems.cc ('k') | media/base/BUILD.gn » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698