| OLD | NEW |
| 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/path_service.h" | 6 #include "base/path_service.h" |
| 7 #include "base/strings/utf_string_conversions.h" | 7 #include "base/strings/utf_string_conversions.h" |
| 8 #include "base/win/windows_version.h" | 8 #include "base/win/windows_version.h" |
| 9 #include "content/browser/media/media_browsertest.h" | 9 #include "content/browser/media/media_browsertest.h" |
| 10 #include "content/public/common/content_switches.h" | 10 #include "content/public/common/content_switches.h" |
| 11 #include "content/public/test/browser_test_utils.h" | 11 #include "content/public/test/browser_test_utils.h" |
| 12 #include "content/shell/browser/shell.h" | 12 #include "content/shell/browser/shell.h" |
| 13 #if defined(OS_ANDROID) | 13 #if defined(OS_ANDROID) |
| 14 #include "base/android/build_info.h" | 14 #include "base/android/build_info.h" |
| 15 #endif | 15 #endif |
| 16 | 16 |
| 17 // Available key systems. | 17 // Available key systems. |
| 18 const char kClearKeyKeySystem[] = "webkit-org.w3.clearkey"; | 18 const char kClearKeyKeySystem[] = "webkit-org.w3.clearkey"; |
| 19 | 19 |
| 20 // Supported media types. | 20 // Supported media types. |
| 21 const char kWebMAudioOnly[] = "audio/webm; codecs=\"vorbis\""; | 21 const char kWebMAudioOnly[] = "audio/webm; codecs=\"vorbis\""; |
| 22 const char kWebMVideoOnly[] = "video/webm; codecs=\"vp8\""; | 22 const char kWebMVideoOnly[] = "video/webm; codecs=\"vp8\""; |
| 23 const char kWebMAudioVideo[] = "video/webm; codecs=\"vorbis, vp8\""; | 23 const char kWebMAudioVideo[] = "video/webm; codecs=\"vorbis, vp8\""; |
| 24 | 24 |
| 25 // EME-specific test results and errors. | 25 // EME-specific test results and errors. |
| 26 const char kEmeKeyError[] = "KEYERROR"; | 26 const char kEmeKeyError[] = "KEYERROR"; |
| 27 const char kEmeNotSupportedError[] = "NOTSUPPORTEDERROR"; | 27 const char kEmeNotSupportedError[] = "NOTSUPPORTEDERROR"; |
| 28 | 28 |
| 29 const char kDefaultEmePlayer[] = "eme_player.html"; |
| 30 |
| 29 // The type of video src used to load media. | 31 // The type of video src used to load media. |
| 30 enum SrcType { | 32 enum SrcType { |
| 31 SRC, | 33 SRC, |
| 32 MSE | 34 MSE |
| 33 }; | 35 }; |
| 34 | 36 |
| 35 namespace content { | 37 namespace content { |
| 36 | 38 |
| 37 // MSE is available on all desktop platforms and on Android 4.1 and later. | 39 // MSE is available on all desktop platforms and on Android 4.1 and later. |
| 38 static bool IsMSESupported() { | 40 static bool IsMSESupported() { |
| 39 #if defined(OS_ANDROID) | 41 #if defined(OS_ANDROID) |
| 40 if (base::android::BuildInfo::GetInstance()->sdk_int() < 16) { | 42 if (base::android::BuildInfo::GetInstance()->sdk_int() < 16) { |
| 41 VLOG(0) << "MSE is only supported in Android 4.1 and later."; | 43 VLOG(0) << "MSE is only supported in Android 4.1 and later."; |
| 42 return false; | 44 return false; |
| 43 } | 45 } |
| 44 #endif // defined(OS_ANDROID) | 46 #endif // defined(OS_ANDROID) |
| 45 return true; | 47 return true; |
| 46 } | 48 } |
| 47 | 49 |
| 48 // Tests encrypted media playback with a combination of parameters: | 50 // Tests encrypted media playback with a combination of parameters: |
| 49 // - char*: Key system name. | 51 // - char*: Key system name. |
| 50 // - bool: True to load media using MSE, otherwise use src. | 52 // - bool: True to load media using MSE, otherwise use src. |
| 51 class EncryptedMediaTest : public content::MediaBrowserTest, | 53 class EncryptedMediaTest : public content::MediaBrowserTest, |
| 52 public testing::WithParamInterface<std::tr1::tuple<const char*, SrcType> > { | 54 public testing::WithParamInterface<std::tr1::tuple<const char*, SrcType> > { |
| 53 public: | 55 public: |
| 54 // Can only be used in parameterized (*_P) tests. | 56 // Can only be used in parameterized (*_P) tests. |
| 55 const char* CurrentKeySystem() { | 57 const std::string CurrentKeySystem() { |
| 56 return std::tr1::get<0>(GetParam()); | 58 return std::tr1::get<0>(GetParam()); |
| 57 } | 59 } |
| 58 | 60 |
| 59 // Can only be used in parameterized (*_P) tests. | 61 // Can only be used in parameterized (*_P) tests. |
| 60 SrcType CurrentSourceType() { | 62 SrcType CurrentSourceType() { |
| 61 return std::tr1::get<1>(GetParam()); | 63 return std::tr1::get<1>(GetParam()); |
| 62 } | 64 } |
| 63 | 65 |
| 64 void TestSimplePlayback(const char* encrypted_media, const char* media_type) { | 66 void TestSimplePlayback(const std::string& encrypted_media, |
| 67 const std::string& media_type) { |
| 65 RunSimpleEncryptedMediaTest( | 68 RunSimpleEncryptedMediaTest( |
| 66 encrypted_media, media_type, CurrentKeySystem(), CurrentSourceType()); | 69 encrypted_media, media_type, CurrentKeySystem(), CurrentSourceType()); |
| 67 } | 70 } |
| 68 | 71 |
| 69 void TestFrameSizeChange() { | 72 void TestFrameSizeChange() { |
| 70 RunEncryptedMediaTest("encrypted_frame_size_change.html", | 73 RunEncryptedMediaTest("encrypted_frame_size_change.html", |
| 71 "frame_size_change-av-enc-v.webm", kWebMAudioVideo, | 74 "frame_size_change-av_enc-v.webm", kWebMAudioVideo, |
| 72 CurrentKeySystem(), CurrentSourceType(), kEnded); | 75 CurrentKeySystem(), CurrentSourceType(), kEnded); |
| 73 } | 76 } |
| 74 | 77 |
| 75 void TestConfigChange() { | 78 void TestConfigChange() { |
| 76 if (CurrentSourceType() != MSE || !IsMSESupported()) { | 79 if (CurrentSourceType() != MSE || !IsMSESupported()) { |
| 77 VLOG(0) << "Skipping test - config change test requires MSE."; | 80 VLOG(0) << "Skipping test - config change test requires MSE."; |
| 78 return; | 81 return; |
| 79 } | 82 } |
| 80 | 83 |
| 81 std::vector<StringPair> query_params; | 84 std::vector<StringPair> query_params; |
| 82 query_params.push_back(std::make_pair("keysystem", CurrentKeySystem())); | 85 query_params.push_back(std::make_pair("keySystem", CurrentKeySystem())); |
| 83 query_params.push_back(std::make_pair("runencrypted", "1")); | 86 query_params.push_back(std::make_pair("runEncrypted", "1")); |
| 84 RunMediaTestPage("mse_config_change.html", &query_params, kEnded, true); | 87 RunMediaTestPage("mse_config_change.html", &query_params, kEnded, true); |
| 85 } | 88 } |
| 86 | 89 |
| 87 void RunEncryptedMediaTest(const char* html_page, | 90 void RunEncryptedMediaTest(const std::string& html_page, |
| 88 const char* media_file, | 91 const std::string& media_file, |
| 89 const char* media_type, | 92 const std::string& media_type, |
| 90 const char* key_system, | 93 const std::string& key_system, |
| 91 SrcType src_type, | 94 SrcType src_type, |
| 92 const char* expectation) { | 95 const std::string& expectation) { |
| 93 if (src_type == MSE && !IsMSESupported()) { | 96 if (src_type == MSE && !IsMSESupported()) { |
| 94 VLOG(0) << "Skipping test - MSE not supported."; | 97 VLOG(0) << "Skipping test - MSE not supported."; |
| 95 return; | 98 return; |
| 96 } | 99 } |
| 97 | 100 |
| 98 std::vector<StringPair> query_params; | 101 std::vector<StringPair> query_params; |
| 99 query_params.push_back(std::make_pair("mediafile", media_file)); | 102 query_params.push_back(std::make_pair("mediaFile", media_file)); |
| 100 query_params.push_back(std::make_pair("mediatype", media_type)); | 103 query_params.push_back(std::make_pair("mediaType", media_type)); |
| 101 query_params.push_back(std::make_pair("keysystem", key_system)); | 104 query_params.push_back(std::make_pair("keySystem", key_system)); |
| 102 if (src_type == MSE) | 105 if (src_type == MSE) |
| 103 query_params.push_back(std::make_pair("usemse", "1")); | 106 query_params.push_back(std::make_pair("useMSE", "1")); |
| 104 RunMediaTestPage(html_page, &query_params, expectation, true); | 107 RunMediaTestPage(html_page, &query_params, expectation, true); |
| 105 } | 108 } |
| 106 | 109 |
| 107 void RunSimpleEncryptedMediaTest(const char* media_file, | 110 void RunSimpleEncryptedMediaTest(const std::string& media_file, |
| 108 const char* media_type, | 111 const std::string& media_type, |
| 109 const char* key_system, | 112 const std::string& key_system, |
| 110 SrcType src_type) { | 113 SrcType src_type) { |
| 111 RunEncryptedMediaTest("encrypted_media_player.html", media_file, | 114 RunEncryptedMediaTest(kDefaultEmePlayer, |
| 112 media_type, key_system, src_type, kEnded); | 115 media_file, |
| 116 media_type, |
| 117 key_system, |
| 118 src_type, |
| 119 kEnded); |
| 113 } | 120 } |
| 114 | 121 |
| 115 protected: | 122 protected: |
| 116 // We want to fail quickly when a test fails because an error is encountered. | 123 // We want to fail quickly when a test fails because an error is encountered. |
| 117 virtual void AddWaitForTitles(content::TitleWatcher* title_watcher) OVERRIDE { | 124 virtual void AddWaitForTitles(content::TitleWatcher* title_watcher) OVERRIDE { |
| 118 MediaBrowserTest::AddWaitForTitles(title_watcher); | 125 MediaBrowserTest::AddWaitForTitles(title_watcher); |
| 119 title_watcher->AlsoWaitForTitle(base::ASCIIToUTF16(kEmeNotSupportedError)); | 126 title_watcher->AlsoWaitForTitle(base::ASCIIToUTF16(kEmeNotSupportedError)); |
| 120 title_watcher->AlsoWaitForTitle(base::ASCIIToUTF16(kEmeKeyError)); | 127 title_watcher->AlsoWaitForTitle(base::ASCIIToUTF16(kEmeKeyError)); |
| 121 } | 128 } |
| 122 | 129 |
| (...skipping 11 matching lines...) Expand all Loading... |
| 134 #if !defined(OS_ANDROID) | 141 #if !defined(OS_ANDROID) |
| 135 // Encrypted media playback with SRC is not supported on Android. | 142 // Encrypted media playback with SRC is not supported on Android. |
| 136 INSTANTIATE_TEST_CASE_P(SRC_ClearKey, EncryptedMediaTest, | 143 INSTANTIATE_TEST_CASE_P(SRC_ClearKey, EncryptedMediaTest, |
| 137 Combine(Values(kClearKeyKeySystem), Values(SRC))); | 144 Combine(Values(kClearKeyKeySystem), Values(SRC))); |
| 138 #endif // !defined(OS_ANDROID) | 145 #endif // !defined(OS_ANDROID) |
| 139 | 146 |
| 140 INSTANTIATE_TEST_CASE_P(MSE_ClearKey, EncryptedMediaTest, | 147 INSTANTIATE_TEST_CASE_P(MSE_ClearKey, EncryptedMediaTest, |
| 141 Combine(Values(kClearKeyKeySystem), Values(MSE))); | 148 Combine(Values(kClearKeyKeySystem), Values(MSE))); |
| 142 | 149 |
| 143 IN_PROC_BROWSER_TEST_P(EncryptedMediaTest, Playback_AudioOnly_WebM) { | 150 IN_PROC_BROWSER_TEST_P(EncryptedMediaTest, Playback_AudioOnly_WebM) { |
| 144 TestSimplePlayback("bear-a-enc_a.webm", kWebMAudioOnly); | 151 TestSimplePlayback("bear-a_enc-a.webm", kWebMAudioOnly); |
| 145 } | 152 } |
| 146 | 153 |
| 147 IN_PROC_BROWSER_TEST_P(EncryptedMediaTest, Playback_AudioClearVideo_WebM) { | 154 IN_PROC_BROWSER_TEST_P(EncryptedMediaTest, Playback_AudioClearVideo_WebM) { |
| 148 TestSimplePlayback("bear-320x240-av-enc_a.webm", kWebMAudioVideo); | 155 TestSimplePlayback("bear-320x240-av_enc-a.webm", kWebMAudioVideo); |
| 149 } | 156 } |
| 150 | 157 |
| 151 IN_PROC_BROWSER_TEST_P(EncryptedMediaTest, Playback_VideoAudio_WebM) { | 158 IN_PROC_BROWSER_TEST_P(EncryptedMediaTest, Playback_VideoAudio_WebM) { |
| 152 TestSimplePlayback("bear-320x240-av-enc_av.webm", kWebMAudioVideo); | 159 TestSimplePlayback("bear-320x240-av_enc-av.webm", kWebMAudioVideo); |
| 153 } | 160 } |
| 154 | 161 |
| 155 IN_PROC_BROWSER_TEST_P(EncryptedMediaTest, Playback_VideoOnly_WebM) { | 162 IN_PROC_BROWSER_TEST_P(EncryptedMediaTest, Playback_VideoOnly_WebM) { |
| 156 TestSimplePlayback("bear-320x240-v-enc_v.webm", kWebMVideoOnly); | 163 TestSimplePlayback("bear-320x240-v_enc-v.webm", kWebMVideoOnly); |
| 157 } | 164 } |
| 158 | 165 |
| 159 IN_PROC_BROWSER_TEST_P(EncryptedMediaTest, Playback_VideoClearAudio_WebM) { | 166 IN_PROC_BROWSER_TEST_P(EncryptedMediaTest, Playback_VideoClearAudio_WebM) { |
| 160 TestSimplePlayback("bear-320x240-av-enc_v.webm", kWebMAudioVideo); | 167 TestSimplePlayback("bear-320x240-av_enc-v.webm", kWebMAudioVideo); |
| 161 } | 168 } |
| 162 | 169 |
| 163 IN_PROC_BROWSER_TEST_P(EncryptedMediaTest, ConfigChangeVideo) { | 170 IN_PROC_BROWSER_TEST_P(EncryptedMediaTest, ConfigChangeVideo) { |
| 164 TestConfigChange(); | 171 TestConfigChange(); |
| 165 } | 172 } |
| 166 | 173 |
| 167 IN_PROC_BROWSER_TEST_P(EncryptedMediaTest, FrameSizeChangeVideo) { | 174 IN_PROC_BROWSER_TEST_P(EncryptedMediaTest, FrameSizeChangeVideo) { |
| 168 // Times out on Windows XP. http://crbug.com/171937 | 175 // Times out on Windows XP. http://crbug.com/171937 |
| 169 #if defined(OS_WIN) | 176 #if defined(OS_WIN) |
| 170 if (base::win::GetVersion() < base::win::VERSION_VISTA) | 177 if (base::win::GetVersion() < base::win::VERSION_VISTA) |
| 171 return; | 178 return; |
| 172 #endif | 179 #endif |
| 173 TestFrameSizeChange(); | 180 TestFrameSizeChange(); |
| 174 } | 181 } |
| 175 | 182 |
| 176 IN_PROC_BROWSER_TEST_F(EncryptedMediaTest, UnknownKeySystemThrowsException) { | 183 IN_PROC_BROWSER_TEST_F(EncryptedMediaTest, UnknownKeySystemThrowsException) { |
| 177 RunEncryptedMediaTest("encrypted_media_player.html", "bear-a-enc_a.webm", | 184 RunEncryptedMediaTest(kDefaultEmePlayer, |
| 178 kWebMAudioOnly, "com.example.foo", MSE, | 185 "bear-a_enc-a.webm", |
| 186 kWebMAudioOnly, |
| 187 "com.example.foo", |
| 188 MSE, |
| 179 kEmeNotSupportedError); | 189 kEmeNotSupportedError); |
| 180 } | 190 } |
| 181 | 191 |
| 182 } // namespace content | 192 } // namespace content |
| OLD | NEW |