| OLD | NEW |
| 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/test_license_server.h" | 14 #include "chrome/browser/media/test_license_server.h" |
| 15 #include "chrome/browser/media/wv_test_license_server_config.h" | 15 #include "chrome/browser/media/wv_test_license_server_config.h" |
| 16 #include "chrome/browser/ui/browser.h" | 16 #include "chrome/browser/ui/browser.h" |
| 17 #include "chrome/browser/ui/tabs/tab_strip_model.h" | 17 #include "chrome/browser/ui/tabs/tab_strip_model.h" |
| 18 #include "chrome/common/chrome_switches.h" | 18 #include "chrome/common/chrome_switches.h" |
| 19 #include "content/public/common/content_switches.h" | 19 #include "content/public/common/content_switches.h" |
| 20 #include "content/public/test/browser_test_utils.h" | 20 #include "content/public/test/browser_test_utils.h" |
| 21 #include "testing/gtest/include/gtest/gtest-spi.h" | 21 #include "testing/gtest/include/gtest/gtest-spi.h" |
| 22 #if defined(OS_ANDROID) | 22 #if defined(OS_ANDROID) |
| 23 #include "base/android/build_info.h" | 23 #include "base/android/build_info.h" |
| 24 #endif | 24 #endif |
| 25 | 25 |
| 26 #if defined(ENABLE_PEPPER_CDMS) |
| 27 #include "chrome/browser/media/pepper_cdm_test_helper.h" |
| 28 #endif |
| 29 |
| 26 #include "widevine_cdm_version.h" // In SHARED_INTERMEDIATE_DIR. | 30 #include "widevine_cdm_version.h" // In SHARED_INTERMEDIATE_DIR. |
| 27 | 31 |
| 28 #if defined(ENABLE_PEPPER_CDMS) | |
| 29 // Platform-specific filename relative to the chrome executable. | |
| 30 const char kClearKeyCdmAdapterFileName[] = | |
| 31 #if defined(OS_MACOSX) | |
| 32 "clearkeycdmadapter.plugin"; | |
| 33 #elif defined(OS_WIN) | |
| 34 "clearkeycdmadapter.dll"; | |
| 35 #elif defined(OS_POSIX) | |
| 36 "libclearkeycdmadapter.so"; | |
| 37 #endif | |
| 38 | |
| 39 const char kClearKeyCdmPluginMimeType[] = "application/x-ppapi-clearkey-cdm"; | |
| 40 #endif // defined(ENABLE_PEPPER_CDMS) | |
| 41 | |
| 42 // Available key systems. | 32 // Available key systems. |
| 43 const char kClearKeyKeySystem[] = "org.w3.clearkey"; | 33 const char kClearKeyKeySystem[] = "org.w3.clearkey"; |
| 44 const char kExternalClearKeyKeySystem[] = "org.chromium.externalclearkey"; | 34 const char kExternalClearKeyKeySystem[] = "org.chromium.externalclearkey"; |
| 45 const char kExternalClearKeyFileIOTestKeySystem[] = | 35 const char kExternalClearKeyFileIOTestKeySystem[] = |
| 46 "org.chromium.externalclearkey.fileiotest"; | 36 "org.chromium.externalclearkey.fileiotest"; |
| 47 const char kExternalClearKeyInitializeFailKeySystem[] = | 37 const char kExternalClearKeyInitializeFailKeySystem[] = |
| 48 "org.chromium.externalclearkey.initializefail"; | 38 "org.chromium.externalclearkey.initializefail"; |
| 49 const char kExternalClearKeyCrashKeySystem[] = | 39 const char kExternalClearKeyCrashKeySystem[] = |
| 50 "org.chromium.externalclearkey.crash"; | 40 "org.chromium.externalclearkey.crash"; |
| 51 | 41 |
| (...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 101 DVLOG(0) << "MSE is only supported in Android 4.1 and later."; | 91 DVLOG(0) << "MSE is only supported in Android 4.1 and later."; |
| 102 return false; | 92 return false; |
| 103 } | 93 } |
| 104 #endif // defined(OS_ANDROID) | 94 #endif // defined(OS_ANDROID) |
| 105 return true; | 95 return true; |
| 106 } | 96 } |
| 107 | 97 |
| 108 // Base class for encrypted media tests. | 98 // Base class for encrypted media tests. |
| 109 class EncryptedMediaTestBase : public MediaBrowserTest { | 99 class EncryptedMediaTestBase : public MediaBrowserTest { |
| 110 public: | 100 public: |
| 111 EncryptedMediaTestBase() : is_pepper_cdm_registered_(false) {} | 101 EncryptedMediaTestBase() {} |
| 112 | 102 |
| 113 bool IsExternalClearKey(const std::string& key_system) { | 103 bool IsExternalClearKey(const std::string& key_system) { |
| 114 if (key_system == kExternalClearKeyKeySystem) | 104 if (key_system == kExternalClearKeyKeySystem) |
| 115 return true; | 105 return true; |
| 116 std::string prefix = std::string(kExternalClearKeyKeySystem) + '.'; | 106 std::string prefix = std::string(kExternalClearKeyKeySystem) + '.'; |
| 117 return key_system.substr(0, prefix.size()) == prefix; | 107 return key_system.substr(0, prefix.size()) == prefix; |
| 118 } | 108 } |
| 119 | 109 |
| 120 #if defined(WIDEVINE_CDM_AVAILABLE) | 110 #if defined(WIDEVINE_CDM_AVAILABLE) |
| 121 bool IsWidevine(const std::string& key_system) { | 111 bool IsWidevine(const std::string& key_system) { |
| (...skipping 132 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 254 void SetUpCommandLineForKeySystem(const std::string& key_system, | 244 void SetUpCommandLineForKeySystem(const std::string& key_system, |
| 255 base::CommandLine* command_line) { | 245 base::CommandLine* command_line) { |
| 256 if (GetServerConfig(key_system)) | 246 if (GetServerConfig(key_system)) |
| 257 // Since the web and license servers listen on different ports, we need to | 247 // Since the web and license servers listen on different ports, we need to |
| 258 // disable web-security to send license requests to the license server. | 248 // disable web-security to send license requests to the license server. |
| 259 // TODO(shadi): Add port forwarding to the test web server configuration. | 249 // TODO(shadi): Add port forwarding to the test web server configuration. |
| 260 command_line->AppendSwitch(switches::kDisableWebSecurity); | 250 command_line->AppendSwitch(switches::kDisableWebSecurity); |
| 261 | 251 |
| 262 #if defined(ENABLE_PEPPER_CDMS) | 252 #if defined(ENABLE_PEPPER_CDMS) |
| 263 if (IsExternalClearKey(key_system)) { | 253 if (IsExternalClearKey(key_system)) { |
| 264 RegisterPepperCdm(command_line, kClearKeyCdmAdapterFileName, key_system); | 254 RegisterPepperCdm(command_line, kClearKeyCdmAdapterFileName, |
| 255 kClearKeyCdmDisplayName, kClearKeyCdmPepperMimeType); |
| 265 } | 256 } |
| 266 #if defined(WIDEVINE_CDM_AVAILABLE) && defined(WIDEVINE_CDM_IS_COMPONENT) | 257 #if defined(WIDEVINE_CDM_AVAILABLE) && defined(WIDEVINE_CDM_IS_COMPONENT) |
| 267 else if (IsWidevine(key_system)) { // NOLINT | 258 else if (IsWidevine(key_system)) { // NOLINT |
| 268 RegisterPepperCdm(command_line, kWidevineCdmAdapterFileName, key_system); | 259 RegisterPepperCdm(command_line, kWidevineCdmAdapterFileName, |
| 260 kWidevineCdmDisplayName, kWidevineCdmPluginMimeType); |
| 269 } | 261 } |
| 270 #endif // defined(WIDEVINE_CDM_AVAILABLE) && defined(WIDEVINE_CDM_IS_COMPONENT) | 262 #endif // defined(WIDEVINE_CDM_AVAILABLE) && defined(WIDEVINE_CDM_IS_COMPONENT) |
| 271 #endif // defined(ENABLE_PEPPER_CDMS) | 263 #endif // defined(ENABLE_PEPPER_CDMS) |
| 272 } | 264 } |
| 273 | |
| 274 private: | |
| 275 #if defined(ENABLE_PEPPER_CDMS) | |
| 276 void RegisterPepperCdm(base::CommandLine* command_line, | |
| 277 const std::string& adapter_name, | |
| 278 const std::string& key_system) { | |
| 279 DCHECK(!is_pepper_cdm_registered_) | |
| 280 << "RegisterPepperCdm() can only be called once."; | |
| 281 is_pepper_cdm_registered_ = true; | |
| 282 | |
| 283 // Append the switch to register the Clear Key CDM Adapter. | |
| 284 base::FilePath plugin_dir; | |
| 285 EXPECT_TRUE(PathService::Get(base::DIR_MODULE, &plugin_dir)); | |
| 286 base::FilePath plugin_lib = plugin_dir.AppendASCII(adapter_name); | |
| 287 EXPECT_TRUE(base::PathExists(plugin_lib)) << plugin_lib.value(); | |
| 288 base::FilePath::StringType pepper_plugin = plugin_lib.value(); | |
| 289 pepper_plugin.append(FILE_PATH_LITERAL("#CDM#0.1.0.0;")); | |
| 290 #if defined(OS_WIN) | |
| 291 pepper_plugin.append(base::ASCIIToUTF16(GetPepperType(key_system))); | |
| 292 #else | |
| 293 pepper_plugin.append(GetPepperType(key_system)); | |
| 294 #endif | |
| 295 command_line->AppendSwitchNative(switches::kRegisterPepperPlugins, | |
| 296 pepper_plugin); | |
| 297 } | |
| 298 | |
| 299 // Adapted from key_systems.cc. | |
| 300 std::string GetPepperType(const std::string& key_system) { | |
| 301 if (IsExternalClearKey(key_system)) | |
| 302 return kClearKeyCdmPluginMimeType; | |
| 303 #if defined(WIDEVINE_CDM_AVAILABLE) | |
| 304 if (IsWidevine(key_system)) | |
| 305 return kWidevineCdmPluginMimeType; | |
| 306 #endif // WIDEVINE_CDM_AVAILABLE | |
| 307 | |
| 308 NOTREACHED(); | |
| 309 return ""; | |
| 310 } | |
| 311 #endif // defined(ENABLE_PEPPER_CDMS) | |
| 312 | |
| 313 bool is_pepper_cdm_registered_; | |
| 314 }; | 265 }; |
| 315 | 266 |
| 316 #if defined(ENABLE_PEPPER_CDMS) | 267 #if defined(ENABLE_PEPPER_CDMS) |
| 317 // Tests encrypted media playback using ExternalClearKey key system in | 268 // Tests encrypted media playback using ExternalClearKey key system in |
| 318 // decrypt-and-decode mode. | 269 // decrypt-and-decode mode. |
| 319 class ECKEncryptedMediaTest : public EncryptedMediaTestBase { | 270 class ECKEncryptedMediaTest : public EncryptedMediaTestBase { |
| 320 public: | 271 public: |
| 321 // We use special |key_system| names to do non-playback related tests, e.g. | 272 // We use special |key_system| names to do non-playback related tests, e.g. |
| 322 // kExternalClearKeyFileIOTestKeySystem is used to test file IO. | 273 // kExternalClearKeyFileIOTestKeySystem is used to test file IO. |
| 323 void TestNonPlaybackCases(const std::string& key_system, | 274 void TestNonPlaybackCases(const std::string& key_system, |
| (...skipping 346 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 670 | 621 |
| 671 IN_PROC_BROWSER_TEST_F(ECKEncryptedMediaTest, LoadLoadableSession) { | 622 IN_PROC_BROWSER_TEST_F(ECKEncryptedMediaTest, LoadLoadableSession) { |
| 672 TestPlaybackCase(kLoadableSession, kEnded); | 623 TestPlaybackCase(kLoadableSession, kEnded); |
| 673 } | 624 } |
| 674 | 625 |
| 675 IN_PROC_BROWSER_TEST_F(ECKEncryptedMediaTest, LoadUnknownSession) { | 626 IN_PROC_BROWSER_TEST_F(ECKEncryptedMediaTest, LoadUnknownSession) { |
| 676 TestPlaybackCase(kUnknownSession, kEmeSessionNotFound); | 627 TestPlaybackCase(kUnknownSession, kEmeSessionNotFound); |
| 677 } | 628 } |
| 678 | 629 |
| 679 #endif // defined(ENABLE_PEPPER_CDMS) | 630 #endif // defined(ENABLE_PEPPER_CDMS) |
| OLD | NEW |