Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(387)

Side by Side Diff: chrome/browser/media/encrypted_media_browsertest.cc

Issue 1983563002: media: Add helper function to register pepper CDMs (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: more cleanup Created 4 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright 2013 The Chromium Authors. All rights reserved. 1 // Copyright 2013 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include <memory> 5 #include <memory>
6 #include <utility> 6 #include <utility>
7 7
8 #include "base/command_line.h" 8 #include "base/command_line.h"
9 #include "base/path_service.h" 9 #include "base/path_service.h"
10 #include "base/strings/utf_string_conversions.h" 10 #include "base/strings/utf_string_conversions.h"
11 #include "base/win/windows_version.h" 11 #include "base/win/windows_version.h"
12 #include "build/build_config.h" 12 #include "build/build_config.h"
13 #include "chrome/browser/media/media_browsertest.h" 13 #include "chrome/browser/media/media_browsertest.h"
14 #include "chrome/browser/media/pepper_cdm_test_helper.h"
14 #include "chrome/browser/media/test_license_server.h" 15 #include "chrome/browser/media/test_license_server.h"
15 #include "chrome/browser/media/wv_test_license_server_config.h" 16 #include "chrome/browser/media/wv_test_license_server_config.h"
16 #include "chrome/browser/ui/browser.h" 17 #include "chrome/browser/ui/browser.h"
17 #include "chrome/browser/ui/tabs/tab_strip_model.h" 18 #include "chrome/browser/ui/tabs/tab_strip_model.h"
18 #include "chrome/common/chrome_switches.h" 19 #include "chrome/common/chrome_switches.h"
19 #include "content/public/common/content_switches.h" 20 #include "content/public/common/content_switches.h"
20 #include "content/public/test/browser_test_utils.h" 21 #include "content/public/test/browser_test_utils.h"
21 #include "testing/gtest/include/gtest/gtest-spi.h" 22 #include "testing/gtest/include/gtest/gtest-spi.h"
22 #if defined(OS_ANDROID) 23 #if defined(OS_ANDROID)
23 #include "base/android/build_info.h" 24 #include "base/android/build_info.h"
24 #endif 25 #endif
25 26
26 #include "widevine_cdm_version.h" // In SHARED_INTERMEDIATE_DIR. 27 #include "widevine_cdm_version.h" // In SHARED_INTERMEDIATE_DIR.
27 28
28 #if defined(ENABLE_PEPPER_CDMS)
29 // Base path for Clear Key CDM (relative to the chrome executable).
30 const char kClearKeyCdmBaseDirectory[] = "ClearKeyCdm";
31
32 // Platform-specific filename relative to kClearKeyCdmBaseDirectory.
33 const char kClearKeyCdmAdapterFileName[] =
34 #if defined(OS_MACOSX)
35 "clearkeycdmadapter.plugin";
36 #elif defined(OS_WIN)
37 "clearkeycdmadapter.dll";
38 #elif defined(OS_POSIX)
39 "libclearkeycdmadapter.so";
40 #endif
41
42 const char kClearKeyCdmPluginMimeType[] = "application/x-ppapi-clearkey-cdm";
43 #endif // defined(ENABLE_PEPPER_CDMS)
44
45 // Available key systems. 29 // Available key systems.
46 const char kClearKeyKeySystem[] = "org.w3.clearkey"; 30 const char kClearKeyKeySystem[] = "org.w3.clearkey";
47 const char kExternalClearKeyKeySystem[] = "org.chromium.externalclearkey"; 31 const char kExternalClearKeyKeySystem[] = "org.chromium.externalclearkey";
48 const char kExternalClearKeyFileIOTestKeySystem[] = 32 const char kExternalClearKeyFileIOTestKeySystem[] =
49 "org.chromium.externalclearkey.fileiotest"; 33 "org.chromium.externalclearkey.fileiotest";
50 const char kExternalClearKeyInitializeFailKeySystem[] = 34 const char kExternalClearKeyInitializeFailKeySystem[] =
51 "org.chromium.externalclearkey.initializefail"; 35 "org.chromium.externalclearkey.initializefail";
52 const char kExternalClearKeyCrashKeySystem[] = 36 const char kExternalClearKeyCrashKeySystem[] =
53 "org.chromium.externalclearkey.crash"; 37 "org.chromium.externalclearkey.crash";
54 38
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after
104 DVLOG(0) << "MSE is only supported in Android 4.1 and later."; 88 DVLOG(0) << "MSE is only supported in Android 4.1 and later.";
105 return false; 89 return false;
106 } 90 }
107 #endif // defined(OS_ANDROID) 91 #endif // defined(OS_ANDROID)
108 return true; 92 return true;
109 } 93 }
110 94
111 // Base class for encrypted media tests. 95 // Base class for encrypted media tests.
112 class EncryptedMediaTestBase : public MediaBrowserTest { 96 class EncryptedMediaTestBase : public MediaBrowserTest {
113 public: 97 public:
114 EncryptedMediaTestBase() : is_pepper_cdm_registered_(false) {} 98 EncryptedMediaTestBase() {}
115 99
116 bool IsExternalClearKey(const std::string& key_system) { 100 bool IsExternalClearKey(const std::string& key_system) {
117 if (key_system == kExternalClearKeyKeySystem) 101 if (key_system == kExternalClearKeyKeySystem)
118 return true; 102 return true;
119 std::string prefix = std::string(kExternalClearKeyKeySystem) + '.'; 103 std::string prefix = std::string(kExternalClearKeyKeySystem) + '.';
120 return key_system.substr(0, prefix.size()) == prefix; 104 return key_system.substr(0, prefix.size()) == prefix;
121 } 105 }
122 106
123 #if defined(WIDEVINE_CDM_AVAILABLE) 107 #if defined(WIDEVINE_CDM_AVAILABLE)
124 bool IsWidevine(const std::string& key_system) { 108 bool IsWidevine(const std::string& key_system) {
(...skipping 133 matching lines...) Expand 10 before | Expand all | Expand 10 after
258 base::CommandLine* command_line) { 242 base::CommandLine* command_line) {
259 if (GetServerConfig(key_system)) 243 if (GetServerConfig(key_system))
260 // Since the web and license servers listen on different ports, we need to 244 // Since the web and license servers listen on different ports, we need to
261 // disable web-security to send license requests to the license server. 245 // disable web-security to send license requests to the license server.
262 // TODO(shadi): Add port forwarding to the test web server configuration. 246 // TODO(shadi): Add port forwarding to the test web server configuration.
263 command_line->AppendSwitch(switches::kDisableWebSecurity); 247 command_line->AppendSwitch(switches::kDisableWebSecurity);
264 248
265 #if defined(ENABLE_PEPPER_CDMS) 249 #if defined(ENABLE_PEPPER_CDMS)
266 if (IsExternalClearKey(key_system)) { 250 if (IsExternalClearKey(key_system)) {
267 RegisterPepperCdm(command_line, kClearKeyCdmBaseDirectory, 251 RegisterPepperCdm(command_line, kClearKeyCdmBaseDirectory,
268 kClearKeyCdmAdapterFileName, key_system); 252 kClearKeyCdmAdapterFileName, GetPepperType(key_system));
269 } 253 }
270 #if defined(WIDEVINE_CDM_AVAILABLE) && defined(WIDEVINE_CDM_IS_COMPONENT) 254 #if defined(WIDEVINE_CDM_AVAILABLE) && defined(WIDEVINE_CDM_IS_COMPONENT)
271 else if (IsWidevine(key_system)) { // NOLINT 255 else if (IsWidevine(key_system)) { // NOLINT
272 RegisterPepperCdm(command_line, kWidevineCdmBaseDirectory, 256 RegisterPepperCdm(command_line, kWidevineCdmBaseDirectory,
273 kWidevineCdmAdapterFileName, key_system); 257 kWidevineCdmAdapterFileName, GetPepperType(key_system));
274 } 258 }
275 #endif // defined(WIDEVINE_CDM_AVAILABLE) && defined(WIDEVINE_CDM_IS_COMPONENT) 259 #endif // defined(WIDEVINE_CDM_AVAILABLE) && defined(WIDEVINE_CDM_IS_COMPONENT)
276 #endif // defined(ENABLE_PEPPER_CDMS) 260 #endif // defined(ENABLE_PEPPER_CDMS)
277 } 261 }
278 262
279 private: 263 private:
280 #if defined(ENABLE_PEPPER_CDMS) 264 #if defined(ENABLE_PEPPER_CDMS)
281 // The CDM adapter should be located in |adapter_base_dir| in DIR_MODULE.
282 void RegisterPepperCdm(base::CommandLine* command_line,
283 const std::string& adapter_base_dir,
284 const std::string& adapter_name,
285 const std::string& key_system) {
286 DCHECK(!is_pepper_cdm_registered_)
287 << "RegisterPepperCdm() can only be called once.";
288 is_pepper_cdm_registered_ = true;
289
290 // Build the CDM adapter path.
291 base::FilePath plugin_dir;
292 EXPECT_TRUE(PathService::Get(base::DIR_MODULE, &plugin_dir));
293 plugin_dir = plugin_dir.AppendASCII(adapter_base_dir);
294
295 base::FilePath plugin_lib = plugin_dir.AppendASCII(adapter_name);
296 EXPECT_TRUE(base::PathExists(plugin_lib)) << plugin_lib.value();
297
298 // Build pepper plugin registration switch.
299 base::FilePath::StringType pepper_plugin = plugin_lib.value();
300 pepper_plugin.append(FILE_PATH_LITERAL("#CDM#0.1.0.0;"));
301 #if defined(OS_WIN)
302 pepper_plugin.append(base::ASCIIToUTF16(GetPepperType(key_system)));
303 #else
304 pepper_plugin.append(GetPepperType(key_system));
305 #endif
306
307 // Append the switch to register the CDM Adapter.
308 command_line->AppendSwitchNative(switches::kRegisterPepperPlugins,
309 pepper_plugin);
310 }
311
312 // Adapted from key_systems.cc. 265 // Adapted from key_systems.cc.
313 std::string GetPepperType(const std::string& key_system) { 266 std::string GetPepperType(const std::string& key_system) {
314 if (IsExternalClearKey(key_system)) 267 if (IsExternalClearKey(key_system))
315 return kClearKeyCdmPluginMimeType; 268 return kClearKeyCdmPluginMimeType;
316 #if defined(WIDEVINE_CDM_AVAILABLE) 269 #if defined(WIDEVINE_CDM_AVAILABLE)
317 if (IsWidevine(key_system)) 270 if (IsWidevine(key_system))
318 return kWidevineCdmPluginMimeType; 271 return kWidevineCdmPluginMimeType;
319 #endif // WIDEVINE_CDM_AVAILABLE 272 #endif // WIDEVINE_CDM_AVAILABLE
320 273
321 NOTREACHED(); 274 NOTREACHED();
322 return ""; 275 return "";
323 } 276 }
324 #endif // defined(ENABLE_PEPPER_CDMS) 277 #endif // defined(ENABLE_PEPPER_CDMS)
325
326 bool is_pepper_cdm_registered_;
327 }; 278 };
328 279
329 #if defined(ENABLE_PEPPER_CDMS) 280 #if defined(ENABLE_PEPPER_CDMS)
330 // Tests encrypted media playback using ExternalClearKey key system in 281 // Tests encrypted media playback using ExternalClearKey key system in
331 // decrypt-and-decode mode. 282 // decrypt-and-decode mode.
332 class ECKEncryptedMediaTest : public EncryptedMediaTestBase { 283 class ECKEncryptedMediaTest : public EncryptedMediaTestBase {
333 public: 284 public:
334 // We use special |key_system| names to do non-playback related tests, e.g. 285 // We use special |key_system| names to do non-playback related tests, e.g.
335 // kExternalClearKeyFileIOTestKeySystem is used to test file IO. 286 // kExternalClearKeyFileIOTestKeySystem is used to test file IO.
336 void TestNonPlaybackCases(const std::string& key_system, 287 void TestNonPlaybackCases(const std::string& key_system,
(...skipping 346 matching lines...) Expand 10 before | Expand all | Expand 10 after
683 634
684 IN_PROC_BROWSER_TEST_F(ECKEncryptedMediaTest, LoadLoadableSession) { 635 IN_PROC_BROWSER_TEST_F(ECKEncryptedMediaTest, LoadLoadableSession) {
685 TestPlaybackCase(kLoadableSession, kEnded); 636 TestPlaybackCase(kLoadableSession, kEnded);
686 } 637 }
687 638
688 IN_PROC_BROWSER_TEST_F(ECKEncryptedMediaTest, LoadUnknownSession) { 639 IN_PROC_BROWSER_TEST_F(ECKEncryptedMediaTest, LoadUnknownSession) {
689 TestPlaybackCase(kUnknownSession, kEmeSessionNotFound); 640 TestPlaybackCase(kUnknownSession, kEmeSessionNotFound);
690 } 641 }
691 642
692 #endif // defined(ENABLE_PEPPER_CDMS) 643 #endif // defined(ENABLE_PEPPER_CDMS)
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698