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

Side by Side Diff: content/browser/media/encrypted_media_browsertest.cc

Issue 2543623003: media: Allow config change between clear and encrypted streams (Closed)
Patch Set: comments addressed Created 3 years, 10 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
« no previous file with comments | « chrome/browser/media/media_browsertest.cc ('k') | content/browser/media/media_browsertest.h » ('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 (c) 2013 The Chromium Authors. All rights reserved. 1 // Copyright (c) 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 "base/command_line.h" 5 #include "base/command_line.h"
6 #include "base/strings/string_number_conversions.h"
6 #include "base/strings/utf_string_conversions.h" 7 #include "base/strings/utf_string_conversions.h"
7 #include "build/build_config.h" 8 #include "build/build_config.h"
8 #include "content/browser/media/media_browsertest.h" 9 #include "content/browser/media/media_browsertest.h"
9 #include "content/public/common/content_switches.h" 10 #include "content/public/common/content_switches.h"
10 #include "content/public/test/browser_test_utils.h" 11 #include "content/public/test/browser_test_utils.h"
11 #include "content/shell/browser/shell.h" 12 #include "content/shell/browser/shell.h"
12 #include "media/base/media.h" 13 #include "media/base/media.h"
13 #include "media/base/media_switches.h" 14 #include "media/base/media_switches.h"
14 15
15 #if defined(OS_ANDROID) 16 #if defined(OS_ANDROID)
16 #include "base/android/build_info.h" 17 #include "base/android/build_info.h"
17 #endif 18 #endif
18 19
19 #if defined(OS_WIN) 20 #if defined(OS_WIN)
20 #include "base/win/windows_version.h" 21 #include "base/win/windows_version.h"
21 #endif 22 #endif
22 23
23 #if defined(ENABLE_MOJO_CDM) 24 #if defined(ENABLE_MOJO_CDM)
24 // When mojo CDM is enabled, External Clear Key is supported in //content/shell/ 25 // When mojo CDM is enabled, External Clear Key is supported in //content/shell/
25 // by using mojo CDM with AesDecryptor running in the remote (e.g. GPU or 26 // by using mojo CDM with AesDecryptor running in the remote (e.g. GPU or
26 // Browser) process. 27 // Browser) process.
27 // Note that External Clear Key is also supported in chrome/ when pepper CDM is 28 // Note that External Clear Key is also supported in chrome/ when pepper CDM is
28 // used, which is tested in browser_tests. 29 // used, which is tested in browser_tests.
29 #define SUPPORTS_EXTERNAL_CLEAR_KEY_IN_CONTENT_SHELL 30 #define SUPPORTS_EXTERNAL_CLEAR_KEY_IN_CONTENT_SHELL
30 #endif 31 #endif
31 32
33 namespace content {
34
32 // Available key systems. 35 // Available key systems.
33 const char kClearKeyKeySystem[] = "org.w3.clearkey"; 36 const char kClearKeyKeySystem[] = "org.w3.clearkey";
34 37
35 #if defined(SUPPORTS_EXTERNAL_CLEAR_KEY_IN_CONTENT_SHELL) 38 #if defined(SUPPORTS_EXTERNAL_CLEAR_KEY_IN_CONTENT_SHELL)
36 const char kExternalClearKeyKeySystem[] = "org.chromium.externalclearkey"; 39 const char kExternalClearKeyKeySystem[] = "org.chromium.externalclearkey";
37 #endif 40 #endif
38 41
39 // Supported media types. 42 // Supported media types.
40 const char kWebMVorbisAudioOnly[] = "audio/webm; codecs=\"vorbis\""; 43 const char kWebMVorbisAudioOnly[] = "audio/webm; codecs=\"vorbis\"";
41 const char kWebMOpusAudioOnly[] = "audio/webm; codecs=\"opus\""; 44 const char kWebMOpusAudioOnly[] = "audio/webm; codecs=\"opus\"";
42 const char kWebMVP8VideoOnly[] = "video/webm; codecs=\"vp8\""; 45 const char kWebMVP8VideoOnly[] = "video/webm; codecs=\"vp8\"";
43 const char kWebMVP9VideoOnly[] = "video/webm; codecs=\"vp9\""; 46 const char kWebMVP9VideoOnly[] = "video/webm; codecs=\"vp9\"";
44 const char kWebMOpusAudioVP9Video[] = "video/webm; codecs=\"opus, vp9\""; 47 const char kWebMOpusAudioVP9Video[] = "video/webm; codecs=\"opus, vp9\"";
45 const char kWebMVorbisAudioVP8Video[] = "video/webm; codecs=\"vorbis, vp8\""; 48 const char kWebMVorbisAudioVP8Video[] = "video/webm; codecs=\"vorbis, vp8\"";
46 49
47 // EME-specific test results and errors. 50 // EME-specific test results and errors.
48 const char kEmeKeyError[] = "KEYERROR"; 51 const char kEmeKeyError[] = "KEYERROR";
49 const char kEmeNotSupportedError[] = "NOTSUPPORTEDERROR"; 52 const char kEmeNotSupportedError[] = "NOTSUPPORTEDERROR";
50 53
51 const char kDefaultEmePlayer[] = "eme_player.html"; 54 const char kDefaultEmePlayer[] = "eme_player.html";
52 55
53 // The type of video src used to load media. 56 // The type of video src used to load media.
54 enum SrcType { 57 enum class SrcType { SRC, MSE };
55 SRC, 58
56 MSE 59 // Must be in sync with CONFIG_CHANGE_TYPE in eme_player_js/global.js
60 enum class ConfigChangeType {
61 CLEAR_TO_CLEAR = 0,
62 CLEAR_TO_ENCRYPTED = 1,
63 ENCRYPTED_TO_CLEAR = 2,
64 ENCRYPTED_TO_ENCRYPTED = 3,
57 }; 65 };
58 66
59 namespace content {
60
61 // Tests encrypted media playback with a combination of parameters: 67 // Tests encrypted media playback with a combination of parameters:
62 // - char*: Key system name. 68 // - char*: Key system name.
63 // - SrcType: The type of video src used to load media, MSE or SRC. 69 // - SrcType: The type of video src used to load media, MSE or SRC.
64 // It is okay to run this test as a non-parameterized test, in this case, 70 // It is okay to run this test as a non-parameterized test, in this case,
65 // GetParam() should not be called. 71 // GetParam() should not be called.
66 class EncryptedMediaTest : public content::MediaBrowserTest, 72 class EncryptedMediaTest : public MediaBrowserTest,
67 public testing::WithParamInterface<std::tr1::tuple<const char*, SrcType> > { 73 public testing::WithParamInterface<
74 std::tr1::tuple<const char*, SrcType>> {
68 public: 75 public:
69 // Can only be used in parameterized (*_P) tests. 76 // Can only be used in parameterized (*_P) tests.
70 const std::string CurrentKeySystem() { 77 const std::string CurrentKeySystem() {
71 return std::tr1::get<0>(GetParam()); 78 return std::tr1::get<0>(GetParam());
72 } 79 }
73 80
74 // Can only be used in parameterized (*_P) tests. 81 // Can only be used in parameterized (*_P) tests.
75 SrcType CurrentSourceType() { 82 SrcType CurrentSourceType() {
76 return std::tr1::get<1>(GetParam()); 83 return std::tr1::get<1>(GetParam());
77 } 84 }
78 85
79 void TestSimplePlayback(const std::string& encrypted_media, 86 void TestSimplePlayback(const std::string& encrypted_media,
80 const std::string& media_type) { 87 const std::string& media_type) {
81 RunSimpleEncryptedMediaTest( 88 RunSimpleEncryptedMediaTest(
82 encrypted_media, media_type, CurrentKeySystem(), CurrentSourceType()); 89 encrypted_media, media_type, CurrentKeySystem(), CurrentSourceType());
83 } 90 }
84 91
85 void TestFrameSizeChange() { 92 void TestFrameSizeChange() {
86 RunEncryptedMediaTest("encrypted_frame_size_change.html", 93 RunEncryptedMediaTest("encrypted_frame_size_change.html",
87 "frame_size_change-av_enc-v.webm", 94 "frame_size_change-av_enc-v.webm",
88 kWebMVorbisAudioVP8Video, CurrentKeySystem(), 95 kWebMVorbisAudioVP8Video, CurrentKeySystem(),
89 CurrentSourceType(), kEnded); 96 CurrentSourceType(), kEnded);
90 } 97 }
91 98
92 void TestConfigChange() { 99 void TestConfigChange(ConfigChangeType config_change_type) {
100 // TODO(xhwang): Even when config change is not supported we still start
101 // content shell only to return directly here. We probably should not run
102 // these test cases at all.
103 if (CurrentSourceType() != SrcType::MSE) {
104 DVLOG(0) << "Config change only happens when using MSE.";
105 return;
106 }
107
93 base::StringPairs query_params; 108 base::StringPairs query_params;
94 query_params.push_back(std::make_pair("keySystem", CurrentKeySystem())); 109 query_params.push_back(std::make_pair("keySystem", CurrentKeySystem()));
95 query_params.push_back(std::make_pair("runEncrypted", "1")); 110 query_params.push_back(std::make_pair(
111 "configChangeType",
112 base::IntToString(static_cast<int>(config_change_type))));
96 RunMediaTestPage("mse_config_change.html", query_params, kEnded, true); 113 RunMediaTestPage("mse_config_change.html", query_params, kEnded, true);
97 } 114 }
98 115
99 void RunEncryptedMediaTest(const std::string& html_page, 116 void RunEncryptedMediaTest(const std::string& html_page,
100 const std::string& media_file, 117 const std::string& media_file,
101 const std::string& media_type, 118 const std::string& media_type,
102 const std::string& key_system, 119 const std::string& key_system,
103 SrcType src_type, 120 SrcType src_type,
104 const std::string& expectation) { 121 const std::string& expectation) {
105 base::StringPairs query_params; 122 base::StringPairs query_params;
106 query_params.push_back(std::make_pair("mediaFile", media_file)); 123 query_params.push_back(std::make_pair("mediaFile", media_file));
107 query_params.push_back(std::make_pair("mediaType", media_type)); 124 query_params.push_back(std::make_pair("mediaType", media_type));
108 query_params.push_back(std::make_pair("keySystem", key_system)); 125 query_params.push_back(std::make_pair("keySystem", key_system));
109 if (src_type == MSE) 126 if (src_type == SrcType::MSE)
110 query_params.push_back(std::make_pair("useMSE", "1")); 127 query_params.push_back(std::make_pair("useMSE", "1"));
111 RunMediaTestPage(html_page, query_params, expectation, true); 128 RunMediaTestPage(html_page, query_params, expectation, true);
112 } 129 }
113 130
114 void RunSimpleEncryptedMediaTest(const std::string& media_file, 131 void RunSimpleEncryptedMediaTest(const std::string& media_file,
115 const std::string& media_type, 132 const std::string& media_type,
116 const std::string& key_system, 133 const std::string& key_system,
117 SrcType src_type) { 134 SrcType src_type) {
118 RunEncryptedMediaTest(kDefaultEmePlayer, 135 RunEncryptedMediaTest(kDefaultEmePlayer,
119 media_file, 136 media_file,
(...skipping 17 matching lines...) Expand all
137 #if defined(SUPPORTS_EXTERNAL_CLEAR_KEY_IN_CONTENT_SHELL) 154 #if defined(SUPPORTS_EXTERNAL_CLEAR_KEY_IN_CONTENT_SHELL)
138 command_line->AppendSwitchASCII(switches::kEnableFeatures, 155 command_line->AppendSwitchASCII(switches::kEnableFeatures,
139 media::kExternalClearKeyForTesting.name); 156 media::kExternalClearKeyForTesting.name);
140 #endif 157 #endif
141 } 158 }
142 }; 159 };
143 160
144 using ::testing::Combine; 161 using ::testing::Combine;
145 using ::testing::Values; 162 using ::testing::Values;
146 163
147 INSTANTIATE_TEST_CASE_P(SRC_ClearKey, EncryptedMediaTest, 164 INSTANTIATE_TEST_CASE_P(SRC_ClearKey,
148 Combine(Values(kClearKeyKeySystem), Values(SRC))); 165 EncryptedMediaTest,
166 Combine(Values(kClearKeyKeySystem),
167 Values(SrcType::SRC)));
149 168
150 INSTANTIATE_TEST_CASE_P(MSE_ClearKey, EncryptedMediaTest, 169 INSTANTIATE_TEST_CASE_P(MSE_ClearKey,
151 Combine(Values(kClearKeyKeySystem), Values(MSE))); 170 EncryptedMediaTest,
171 Combine(Values(kClearKeyKeySystem),
172 Values(SrcType::MSE)));
152 173
153 #if defined(SUPPORTS_EXTERNAL_CLEAR_KEY_IN_CONTENT_SHELL) 174 #if defined(SUPPORTS_EXTERNAL_CLEAR_KEY_IN_CONTENT_SHELL)
154 INSTANTIATE_TEST_CASE_P(SRC_ExternalClearKey, 175 INSTANTIATE_TEST_CASE_P(SRC_ExternalClearKey,
155 EncryptedMediaTest, 176 EncryptedMediaTest,
156 Combine(Values(kExternalClearKeyKeySystem), 177 Combine(Values(kExternalClearKeyKeySystem),
157 Values(SRC))); 178 Values(SrcType::SRC)));
158 179
159 INSTANTIATE_TEST_CASE_P(MSE_ExternalClearKey, 180 INSTANTIATE_TEST_CASE_P(MSE_ExternalClearKey,
160 EncryptedMediaTest, 181 EncryptedMediaTest,
161 Combine(Values(kExternalClearKeyKeySystem), 182 Combine(Values(kExternalClearKeyKeySystem),
162 Values(MSE))); 183 Values(SrcType::MSE)));
163 #endif 184 #endif
164 185
165 IN_PROC_BROWSER_TEST_P(EncryptedMediaTest, Playback_AudioOnly_WebM) { 186 IN_PROC_BROWSER_TEST_P(EncryptedMediaTest, Playback_AudioOnly_WebM) {
166 TestSimplePlayback("bear-a_enc-a.webm", kWebMVorbisAudioOnly); 187 TestSimplePlayback("bear-a_enc-a.webm", kWebMVorbisAudioOnly);
167 } 188 }
168 189
169 IN_PROC_BROWSER_TEST_P(EncryptedMediaTest, Playback_AudioClearVideo_WebM) { 190 IN_PROC_BROWSER_TEST_P(EncryptedMediaTest, Playback_AudioClearVideo_WebM) {
170 TestSimplePlayback("bear-320x240-av_enc-a.webm", kWebMVorbisAudioVP8Video); 191 TestSimplePlayback("bear-320x240-av_enc-a.webm", kWebMVorbisAudioVP8Video);
171 } 192 }
172 193
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
210 } 231 }
211 232
212 IN_PROC_BROWSER_TEST_P(EncryptedMediaTest, Playback_VideoClearAudio_WebM_Opus) { 233 IN_PROC_BROWSER_TEST_P(EncryptedMediaTest, Playback_VideoClearAudio_WebM_Opus) {
213 #if defined(OS_ANDROID) 234 #if defined(OS_ANDROID)
214 if (!media::PlatformHasOpusSupport()) 235 if (!media::PlatformHasOpusSupport())
215 return; 236 return;
216 #endif 237 #endif
217 TestSimplePlayback("bear-320x240-opus-av_enc-v.webm", kWebMOpusAudioVP9Video); 238 TestSimplePlayback("bear-320x240-opus-av_enc-v.webm", kWebMOpusAudioVP9Video);
218 } 239 }
219 240
220 IN_PROC_BROWSER_TEST_P(EncryptedMediaTest, ConfigChangeVideo) { 241 // Strictly speaking this is not an "encrypted" media test. Keep it here for
221 TestConfigChange(); 242 // completeness.
243 IN_PROC_BROWSER_TEST_P(EncryptedMediaTest, ConfigChangeVideo_ClearToClear) {
244 TestConfigChange(ConfigChangeType::CLEAR_TO_CLEAR);
245 }
246
247 // TODO(xhwang): Support switching from clear to encrypted and enable this test.
248 // See http://crbug.com/597443
249 IN_PROC_BROWSER_TEST_P(EncryptedMediaTest,
250 DISABLED_ConfigChangeVideo_ClearToEncrypted) {
251 TestConfigChange(ConfigChangeType::CLEAR_TO_ENCRYPTED);
252 }
253
254 IN_PROC_BROWSER_TEST_P(EncryptedMediaTest, ConfigChangeVideo_EncryptedToClear) {
255 TestConfigChange(ConfigChangeType::ENCRYPTED_TO_CLEAR);
256 }
257
258 IN_PROC_BROWSER_TEST_P(EncryptedMediaTest,
259 ConfigChangeVideo_EncryptedToEncrypted) {
260 TestConfigChange(ConfigChangeType::ENCRYPTED_TO_ENCRYPTED);
222 } 261 }
223 262
224 IN_PROC_BROWSER_TEST_P(EncryptedMediaTest, FrameSizeChangeVideo) { 263 IN_PROC_BROWSER_TEST_P(EncryptedMediaTest, FrameSizeChangeVideo) {
225 TestFrameSizeChange(); 264 TestFrameSizeChange();
226 } 265 }
227 266
228 IN_PROC_BROWSER_TEST_F(EncryptedMediaTest, UnknownKeySystemThrowsException) { 267 IN_PROC_BROWSER_TEST_F(EncryptedMediaTest, UnknownKeySystemThrowsException) {
229 RunEncryptedMediaTest(kDefaultEmePlayer, "bear-a_enc-a.webm", 268 RunEncryptedMediaTest(kDefaultEmePlayer, "bear-a_enc-a.webm",
230 kWebMVorbisAudioOnly, "com.example.foo", MSE, 269 kWebMVorbisAudioOnly, "com.example.foo", SrcType::MSE,
231 kEmeNotSupportedError); 270 kEmeNotSupportedError);
232 } 271 }
233 272
234 } // namespace content 273 } // namespace content
OLDNEW
« no previous file with comments | « chrome/browser/media/media_browsertest.cc ('k') | content/browser/media/media_browsertest.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698