blob: 779773087e81ee311c54f912b036c40660fe5dc4 [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
5#include "base/command_line.h"
[email protected]df06a3e2014-01-31 21:36:596#include "base/memory/scoped_ptr.h"
[email protected]63dc9072013-09-12 06:20:477#include "base/path_service.h"
8#include "base/strings/utf_string_conversions.h"
9#include "base/win/windows_version.h"
10#include "chrome/browser/media/media_browsertest.h"
[email protected]df06a3e2014-01-31 21:36:5911#include "chrome/browser/media/test_license_server.h"
12#include "chrome/browser/media/wv_test_license_server_config.h"
[email protected]63dc9072013-09-12 06:20:4713#include "chrome/browser/ui/browser.h"
14#include "chrome/browser/ui/tabs/tab_strip_model.h"
15#include "chrome/common/chrome_switches.h"
16#include "content/public/test/browser_test_utils.h"
[email protected]1be9fa072014-03-21 22:50:2917#include "testing/gtest/include/gtest/gtest-spi.h"
[email protected]6479b192013-10-19 18:28:0418#if defined(OS_ANDROID)
19#include "base/android/build_info.h"
20#endif
[email protected]63dc9072013-09-12 06:20:4721
[email protected]df06a3e2014-01-31 21:36:5922#include "widevine_cdm_version.h" // In SHARED_INTERMEDIATE_DIR.
[email protected]63dc9072013-09-12 06:20:4723
[email protected]63dc9072013-09-12 06:20:4724#if defined(ENABLE_PEPPER_CDMS)
25// Platform-specific filename relative to the chrome executable.
[email protected]1825e772013-10-08 06:39:1126const char kClearKeyCdmAdapterFileName[] =
[email protected]63dc9072013-09-12 06:20:4727#if defined(OS_MACOSX)
28 "clearkeycdmadapter.plugin";
29#elif defined(OS_WIN)
30 "clearkeycdmadapter.dll";
31#elif defined(OS_POSIX)
32 "libclearkeycdmadapter.so";
33#endif
[email protected]1825e772013-10-08 06:39:1134
35const char kClearKeyCdmPluginMimeType[] = "application/x-ppapi-clearkey-cdm";
[email protected]63dc9072013-09-12 06:20:4736#endif // defined(ENABLE_PEPPER_CDMS)
37
38// Available key systems.
[email protected]a32ef592014-03-07 19:11:1539const char kClearKeyKeySystem[] = "org.w3.clearkey";
40const char kPrefixedClearKeyKeySystem[] = "webkit-org.w3.clearkey";
[email protected]ab998e82013-11-22 20:31:3541const char kExternalClearKeyKeySystem[] = "org.chromium.externalclearkey";
42const char kExternalClearKeyDecryptOnlyKeySystem[] =
43 "org.chromium.externalclearkey.decryptonly";
[email protected]34afd582013-12-20 07:26:1844const char kExternalClearKeyFileIOTestKeySystem[] =
45 "org.chromium.externalclearkey.fileiotest";
[email protected]ab998e82013-11-22 20:31:3546const char kExternalClearKeyInitializeFailKeySystem[] =
47 "org.chromium.externalclearkey.initializefail";
[email protected]a27d34ab2014-01-09 04:23:2948const char kExternalClearKeyCrashKeySystem[] =
49 "org.chromium.externalclearkey.crash";
[email protected]63dc9072013-09-12 06:20:4750
51// Supported media types.
[email protected]095ccbe42013-09-26 00:06:4252const char kWebMAudioOnly[] = "audio/webm; codecs=\"vorbis\"";
53const char kWebMVideoOnly[] = "video/webm; codecs=\"vp8\"";
[email protected]095ccbe42013-09-26 00:06:4254const char kWebMAudioVideo[] = "video/webm; codecs=\"vorbis, vp8\"";
jamescook6107ed82014-11-06 06:59:2155// Some tests are disabled in Chrome OS official builds. http://crbug.com/430711
56#if !(defined(OS_CHROMEOS) && defined(OFFICIAL_BUILD))
57const char kWebMVP9VideoOnly[] = "video/webm; codecs=\"vp9\"";
[email protected]095ccbe42013-09-26 00:06:4258#if defined(USE_PROPRIETARY_CODECS)
59const char kMP4AudioOnly[] = "audio/mp4; codecs=\"mp4a.40.2\"";
60const char kMP4VideoOnly[] = "video/mp4; codecs=\"avc1.4D4041\"";
61#endif // defined(USE_PROPRIETARY_CODECS)
jamescook6107ed82014-11-06 06:59:2162#endif // !(defined(OS_CHROMEOS) && defined(OFFICIAL_BUILD))
[email protected]63dc9072013-09-12 06:20:4763
[email protected]0af5dfa2014-02-07 22:33:4464// Sessions to load.
65const char kNoSessionToLoad[] = "";
66const char kLoadableSession[] = "LoadableSession";
67const char kUnknownSession[] = "UnknownSession";
68
[email protected]2e850f12013-09-18 01:27:2969// EME-specific test results and errors.
[email protected]e11d89d2014-06-19 11:36:3170const char kEmeKeyError[] = "KEY_ERROR";
[email protected]297b5a352013-10-18 00:09:1771const char kEmeNotSupportedError[] = "NOTSUPPORTEDERROR";
[email protected]e11d89d2014-06-19 11:36:3172const char kFileIOTestSuccess[] = "FILE_IO_TEST_SUCCESS";
73
74const char kDefaultEmePlayer[] = "eme_player.html";
[email protected]63dc9072013-09-12 06:20:4775
76// The type of video src used to load media.
77enum SrcType {
78 SRC,
79 MSE
80};
81
[email protected]a32ef592014-03-07 19:11:1582// Whether to use prefixed or unprefixed EME.
83enum EmeVersion {
84 PREFIXED,
85 UNPREFIXED
86};
87
[email protected]6479b192013-10-19 18:28:0488// MSE is available on all desktop platforms and on Android 4.1 and later.
89static bool IsMSESupported() {
90#if defined(OS_ANDROID)
91 if (base::android::BuildInfo::GetInstance()->sdk_int() < 16) {
anujk.sharma9da298e12014-11-07 04:48:4392 DVLOG(0) << "MSE is only supported in Android 4.1 and later.";
[email protected]6479b192013-10-19 18:28:0493 return false;
94 }
95#endif // defined(OS_ANDROID)
96 return true;
97}
98
[email protected]ab998e82013-11-22 20:31:3599static bool IsParentKeySystemOf(const std::string& parent_key_system,
100 const std::string& key_system) {
101 std::string prefix = parent_key_system + '.';
102 return key_system.substr(0, prefix.size()) == prefix;
103}
104
[email protected]e6bf64142013-10-18 23:07:54105// Base class for encrypted media tests.
106class EncryptedMediaTestBase : public MediaBrowserTest {
[email protected]63dc9072013-09-12 06:20:47107 public:
[email protected]e6bf64142013-10-18 23:07:54108 EncryptedMediaTestBase() : is_pepper_cdm_registered_(false) {}
[email protected]63dc9072013-09-12 06:20:47109
[email protected]ab998e82013-11-22 20:31:35110 bool IsExternalClearKey(const std::string& key_system) {
111 return key_system == kExternalClearKeyKeySystem ||
112 IsParentKeySystemOf(kExternalClearKeyKeySystem, key_system);
[email protected]63dc9072013-09-12 06:20:47113 }
114
[email protected]1825e772013-10-08 06:39:11115#if defined(WIDEVINE_CDM_AVAILABLE)
[email protected]ab998e82013-11-22 20:31:35116 bool IsWidevine(const std::string& key_system) {
117 return key_system == kWidevineKeySystem;
[email protected]1825e772013-10-08 06:39:11118 }
119#endif // defined(WIDEVINE_CDM_AVAILABLE)
120
[email protected]8a229322014-07-22 23:33:07121 void RunEncryptedMediaTestPage(
122 const std::string& html_page,
123 const std::string& key_system,
anand.ratn2636d972014-09-30 04:06:58124 base::StringPairs& query_params,
[email protected]8a229322014-07-22 23:33:07125 const std::string& expected_title) {
anand.ratn2636d972014-09-30 04:06:58126 base::StringPairs new_query_params = query_params;
[email protected]8a229322014-07-22 23:33:07127 StartLicenseServerIfNeeded(key_system, &new_query_params);
128 RunMediaTestPage(html_page, new_query_params, expected_title, true);
[email protected]df06a3e2014-01-31 21:36:59129 }
130
[email protected]0af5dfa2014-02-07 22:33:44131 // Tests |html_page| using |media_file| (with |media_type|) and |key_system|.
132 // When |session_to_load| is not empty, the test will try to load
133 // |session_to_load| with stored keys, instead of creating a new session
134 // and trying to update it with licenses.
135 // When |force_invalid_response| is true, the test will provide invalid
136 // responses, which should trigger errors.
137 // TODO(xhwang): Find an easier way to pass multiple configuration test
138 // options.
[email protected]df06a3e2014-01-31 21:36:59139 void RunEncryptedMediaTest(const std::string& html_page,
140 const std::string& media_file,
141 const std::string& media_type,
142 const std::string& key_system,
[email protected]1825e772013-10-08 06:39:11143 SrcType src_type,
[email protected]a32ef592014-03-07 19:11:15144 EmeVersion eme_version,
[email protected]0af5dfa2014-02-07 22:33:44145 const std::string& session_to_load,
[email protected]df06a3e2014-01-31 21:36:59146 bool force_invalid_response,
147 const std::string& expected_title) {
[email protected]6479b192013-10-19 18:28:04148 if (src_type == MSE && !IsMSESupported()) {
anujk.sharma9da298e12014-11-07 04:48:43149 DVLOG(0) << "Skipping test - MSE not supported.";
[email protected]6479b192013-10-19 18:28:04150 return;
151 }
anand.ratn2636d972014-09-30 04:06:58152 base::StringPairs query_params;
[email protected]df06a3e2014-01-31 21:36:59153 query_params.push_back(std::make_pair("mediaFile", media_file));
154 query_params.push_back(std::make_pair("mediaType", media_type));
155 query_params.push_back(std::make_pair("keySystem", key_system));
[email protected]63dc9072013-09-12 06:20:47156 if (src_type == MSE)
[email protected]df06a3e2014-01-31 21:36:59157 query_params.push_back(std::make_pair("useMSE", "1"));
[email protected]a32ef592014-03-07 19:11:15158 if (eme_version == PREFIXED)
159 query_params.push_back(std::make_pair("usePrefixedEME", "1"));
[email protected]df06a3e2014-01-31 21:36:59160 if (force_invalid_response)
161 query_params.push_back(std::make_pair("forceInvalidResponse", "1"));
[email protected]0af5dfa2014-02-07 22:33:44162 if (!session_to_load.empty())
163 query_params.push_back(std::make_pair("sessionToLoad", session_to_load));
[email protected]8a229322014-07-22 23:33:07164 RunEncryptedMediaTestPage(html_page, key_system, query_params,
[email protected]df06a3e2014-01-31 21:36:59165 expected_title);
[email protected]63dc9072013-09-12 06:20:47166 }
167
[email protected]df06a3e2014-01-31 21:36:59168 void RunSimpleEncryptedMediaTest(const std::string& media_file,
169 const std::string& media_type,
170 const std::string& key_system,
[email protected]a32ef592014-03-07 19:11:15171 SrcType src_type,
172 EmeVersion eme_version) {
[email protected]df06a3e2014-01-31 21:36:59173 std::string expected_title = kEnded;
174 if (!IsPlayBackPossible(key_system))
175 expected_title = kEmeKeyError;
[email protected]1825e772013-10-08 06:39:11176
[email protected]e11d89d2014-06-19 11:36:31177 RunEncryptedMediaTest(kDefaultEmePlayer,
[email protected]a32ef592014-03-07 19:11:15178 media_file,
179 media_type,
180 key_system,
181 src_type,
182 eme_version,
183 kNoSessionToLoad,
184 false,
[email protected]df06a3e2014-01-31 21:36:59185 expected_title);
186 // Check KeyMessage received for all key systems.
187 bool receivedKeyMessage = false;
188 EXPECT_TRUE(content::ExecuteScriptAndExtractBool(
189 browser()->tab_strip_model()->GetActiveWebContents(),
[email protected]e11d89d2014-06-19 11:36:31190 "window.domAutomationController.send("
191 "document.querySelector('video').receivedKeyMessage);",
[email protected]df06a3e2014-01-31 21:36:59192 &receivedKeyMessage));
193 EXPECT_TRUE(receivedKeyMessage);
194 }
195
[email protected]8a229322014-07-22 23:33:07196 // Starts a license server if available for the |key_system| and adds a
197 // 'licenseServerURL' query parameter to |query_params|.
[email protected]df06a3e2014-01-31 21:36:59198 void StartLicenseServerIfNeeded(const std::string& key_system,
anand.ratn2636d972014-09-30 04:06:58199 base::StringPairs* query_params) {
[email protected]df06a3e2014-01-31 21:36:59200 scoped_ptr<TestLicenseServerConfig> config = GetServerConfig(key_system);
201 if (!config)
202 return;
203 license_server_.reset(new TestLicenseServer(config.Pass()));
204 EXPECT_TRUE(license_server_->Start());
[email protected]8a229322014-07-22 23:33:07205 query_params->push_back(
206 std::make_pair("licenseServerURL", license_server_->GetServerURL()));
[email protected]df06a3e2014-01-31 21:36:59207 }
208
209 bool IsPlayBackPossible(const std::string& key_system) {
210#if defined(WIDEVINE_CDM_AVAILABLE)
211 if (IsWidevine(key_system) && !GetServerConfig(key_system))
212 return false;
213#endif // defined(WIDEVINE_CDM_AVAILABLE)
214 return true;
215 }
216
217 scoped_ptr<TestLicenseServerConfig> GetServerConfig(
218 const std::string& key_system) {
219#if defined(WIDEVINE_CDM_AVAILABLE)
220 if (IsWidevine(key_system)) {
221 scoped_ptr<TestLicenseServerConfig> config =
222 scoped_ptr<TestLicenseServerConfig>(new WVTestLicenseServerConfig());
223 if (config->IsPlatformSupported())
224 return config.Pass();
225 }
226#endif // defined(WIDEVINE_CDM_AVAILABLE)
227 return scoped_ptr<TestLicenseServerConfig>();
[email protected]1825e772013-10-08 06:39:11228 }
229
[email protected]63dc9072013-09-12 06:20:47230 protected:
[email protected]df06a3e2014-01-31 21:36:59231 scoped_ptr<TestLicenseServer> license_server_;
232
[email protected]2e850f12013-09-18 01:27:29233 // We want to fail quickly when a test fails because an error is encountered.
dchengd7e84a052014-10-22 00:18:51234 void AddWaitForTitles(content::TitleWatcher* title_watcher) override {
[email protected]2e850f12013-09-18 01:27:29235 MediaBrowserTest::AddWaitForTitles(title_watcher);
[email protected]6778fed2013-12-24 20:09:37236 title_watcher->AlsoWaitForTitle(base::ASCIIToUTF16(kEmeNotSupportedError));
237 title_watcher->AlsoWaitForTitle(base::ASCIIToUTF16(kEmeKeyError));
[email protected]2e850f12013-09-18 01:27:29238 }
239
dchengd7e84a052014-10-22 00:18:51240 void SetUpCommandLine(CommandLine* command_line) override {
[email protected]2289b432014-08-08 17:52:11241#if defined(OS_ANDROID)
242 command_line->AppendSwitch(
243 switches::kDisableGestureRequirementForMediaPlayback);
244#endif // defined(OS_ANDROID)
245 }
246
[email protected]df06a3e2014-01-31 21:36:59247 void SetUpCommandLineForKeySystem(const std::string& key_system,
[email protected]e6bf64142013-10-18 23:07:54248 CommandLine* command_line) {
[email protected]df06a3e2014-01-31 21:36:59249 if (GetServerConfig(key_system))
250 // Since the web and license servers listen on different ports, we need to
251 // disable web-security to send license requests to the license server.
252 // TODO(shadi): Add port forwarding to the test web server configuration.
253 command_line->AppendSwitch(switches::kDisableWebSecurity);
254
[email protected]e6bf64142013-10-18 23:07:54255#if defined(ENABLE_PEPPER_CDMS)
256 if (IsExternalClearKey(key_system)) {
[email protected]ab998e82013-11-22 20:31:35257 RegisterPepperCdm(command_line, kClearKeyCdmAdapterFileName, key_system);
[email protected]e6bf64142013-10-18 23:07:54258 }
259#if defined(WIDEVINE_CDM_AVAILABLE) && defined(WIDEVINE_CDM_IS_COMPONENT)
260 else if (IsWidevine(key_system)) {
[email protected]ab998e82013-11-22 20:31:35261 RegisterPepperCdm(command_line, kWidevineCdmAdapterFileName, key_system);
[email protected]e6bf64142013-10-18 23:07:54262 }
263#endif // defined(WIDEVINE_CDM_AVAILABLE) && defined(WIDEVINE_CDM_IS_COMPONENT)
264#endif // defined(ENABLE_PEPPER_CDMS)
265 }
266
267 private:
[email protected]1825e772013-10-08 06:39:11268#if defined(ENABLE_PEPPER_CDMS)
[email protected]63dc9072013-09-12 06:20:47269 void RegisterPepperCdm(CommandLine* command_line,
270 const std::string& adapter_name,
271 const std::string& key_system) {
[email protected]e6bf64142013-10-18 23:07:54272 DCHECK(!is_pepper_cdm_registered_)
273 << "RegisterPepperCdm() can only be called once.";
274 is_pepper_cdm_registered_ = true;
275
[email protected]63dc9072013-09-12 06:20:47276 // Append the switch to register the Clear Key CDM Adapter.
277 base::FilePath plugin_dir;
278 EXPECT_TRUE(PathService::Get(base::DIR_MODULE, &plugin_dir));
279 base::FilePath plugin_lib = plugin_dir.AppendASCII(adapter_name);
[email protected]1825e772013-10-08 06:39:11280 EXPECT_TRUE(base::PathExists(plugin_lib)) << plugin_lib.value();
[email protected]63dc9072013-09-12 06:20:47281 base::FilePath::StringType pepper_plugin = plugin_lib.value();
282 pepper_plugin.append(FILE_PATH_LITERAL("#CDM#0.1.0.0;"));
283#if defined(OS_WIN)
[email protected]6778fed2013-12-24 20:09:37284 pepper_plugin.append(base::ASCIIToWide(GetPepperType(key_system)));
[email protected]63dc9072013-09-12 06:20:47285#else
286 pepper_plugin.append(GetPepperType(key_system));
287#endif
288 command_line->AppendSwitchNative(switches::kRegisterPepperPlugins,
289 pepper_plugin);
290 }
291
292 // Adapted from key_systems.cc.
293 std::string GetPepperType(const std::string& key_system) {
[email protected]ab998e82013-11-22 20:31:35294 if (IsExternalClearKey(key_system))
[email protected]1825e772013-10-08 06:39:11295 return kClearKeyCdmPluginMimeType;
[email protected]63dc9072013-09-12 06:20:47296#if defined(WIDEVINE_CDM_AVAILABLE)
[email protected]ab998e82013-11-22 20:31:35297 if (IsWidevine(key_system))
[email protected]1825e772013-10-08 06:39:11298 return kWidevineCdmPluginMimeType;
[email protected]63dc9072013-09-12 06:20:47299#endif // WIDEVINE_CDM_AVAILABLE
300
301 NOTREACHED();
302 return "";
303 }
304#endif // defined(ENABLE_PEPPER_CDMS)
[email protected]e6bf64142013-10-18 23:07:54305
306 bool is_pepper_cdm_registered_;
307};
308
309#if defined(ENABLE_PEPPER_CDMS)
[email protected]ab998e82013-11-22 20:31:35310// Tests encrypted media playback using ExternalClearKey key system in
311// decrypt-and-decode mode.
[email protected]e6bf64142013-10-18 23:07:54312class ECKEncryptedMediaTest : public EncryptedMediaTestBase {
[email protected]0af5dfa2014-02-07 22:33:44313 public:
314 // We use special |key_system| names to do non-playback related tests, e.g.
315 // kExternalClearKeyFileIOTestKeySystem is used to test file IO.
316 void TestNonPlaybackCases(const std::string& key_system,
317 const std::string& expected_title) {
318 // Since we do not test playback, arbitrarily choose a test file and source
319 // type.
[email protected]e11d89d2014-06-19 11:36:31320 RunEncryptedMediaTest(kDefaultEmePlayer,
[email protected]8a229322014-07-22 23:33:07321 "bear-a_enc-a.webm",
[email protected]0af5dfa2014-02-07 22:33:44322 kWebMAudioOnly,
323 key_system,
324 SRC,
[email protected]a32ef592014-03-07 19:11:15325 PREFIXED,
[email protected]0af5dfa2014-02-07 22:33:44326 kNoSessionToLoad,
327 false,
328 expected_title);
329 }
330
[email protected]e6bf64142013-10-18 23:07:54331 protected:
dchengd7e84a052014-10-22 00:18:51332 void SetUpCommandLine(CommandLine* command_line) override {
[email protected]e6bf64142013-10-18 23:07:54333 EncryptedMediaTestBase::SetUpCommandLine(command_line);
334 SetUpCommandLineForKeySystem(kExternalClearKeyKeySystem, command_line);
335 }
336};
337
jrummellc467d232014-10-21 17:55:22338// Tests encrypted media playback using ExternalClearKey key system in
339// decrypt-and-decode mode for unprefixed EME.
340// TODO(jrummell): Merge with ECKEncryptedMediaTest once unprefixed is
341// enabled by default.
342class ECKUnprefixedEncryptedMediaTest : public EncryptedMediaTestBase {
343 protected:
dchenge1bc7982014-10-30 00:32:40344 void SetUpCommandLine(CommandLine* command_line) override {
jrummellc467d232014-10-21 17:55:22345 EncryptedMediaTestBase::SetUpCommandLine(command_line);
346 command_line->AppendSwitch(switches::kEnableEncryptedMedia);
347 SetUpCommandLineForKeySystem(kExternalClearKeyKeySystem, command_line);
348 }
349};
350
[email protected]e6bf64142013-10-18 23:07:54351#if defined(WIDEVINE_CDM_AVAILABLE)
352// Tests encrypted media playback using Widevine key system.
353class WVEncryptedMediaTest : public EncryptedMediaTestBase {
354 protected:
mostynb2b52d1db2014-10-07 02:47:17355 virtual void SetUpCommandLine(CommandLine* command_line) override {
[email protected]e6bf64142013-10-18 23:07:54356 EncryptedMediaTestBase::SetUpCommandLine(command_line);
[email protected]a32ef592014-03-07 19:11:15357 command_line->AppendSwitch(switches::kEnableEncryptedMedia);
[email protected]e6bf64142013-10-18 23:07:54358 SetUpCommandLineForKeySystem(kWidevineKeySystem, command_line);
359 }
360};
[email protected]df06a3e2014-01-31 21:36:59361
[email protected]e6bf64142013-10-18 23:07:54362#endif // defined(WIDEVINE_CDM_AVAILABLE)
363#endif // defined(ENABLE_PEPPER_CDMS)
364
365// Tests encrypted media playback with a combination of parameters:
366// - char*: Key system name.
367// - bool: True to load media using MSE, otherwise use src.
[email protected]a32ef592014-03-07 19:11:15368// - bool: True to use unprefixed EME, otherwise use prefixed EME.
[email protected]e6bf64142013-10-18 23:07:54369//
370// Note: Only parameterized (*_P) tests can be used. Non-parameterized (*_F)
371// tests will crash at GetParam(). To add non-parameterized tests, use
372// EncryptedMediaTestBase or one of its subclasses (e.g. WVEncryptedMediaTest).
[email protected]a32ef592014-03-07 19:11:15373class EncryptedMediaTest
374 : public EncryptedMediaTestBase,
375 public testing::WithParamInterface<
376 std::tr1::tuple<const char*, SrcType, EmeVersion> > {
[email protected]e6bf64142013-10-18 23:07:54377 public:
[email protected]df06a3e2014-01-31 21:36:59378 std::string CurrentKeySystem() {
[email protected]e6bf64142013-10-18 23:07:54379 return std::tr1::get<0>(GetParam());
380 }
381
382 SrcType CurrentSourceType() {
383 return std::tr1::get<1>(GetParam());
384 }
385
[email protected]a32ef592014-03-07 19:11:15386 EmeVersion CurrentEmeVersion() {
387 return std::tr1::get<2>(GetParam());
388 }
389
[email protected]df06a3e2014-01-31 21:36:59390 void TestSimplePlayback(const std::string& encrypted_media,
391 const std::string& media_type) {
[email protected]a32ef592014-03-07 19:11:15392 RunSimpleEncryptedMediaTest(encrypted_media,
393 media_type,
394 CurrentKeySystem(),
395 CurrentSourceType(),
396 CurrentEmeVersion());
[email protected]e6bf64142013-10-18 23:07:54397 }
398
[email protected]df06a3e2014-01-31 21:36:59399 void RunInvalidResponseTest() {
[email protected]e11d89d2014-06-19 11:36:31400 RunEncryptedMediaTest(kDefaultEmePlayer,
[email protected]8a229322014-07-22 23:33:07401 "bear-320x240-av_enc-av.webm",
[email protected]df06a3e2014-01-31 21:36:59402 kWebMAudioVideo,
403 CurrentKeySystem(),
404 CurrentSourceType(),
[email protected]a32ef592014-03-07 19:11:15405 CurrentEmeVersion(),
[email protected]0af5dfa2014-02-07 22:33:44406 kNoSessionToLoad,
[email protected]df06a3e2014-01-31 21:36:59407 true,
408 kEmeKeyError);
409 }
410
[email protected]e6bf64142013-10-18 23:07:54411 void TestFrameSizeChange() {
[email protected]e6bf64142013-10-18 23:07:54412 RunEncryptedMediaTest("encrypted_frame_size_change.html",
[email protected]8a229322014-07-22 23:33:07413 "frame_size_change-av_enc-v.webm",
[email protected]df06a3e2014-01-31 21:36:59414 kWebMAudioVideo,
415 CurrentKeySystem(),
416 CurrentSourceType(),
[email protected]a32ef592014-03-07 19:11:15417 CurrentEmeVersion(),
[email protected]0af5dfa2014-02-07 22:33:44418 kNoSessionToLoad,
[email protected]df06a3e2014-01-31 21:36:59419 false,
420 kEnded);
[email protected]e6bf64142013-10-18 23:07:54421 }
422
423 void TestConfigChange() {
[email protected]df06a3e2014-01-31 21:36:59424 DCHECK(IsMSESupported());
anand.ratn2636d972014-09-30 04:06:58425 base::StringPairs query_params;
[email protected]df06a3e2014-01-31 21:36:59426 query_params.push_back(std::make_pair("keySystem", CurrentKeySystem()));
427 query_params.push_back(std::make_pair("runEncrypted", "1"));
[email protected]a32ef592014-03-07 19:11:15428 if (CurrentEmeVersion() == PREFIXED)
429 query_params.push_back(std::make_pair("usePrefixedEME", "1"));
[email protected]df06a3e2014-01-31 21:36:59430 RunEncryptedMediaTestPage("mse_config_change.html",
431 CurrentKeySystem(),
[email protected]8a229322014-07-22 23:33:07432 query_params,
[email protected]df06a3e2014-01-31 21:36:59433 kEnded);
[email protected]e6bf64142013-10-18 23:07:54434 }
435
436 protected:
dchengd7e84a052014-10-22 00:18:51437 void SetUpCommandLine(CommandLine* command_line) override {
[email protected]e6bf64142013-10-18 23:07:54438 EncryptedMediaTestBase::SetUpCommandLine(command_line);
439 SetUpCommandLineForKeySystem(CurrentKeySystem(), command_line);
[email protected]a32ef592014-03-07 19:11:15440
441 if (CurrentEmeVersion() == UNPREFIXED)
442 command_line->AppendSwitch(switches::kEnableEncryptedMedia);
[email protected]e6bf64142013-10-18 23:07:54443 }
[email protected]63dc9072013-09-12 06:20:47444};
445
[email protected]6479b192013-10-19 18:28:04446using ::testing::Combine;
447using ::testing::Values;
448
449#if !defined(OS_ANDROID)
[email protected]a32ef592014-03-07 19:11:15450INSTANTIATE_TEST_CASE_P(SRC_ClearKey_Prefixed,
451 EncryptedMediaTest,
452 Combine(Values(kPrefixedClearKeyKeySystem),
453 Values(SRC),
454 Values(PREFIXED)));
455
456// TODO(jrummell): Enable unprefixed tests before shipping unprefixed EME.
457// Disabled now as they don't provide much additional coverage, but do take a
458// bit of time to execute.
459INSTANTIATE_TEST_CASE_P(DISABLED_SRC_ClearKey,
460 EncryptedMediaTest,
461 Combine(Values(kClearKeyKeySystem),
462 Values(SRC),
463 Values(UNPREFIXED)));
[email protected]6479b192013-10-19 18:28:04464#endif // !defined(OS_ANDROID)
465
[email protected]a32ef592014-03-07 19:11:15466INSTANTIATE_TEST_CASE_P(MSE_ClearKey_Prefixed,
467 EncryptedMediaTest,
468 Combine(Values(kPrefixedClearKeyKeySystem),
469 Values(MSE),
470 Values(PREFIXED)));
jrummell77419192014-10-31 21:40:44471INSTANTIATE_TEST_CASE_P(MSE_ClearKey,
[email protected]a32ef592014-03-07 19:11:15472 EncryptedMediaTest,
473 Combine(Values(kClearKeyKeySystem),
474 Values(MSE),
475 Values(UNPREFIXED)));
[email protected]63dc9072013-09-12 06:20:47476
477// External Clear Key is currently only used on platforms that use Pepper CDMs.
478#if defined(ENABLE_PEPPER_CDMS)
[email protected]a32ef592014-03-07 19:11:15479INSTANTIATE_TEST_CASE_P(SRC_ExternalClearKey_Prefixed,
480 EncryptedMediaTest,
481 Combine(Values(kExternalClearKeyKeySystem),
482 Values(SRC),
483 Values(PREFIXED)));
[email protected]1ab297a2014-03-26 04:52:12484INSTANTIATE_TEST_CASE_P(SRC_ExternalClearKey,
[email protected]a32ef592014-03-07 19:11:15485 EncryptedMediaTest,
486 Combine(Values(kExternalClearKeyKeySystem),
487 Values(SRC),
488 Values(UNPREFIXED)));
489INSTANTIATE_TEST_CASE_P(MSE_ExternalClearKey_Prefixed,
490 EncryptedMediaTest,
491 Combine(Values(kExternalClearKeyKeySystem),
492 Values(MSE),
493 Values(PREFIXED)));
[email protected]1ab297a2014-03-26 04:52:12494INSTANTIATE_TEST_CASE_P(MSE_ExternalClearKey,
[email protected]a32ef592014-03-07 19:11:15495 EncryptedMediaTest,
496 Combine(Values(kExternalClearKeyKeySystem),
497 Values(MSE),
498 Values(UNPREFIXED)));
[email protected]ab998e82013-11-22 20:31:35499// To reduce test time, only run ExternalClearKeyDecryptOnly with MSE.
[email protected]a32ef592014-03-07 19:11:15500INSTANTIATE_TEST_CASE_P(MSE_ExternalClearKeyDecryptOnly_Prefixed,
501 EncryptedMediaTest,
502 Combine(Values(kExternalClearKeyDecryptOnlyKeySystem),
503 Values(MSE),
504 Values(PREFIXED)));
[email protected]1ab297a2014-03-26 04:52:12505INSTANTIATE_TEST_CASE_P(MSE_ExternalClearKeyDecryptOnly,
[email protected]a32ef592014-03-07 19:11:15506 EncryptedMediaTest,
507 Combine(Values(kExternalClearKeyDecryptOnlyKeySystem),
508 Values(MSE),
509 Values(UNPREFIXED)));
[email protected]8a229322014-07-22 23:33:07510#endif // defined(ENABLE_PEPPER_CDMS)
[email protected]63dc9072013-09-12 06:20:47511
[email protected]1825e772013-10-08 06:39:11512#if defined(WIDEVINE_CDM_AVAILABLE)
513// This test doesn't fully test playback with Widevine. So we only run Widevine
[email protected]6479b192013-10-19 18:28:04514// test with MSE (no SRC) to reduce test time. Also, on Android EME only works
515// with MSE and we cannot run this test with SRC.
[email protected]a32ef592014-03-07 19:11:15516INSTANTIATE_TEST_CASE_P(MSE_Widevine_Prefixed,
517 EncryptedMediaTest,
518 Combine(Values(kWidevineKeySystem),
519 Values(MSE),
520 Values(PREFIXED)));
[email protected]78d96542014-03-27 11:45:47521
522// Following tests fail if Widevine is loaded as a component, crbug.com/356833.
523#if !defined(WIDEVINE_CDM_IS_COMPONENT)
[email protected]1ab297a2014-03-26 04:52:12524INSTANTIATE_TEST_CASE_P(MSE_Widevine,
[email protected]a32ef592014-03-07 19:11:15525 EncryptedMediaTest,
526 Combine(Values(kWidevineKeySystem),
527 Values(MSE),
528 Values(UNPREFIXED)));
[email protected]78d96542014-03-27 11:45:47529#endif // !defined(WIDEVINE_CDM_IS_COMPONENT)
[email protected]1825e772013-10-08 06:39:11530#endif // defined(WIDEVINE_CDM_AVAILABLE)
[email protected]63dc9072013-09-12 06:20:47531
jamescook6107ed82014-11-06 06:59:21532// These tests time out in Chrome OS official builds. http://crbug.com/430711
533#if !(defined(OS_CHROMEOS) && defined(OFFICIAL_BUILD))
[email protected]626e517c2014-08-19 00:49:46534IN_PROC_BROWSER_TEST_P(EncryptedMediaTest, Playback_AudioOnly_WebM) {
[email protected]8a229322014-07-22 23:33:07535 TestSimplePlayback("bear-a_enc-a.webm", kWebMAudioOnly);
[email protected]63dc9072013-09-12 06:20:47536}
537
[email protected]626e517c2014-08-19 00:49:46538IN_PROC_BROWSER_TEST_P(EncryptedMediaTest, Playback_AudioClearVideo_WebM) {
[email protected]8a229322014-07-22 23:33:07539 TestSimplePlayback("bear-320x240-av_enc-a.webm", kWebMAudioVideo);
[email protected]63dc9072013-09-12 06:20:47540}
541
[email protected]626e517c2014-08-19 00:49:46542IN_PROC_BROWSER_TEST_P(EncryptedMediaTest, Playback_VideoAudio_WebM) {
[email protected]8a229322014-07-22 23:33:07543 TestSimplePlayback("bear-320x240-av_enc-av.webm", kWebMAudioVideo);
[email protected]63dc9072013-09-12 06:20:47544}
545
[email protected]626e517c2014-08-19 00:49:46546IN_PROC_BROWSER_TEST_P(EncryptedMediaTest, Playback_VideoOnly_WebM) {
[email protected]8a229322014-07-22 23:33:07547 TestSimplePlayback("bear-320x240-v_enc-v.webm", kWebMVideoOnly);
[email protected]63dc9072013-09-12 06:20:47548}
549
[email protected]626e517c2014-08-19 00:49:46550IN_PROC_BROWSER_TEST_P(EncryptedMediaTest, Playback_VideoClearAudio_WebM) {
[email protected]8a229322014-07-22 23:33:07551 TestSimplePlayback("bear-320x240-av_enc-v.webm", kWebMAudioVideo);
[email protected]63dc9072013-09-12 06:20:47552}
553
[email protected]626e517c2014-08-19 00:49:46554IN_PROC_BROWSER_TEST_P(EncryptedMediaTest, Playback_VP9Video_WebM) {
[email protected]8a229322014-07-22 23:33:07555 TestSimplePlayback("bear-320x240-v-vp9_enc-v.webm", kWebMVP9VideoOnly);
[email protected]2b197ac72014-04-11 23:33:52556}
557
[email protected]626e517c2014-08-19 00:49:46558IN_PROC_BROWSER_TEST_P(EncryptedMediaTest, InvalidResponseKeyError) {
[email protected]df06a3e2014-01-31 21:36:59559 RunInvalidResponseTest();
560}
561
[email protected]1825e772013-10-08 06:39:11562IN_PROC_BROWSER_TEST_P(EncryptedMediaTest, ConfigChangeVideo) {
[email protected]df06a3e2014-01-31 21:36:59563 if (CurrentSourceType() != MSE || !IsMSESupported()) {
anujk.sharma9da298e12014-11-07 04:48:43564 DVLOG(0) << "Skipping test - ConfigChange test requires MSE.";
[email protected]df06a3e2014-01-31 21:36:59565 return;
566 }
567 if (!IsPlayBackPossible(CurrentKeySystem())) {
anujk.sharma9da298e12014-11-07 04:48:43568 DVLOG(0) << "Skipping test - ConfigChange test requires video playback.";
[email protected]df06a3e2014-01-31 21:36:59569 return;
570 }
[email protected]1825e772013-10-08 06:39:11571 TestConfigChange();
572}
573
574IN_PROC_BROWSER_TEST_P(EncryptedMediaTest, FrameSizeChangeVideo) {
[email protected]63dc9072013-09-12 06:20:47575 // Times out on Windows XP. http://crbug.com/171937
576#if defined(OS_WIN)
577 if (base::win::GetVersion() < base::win::VERSION_VISTA)
578 return;
579#endif
[email protected]df06a3e2014-01-31 21:36:59580 if (!IsPlayBackPossible(CurrentKeySystem())) {
anujk.sharma9da298e12014-11-07 04:48:43581 DVLOG(0) << "Skipping test - FrameSizeChange test requires video playback.";
[email protected]df06a3e2014-01-31 21:36:59582 return;
583 }
[email protected]1825e772013-10-08 06:39:11584 TestFrameSizeChange();
[email protected]63dc9072013-09-12 06:20:47585}
586
587#if defined(USE_PROPRIETARY_CODECS)
588IN_PROC_BROWSER_TEST_P(EncryptedMediaTest, Playback_VideoOnly_MP4) {
[email protected]63dc9072013-09-12 06:20:47589 // MP4 without MSE is not support yet, http://crbug.com/170793.
[email protected]1825e772013-10-08 06:39:11590 if (CurrentSourceType() != MSE) {
anujk.sharma9da298e12014-11-07 04:48:43591 DVLOG(0) << "Skipping test; Can only play MP4 encrypted streams by MSE.";
[email protected]63dc9072013-09-12 06:20:47592 return;
593 }
[email protected]1825e772013-10-08 06:39:11594 TestSimplePlayback("bear-640x360-v_frag-cenc.mp4", kMP4VideoOnly);
[email protected]63dc9072013-09-12 06:20:47595}
596
597IN_PROC_BROWSER_TEST_P(EncryptedMediaTest, Playback_AudioOnly_MP4) {
[email protected]63dc9072013-09-12 06:20:47598 // MP4 without MSE is not support yet, http://crbug.com/170793.
[email protected]1825e772013-10-08 06:39:11599 if (CurrentSourceType() != MSE) {
anujk.sharma9da298e12014-11-07 04:48:43600 DVLOG(0) << "Skipping test; Can only play MP4 encrypted streams by MSE.";
[email protected]63dc9072013-09-12 06:20:47601 return;
602 }
[email protected]1825e772013-10-08 06:39:11603 TestSimplePlayback("bear-640x360-a_frag-cenc.mp4", kMP4AudioOnly);
[email protected]63dc9072013-09-12 06:20:47604}
605#endif // defined(USE_PROPRIETARY_CODECS)
jamescook6107ed82014-11-06 06:59:21606#endif // !(defined(OS_CHROMEOS) && defined(OFFICIAL_BUILD))
[email protected]63dc9072013-09-12 06:20:47607
[email protected]63dc9072013-09-12 06:20:47608#if defined(WIDEVINE_CDM_AVAILABLE)
609// The parent key system cannot be used in generateKeyRequest.
[email protected]a32ef592014-03-07 19:11:15610IN_PROC_BROWSER_TEST_F(WVEncryptedMediaTest, ParentThrowsException_Prefixed) {
[email protected]e11d89d2014-06-19 11:36:31611 RunEncryptedMediaTest(kDefaultEmePlayer,
[email protected]8a229322014-07-22 23:33:07612 "bear-a_enc-a.webm",
[email protected]297b5a352013-10-18 00:09:17613 kWebMAudioOnly,
614 "com.widevine",
[email protected]e6bf64142013-10-18 23:07:54615 MSE,
[email protected]a32ef592014-03-07 19:11:15616 PREFIXED,
617 kNoSessionToLoad,
618 false,
619 kEmeNotSupportedError);
620}
621
622// TODO(jrummell): http://crbug.com/349181
623// The parent key system cannot be used when creating MediaKeys.
[email protected]b1620732014-04-01 23:17:18624IN_PROC_BROWSER_TEST_F(WVEncryptedMediaTest, ParentThrowsException) {
[email protected]e11d89d2014-06-19 11:36:31625 RunEncryptedMediaTest(kDefaultEmePlayer,
[email protected]8a229322014-07-22 23:33:07626 "bear-a_enc-a.webm",
[email protected]a32ef592014-03-07 19:11:15627 kWebMAudioOnly,
628 "com.widevine",
629 MSE,
630 UNPREFIXED,
[email protected]0af5dfa2014-02-07 22:33:44631 kNoSessionToLoad,
[email protected]df06a3e2014-01-31 21:36:59632 false,
[email protected]297b5a352013-10-18 00:09:17633 kEmeNotSupportedError);
[email protected]63dc9072013-09-12 06:20:47634}
[email protected]63dc9072013-09-12 06:20:47635#endif // defined(WIDEVINE_CDM_AVAILABLE)
[email protected]a941d4e572013-10-14 21:22:05636
637#if defined(ENABLE_PEPPER_CDMS)
[email protected]34afd582013-12-20 07:26:18638IN_PROC_BROWSER_TEST_F(ECKEncryptedMediaTest, InitializeCDMFail) {
[email protected]0af5dfa2014-02-07 22:33:44639 TestNonPlaybackCases(kExternalClearKeyInitializeFailKeySystem, kEmeKeyError);
[email protected]a941d4e572013-10-14 21:22:05640}
[email protected]34afd582013-12-20 07:26:18641
[email protected]a27d34ab2014-01-09 04:23:29642// When CDM crashes, we should still get a decode error.
[email protected]edaeb3f92014-06-19 18:27:22643// crbug.com/386657
644IN_PROC_BROWSER_TEST_F(ECKEncryptedMediaTest, DISABLED_CDMCrashDuringDecode) {
[email protected]1be9fa072014-03-21 22:50:29645 IgnorePluginCrash();
[email protected]0af5dfa2014-02-07 22:33:44646 TestNonPlaybackCases(kExternalClearKeyCrashKeySystem, kError);
[email protected]a27d34ab2014-01-09 04:23:29647}
648
[email protected]1be9fa072014-03-21 22:50:29649// Testing that the media browser test does fail on plugin crash.
[email protected]edaeb3f92014-06-19 18:27:22650// crbug.com/386657
651IN_PROC_BROWSER_TEST_F(ECKEncryptedMediaTest, DISABLED_CDMExpectedCrash) {
[email protected]1be9fa072014-03-21 22:50:29652 // Plugin crash is not ignored by default, the test is expected to fail.
653 EXPECT_NONFATAL_FAILURE(
654 TestNonPlaybackCases(kExternalClearKeyCrashKeySystem, kError),
655 "plugin crash");
656}
657
xhwang0c617e112014-09-19 17:33:24658IN_PROC_BROWSER_TEST_F(ECKEncryptedMediaTest, FileIOTest) {
[email protected]0af5dfa2014-02-07 22:33:44659 TestNonPlaybackCases(kExternalClearKeyFileIOTestKeySystem,
660 kFileIOTestSuccess);
661}
662
663IN_PROC_BROWSER_TEST_F(ECKEncryptedMediaTest, LoadLoadableSession) {
[email protected]e11d89d2014-06-19 11:36:31664 RunEncryptedMediaTest(kDefaultEmePlayer,
[email protected]8a229322014-07-22 23:33:07665 "bear-320x240-v_enc-v.webm",
[email protected]0af5dfa2014-02-07 22:33:44666 kWebMVideoOnly,
667 kExternalClearKeyKeySystem,
[email protected]34afd582013-12-20 07:26:18668 SRC,
[email protected]a32ef592014-03-07 19:11:15669 PREFIXED,
[email protected]0af5dfa2014-02-07 22:33:44670 kLoadableSession,
[email protected]df06a3e2014-01-31 21:36:59671 false,
[email protected]0af5dfa2014-02-07 22:33:44672 kEnded);
673}
674
675IN_PROC_BROWSER_TEST_F(ECKEncryptedMediaTest, LoadUnknownSession) {
676 // TODO(xhwang): Add a specific error for this failure, e.g. kSessionNotFound.
[email protected]e11d89d2014-06-19 11:36:31677 RunEncryptedMediaTest(kDefaultEmePlayer,
[email protected]8a229322014-07-22 23:33:07678 "bear-320x240-v_enc-v.webm",
[email protected]0af5dfa2014-02-07 22:33:44679 kWebMVideoOnly,
680 kExternalClearKeyKeySystem,
681 SRC,
[email protected]a32ef592014-03-07 19:11:15682 PREFIXED,
[email protected]0af5dfa2014-02-07 22:33:44683 kUnknownSession,
684 false,
685 kEmeKeyError);
[email protected]34afd582013-12-20 07:26:18686}
jrummellc467d232014-10-21 17:55:22687
688IN_PROC_BROWSER_TEST_F(ECKUnprefixedEncryptedMediaTest, LoadLoadableSession) {
689 RunEncryptedMediaTest(kDefaultEmePlayer,
690 "bear-320x240-v_enc-v.webm",
691 kWebMVideoOnly,
692 kExternalClearKeyKeySystem,
693 SRC,
694 UNPREFIXED,
695 kLoadableSession,
696 false,
697 kEnded);
698}
699
700IN_PROC_BROWSER_TEST_F(ECKUnprefixedEncryptedMediaTest, LoadUnknownSession) {
701 // TODO(xhwang): Add a specific error for this failure, e.g. kSessionNotFound.
702 RunEncryptedMediaTest(kDefaultEmePlayer,
703 "bear-320x240-v_enc-v.webm",
704 kWebMVideoOnly,
705 kExternalClearKeyKeySystem,
706 SRC,
707 UNPREFIXED,
708 kUnknownSession,
709 false,
710 kEmeKeyError);
711}
[email protected]a941d4e572013-10-14 21:22:05712#endif // defined(ENABLE_PEPPER_CDMS)