blob: 78cd3c866cabbdfa689bcceb20b0ff9ade5e0c9d [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>
dchenge73d8520c2015-12-27 01:19:096#include <utility>
7
[email protected]63dc9072013-09-12 06:20:478#include "base/command_line.h"
9#include "base/path_service.h"
10#include "base/strings/utf_string_conversions.h"
11#include "base/win/windows_version.h"
avi6846aef2015-12-26 01:09:3812#include "build/build_config.h"
[email protected]63dc9072013-09-12 06:20:4713#include "chrome/browser/media/media_browsertest.h"
[email protected]df06a3e2014-01-31 21:36:5914#include "chrome/browser/media/test_license_server.h"
15#include "chrome/browser/media/wv_test_license_server_config.h"
[email protected]63dc9072013-09-12 06:20:4716#include "chrome/browser/ui/browser.h"
17#include "chrome/browser/ui/tabs/tab_strip_model.h"
18#include "chrome/common/chrome_switches.h"
brettw90e92602015-10-10 00:12:4019#include "content/public/common/content_switches.h"
[email protected]63dc9072013-09-12 06:20:4720#include "content/public/test/browser_test_utils.h"
[email protected]1be9fa072014-03-21 22:50:2921#include "testing/gtest/include/gtest/gtest-spi.h"
[email protected]6479b192013-10-19 18:28:0422#if defined(OS_ANDROID)
23#include "base/android/build_info.h"
24#endif
[email protected]63dc9072013-09-12 06:20:4725
[email protected]63dc9072013-09-12 06:20:4726#if defined(ENABLE_PEPPER_CDMS)
xhwangb9417142016-05-18 22:23:3627#include "chrome/browser/media/pepper_cdm_test_helper.h"
[email protected]63dc9072013-09-12 06:20:4728#endif
[email protected]1825e772013-10-08 06:39:1129
xhwangb9417142016-05-18 22:23:3630#include "widevine_cdm_version.h" // In SHARED_INTERMEDIATE_DIR.
[email protected]63dc9072013-09-12 06:20:4731
32// Available key systems.
[email protected]a32ef592014-03-07 19:11:1533const char kClearKeyKeySystem[] = "org.w3.clearkey";
[email protected]ab998e82013-11-22 20:31:3534const char kExternalClearKeyKeySystem[] = "org.chromium.externalclearkey";
[email protected]34afd582013-12-20 07:26:1835const char kExternalClearKeyFileIOTestKeySystem[] =
36 "org.chromium.externalclearkey.fileiotest";
[email protected]ab998e82013-11-22 20:31:3537const char kExternalClearKeyInitializeFailKeySystem[] =
38 "org.chromium.externalclearkey.initializefail";
[email protected]a27d34ab2014-01-09 04:23:2939const char kExternalClearKeyCrashKeySystem[] =
40 "org.chromium.externalclearkey.crash";
[email protected]63dc9072013-09-12 06:20:4741
42// Supported media types.
[email protected]095ccbe42013-09-26 00:06:4243const char kWebMAudioOnly[] = "audio/webm; codecs=\"vorbis\"";
44const char kWebMVideoOnly[] = "video/webm; codecs=\"vp8\"";
45const char kWebMAudioVideo[] = "video/webm; codecs=\"vorbis, vp8\"";
jamescook6107ed82014-11-06 06:59:2146const char kWebMVP9VideoOnly[] = "video/webm; codecs=\"vp9\"";
[email protected]095ccbe42013-09-26 00:06:4247#if defined(USE_PROPRIETARY_CODECS)
48const char kMP4AudioOnly[] = "audio/mp4; codecs=\"mp4a.40.2\"";
49const char kMP4VideoOnly[] = "video/mp4; codecs=\"avc1.4D4041\"";
50#endif // defined(USE_PROPRIETARY_CODECS)
[email protected]63dc9072013-09-12 06:20:4751
[email protected]0af5dfa2014-02-07 22:33:4452// Sessions to load.
53const char kNoSessionToLoad[] = "";
54const char kLoadableSession[] = "LoadableSession";
55const char kUnknownSession[] = "UnknownSession";
56
[email protected]2e850f12013-09-18 01:27:2957// EME-specific test results and errors.
[email protected]e11d89d2014-06-19 11:36:3158const char kFileIOTestSuccess[] = "FILE_IO_TEST_SUCCESS";
jrummell0c6ba542015-07-08 18:04:4459const char kEmeNotSupportedError[] = "NOTSUPPORTEDERROR";
60const char kEmeGenerateRequestFailed[] = "EME_GENERATEREQUEST_FAILED";
jrummell14fae6f2015-07-10 20:40:1561const char kEmeSessionNotFound[] = "EME_SESSION_NOT_FOUND";
jrummell0c6ba542015-07-08 18:04:4462const char kEmeLoadFailed[] = "EME_LOAD_FAILED";
63const char kEmeUpdateFailed[] = "EME_UPDATE_FAILED";
64const char kEmeErrorEvent[] = "EME_ERROR_EVENT";
65const char kEmeMessageUnexpectedType[] = "EME_MESSAGE_UNEXPECTED_TYPE";
ddorwinfdb9a2b2016-02-22 22:25:1066const char kEmeRenewalMissingHeader[] = "EME_RENEWAL_MISSING_HEADER";
[email protected]e11d89d2014-06-19 11:36:3167
68const char kDefaultEmePlayer[] = "eme_player.html";
[email protected]63dc9072013-09-12 06:20:4769
70// The type of video src used to load media.
71enum SrcType {
72 SRC,
73 MSE
74};
75
jrummellb3944632015-03-14 00:19:4276// Whether the video should be played once or twice.
77enum class PlayTwice { NO, YES };
78
jrummellc015cb962015-07-17 00:41:3079// Format of a container when testing different streams.
80enum class EncryptedContainer {
81 CLEAR_WEBM,
82 CLEAR_MP4,
83 ENCRYPTED_WEBM,
84 ENCRYPTED_MP4
85};
86
[email protected]6479b192013-10-19 18:28:0487// MSE is available on all desktop platforms and on Android 4.1 and later.
88static bool IsMSESupported() {
89#if defined(OS_ANDROID)
90 if (base::android::BuildInfo::GetInstance()->sdk_int() < 16) {
anujk.sharma9da298e12014-11-07 04:48:4391 DVLOG(0) << "MSE is only supported in Android 4.1 and later.";
[email protected]6479b192013-10-19 18:28:0492 return false;
93 }
94#endif // defined(OS_ANDROID)
95 return true;
96}
97
[email protected]e6bf64142013-10-18 23:07:5498// Base class for encrypted media tests.
99class EncryptedMediaTestBase : public MediaBrowserTest {
[email protected]63dc9072013-09-12 06:20:47100 public:
xhwangb9417142016-05-18 22:23:36101 EncryptedMediaTestBase() {}
[email protected]63dc9072013-09-12 06:20:47102
[email protected]ab998e82013-11-22 20:31:35103 bool IsExternalClearKey(const std::string& key_system) {
ddorwin40312df2016-02-26 01:25:01104 if (key_system == kExternalClearKeyKeySystem)
105 return true;
106 std::string prefix = std::string(kExternalClearKeyKeySystem) + '.';
107 return key_system.substr(0, prefix.size()) == prefix;
[email protected]63dc9072013-09-12 06:20:47108 }
109
[email protected]1825e772013-10-08 06:39:11110#if defined(WIDEVINE_CDM_AVAILABLE)
[email protected]ab998e82013-11-22 20:31:35111 bool IsWidevine(const std::string& key_system) {
112 return key_system == kWidevineKeySystem;
[email protected]1825e772013-10-08 06:39:11113 }
114#endif // defined(WIDEVINE_CDM_AVAILABLE)
115
[email protected]8a229322014-07-22 23:33:07116 void RunEncryptedMediaTestPage(
117 const std::string& html_page,
118 const std::string& key_system,
anand.ratn2636d972014-09-30 04:06:58119 base::StringPairs& query_params,
[email protected]8a229322014-07-22 23:33:07120 const std::string& expected_title) {
anand.ratn2636d972014-09-30 04:06:58121 base::StringPairs new_query_params = query_params;
[email protected]8a229322014-07-22 23:33:07122 StartLicenseServerIfNeeded(key_system, &new_query_params);
123 RunMediaTestPage(html_page, new_query_params, expected_title, true);
[email protected]df06a3e2014-01-31 21:36:59124 }
125
[email protected]0af5dfa2014-02-07 22:33:44126 // Tests |html_page| using |media_file| (with |media_type|) and |key_system|.
127 // When |session_to_load| is not empty, the test will try to load
128 // |session_to_load| with stored keys, instead of creating a new session
129 // and trying to update it with licenses.
130 // When |force_invalid_response| is true, the test will provide invalid
131 // responses, which should trigger errors.
132 // TODO(xhwang): Find an easier way to pass multiple configuration test
133 // options.
[email protected]df06a3e2014-01-31 21:36:59134 void RunEncryptedMediaTest(const std::string& html_page,
135 const std::string& media_file,
136 const std::string& media_type,
137 const std::string& key_system,
[email protected]1825e772013-10-08 06:39:11138 SrcType src_type,
[email protected]0af5dfa2014-02-07 22:33:44139 const std::string& session_to_load,
[email protected]df06a3e2014-01-31 21:36:59140 bool force_invalid_response,
jrummellb3944632015-03-14 00:19:42141 PlayTwice play_twice,
[email protected]df06a3e2014-01-31 21:36:59142 const std::string& expected_title) {
[email protected]6479b192013-10-19 18:28:04143 if (src_type == MSE && !IsMSESupported()) {
anujk.sharma9da298e12014-11-07 04:48:43144 DVLOG(0) << "Skipping test - MSE not supported.";
[email protected]6479b192013-10-19 18:28:04145 return;
146 }
anand.ratn2636d972014-09-30 04:06:58147 base::StringPairs query_params;
[email protected]df06a3e2014-01-31 21:36:59148 query_params.push_back(std::make_pair("mediaFile", media_file));
149 query_params.push_back(std::make_pair("mediaType", media_type));
150 query_params.push_back(std::make_pair("keySystem", key_system));
[email protected]63dc9072013-09-12 06:20:47151 if (src_type == MSE)
[email protected]df06a3e2014-01-31 21:36:59152 query_params.push_back(std::make_pair("useMSE", "1"));
153 if (force_invalid_response)
154 query_params.push_back(std::make_pair("forceInvalidResponse", "1"));
[email protected]0af5dfa2014-02-07 22:33:44155 if (!session_to_load.empty())
156 query_params.push_back(std::make_pair("sessionToLoad", session_to_load));
jrummellb3944632015-03-14 00:19:42157 if (play_twice == PlayTwice::YES)
158 query_params.push_back(std::make_pair("playTwice", "1"));
[email protected]8a229322014-07-22 23:33:07159 RunEncryptedMediaTestPage(html_page, key_system, query_params,
[email protected]df06a3e2014-01-31 21:36:59160 expected_title);
[email protected]63dc9072013-09-12 06:20:47161 }
162
[email protected]df06a3e2014-01-31 21:36:59163 void RunSimpleEncryptedMediaTest(const std::string& media_file,
164 const std::string& media_type,
165 const std::string& key_system,
ddorwinfdb9a2b2016-02-22 22:25:10166 SrcType src_type) {
[email protected]df06a3e2014-01-31 21:36:59167 std::string expected_title = kEnded;
jrummell0c6ba542015-07-08 18:04:44168 if (!IsPlayBackPossible(key_system)) {
ddorwinfdb9a2b2016-02-22 22:25:10169 expected_title = kEmeUpdateFailed;
jrummell0c6ba542015-07-08 18:04:44170 }
[email protected]1825e772013-10-08 06:39:11171
jrummellb3944632015-03-14 00:19:42172 RunEncryptedMediaTest(kDefaultEmePlayer, media_file, media_type, key_system,
ddorwinfdb9a2b2016-02-22 22:25:10173 src_type, kNoSessionToLoad, false, PlayTwice::NO,
174 expected_title);
[email protected]df06a3e2014-01-31 21:36:59175 // Check KeyMessage received for all key systems.
176 bool receivedKeyMessage = false;
177 EXPECT_TRUE(content::ExecuteScriptAndExtractBool(
178 browser()->tab_strip_model()->GetActiveWebContents(),
[email protected]e11d89d2014-06-19 11:36:31179 "window.domAutomationController.send("
180 "document.querySelector('video').receivedKeyMessage);",
[email protected]df06a3e2014-01-31 21:36:59181 &receivedKeyMessage));
182 EXPECT_TRUE(receivedKeyMessage);
183 }
184
[email protected]8a229322014-07-22 23:33:07185 // Starts a license server if available for the |key_system| and adds a
186 // 'licenseServerURL' query parameter to |query_params|.
[email protected]df06a3e2014-01-31 21:36:59187 void StartLicenseServerIfNeeded(const std::string& key_system,
anand.ratn2636d972014-09-30 04:06:58188 base::StringPairs* query_params) {
dchengc16dc8092016-04-08 23:12:56189 std::unique_ptr<TestLicenseServerConfig> config =
190 GetServerConfig(key_system);
[email protected]df06a3e2014-01-31 21:36:59191 if (!config)
192 return;
dchenge73d8520c2015-12-27 01:19:09193 license_server_.reset(new TestLicenseServer(std::move(config)));
[email protected]df06a3e2014-01-31 21:36:59194 EXPECT_TRUE(license_server_->Start());
[email protected]8a229322014-07-22 23:33:07195 query_params->push_back(
196 std::make_pair("licenseServerURL", license_server_->GetServerURL()));
[email protected]df06a3e2014-01-31 21:36:59197 }
198
199 bool IsPlayBackPossible(const std::string& key_system) {
200#if defined(WIDEVINE_CDM_AVAILABLE)
201 if (IsWidevine(key_system) && !GetServerConfig(key_system))
202 return false;
203#endif // defined(WIDEVINE_CDM_AVAILABLE)
204 return true;
205 }
206
dchengc16dc8092016-04-08 23:12:56207 std::unique_ptr<TestLicenseServerConfig> GetServerConfig(
[email protected]df06a3e2014-01-31 21:36:59208 const std::string& key_system) {
209#if defined(WIDEVINE_CDM_AVAILABLE)
210 if (IsWidevine(key_system)) {
dchengc16dc8092016-04-08 23:12:56211 std::unique_ptr<TestLicenseServerConfig> config(
212 new WVTestLicenseServerConfig);
[email protected]df06a3e2014-01-31 21:36:59213 if (config->IsPlatformSupported())
dcheng7c133cc2015-12-31 06:57:59214 return config;
[email protected]df06a3e2014-01-31 21:36:59215 }
216#endif // defined(WIDEVINE_CDM_AVAILABLE)
dcheng7c133cc2015-12-31 06:57:59217 return nullptr;
[email protected]1825e772013-10-08 06:39:11218 }
219
[email protected]63dc9072013-09-12 06:20:47220 protected:
dchengc16dc8092016-04-08 23:12:56221 std::unique_ptr<TestLicenseServer> license_server_;
[email protected]df06a3e2014-01-31 21:36:59222
[email protected]2e850f12013-09-18 01:27:29223 // We want to fail quickly when a test fails because an error is encountered.
dchengd7e84a052014-10-22 00:18:51224 void AddWaitForTitles(content::TitleWatcher* title_watcher) override {
[email protected]2e850f12013-09-18 01:27:29225 MediaBrowserTest::AddWaitForTitles(title_watcher);
[email protected]6778fed2013-12-24 20:09:37226 title_watcher->AlsoWaitForTitle(base::ASCIIToUTF16(kEmeNotSupportedError));
jrummell0c6ba542015-07-08 18:04:44227 title_watcher->AlsoWaitForTitle(
228 base::ASCIIToUTF16(kEmeGenerateRequestFailed));
jrummell14fae6f2015-07-10 20:40:15229 title_watcher->AlsoWaitForTitle(base::ASCIIToUTF16(kEmeSessionNotFound));
jrummell0c6ba542015-07-08 18:04:44230 title_watcher->AlsoWaitForTitle(base::ASCIIToUTF16(kEmeLoadFailed));
231 title_watcher->AlsoWaitForTitle(base::ASCIIToUTF16(kEmeUpdateFailed));
232 title_watcher->AlsoWaitForTitle(base::ASCIIToUTF16(kEmeErrorEvent));
233 title_watcher->AlsoWaitForTitle(
234 base::ASCIIToUTF16(kEmeMessageUnexpectedType));
235 title_watcher->AlsoWaitForTitle(
ddorwinfdb9a2b2016-02-22 22:25:10236 base::ASCIIToUTF16(kEmeRenewalMissingHeader));
[email protected]2e850f12013-09-18 01:27:29237 }
238
avi556c05022014-12-22 23:31:43239 void SetUpCommandLine(base::CommandLine* command_line) override {
[email protected]2289b432014-08-08 17:52:11240 command_line->AppendSwitch(
241 switches::kDisableGestureRequirementForMediaPlayback);
[email protected]2289b432014-08-08 17:52:11242 }
243
[email protected]df06a3e2014-01-31 21:36:59244 void SetUpCommandLineForKeySystem(const std::string& key_system,
avi556c05022014-12-22 23:31:43245 base::CommandLine* command_line) {
[email protected]df06a3e2014-01-31 21:36:59246 if (GetServerConfig(key_system))
247 // Since the web and license servers listen on different ports, we need to
248 // disable web-security to send license requests to the license server.
249 // TODO(shadi): Add port forwarding to the test web server configuration.
250 command_line->AppendSwitch(switches::kDisableWebSecurity);
251
[email protected]e6bf64142013-10-18 23:07:54252#if defined(ENABLE_PEPPER_CDMS)
253 if (IsExternalClearKey(key_system)) {
xhwangb9417142016-05-18 22:23:36254 RegisterPepperCdm(command_line, kClearKeyCdmAdapterFileName,
255 kClearKeyCdmDisplayName, kClearKeyCdmPepperMimeType);
[email protected]e6bf64142013-10-18 23:07:54256 }
257#if defined(WIDEVINE_CDM_AVAILABLE) && defined(WIDEVINE_CDM_IS_COMPONENT)
thestig11bf74d2014-11-24 20:14:42258 else if (IsWidevine(key_system)) { // NOLINT
xhwangb9417142016-05-18 22:23:36259 RegisterPepperCdm(command_line, kWidevineCdmAdapterFileName,
260 kWidevineCdmDisplayName, kWidevineCdmPluginMimeType);
[email protected]e6bf64142013-10-18 23:07:54261 }
262#endif // defined(WIDEVINE_CDM_AVAILABLE) && defined(WIDEVINE_CDM_IS_COMPONENT)
263#endif // defined(ENABLE_PEPPER_CDMS)
264 }
[email protected]e6bf64142013-10-18 23:07:54265};
266
267#if defined(ENABLE_PEPPER_CDMS)
[email protected]ab998e82013-11-22 20:31:35268// Tests encrypted media playback using ExternalClearKey key system in
269// decrypt-and-decode mode.
[email protected]e6bf64142013-10-18 23:07:54270class ECKEncryptedMediaTest : public EncryptedMediaTestBase {
[email protected]0af5dfa2014-02-07 22:33:44271 public:
272 // We use special |key_system| names to do non-playback related tests, e.g.
273 // kExternalClearKeyFileIOTestKeySystem is used to test file IO.
274 void TestNonPlaybackCases(const std::string& key_system,
275 const std::string& expected_title) {
276 // Since we do not test playback, arbitrarily choose a test file and source
277 // type.
ddorwinfdb9a2b2016-02-22 22:25:10278 RunEncryptedMediaTest(kDefaultEmePlayer, "bear-a_enc-a.webm",
279 kWebMAudioOnly, key_system, SRC, kNoSessionToLoad,
280 false, PlayTwice::NO, expected_title);
jrummell19f2c902015-02-11 01:17:50281 }
282
283 void TestPlaybackCase(const std::string& session_to_load,
284 const std::string& expected_title) {
285 RunEncryptedMediaTest(kDefaultEmePlayer, "bear-320x240-v_enc-v.webm",
286 kWebMVideoOnly, kExternalClearKeyKeySystem, SRC,
ddorwinfdb9a2b2016-02-22 22:25:10287 session_to_load, false, PlayTwice::NO,
jrummellb3944632015-03-14 00:19:42288 expected_title);
jrummell19f2c902015-02-11 01:17:50289 }
290
jrummellc467d232014-10-21 17:55:22291 protected:
avi556c05022014-12-22 23:31:43292 void SetUpCommandLine(base::CommandLine* command_line) override {
jrummellc467d232014-10-21 17:55:22293 EncryptedMediaTestBase::SetUpCommandLine(command_line);
jrummellc467d232014-10-21 17:55:22294 SetUpCommandLineForKeySystem(kExternalClearKeyKeySystem, command_line);
295 }
296};
297
[email protected]e6bf64142013-10-18 23:07:54298#if defined(WIDEVINE_CDM_AVAILABLE)
299// Tests encrypted media playback using Widevine key system.
300class WVEncryptedMediaTest : public EncryptedMediaTestBase {
301 protected:
Daniel Cheng43ba4a0122014-12-31 06:30:35302 void SetUpCommandLine(base::CommandLine* command_line) override {
[email protected]e6bf64142013-10-18 23:07:54303 EncryptedMediaTestBase::SetUpCommandLine(command_line);
304 SetUpCommandLineForKeySystem(kWidevineKeySystem, command_line);
305 }
306};
[email protected]df06a3e2014-01-31 21:36:59307
[email protected]e6bf64142013-10-18 23:07:54308#endif // defined(WIDEVINE_CDM_AVAILABLE)
309#endif // defined(ENABLE_PEPPER_CDMS)
310
311// Tests encrypted media playback with a combination of parameters:
312// - char*: Key system name.
jrummell19f2c902015-02-11 01:17:50313// - SrcType: Use MSE or SRC.
[email protected]e6bf64142013-10-18 23:07:54314//
315// Note: Only parameterized (*_P) tests can be used. Non-parameterized (*_F)
316// tests will crash at GetParam(). To add non-parameterized tests, use
317// EncryptedMediaTestBase or one of its subclasses (e.g. WVEncryptedMediaTest).
ddorwinfdb9a2b2016-02-22 22:25:10318class EncryptedMediaTest : public EncryptedMediaTestBase,
319 public testing::WithParamInterface<
320 std::tr1::tuple<const char*, SrcType>> {
[email protected]e6bf64142013-10-18 23:07:54321 public:
[email protected]df06a3e2014-01-31 21:36:59322 std::string CurrentKeySystem() {
[email protected]e6bf64142013-10-18 23:07:54323 return std::tr1::get<0>(GetParam());
324 }
325
326 SrcType CurrentSourceType() {
327 return std::tr1::get<1>(GetParam());
328 }
329
[email protected]df06a3e2014-01-31 21:36:59330 void TestSimplePlayback(const std::string& encrypted_media,
331 const std::string& media_type) {
ddorwinfdb9a2b2016-02-22 22:25:10332 RunSimpleEncryptedMediaTest(encrypted_media, media_type, CurrentKeySystem(),
333 CurrentSourceType());
[email protected]e6bf64142013-10-18 23:07:54334 }
335
jrummellb3944632015-03-14 00:19:42336 void TestMultiplePlayback(const std::string& encrypted_media,
337 const std::string& media_type) {
jrummelld9dc7902015-03-16 20:59:28338 DCHECK(IsPlayBackPossible(CurrentKeySystem()));
jrummellb3944632015-03-14 00:19:42339 RunEncryptedMediaTest(kDefaultEmePlayer, encrypted_media, media_type,
340 CurrentKeySystem(), CurrentSourceType(),
ddorwinfdb9a2b2016-02-22 22:25:10341 kNoSessionToLoad, false, PlayTwice::YES, kEnded);
jrummellb3944632015-03-14 00:19:42342 }
343
[email protected]df06a3e2014-01-31 21:36:59344 void RunInvalidResponseTest() {
ddorwinfdb9a2b2016-02-22 22:25:10345 RunEncryptedMediaTest(kDefaultEmePlayer, "bear-320x240-av_enc-av.webm",
346 kWebMAudioVideo, CurrentKeySystem(),
347 CurrentSourceType(), kNoSessionToLoad, true,
348 PlayTwice::NO, kEmeUpdateFailed);
[email protected]df06a3e2014-01-31 21:36:59349 }
350
[email protected]e6bf64142013-10-18 23:07:54351 void TestFrameSizeChange() {
ddorwinfdb9a2b2016-02-22 22:25:10352 RunEncryptedMediaTest("encrypted_frame_size_change.html",
353 "frame_size_change-av_enc-v.webm", kWebMAudioVideo,
354 CurrentKeySystem(), CurrentSourceType(),
355 kNoSessionToLoad, false, PlayTwice::NO, kEnded);
[email protected]e6bf64142013-10-18 23:07:54356 }
357
358 void TestConfigChange() {
[email protected]df06a3e2014-01-31 21:36:59359 DCHECK(IsMSESupported());
anand.ratn2636d972014-09-30 04:06:58360 base::StringPairs query_params;
[email protected]df06a3e2014-01-31 21:36:59361 query_params.push_back(std::make_pair("keySystem", CurrentKeySystem()));
362 query_params.push_back(std::make_pair("runEncrypted", "1"));
363 RunEncryptedMediaTestPage("mse_config_change.html",
364 CurrentKeySystem(),
[email protected]8a229322014-07-22 23:33:07365 query_params,
[email protected]df06a3e2014-01-31 21:36:59366 kEnded);
[email protected]e6bf64142013-10-18 23:07:54367 }
368
jrummellc015cb962015-07-17 00:41:30369 std::string ConvertContainerFormat(EncryptedContainer format) {
370 switch (format) {
371 case EncryptedContainer::CLEAR_MP4:
372 return "CLEAR_MP4";
373 case EncryptedContainer::CLEAR_WEBM:
374 return "CLEAR_WEBM";
375 case EncryptedContainer::ENCRYPTED_MP4:
376 return "ENCRYPTED_MP4";
377 case EncryptedContainer::ENCRYPTED_WEBM:
378 return "ENCRYPTED_WEBM";
379 }
380 NOTREACHED();
381 return "UNKNOWN";
382 }
383
384 void TestDifferentContainers(EncryptedContainer video_format,
385 EncryptedContainer audio_format) {
386 DCHECK(IsMSESupported());
jrummellc015cb962015-07-17 00:41:30387 base::StringPairs query_params;
388 query_params.push_back(std::make_pair("keySystem", CurrentKeySystem()));
389 query_params.push_back(std::make_pair("runEncrypted", "1"));
390 query_params.push_back(
391 std::make_pair("videoFormat", ConvertContainerFormat(video_format)));
392 query_params.push_back(
393 std::make_pair("audioFormat", ConvertContainerFormat(audio_format)));
394 RunEncryptedMediaTestPage("mse_different_containers.html",
395 CurrentKeySystem(), query_params, kEnded);
396 }
397
[email protected]e6bf64142013-10-18 23:07:54398 protected:
avi556c05022014-12-22 23:31:43399 void SetUpCommandLine(base::CommandLine* command_line) override {
[email protected]e6bf64142013-10-18 23:07:54400 EncryptedMediaTestBase::SetUpCommandLine(command_line);
401 SetUpCommandLineForKeySystem(CurrentKeySystem(), command_line);
402 }
[email protected]63dc9072013-09-12 06:20:47403};
404
[email protected]6479b192013-10-19 18:28:04405using ::testing::Combine;
406using ::testing::Values;
407
408#if !defined(OS_ANDROID)
jrummell19f2c902015-02-11 01:17:50409INSTANTIATE_TEST_CASE_P(SRC_ClearKey,
[email protected]a32ef592014-03-07 19:11:15410 EncryptedMediaTest,
ddorwinfdb9a2b2016-02-22 22:25:10411 Combine(Values(kClearKeyKeySystem), Values(SRC)));
[email protected]6479b192013-10-19 18:28:04412#endif // !defined(OS_ANDROID)
413
jrummell77419192014-10-31 21:40:44414INSTANTIATE_TEST_CASE_P(MSE_ClearKey,
[email protected]a32ef592014-03-07 19:11:15415 EncryptedMediaTest,
ddorwinfdb9a2b2016-02-22 22:25:10416 Combine(Values(kClearKeyKeySystem), Values(MSE)));
[email protected]63dc9072013-09-12 06:20:47417
418// External Clear Key is currently only used on platforms that use Pepper CDMs.
419#if defined(ENABLE_PEPPER_CDMS)
[email protected]1ab297a2014-03-26 04:52:12420INSTANTIATE_TEST_CASE_P(SRC_ExternalClearKey,
[email protected]a32ef592014-03-07 19:11:15421 EncryptedMediaTest,
422 Combine(Values(kExternalClearKeyKeySystem),
ddorwinfdb9a2b2016-02-22 22:25:10423 Values(SRC)));
jam79bf1f6c2015-08-13 20:46:04424
[email protected]1ab297a2014-03-26 04:52:12425INSTANTIATE_TEST_CASE_P(MSE_ExternalClearKey,
[email protected]a32ef592014-03-07 19:11:15426 EncryptedMediaTest,
427 Combine(Values(kExternalClearKeyKeySystem),
ddorwinfdb9a2b2016-02-22 22:25:10428 Values(MSE)));
mnissler27025372015-10-19 14:26:23429
mnissler27025372015-10-19 14:26:23430const char kExternalClearKeyDecryptOnlyKeySystem[] =
431 "org.chromium.externalclearkey.decryptonly";
432
[email protected]ab998e82013-11-22 20:31:35433// To reduce test time, only run ExternalClearKeyDecryptOnly with MSE.
[email protected]1ab297a2014-03-26 04:52:12434INSTANTIATE_TEST_CASE_P(MSE_ExternalClearKeyDecryptOnly,
[email protected]a32ef592014-03-07 19:11:15435 EncryptedMediaTest,
436 Combine(Values(kExternalClearKeyDecryptOnlyKeySystem),
ddorwinfdb9a2b2016-02-22 22:25:10437 Values(MSE)));
[email protected]8a229322014-07-22 23:33:07438#endif // defined(ENABLE_PEPPER_CDMS)
[email protected]63dc9072013-09-12 06:20:47439
[email protected]1825e772013-10-08 06:39:11440#if defined(WIDEVINE_CDM_AVAILABLE)
jonross5785b8662015-10-22 21:12:53441#if !defined(OS_CHROMEOS)
[email protected]1ab297a2014-03-26 04:52:12442INSTANTIATE_TEST_CASE_P(MSE_Widevine,
[email protected]a32ef592014-03-07 19:11:15443 EncryptedMediaTest,
ddorwinfdb9a2b2016-02-22 22:25:10444 Combine(Values(kWidevineKeySystem), Values(MSE)));
jonross5785b8662015-10-22 21:12:53445#endif // !defined(OS_CHROMEOS)
[email protected]1825e772013-10-08 06:39:11446#endif // defined(WIDEVINE_CDM_AVAILABLE)
[email protected]63dc9072013-09-12 06:20:47447
[email protected]626e517c2014-08-19 00:49:46448IN_PROC_BROWSER_TEST_P(EncryptedMediaTest, Playback_AudioOnly_WebM) {
[email protected]8a229322014-07-22 23:33:07449 TestSimplePlayback("bear-a_enc-a.webm", kWebMAudioOnly);
[email protected]63dc9072013-09-12 06:20:47450}
451
[email protected]626e517c2014-08-19 00:49:46452IN_PROC_BROWSER_TEST_P(EncryptedMediaTest, Playback_AudioClearVideo_WebM) {
[email protected]8a229322014-07-22 23:33:07453 TestSimplePlayback("bear-320x240-av_enc-a.webm", kWebMAudioVideo);
[email protected]63dc9072013-09-12 06:20:47454}
455
[email protected]626e517c2014-08-19 00:49:46456IN_PROC_BROWSER_TEST_P(EncryptedMediaTest, Playback_VideoAudio_WebM) {
[email protected]8a229322014-07-22 23:33:07457 TestSimplePlayback("bear-320x240-av_enc-av.webm", kWebMAudioVideo);
[email protected]63dc9072013-09-12 06:20:47458}
459
[email protected]626e517c2014-08-19 00:49:46460IN_PROC_BROWSER_TEST_P(EncryptedMediaTest, Playback_VideoOnly_WebM) {
[email protected]8a229322014-07-22 23:33:07461 TestSimplePlayback("bear-320x240-v_enc-v.webm", kWebMVideoOnly);
[email protected]63dc9072013-09-12 06:20:47462}
463
[email protected]626e517c2014-08-19 00:49:46464IN_PROC_BROWSER_TEST_P(EncryptedMediaTest, Playback_VideoClearAudio_WebM) {
[email protected]8a229322014-07-22 23:33:07465 TestSimplePlayback("bear-320x240-av_enc-v.webm", kWebMAudioVideo);
[email protected]63dc9072013-09-12 06:20:47466}
467
jrummell2fe87672015-01-02 19:13:51468IN_PROC_BROWSER_TEST_P(EncryptedMediaTest, Playback_VP9Video_WebM) {
[email protected]8a229322014-07-22 23:33:07469 TestSimplePlayback("bear-320x240-v-vp9_enc-v.webm", kWebMVP9VideoOnly);
[email protected]2b197ac72014-04-11 23:33:52470}
471
jrummell2fe87672015-01-02 19:13:51472IN_PROC_BROWSER_TEST_P(EncryptedMediaTest, Playback_AudioOnly_WebM_Opus) {
sandersd5ec6dcf2014-11-26 20:39:38473 TestSimplePlayback("bear-320x240-opus-a_enc-a.webm", kWebMAudioOnly);
474}
475
476IN_PROC_BROWSER_TEST_P(EncryptedMediaTest, Playback_VideoAudio_WebM_Opus) {
477 TestSimplePlayback("bear-320x240-opus-av_enc-av.webm", kWebMAudioVideo);
478}
479
480IN_PROC_BROWSER_TEST_P(EncryptedMediaTest, Playback_VideoClearAudio_WebM_Opus) {
481 TestSimplePlayback("bear-320x240-opus-av_enc-v.webm", kWebMAudioVideo);
482}
483
jrummellb3944632015-03-14 00:19:42484IN_PROC_BROWSER_TEST_P(EncryptedMediaTest, Playback_Multiple_VideoAudio_WebM) {
jrummelld9dc7902015-03-16 20:59:28485 if (!IsPlayBackPossible(CurrentKeySystem())) {
486 DVLOG(0) << "Skipping test - Playback_Multiple test requires playback.";
487 return;
488 }
jrummellb3944632015-03-14 00:19:42489 TestMultiplePlayback("bear-320x240-av_enc-av.webm", kWebMAudioVideo);
490}
491
[email protected]626e517c2014-08-19 00:49:46492IN_PROC_BROWSER_TEST_P(EncryptedMediaTest, InvalidResponseKeyError) {
[email protected]df06a3e2014-01-31 21:36:59493 RunInvalidResponseTest();
494}
495
[email protected]1825e772013-10-08 06:39:11496IN_PROC_BROWSER_TEST_P(EncryptedMediaTest, ConfigChangeVideo) {
[email protected]df06a3e2014-01-31 21:36:59497 if (CurrentSourceType() != MSE || !IsMSESupported()) {
anujk.sharma9da298e12014-11-07 04:48:43498 DVLOG(0) << "Skipping test - ConfigChange test requires MSE.";
[email protected]df06a3e2014-01-31 21:36:59499 return;
500 }
501 if (!IsPlayBackPossible(CurrentKeySystem())) {
anujk.sharma9da298e12014-11-07 04:48:43502 DVLOG(0) << "Skipping test - ConfigChange test requires video playback.";
[email protected]df06a3e2014-01-31 21:36:59503 return;
504 }
[email protected]1825e772013-10-08 06:39:11505 TestConfigChange();
506}
507
jrummell2fe87672015-01-02 19:13:51508IN_PROC_BROWSER_TEST_P(EncryptedMediaTest, FrameSizeChangeVideo) {
[email protected]63dc9072013-09-12 06:20:47509 // Times out on Windows XP. http://crbug.com/171937
510#if defined(OS_WIN)
511 if (base::win::GetVersion() < base::win::VERSION_VISTA)
512 return;
513#endif
[email protected]df06a3e2014-01-31 21:36:59514 if (!IsPlayBackPossible(CurrentKeySystem())) {
anujk.sharma9da298e12014-11-07 04:48:43515 DVLOG(0) << "Skipping test - FrameSizeChange test requires video playback.";
[email protected]df06a3e2014-01-31 21:36:59516 return;
517 }
[email protected]1825e772013-10-08 06:39:11518 TestFrameSizeChange();
[email protected]63dc9072013-09-12 06:20:47519}
520
521#if defined(USE_PROPRIETARY_CODECS)
522IN_PROC_BROWSER_TEST_P(EncryptedMediaTest, Playback_VideoOnly_MP4) {
[email protected]63dc9072013-09-12 06:20:47523 // MP4 without MSE is not support yet, http://crbug.com/170793.
[email protected]1825e772013-10-08 06:39:11524 if (CurrentSourceType() != MSE) {
anujk.sharma9da298e12014-11-07 04:48:43525 DVLOG(0) << "Skipping test; Can only play MP4 encrypted streams by MSE.";
[email protected]63dc9072013-09-12 06:20:47526 return;
527 }
[email protected]1825e772013-10-08 06:39:11528 TestSimplePlayback("bear-640x360-v_frag-cenc.mp4", kMP4VideoOnly);
[email protected]63dc9072013-09-12 06:20:47529}
530
531IN_PROC_BROWSER_TEST_P(EncryptedMediaTest, Playback_AudioOnly_MP4) {
[email protected]63dc9072013-09-12 06:20:47532 // MP4 without MSE is not support yet, http://crbug.com/170793.
[email protected]1825e772013-10-08 06:39:11533 if (CurrentSourceType() != MSE) {
anujk.sharma9da298e12014-11-07 04:48:43534 DVLOG(0) << "Skipping test; Can only play MP4 encrypted streams by MSE.";
[email protected]63dc9072013-09-12 06:20:47535 return;
536 }
[email protected]1825e772013-10-08 06:39:11537 TestSimplePlayback("bear-640x360-a_frag-cenc.mp4", kMP4AudioOnly);
[email protected]63dc9072013-09-12 06:20:47538}
jrummellc015cb962015-07-17 00:41:30539
540IN_PROC_BROWSER_TEST_P(EncryptedMediaTest,
541 Playback_EncryptedVideo_MP4_ClearAudio_WEBM) {
542 // MP4 without MSE is not support yet, http://crbug.com/170793.
543 if (CurrentSourceType() != MSE) {
544 DVLOG(0) << "Skipping test; Can only play MP4 encrypted streams by MSE.";
545 return;
546 }
jrummellc015cb962015-07-17 00:41:30547 if (!IsPlayBackPossible(CurrentKeySystem())) {
548 DVLOG(0) << "Skipping test - Test requires video playback.";
549 return;
550 }
551 TestDifferentContainers(EncryptedContainer::ENCRYPTED_MP4,
552 EncryptedContainer::CLEAR_WEBM);
553}
554
555IN_PROC_BROWSER_TEST_P(EncryptedMediaTest,
556 Playback_ClearVideo_WEBM_EncryptedAudio_MP4) {
557 // MP4 without MSE is not support yet, http://crbug.com/170793.
558 if (CurrentSourceType() != MSE) {
559 DVLOG(0) << "Skipping test; Can only play MP4 encrypted streams by MSE.";
560 return;
561 }
jrummellc015cb962015-07-17 00:41:30562 if (!IsPlayBackPossible(CurrentKeySystem())) {
563 DVLOG(0) << "Skipping test - Test requires video playback.";
564 return;
565 }
566 TestDifferentContainers(EncryptedContainer::CLEAR_WEBM,
567 EncryptedContainer::ENCRYPTED_MP4);
568}
569
570IN_PROC_BROWSER_TEST_P(EncryptedMediaTest,
571 Playback_EncryptedVideo_WEBM_EncryptedAudio_MP4) {
572 // MP4 without MSE is not support yet, http://crbug.com/170793.
573 if (CurrentSourceType() != MSE) {
574 DVLOG(0) << "Skipping test; Can only play MP4 encrypted streams by MSE.";
575 return;
576 }
jrummellc015cb962015-07-17 00:41:30577 if (!IsPlayBackPossible(CurrentKeySystem())) {
578 DVLOG(0) << "Skipping test - Test requires video playback.";
579 return;
580 }
581 TestDifferentContainers(EncryptedContainer::ENCRYPTED_WEBM,
582 EncryptedContainer::ENCRYPTED_MP4);
583}
[email protected]63dc9072013-09-12 06:20:47584#endif // defined(USE_PROPRIETARY_CODECS)
585
[email protected]63dc9072013-09-12 06:20:47586#if defined(WIDEVINE_CDM_AVAILABLE)
[email protected]a32ef592014-03-07 19:11:15587// The parent key system cannot be used when creating MediaKeys.
[email protected]b1620732014-04-01 23:17:18588IN_PROC_BROWSER_TEST_F(WVEncryptedMediaTest, ParentThrowsException) {
jrummellb3944632015-03-14 00:19:42589 RunEncryptedMediaTest(kDefaultEmePlayer, "bear-a_enc-a.webm", kWebMAudioOnly,
ddorwinfdb9a2b2016-02-22 22:25:10590 "com.widevine", MSE, kNoSessionToLoad, false,
591 PlayTwice::NO, kEmeNotSupportedError);
[email protected]63dc9072013-09-12 06:20:47592}
[email protected]63dc9072013-09-12 06:20:47593#endif // defined(WIDEVINE_CDM_AVAILABLE)
[email protected]a941d4e572013-10-14 21:22:05594
595#if defined(ENABLE_PEPPER_CDMS)
[email protected]34afd582013-12-20 07:26:18596IN_PROC_BROWSER_TEST_F(ECKEncryptedMediaTest, InitializeCDMFail) {
jrummell87a2db52015-05-05 22:27:18597 TestNonPlaybackCases(kExternalClearKeyInitializeFailKeySystem,
598 kEmeNotSupportedError);
[email protected]a941d4e572013-10-14 21:22:05599}
[email protected]34afd582013-12-20 07:26:18600
jrummellfed298d22015-07-01 00:26:51601// When CDM crashes, we should still get a decode error. |kError| is reported
602// when the HTMLVideoElement error event fires, indicating an error happened
603// during playback.
604IN_PROC_BROWSER_TEST_F(ECKEncryptedMediaTest, CDMCrashDuringDecode) {
[email protected]1be9fa072014-03-21 22:50:29605 IgnorePluginCrash();
[email protected]0af5dfa2014-02-07 22:33:44606 TestNonPlaybackCases(kExternalClearKeyCrashKeySystem, kError);
[email protected]a27d34ab2014-01-09 04:23:29607}
608
[email protected]1be9fa072014-03-21 22:50:29609// Testing that the media browser test does fail on plugin crash.
jrummellfed298d22015-07-01 00:26:51610IN_PROC_BROWSER_TEST_F(ECKEncryptedMediaTest, CDMExpectedCrash) {
[email protected]1be9fa072014-03-21 22:50:29611 // Plugin crash is not ignored by default, the test is expected to fail.
612 EXPECT_NONFATAL_FAILURE(
613 TestNonPlaybackCases(kExternalClearKeyCrashKeySystem, kError),
jrummellfed298d22015-07-01 00:26:51614 "Failing test due to plugin crash.");
[email protected]1be9fa072014-03-21 22:50:29615}
616
xhwang0c617e112014-09-19 17:33:24617IN_PROC_BROWSER_TEST_F(ECKEncryptedMediaTest, FileIOTest) {
[email protected]0af5dfa2014-02-07 22:33:44618 TestNonPlaybackCases(kExternalClearKeyFileIOTestKeySystem,
619 kFileIOTestSuccess);
620}
621
622IN_PROC_BROWSER_TEST_F(ECKEncryptedMediaTest, LoadLoadableSession) {
jrummell19f2c902015-02-11 01:17:50623 TestPlaybackCase(kLoadableSession, kEnded);
[email protected]0af5dfa2014-02-07 22:33:44624}
625
626IN_PROC_BROWSER_TEST_F(ECKEncryptedMediaTest, LoadUnknownSession) {
jrummell14fae6f2015-07-10 20:40:15627 TestPlaybackCase(kUnknownSession, kEmeSessionNotFound);
[email protected]34afd582013-12-20 07:26:18628}
jrummellc467d232014-10-21 17:55:22629
[email protected]a941d4e572013-10-14 21:22:05630#endif // defined(ENABLE_PEPPER_CDMS)