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