| 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 | |
| 30 #include "widevine_cdm_version.h" // In SHARED_INTERMEDIATE_DIR. | 26 #include "widevine_cdm_version.h" // In SHARED_INTERMEDIATE_DIR. |
| 31 | 27 |
| 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 |
| 32 // Available key systems. | 42 // Available key systems. |
| 33 const char kClearKeyKeySystem[] = "org.w3.clearkey"; | 43 const char kClearKeyKeySystem[] = "org.w3.clearkey"; |
| 34 const char kExternalClearKeyKeySystem[] = "org.chromium.externalclearkey"; | 44 const char kExternalClearKeyKeySystem[] = "org.chromium.externalclearkey"; |
| 35 const char kExternalClearKeyFileIOTestKeySystem[] = | 45 const char kExternalClearKeyFileIOTestKeySystem[] = |
| 36 "org.chromium.externalclearkey.fileiotest"; | 46 "org.chromium.externalclearkey.fileiotest"; |
| 37 const char kExternalClearKeyInitializeFailKeySystem[] = | 47 const char kExternalClearKeyInitializeFailKeySystem[] = |
| 38 "org.chromium.externalclearkey.initializefail"; | 48 "org.chromium.externalclearkey.initializefail"; |
| 39 const char kExternalClearKeyCrashKeySystem[] = | 49 const char kExternalClearKeyCrashKeySystem[] = |
| 40 "org.chromium.externalclearkey.crash"; | 50 "org.chromium.externalclearkey.crash"; |
| 41 | 51 |
| (...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 91 DVLOG(0) << "MSE is only supported in Android 4.1 and later."; | 101 DVLOG(0) << "MSE is only supported in Android 4.1 and later."; |
| 92 return false; | 102 return false; |
| 93 } | 103 } |
| 94 #endif // defined(OS_ANDROID) | 104 #endif // defined(OS_ANDROID) |
| 95 return true; | 105 return true; |
| 96 } | 106 } |
| 97 | 107 |
| 98 // Base class for encrypted media tests. | 108 // Base class for encrypted media tests. |
| 99 class EncryptedMediaTestBase : public MediaBrowserTest { | 109 class EncryptedMediaTestBase : public MediaBrowserTest { |
| 100 public: | 110 public: |
| 101 EncryptedMediaTestBase() {} | 111 EncryptedMediaTestBase() : is_pepper_cdm_registered_(false) {} |
| 102 | 112 |
| 103 bool IsExternalClearKey(const std::string& key_system) { | 113 bool IsExternalClearKey(const std::string& key_system) { |
| 104 if (key_system == kExternalClearKeyKeySystem) | 114 if (key_system == kExternalClearKeyKeySystem) |
| 105 return true; | 115 return true; |
| 106 std::string prefix = std::string(kExternalClearKeyKeySystem) + '.'; | 116 std::string prefix = std::string(kExternalClearKeyKeySystem) + '.'; |
| 107 return key_system.substr(0, prefix.size()) == prefix; | 117 return key_system.substr(0, prefix.size()) == prefix; |
| 108 } | 118 } |
| 109 | 119 |
| 110 #if defined(WIDEVINE_CDM_AVAILABLE) | 120 #if defined(WIDEVINE_CDM_AVAILABLE) |
| 111 bool IsWidevine(const std::string& key_system) { | 121 bool IsWidevine(const std::string& key_system) { |
| (...skipping 132 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 244 void SetUpCommandLineForKeySystem(const std::string& key_system, | 254 void SetUpCommandLineForKeySystem(const std::string& key_system, |
| 245 base::CommandLine* command_line) { | 255 base::CommandLine* command_line) { |
| 246 if (GetServerConfig(key_system)) | 256 if (GetServerConfig(key_system)) |
| 247 // Since the web and license servers listen on different ports, we need to | 257 // 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. | 258 // disable web-security to send license requests to the license server. |
| 249 // TODO(shadi): Add port forwarding to the test web server configuration. | 259 // TODO(shadi): Add port forwarding to the test web server configuration. |
| 250 command_line->AppendSwitch(switches::kDisableWebSecurity); | 260 command_line->AppendSwitch(switches::kDisableWebSecurity); |
| 251 | 261 |
| 252 #if defined(ENABLE_PEPPER_CDMS) | 262 #if defined(ENABLE_PEPPER_CDMS) |
| 253 if (IsExternalClearKey(key_system)) { | 263 if (IsExternalClearKey(key_system)) { |
| 254 RegisterPepperCdm(command_line, kClearKeyCdmAdapterFileName, | 264 RegisterPepperCdm(command_line, kClearKeyCdmAdapterFileName, key_system); |
| 255 GetPepperType(key_system)); | |
| 256 } | 265 } |
| 257 #if defined(WIDEVINE_CDM_AVAILABLE) && defined(WIDEVINE_CDM_IS_COMPONENT) | 266 #if defined(WIDEVINE_CDM_AVAILABLE) && defined(WIDEVINE_CDM_IS_COMPONENT) |
| 258 else if (IsWidevine(key_system)) { // NOLINT | 267 else if (IsWidevine(key_system)) { // NOLINT |
| 259 RegisterPepperCdm(command_line, kWidevineCdmAdapterFileName, | 268 RegisterPepperCdm(command_line, kWidevineCdmAdapterFileName, key_system); |
| 260 GetPepperType(key_system)); | |
| 261 } | 269 } |
| 262 #endif // defined(WIDEVINE_CDM_AVAILABLE) && defined(WIDEVINE_CDM_IS_COMPONENT) | 270 #endif // defined(WIDEVINE_CDM_AVAILABLE) && defined(WIDEVINE_CDM_IS_COMPONENT) |
| 263 #endif // defined(ENABLE_PEPPER_CDMS) | 271 #endif // defined(ENABLE_PEPPER_CDMS) |
| 264 } | 272 } |
| 265 | 273 |
| 266 private: | 274 private: |
| 267 #if defined(ENABLE_PEPPER_CDMS) | 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 |
| 268 // Adapted from key_systems.cc. | 299 // Adapted from key_systems.cc. |
| 269 std::string GetPepperType(const std::string& key_system) { | 300 std::string GetPepperType(const std::string& key_system) { |
| 270 if (IsExternalClearKey(key_system)) | 301 if (IsExternalClearKey(key_system)) |
| 271 return kClearKeyCdmPepperMimeType; | 302 return kClearKeyCdmPluginMimeType; |
| 272 #if defined(WIDEVINE_CDM_AVAILABLE) | 303 #if defined(WIDEVINE_CDM_AVAILABLE) |
| 273 if (IsWidevine(key_system)) | 304 if (IsWidevine(key_system)) |
| 274 return kWidevineCdmPluginMimeType; | 305 return kWidevineCdmPluginMimeType; |
| 275 #endif // WIDEVINE_CDM_AVAILABLE | 306 #endif // WIDEVINE_CDM_AVAILABLE |
| 276 | 307 |
| 277 NOTREACHED(); | 308 NOTREACHED(); |
| 278 return ""; | 309 return ""; |
| 279 } | 310 } |
| 280 #endif // defined(ENABLE_PEPPER_CDMS) | 311 #endif // defined(ENABLE_PEPPER_CDMS) |
| 312 |
| 313 bool is_pepper_cdm_registered_; |
| 281 }; | 314 }; |
| 282 | 315 |
| 283 #if defined(ENABLE_PEPPER_CDMS) | 316 #if defined(ENABLE_PEPPER_CDMS) |
| 284 // Tests encrypted media playback using ExternalClearKey key system in | 317 // Tests encrypted media playback using ExternalClearKey key system in |
| 285 // decrypt-and-decode mode. | 318 // decrypt-and-decode mode. |
| 286 class ECKEncryptedMediaTest : public EncryptedMediaTestBase { | 319 class ECKEncryptedMediaTest : public EncryptedMediaTestBase { |
| 287 public: | 320 public: |
| 288 // We use special |key_system| names to do non-playback related tests, e.g. | 321 // We use special |key_system| names to do non-playback related tests, e.g. |
| 289 // kExternalClearKeyFileIOTestKeySystem is used to test file IO. | 322 // kExternalClearKeyFileIOTestKeySystem is used to test file IO. |
| 290 void TestNonPlaybackCases(const std::string& key_system, | 323 void TestNonPlaybackCases(const std::string& key_system, |
| (...skipping 346 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 637 | 670 |
| 638 IN_PROC_BROWSER_TEST_F(ECKEncryptedMediaTest, LoadLoadableSession) { | 671 IN_PROC_BROWSER_TEST_F(ECKEncryptedMediaTest, LoadLoadableSession) { |
| 639 TestPlaybackCase(kLoadableSession, kEnded); | 672 TestPlaybackCase(kLoadableSession, kEnded); |
| 640 } | 673 } |
| 641 | 674 |
| 642 IN_PROC_BROWSER_TEST_F(ECKEncryptedMediaTest, LoadUnknownSession) { | 675 IN_PROC_BROWSER_TEST_F(ECKEncryptedMediaTest, LoadUnknownSession) { |
| 643 TestPlaybackCase(kUnknownSession, kEmeSessionNotFound); | 676 TestPlaybackCase(kUnknownSession, kEmeSessionNotFound); |
| 644 } | 677 } |
| 645 | 678 |
| 646 #endif // defined(ENABLE_PEPPER_CDMS) | 679 #endif // defined(ENABLE_PEPPER_CDMS) |
| OLD | NEW |