[email protected] | 63dc907 | 2013-09-12 06:20:47 | [diff] [blame] | 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 |
| 3 | // found in the LICENSE file. |
| 4 | |
dcheng | c16dc809 | 2016-04-08 23:12:56 | [diff] [blame] | 5 | #include <memory> |
dcheng | e73d8520c | 2015-12-27 01:19:09 | [diff] [blame] | 6 | #include <utility> |
| 7 | |
[email protected] | 63dc907 | 2013-09-12 06:20:47 | [diff] [blame] | 8 | #include "base/command_line.h" |
| 9 | #include "base/path_service.h" |
xhwang | 65c2303 | 2017-02-17 04:37:42 | [diff] [blame] | 10 | #include "base/strings/string_number_conversions.h" |
[email protected] | 63dc907 | 2013-09-12 06:20:47 | [diff] [blame] | 11 | #include "base/strings/utf_string_conversions.h" |
jrummell | 90f8b20 | 2017-05-05 17:21:39 | [diff] [blame] | 12 | #include "base/threading/thread_restrictions.h" |
avi | 6846aef | 2015-12-26 01:09:38 | [diff] [blame] | 13 | #include "build/build_config.h" |
[email protected] | 63dc907 | 2013-09-12 06:20:47 | [diff] [blame] | 14 | #include "chrome/browser/media/media_browsertest.h" |
[email protected] | df06a3e | 2014-01-31 21:36:59 | [diff] [blame] | 15 | #include "chrome/browser/media/test_license_server.h" |
| 16 | #include "chrome/browser/media/wv_test_license_server_config.h" |
xhwang | d252d7b5 | 2017-02-08 18:52:36 | [diff] [blame] | 17 | #include "chrome/browser/profiles/profile.h" |
[email protected] | 63dc907 | 2013-09-12 06:20:47 | [diff] [blame] | 18 | #include "chrome/browser/ui/browser.h" |
| 19 | #include "chrome/browser/ui/tabs/tab_strip_model.h" |
| 20 | #include "chrome/common/chrome_switches.h" |
xhwang | d252d7b5 | 2017-02-08 18:52:36 | [diff] [blame] | 21 | #include "chrome/common/pref_names.h" |
xhwang | 3be44be | 2016-05-25 17:24:49 | [diff] [blame] | 22 | #include "chrome/test/base/test_launcher_utils.h" |
xhwang | d252d7b5 | 2017-02-08 18:52:36 | [diff] [blame] | 23 | #include "components/prefs/pref_service.h" |
brettw | 90e9260 | 2015-10-10 00:12:40 | [diff] [blame] | 24 | #include "content/public/common/content_switches.h" |
[email protected] | 63dc907 | 2013-09-12 06:20:47 | [diff] [blame] | 25 | #include "content/public/test/browser_test_utils.h" |
xhwang | 3487934 | 2017-02-11 23:22:33 | [diff] [blame] | 26 | #include "media/base/key_system_names.h" |
kqyang | f93bb7b | 2016-12-03 02:28:19 | [diff] [blame] | 27 | #include "media/base/media_switches.h" |
brettw | 68c7753 | 2017-01-21 00:28:06 | [diff] [blame] | 28 | #include "media/media_features.h" |
brettw | c5fcdd0 | 2016-10-12 07:25:12 | [diff] [blame] | 29 | #include "ppapi/features/features.h" |
[email protected] | 1be9fa07 | 2014-03-21 22:50:29 | [diff] [blame] | 30 | #include "testing/gtest/include/gtest/gtest-spi.h" |
brettw | c5fcdd0 | 2016-10-12 07:25:12 | [diff] [blame] | 31 | |
[email protected] | 6479b19 | 2013-10-19 18:28:04 | [diff] [blame] | 32 | #if defined(OS_ANDROID) |
| 33 | #include "base/android/build_info.h" |
| 34 | #endif |
[email protected] | 63dc907 | 2013-09-12 06:20:47 | [diff] [blame] | 35 | |
wychen | 7b07e7b | 2017-01-10 17:48:29 | [diff] [blame] | 36 | #if defined(OS_WIN) |
| 37 | #include "base/win/windows_version.h" |
| 38 | #endif |
| 39 | |
brettw | c5fcdd0 | 2016-10-12 07:25:12 | [diff] [blame] | 40 | #if BUILDFLAG(ENABLE_PEPPER_CDMS) |
xhwang | b941714 | 2016-05-18 22:23:36 | [diff] [blame] | 41 | #include "chrome/browser/media/pepper_cdm_test_helper.h" |
xhwang | 6bca3b79 | 2016-09-15 18:45:17 | [diff] [blame] | 42 | #include "media/base/media_switches.h" |
Xiaohan Wang | 17d4ffa | 2017-06-06 19:10:11 | [diff] [blame] | 43 | #include "media/cdm/cdm_paths.h" |
[email protected] | 63dc907 | 2013-09-12 06:20:47 | [diff] [blame] | 44 | #endif |
[email protected] | 1825e77 | 2013-10-08 06:39:11 | [diff] [blame] | 45 | |
xhwang | b941714 | 2016-05-18 22:23:36 | [diff] [blame] | 46 | #include "widevine_cdm_version.h" // In SHARED_INTERMEDIATE_DIR. |
[email protected] | 63dc907 | 2013-09-12 06:20:47 | [diff] [blame] | 47 | |
xhwang | 65c2303 | 2017-02-17 04:37:42 | [diff] [blame] | 48 | namespace chrome { |
| 49 | |
[email protected] | 63dc907 | 2013-09-12 06:20:47 | [diff] [blame] | 50 | // Available key systems. |
[email protected] | a32ef59 | 2014-03-07 19:11:15 | [diff] [blame] | 51 | const char kClearKeyKeySystem[] = "org.w3.clearkey"; |
[email protected] | ab998e8 | 2013-11-22 20:31:35 | [diff] [blame] | 52 | const char kExternalClearKeyKeySystem[] = "org.chromium.externalclearkey"; |
xhwang | 640ef5d | 2016-08-17 16:46:08 | [diff] [blame] | 53 | |
| 54 | // Variants of External Clear Key key system to test different scenarios. |
| 55 | // To add a new variant, make sure you also update: |
| 56 | // - media/test/data/eme_player_js/globals.js |
| 57 | // - AddExternalClearKey() in chrome_key_systems.cc |
| 58 | // - CreateCdmInstance() in clear_key_cdm.cc |
xhwang | 0cfb528 | 2016-08-25 03:33:25 | [diff] [blame] | 59 | const char kExternalClearKeyRenewalKeySystem[] = |
| 60 | "org.chromium.externalclearkey.renewal"; |
[email protected] | 34afd58 | 2013-12-20 07:26:18 | [diff] [blame] | 61 | const char kExternalClearKeyFileIOTestKeySystem[] = |
| 62 | "org.chromium.externalclearkey.fileiotest"; |
[email protected] | ab998e8 | 2013-11-22 20:31:35 | [diff] [blame] | 63 | const char kExternalClearKeyInitializeFailKeySystem[] = |
| 64 | "org.chromium.externalclearkey.initializefail"; |
xhwang | 640ef5d | 2016-08-17 16:46:08 | [diff] [blame] | 65 | const char kExternalClearKeyOutputProtectionTestKeySystem[] = |
| 66 | "org.chromium.externalclearkey.outputprotectiontest"; |
xhwang | 382935d | 2016-10-27 22:11:20 | [diff] [blame] | 67 | const char kExternalClearKeyPlatformVerificationTestKeySystem[] = |
| 68 | "org.chromium.externalclearkey.platformverificationtest"; |
[email protected] | a27d34ab | 2014-01-09 04:23:29 | [diff] [blame] | 69 | const char kExternalClearKeyCrashKeySystem[] = |
| 70 | "org.chromium.externalclearkey.crash"; |
xhwang | c394103 | 2017-03-20 18:50:35 | [diff] [blame] | 71 | #if BUILDFLAG(ENABLE_CDM_HOST_VERIFICATION) |
xhwang | 785a834 | 2017-01-26 06:46:39 | [diff] [blame] | 72 | const char kExternalClearKeyVerifyCdmHostTestKeySystem[] = |
| 73 | "org.chromium.externalclearkey.verifycdmhosttest"; |
xhwang | c394103 | 2017-03-20 18:50:35 | [diff] [blame] | 74 | #endif |
[email protected] | 63dc907 | 2013-09-12 06:20:47 | [diff] [blame] | 75 | |
| 76 | // Supported media types. |
servolk | 0b214678 | 2016-08-30 03:47:45 | [diff] [blame] | 77 | const char kWebMVorbisAudioOnly[] = "audio/webm; codecs=\"vorbis\""; |
servolk | 0b214678 | 2016-08-30 03:47:45 | [diff] [blame] | 78 | const char kWebMVP8VideoOnly[] = "video/webm; codecs=\"vp8\""; |
| 79 | const char kWebMVorbisAudioVP8Video[] = "video/webm; codecs=\"vorbis, vp8\""; |
| 80 | const char kWebMOpusAudioVP9Video[] = "video/webm; codecs=\"opus, vp9\""; |
jamescook | 6107ed8 | 2014-11-06 06:59:21 | [diff] [blame] | 81 | const char kWebMVP9VideoOnly[] = "video/webm; codecs=\"vp9\""; |
brettw | 68c7753 | 2017-01-21 00:28:06 | [diff] [blame] | 82 | #if BUILDFLAG(USE_PROPRIETARY_CODECS) |
jrummell | 2737b99 | 2016-10-03 23:30:18 | [diff] [blame] | 83 | const char kMP4VideoOnly[] = "video/mp4; codecs=\"avc1.4D000C\""; |
kqyang | bfe1030 | 2017-05-06 19:06:41 | [diff] [blame] | 84 | const char kMP4VideoVp9Only[] = |
| 85 | "video/mp4; codecs=\"vp09.00.10.08.01.02.02.02.00\""; |
brettw | 68c7753 | 2017-01-21 00:28:06 | [diff] [blame] | 86 | #endif // BUILDFLAG(USE_PROPRIETARY_CODECS) |
[email protected] | 63dc907 | 2013-09-12 06:20:47 | [diff] [blame] | 87 | |
[email protected] | 0af5dfa | 2014-02-07 22:33:44 | [diff] [blame] | 88 | // Sessions to load. |
| 89 | const char kNoSessionToLoad[] = ""; |
| 90 | const char kLoadableSession[] = "LoadableSession"; |
| 91 | const char kUnknownSession[] = "UnknownSession"; |
| 92 | |
[email protected] | 2e850f1 | 2013-09-18 01:27:29 | [diff] [blame] | 93 | // EME-specific test results and errors. |
xhwang | 640ef5d | 2016-08-17 16:46:08 | [diff] [blame] | 94 | const char kUnitTestSuccess[] = "UNIT_TEST_SUCCESS"; |
jrummell | 0c6ba54 | 2015-07-08 18:04:44 | [diff] [blame] | 95 | const char kEmeNotSupportedError[] = "NOTSUPPORTEDERROR"; |
| 96 | const char kEmeGenerateRequestFailed[] = "EME_GENERATEREQUEST_FAILED"; |
jrummell | 14fae6f | 2015-07-10 20:40:15 | [diff] [blame] | 97 | const char kEmeSessionNotFound[] = "EME_SESSION_NOT_FOUND"; |
jrummell | 0c6ba54 | 2015-07-08 18:04:44 | [diff] [blame] | 98 | const char kEmeLoadFailed[] = "EME_LOAD_FAILED"; |
| 99 | const char kEmeUpdateFailed[] = "EME_UPDATE_FAILED"; |
| 100 | const char kEmeErrorEvent[] = "EME_ERROR_EVENT"; |
| 101 | const char kEmeMessageUnexpectedType[] = "EME_MESSAGE_UNEXPECTED_TYPE"; |
ddorwin | fdb9a2b | 2016-02-22 22:25:10 | [diff] [blame] | 102 | const char kEmeRenewalMissingHeader[] = "EME_RENEWAL_MISSING_HEADER"; |
jrummell | 35c1aa88 | 2016-11-16 00:49:15 | [diff] [blame] | 103 | const char kEmeSessionClosedAndError[] = "EME_SESSION_CLOSED_AND_ERROR"; |
[email protected] | e11d89d | 2014-06-19 11:36:31 | [diff] [blame] | 104 | |
| 105 | const char kDefaultEmePlayer[] = "eme_player.html"; |
[email protected] | 63dc907 | 2013-09-12 06:20:47 | [diff] [blame] | 106 | |
| 107 | // The type of video src used to load media. |
xhwang | 65c2303 | 2017-02-17 04:37:42 | [diff] [blame] | 108 | enum class SrcType { SRC, MSE }; |
| 109 | |
| 110 | // Must be in sync with CONFIG_CHANGE_TYPE in eme_player_js/global.js |
| 111 | enum class ConfigChangeType { |
| 112 | CLEAR_TO_CLEAR = 0, |
| 113 | CLEAR_TO_ENCRYPTED = 1, |
| 114 | ENCRYPTED_TO_CLEAR = 2, |
| 115 | ENCRYPTED_TO_ENCRYPTED = 3, |
[email protected] | 63dc907 | 2013-09-12 06:20:47 | [diff] [blame] | 116 | }; |
| 117 | |
jrummell | b394463 | 2015-03-14 00:19:42 | [diff] [blame] | 118 | // Whether the video should be played once or twice. |
patricialor | 58397dcb | 2017-02-07 08:42:50 | [diff] [blame] | 119 | enum class PlayCount { ONCE, TWICE }; |
jrummell | b394463 | 2015-03-14 00:19:42 | [diff] [blame] | 120 | |
jrummell | c015cb96 | 2015-07-17 00:41:30 | [diff] [blame] | 121 | // Format of a container when testing different streams. |
| 122 | enum class EncryptedContainer { |
| 123 | CLEAR_WEBM, |
| 124 | CLEAR_MP4, |
| 125 | ENCRYPTED_WEBM, |
| 126 | ENCRYPTED_MP4 |
| 127 | }; |
| 128 | |
[email protected] | e6bf6414 | 2013-10-18 23:07:54 | [diff] [blame] | 129 | // Base class for encrypted media tests. |
| 130 | class EncryptedMediaTestBase : public MediaBrowserTest { |
[email protected] | 63dc907 | 2013-09-12 06:20:47 | [diff] [blame] | 131 | public: |
[email protected] | ab998e8 | 2013-11-22 20:31:35 | [diff] [blame] | 132 | bool IsExternalClearKey(const std::string& key_system) { |
ddorwin | 40312df | 2016-02-26 01:25:01 | [diff] [blame] | 133 | if (key_system == kExternalClearKeyKeySystem) |
| 134 | return true; |
| 135 | std::string prefix = std::string(kExternalClearKeyKeySystem) + '.'; |
| 136 | return key_system.substr(0, prefix.size()) == prefix; |
[email protected] | 63dc907 | 2013-09-12 06:20:47 | [diff] [blame] | 137 | } |
| 138 | |
[email protected] | 1825e77 | 2013-10-08 06:39:11 | [diff] [blame] | 139 | #if defined(WIDEVINE_CDM_AVAILABLE) |
[email protected] | ab998e8 | 2013-11-22 20:31:35 | [diff] [blame] | 140 | bool IsWidevine(const std::string& key_system) { |
| 141 | return key_system == kWidevineKeySystem; |
[email protected] | 1825e77 | 2013-10-08 06:39:11 | [diff] [blame] | 142 | } |
| 143 | #endif // defined(WIDEVINE_CDM_AVAILABLE) |
| 144 | |
[email protected] | 8a22932 | 2014-07-22 23:33:07 | [diff] [blame] | 145 | void RunEncryptedMediaTestPage( |
| 146 | const std::string& html_page, |
| 147 | const std::string& key_system, |
anand.ratn | 2636d97 | 2014-09-30 04:06:58 | [diff] [blame] | 148 | base::StringPairs& query_params, |
[email protected] | 8a22932 | 2014-07-22 23:33:07 | [diff] [blame] | 149 | const std::string& expected_title) { |
anand.ratn | 2636d97 | 2014-09-30 04:06:58 | [diff] [blame] | 150 | base::StringPairs new_query_params = query_params; |
[email protected] | 8a22932 | 2014-07-22 23:33:07 | [diff] [blame] | 151 | StartLicenseServerIfNeeded(key_system, &new_query_params); |
| 152 | RunMediaTestPage(html_page, new_query_params, expected_title, true); |
[email protected] | df06a3e | 2014-01-31 21:36:59 | [diff] [blame] | 153 | } |
| 154 | |
[email protected] | 0af5dfa | 2014-02-07 22:33:44 | [diff] [blame] | 155 | // Tests |html_page| using |media_file| (with |media_type|) and |key_system|. |
| 156 | // When |session_to_load| is not empty, the test will try to load |
| 157 | // |session_to_load| with stored keys, instead of creating a new session |
| 158 | // and trying to update it with licenses. |
| 159 | // When |force_invalid_response| is true, the test will provide invalid |
| 160 | // responses, which should trigger errors. |
| 161 | // TODO(xhwang): Find an easier way to pass multiple configuration test |
| 162 | // options. |
[email protected] | df06a3e | 2014-01-31 21:36:59 | [diff] [blame] | 163 | void RunEncryptedMediaTest(const std::string& html_page, |
| 164 | const std::string& media_file, |
| 165 | const std::string& media_type, |
| 166 | const std::string& key_system, |
[email protected] | 1825e77 | 2013-10-08 06:39:11 | [diff] [blame] | 167 | SrcType src_type, |
[email protected] | 0af5dfa | 2014-02-07 22:33:44 | [diff] [blame] | 168 | const std::string& session_to_load, |
[email protected] | df06a3e | 2014-01-31 21:36:59 | [diff] [blame] | 169 | bool force_invalid_response, |
patricialor | 58397dcb | 2017-02-07 08:42:50 | [diff] [blame] | 170 | PlayCount play_count, |
[email protected] | df06a3e | 2014-01-31 21:36:59 | [diff] [blame] | 171 | const std::string& expected_title) { |
anand.ratn | 2636d97 | 2014-09-30 04:06:58 | [diff] [blame] | 172 | base::StringPairs query_params; |
[email protected] | df06a3e | 2014-01-31 21:36:59 | [diff] [blame] | 173 | query_params.push_back(std::make_pair("mediaFile", media_file)); |
| 174 | query_params.push_back(std::make_pair("mediaType", media_type)); |
| 175 | query_params.push_back(std::make_pair("keySystem", key_system)); |
xhwang | 65c2303 | 2017-02-17 04:37:42 | [diff] [blame] | 176 | if (src_type == SrcType::MSE) |
[email protected] | df06a3e | 2014-01-31 21:36:59 | [diff] [blame] | 177 | query_params.push_back(std::make_pair("useMSE", "1")); |
| 178 | if (force_invalid_response) |
| 179 | query_params.push_back(std::make_pair("forceInvalidResponse", "1")); |
[email protected] | 0af5dfa | 2014-02-07 22:33:44 | [diff] [blame] | 180 | if (!session_to_load.empty()) |
| 181 | query_params.push_back(std::make_pair("sessionToLoad", session_to_load)); |
patricialor | 58397dcb | 2017-02-07 08:42:50 | [diff] [blame] | 182 | if (play_count == PlayCount::TWICE) |
jrummell | b394463 | 2015-03-14 00:19:42 | [diff] [blame] | 183 | query_params.push_back(std::make_pair("playTwice", "1")); |
[email protected] | 8a22932 | 2014-07-22 23:33:07 | [diff] [blame] | 184 | RunEncryptedMediaTestPage(html_page, key_system, query_params, |
[email protected] | df06a3e | 2014-01-31 21:36:59 | [diff] [blame] | 185 | expected_title); |
[email protected] | 63dc907 | 2013-09-12 06:20:47 | [diff] [blame] | 186 | } |
| 187 | |
[email protected] | df06a3e | 2014-01-31 21:36:59 | [diff] [blame] | 188 | void RunSimpleEncryptedMediaTest(const std::string& media_file, |
| 189 | const std::string& media_type, |
| 190 | const std::string& key_system, |
ddorwin | fdb9a2b | 2016-02-22 22:25:10 | [diff] [blame] | 191 | SrcType src_type) { |
[email protected] | df06a3e | 2014-01-31 21:36:59 | [diff] [blame] | 192 | std::string expected_title = kEnded; |
jrummell | 0c6ba54 | 2015-07-08 18:04:44 | [diff] [blame] | 193 | if (!IsPlayBackPossible(key_system)) { |
ddorwin | fdb9a2b | 2016-02-22 22:25:10 | [diff] [blame] | 194 | expected_title = kEmeUpdateFailed; |
jrummell | 0c6ba54 | 2015-07-08 18:04:44 | [diff] [blame] | 195 | } |
[email protected] | 1825e77 | 2013-10-08 06:39:11 | [diff] [blame] | 196 | |
jrummell | b394463 | 2015-03-14 00:19:42 | [diff] [blame] | 197 | RunEncryptedMediaTest(kDefaultEmePlayer, media_file, media_type, key_system, |
patricialor | 58397dcb | 2017-02-07 08:42:50 | [diff] [blame] | 198 | src_type, kNoSessionToLoad, false, PlayCount::ONCE, |
ddorwin | fdb9a2b | 2016-02-22 22:25:10 | [diff] [blame] | 199 | expected_title); |
[email protected] | df06a3e | 2014-01-31 21:36:59 | [diff] [blame] | 200 | // Check KeyMessage received for all key systems. |
| 201 | bool receivedKeyMessage = false; |
| 202 | EXPECT_TRUE(content::ExecuteScriptAndExtractBool( |
| 203 | browser()->tab_strip_model()->GetActiveWebContents(), |
[email protected] | e11d89d | 2014-06-19 11:36:31 | [diff] [blame] | 204 | "window.domAutomationController.send(" |
| 205 | "document.querySelector('video').receivedKeyMessage);", |
[email protected] | df06a3e | 2014-01-31 21:36:59 | [diff] [blame] | 206 | &receivedKeyMessage)); |
| 207 | EXPECT_TRUE(receivedKeyMessage); |
| 208 | } |
| 209 | |
[email protected] | 8a22932 | 2014-07-22 23:33:07 | [diff] [blame] | 210 | // Starts a license server if available for the |key_system| and adds a |
| 211 | // 'licenseServerURL' query parameter to |query_params|. |
[email protected] | df06a3e | 2014-01-31 21:36:59 | [diff] [blame] | 212 | void StartLicenseServerIfNeeded(const std::string& key_system, |
anand.ratn | 2636d97 | 2014-09-30 04:06:58 | [diff] [blame] | 213 | base::StringPairs* query_params) { |
dcheng | c16dc809 | 2016-04-08 23:12:56 | [diff] [blame] | 214 | std::unique_ptr<TestLicenseServerConfig> config = |
| 215 | GetServerConfig(key_system); |
[email protected] | df06a3e | 2014-01-31 21:36:59 | [diff] [blame] | 216 | if (!config) |
| 217 | return; |
dcheng | e73d8520c | 2015-12-27 01:19:09 | [diff] [blame] | 218 | license_server_.reset(new TestLicenseServer(std::move(config))); |
jrummell | 90f8b20 | 2017-05-05 17:21:39 | [diff] [blame] | 219 | { |
| 220 | base::ThreadRestrictions::ScopedAllowIO allow_io; |
| 221 | EXPECT_TRUE(license_server_->Start()); |
| 222 | } |
[email protected] | 8a22932 | 2014-07-22 23:33:07 | [diff] [blame] | 223 | query_params->push_back( |
| 224 | std::make_pair("licenseServerURL", license_server_->GetServerURL())); |
[email protected] | df06a3e | 2014-01-31 21:36:59 | [diff] [blame] | 225 | } |
| 226 | |
| 227 | bool IsPlayBackPossible(const std::string& key_system) { |
| 228 | #if defined(WIDEVINE_CDM_AVAILABLE) |
| 229 | if (IsWidevine(key_system) && !GetServerConfig(key_system)) |
| 230 | return false; |
| 231 | #endif // defined(WIDEVINE_CDM_AVAILABLE) |
| 232 | return true; |
| 233 | } |
| 234 | |
dcheng | c16dc809 | 2016-04-08 23:12:56 | [diff] [blame] | 235 | std::unique_ptr<TestLicenseServerConfig> GetServerConfig( |
[email protected] | df06a3e | 2014-01-31 21:36:59 | [diff] [blame] | 236 | const std::string& key_system) { |
| 237 | #if defined(WIDEVINE_CDM_AVAILABLE) |
| 238 | if (IsWidevine(key_system)) { |
dcheng | c16dc809 | 2016-04-08 23:12:56 | [diff] [blame] | 239 | std::unique_ptr<TestLicenseServerConfig> config( |
| 240 | new WVTestLicenseServerConfig); |
[email protected] | df06a3e | 2014-01-31 21:36:59 | [diff] [blame] | 241 | if (config->IsPlatformSupported()) |
dcheng | 7c133cc | 2015-12-31 06:57:59 | [diff] [blame] | 242 | return config; |
[email protected] | df06a3e | 2014-01-31 21:36:59 | [diff] [blame] | 243 | } |
| 244 | #endif // defined(WIDEVINE_CDM_AVAILABLE) |
dcheng | 7c133cc | 2015-12-31 06:57:59 | [diff] [blame] | 245 | return nullptr; |
[email protected] | 1825e77 | 2013-10-08 06:39:11 | [diff] [blame] | 246 | } |
| 247 | |
[email protected] | 63dc907 | 2013-09-12 06:20:47 | [diff] [blame] | 248 | protected: |
dcheng | c16dc809 | 2016-04-08 23:12:56 | [diff] [blame] | 249 | std::unique_ptr<TestLicenseServer> license_server_; |
[email protected] | df06a3e | 2014-01-31 21:36:59 | [diff] [blame] | 250 | |
[email protected] | 2e850f1 | 2013-09-18 01:27:29 | [diff] [blame] | 251 | // We want to fail quickly when a test fails because an error is encountered. |
dcheng | d7e84a05 | 2014-10-22 00:18:51 | [diff] [blame] | 252 | void AddWaitForTitles(content::TitleWatcher* title_watcher) override { |
[email protected] | 2e850f1 | 2013-09-18 01:27:29 | [diff] [blame] | 253 | MediaBrowserTest::AddWaitForTitles(title_watcher); |
[email protected] | 6778fed | 2013-12-24 20:09:37 | [diff] [blame] | 254 | title_watcher->AlsoWaitForTitle(base::ASCIIToUTF16(kEmeNotSupportedError)); |
jrummell | 0c6ba54 | 2015-07-08 18:04:44 | [diff] [blame] | 255 | title_watcher->AlsoWaitForTitle( |
| 256 | base::ASCIIToUTF16(kEmeGenerateRequestFailed)); |
jrummell | 14fae6f | 2015-07-10 20:40:15 | [diff] [blame] | 257 | title_watcher->AlsoWaitForTitle(base::ASCIIToUTF16(kEmeSessionNotFound)); |
jrummell | 0c6ba54 | 2015-07-08 18:04:44 | [diff] [blame] | 258 | title_watcher->AlsoWaitForTitle(base::ASCIIToUTF16(kEmeLoadFailed)); |
| 259 | title_watcher->AlsoWaitForTitle(base::ASCIIToUTF16(kEmeUpdateFailed)); |
| 260 | title_watcher->AlsoWaitForTitle(base::ASCIIToUTF16(kEmeErrorEvent)); |
| 261 | title_watcher->AlsoWaitForTitle( |
| 262 | base::ASCIIToUTF16(kEmeMessageUnexpectedType)); |
| 263 | title_watcher->AlsoWaitForTitle( |
ddorwin | fdb9a2b | 2016-02-22 22:25:10 | [diff] [blame] | 264 | base::ASCIIToUTF16(kEmeRenewalMissingHeader)); |
[email protected] | 2e850f1 | 2013-09-18 01:27:29 | [diff] [blame] | 265 | } |
| 266 | |
avi | 556c0502 | 2014-12-22 23:31:43 | [diff] [blame] | 267 | void SetUpCommandLine(base::CommandLine* command_line) override { |
zmin | 32d29a1 | 2017-04-27 20:48:26 | [diff] [blame] | 268 | command_line->AppendSwitch(switches::kIgnoreAutoplayRestrictionsForTests); |
[email protected] | 2289b43 | 2014-08-08 17:52:11 | [diff] [blame] | 269 | } |
| 270 | |
brettw | c5fcdd0 | 2016-10-12 07:25:12 | [diff] [blame] | 271 | #if BUILDFLAG(ENABLE_PEPPER_CDMS) |
xhwang | 3be44be | 2016-05-25 17:24:49 | [diff] [blame] | 272 | void SetUpDefaultCommandLine(base::CommandLine* command_line) override { |
| 273 | base::CommandLine default_command_line(base::CommandLine::NO_PROGRAM); |
| 274 | InProcessBrowserTest::SetUpDefaultCommandLine(&default_command_line); |
| 275 | test_launcher_utils::RemoveCommandLineSwitch( |
| 276 | default_command_line, switches::kDisableComponentUpdate, command_line); |
| 277 | } |
brettw | c5fcdd0 | 2016-10-12 07:25:12 | [diff] [blame] | 278 | #endif // BUILDFLAG(ENABLE_PEPPER_CDMS) |
xhwang | 3be44be | 2016-05-25 17:24:49 | [diff] [blame] | 279 | |
[email protected] | df06a3e | 2014-01-31 21:36:59 | [diff] [blame] | 280 | void SetUpCommandLineForKeySystem(const std::string& key_system, |
avi | 556c0502 | 2014-12-22 23:31:43 | [diff] [blame] | 281 | base::CommandLine* command_line) { |
[email protected] | df06a3e | 2014-01-31 21:36:59 | [diff] [blame] | 282 | if (GetServerConfig(key_system)) |
| 283 | // Since the web and license servers listen on different ports, we need to |
| 284 | // disable web-security to send license requests to the license server. |
| 285 | // TODO(shadi): Add port forwarding to the test web server configuration. |
| 286 | command_line->AppendSwitch(switches::kDisableWebSecurity); |
| 287 | |
brettw | c5fcdd0 | 2016-10-12 07:25:12 | [diff] [blame] | 288 | #if BUILDFLAG(ENABLE_PEPPER_CDMS) |
[email protected] | e6bf6414 | 2013-10-18 23:07:54 | [diff] [blame] | 289 | if (IsExternalClearKey(key_system)) { |
Xiaohan Wang | 17d4ffa | 2017-06-06 19:10:11 | [diff] [blame] | 290 | RegisterPepperCdm(command_line, media::kClearKeyCdmBaseDirectory, |
| 291 | media::kClearKeyCdmAdapterFileName, |
| 292 | media::kClearKeyCdmDisplayName, |
| 293 | media::kClearKeyCdmPepperMimeType); |
xhwang | 6bca3b79 | 2016-09-15 18:45:17 | [diff] [blame] | 294 | command_line->AppendSwitchASCII(switches::kEnableFeatures, |
| 295 | media::kExternalClearKeyForTesting.name); |
[email protected] | e6bf6414 | 2013-10-18 23:07:54 | [diff] [blame] | 296 | } |
brettw | c5fcdd0 | 2016-10-12 07:25:12 | [diff] [blame] | 297 | #endif // BUILDFLAG(ENABLE_PEPPER_CDMS) |
[email protected] | e6bf6414 | 2013-10-18 23:07:54 | [diff] [blame] | 298 | } |
[email protected] | e6bf6414 | 2013-10-18 23:07:54 | [diff] [blame] | 299 | }; |
| 300 | |
brettw | c5fcdd0 | 2016-10-12 07:25:12 | [diff] [blame] | 301 | #if BUILDFLAG(ENABLE_PEPPER_CDMS) |
[email protected] | ab998e8 | 2013-11-22 20:31:35 | [diff] [blame] | 302 | // Tests encrypted media playback using ExternalClearKey key system in |
| 303 | // decrypt-and-decode mode. |
[email protected] | e6bf6414 | 2013-10-18 23:07:54 | [diff] [blame] | 304 | class ECKEncryptedMediaTest : public EncryptedMediaTestBase { |
[email protected] | 0af5dfa | 2014-02-07 22:33:44 | [diff] [blame] | 305 | public: |
| 306 | // We use special |key_system| names to do non-playback related tests, e.g. |
| 307 | // kExternalClearKeyFileIOTestKeySystem is used to test file IO. |
| 308 | void TestNonPlaybackCases(const std::string& key_system, |
| 309 | const std::string& expected_title) { |
| 310 | // Since we do not test playback, arbitrarily choose a test file and source |
| 311 | // type. |
ddorwin | fdb9a2b | 2016-02-22 22:25:10 | [diff] [blame] | 312 | RunEncryptedMediaTest(kDefaultEmePlayer, "bear-a_enc-a.webm", |
xhwang | 65c2303 | 2017-02-17 04:37:42 | [diff] [blame] | 313 | kWebMVorbisAudioOnly, key_system, SrcType::SRC, |
patricialor | 58397dcb | 2017-02-07 08:42:50 | [diff] [blame] | 314 | kNoSessionToLoad, false, PlayCount::ONCE, |
servolk | 0b214678 | 2016-08-30 03:47:45 | [diff] [blame] | 315 | expected_title); |
jrummell | 19f2c90 | 2015-02-11 01:17:50 | [diff] [blame] | 316 | } |
| 317 | |
xhwang | 0cfb528 | 2016-08-25 03:33:25 | [diff] [blame] | 318 | void TestPlaybackCase(const std::string& key_system, |
| 319 | const std::string& session_to_load, |
jrummell | 19f2c90 | 2015-02-11 01:17:50 | [diff] [blame] | 320 | const std::string& expected_title) { |
| 321 | RunEncryptedMediaTest(kDefaultEmePlayer, "bear-320x240-v_enc-v.webm", |
xhwang | 65c2303 | 2017-02-17 04:37:42 | [diff] [blame] | 322 | kWebMVP8VideoOnly, key_system, SrcType::SRC, |
| 323 | session_to_load, false, PlayCount::ONCE, |
| 324 | expected_title); |
jrummell | 19f2c90 | 2015-02-11 01:17:50 | [diff] [blame] | 325 | } |
| 326 | |
jrummell | c467d23 | 2014-10-21 17:55:22 | [diff] [blame] | 327 | protected: |
avi | 556c0502 | 2014-12-22 23:31:43 | [diff] [blame] | 328 | void SetUpCommandLine(base::CommandLine* command_line) override { |
jrummell | c467d23 | 2014-10-21 17:55:22 | [diff] [blame] | 329 | EncryptedMediaTestBase::SetUpCommandLine(command_line); |
jrummell | c467d23 | 2014-10-21 17:55:22 | [diff] [blame] | 330 | SetUpCommandLineForKeySystem(kExternalClearKeyKeySystem, command_line); |
| 331 | } |
| 332 | }; |
| 333 | |
[email protected] | e6bf6414 | 2013-10-18 23:07:54 | [diff] [blame] | 334 | #if defined(WIDEVINE_CDM_AVAILABLE) |
| 335 | // Tests encrypted media playback using Widevine key system. |
| 336 | class WVEncryptedMediaTest : public EncryptedMediaTestBase { |
| 337 | protected: |
Daniel Cheng | 43ba4a012 | 2014-12-31 06:30:35 | [diff] [blame] | 338 | void SetUpCommandLine(base::CommandLine* command_line) override { |
[email protected] | e6bf6414 | 2013-10-18 23:07:54 | [diff] [blame] | 339 | EncryptedMediaTestBase::SetUpCommandLine(command_line); |
| 340 | SetUpCommandLineForKeySystem(kWidevineKeySystem, command_line); |
| 341 | } |
| 342 | }; |
[email protected] | df06a3e | 2014-01-31 21:36:59 | [diff] [blame] | 343 | |
[email protected] | e6bf6414 | 2013-10-18 23:07:54 | [diff] [blame] | 344 | #endif // defined(WIDEVINE_CDM_AVAILABLE) |
brettw | c5fcdd0 | 2016-10-12 07:25:12 | [diff] [blame] | 345 | #endif // BUILDFLAG(ENABLE_PEPPER_CDMS) |
[email protected] | e6bf6414 | 2013-10-18 23:07:54 | [diff] [blame] | 346 | |
| 347 | // Tests encrypted media playback with a combination of parameters: |
| 348 | // - char*: Key system name. |
jrummell | 19f2c90 | 2015-02-11 01:17:50 | [diff] [blame] | 349 | // - SrcType: Use MSE or SRC. |
[email protected] | e6bf6414 | 2013-10-18 23:07:54 | [diff] [blame] | 350 | // |
| 351 | // Note: Only parameterized (*_P) tests can be used. Non-parameterized (*_F) |
| 352 | // tests will crash at GetParam(). To add non-parameterized tests, use |
| 353 | // EncryptedMediaTestBase or one of its subclasses (e.g. WVEncryptedMediaTest). |
ddorwin | fdb9a2b | 2016-02-22 22:25:10 | [diff] [blame] | 354 | class EncryptedMediaTest : public EncryptedMediaTestBase, |
| 355 | public testing::WithParamInterface< |
| 356 | std::tr1::tuple<const char*, SrcType>> { |
[email protected] | e6bf6414 | 2013-10-18 23:07:54 | [diff] [blame] | 357 | public: |
[email protected] | df06a3e | 2014-01-31 21:36:59 | [diff] [blame] | 358 | std::string CurrentKeySystem() { |
[email protected] | e6bf6414 | 2013-10-18 23:07:54 | [diff] [blame] | 359 | return std::tr1::get<0>(GetParam()); |
| 360 | } |
| 361 | |
| 362 | SrcType CurrentSourceType() { |
| 363 | return std::tr1::get<1>(GetParam()); |
| 364 | } |
| 365 | |
[email protected] | df06a3e | 2014-01-31 21:36:59 | [diff] [blame] | 366 | void TestSimplePlayback(const std::string& encrypted_media, |
| 367 | const std::string& media_type) { |
ddorwin | fdb9a2b | 2016-02-22 22:25:10 | [diff] [blame] | 368 | RunSimpleEncryptedMediaTest(encrypted_media, media_type, CurrentKeySystem(), |
| 369 | CurrentSourceType()); |
[email protected] | e6bf6414 | 2013-10-18 23:07:54 | [diff] [blame] | 370 | } |
| 371 | |
jrummell | b394463 | 2015-03-14 00:19:42 | [diff] [blame] | 372 | void TestMultiplePlayback(const std::string& encrypted_media, |
| 373 | const std::string& media_type) { |
jrummell | d9dc790 | 2015-03-16 20:59:28 | [diff] [blame] | 374 | DCHECK(IsPlayBackPossible(CurrentKeySystem())); |
jrummell | b394463 | 2015-03-14 00:19:42 | [diff] [blame] | 375 | RunEncryptedMediaTest(kDefaultEmePlayer, encrypted_media, media_type, |
| 376 | CurrentKeySystem(), CurrentSourceType(), |
patricialor | 58397dcb | 2017-02-07 08:42:50 | [diff] [blame] | 377 | kNoSessionToLoad, false, PlayCount::TWICE, kEnded); |
jrummell | b394463 | 2015-03-14 00:19:42 | [diff] [blame] | 378 | } |
| 379 | |
[email protected] | df06a3e | 2014-01-31 21:36:59 | [diff] [blame] | 380 | void RunInvalidResponseTest() { |
ddorwin | fdb9a2b | 2016-02-22 22:25:10 | [diff] [blame] | 381 | RunEncryptedMediaTest(kDefaultEmePlayer, "bear-320x240-av_enc-av.webm", |
servolk | 0b214678 | 2016-08-30 03:47:45 | [diff] [blame] | 382 | kWebMVorbisAudioVP8Video, CurrentKeySystem(), |
ddorwin | fdb9a2b | 2016-02-22 22:25:10 | [diff] [blame] | 383 | CurrentSourceType(), kNoSessionToLoad, true, |
patricialor | 58397dcb | 2017-02-07 08:42:50 | [diff] [blame] | 384 | PlayCount::ONCE, kEmeUpdateFailed); |
[email protected] | df06a3e | 2014-01-31 21:36:59 | [diff] [blame] | 385 | } |
| 386 | |
[email protected] | e6bf6414 | 2013-10-18 23:07:54 | [diff] [blame] | 387 | void TestFrameSizeChange() { |
servolk | 0b214678 | 2016-08-30 03:47:45 | [diff] [blame] | 388 | RunEncryptedMediaTest( |
| 389 | "encrypted_frame_size_change.html", "frame_size_change-av_enc-v.webm", |
| 390 | kWebMVorbisAudioVP8Video, CurrentKeySystem(), CurrentSourceType(), |
patricialor | 58397dcb | 2017-02-07 08:42:50 | [diff] [blame] | 391 | kNoSessionToLoad, false, PlayCount::ONCE, kEnded); |
[email protected] | e6bf6414 | 2013-10-18 23:07:54 | [diff] [blame] | 392 | } |
| 393 | |
xhwang | 65c2303 | 2017-02-17 04:37:42 | [diff] [blame] | 394 | void TestConfigChange(ConfigChangeType config_change_type) { |
| 395 | // TODO(xhwang): Even when config change or playback is not supported we |
| 396 | // still start Chrome only to return directly here. We probably should not |
| 397 | // run these test cases at all. See http://crbug.com/693288 |
| 398 | if (CurrentSourceType() != SrcType::MSE) { |
| 399 | DVLOG(0) << "Config change only happens when using MSE."; |
| 400 | return; |
| 401 | } |
| 402 | if (!IsPlayBackPossible(CurrentKeySystem())) { |
| 403 | DVLOG(0) << "Skipping test - ConfigChange test requires video playback."; |
| 404 | return; |
| 405 | } |
| 406 | |
anand.ratn | 2636d97 | 2014-09-30 04:06:58 | [diff] [blame] | 407 | base::StringPairs query_params; |
[email protected] | df06a3e | 2014-01-31 21:36:59 | [diff] [blame] | 408 | query_params.push_back(std::make_pair("keySystem", CurrentKeySystem())); |
xhwang | 65c2303 | 2017-02-17 04:37:42 | [diff] [blame] | 409 | query_params.push_back(std::make_pair( |
| 410 | "configChangeType", |
| 411 | base::IntToString(static_cast<int>(config_change_type)))); |
| 412 | RunEncryptedMediaTestPage("mse_config_change.html", CurrentKeySystem(), |
| 413 | query_params, kEnded); |
[email protected] | e6bf6414 | 2013-10-18 23:07:54 | [diff] [blame] | 414 | } |
| 415 | |
jrummell | c015cb96 | 2015-07-17 00:41:30 | [diff] [blame] | 416 | std::string ConvertContainerFormat(EncryptedContainer format) { |
| 417 | switch (format) { |
| 418 | case EncryptedContainer::CLEAR_MP4: |
| 419 | return "CLEAR_MP4"; |
| 420 | case EncryptedContainer::CLEAR_WEBM: |
| 421 | return "CLEAR_WEBM"; |
| 422 | case EncryptedContainer::ENCRYPTED_MP4: |
| 423 | return "ENCRYPTED_MP4"; |
| 424 | case EncryptedContainer::ENCRYPTED_WEBM: |
| 425 | return "ENCRYPTED_WEBM"; |
| 426 | } |
| 427 | NOTREACHED(); |
| 428 | return "UNKNOWN"; |
| 429 | } |
| 430 | |
| 431 | void TestDifferentContainers(EncryptedContainer video_format, |
| 432 | EncryptedContainer audio_format) { |
jrummell | c015cb96 | 2015-07-17 00:41:30 | [diff] [blame] | 433 | base::StringPairs query_params; |
| 434 | query_params.push_back(std::make_pair("keySystem", CurrentKeySystem())); |
| 435 | query_params.push_back(std::make_pair("runEncrypted", "1")); |
| 436 | query_params.push_back( |
| 437 | std::make_pair("videoFormat", ConvertContainerFormat(video_format))); |
| 438 | query_params.push_back( |
| 439 | std::make_pair("audioFormat", ConvertContainerFormat(audio_format))); |
| 440 | RunEncryptedMediaTestPage("mse_different_containers.html", |
| 441 | CurrentKeySystem(), query_params, kEnded); |
| 442 | } |
| 443 | |
xhwang | d252d7b5 | 2017-02-08 18:52:36 | [diff] [blame] | 444 | void DisableEncryptedMedia() { |
| 445 | PrefService* pref_service = browser()->profile()->GetPrefs(); |
| 446 | pref_service->SetBoolean(prefs::kWebKitEncryptedMediaEnabled, false); |
| 447 | } |
| 448 | |
[email protected] | e6bf6414 | 2013-10-18 23:07:54 | [diff] [blame] | 449 | protected: |
avi | 556c0502 | 2014-12-22 23:31:43 | [diff] [blame] | 450 | void SetUpCommandLine(base::CommandLine* command_line) override { |
[email protected] | e6bf6414 | 2013-10-18 23:07:54 | [diff] [blame] | 451 | EncryptedMediaTestBase::SetUpCommandLine(command_line); |
| 452 | SetUpCommandLineForKeySystem(CurrentKeySystem(), command_line); |
| 453 | } |
[email protected] | 63dc907 | 2013-09-12 06:20:47 | [diff] [blame] | 454 | }; |
| 455 | |
[email protected] | 6479b19 | 2013-10-19 18:28:04 | [diff] [blame] | 456 | using ::testing::Combine; |
| 457 | using ::testing::Values; |
| 458 | |
jrummell | 7741919 | 2014-10-31 21:40:44 | [diff] [blame] | 459 | INSTANTIATE_TEST_CASE_P(MSE_ClearKey, |
[email protected] | a32ef59 | 2014-03-07 19:11:15 | [diff] [blame] | 460 | EncryptedMediaTest, |
xhwang | 65c2303 | 2017-02-17 04:37:42 | [diff] [blame] | 461 | Combine(Values(kClearKeyKeySystem), |
| 462 | Values(SrcType::MSE))); |
[email protected] | 63dc907 | 2013-09-12 06:20:47 | [diff] [blame] | 463 | |
| 464 | // External Clear Key is currently only used on platforms that use Pepper CDMs. |
brettw | c5fcdd0 | 2016-10-12 07:25:12 | [diff] [blame] | 465 | #if BUILDFLAG(ENABLE_PEPPER_CDMS) |
[email protected] | 1ab297a | 2014-03-26 04:52:12 | [diff] [blame] | 466 | INSTANTIATE_TEST_CASE_P(SRC_ExternalClearKey, |
[email protected] | a32ef59 | 2014-03-07 19:11:15 | [diff] [blame] | 467 | EncryptedMediaTest, |
| 468 | Combine(Values(kExternalClearKeyKeySystem), |
xhwang | 65c2303 | 2017-02-17 04:37:42 | [diff] [blame] | 469 | Values(SrcType::SRC))); |
jam | 79bf1f6c | 2015-08-13 20:46:04 | [diff] [blame] | 470 | |
[email protected] | 1ab297a | 2014-03-26 04:52:12 | [diff] [blame] | 471 | INSTANTIATE_TEST_CASE_P(MSE_ExternalClearKey, |
[email protected] | a32ef59 | 2014-03-07 19:11:15 | [diff] [blame] | 472 | EncryptedMediaTest, |
| 473 | Combine(Values(kExternalClearKeyKeySystem), |
xhwang | 65c2303 | 2017-02-17 04:37:42 | [diff] [blame] | 474 | Values(SrcType::MSE))); |
Xiaohan Wang | 439859f3 | 2017-06-06 22:55:24 | [diff] [blame^] | 475 | #else |
| 476 | // To reduce test time, only run ClearKey SRC tests when we are not running |
| 477 | // ExternalClearKey SRC tests. |
| 478 | INSTANTIATE_TEST_CASE_P(SRC_ClearKey, |
[email protected] | a32ef59 | 2014-03-07 19:11:15 | [diff] [blame] | 479 | EncryptedMediaTest, |
Xiaohan Wang | 439859f3 | 2017-06-06 22:55:24 | [diff] [blame^] | 480 | Combine(Values(kClearKeyKeySystem), |
| 481 | Values(SrcType::SRC))); |
brettw | c5fcdd0 | 2016-10-12 07:25:12 | [diff] [blame] | 482 | #endif // BUILDFLAG(ENABLE_PEPPER_CDMS) |
[email protected] | 63dc907 | 2013-09-12 06:20:47 | [diff] [blame] | 483 | |
[email protected] | 1825e77 | 2013-10-08 06:39:11 | [diff] [blame] | 484 | #if defined(WIDEVINE_CDM_AVAILABLE) |
jonross | 5785b866 | 2015-10-22 21:12:53 | [diff] [blame] | 485 | #if !defined(OS_CHROMEOS) |
[email protected] | 1ab297a | 2014-03-26 04:52:12 | [diff] [blame] | 486 | INSTANTIATE_TEST_CASE_P(MSE_Widevine, |
[email protected] | a32ef59 | 2014-03-07 19:11:15 | [diff] [blame] | 487 | EncryptedMediaTest, |
xhwang | 65c2303 | 2017-02-17 04:37:42 | [diff] [blame] | 488 | Combine(Values(kWidevineKeySystem), |
| 489 | Values(SrcType::MSE))); |
jonross | 5785b866 | 2015-10-22 21:12:53 | [diff] [blame] | 490 | #endif // !defined(OS_CHROMEOS) |
[email protected] | 1825e77 | 2013-10-08 06:39:11 | [diff] [blame] | 491 | #endif // defined(WIDEVINE_CDM_AVAILABLE) |
[email protected] | 63dc907 | 2013-09-12 06:20:47 | [diff] [blame] | 492 | |
[email protected] | 626e517c | 2014-08-19 00:49:46 | [diff] [blame] | 493 | IN_PROC_BROWSER_TEST_P(EncryptedMediaTest, Playback_AudioClearVideo_WebM) { |
servolk | 0b214678 | 2016-08-30 03:47:45 | [diff] [blame] | 494 | TestSimplePlayback("bear-320x240-av_enc-a.webm", kWebMVorbisAudioVP8Video); |
[email protected] | 63dc907 | 2013-09-12 06:20:47 | [diff] [blame] | 495 | } |
| 496 | |
[email protected] | 626e517c | 2014-08-19 00:49:46 | [diff] [blame] | 497 | IN_PROC_BROWSER_TEST_P(EncryptedMediaTest, Playback_VideoAudio_WebM) { |
servolk | 0b214678 | 2016-08-30 03:47:45 | [diff] [blame] | 498 | TestSimplePlayback("bear-320x240-av_enc-av.webm", kWebMVorbisAudioVP8Video); |
[email protected] | 63dc907 | 2013-09-12 06:20:47 | [diff] [blame] | 499 | } |
| 500 | |
[email protected] | 626e517c | 2014-08-19 00:49:46 | [diff] [blame] | 501 | IN_PROC_BROWSER_TEST_P(EncryptedMediaTest, Playback_VideoClearAudio_WebM) { |
servolk | 0b214678 | 2016-08-30 03:47:45 | [diff] [blame] | 502 | TestSimplePlayback("bear-320x240-av_enc-v.webm", kWebMVorbisAudioVP8Video); |
[email protected] | 63dc907 | 2013-09-12 06:20:47 | [diff] [blame] | 503 | } |
| 504 | |
kqyang | 2cf59b5 | 2016-10-10 22:16:17 | [diff] [blame] | 505 | IN_PROC_BROWSER_TEST_P(EncryptedMediaTest, Playback_VP9Video_WebM_Fullsample) { |
| 506 | TestSimplePlayback("bear-320x240-v-vp9_fullsample_enc-v.webm", |
| 507 | kWebMVP9VideoOnly); |
| 508 | } |
| 509 | |
| 510 | IN_PROC_BROWSER_TEST_P(EncryptedMediaTest, Playback_VP9Video_WebM_Subsample) { |
| 511 | TestSimplePlayback("bear-320x240-v-vp9_subsample_enc-v.webm", |
| 512 | kWebMVP9VideoOnly); |
[email protected] | 2b197ac7 | 2014-04-11 23:33:52 | [diff] [blame] | 513 | } |
| 514 | |
sandersd | 5ec6dcf | 2014-11-26 20:39:38 | [diff] [blame] | 515 | IN_PROC_BROWSER_TEST_P(EncryptedMediaTest, Playback_VideoAudio_WebM_Opus) { |
servolk | 0b214678 | 2016-08-30 03:47:45 | [diff] [blame] | 516 | TestSimplePlayback("bear-320x240-opus-av_enc-av.webm", |
| 517 | kWebMOpusAudioVP9Video); |
sandersd | 5ec6dcf | 2014-11-26 20:39:38 | [diff] [blame] | 518 | } |
| 519 | |
| 520 | IN_PROC_BROWSER_TEST_P(EncryptedMediaTest, Playback_VideoClearAudio_WebM_Opus) { |
servolk | 0b214678 | 2016-08-30 03:47:45 | [diff] [blame] | 521 | TestSimplePlayback("bear-320x240-opus-av_enc-v.webm", kWebMOpusAudioVP9Video); |
sandersd | 5ec6dcf | 2014-11-26 20:39:38 | [diff] [blame] | 522 | } |
| 523 | |
jrummell | b394463 | 2015-03-14 00:19:42 | [diff] [blame] | 524 | IN_PROC_BROWSER_TEST_P(EncryptedMediaTest, Playback_Multiple_VideoAudio_WebM) { |
jrummell | d9dc790 | 2015-03-16 20:59:28 | [diff] [blame] | 525 | if (!IsPlayBackPossible(CurrentKeySystem())) { |
| 526 | DVLOG(0) << "Skipping test - Playback_Multiple test requires playback."; |
| 527 | return; |
| 528 | } |
servolk | 0b214678 | 2016-08-30 03:47:45 | [diff] [blame] | 529 | TestMultiplePlayback("bear-320x240-av_enc-av.webm", kWebMVorbisAudioVP8Video); |
jrummell | b394463 | 2015-03-14 00:19:42 | [diff] [blame] | 530 | } |
| 531 | |
[email protected] | 626e517c | 2014-08-19 00:49:46 | [diff] [blame] | 532 | IN_PROC_BROWSER_TEST_P(EncryptedMediaTest, InvalidResponseKeyError) { |
[email protected] | df06a3e | 2014-01-31 21:36:59 | [diff] [blame] | 533 | RunInvalidResponseTest(); |
| 534 | } |
| 535 | |
xhwang | 65c2303 | 2017-02-17 04:37:42 | [diff] [blame] | 536 | // Strictly speaking this is not an "encrypted" media test. Keep it here for |
| 537 | // completeness. |
| 538 | IN_PROC_BROWSER_TEST_P(EncryptedMediaTest, ConfigChangeVideo_ClearToClear) { |
| 539 | TestConfigChange(ConfigChangeType::CLEAR_TO_CLEAR); |
| 540 | } |
| 541 | |
xhwang | b2827d2 | 2017-02-24 22:57:33 | [diff] [blame] | 542 | IN_PROC_BROWSER_TEST_P(EncryptedMediaTest, ConfigChangeVideo_ClearToEncrypted) { |
xhwang | 65c2303 | 2017-02-17 04:37:42 | [diff] [blame] | 543 | TestConfigChange(ConfigChangeType::CLEAR_TO_ENCRYPTED); |
| 544 | } |
| 545 | |
| 546 | IN_PROC_BROWSER_TEST_P(EncryptedMediaTest, ConfigChangeVideo_EncryptedToClear) { |
| 547 | TestConfigChange(ConfigChangeType::ENCRYPTED_TO_CLEAR); |
| 548 | } |
| 549 | |
| 550 | IN_PROC_BROWSER_TEST_P(EncryptedMediaTest, |
| 551 | ConfigChangeVideo_EncryptedToEncrypted) { |
| 552 | TestConfigChange(ConfigChangeType::ENCRYPTED_TO_ENCRYPTED); |
[email protected] | 1825e77 | 2013-10-08 06:39:11 | [diff] [blame] | 553 | } |
| 554 | |
dalecurtis | 71bec519 | 2016-10-28 03:16:44 | [diff] [blame] | 555 | IN_PROC_BROWSER_TEST_P(EncryptedMediaTest, FrameSizeChangeVideo) { |
[email protected] | df06a3e | 2014-01-31 21:36:59 | [diff] [blame] | 556 | if (!IsPlayBackPossible(CurrentKeySystem())) { |
anujk.sharma | 9da298e1 | 2014-11-07 04:48:43 | [diff] [blame] | 557 | DVLOG(0) << "Skipping test - FrameSizeChange test requires video playback."; |
[email protected] | df06a3e | 2014-01-31 21:36:59 | [diff] [blame] | 558 | return; |
| 559 | } |
[email protected] | 1825e77 | 2013-10-08 06:39:11 | [diff] [blame] | 560 | TestFrameSizeChange(); |
[email protected] | 63dc907 | 2013-09-12 06:20:47 | [diff] [blame] | 561 | } |
| 562 | |
xhwang | d252d7b5 | 2017-02-08 18:52:36 | [diff] [blame] | 563 | IN_PROC_BROWSER_TEST_P(EncryptedMediaTest, EncryptedMediaDisabled) { |
| 564 | DisableEncryptedMedia(); |
xhwang | 3487934 | 2017-02-11 23:22:33 | [diff] [blame] | 565 | |
| 566 | // Clear Key key system is always supported. |
| 567 | std::string expected_title = |
| 568 | media::IsClearKey(CurrentKeySystem()) ? kEnded : kEmeNotSupportedError; |
| 569 | |
xhwang | d252d7b5 | 2017-02-08 18:52:36 | [diff] [blame] | 570 | RunEncryptedMediaTest(kDefaultEmePlayer, "bear-a_enc-a.webm", |
| 571 | kWebMVorbisAudioOnly, CurrentKeySystem(), |
| 572 | CurrentSourceType(), kNoSessionToLoad, false, |
xhwang | 3487934 | 2017-02-11 23:22:33 | [diff] [blame] | 573 | PlayCount::ONCE, expected_title); |
xhwang | d252d7b5 | 2017-02-08 18:52:36 | [diff] [blame] | 574 | } |
| 575 | |
brettw | 68c7753 | 2017-01-21 00:28:06 | [diff] [blame] | 576 | #if BUILDFLAG(USE_PROPRIETARY_CODECS) |
Xiaohan Wang | 70e545d2 | 2017-06-06 21:18:45 | [diff] [blame] | 577 | IN_PROC_BROWSER_TEST_P(EncryptedMediaTest, Playback_VideoOnly_MP4) { |
[email protected] | 63dc907 | 2013-09-12 06:20:47 | [diff] [blame] | 578 | // MP4 without MSE is not support yet, http://crbug.com/170793. |
xhwang | 65c2303 | 2017-02-17 04:37:42 | [diff] [blame] | 579 | if (CurrentSourceType() != SrcType::MSE) { |
anujk.sharma | 9da298e1 | 2014-11-07 04:48:43 | [diff] [blame] | 580 | DVLOG(0) << "Skipping test; Can only play MP4 encrypted streams by MSE."; |
[email protected] | 63dc907 | 2013-09-12 06:20:47 | [diff] [blame] | 581 | return; |
| 582 | } |
[email protected] | 1825e77 | 2013-10-08 06:39:11 | [diff] [blame] | 583 | TestSimplePlayback("bear-640x360-v_frag-cenc.mp4", kMP4VideoOnly); |
[email protected] | 63dc907 | 2013-09-12 06:20:47 | [diff] [blame] | 584 | } |
| 585 | |
kqyang | f93bb7b | 2016-12-03 02:28:19 | [diff] [blame] | 586 | IN_PROC_BROWSER_TEST_P(EncryptedMediaTest, Playback_VideoOnly_MP4_VP9) { |
| 587 | // MP4 without MSE is not support yet, http://crbug.com/170793. |
xhwang | 65c2303 | 2017-02-17 04:37:42 | [diff] [blame] | 588 | if (CurrentSourceType() != SrcType::MSE) { |
kqyang | f93bb7b | 2016-12-03 02:28:19 | [diff] [blame] | 589 | DVLOG(0) << "Skipping test; Can only play MP4 encrypted streams by MSE."; |
| 590 | return; |
| 591 | } |
| 592 | TestSimplePlayback("bear-320x240-v_frag-vp9-cenc.mp4", kMP4VideoVp9Only); |
| 593 | } |
| 594 | |
jrummell | c015cb96 | 2015-07-17 00:41:30 | [diff] [blame] | 595 | IN_PROC_BROWSER_TEST_P(EncryptedMediaTest, |
| 596 | Playback_EncryptedVideo_MP4_ClearAudio_WEBM) { |
| 597 | // MP4 without MSE is not support yet, http://crbug.com/170793. |
xhwang | 65c2303 | 2017-02-17 04:37:42 | [diff] [blame] | 598 | if (CurrentSourceType() != SrcType::MSE) { |
jrummell | c015cb96 | 2015-07-17 00:41:30 | [diff] [blame] | 599 | DVLOG(0) << "Skipping test; Can only play MP4 encrypted streams by MSE."; |
| 600 | return; |
| 601 | } |
jrummell | c015cb96 | 2015-07-17 00:41:30 | [diff] [blame] | 602 | if (!IsPlayBackPossible(CurrentKeySystem())) { |
| 603 | DVLOG(0) << "Skipping test - Test requires video playback."; |
| 604 | return; |
| 605 | } |
| 606 | TestDifferentContainers(EncryptedContainer::ENCRYPTED_MP4, |
| 607 | EncryptedContainer::CLEAR_WEBM); |
| 608 | } |
| 609 | |
| 610 | IN_PROC_BROWSER_TEST_P(EncryptedMediaTest, |
| 611 | Playback_ClearVideo_WEBM_EncryptedAudio_MP4) { |
| 612 | // MP4 without MSE is not support yet, http://crbug.com/170793. |
xhwang | 65c2303 | 2017-02-17 04:37:42 | [diff] [blame] | 613 | if (CurrentSourceType() != SrcType::MSE) { |
jrummell | c015cb96 | 2015-07-17 00:41:30 | [diff] [blame] | 614 | DVLOG(0) << "Skipping test; Can only play MP4 encrypted streams by MSE."; |
| 615 | return; |
| 616 | } |
jrummell | c015cb96 | 2015-07-17 00:41:30 | [diff] [blame] | 617 | if (!IsPlayBackPossible(CurrentKeySystem())) { |
| 618 | DVLOG(0) << "Skipping test - Test requires video playback."; |
| 619 | return; |
| 620 | } |
| 621 | TestDifferentContainers(EncryptedContainer::CLEAR_WEBM, |
| 622 | EncryptedContainer::ENCRYPTED_MP4); |
| 623 | } |
| 624 | |
| 625 | IN_PROC_BROWSER_TEST_P(EncryptedMediaTest, |
| 626 | Playback_EncryptedVideo_WEBM_EncryptedAudio_MP4) { |
| 627 | // MP4 without MSE is not support yet, http://crbug.com/170793. |
xhwang | 65c2303 | 2017-02-17 04:37:42 | [diff] [blame] | 628 | if (CurrentSourceType() != SrcType::MSE) { |
jrummell | c015cb96 | 2015-07-17 00:41:30 | [diff] [blame] | 629 | DVLOG(0) << "Skipping test; Can only play MP4 encrypted streams by MSE."; |
| 630 | return; |
| 631 | } |
jrummell | c015cb96 | 2015-07-17 00:41:30 | [diff] [blame] | 632 | if (!IsPlayBackPossible(CurrentKeySystem())) { |
| 633 | DVLOG(0) << "Skipping test - Test requires video playback."; |
| 634 | return; |
| 635 | } |
| 636 | TestDifferentContainers(EncryptedContainer::ENCRYPTED_WEBM, |
| 637 | EncryptedContainer::ENCRYPTED_MP4); |
| 638 | } |
brettw | 68c7753 | 2017-01-21 00:28:06 | [diff] [blame] | 639 | #endif // BUILDFLAG(USE_PROPRIETARY_CODECS) |
[email protected] | 63dc907 | 2013-09-12 06:20:47 | [diff] [blame] | 640 | |
[email protected] | 63dc907 | 2013-09-12 06:20:47 | [diff] [blame] | 641 | #if defined(WIDEVINE_CDM_AVAILABLE) |
[email protected] | a32ef59 | 2014-03-07 19:11:15 | [diff] [blame] | 642 | // The parent key system cannot be used when creating MediaKeys. |
[email protected] | b162073 | 2014-04-01 23:17:18 | [diff] [blame] | 643 | IN_PROC_BROWSER_TEST_F(WVEncryptedMediaTest, ParentThrowsException) { |
servolk | 0b214678 | 2016-08-30 03:47:45 | [diff] [blame] | 644 | RunEncryptedMediaTest(kDefaultEmePlayer, "bear-a_enc-a.webm", |
xhwang | 65c2303 | 2017-02-17 04:37:42 | [diff] [blame] | 645 | kWebMVorbisAudioOnly, "com.widevine", SrcType::MSE, |
patricialor | 58397dcb | 2017-02-07 08:42:50 | [diff] [blame] | 646 | kNoSessionToLoad, false, PlayCount::ONCE, |
servolk | 0b214678 | 2016-08-30 03:47:45 | [diff] [blame] | 647 | kEmeNotSupportedError); |
[email protected] | 63dc907 | 2013-09-12 06:20:47 | [diff] [blame] | 648 | } |
[email protected] | 63dc907 | 2013-09-12 06:20:47 | [diff] [blame] | 649 | #endif // defined(WIDEVINE_CDM_AVAILABLE) |
[email protected] | a941d4e57 | 2013-10-14 21:22:05 | [diff] [blame] | 650 | |
brettw | c5fcdd0 | 2016-10-12 07:25:12 | [diff] [blame] | 651 | #if BUILDFLAG(ENABLE_PEPPER_CDMS) |
[email protected] | 34afd58 | 2013-12-20 07:26:18 | [diff] [blame] | 652 | IN_PROC_BROWSER_TEST_F(ECKEncryptedMediaTest, InitializeCDMFail) { |
jrummell | 87a2db5 | 2015-05-05 22:27:18 | [diff] [blame] | 653 | TestNonPlaybackCases(kExternalClearKeyInitializeFailKeySystem, |
| 654 | kEmeNotSupportedError); |
[email protected] | a941d4e57 | 2013-10-14 21:22:05 | [diff] [blame] | 655 | } |
[email protected] | 34afd58 | 2013-12-20 07:26:18 | [diff] [blame] | 656 | |
jrummell | 35c1aa88 | 2016-11-16 00:49:15 | [diff] [blame] | 657 | // When CDM crashes, we should still get a decode error and all sessions should |
| 658 | // be closed. |
jrummell | fed298d2 | 2015-07-01 00:26:51 | [diff] [blame] | 659 | IN_PROC_BROWSER_TEST_F(ECKEncryptedMediaTest, CDMCrashDuringDecode) { |
[email protected] | 1be9fa07 | 2014-03-21 22:50:29 | [diff] [blame] | 660 | IgnorePluginCrash(); |
jrummell | 35c1aa88 | 2016-11-16 00:49:15 | [diff] [blame] | 661 | TestNonPlaybackCases(kExternalClearKeyCrashKeySystem, |
| 662 | kEmeSessionClosedAndError); |
[email protected] | a27d34ab | 2014-01-09 04:23:29 | [diff] [blame] | 663 | } |
| 664 | |
[email protected] | 1be9fa07 | 2014-03-21 22:50:29 | [diff] [blame] | 665 | // Testing that the media browser test does fail on plugin crash. |
jrummell | fed298d2 | 2015-07-01 00:26:51 | [diff] [blame] | 666 | IN_PROC_BROWSER_TEST_F(ECKEncryptedMediaTest, CDMExpectedCrash) { |
[email protected] | 1be9fa07 | 2014-03-21 22:50:29 | [diff] [blame] | 667 | // Plugin crash is not ignored by default, the test is expected to fail. |
jrummell | 35c1aa88 | 2016-11-16 00:49:15 | [diff] [blame] | 668 | EXPECT_NONFATAL_FAILURE(TestNonPlaybackCases(kExternalClearKeyCrashKeySystem, |
| 669 | kEmeSessionClosedAndError), |
| 670 | "Failing test due to plugin crash."); |
[email protected] | 1be9fa07 | 2014-03-21 22:50:29 | [diff] [blame] | 671 | } |
| 672 | |
xhwang | 0c617e11 | 2014-09-19 17:33:24 | [diff] [blame] | 673 | IN_PROC_BROWSER_TEST_F(ECKEncryptedMediaTest, FileIOTest) { |
xhwang | 640ef5d | 2016-08-17 16:46:08 | [diff] [blame] | 674 | TestNonPlaybackCases(kExternalClearKeyFileIOTestKeySystem, kUnitTestSuccess); |
| 675 | } |
| 676 | |
| 677 | // TODO(xhwang): Investigate how to fake capturing activities to test the |
| 678 | // network link detection logic in OutputProtectionProxy. |
| 679 | IN_PROC_BROWSER_TEST_F(ECKEncryptedMediaTest, OutputProtectionTest) { |
| 680 | TestNonPlaybackCases(kExternalClearKeyOutputProtectionTestKeySystem, |
| 681 | kUnitTestSuccess); |
[email protected] | 0af5dfa | 2014-02-07 22:33:44 | [diff] [blame] | 682 | } |
| 683 | |
xhwang | 382935d | 2016-10-27 22:11:20 | [diff] [blame] | 684 | IN_PROC_BROWSER_TEST_F(ECKEncryptedMediaTest, PlatformVerificationTest) { |
| 685 | TestNonPlaybackCases(kExternalClearKeyPlatformVerificationTestKeySystem, |
| 686 | kUnitTestSuccess); |
| 687 | } |
| 688 | |
xhwang | 0cfb528 | 2016-08-25 03:33:25 | [diff] [blame] | 689 | IN_PROC_BROWSER_TEST_F(ECKEncryptedMediaTest, Renewal) { |
| 690 | TestPlaybackCase(kExternalClearKeyRenewalKeySystem, kNoSessionToLoad, kEnded); |
| 691 | } |
| 692 | |
[email protected] | 0af5dfa | 2014-02-07 22:33:44 | [diff] [blame] | 693 | IN_PROC_BROWSER_TEST_F(ECKEncryptedMediaTest, LoadLoadableSession) { |
xhwang | 0cfb528 | 2016-08-25 03:33:25 | [diff] [blame] | 694 | TestPlaybackCase(kExternalClearKeyKeySystem, kLoadableSession, kEnded); |
[email protected] | 0af5dfa | 2014-02-07 22:33:44 | [diff] [blame] | 695 | } |
| 696 | |
| 697 | IN_PROC_BROWSER_TEST_F(ECKEncryptedMediaTest, LoadUnknownSession) { |
xhwang | 0cfb528 | 2016-08-25 03:33:25 | [diff] [blame] | 698 | TestPlaybackCase(kExternalClearKeyKeySystem, kUnknownSession, |
| 699 | kEmeSessionNotFound); |
[email protected] | 34afd58 | 2013-12-20 07:26:18 | [diff] [blame] | 700 | } |
Xiaohan Wang | 439859f3 | 2017-06-06 22:55:24 | [diff] [blame^] | 701 | |
| 702 | const char kExternalClearKeyDecryptOnlyKeySystem[] = |
| 703 | "org.chromium.externalclearkey.decryptonly"; |
| 704 | |
| 705 | IN_PROC_BROWSER_TEST_F(ECKEncryptedMediaTest, DecryptOnly_VideoAudio_WebM) { |
| 706 | RunSimpleEncryptedMediaTest( |
| 707 | "bear-320x240-av_enc-av.webm", kWebMVorbisAudioVP8Video, |
| 708 | kExternalClearKeyDecryptOnlyKeySystem, SrcType::MSE); |
| 709 | } |
| 710 | |
| 711 | #if BUILDFLAG(USE_PROPRIETARY_CODECS) |
| 712 | IN_PROC_BROWSER_TEST_F(ECKEncryptedMediaTest, DecryptOnly_VideoOnly_MP4_VP9) { |
| 713 | RunSimpleEncryptedMediaTest( |
| 714 | "bear-320x240-v_frag-vp9-cenc.mp4", kMP4VideoVp9Only, |
| 715 | kExternalClearKeyDecryptOnlyKeySystem, SrcType::MSE); |
| 716 | } |
| 717 | #endif // BUILDFLAG(USE_PROPRIETARY_CODECS) |
xhwang | c394103 | 2017-03-20 18:50:35 | [diff] [blame] | 718 | #endif // BUILDFLAG(ENABLE_PEPPER_CDMS) |
jrummell | c467d23 | 2014-10-21 17:55:22 | [diff] [blame] | 719 | |
xhwang | c394103 | 2017-03-20 18:50:35 | [diff] [blame] | 720 | #if BUILDFLAG(ENABLE_CDM_HOST_VERIFICATION) |
xhwang | 785a834 | 2017-01-26 06:46:39 | [diff] [blame] | 721 | IN_PROC_BROWSER_TEST_F(ECKEncryptedMediaTest, VerifyCdmHostTest) { |
| 722 | TestNonPlaybackCases(kExternalClearKeyVerifyCdmHostTestKeySystem, |
| 723 | kUnitTestSuccess); |
| 724 | } |
xhwang | c394103 | 2017-03-20 18:50:35 | [diff] [blame] | 725 | #endif // BUILDFLAG(ENABLE_CDM_HOST_VERIFICATION) |
xhwang | 65c2303 | 2017-02-17 04:37:42 | [diff] [blame] | 726 | |
| 727 | } // namespace chrome |