blob: 7b97a96134e6738f63226c1e4ba7f9fd7bb3b56a [file] [log] [blame]
[email protected]63dc9072013-09-12 06:20:471// 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
dchengc16dc8092016-04-08 23:12:565#include <memory>
Victor Costanaeb7f8e2018-04-06 19:05:266#include <tuple>
dchenge73d8520c2015-12-27 01:19:097#include <utility>
8
[email protected]63dc9072013-09-12 06:20:479#include "base/command_line.h"
10#include "base/path_service.h"
xhwang65c23032017-02-17 04:37:4211#include "base/strings/string_number_conversions.h"
[email protected]63dc9072013-09-12 06:20:4712#include "base/strings/utf_string_conversions.h"
Xiaohan Wang4b319712017-06-22 22:02:3913#include "base/test/scoped_feature_list.h"
jrummell90f8b202017-05-05 17:21:3914#include "base/threading/thread_restrictions.h"
avi6846aef2015-12-26 01:09:3815#include "build/build_config.h"
[email protected]63dc9072013-09-12 06:20:4716#include "chrome/browser/media/media_browsertest.h"
[email protected]df06a3e2014-01-31 21:36:5917#include "chrome/browser/media/test_license_server.h"
18#include "chrome/browser/media/wv_test_license_server_config.h"
xhwangd252d7b52017-02-08 18:52:3619#include "chrome/browser/profiles/profile.h"
[email protected]63dc9072013-09-12 06:20:4720#include "chrome/browser/ui/browser.h"
21#include "chrome/browser/ui/tabs/tab_strip_model.h"
22#include "chrome/common/chrome_switches.h"
xhwangd252d7b52017-02-08 18:52:3623#include "chrome/common/pref_names.h"
xhwang3be44be2016-05-25 17:24:4924#include "chrome/test/base/test_launcher_utils.h"
xhwangd252d7b52017-02-08 18:52:3625#include "components/prefs/pref_service.h"
Xiaohan Wangcc031eb12017-11-03 08:02:2126#include "components/variations/variations_switches.h"
brettw90e92602015-10-10 00:12:4027#include "content/public/common/content_switches.h"
[email protected]63dc9072013-09-12 06:20:4728#include "content/public/test/browser_test_utils.h"
xhwang34879342017-02-11 23:22:3329#include "media/base/key_system_names.h"
kqyangf93bb7b2016-12-03 02:28:1930#include "media/base/media_switches.h"
Xiaohan Wangf367d1082018-04-20 19:50:5531#include "media/cdm/supported_cdm_versions.h"
Scott Violeta35f9a42018-03-22 22:00:4432#include "media/media_buildflags.h"
[email protected]1be9fa072014-03-21 22:50:2933#include "testing/gtest/include/gtest/gtest-spi.h"
brettwc5fcdd02016-10-12 07:25:1234
wychen7b07e7b2017-01-10 17:48:2935#if defined(OS_WIN)
36#include "base/win/windows_version.h"
37#endif
38
Xiaohan Wang3a2df1e2017-07-24 18:34:4439#if BUILDFLAG(ENABLE_LIBRARY_CDMS)
Xiaohan Wangfef7061a2017-09-14 02:41:1240#include "chrome/browser/media/library_cdm_test_helper.h"
Xiaohan Wang17d4ffa2017-06-06 19:10:1141#include "media/cdm/cdm_paths.h"
[email protected]63dc9072013-09-12 06:20:4742#endif
[email protected]1825e772013-10-08 06:39:1143
xhwangb9417142016-05-18 22:23:3644#include "widevine_cdm_version.h" // In SHARED_INTERMEDIATE_DIR.
[email protected]63dc9072013-09-12 06:20:4745
[email protected]63dc9072013-09-12 06:20:4746// Available key systems.
[email protected]a32ef592014-03-07 19:11:1547const char kClearKeyKeySystem[] = "org.w3.clearkey";
[email protected]ab998e82013-11-22 20:31:3548const char kExternalClearKeyKeySystem[] = "org.chromium.externalclearkey";
xhwang640ef5d2016-08-17 16:46:0849
Xiaohan Wang9a93b23c2017-08-01 17:06:0950#if BUILDFLAG(ENABLE_LIBRARY_CDMS)
xhwang640ef5d2016-08-17 16:46:0851// 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 Wangdaf577f2017-12-21 21:30:5654// - media/test/data/eme_player_js/player_utils.js
xhwang640ef5d2016-08-17 16:46:0855// - AddExternalClearKey() in chrome_key_systems.cc
56// - CreateCdmInstance() in clear_key_cdm.cc
Xiaohan Wangf0bf3de2018-01-06 21:23:3057const char kExternalClearKeyMessageTypeTestKeySystem[] =
58 "org.chromium.externalclearkey.messagetypetest";
[email protected]34afd582013-12-20 07:26:1859const char kExternalClearKeyFileIOTestKeySystem[] =
60 "org.chromium.externalclearkey.fileiotest";
[email protected]ab998e82013-11-22 20:31:3561const char kExternalClearKeyInitializeFailKeySystem[] =
62 "org.chromium.externalclearkey.initializefail";
xhwang640ef5d2016-08-17 16:46:0863const char kExternalClearKeyOutputProtectionTestKeySystem[] =
64 "org.chromium.externalclearkey.outputprotectiontest";
xhwang382935d2016-10-27 22:11:2065const char kExternalClearKeyPlatformVerificationTestKeySystem[] =
66 "org.chromium.externalclearkey.platformverificationtest";
[email protected]a27d34ab2014-01-09 04:23:2967const char kExternalClearKeyCrashKeySystem[] =
68 "org.chromium.externalclearkey.crash";
xhwangc3941032017-03-20 18:50:3569#if BUILDFLAG(ENABLE_CDM_HOST_VERIFICATION)
xhwang785a8342017-01-26 06:46:3970const char kExternalClearKeyVerifyCdmHostTestKeySystem[] =
71 "org.chromium.externalclearkey.verifycdmhosttest";
xhwangc3941032017-03-20 18:50:3572#endif
John Rummelleff649e52017-07-20 01:11:5973const char kExternalClearKeyStorageIdTestKeySystem[] =
74 "org.chromium.externalclearkey.storageidtest";
Xiaohan Wangdaf577f2017-12-21 21:30:5675const char kExternalClearKeyCdmProxyTestKeySystem[] =
76 "org.chromium.externalclearkey.cdmproxytest";
Xiaohan Wang9a93b23c2017-08-01 17:06:0977#endif
[email protected]63dc9072013-09-12 06:20:4778
79// Supported media types.
servolk0b2146782016-08-30 03:47:4580const char kWebMVorbisAudioOnly[] = "audio/webm; codecs=\"vorbis\"";
servolk0b2146782016-08-30 03:47:4581const char kWebMVorbisAudioVP8Video[] = "video/webm; codecs=\"vorbis, vp8\"";
82const char kWebMOpusAudioVP9Video[] = "video/webm; codecs=\"opus, vp9\"";
jamescook6107ed82014-11-06 06:59:2183const char kWebMVP9VideoOnly[] = "video/webm; codecs=\"vp9\"";
Xiaohan Wang9a93b23c2017-08-01 17:06:0984#if BUILDFLAG(ENABLE_LIBRARY_CDMS)
85const char kWebMVP8VideoOnly[] = "video/webm; codecs=\"vp8\"";
86#endif
brettw68c77532017-01-21 00:28:0687#if BUILDFLAG(USE_PROPRIETARY_CODECS)
John Rummell6d369e02017-08-31 21:12:2988const char kMP4VideoOnly[] = "video/mp4; codecs=\"avc1.64001E\"";
kqyangbfe10302017-05-06 19:06:4189const char kMP4VideoVp9Only[] =
90 "video/mp4; codecs=\"vp09.00.10.08.01.02.02.02.00\"";
brettw68c77532017-01-21 00:28:0691#endif // BUILDFLAG(USE_PROPRIETARY_CODECS)
[email protected]63dc9072013-09-12 06:20:4792
[email protected]0af5dfa2014-02-07 22:33:4493// Sessions to load.
94const char kNoSessionToLoad[] = "";
Xiaohan Wang9a93b23c2017-08-01 17:06:0995#if BUILDFLAG(ENABLE_LIBRARY_CDMS)
[email protected]0af5dfa2014-02-07 22:33:4496const char kLoadableSession[] = "LoadableSession";
97const char kUnknownSession[] = "UnknownSession";
Xiaohan Wang9a93b23c2017-08-01 17:06:0998#endif
[email protected]0af5dfa2014-02-07 22:33:4499
[email protected]2e850f12013-09-18 01:27:29100// EME-specific test results and errors.
xhwang640ef5d2016-08-17 16:46:08101const char kUnitTestSuccess[] = "UNIT_TEST_SUCCESS";
Xiaohan Wangada25fe2017-07-24 21:24:24102const char kEmeUnitTestFailure[] = "UNIT_TEST_FAILURE";
jrummell0c6ba542015-07-08 18:04:44103const char kEmeNotSupportedError[] = "NOTSUPPORTEDERROR";
104const char kEmeGenerateRequestFailed[] = "EME_GENERATEREQUEST_FAILED";
jrummell14fae6f2015-07-10 20:40:15105const char kEmeSessionNotFound[] = "EME_SESSION_NOT_FOUND";
jrummell0c6ba542015-07-08 18:04:44106const char kEmeLoadFailed[] = "EME_LOAD_FAILED";
107const char kEmeUpdateFailed[] = "EME_UPDATE_FAILED";
108const char kEmeErrorEvent[] = "EME_ERROR_EVENT";
109const char kEmeMessageUnexpectedType[] = "EME_MESSAGE_UNEXPECTED_TYPE";
ddorwinfdb9a2b2016-02-22 22:25:10110const char kEmeRenewalMissingHeader[] = "EME_RENEWAL_MISSING_HEADER";
Xiaohan Wang9a93b23c2017-08-01 17:06:09111#if BUILDFLAG(ENABLE_LIBRARY_CDMS)
jrummell35c1aa882016-11-16 00:49:15112const char kEmeSessionClosedAndError[] = "EME_SESSION_CLOSED_AND_ERROR";
Xiaohan Wang9a93b23c2017-08-01 17:06:09113#endif
[email protected]e11d89d2014-06-19 11:36:31114
115const char kDefaultEmePlayer[] = "eme_player.html";
[email protected]63dc9072013-09-12 06:20:47116
117// The type of video src used to load media.
xhwang65c23032017-02-17 04:37:42118enum class SrcType { SRC, MSE };
119
xhwang65c23032017-02-17 04:37:42120// Must be in sync with CONFIG_CHANGE_TYPE in eme_player_js/global.js
121enum class ConfigChangeType {
122 CLEAR_TO_CLEAR = 0,
123 CLEAR_TO_ENCRYPTED = 1,
124 ENCRYPTED_TO_CLEAR = 2,
125 ENCRYPTED_TO_ENCRYPTED = 3,
[email protected]63dc9072013-09-12 06:20:47126};
127
jrummellb3944632015-03-14 00:19:42128// Whether the video should be played once or twice.
patricialor58397dcb2017-02-07 08:42:50129enum class PlayCount { ONCE, TWICE };
jrummellb3944632015-03-14 00:19:42130
jrummellc015cb962015-07-17 00:41:30131// Format of a container when testing different streams.
132enum class EncryptedContainer {
133 CLEAR_WEBM,
134 CLEAR_MP4,
135 ENCRYPTED_WEBM,
136 ENCRYPTED_MP4
137};
138
[email protected]e6bf64142013-10-18 23:07:54139// Base class for encrypted media tests.
140class EncryptedMediaTestBase : public MediaBrowserTest {
[email protected]63dc9072013-09-12 06:20:47141 public:
[email protected]ab998e82013-11-22 20:31:35142 bool IsExternalClearKey(const std::string& key_system) {
ddorwin40312df2016-02-26 01:25:01143 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]63dc9072013-09-12 06:20:47147 }
148
[email protected]1825e772013-10-08 06:39:11149#if defined(WIDEVINE_CDM_AVAILABLE)
[email protected]ab998e82013-11-22 20:31:35150 bool IsWidevine(const std::string& key_system) {
151 return key_system == kWidevineKeySystem;
[email protected]1825e772013-10-08 06:39:11152 }
153#endif // defined(WIDEVINE_CDM_AVAILABLE)
154
Lei Zhangc5b042c2017-11-11 00:39:23155 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.ratn2636d972014-09-30 04:06:58159 base::StringPairs new_query_params = query_params;
[email protected]8a229322014-07-22 23:33:07160 StartLicenseServerIfNeeded(key_system, &new_query_params);
161 RunMediaTestPage(html_page, new_query_params, expected_title, true);
[email protected]df06a3e2014-01-31 21:36:59162 }
163
[email protected]0af5dfa2014-02-07 22:33:44164 // 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]df06a3e2014-01-31 21:36:59172 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]1825e772013-10-08 06:39:11176 SrcType src_type,
[email protected]0af5dfa2014-02-07 22:33:44177 const std::string& session_to_load,
[email protected]df06a3e2014-01-31 21:36:59178 bool force_invalid_response,
patricialor58397dcb2017-02-07 08:42:50179 PlayCount play_count,
[email protected]df06a3e2014-01-31 21:36:59180 const std::string& expected_title) {
anand.ratn2636d972014-09-30 04:06:58181 base::StringPairs query_params;
Xiaohan Wang72657e6c2017-07-25 18:45:52182 query_params.emplace_back("mediaFile", media_file);
183 query_params.emplace_back("mediaType", media_type);
184 query_params.emplace_back("keySystem", key_system);
xhwang65c23032017-02-17 04:37:42185 if (src_type == SrcType::MSE)
Xiaohan Wang72657e6c2017-07-25 18:45:52186 query_params.emplace_back("useMSE", "1");
[email protected]df06a3e2014-01-31 21:36:59187 if (force_invalid_response)
Xiaohan Wang72657e6c2017-07-25 18:45:52188 query_params.emplace_back("forceInvalidResponse", "1");
[email protected]0af5dfa2014-02-07 22:33:44189 if (!session_to_load.empty())
Xiaohan Wang72657e6c2017-07-25 18:45:52190 query_params.emplace_back("sessionToLoad", session_to_load);
patricialor58397dcb2017-02-07 08:42:50191 if (play_count == PlayCount::TWICE)
Xiaohan Wang72657e6c2017-07-25 18:45:52192 query_params.emplace_back("playTwice", "1");
[email protected]8a229322014-07-22 23:33:07193 RunEncryptedMediaTestPage(html_page, key_system, query_params,
[email protected]df06a3e2014-01-31 21:36:59194 expected_title);
[email protected]63dc9072013-09-12 06:20:47195 }
196
[email protected]df06a3e2014-01-31 21:36:59197 void RunSimpleEncryptedMediaTest(const std::string& media_file,
198 const std::string& media_type,
199 const std::string& key_system,
ddorwinfdb9a2b2016-02-22 22:25:10200 SrcType src_type) {
cm.sanchi2fd33362017-11-14 03:20:36201 std::string expected_title = media::kEnded;
jrummell0c6ba542015-07-08 18:04:44202 if (!IsPlayBackPossible(key_system)) {
ddorwinfdb9a2b2016-02-22 22:25:10203 expected_title = kEmeUpdateFailed;
jrummell0c6ba542015-07-08 18:04:44204 }
[email protected]1825e772013-10-08 06:39:11205
jrummellb3944632015-03-14 00:19:42206 RunEncryptedMediaTest(kDefaultEmePlayer, media_file, media_type, key_system,
patricialor58397dcb2017-02-07 08:42:50207 src_type, kNoSessionToLoad, false, PlayCount::ONCE,
ddorwinfdb9a2b2016-02-22 22:25:10208 expected_title);
[email protected]df06a3e2014-01-31 21:36:59209 // Check KeyMessage received for all key systems.
210 bool receivedKeyMessage = false;
211 EXPECT_TRUE(content::ExecuteScriptAndExtractBool(
212 browser()->tab_strip_model()->GetActiveWebContents(),
[email protected]e11d89d2014-06-19 11:36:31213 "window.domAutomationController.send("
214 "document.querySelector('video').receivedKeyMessage);",
[email protected]df06a3e2014-01-31 21:36:59215 &receivedKeyMessage));
216 EXPECT_TRUE(receivedKeyMessage);
217 }
218
[email protected]8a229322014-07-22 23:33:07219 // Starts a license server if available for the |key_system| and adds a
220 // 'licenseServerURL' query parameter to |query_params|.
[email protected]df06a3e2014-01-31 21:36:59221 void StartLicenseServerIfNeeded(const std::string& key_system,
anand.ratn2636d972014-09-30 04:06:58222 base::StringPairs* query_params) {
dchengc16dc8092016-04-08 23:12:56223 std::unique_ptr<TestLicenseServerConfig> config =
224 GetServerConfig(key_system);
[email protected]df06a3e2014-01-31 21:36:59225 if (!config)
226 return;
dchenge73d8520c2015-12-27 01:19:09227 license_server_.reset(new TestLicenseServer(std::move(config)));
jrummell90f8b202017-05-05 17:21:39228 {
Francois Doraye6fb2d02017-10-18 21:29:13229 base::ScopedAllowBlockingForTesting allow_blocking;
jrummell90f8b202017-05-05 17:21:39230 EXPECT_TRUE(license_server_->Start());
231 }
[email protected]8a229322014-07-22 23:33:07232 query_params->push_back(
233 std::make_pair("licenseServerURL", license_server_->GetServerURL()));
[email protected]df06a3e2014-01-31 21:36:59234 }
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
dchengc16dc8092016-04-08 23:12:56244 std::unique_ptr<TestLicenseServerConfig> GetServerConfig(
[email protected]df06a3e2014-01-31 21:36:59245 const std::string& key_system) {
246#if defined(WIDEVINE_CDM_AVAILABLE)
247 if (IsWidevine(key_system)) {
dchengc16dc8092016-04-08 23:12:56248 std::unique_ptr<TestLicenseServerConfig> config(
249 new WVTestLicenseServerConfig);
[email protected]df06a3e2014-01-31 21:36:59250 if (config->IsPlatformSupported())
dcheng7c133cc2015-12-31 06:57:59251 return config;
[email protected]df06a3e2014-01-31 21:36:59252 }
253#endif // defined(WIDEVINE_CDM_AVAILABLE)
dcheng7c133cc2015-12-31 06:57:59254 return nullptr;
[email protected]1825e772013-10-08 06:39:11255 }
256
[email protected]63dc9072013-09-12 06:20:47257 protected:
dchengc16dc8092016-04-08 23:12:56258 std::unique_ptr<TestLicenseServer> license_server_;
[email protected]df06a3e2014-01-31 21:36:59259
[email protected]2e850f12013-09-18 01:27:29260 // We want to fail quickly when a test fails because an error is encountered.
dchengd7e84a052014-10-22 00:18:51261 void AddWaitForTitles(content::TitleWatcher* title_watcher) override {
[email protected]2e850f12013-09-18 01:27:29262 MediaBrowserTest::AddWaitForTitles(title_watcher);
Xiaohan Wangada25fe2017-07-24 21:24:24263 title_watcher->AlsoWaitForTitle(base::ASCIIToUTF16(kEmeUnitTestFailure));
[email protected]6778fed2013-12-24 20:09:37264 title_watcher->AlsoWaitForTitle(base::ASCIIToUTF16(kEmeNotSupportedError));
jrummell0c6ba542015-07-08 18:04:44265 title_watcher->AlsoWaitForTitle(
266 base::ASCIIToUTF16(kEmeGenerateRequestFailed));
jrummell14fae6f2015-07-10 20:40:15267 title_watcher->AlsoWaitForTitle(base::ASCIIToUTF16(kEmeSessionNotFound));
jrummell0c6ba542015-07-08 18:04:44268 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(
ddorwinfdb9a2b2016-02-22 22:25:10274 base::ASCIIToUTF16(kEmeRenewalMissingHeader));
[email protected]2e850f12013-09-18 01:27:29275 }
276
avi556c05022014-12-22 23:31:43277 void SetUpCommandLine(base::CommandLine* command_line) override {
Mounir Lamouri163e1b42017-12-11 17:34:17278 command_line->AppendSwitchASCII(
279 switches::kAutoplayPolicy,
280 switches::autoplay::kNoUserGestureRequiredPolicy);
Xiaohan Wangada25fe2017-07-24 21:24:24281 command_line->AppendSwitchASCII(switches::kEnableBlinkFeatures,
282 "EncryptedMediaHdcpPolicyCheck");
[email protected]2289b432014-08-08 17:52:11283 }
284
Xiaohan Wang3a2df1e2017-07-24 18:34:44285#if BUILDFLAG(ENABLE_LIBRARY_CDMS)
xhwang3be44be2016-05-25 17:24:49286 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 Wang3a2df1e2017-07-24 18:34:44292#endif // BUILDFLAG(ENABLE_LIBRARY_CDMS)
xhwang3be44be2016-05-25 17:24:49293
[email protected]df06a3e2014-01-31 21:36:59294 void SetUpCommandLineForKeySystem(const std::string& key_system,
avi556c05022014-12-22 23:31:43295 base::CommandLine* command_line) {
[email protected]df06a3e2014-01-31 21:36:59296 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 Wang3a2df1e2017-07-24 18:34:44302#if BUILDFLAG(ENABLE_LIBRARY_CDMS)
[email protected]e6bf64142013-10-18 23:07:54303 if (IsExternalClearKey(key_system)) {
Xiaohan Wangfa6b26332018-01-11 23:28:31304 RegisterClearKeyCdm(command_line);
Xiaohan Wang6114a3e2018-03-19 22:36:11305 std::vector<base::Feature> enabled_features = {
306 media::kExternalClearKeyForTesting};
Xiaohan Wang6114a3e2018-03-19 22:36:11307 scoped_feature_list_.InitWithFeatures(enabled_features, {});
[email protected]e6bf64142013-10-18 23:07:54308 }
Xiaohan Wang3a2df1e2017-07-24 18:34:44309#endif // BUILDFLAG(ENABLE_LIBRARY_CDMS)
Xiaohan Wangcc031eb12017-11-03 08:02:21310 }
311
Xiaohan Wang4b319712017-06-22 22:02:39312 base::test::ScopedFeatureList scoped_feature_list_;
[email protected]e6bf64142013-10-18 23:07:54313};
314
Xiaohan Wang3a2df1e2017-07-24 18:34:44315#if BUILDFLAG(ENABLE_LIBRARY_CDMS)
Xiaohan Wangf367d1082018-04-20 19:50:55316// 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
319class ECKEncryptedMediaTest : public EncryptedMediaTestBase,
320 public testing::WithParamInterface<int> {
[email protected]0af5dfa2014-02-07 22:33:44321 public:
Xiaohan Wangf367d1082018-04-20 19:50:55322 int GetCdmInterfaceVersion() { return GetParam(); }
323
Xiaohan Wang4b319712017-06-22 22:02:39324 // We use special |key_system| names to do non-playback related tests,
325 // e.g. kExternalClearKeyFileIOTestKeySystem is used to test file IO.
[email protected]0af5dfa2014-02-07 22:33:44326 void TestNonPlaybackCases(const std::string& key_system,
327 const std::string& expected_title) {
Xiaohan Wang2e9c6412018-03-06 22:53:51328 // Make sure the Clear Key CDM is properly registered in CdmRegistry.
329 EXPECT_TRUE(IsLibraryCdmRegistered(media::kClearKeyCdmGuid));
Xiaohan Wangfef7061a2017-09-14 02:41:12330
[email protected]0af5dfa2014-02-07 22:33:44331 // Since we do not test playback, arbitrarily choose a test file and source
332 // type.
ddorwinfdb9a2b2016-02-22 22:25:10333 RunEncryptedMediaTest(kDefaultEmePlayer, "bear-a_enc-a.webm",
xhwang65c23032017-02-17 04:37:42334 kWebMVorbisAudioOnly, key_system, SrcType::SRC,
patricialor58397dcb2017-02-07 08:42:50335 kNoSessionToLoad, false, PlayCount::ONCE,
servolk0b2146782016-08-30 03:47:45336 expected_title);
jrummell19f2c902015-02-11 01:17:50337 }
338
xhwang0cfb5282016-08-25 03:33:25339 void TestPlaybackCase(const std::string& key_system,
340 const std::string& session_to_load,
jrummell19f2c902015-02-11 01:17:50341 const std::string& expected_title) {
342 RunEncryptedMediaTest(kDefaultEmePlayer, "bear-320x240-v_enc-v.webm",
Xiaohan Wang4b319712017-06-22 22:02:39343 kWebMVP8VideoOnly, key_system, SrcType::MSE,
xhwang65c23032017-02-17 04:37:42344 session_to_load, false, PlayCount::ONCE,
345 expected_title);
jrummell19f2c902015-02-11 01:17:50346 }
347
John Rummelld5069c842018-03-09 00:41:55348#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 Wangdaf577f2017-12-21 21:30:56359 protected:
360 void SetUpCommandLine(base::CommandLine* command_line) override {
361 EncryptedMediaTestBase::SetUpCommandLine(command_line);
Xiaohan Wangf367d1082018-04-20 19:50:55362 SetUpCommandLineForKeySystem(kExternalClearKeyKeySystem, command_line);
363 // Override enabled CDM interface version for testing.
364 command_line->AppendSwitchASCII(
365 switches::kOverrideEnabledCdmInterfaceVersion,
366 base::IntToString(GetCdmInterfaceVersion()));
Xiaohan Wangdaf577f2017-12-21 21:30:56367 }
368};
369
Xiaohan Wang3a2df1e2017-07-24 18:34:44370#endif // BUILDFLAG(ENABLE_LIBRARY_CDMS)
[email protected]e6bf64142013-10-18 23:07:54371
372// Tests encrypted media playback with a combination of parameters:
373// - char*: Key system name.
jrummell19f2c902015-02-11 01:17:50374// - SrcType: Use MSE or SRC.
[email protected]e6bf64142013-10-18 23:07:54375//
Xiaohan Wangf367d1082018-04-20 19:50:55376// 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 Costanaeb7f8e2018-04-06 19:05:26381class EncryptedMediaTest
382 : public EncryptedMediaTestBase,
383 public testing::WithParamInterface<std::tuple<const char*, SrcType>> {
[email protected]e6bf64142013-10-18 23:07:54384 public:
Victor Costanaeb7f8e2018-04-06 19:05:26385 std::string CurrentKeySystem() { return std::get<0>(GetParam()); }
[email protected]e6bf64142013-10-18 23:07:54386
Victor Costanaeb7f8e2018-04-06 19:05:26387 SrcType CurrentSourceType() { return std::get<1>(GetParam()); }
[email protected]e6bf64142013-10-18 23:07:54388
[email protected]df06a3e2014-01-31 21:36:59389 void TestSimplePlayback(const std::string& encrypted_media,
390 const std::string& media_type) {
ddorwinfdb9a2b2016-02-22 22:25:10391 RunSimpleEncryptedMediaTest(encrypted_media, media_type, CurrentKeySystem(),
392 CurrentSourceType());
[email protected]e6bf64142013-10-18 23:07:54393 }
394
jrummellb3944632015-03-14 00:19:42395 void TestMultiplePlayback(const std::string& encrypted_media,
396 const std::string& media_type) {
jrummelld9dc7902015-03-16 20:59:28397 DCHECK(IsPlayBackPossible(CurrentKeySystem()));
jrummellb3944632015-03-14 00:19:42398 RunEncryptedMediaTest(kDefaultEmePlayer, encrypted_media, media_type,
399 CurrentKeySystem(), CurrentSourceType(),
cm.sanchi2fd33362017-11-14 03:20:36400 kNoSessionToLoad, false, PlayCount::TWICE,
401 media::kEnded);
jrummellb3944632015-03-14 00:19:42402 }
403
[email protected]df06a3e2014-01-31 21:36:59404 void RunInvalidResponseTest() {
ddorwinfdb9a2b2016-02-22 22:25:10405 RunEncryptedMediaTest(kDefaultEmePlayer, "bear-320x240-av_enc-av.webm",
servolk0b2146782016-08-30 03:47:45406 kWebMVorbisAudioVP8Video, CurrentKeySystem(),
ddorwinfdb9a2b2016-02-22 22:25:10407 CurrentSourceType(), kNoSessionToLoad, true,
patricialor58397dcb2017-02-07 08:42:50408 PlayCount::ONCE, kEmeUpdateFailed);
[email protected]df06a3e2014-01-31 21:36:59409 }
410
[email protected]e6bf64142013-10-18 23:07:54411 void TestFrameSizeChange() {
servolk0b2146782016-08-30 03:47:45412 RunEncryptedMediaTest(
413 "encrypted_frame_size_change.html", "frame_size_change-av_enc-v.webm",
414 kWebMVorbisAudioVP8Video, CurrentKeySystem(), CurrentSourceType(),
cm.sanchi2fd33362017-11-14 03:20:36415 kNoSessionToLoad, false, PlayCount::ONCE, media::kEnded);
[email protected]e6bf64142013-10-18 23:07:54416 }
417
xhwang65c23032017-02-17 04:37:42418 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.ratn2636d972014-09-30 04:06:58431 base::StringPairs query_params;
Xiaohan Wang72657e6c2017-07-25 18:45:52432 query_params.emplace_back("keySystem", CurrentKeySystem());
433 query_params.emplace_back(
xhwang65c23032017-02-17 04:37:42434 "configChangeType",
Xiaohan Wang72657e6c2017-07-25 18:45:52435 base::IntToString(static_cast<int>(config_change_type)));
xhwang65c23032017-02-17 04:37:42436 RunEncryptedMediaTestPage("mse_config_change.html", CurrentKeySystem(),
cm.sanchi2fd33362017-11-14 03:20:36437 query_params, media::kEnded);
[email protected]e6bf64142013-10-18 23:07:54438 }
439
Xiaohan Wangada25fe2017-07-24 21:24:24440 void TestPolicyCheck() {
Xiaohan Wangada25fe2017-07-24 21:24:24441 base::StringPairs query_params;
442 // We do not care about playback so choose an arbitrary media file.
Xiaohan Wang72657e6c2017-07-25 18:45:52443 query_params.emplace_back("mediaFile", "bear-a_enc-a.webm");
444 query_params.emplace_back("mediaType", kWebMVorbisAudioOnly);
Xiaohan Wangada25fe2017-07-24 21:24:24445 if (CurrentSourceType() == SrcType::MSE)
Xiaohan Wang72657e6c2017-07-25 18:45:52446 query_params.emplace_back("useMSE", "1");
447 query_params.emplace_back("keySystem", CurrentKeySystem());
448 query_params.emplace_back("policyCheck", "1");
Xiaohan Wangada25fe2017-07-24 21:24:24449 RunEncryptedMediaTestPage(kDefaultEmePlayer, CurrentKeySystem(),
450 query_params, kUnitTestSuccess);
451 }
452
jrummellc015cb962015-07-17 00:41:30453 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) {
jrummellc015cb962015-07-17 00:41:30470 base::StringPairs query_params;
Xiaohan Wang72657e6c2017-07-25 18:45:52471 query_params.emplace_back("keySystem", CurrentKeySystem());
472 query_params.emplace_back("runEncrypted", "1");
jrummellc015cb962015-07-17 00:41:30473 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.sanchi2fd33362017-11-14 03:20:36478 CurrentKeySystem(), query_params, media::kEnded);
jrummellc015cb962015-07-17 00:41:30479 }
480
xhwangd252d7b52017-02-08 18:52:36481 void DisableEncryptedMedia() {
482 PrefService* pref_service = browser()->profile()->GetPrefs();
Xiaohan Wang2ec4a6832017-11-15 00:55:51483 pref_service->SetBoolean(prefs::kEnableEncryptedMedia, false);
xhwangd252d7b52017-02-08 18:52:36484 }
485
[email protected]e6bf64142013-10-18 23:07:54486 protected:
avi556c05022014-12-22 23:31:43487 void SetUpCommandLine(base::CommandLine* command_line) override {
[email protected]e6bf64142013-10-18 23:07:54488 EncryptedMediaTestBase::SetUpCommandLine(command_line);
Xiaohan Wangf367d1082018-04-20 19:50:55489 SetUpCommandLineForKeySystem(CurrentKeySystem(), command_line);
[email protected]e6bf64142013-10-18 23:07:54490 }
[email protected]63dc9072013-09-12 06:20:47491};
492
[email protected]6479b192013-10-19 18:28:04493using ::testing::Combine;
494using ::testing::Values;
495
jrummell77419192014-10-31 21:40:44496INSTANTIATE_TEST_CASE_P(MSE_ClearKey,
[email protected]a32ef592014-03-07 19:11:15497 EncryptedMediaTest,
xhwang65c23032017-02-17 04:37:42498 Combine(Values(kClearKeyKeySystem),
Xiaohan Wang2e9c6412018-03-06 22:53:51499 Values(SrcType::MSE)));
[email protected]63dc9072013-09-12 06:20:47500
Xiaohan Wang2e9c6412018-03-06 22:53:51501// External Clear Key is currently only used on platforms that use library CDMs.
Xiaohan Wang3a2df1e2017-07-24 18:34:44502#if BUILDFLAG(ENABLE_LIBRARY_CDMS)
[email protected]1ab297a2014-03-26 04:52:12503INSTANTIATE_TEST_CASE_P(SRC_ExternalClearKey,
[email protected]a32ef592014-03-07 19:11:15504 EncryptedMediaTest,
505 Combine(Values(kExternalClearKeyKeySystem),
Xiaohan Wang2e9c6412018-03-06 22:53:51506 Values(SrcType::SRC)));
jam79bf1f6c2015-08-13 20:46:04507
[email protected]1ab297a2014-03-26 04:52:12508INSTANTIATE_TEST_CASE_P(MSE_ExternalClearKey,
[email protected]a32ef592014-03-07 19:11:15509 EncryptedMediaTest,
510 Combine(Values(kExternalClearKeyKeySystem),
Xiaohan Wang2e9c6412018-03-06 22:53:51511 Values(SrcType::MSE)));
Xiaohan Wang3a2df1e2017-07-24 18:34:44512#else // BUILDFLAG(ENABLE_LIBRARY_CDMS)
Xiaohan Wang439859f32017-06-06 22:55:24513// To reduce test time, only run ClearKey SRC tests when we are not running
514// ExternalClearKey SRC tests.
515INSTANTIATE_TEST_CASE_P(SRC_ClearKey,
[email protected]a32ef592014-03-07 19:11:15516 EncryptedMediaTest,
Xiaohan Wang439859f32017-06-06 22:55:24517 Combine(Values(kClearKeyKeySystem),
Xiaohan Wang2e9c6412018-03-06 22:53:51518 Values(SrcType::SRC)));
Xiaohan Wang3a2df1e2017-07-24 18:34:44519#endif // BUILDFLAG(ENABLE_LIBRARY_CDMS)
[email protected]63dc9072013-09-12 06:20:47520
[email protected]1825e772013-10-08 06:39:11521#if defined(WIDEVINE_CDM_AVAILABLE)
jonross5785b8662015-10-22 21:12:53522#if !defined(OS_CHROMEOS)
[email protected]1ab297a2014-03-26 04:52:12523INSTANTIATE_TEST_CASE_P(MSE_Widevine,
[email protected]a32ef592014-03-07 19:11:15524 EncryptedMediaTest,
xhwang65c23032017-02-17 04:37:42525 Combine(Values(kWidevineKeySystem),
Xiaohan Wang2e9c6412018-03-06 22:53:51526 Values(SrcType::MSE)));
jonross5785b8662015-10-22 21:12:53527#endif // !defined(OS_CHROMEOS)
[email protected]1825e772013-10-08 06:39:11528#endif // defined(WIDEVINE_CDM_AVAILABLE)
[email protected]63dc9072013-09-12 06:20:47529
[email protected]626e517c2014-08-19 00:49:46530IN_PROC_BROWSER_TEST_P(EncryptedMediaTest, Playback_AudioClearVideo_WebM) {
servolk0b2146782016-08-30 03:47:45531 TestSimplePlayback("bear-320x240-av_enc-a.webm", kWebMVorbisAudioVP8Video);
[email protected]63dc9072013-09-12 06:20:47532}
533
[email protected]626e517c2014-08-19 00:49:46534IN_PROC_BROWSER_TEST_P(EncryptedMediaTest, Playback_VideoAudio_WebM) {
servolk0b2146782016-08-30 03:47:45535 TestSimplePlayback("bear-320x240-av_enc-av.webm", kWebMVorbisAudioVP8Video);
[email protected]63dc9072013-09-12 06:20:47536}
537
Xiaohan Wang781d8752017-12-13 04:29:51538IN_PROC_BROWSER_TEST_P(EncryptedMediaTest, Playback_VideoClearAudio_WebM) {
servolk0b2146782016-08-30 03:47:45539 TestSimplePlayback("bear-320x240-av_enc-v.webm", kWebMVorbisAudioVP8Video);
[email protected]63dc9072013-09-12 06:20:47540}
541
kqyang2cf59b52016-10-10 22:16:17542IN_PROC_BROWSER_TEST_P(EncryptedMediaTest, Playback_VP9Video_WebM_Fullsample) {
543 TestSimplePlayback("bear-320x240-v-vp9_fullsample_enc-v.webm",
544 kWebMVP9VideoOnly);
545}
546
547IN_PROC_BROWSER_TEST_P(EncryptedMediaTest, Playback_VP9Video_WebM_Subsample) {
548 TestSimplePlayback("bear-320x240-v-vp9_subsample_enc-v.webm",
549 kWebMVP9VideoOnly);
[email protected]2b197ac72014-04-11 23:33:52550}
551
sandersd5ec6dcf2014-11-26 20:39:38552IN_PROC_BROWSER_TEST_P(EncryptedMediaTest, Playback_VideoAudio_WebM_Opus) {
servolk0b2146782016-08-30 03:47:45553 TestSimplePlayback("bear-320x240-opus-av_enc-av.webm",
554 kWebMOpusAudioVP9Video);
sandersd5ec6dcf2014-11-26 20:39:38555}
556
557IN_PROC_BROWSER_TEST_P(EncryptedMediaTest, Playback_VideoClearAudio_WebM_Opus) {
servolk0b2146782016-08-30 03:47:45558 TestSimplePlayback("bear-320x240-opus-av_enc-v.webm", kWebMOpusAudioVP9Video);
sandersd5ec6dcf2014-11-26 20:39:38559}
560
jrummellb3944632015-03-14 00:19:42561IN_PROC_BROWSER_TEST_P(EncryptedMediaTest, Playback_Multiple_VideoAudio_WebM) {
jrummelld9dc7902015-03-16 20:59:28562 if (!IsPlayBackPossible(CurrentKeySystem())) {
563 DVLOG(0) << "Skipping test - Playback_Multiple test requires playback.";
564 return;
565 }
servolk0b2146782016-08-30 03:47:45566 TestMultiplePlayback("bear-320x240-av_enc-av.webm", kWebMVorbisAudioVP8Video);
jrummellb3944632015-03-14 00:19:42567}
568
[email protected]626e517c2014-08-19 00:49:46569IN_PROC_BROWSER_TEST_P(EncryptedMediaTest, InvalidResponseKeyError) {
[email protected]df06a3e2014-01-31 21:36:59570 RunInvalidResponseTest();
571}
572
xhwang65c23032017-02-17 04:37:42573// Strictly speaking this is not an "encrypted" media test. Keep it here for
574// completeness.
575IN_PROC_BROWSER_TEST_P(EncryptedMediaTest, ConfigChangeVideo_ClearToClear) {
576 TestConfigChange(ConfigChangeType::CLEAR_TO_CLEAR);
577}
578
xhwangb2827d22017-02-24 22:57:33579IN_PROC_BROWSER_TEST_P(EncryptedMediaTest, ConfigChangeVideo_ClearToEncrypted) {
xhwang65c23032017-02-17 04:37:42580 TestConfigChange(ConfigChangeType::CLEAR_TO_ENCRYPTED);
581}
582
583IN_PROC_BROWSER_TEST_P(EncryptedMediaTest, ConfigChangeVideo_EncryptedToClear) {
584 TestConfigChange(ConfigChangeType::ENCRYPTED_TO_CLEAR);
585}
586
587IN_PROC_BROWSER_TEST_P(EncryptedMediaTest,
588 ConfigChangeVideo_EncryptedToEncrypted) {
589 TestConfigChange(ConfigChangeType::ENCRYPTED_TO_ENCRYPTED);
[email protected]1825e772013-10-08 06:39:11590}
591
dalecurtis71bec5192016-10-28 03:16:44592IN_PROC_BROWSER_TEST_P(EncryptedMediaTest, FrameSizeChangeVideo) {
[email protected]df06a3e2014-01-31 21:36:59593 if (!IsPlayBackPossible(CurrentKeySystem())) {
anujk.sharma9da298e12014-11-07 04:48:43594 DVLOG(0) << "Skipping test - FrameSizeChange test requires video playback.";
[email protected]df06a3e2014-01-31 21:36:59595 return;
596 }
[email protected]1825e772013-10-08 06:39:11597 TestFrameSizeChange();
[email protected]63dc9072013-09-12 06:20:47598}
599
Xiaohan Wangada25fe2017-07-24 21:24:24600IN_PROC_BROWSER_TEST_P(EncryptedMediaTest, PolicyCheck) {
601 TestPolicyCheck();
602}
603
xhwangd252d7b52017-02-08 18:52:36604IN_PROC_BROWSER_TEST_P(EncryptedMediaTest, EncryptedMediaDisabled) {
605 DisableEncryptedMedia();
xhwang34879342017-02-11 23:22:33606
607 // Clear Key key system is always supported.
cm.sanchi2fd33362017-11-14 03:20:36608 std::string expected_title = media::IsClearKey(CurrentKeySystem())
609 ? media::kEnded
610 : kEmeNotSupportedError;
xhwang34879342017-02-11 23:22:33611
xhwangd252d7b52017-02-08 18:52:36612 RunEncryptedMediaTest(kDefaultEmePlayer, "bear-a_enc-a.webm",
613 kWebMVorbisAudioOnly, CurrentKeySystem(),
614 CurrentSourceType(), kNoSessionToLoad, false,
xhwang34879342017-02-11 23:22:33615 PlayCount::ONCE, expected_title);
xhwangd252d7b52017-02-08 18:52:36616}
617
brettw68c77532017-01-21 00:28:06618#if BUILDFLAG(USE_PROPRIETARY_CODECS)
Xiaohan Wang70e545d22017-06-06 21:18:45619IN_PROC_BROWSER_TEST_P(EncryptedMediaTest, Playback_VideoOnly_MP4) {
[email protected]63dc9072013-09-12 06:20:47620 // MP4 without MSE is not support yet, http://crbug.com/170793.
xhwang65c23032017-02-17 04:37:42621 if (CurrentSourceType() != SrcType::MSE) {
anujk.sharma9da298e12014-11-07 04:48:43622 DVLOG(0) << "Skipping test; Can only play MP4 encrypted streams by MSE.";
[email protected]63dc9072013-09-12 06:20:47623 return;
624 }
[email protected]1825e772013-10-08 06:39:11625 TestSimplePlayback("bear-640x360-v_frag-cenc.mp4", kMP4VideoOnly);
[email protected]63dc9072013-09-12 06:20:47626}
627
John Rummelld5069c842018-03-09 00:41:55628IN_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
kqyangf93bb7b2016-12-03 02:28:19637IN_PROC_BROWSER_TEST_P(EncryptedMediaTest, Playback_VideoOnly_MP4_VP9) {
638 // MP4 without MSE is not support yet, http://crbug.com/170793.
xhwang65c23032017-02-17 04:37:42639 if (CurrentSourceType() != SrcType::MSE) {
kqyangf93bb7b2016-12-03 02:28:19640 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
jrummellc015cb962015-07-17 00:41:30646IN_PROC_BROWSER_TEST_P(EncryptedMediaTest,
647 Playback_EncryptedVideo_MP4_ClearAudio_WEBM) {
648 // MP4 without MSE is not support yet, http://crbug.com/170793.
xhwang65c23032017-02-17 04:37:42649 if (CurrentSourceType() != SrcType::MSE) {
jrummellc015cb962015-07-17 00:41:30650 DVLOG(0) << "Skipping test; Can only play MP4 encrypted streams by MSE.";
651 return;
652 }
jrummellc015cb962015-07-17 00:41:30653 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
661IN_PROC_BROWSER_TEST_P(EncryptedMediaTest,
662 Playback_ClearVideo_WEBM_EncryptedAudio_MP4) {
663 // MP4 without MSE is not support yet, http://crbug.com/170793.
xhwang65c23032017-02-17 04:37:42664 if (CurrentSourceType() != SrcType::MSE) {
jrummellc015cb962015-07-17 00:41:30665 DVLOG(0) << "Skipping test; Can only play MP4 encrypted streams by MSE.";
666 return;
667 }
jrummellc015cb962015-07-17 00:41:30668 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
676IN_PROC_BROWSER_TEST_P(EncryptedMediaTest,
677 Playback_EncryptedVideo_WEBM_EncryptedAudio_MP4) {
678 // MP4 without MSE is not support yet, http://crbug.com/170793.
xhwang65c23032017-02-17 04:37:42679 if (CurrentSourceType() != SrcType::MSE) {
jrummellc015cb962015-07-17 00:41:30680 DVLOG(0) << "Skipping test; Can only play MP4 encrypted streams by MSE.";
681 return;
682 }
jrummellc015cb962015-07-17 00:41:30683 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}
brettw68c77532017-01-21 00:28:06690#endif // BUILDFLAG(USE_PROPRIETARY_CODECS)
[email protected]63dc9072013-09-12 06:20:47691
Xiaohan Wang9a93b23c2017-08-01 17:06:09692#if BUILDFLAG(ENABLE_LIBRARY_CDMS)
[email protected]a941d4e572013-10-14 21:22:05693
Xiaohan Wangf367d1082018-04-20 19:50:55694// Test both CDM_9 and CDM_10.
Xiaohan Wangf89c6c52018-04-20 22:04:30695static_assert(media::CheckSupportedCdmInterfaceVersions(9, 11),
Xiaohan Wangf367d1082018-04-20 19:50:55696 "Mismatch between implementation and test coverage");
697INSTANTIATE_TEST_CASE_P(CDM_9, ECKEncryptedMediaTest, Values(9));
698INSTANTIATE_TEST_CASE_P(CDM_10, ECKEncryptedMediaTest, Values(10));
Xiaohan Wangf89c6c52018-04-20 22:04:30699INSTANTIATE_TEST_CASE_P(CDM_11, ECKEncryptedMediaTest, Values(11));
Xiaohan Wangf367d1082018-04-20 19:50:55700
701IN_PROC_BROWSER_TEST_P(ECKEncryptedMediaTest, InitializeCDMFail) {
jrummell87a2db52015-05-05 22:27:18702 TestNonPlaybackCases(kExternalClearKeyInitializeFailKeySystem,
703 kEmeNotSupportedError);
[email protected]a941d4e572013-10-14 21:22:05704}
[email protected]34afd582013-12-20 07:26:18705
jrummell35c1aa882016-11-16 00:49:15706// When CDM crashes, we should still get a decode error and all sessions should
707// be closed.
Morten Stenshorne03e855b2018-04-19 13:05:29708// Flaky: crbug.com/832800
Xiaohan Wangf367d1082018-04-20 19:50:55709IN_PROC_BROWSER_TEST_P(ECKEncryptedMediaTest, DISABLED_CDMCrashDuringDecode) {
[email protected]1be9fa072014-03-21 22:50:29710 IgnorePluginCrash();
jrummell35c1aa882016-11-16 00:49:15711 TestNonPlaybackCases(kExternalClearKeyCrashKeySystem,
712 kEmeSessionClosedAndError);
[email protected]a27d34ab2014-01-09 04:23:29713}
714
Xiaohan Wangf367d1082018-04-20 19:50:55715IN_PROC_BROWSER_TEST_P(ECKEncryptedMediaTest, FileIOTest) {
xhwang640ef5d2016-08-17 16:46:08716 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 Wangf367d1082018-04-20 19:50:55721IN_PROC_BROWSER_TEST_P(ECKEncryptedMediaTest, OutputProtectionTest) {
xhwang640ef5d2016-08-17 16:46:08722 TestNonPlaybackCases(kExternalClearKeyOutputProtectionTestKeySystem,
723 kUnitTestSuccess);
[email protected]0af5dfa2014-02-07 22:33:44724}
725
Xiaohan Wangf367d1082018-04-20 19:50:55726IN_PROC_BROWSER_TEST_P(ECKEncryptedMediaTest, PlatformVerificationTest) {
xhwang382935d2016-10-27 22:11:20727 TestNonPlaybackCases(kExternalClearKeyPlatformVerificationTestKeySystem,
728 kUnitTestSuccess);
729}
730
Tarun Bansalbf793272018-01-02 22:56:06731#if defined(OS_LINUX) && defined(ADDRESS_SANITIZER)
732// Flaky with ASan enabled: crbug.com/798563.
Xiaohan Wangf0bf3de2018-01-06 21:23:30733#define MAYBE_MessageTypeTest DISABLED_MessageTypeTest
Tarun Bansalbf793272018-01-02 22:56:06734#else
Xiaohan Wangf0bf3de2018-01-06 21:23:30735#define MAYBE_MessageTypeTest MessageTypeTest
Tarun Bansalbf793272018-01-02 22:56:06736#endif
Xiaohan Wangf367d1082018-04-20 19:50:55737IN_PROC_BROWSER_TEST_P(ECKEncryptedMediaTest, MAYBE_MessageTypeTest) {
Xiaohan Wangf0bf3de2018-01-06 21:23:30738 TestPlaybackCase(kExternalClearKeyMessageTypeTestKeySystem, kNoSessionToLoad,
cm.sanchi2fd33362017-11-14 03:20:36739 media::kEnded);
John Rummell4fa9fb7b2017-07-20 23:03:27740
Xiaohan Wangf0bf3de2018-01-06 21:23:30741 int num_received_message_types = 0;
742 EXPECT_TRUE(content::ExecuteScriptAndExtractInt(
John Rummell4fa9fb7b2017-07-20 23:03:27743 browser()->tab_strip_model()->GetActiveWebContents(),
744 "window.domAutomationController.send("
Xiaohan Wangf0bf3de2018-01-06 21:23:30745 "document.querySelector('video').receivedMessageTypes.size);",
746 &num_received_message_types));
Xiaohan Wangf367d1082018-04-20 19:50:55747
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);
xhwang0cfb5282016-08-25 03:33:25751}
752
Xiaohan Wangf367d1082018-04-20 19:50:55753IN_PROC_BROWSER_TEST_P(ECKEncryptedMediaTest, LoadLoadableSession) {
cm.sanchi2fd33362017-11-14 03:20:36754 TestPlaybackCase(kExternalClearKeyKeySystem, kLoadableSession, media::kEnded);
[email protected]0af5dfa2014-02-07 22:33:44755}
756
Xiaohan Wangf367d1082018-04-20 19:50:55757IN_PROC_BROWSER_TEST_P(ECKEncryptedMediaTest, LoadUnknownSession) {
xhwang0cfb5282016-08-25 03:33:25758 TestPlaybackCase(kExternalClearKeyKeySystem, kUnknownSession,
759 kEmeSessionNotFound);
[email protected]34afd582013-12-20 07:26:18760}
Xiaohan Wang439859f32017-06-06 22:55:24761
762const char kExternalClearKeyDecryptOnlyKeySystem[] =
763 "org.chromium.externalclearkey.decryptonly";
764
Xiaohan Wangf367d1082018-04-20 19:50:55765IN_PROC_BROWSER_TEST_P(ECKEncryptedMediaTest, DecryptOnly_VideoAudio_WebM) {
Xiaohan Wang439859f32017-06-06 22:55:24766 RunSimpleEncryptedMediaTest(
767 "bear-320x240-av_enc-av.webm", kWebMVorbisAudioVP8Video,
768 kExternalClearKeyDecryptOnlyKeySystem, SrcType::MSE);
769}
770
771#if BUILDFLAG(USE_PROPRIETARY_CODECS)
Xiaohan Wangf367d1082018-04-20 19:50:55772
773IN_PROC_BROWSER_TEST_P(ECKEncryptedMediaTest, DecryptOnly_VideoOnly_MP4_VP9) {
Xiaohan Wang439859f32017-06-06 22:55:24774 RunSimpleEncryptedMediaTest(
775 "bear-320x240-v_frag-vp9-cenc.mp4", kMP4VideoVp9Only,
776 kExternalClearKeyDecryptOnlyKeySystem, SrcType::MSE);
777}
Xiaohan Wangf367d1082018-04-20 19:50:55778
779// Encryption Scheme tests. ClearKey key system is covered in
780// content/browser/media/encrypted_media_browsertest.cc.
781IN_PROC_BROWSER_TEST_P(ECKEncryptedMediaTest, Playback_Encryption_CENC) {
782 TestMP4EncryptionPlayback(kExternalClearKeyKeySystem,
783 "bear-640x360-v_frag-cenc.mp4", media::kEnded);
784}
785
786IN_PROC_BROWSER_TEST_P(ECKEncryptedMediaTest, Playback_Encryption_CBC1) {
787 TestMP4EncryptionPlayback(kExternalClearKeyKeySystem,
788 "bear-640x360-v_frag-cbc1.mp4", media::kError);
789}
790
791IN_PROC_BROWSER_TEST_P(ECKEncryptedMediaTest, Playback_Encryption_CENS) {
792 TestMP4EncryptionPlayback(kExternalClearKeyKeySystem,
793 "bear-640x360-v_frag-cens.mp4", media::kError);
794}
795
796IN_PROC_BROWSER_TEST_P(ECKEncryptedMediaTest, Playback_Encryption_CBCS) {
797 TestMP4EncryptionPlayback(kExternalClearKeyKeySystem,
798 "bear-640x360-v_frag-cbcs.mp4", media::kError);
799}
800
Xiaohan Wang439859f32017-06-06 22:55:24801#endif // BUILDFLAG(USE_PROPRIETARY_CODECS)
jrummellc467d232014-10-21 17:55:22802
xhwangc3941032017-03-20 18:50:35803#if BUILDFLAG(ENABLE_CDM_HOST_VERIFICATION)
Xiaohan Wangf367d1082018-04-20 19:50:55804IN_PROC_BROWSER_TEST_P(ECKEncryptedMediaTest, VerifyCdmHostTest) {
xhwang785a8342017-01-26 06:46:39805 TestNonPlaybackCases(kExternalClearKeyVerifyCdmHostTestKeySystem,
806 kUnitTestSuccess);
807}
xhwangc3941032017-03-20 18:50:35808#endif // BUILDFLAG(ENABLE_CDM_HOST_VERIFICATION)
xhwang65c23032017-02-17 04:37:42809
Xiaohan Wangf367d1082018-04-20 19:50:55810IN_PROC_BROWSER_TEST_P(ECKEncryptedMediaTest, StorageIdTest) {
John Rummelleff649e52017-07-20 01:11:59811 TestNonPlaybackCases(kExternalClearKeyStorageIdTestKeySystem,
812 kUnitTestSuccess);
813}
Xiaohan Wang328218572017-10-02 19:20:41814
Xiaohan Wangf367d1082018-04-20 19:50:55815IN_PROC_BROWSER_TEST_P(ECKEncryptedMediaTest, MultipleCdmTypes) {
Xiaohan Wang328218572017-10-02 19:20:41816 base::StringPairs empty_query_params;
cm.sanchi2fd33362017-11-14 03:20:36817 RunMediaTestPage("multiple_cdm_types.html", empty_query_params, media::kEnded,
818 true);
Xiaohan Wang328218572017-10-02 19:20:41819}
Xiaohan Wang328218572017-10-02 19:20:41820
Xiaohan Wangf367d1082018-04-20 19:50:55821// Tests that only works on newer CDM interfaces.
Xiaohan Wangdaf577f2017-12-21 21:30:56822
Xiaohan Wangf367d1082018-04-20 19:50:55823IN_PROC_BROWSER_TEST_P(ECKEncryptedMediaTest, CdmProxy) {
Xiaohan Wangf89c6c52018-04-20 22:04:30824 if (GetCdmInterfaceVersion() < 11) {
825 DVLOG(0) << "Skipping test; CdmProxy only supported on CDM_11 and above.";
Xiaohan Wangf367d1082018-04-20 19:50:55826 return;
827 }
828
Xiaohan Wangdaf577f2017-12-21 21:30:56829 TestNonPlaybackCases(kExternalClearKeyCdmProxyTestKeySystem,
830 kUnitTestSuccess);
831}
832
Xiaohan Wang9a93b23c2017-08-01 17:06:09833#endif // BUILDFLAG(ENABLE_LIBRARY_CDMS)