summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorshadi@chromium.org <shadi@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2014-03-05 10:32:43 +0000
committershadi@chromium.org <shadi@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2014-03-05 10:32:43 +0000
commita7416d79fbc910ce294ad4a0772cf3cf38740715 (patch)
tree40f26b4a8fd9ef1f6f16fd8915e83c765c973c42
parenta0929316dee3d6ccb4ed4faea02f8fc07b02bbdc (diff)
downloadchromium_src-a7416d79fbc910ce294ad4a0772cf3cf38740715.zip
chromium_src-a7416d79fbc910ce294ad4a0772cf3cf38740715.tar.gz
chromium_src-a7416d79fbc910ce294ad4a0772cf3cf38740715.tar.bz2
Update WV browser tests to use portable test license server (reland r254258).
The DEPS roll for test license server has been fixed. This CL updates WV encrypted media browser tests to: - use test license server in third_party/widevine/test. - dynamically select an open port to start the test server on. It also adds a new gyp target for test_license_server. BUG=339983 Review URL: https://codereview.chromium.org/186243003 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@255004 0039d316-1c4b-4281-b951-d872f2087c98
-rw-r--r--chrome/browser/media/test_license_server.cc9
-rw-r--r--chrome/browser/media/test_license_server_config.h8
-rw-r--r--chrome/browser/media/wv_test_license_server_config.cc139
-rw-r--r--chrome/browser/media/wv_test_license_server_config.h23
-rw-r--r--chrome/chrome_tests.gypi1
-rw-r--r--chrome/test/data/media/encrypted_media_utils.js55
-rw-r--r--third_party/widevine/cdm/widevine_cdm.gyp11
7 files changed, 181 insertions, 65 deletions
diff --git a/chrome/browser/media/test_license_server.cc b/chrome/browser/media/test_license_server.cc
index d27437f..65fd830 100644
--- a/chrome/browser/media/test_license_server.cc
+++ b/chrome/browser/media/test_license_server.cc
@@ -30,14 +30,11 @@ bool TestLicenseServer::Start() {
return false;
}
- base::FilePath license_server_path;
- server_config_->GetLicenseServerPath(&license_server_path);
- if (!base::PathExists(license_server_path)) {
- VLOG(0) << "Missing license server file at " << license_server_path.value();
+ CommandLine command_line(CommandLine::NO_PROGRAM);
+ if (!server_config_->GetServerCommandLine(&command_line)) {
+ VLOG(0) << "Could not get server command line to launch.";
return false;
}
- CommandLine command_line(license_server_path);
- server_config_->AppendCommandLineArgs(&command_line);
VLOG(0) << "Starting test license server " <<
command_line.GetCommandLineString();
diff --git a/chrome/browser/media/test_license_server_config.h b/chrome/browser/media/test_license_server_config.h
index 1b4ffd4..b25da78 100644
--- a/chrome/browser/media/test_license_server_config.h
+++ b/chrome/browser/media/test_license_server_config.h
@@ -25,11 +25,9 @@ class TestLicenseServerConfig {
// http://localhost:8888/license_server
virtual std::string GetServerURL() = 0;
- // Retrieves the path for the license server binaries.
- virtual void GetLicenseServerPath(base::FilePath* path) = 0;
-
- // Appends any necessary server command line arguments.
- virtual void AppendCommandLineArgs(CommandLine* command_line) {}
+ // Returns true if it successfully sets the command line to run the license
+ // server with needed args and switches.
+ virtual bool GetServerCommandLine(CommandLine* command_line) = 0;
// Returns true if the server is supported on current platform.
virtual bool IsPlatformSupported() = 0;
diff --git a/chrome/browser/media/wv_test_license_server_config.cc b/chrome/browser/media/wv_test_license_server_config.cc
index 0c887f7..15409ed 100644
--- a/chrome/browser/media/wv_test_license_server_config.cc
+++ b/chrome/browser/media/wv_test_license_server_config.cc
@@ -5,11 +5,18 @@
#include "chrome/browser/media/wv_test_license_server_config.h"
#include "base/command_line.h"
+#include "base/environment.h"
#include "base/file_util.h"
#include "base/path_service.h"
+#include "base/rand_util.h"
#include "base/strings/stringprintf.h"
+#include "net/base/net_errors.h"
+#include "net/socket/tcp_server_socket.h"
+#include "net/test/python_utils.h"
-const uint16 kDefaultPort = 8888;
+
+const uint16 kMinPort = 17000;
+const uint16 kPortRangeSize = 1000;
// Widevine license server configuration files.
const base::FilePath::CharType kKeysFileName[] =
@@ -19,64 +26,130 @@ const base::FilePath::CharType kPoliciesFileName[] =
const base::FilePath::CharType kProfilesFileName[] =
FILE_PATH_LITERAL("profiles.dat");
-// License server root path relative to source dir.
-const base::FilePath::CharType kLicenseServerRootPath[] =
- FILE_PATH_LITERAL("chrome/test/media/license_server/widevine");
-
// License server configuration files directory name relative to root.
const base::FilePath::CharType kLicenseServerConfigDirName[] =
FILE_PATH_LITERAL("config");
-// Platform-specific license server binary path relative to root.
-const base::FilePath::CharType kLicenseServerBinPath[] =
-#if defined(OS_LINUX)
- FILE_PATH_LITERAL("linux/license_server");
-#else
- FILE_PATH_LITERAL("unsupported_platform");
-#endif // defined(OS_LINUX)
-
WVTestLicenseServerConfig::WVTestLicenseServerConfig() {
}
WVTestLicenseServerConfig::~WVTestLicenseServerConfig() {
}
-void WVTestLicenseServerConfig::AppendCommandLineArgs(
+bool WVTestLicenseServerConfig::GetServerCommandLine(
CommandLine* command_line) {
- base::FilePath source_root;
- PathService::Get(base::DIR_SOURCE_ROOT, &source_root);
- base::FilePath config_path =
- source_root.Append(kLicenseServerRootPath)
- .Append(kLicenseServerConfigDirName);
+ if (!GetPythonCommand(command_line)) {
+ LOG(ERROR) << "Could not get Python runtime command.";
+ return false;
+ }
+
+ // Add the Python protocol buffers files directory to Python path.
+ base::FilePath pyproto_dir;
+ if (!GetPyProtoPath(&pyproto_dir)) {
+ VLOG(0) << "Cannot find pyproto directory required by license server.";
+ return false;
+ }
+ AppendToPythonPath(pyproto_dir);
+
+ base::FilePath license_server_path;
+ GetLicenseServerPath(&license_server_path);
+ if (!base::PathExists(license_server_path)) {
+ VLOG(0) << "Missing license server file at " << license_server_path.value();
+ return false;
+ }
+
+ base::FilePath server_root;
+ GetLicenseServerRootPath(&server_root);
+ base::FilePath config_path = server_root.Append(kLicenseServerConfigDirName);
if (!base::PathExists(config_path.Append(kKeysFileName)) ||
!base::PathExists(config_path.Append(kPoliciesFileName)) ||
!base::PathExists(config_path.Append(kProfilesFileName))) {
- CHECK(false) << "Missing license server configuration files.";
- return;
+ VLOG(0) << "Missing license server configuration files.";
+ return false;
}
- command_line->AppendSwitchPath("key_file", config_path.Append(kKeysFileName));
- command_line->AppendSwitchPath("policies_file",
- config_path.Append(kPoliciesFileName));
- command_line->AppendSwitchPath("profiles_file",
- config_path.Append(kProfilesFileName));
- command_line->AppendSwitchASCII("port",
- base::StringPrintf("%u", kDefaultPort));
- command_line->AppendSwitch("allow_unknown_devices");
+
+ if (!SelectServerPort())
+ return false;
+
+ // Needed to dynamically load .so libraries used by license server.
+ // TODO(shadi): Remove need to set env variable once b/12932983 is fixed.
+#if defined(OS_LINUX)
+ scoped_ptr<base::Environment> env(base::Environment::Create());
+ const char kLibraryPathEnvVarName[] = "LD_LIBRARY_PATH";
+ std::string library_paths(license_server_path.DirName().value());
+ std::string old_path;
+ if (env->GetVar(kLibraryPathEnvVarName, &old_path))
+ library_paths.append(":").append(old_path);
+ env->SetVar(kLibraryPathEnvVarName, library_paths);
+#endif // defined(OS_LINUX)
+
+ // Since it is a Python command line, we need to AppendArg instead of
+ // AppendSwitch so that the arguments are passed to the Python server instead
+ // of Python engine.
+ command_line->AppendArgPath(license_server_path);
+ command_line->AppendArg("-k");
+ command_line->AppendArgPath(config_path.Append(kKeysFileName));
+ command_line->AppendArg("-o");
+ command_line->AppendArgPath(config_path.Append(kPoliciesFileName));
+ command_line->AppendArg("-r");
+ command_line->AppendArgPath(config_path.Append(kProfilesFileName));
+ command_line->AppendArg(base::StringPrintf("--port=%u", port_));
+ return true;
+}
+
+bool WVTestLicenseServerConfig::SelectServerPort() {
+ // Try all ports within the range of kMinPort to (kMinPort + kPortRangeSize)
+ // Instead of starting from kMinPort, use a random port within that range.
+ net::IPAddressNumber address;
+ net::ParseIPLiteralToNumber("127.0.0.1", &address);
+ uint16 start_seed = base::RandInt(0, kPortRangeSize);
+ uint16 try_port = 0;
+ for (uint16 i = 0; i < kPortRangeSize; ++i) {
+ try_port = kMinPort + (start_seed + i) % kPortRangeSize;
+ net::NetLog::Source source;
+ net::TCPServerSocket sock(NULL, source);
+ if (sock.Listen(net::IPEndPoint(address, try_port), 1) == net::OK) {
+ port_ = try_port;
+ return true;
+ }
+ }
+ VLOG(0) << "Could not find an open port in the range of " << kMinPort <<
+ " to " << kMinPort + kPortRangeSize;
+ return false;
}
bool WVTestLicenseServerConfig::IsPlatformSupported() {
- // TODO(shadi): Enable on Linux once crbug.com/339983 is resolved.
+#if defined(OS_LINUX)
+ return true;
+#else
return false;
+#endif // defined(OS_LINUX)
}
std::string WVTestLicenseServerConfig::GetServerURL() {
- return base::StringPrintf("http://localhost:%u/license_server", kDefaultPort);
+ return base::StringPrintf("http://localhost:%u/license_server", port_);
}
void WVTestLicenseServerConfig::GetLicenseServerPath(base::FilePath *path) {
+ base::FilePath server_root;
+ GetLicenseServerRootPath(&server_root);
+ // Platform-specific license server binary path relative to root.
+ *path =
+#if defined(OS_LINUX)
+ server_root.Append(FILE_PATH_LITERAL("linux"))
+ .Append(FILE_PATH_LITERAL("license_server.py"));
+#else
+ server_root.Append(FILE_PATH_LITERAL("unsupported_platform"));
+#endif // defined(OS_LINUX)
+}
+
+void WVTestLicenseServerConfig::GetLicenseServerRootPath(
+ base::FilePath* path) {
base::FilePath source_root;
PathService::Get(base::DIR_SOURCE_ROOT, &source_root);
- *path = source_root.Append(kLicenseServerRootPath)
- .Append(kLicenseServerBinPath);
+ *path = source_root.Append(FILE_PATH_LITERAL("third_party"))
+ .Append(FILE_PATH_LITERAL("widevine"))
+ .Append(FILE_PATH_LITERAL("test"))
+ .Append(FILE_PATH_LITERAL("license_server"));
}
diff --git a/chrome/browser/media/wv_test_license_server_config.h b/chrome/browser/media/wv_test_license_server_config.h
index ae79f60..ecd7874 100644
--- a/chrome/browser/media/wv_test_license_server_config.h
+++ b/chrome/browser/media/wv_test_license_server_config.h
@@ -15,18 +15,25 @@ class WVTestLicenseServerConfig : public TestLicenseServerConfig {
virtual std::string GetServerURL() OVERRIDE;
- // Retrieves the path for the license server binaries.
- // WV license server files are located under:
- // chrome/test/license_server/<platform>/
- virtual void GetLicenseServerPath(base::FilePath* path) OVERRIDE;
-
- // Appends necessary Widevine license server command line arguments:
- // port number, keys file path, policies file path, and profiles file path.
- virtual void AppendCommandLineArgs(CommandLine* command_line) OVERRIDE;
+ virtual bool GetServerCommandLine(CommandLine* command_line) OVERRIDE;
virtual bool IsPlatformSupported() OVERRIDE;
private:
+ // Server port. The port value should be set by calling SelectServerPort().
+ uint16 port_;
+
+ // Retrieves the path for the WV license server root:
+ // third_party/widevine/test/license_server/
+ void GetLicenseServerRootPath(base::FilePath* path);
+
+ // Retrieves the path for the WV license server:
+ // <license_server_root_path>/<platform>/
+ void GetLicenseServerPath(base::FilePath* path);
+
+ // Sets the server port to a randomly available port within a limited range.
+ bool SelectServerPort();
+
DISALLOW_COPY_AND_ASSIGN(WVTestLicenseServerConfig);
};
diff --git a/chrome/chrome_tests.gypi b/chrome/chrome_tests.gypi
index 06168b2..fe7949f 100644
--- a/chrome/chrome_tests.gypi
+++ b/chrome/chrome_tests.gypi
@@ -924,6 +924,7 @@
# Runtime dependencies
'../ppapi/ppapi_internal.gyp:ppapi_tests',
'../third_party/mesa/mesa.gyp:osmesa',
+ '../third_party/widevine/cdm/widevine_cdm.gyp:widevine_test_license_server',
],
'include_dirs': [
'..',
diff --git a/chrome/test/data/media/encrypted_media_utils.js b/chrome/test/data/media/encrypted_media_utils.js
index 1c3b8ff..5a95163 100644
--- a/chrome/test/data/media/encrypted_media_utils.js
+++ b/chrome/test/data/media/encrypted_media_utils.js
@@ -9,12 +9,13 @@ var useMSE = QueryString.useMSE == 1;
var forceInvalidResponse = QueryString.forceInvalidResponse == 1;
var sessionToLoad = QueryString.sessionToLoad;
var licenseServerURL = QueryString.licenseServerURL;
-// Number of possible retries used to get a license from license server.
+// Maximum license request attempts that the media element can make to get a
+// valid license response from the license server.
// This is used to avoid server boot up delays since there is no direct way
// to know if it is ready crbug.com/339289.
-var requestLicenseTries = 3;
+var MAX_LICENSE_REQUEST_ATTEMPTS = 3;
// Delay in ms between retries to get a license from license server.
-var licenseRequestRetryDelayMs = 3000;
+var LICENSE_REQUEST_RETRY_DELAY_MS = 3000;
// Default key used to encrypt many media files used in browser tests.
var KEY = new Uint8Array([0xeb, 0xdd, 0x62, 0xf1, 0x68, 0x14, 0xd2, 0x7b,
@@ -229,31 +230,59 @@ function getInitDataFromKeyId(keyID) {
}
function requestLicense(message) {
+ // Store license request attempts per target <video>.
+ if (message.target.licenseRequestAttempts == undefined)
+ message.target.licenseRequestAttempts = 0;
+
+ if (message.target.licenseRequestAttempts == MAX_LICENSE_REQUEST_ATTEMPTS) {
+ failTest('Exceeded maximum license request attempts.');
+ return;
+ }
+ message.target.licenseRequestAttempts++;
console.log('Requesting license from license server ' + licenseServerURL);
+ if (!URLExists(licenseServerURL)) {
+ console.log('License server is not available, retrying in ' +
+ LICENSE_REQUEST_RETRY_DELAY_MS + ' ms.');
+ setTimeout(requestLicense, LICENSE_REQUEST_RETRY_DELAY_MS, message);
+ return;
+ }
+
+ requestLicenseTry(message);
+}
+
+function requestLicenseTry(message) {
var xmlhttp = new XMLHttpRequest();
xmlhttp.responseType = 'arraybuffer';
xmlhttp.open("POST", licenseServerURL, true);
xmlhttp.onload = function(e) {
- requestLicenseTries--;
if (this.status == 200) {
var response = new Uint8Array(this.response);
console.log('Adding license response', response);
message.target.webkitAddKey(keySystem, response, new Uint8Array(1),
- message.sessionId);
+ message.sessionId);
+ // Reset license request count so that renewal requests can be sent later.
+ message.target.licenseRequestAttempts = 0;
} else {
console.log('Bad response: ' + this.response);
console.log('License response bad status = ' + this.status);
- // The license request failed. Wait few secs and try again.
- if (requestLicenseTries > 0) {
- console.log('License response failed so we will try again in ' +
- licenseRequestRetryDelayMs + 'ms.');
- setTimeout(requestLicense, licenseRequestRetryDelayMs, message);
- }
- else
- failTest('Bad license server response: ' + this.response);
+ console.log('Retrying license request if possible.');
+ setTimeout(requestLicense, LICENSE_REQUEST_RETRY_DELAY_MS, message);
}
}
console.log('license request message', message.message);
xmlhttp.send(message.message);
}
+
+function URLExists(url) {
+ if (!url)
+ return false;
+ var http = new XMLHttpRequest();
+ http.open('HEAD', url, false);
+ try {
+ http.send();
+ return http.status != 404;
+ } catch (e) {
+ return false;
+ }
+}
diff --git a/third_party/widevine/cdm/widevine_cdm.gyp b/third_party/widevine/cdm/widevine_cdm.gyp
index d094958..674038b 100644
--- a/third_party/widevine/cdm/widevine_cdm.gyp
+++ b/third_party/widevine/cdm/widevine_cdm.gyp
@@ -108,5 +108,16 @@
'files': [ '<@(widevine_cdm_binary_files)' ],
}],
},
+ {
+ 'target_name': 'widevine_test_license_server',
+ 'type': 'none',
+ 'conditions': [
+ [ 'branding == "Chrome" and OS == "linux"', {
+ 'dependencies': [
+ '<(DEPTH)/third_party/widevine/test/license_server/license_server.gyp:test_license_server',
+ ],
+ }],
+ ],
+ },
],
}