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