Commit 1bede83d authored by shadi@chromium.org's avatar shadi@chromium.org

Have media content and chrome browser tests load data from media/test/data

Update remaining encrypted media browser tests to use new player app.

(This is identical to r282795 which got reverted, i.e. revert of revert).

The fix was submitted separately in r283757

BUG=379314

Review URL: https://codereview.chromium.org/398823004

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@284489 0039d316-1c4b-4281-b951-d872f2087c98
parent 5c5e60b1
...@@ -115,12 +115,14 @@ class EncryptedMediaTestBase : public MediaBrowserTest { ...@@ -115,12 +115,14 @@ class EncryptedMediaTestBase : public MediaBrowserTest {
} }
#endif // defined(WIDEVINE_CDM_AVAILABLE) #endif // defined(WIDEVINE_CDM_AVAILABLE)
void RunEncryptedMediaTestPage(const std::string& html_page, void RunEncryptedMediaTestPage(
const std::string& html_page,
const std::string& key_system, const std::string& key_system,
std::vector<StringPair>* query_params, const media::QueryParams& query_params,
const std::string& expected_title) { const std::string& expected_title) {
StartLicenseServerIfNeeded(key_system, query_params); media::QueryParams new_query_params = query_params;
RunMediaTestPage(html_page, query_params, expected_title, true); StartLicenseServerIfNeeded(key_system, &new_query_params);
RunMediaTestPage(html_page, new_query_params, expected_title, true);
} }
// Tests |html_page| using |media_file| (with |media_type|) and |key_system|. // Tests |html_page| using |media_file| (with |media_type|) and |key_system|.
...@@ -144,7 +146,7 @@ class EncryptedMediaTestBase : public MediaBrowserTest { ...@@ -144,7 +146,7 @@ class EncryptedMediaTestBase : public MediaBrowserTest {
VLOG(0) << "Skipping test - MSE not supported."; VLOG(0) << "Skipping test - MSE not supported.";
return; return;
} }
std::vector<StringPair> query_params; media::QueryParams query_params;
query_params.push_back(std::make_pair("mediaFile", media_file)); query_params.push_back(std::make_pair("mediaFile", media_file));
query_params.push_back(std::make_pair("mediaType", media_type)); query_params.push_back(std::make_pair("mediaType", media_type));
query_params.push_back(std::make_pair("keySystem", key_system)); query_params.push_back(std::make_pair("keySystem", key_system));
...@@ -156,7 +158,7 @@ class EncryptedMediaTestBase : public MediaBrowserTest { ...@@ -156,7 +158,7 @@ class EncryptedMediaTestBase : public MediaBrowserTest {
query_params.push_back(std::make_pair("forceInvalidResponse", "1")); query_params.push_back(std::make_pair("forceInvalidResponse", "1"));
if (!session_to_load.empty()) if (!session_to_load.empty())
query_params.push_back(std::make_pair("sessionToLoad", session_to_load)); query_params.push_back(std::make_pair("sessionToLoad", session_to_load));
RunEncryptedMediaTestPage(html_page, key_system, &query_params, RunEncryptedMediaTestPage(html_page, key_system, query_params,
expected_title); expected_title);
} }
...@@ -188,16 +190,17 @@ class EncryptedMediaTestBase : public MediaBrowserTest { ...@@ -188,16 +190,17 @@ class EncryptedMediaTestBase : public MediaBrowserTest {
EXPECT_TRUE(receivedKeyMessage); EXPECT_TRUE(receivedKeyMessage);
} }
// Starts a license server if available for the |key_system| and adds a
// 'licenseServerURL' query parameter to |query_params|.
void StartLicenseServerIfNeeded(const std::string& key_system, void StartLicenseServerIfNeeded(const std::string& key_system,
std::vector<StringPair>* query_params) { media::QueryParams* query_params) {
scoped_ptr<TestLicenseServerConfig> config = GetServerConfig(key_system); scoped_ptr<TestLicenseServerConfig> config = GetServerConfig(key_system);
if (!config) if (!config)
return; return;
license_server_.reset(new TestLicenseServer(config.Pass())); license_server_.reset(new TestLicenseServer(config.Pass()));
EXPECT_TRUE(license_server_->Start()); EXPECT_TRUE(license_server_->Start());
query_params->push_back(std::make_pair("licenseServerURL", query_params->push_back(
license_server_->GetServerURL())); std::make_pair("licenseServerURL", license_server_->GetServerURL()));
} }
bool IsPlayBackPossible(const std::string& key_system) { bool IsPlayBackPossible(const std::string& key_system) {
...@@ -312,7 +315,7 @@ class ECKEncryptedMediaTest : public EncryptedMediaTestBase { ...@@ -312,7 +315,7 @@ class ECKEncryptedMediaTest : public EncryptedMediaTestBase {
// Since we do not test playback, arbitrarily choose a test file and source // Since we do not test playback, arbitrarily choose a test file and source
// type. // type.
RunEncryptedMediaTest(kDefaultEmePlayer, RunEncryptedMediaTest(kDefaultEmePlayer,
"bear-a-enc_a.webm", "bear-a_enc-a.webm",
kWebMAudioOnly, kWebMAudioOnly,
key_system, key_system,
SRC, SRC,
...@@ -379,7 +382,7 @@ class EncryptedMediaTest ...@@ -379,7 +382,7 @@ class EncryptedMediaTest
void RunInvalidResponseTest() { void RunInvalidResponseTest() {
RunEncryptedMediaTest(kDefaultEmePlayer, RunEncryptedMediaTest(kDefaultEmePlayer,
"bear-320x240-av-enc_av.webm", "bear-320x240-av_enc-av.webm",
kWebMAudioVideo, kWebMAudioVideo,
CurrentKeySystem(), CurrentKeySystem(),
CurrentSourceType(), CurrentSourceType(),
...@@ -391,7 +394,7 @@ class EncryptedMediaTest ...@@ -391,7 +394,7 @@ class EncryptedMediaTest
void TestFrameSizeChange() { void TestFrameSizeChange() {
RunEncryptedMediaTest("encrypted_frame_size_change.html", RunEncryptedMediaTest("encrypted_frame_size_change.html",
"frame_size_change-av-enc-v.webm", "frame_size_change-av_enc-v.webm",
kWebMAudioVideo, kWebMAudioVideo,
CurrentKeySystem(), CurrentKeySystem(),
CurrentSourceType(), CurrentSourceType(),
...@@ -403,14 +406,14 @@ class EncryptedMediaTest ...@@ -403,14 +406,14 @@ class EncryptedMediaTest
void TestConfigChange() { void TestConfigChange() {
DCHECK(IsMSESupported()); DCHECK(IsMSESupported());
std::vector<StringPair> query_params; media::QueryParams query_params;
query_params.push_back(std::make_pair("keySystem", CurrentKeySystem())); query_params.push_back(std::make_pair("keySystem", CurrentKeySystem()));
query_params.push_back(std::make_pair("runEncrypted", "1")); query_params.push_back(std::make_pair("runEncrypted", "1"));
if (CurrentEmeVersion() == PREFIXED) if (CurrentEmeVersion() == PREFIXED)
query_params.push_back(std::make_pair("usePrefixedEME", "1")); query_params.push_back(std::make_pair("usePrefixedEME", "1"));
RunEncryptedMediaTestPage("mse_config_change.html", RunEncryptedMediaTestPage("mse_config_change.html",
CurrentKeySystem(), CurrentKeySystem(),
&query_params, query_params,
kEnded); kEnded);
} }
...@@ -511,27 +514,27 @@ INSTANTIATE_TEST_CASE_P(MSE_Widevine, ...@@ -511,27 +514,27 @@ INSTANTIATE_TEST_CASE_P(MSE_Widevine,
#endif // defined(WIDEVINE_CDM_AVAILABLE) #endif // defined(WIDEVINE_CDM_AVAILABLE)
IN_PROC_BROWSER_TEST_P(EncryptedMediaTest, Playback_AudioOnly_WebM) { IN_PROC_BROWSER_TEST_P(EncryptedMediaTest, Playback_AudioOnly_WebM) {
TestSimplePlayback("bear-a-enc_a.webm", kWebMAudioOnly); TestSimplePlayback("bear-a_enc-a.webm", kWebMAudioOnly);
} }
IN_PROC_BROWSER_TEST_P(EncryptedMediaTest, Playback_AudioClearVideo_WebM) { IN_PROC_BROWSER_TEST_P(EncryptedMediaTest, Playback_AudioClearVideo_WebM) {
TestSimplePlayback("bear-320x240-av-enc_a.webm", kWebMAudioVideo); TestSimplePlayback("bear-320x240-av_enc-a.webm", kWebMAudioVideo);
} }
IN_PROC_BROWSER_TEST_P(EncryptedMediaTest, Playback_VideoAudio_WebM) { IN_PROC_BROWSER_TEST_P(EncryptedMediaTest, Playback_VideoAudio_WebM) {
TestSimplePlayback("bear-320x240-av-enc_av.webm", kWebMAudioVideo); TestSimplePlayback("bear-320x240-av_enc-av.webm", kWebMAudioVideo);
} }
IN_PROC_BROWSER_TEST_P(EncryptedMediaTest, Playback_VideoOnly_WebM) { IN_PROC_BROWSER_TEST_P(EncryptedMediaTest, Playback_VideoOnly_WebM) {
TestSimplePlayback("bear-320x240-v-enc_v.webm", kWebMVideoOnly); TestSimplePlayback("bear-320x240-v_enc-v.webm", kWebMVideoOnly);
} }
IN_PROC_BROWSER_TEST_P(EncryptedMediaTest, Playback_VideoClearAudio_WebM) { IN_PROC_BROWSER_TEST_P(EncryptedMediaTest, Playback_VideoClearAudio_WebM) {
TestSimplePlayback("bear-320x240-av-enc_v.webm", kWebMAudioVideo); TestSimplePlayback("bear-320x240-av_enc-v.webm", kWebMAudioVideo);
} }
IN_PROC_BROWSER_TEST_P(EncryptedMediaTest, Playback_VP9Video_WebM) { IN_PROC_BROWSER_TEST_P(EncryptedMediaTest, Playback_VP9Video_WebM) {
TestSimplePlayback("bear-320x240-v-vp9-enc_v.webm", kWebMVP9VideoOnly); TestSimplePlayback("bear-320x240-v-vp9_enc-v.webm", kWebMVP9VideoOnly);
} }
IN_PROC_BROWSER_TEST_P(EncryptedMediaTest, InvalidResponseKeyError) { IN_PROC_BROWSER_TEST_P(EncryptedMediaTest, InvalidResponseKeyError) {
...@@ -587,7 +590,7 @@ IN_PROC_BROWSER_TEST_P(EncryptedMediaTest, Playback_AudioOnly_MP4) { ...@@ -587,7 +590,7 @@ IN_PROC_BROWSER_TEST_P(EncryptedMediaTest, Playback_AudioOnly_MP4) {
// The parent key system cannot be used in generateKeyRequest. // The parent key system cannot be used in generateKeyRequest.
IN_PROC_BROWSER_TEST_F(WVEncryptedMediaTest, ParentThrowsException_Prefixed) { IN_PROC_BROWSER_TEST_F(WVEncryptedMediaTest, ParentThrowsException_Prefixed) {
RunEncryptedMediaTest(kDefaultEmePlayer, RunEncryptedMediaTest(kDefaultEmePlayer,
"bear-a-enc_a.webm", "bear-a_enc-a.webm",
kWebMAudioOnly, kWebMAudioOnly,
"com.widevine", "com.widevine",
MSE, MSE,
...@@ -601,7 +604,7 @@ IN_PROC_BROWSER_TEST_F(WVEncryptedMediaTest, ParentThrowsException_Prefixed) { ...@@ -601,7 +604,7 @@ IN_PROC_BROWSER_TEST_F(WVEncryptedMediaTest, ParentThrowsException_Prefixed) {
// The parent key system cannot be used when creating MediaKeys. // The parent key system cannot be used when creating MediaKeys.
IN_PROC_BROWSER_TEST_F(WVEncryptedMediaTest, ParentThrowsException) { IN_PROC_BROWSER_TEST_F(WVEncryptedMediaTest, ParentThrowsException) {
RunEncryptedMediaTest(kDefaultEmePlayer, RunEncryptedMediaTest(kDefaultEmePlayer,
"bear-a-enc_a.webm", "bear-a_enc-a.webm",
kWebMAudioOnly, kWebMAudioOnly,
"com.widevine", "com.widevine",
MSE, MSE,
...@@ -640,7 +643,7 @@ IN_PROC_BROWSER_TEST_F(ECKEncryptedMediaTest, FileIOTest) { ...@@ -640,7 +643,7 @@ IN_PROC_BROWSER_TEST_F(ECKEncryptedMediaTest, FileIOTest) {
IN_PROC_BROWSER_TEST_F(ECKEncryptedMediaTest, LoadLoadableSession) { IN_PROC_BROWSER_TEST_F(ECKEncryptedMediaTest, LoadLoadableSession) {
RunEncryptedMediaTest(kDefaultEmePlayer, RunEncryptedMediaTest(kDefaultEmePlayer,
"bear-320x240-v-enc_v.webm", "bear-320x240-v_enc-v.webm",
kWebMVideoOnly, kWebMVideoOnly,
kExternalClearKeyKeySystem, kExternalClearKeyKeySystem,
SRC, SRC,
...@@ -653,7 +656,7 @@ IN_PROC_BROWSER_TEST_F(ECKEncryptedMediaTest, LoadLoadableSession) { ...@@ -653,7 +656,7 @@ IN_PROC_BROWSER_TEST_F(ECKEncryptedMediaTest, LoadLoadableSession) {
IN_PROC_BROWSER_TEST_F(ECKEncryptedMediaTest, LoadUnknownSession) { IN_PROC_BROWSER_TEST_F(ECKEncryptedMediaTest, LoadUnknownSession) {
// TODO(xhwang): Add a specific error for this failure, e.g. kSessionNotFound. // TODO(xhwang): Add a specific error for this failure, e.g. kSessionNotFound.
RunEncryptedMediaTest(kDefaultEmePlayer, RunEncryptedMediaTest(kDefaultEmePlayer,
"bear-320x240-v-enc_v.webm", "bear-320x240-v_enc-v.webm",
kWebMVideoOnly, kWebMVideoOnly,
kExternalClearKeyKeySystem, kExternalClearKeyKeySystem,
SRC, SRC,
......
...@@ -17,6 +17,7 @@ ...@@ -17,6 +17,7 @@
#include "chrome/test/base/ui_test_utils.h" #include "chrome/test/base/ui_test_utils.h"
#include "content/public/common/content_switches.h" #include "content/public/common/content_switches.h"
#include "content/public/test/browser_test_utils.h" #include "content/public/test/browser_test_utils.h"
#include "media/base/test_data_util.h"
#include "url/gurl.h" #include "url/gurl.h"
#include "widevine_cdm_version.h" // In SHARED_INTERMEDIATE_DIR. #include "widevine_cdm_version.h" // In SHARED_INTERMEDIATE_DIR.
...@@ -224,9 +225,10 @@ class EncryptedMediaIsTypeSupportedTest : public InProcessBrowserTest { ...@@ -224,9 +225,10 @@ class EncryptedMediaIsTypeSupportedTest : public InProcessBrowserTest {
// Load the test page needed. IsConcreteSupportedKeySystem() needs some // Load the test page needed. IsConcreteSupportedKeySystem() needs some
// JavaScript and a video loaded in order to work. // JavaScript and a video loaded in order to work.
if (!is_test_page_loaded_) { if (!is_test_page_loaded_) {
ASSERT_TRUE(test_server()->Start()); scoped_ptr<net::SpawnedTestServer> http_test_server =
GURL gurl = test_server()->GetURL( media::StartMediaHttpTestServer();
"files/media/test_key_system_instantiation.html"); GURL gurl = http_test_server->GetURL(
"files/test_key_system_instantiation.html");
ui_test_utils::NavigateToURL(browser(), gurl); ui_test_utils::NavigateToURL(browser(), gurl);
is_test_page_loaded_ = true; is_test_page_loaded_ = true;
} }
......
...@@ -4,12 +4,9 @@ ...@@ -4,12 +4,9 @@
#include "chrome/browser/media/media_browsertest.h" #include "chrome/browser/media/media_browsertest.h"
#include "base/path_service.h"
#include "base/strings/stringprintf.h"
#include "base/strings/utf_string_conversions.h" #include "base/strings/utf_string_conversions.h"
#include "chrome/browser/ui/browser.h" #include "chrome/browser/ui/browser.h"
#include "chrome/browser/ui/tabs/tab_strip_model.h" #include "chrome/browser/ui/tabs/tab_strip_model.h"
#include "chrome/common/chrome_paths.h"
#include "chrome/test/base/ui_test_utils.h" #include "chrome/test/base/ui_test_utils.h"
#include "content/public/browser/navigation_controller.h" #include "content/public/browser/navigation_controller.h"
#include "content/public/browser/navigation_entry.h" #include "content/public/browser/navigation_entry.h"
...@@ -28,37 +25,27 @@ MediaBrowserTest::MediaBrowserTest() : ignore_plugin_crash_(false) { ...@@ -28,37 +25,27 @@ MediaBrowserTest::MediaBrowserTest() : ignore_plugin_crash_(false) {
MediaBrowserTest::~MediaBrowserTest() { MediaBrowserTest::~MediaBrowserTest() {
} }
void MediaBrowserTest::RunMediaTestPage( void MediaBrowserTest::RunMediaTestPage(const std::string& html_page,
const std::string& html_page, std::vector<StringPair>* query_params, const media::QueryParams& query_params,
const std::string& expected_title, bool http) { const std::string& expected_title,
bool http) {
GURL gurl; GURL gurl;
std::string query = ""; std::string query = media::GetURLQueryString(query_params);
if (query_params != NULL && !query_params->empty()) { scoped_ptr<net::SpawnedTestServer> http_test_server;
std::vector<StringPair>::const_iterator itr = query_params->begin();
query = itr->first + "=" + itr->second;
++itr;
for (; itr != query_params->end(); ++itr) {
query.append("&" + itr->first + "=" + itr->second);
}
}
if (http) { if (http) {
ASSERT_TRUE(test_server()->Start()); http_test_server = media::StartMediaHttpTestServer();
gurl = test_server()->GetURL("files/media/" + html_page + "?" + query); gurl = http_test_server->GetURL("files/" + html_page + "?" + query);
} else { } else {
base::FilePath test_file_path; gurl = content::GetFileUrlWithQuery(media::GetTestDataFilePath(html_page),
PathService::Get(chrome::DIR_TEST_DATA, &test_file_path); query);
test_file_path = test_file_path.AppendASCII("media")
.AppendASCII(html_page);
gurl = content::GetFileUrlWithQuery(test_file_path, query);
} }
std::string final_title = RunTest(gurl, expected_title);
base::string16 final_title = RunTest(gurl, expected_title); EXPECT_EQ(expected_title, final_title);
EXPECT_EQ(base::ASCIIToUTF16(expected_title), final_title);
} }
base::string16 MediaBrowserTest::RunTest(const GURL& gurl, std::string MediaBrowserTest::RunTest(const GURL& gurl,
const std::string& expected_title) { const std::string& expected_title) {
VLOG(0) << "Running test URL: " << gurl; DVLOG(0) << "Running test URL: " << gurl;
// Observe the web contents for plugin crashes. // Observe the web contents for plugin crashes.
Observe(browser()->tab_strip_model()->GetActiveWebContents()); Observe(browser()->tab_strip_model()->GetActiveWebContents());
content::TitleWatcher title_watcher( content::TitleWatcher title_watcher(
...@@ -66,8 +53,8 @@ base::string16 MediaBrowserTest::RunTest(const GURL& gurl, ...@@ -66,8 +53,8 @@ base::string16 MediaBrowserTest::RunTest(const GURL& gurl,
base::ASCIIToUTF16(expected_title)); base::ASCIIToUTF16(expected_title));
AddWaitForTitles(&title_watcher); AddWaitForTitles(&title_watcher);
ui_test_utils::NavigateToURL(browser(), gurl); ui_test_utils::NavigateToURL(browser(), gurl);
base::string16 result = title_watcher.WaitAndGetTitle();
return title_watcher.WaitAndGetTitle(); return base::UTF16ToASCII(result);
} }
void MediaBrowserTest::AddWaitForTitles(content::TitleWatcher* title_watcher) { void MediaBrowserTest::AddWaitForTitles(content::TitleWatcher* title_watcher) {
......
...@@ -5,11 +5,11 @@ ...@@ -5,11 +5,11 @@
#ifndef CHROME_BROWSER_MEDIA_MEDIA_BROWSERTEST_H_ #ifndef CHROME_BROWSER_MEDIA_MEDIA_BROWSERTEST_H_
#define CHROME_BROWSER_MEDIA_MEDIA_BROWSERTEST_H_ #define CHROME_BROWSER_MEDIA_MEDIA_BROWSERTEST_H_
#include <utility> #include <string>
#include <vector>
#include "chrome/test/base/in_process_browser_test.h" #include "chrome/test/base/in_process_browser_test.h"
#include "content/public/browser/web_contents_observer.h" #include "content/public/browser/web_contents_observer.h"
#include "media/base/test_data_util.h"
namespace content { namespace content {
class TitleWatcher; class TitleWatcher;
...@@ -21,8 +21,6 @@ class TitleWatcher; ...@@ -21,8 +21,6 @@ class TitleWatcher;
class MediaBrowserTest : public InProcessBrowserTest, class MediaBrowserTest : public InProcessBrowserTest,
public content::WebContentsObserver { public content::WebContentsObserver {
protected: protected:
typedef std::pair<std::string, std::string> StringPair;
// Common test results. // Common test results.
static const char kEnded[]; static const char kEnded[];
// TODO(xhwang): Report detailed errors, e.g. "ERROR-3". // TODO(xhwang): Report detailed errors, e.g. "ERROR-3".
...@@ -38,12 +36,13 @@ class MediaBrowserTest : public InProcessBrowserTest, ...@@ -38,12 +36,13 @@ class MediaBrowserTest : public InProcessBrowserTest,
// page, otherwise a local file URL is loaded inside the content shell. // page, otherwise a local file URL is loaded inside the content shell.
// It uses RunTest() to check for expected test output. // It uses RunTest() to check for expected test output.
void RunMediaTestPage(const std::string& html_page, void RunMediaTestPage(const std::string& html_page,
std::vector<StringPair>* query_params, const media::QueryParams& query_params,
const std::string& expected, bool http); const std::string& expected,
bool http);
// Opens a URL and waits for the document title to match either one of the // Opens a URL and waits for the document title to match either one of the
// default strings or the expected string. // default strings or the expected string. Returns the matching title value.
base::string16 RunTest(const GURL& gurl, const std::string& expected); std::string RunTest(const GURL& gurl, const std::string& expected);
virtual void AddWaitForTitles(content::TitleWatcher* title_watcher); virtual void AddWaitForTitles(content::TitleWatcher* title_watcher);
......
...@@ -3,7 +3,6 @@ ...@@ -3,7 +3,6 @@
// found in the LICENSE file. // found in the LICENSE file.
#include "base/command_line.h" #include "base/command_line.h"
#include "base/path_service.h"
#include "base/strings/utf_string_conversions.h" #include "base/strings/utf_string_conversions.h"
#include "base/win/windows_version.h" #include "base/win/windows_version.h"
#include "content/browser/media/media_browsertest.h" #include "content/browser/media/media_browsertest.h"
...@@ -26,6 +25,8 @@ const char kWebMAudioVideo[] = "video/webm; codecs=\"vorbis, vp8\""; ...@@ -26,6 +25,8 @@ const char kWebMAudioVideo[] = "video/webm; codecs=\"vorbis, vp8\"";
const char kEmeKeyError[] = "KEYERROR"; const char kEmeKeyError[] = "KEYERROR";
const char kEmeNotSupportedError[] = "NOTSUPPORTEDERROR"; const char kEmeNotSupportedError[] = "NOTSUPPORTEDERROR";
const char kDefaultEmePlayer[] = "eme_player.html";
// The type of video src used to load media. // The type of video src used to load media.
enum SrcType { enum SrcType {
SRC, SRC,
...@@ -52,7 +53,7 @@ class EncryptedMediaTest : public content::MediaBrowserTest, ...@@ -52,7 +53,7 @@ class EncryptedMediaTest : public content::MediaBrowserTest,
public testing::WithParamInterface<std::tr1::tuple<const char*, SrcType> > { public testing::WithParamInterface<std::tr1::tuple<const char*, SrcType> > {
public: public:
// Can only be used in parameterized (*_P) tests. // Can only be used in parameterized (*_P) tests.
const char* CurrentKeySystem() { const std::string CurrentKeySystem() {
return std::tr1::get<0>(GetParam()); return std::tr1::get<0>(GetParam());
} }
...@@ -61,14 +62,15 @@ class EncryptedMediaTest : public content::MediaBrowserTest, ...@@ -61,14 +62,15 @@ class EncryptedMediaTest : public content::MediaBrowserTest,
return std::tr1::get<1>(GetParam()); return std::tr1::get<1>(GetParam());
} }
void TestSimplePlayback(const char* encrypted_media, const char* media_type) { void TestSimplePlayback(const std::string& encrypted_media,
const std::string& media_type) {
RunSimpleEncryptedMediaTest( RunSimpleEncryptedMediaTest(
encrypted_media, media_type, CurrentKeySystem(), CurrentSourceType()); encrypted_media, media_type, CurrentKeySystem(), CurrentSourceType());
} }
void TestFrameSizeChange() { void TestFrameSizeChange() {
RunEncryptedMediaTest("encrypted_frame_size_change.html", RunEncryptedMediaTest("encrypted_frame_size_change.html",
"frame_size_change-av-enc-v.webm", kWebMAudioVideo, "frame_size_change-av_enc-v.webm", kWebMAudioVideo,
CurrentKeySystem(), CurrentSourceType(), kEnded); CurrentKeySystem(), CurrentSourceType(), kEnded);
} }
...@@ -78,38 +80,42 @@ class EncryptedMediaTest : public content::MediaBrowserTest, ...@@ -78,38 +80,42 @@ class EncryptedMediaTest : public content::MediaBrowserTest,
return; return;
} }
std::vector<StringPair> query_params; media::QueryParams query_params;
query_params.push_back(std::make_pair("keysystem", CurrentKeySystem())); query_params.push_back(std::make_pair("keySystem", CurrentKeySystem()));
query_params.push_back(std::make_pair("runencrypted", "1")); query_params.push_back(std::make_pair("runEncrypted", "1"));
RunMediaTestPage("mse_config_change.html", &query_params, kEnded, true); RunMediaTestPage("mse_config_change.html", query_params, kEnded, true);
} }
void RunEncryptedMediaTest(const char* html_page, void RunEncryptedMediaTest(const std::string& html_page,
const char* media_file, const std::string& media_file,
const char* media_type, const std::string& media_type,
const char* key_system, const std::string& key_system,
SrcType src_type, SrcType src_type,
const char* expectation) { const std::string& expectation) {
if (src_type == MSE && !IsMSESupported()) { if (src_type == MSE && !IsMSESupported()) {
VLOG(0) << "Skipping test - MSE not supported."; VLOG(0) << "Skipping test - MSE not supported.";
return; return;
} }
std::vector<StringPair> query_params; media::QueryParams query_params;
query_params.push_back(std::make_pair("mediafile", media_file)); query_params.push_back(std::make_pair("mediaFile", media_file));
query_params.push_back(std::make_pair("mediatype", media_type)); query_params.push_back(std::make_pair("mediaType", media_type));
query_params.push_back(std::make_pair("keysystem", key_system)); query_params.push_back(std::make_pair("keySystem", key_system));
if (src_type == MSE) if (src_type == MSE)
query_params.push_back(std::make_pair("usemse", "1")); query_params.push_back(std::make_pair("useMSE", "1"));
RunMediaTestPage(html_page, &query_params, expectation, true); RunMediaTestPage(html_page, query_params, expectation, true);
} }
void RunSimpleEncryptedMediaTest(const char* media_file, void RunSimpleEncryptedMediaTest(const std::string& media_file,
const char* media_type, const std::string& media_type,
const char* key_system, const std::string& key_system,
SrcType src_type) { SrcType src_type) {
RunEncryptedMediaTest("encrypted_media_player.html", media_file, RunEncryptedMediaTest(kDefaultEmePlayer,
media_type, key_system, src_type, kEnded); media_file,
media_type,
key_system,
src_type,
kEnded);
} }
protected: protected:
...@@ -141,23 +147,23 @@ INSTANTIATE_TEST_CASE_P(MSE_ClearKey, EncryptedMediaTest, ...@@ -141,23 +147,23 @@ INSTANTIATE_TEST_CASE_P(MSE_ClearKey, EncryptedMediaTest,
Combine(Values(kClearKeyKeySystem), Values(MSE))); Combine(Values(kClearKeyKeySystem), Values(MSE)));
IN_PROC_BROWSER_TEST_P(EncryptedMediaTest, Playback_AudioOnly_WebM) { IN_PROC_BROWSER_TEST_P(EncryptedMediaTest, Playback_AudioOnly_WebM) {
TestSimplePlayback("bear-a-enc_a.webm", kWebMAudioOnly); TestSimplePlayback("bear-a_enc-a.webm", kWebMAudioOnly);
} }
IN_PROC_BROWSER_TEST_P(EncryptedMediaTest, Playback_AudioClearVideo_WebM) { IN_PROC_BROWSER_TEST_P(EncryptedMediaTest, Playback_AudioClearVideo_WebM) {
TestSimplePlayback("bear-320x240-av-enc_a.webm", kWebMAudioVideo); TestSimplePlayback("bear-320x240-av_enc-a.webm", kWebMAudioVideo);
} }
IN_PROC_BROWSER_TEST_P(EncryptedMediaTest, Playback_VideoAudio_WebM) { IN_PROC_BROWSER_TEST_P(EncryptedMediaTest, Playback_VideoAudio_WebM) {
TestSimplePlayback("bear-320x240-av-enc_av.webm", kWebMAudioVideo); TestSimplePlayback("bear-320x240-av_enc-av.webm", kWebMAudioVideo);
} }
IN_PROC_BROWSER_TEST_P(EncryptedMediaTest, Playback_VideoOnly_WebM) { IN_PROC_BROWSER_TEST_P(EncryptedMediaTest, Playback_VideoOnly_WebM) {
TestSimplePlayback("bear-320x240-v-enc_v.webm", kWebMVideoOnly); TestSimplePlayback("bear-320x240-v_enc-v.webm", kWebMVideoOnly);
} }
IN_PROC_BROWSER_TEST_P(EncryptedMediaTest, Playback_VideoClearAudio_WebM) { IN_PROC_BROWSER_TEST_P(EncryptedMediaTest, Playback_VideoClearAudio_WebM) {
TestSimplePlayback("bear-320x240-av-enc_v.webm", kWebMAudioVideo); TestSimplePlayback("bear-320x240-av_enc-v.webm", kWebMAudioVideo);
} }
IN_PROC_BROWSER_TEST_P(EncryptedMediaTest, ConfigChangeVideo) { IN_PROC_BROWSER_TEST_P(EncryptedMediaTest, ConfigChangeVideo) {
...@@ -174,8 +180,11 @@ IN_PROC_BROWSER_TEST_P(EncryptedMediaTest, FrameSizeChangeVideo) { ...@@ -174,8 +180,11 @@ IN_PROC_BROWSER_TEST_P(EncryptedMediaTest, FrameSizeChangeVideo) {
} }
IN_PROC_BROWSER_TEST_F(EncryptedMediaTest, UnknownKeySystemThrowsException) { IN_PROC_BROWSER_TEST_F(EncryptedMediaTest, UnknownKeySystemThrowsException) {
RunEncryptedMediaTest("encrypted_media_player.html", "bear-a-enc_a.webm", RunEncryptedMediaTest(kDefaultEmePlayer,
kWebMAudioOnly, "com.example.foo", MSE, "bear-a_enc-a.webm",
kWebMAudioOnly,
"com.example.foo",
MSE,
kEmeNotSupportedError); kEmeNotSupportedError);
} }
......
...@@ -4,10 +4,8 @@ ...@@ -4,10 +4,8 @@
#include "content/browser/media/media_browsertest.h" #include "content/browser/media/media_browsertest.h"
#include "base/strings/stringprintf.h"
#include "base/strings/utf_string_conversions.h" #include "base/strings/utf_string_conversions.h"
#include "content/public/browser/web_contents.h" #include "content/public/browser/web_contents.h"
#include "content/public/common/url_constants.h"
#include "content/public/test/browser_test_utils.h" #include "content/public/test/browser_test_utils.h"
#include "content/public/test/content_browser_test_utils.h" #include "content/public/test/content_browser_test_utils.h"
#include "content/shell/browser/shell.h" #include "content/shell/browser/shell.h"
...@@ -26,39 +24,33 @@ const char MediaBrowserTest::kEnded[] = "ENDED"; ...@@ -26,39 +24,33 @@ const char MediaBrowserTest::kEnded[] = "ENDED";
const char MediaBrowserTest::kError[] = "ERROR"; const char MediaBrowserTest::kError[] = "ERROR";
const char MediaBrowserTest::kFailed[] = "FAILED"; const char MediaBrowserTest::kFailed[] = "FAILED";
void MediaBrowserTest::RunMediaTestPage( void MediaBrowserTest::RunMediaTestPage(const std::string& html_page,
const char* html_page, std::vector<StringPair>* query_params, const media::QueryParams& query_params,
const char* expected, bool http) { const std::string& expected_title,
bool http) {
GURL gurl; GURL gurl;
std::string query = ""; std::string query = media::GetURLQueryString(query_params);
if (query_params != NULL && !query_params->empty()) { scoped_ptr<net::SpawnedTestServer> http_test_server;
std::vector<StringPair>::const_iterator itr = query_params->begin();
query = base::StringPrintf("%s=%s", itr->first, itr->second);
++itr;
for (; itr != query_params->end(); ++itr) {
query.append(base::StringPrintf("&%s=%s", itr->first, itr->second));
}
}
if (http) { if (http) {
ASSERT_TRUE(test_server()->Start()); http_test_server = media::StartMediaHttpTestServer();
gurl = test_server()->GetURL( gurl = http_test_server->GetURL("files/" + html_page + "?" + query);
base::StringPrintf("files/media/%s?%s", html_page, query.c_str()));
} else { } else {
base::FilePath test_file_path = GetTestFilePath("media", html_page); gurl = content::GetFileUrlWithQuery(media::GetTestDataFilePath(html_page),
gurl = GetFileUrlWithQuery(test_file_path, query); query);
} }
RunTest(gurl, expected); std::string final_title = RunTest(gurl, expected_title);
EXPECT_EQ(expected_title, final_title);
} }
void MediaBrowserTest::RunTest(const GURL& gurl, const char* expected) { std::string MediaBrowserTest::RunTest(const GURL& gurl,
const base::string16 expected_title = base::ASCIIToUTF16(expected); const std::string& expected_title) {
DVLOG(1) << "Running test URL: " << gurl; VLOG(0) << "Running test URL: " << gurl;
TitleWatcher title_watcher(shell()->web_contents(), expected_title); TitleWatcher title_watcher(shell()->web_contents(),
base::ASCIIToUTF16(expected_title));
AddWaitForTitles(&title_watcher); AddWaitForTitles(&title_watcher);
NavigateToURL(shell(), gurl); NavigateToURL(shell(), gurl);
base::string16 result = title_watcher.WaitAndGetTitle();
base::string16 final_title = title_watcher.WaitAndGetTitle(); return base::UTF16ToASCII(result);
EXPECT_EQ(expected_title, final_title);
} }
void MediaBrowserTest::AddWaitForTitles(content::TitleWatcher* title_watcher) { void MediaBrowserTest::AddWaitForTitles(content::TitleWatcher* title_watcher) {
...@@ -75,25 +67,29 @@ class MediaTest : public testing::WithParamInterface<bool>, ...@@ -75,25 +67,29 @@ class MediaTest : public testing::WithParamInterface<bool>,
public MediaBrowserTest { public MediaBrowserTest {
public: public:
// Play specified audio over http:// or file:// depending on |http| setting. // Play specified audio over http:// or file:// depending on |http| setting.
void PlayAudio(const char* media_file, bool http) { void PlayAudio(const std::string& media_file, bool http) {
PlayMedia("audio", media_file, http); PlayMedia("audio", media_file, http);
} }
// Play specified video over http:// or file:// depending on |http| setting. // Play specified video over http:// or file:// depending on |http| setting.
void PlayVideo(const char* media_file, bool http) { void PlayVideo(const std::string& media_file, bool http) {
PlayMedia("video", media_file, http); PlayMedia("video", media_file, http);
} }
// Run specified color format test with the expected result. // Run specified color format test with the expected result.
void RunColorFormatTest(const char* media_file, const char* expected) { void RunColorFormatTest(const std::string& media_file,
base::FilePath test_file_path = GetTestFilePath("media", "blackwhite.html"); const std::string& expected) {
base::FilePath test_file_path =
media::GetTestDataFilePath("blackwhite.html");
RunTest(GetFileUrlWithQuery(test_file_path, media_file), expected); RunTest(GetFileUrlWithQuery(test_file_path, media_file), expected);
} }
void PlayMedia(const char* tag, const char* media_file, bool http) { void PlayMedia(const std::string& tag,
std::vector<StringPair> query_params; const std::string& media_file,
bool http) {
media::QueryParams query_params;
query_params.push_back(std::make_pair(tag, media_file)); query_params.push_back(std::make_pair(tag, media_file));
RunMediaTestPage("player.html", &query_params, kEnded, http); RunMediaTestPage("player.html", query_params, kEnded, http);
} }
}; };
...@@ -140,7 +136,7 @@ IN_PROC_BROWSER_TEST_P(MediaTest, VideoBearMovPcmS16be) { ...@@ -140,7 +136,7 @@ IN_PROC_BROWSER_TEST_P(MediaTest, VideoBearMovPcmS16be) {
IN_PROC_BROWSER_TEST_P(MediaTest, VideoBearMovPcmS24be) { IN_PROC_BROWSER_TEST_P(MediaTest, VideoBearMovPcmS24be) {
PlayVideo("bear_pcm_s24be.mov", GetParam()); PlayVideo("bear_pcm_s24be.mov", GetParam());
} }
#endif #endif // defined(USE_PROPRIETARY_CODECS)
#if defined(OS_CHROMEOS) #if defined(OS_CHROMEOS)
#if defined(USE_PROPRIETARY_CODECS) #if defined(USE_PROPRIETARY_CODECS)
...@@ -171,8 +167,9 @@ IN_PROC_BROWSER_TEST_P(MediaTest, VideoBearWavGsmms) { ...@@ -171,8 +167,9 @@ IN_PROC_BROWSER_TEST_P(MediaTest, VideoBearWavGsmms) {
IN_PROC_BROWSER_TEST_P(MediaTest, VideoBearFlac) { IN_PROC_BROWSER_TEST_P(MediaTest, VideoBearFlac) {
PlayAudio("bear.flac", GetParam()); PlayAudio("bear.flac", GetParam());
} }
#endif #endif // defined(USE_PROPRIETARY_CODECS)
#endif #endif // defined(OS_CHROMEOS)
IN_PROC_BROWSER_TEST_P(MediaTest, VideoBearWavAlaw) { IN_PROC_BROWSER_TEST_P(MediaTest, VideoBearWavAlaw) {
PlayAudio("bear_alaw.wav", GetParam()); PlayAudio("bear_alaw.wav", GetParam());
...@@ -209,19 +206,19 @@ INSTANTIATE_TEST_CASE_P(File, MediaTest, ::testing::Values(false)); ...@@ -209,19 +206,19 @@ INSTANTIATE_TEST_CASE_P(File, MediaTest, ::testing::Values(false));
INSTANTIATE_TEST_CASE_P(Http, MediaTest, ::testing::Values(true)); INSTANTIATE_TEST_CASE_P(Http, MediaTest, ::testing::Values(true));
IN_PROC_BROWSER_TEST_F(MediaTest, MAYBE(Yuv420pTheora)) { IN_PROC_BROWSER_TEST_F(MediaTest, MAYBE(Yuv420pTheora)) {
RunColorFormatTest("yuv420p.ogv", "ENDED"); RunColorFormatTest("yuv420p.ogv", kEnded);
} }
IN_PROC_BROWSER_TEST_F(MediaTest, MAYBE(Yuv422pTheora)) { IN_PROC_BROWSER_TEST_F(MediaTest, MAYBE(Yuv422pTheora)) {
RunColorFormatTest("yuv422p.ogv", "ENDED"); RunColorFormatTest("yuv422p.ogv", kEnded);
} }
IN_PROC_BROWSER_TEST_F(MediaTest, MAYBE(Yuv444pTheora)) { IN_PROC_BROWSER_TEST_F(MediaTest, MAYBE(Yuv444pTheora)) {
RunColorFormatTest("yuv444p.ogv", "ENDED"); RunColorFormatTest("yuv444p.ogv", kEnded);
} }
IN_PROC_BROWSER_TEST_F(MediaTest, MAYBE(Yuv420pVp8)) { IN_PROC_BROWSER_TEST_F(MediaTest, MAYBE(Yuv420pVp8)) {
RunColorFormatTest("yuv420p.webm", "ENDED"); RunColorFormatTest("yuv420p.webm", kEnded);
} }
// TODO(johannkoenig): Reenable after landing libvpx roll // TODO(johannkoenig): Reenable after landing libvpx roll
...@@ -232,24 +229,24 @@ IN_PROC_BROWSER_TEST_F(MediaTest, DISABLED_Yuv444pVp9) { ...@@ -232,24 +229,24 @@ IN_PROC_BROWSER_TEST_F(MediaTest, DISABLED_Yuv444pVp9) {
#if defined(USE_PROPRIETARY_CODECS) #if defined(USE_PROPRIETARY_CODECS)
IN_PROC_BROWSER_TEST_F(MediaTest, MAYBE(Yuv420pH264)) { IN_PROC_BROWSER_TEST_F(MediaTest, MAYBE(Yuv420pH264)) {
RunColorFormatTest("yuv420p.mp4", "ENDED"); RunColorFormatTest("yuv420p.mp4", kEnded);
} }
IN_PROC_BROWSER_TEST_F(MediaTest, MAYBE(Yuvj420pH264)) { IN_PROC_BROWSER_TEST_F(MediaTest, MAYBE(Yuvj420pH264)) {
RunColorFormatTest("yuvj420p.mp4", "ENDED"); RunColorFormatTest("yuvj420p.mp4", kEnded);
} }
IN_PROC_BROWSER_TEST_F(MediaTest, MAYBE(Yuv422pH264)) { IN_PROC_BROWSER_TEST_F(MediaTest, MAYBE(Yuv422pH264)) {
RunColorFormatTest("yuv422p.mp4", "ENDED"); RunColorFormatTest("yuv422p.mp4", kEnded);
} }
IN_PROC_BROWSER_TEST_F(MediaTest, MAYBE(Yuv444pH264)) { IN_PROC_BROWSER_TEST_F(MediaTest, MAYBE(Yuv444pH264)) {
RunColorFormatTest("yuv444p.mp4", "ENDED"); RunColorFormatTest("yuv444p.mp4", kEnded);
} }
#if defined(OS_CHROMEOS) #if defined(OS_CHROMEOS)
IN_PROC_BROWSER_TEST_F(MediaTest, Yuv420pMpeg4) { IN_PROC_BROWSER_TEST_F(MediaTest, Yuv420pMpeg4) {
RunColorFormatTest("yuv420p.avi", "ENDED"); RunColorFormatTest("yuv420p.avi", kEnded);
} }
#endif // defined(OS_CHROMEOS) #endif // defined(OS_CHROMEOS)
#endif // defined(USE_PROPRIETARY_CODECS) #endif // defined(USE_PROPRIETARY_CODECS)
......
...@@ -5,10 +5,10 @@ ...@@ -5,10 +5,10 @@
#ifndef CONTENT_BROWSER_MEDIA_MEDIA_BROWSERTEST_H_ #ifndef CONTENT_BROWSER_MEDIA_MEDIA_BROWSERTEST_H_
#define CONTENT_BROWSER_MEDIA_MEDIA_BROWSERTEST_H_ #define CONTENT_BROWSER_MEDIA_MEDIA_BROWSERTEST_H_
#include <utility> #include <string>
#include <vector>
#include "content/public/test/content_browser_test.h" #include "content/public/test/content_browser_test.h"
#include "media/base/test_data_util.h"
namespace content { namespace content {
...@@ -19,8 +19,6 @@ class TitleWatcher; ...@@ -19,8 +19,6 @@ class TitleWatcher;
// the test http server. // the test http server.
class MediaBrowserTest : public ContentBrowserTest { class MediaBrowserTest : public ContentBrowserTest {
public: public:
typedef std::pair<const char*, const char*> StringPair;
// Common test results. // Common test results.
static const char kEnded[]; static const char kEnded[];
static const char kError[]; static const char kError[];
...@@ -30,13 +28,14 @@ class MediaBrowserTest : public ContentBrowserTest { ...@@ -30,13 +28,14 @@ class MediaBrowserTest : public ContentBrowserTest {
// If http is true, the test starts a local http test server to load the test // If http is true, the test starts a local http test server to load the test
// page, otherwise a local file URL is loaded inside the content shell. // page, otherwise a local file URL is loaded inside the content shell.
// It uses RunTest() to check for expected test output. // It uses RunTest() to check for expected test output.
void RunMediaTestPage(const char* html_page, void RunMediaTestPage(const std::string& html_page,
std::vector<StringPair>* query_params, const media::QueryParams& query_params,
const char* expected, bool http); const std::string& expected,
bool http);
// Opens a URL and waits for the document title to match either one of the // Opens a URL and waits for the document title to match either one of the
// default strings or the expected string. // default strings or the expected string. Returns the matching title value.
void RunTest(const GURL& gurl, const char* expected); std::string RunTest(const GURL& gurl, const std::string& expected);
virtual void AddWaitForTitles(content::TitleWatcher* title_watcher); virtual void AddWaitForTitles(content::TitleWatcher* title_watcher);
}; };
......
...@@ -32,17 +32,18 @@ static bool IsMSESupported() { ...@@ -32,17 +32,18 @@ static bool IsMSESupported() {
class MediaSourceTest : public content::MediaBrowserTest { class MediaSourceTest : public content::MediaBrowserTest {
public: public:
void TestSimplePlayback(const char* media_file, const char* media_type, void TestSimplePlayback(const std::string& media_file,
const char* expectation) { const std::string& media_type,
const std::string& expectation) {
if (!IsMSESupported()) { if (!IsMSESupported()) {
VLOG(0) << "Skipping test - MSE not supported."; VLOG(0) << "Skipping test - MSE not supported.";
return; return;
} }
std::vector<StringPair> query_params; media::QueryParams query_params;
query_params.push_back(std::make_pair("mediafile", media_file)); query_params.push_back(std::make_pair("mediaFile", media_file));
query_params.push_back(std::make_pair("mediatype", media_type)); query_params.push_back(std::make_pair("mediaType", media_type));
RunMediaTestPage("media_source_player.html", &query_params, expectation, RunMediaTestPage("media_source_player.html", query_params, expectation,
true); true);
} }
...@@ -84,7 +85,10 @@ IN_PROC_BROWSER_TEST_F(MediaSourceTest, ConfigChangeVideo) { ...@@ -84,7 +85,10 @@ IN_PROC_BROWSER_TEST_F(MediaSourceTest, ConfigChangeVideo) {
VLOG(0) << "Skipping test - MSE not supported."; VLOG(0) << "Skipping test - MSE not supported.";
return; return;
} }
RunMediaTestPage("mse_config_change.html", NULL, kEnded, true); RunMediaTestPage("mse_config_change.html",
media::QueryParams(),
kEnded,
true);
} }
} // namespace content } // namespace content
<!DOCTYPE html>
<html>
<body onload="load()">
<p>Tests decoding and rendering encrypted video element that has a changing
resolution.</p>
<video width=320 controls></video>
<video controls></video>
<script src="media_utils.js" type="text/javascript"></script>
<script src="media_source_utils.js" type="text/javascript"></script>
<script src="encrypted_media_utils.js" type="text/javascript"></script>
<script>
var firstVideoSeek = false;
var video_fixed_size = document.getElementsByTagName("video")[0];
var video = document.getElementsByTagName("video")[1];
function load() {
loadVideo(video_fixed_size);
loadVideo(video);
}
function loadVideo(video) {
var mediaSource = loadEncryptedMediaFromURL(video);
video.addEventListener('playing', function() {
// Make sure the video plays for a bit.
video.addEventListener('timeupdate', function() {
if (video.currentTime > 1.0) {
video.pause();
}
});
});
video.addEventListener('pause', function() {
video.addEventListener('seeked', function() {
if (!firstVideoSeek) {
console.log('One video seeked.');
firstVideoSeek = true;
return;
}
setResultInTitle('ENDED');
});
video.currentTime = 0.5;
});
video.addEventListener('canplay', oncanplay);
video.play();
}
</script>
</body>
</html>
<!DOCTYPE html>
<html>
<head>
<title>Encrypted Media Player</title>
</head>
<body onload="runTest();">
<video controls></video>
<script src="media_utils.js" type="text/javascript"></script>
<script src="media_source_utils.js" type="text/javascript"></script>
<script src="encrypted_media_utils.js" type="text/javascript"></script>
<script type="text/javascript">
var video = document.querySelector('video');
function onTimeUpdate() {
if (video.currentTime < 1)
return;
// keyadded may be fired around the start of playback; check for it
// after a delay to avoid timing issues.
if (!video.receivedKeyAdded)
failTest('Key added event not received.');
if (video.isHeartbeatExpected && !video.receivedHeartbeat)
failTest('Heartbeat keymessage event not received.');
video.removeEventListener('ended', failTest);
installTitleEventHandler(video, 'ended');
video.removeEventListener('timeupdate', onTimeUpdate);
}
// The test completes after playing the encrypted media for 1 second and
// getting the ended event or when an error occurs at any time.
function runTest() {
loadEncryptedMediaFromURL(video);
video.addEventListener('timeupdate', onTimeUpdate);
video.play();
}
</script>
</body>
</html>
// Copyright (c) 2013 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
var keySystem = QueryString.keysystem;
var mediaFile = QueryString.mediafile;
var mediaType = QueryString.mediatype || 'video/webm; codecs="vorbis, vp8"';
var useMSE = QueryString.usemse == 1;
// Default key used to encrypt many media files used in browser tests.
var KEY = new Uint8Array([0xeb, 0xdd, 0x62, 0xf1, 0x68, 0x14, 0xd2, 0x7b,
0x68, 0xef, 0x12, 0x2a, 0xfc, 0xe4, 0xae, 0x3c]);
// KEY_ID constant used as init data while encrypting test media files.
var KEY_ID = getInitDataFromKeyId("0123456789012345");
// Heart beat message header.
var HEART_BEAT_HEADER = 'HEARTBEAT';
var EXTERNAL_CLEAR_KEY_KEY_SYSTEM = "org.chromium.externalclearkey";
// Note that his URL has been normalized from the one in clear_key_cdm.cc.
var EXTERNAL_CLEAR_KEY_HEARTBEAT_URL =
'http://test.externalclearkey.chromium.org/';
function isHeartbeatMessage(msg) {
if (msg.length < HEART_BEAT_HEADER.length)
return false;
for (var i = 0; i < HEART_BEAT_HEADER.length; ++i) {
if (String.fromCharCode(msg[i]) != HEART_BEAT_HEADER[i])
return false;
}
return true;
}
function loadEncryptedMediaFromURL(video) {
return loadEncryptedMedia(video, mediaFile, keySystem, KEY, useMSE);
}
function loadEncryptedMedia(video, mediaFile, keySystem, key, useMSE,
appendSourceCallbackFn) {
var keyRequested = false;
var sourceOpened = false;
// Add properties to enable verification that events occurred.
video.receivedKeyAdded = false;
video.receivedHeartbeat = false;
video.isHeartbeatExpected = keySystem === EXTERNAL_CLEAR_KEY_KEY_SYSTEM;
video.receivedKeyMessage = false;
if (!(video && mediaFile && keySystem && key)) {
failTest('Missing parameters in loadEncryptedMedia().');
return;
}
function onNeedKey(e) {
if (keyRequested)
return;
keyRequested = true;
console.log('onNeedKey', e);
try {
video.webkitGenerateKeyRequest(keySystem, e.initData);
}
catch(error) {
setResultInTitle(error.name);
}
}
function onKeyAdded(e) {
e.target.receivedKeyAdded = true;
}
function onKeyMessage(e) {
video.receivedKeyMessage = true;
if (!e.keySystem || e.keySystem != keySystem) {
failTest('keymessage with unexpected keySystem: ' + e.keySystem);
return;
}
if (!e.sessionId) {
failTest('keymessage without a sessionId: ' + e.sessionId);
return;
}
if (!e.message) {
failTest('keymessage without a message: ' + e.message);
return;
}
if (isHeartbeatMessage(e.message)) {
console.log('onKeyMessage - heartbeat', e);
e.target.receivedHeartbeat = true;
verifyHeartbeatMessage(e);
return;
}
// No tested key system returns defaultURL in for key request messages.
if (e.defaultURL) {
failTest('keymessage unexpectedly has defaultURL: ' + e.defaultURL);
return;
}
// keymessage in response to generateKeyRequest. Reply with key.
console.log('onKeyMessage - key request', e);
var initData = e.message;
if (mediaType.indexOf('mp4') != -1)
initData = KEY_ID; // Temporary hack for Clear Key in v0.1.
video.webkitAddKey(keySystem, key, initData);
}
function verifyHeartbeatMessage(e) {
// Only External Clear Key sends a HEARTBEAT message.
if (e.keySystem != EXTERNAL_CLEAR_KEY_KEY_SYSTEM) {
failTest('Unexpected heartbeat from ' + e.keySystem);
return;
}
if (e.defaultURL != EXTERNAL_CLEAR_KEY_HEARTBEAT_URL) {
failTest('Heartbeat message with unexpected defaultURL: ' + e.defaultURL);
return;
}
}
video.addEventListener('webkitneedkey', onNeedKey);
video.addEventListener('webkitkeymessage', onKeyMessage);
video.addEventListener('webkitkeyerror', function() {
setResultInTitle("KeyError");
});
video.addEventListener('webkitkeyadded', onKeyAdded);
installTitleEventHandler(video, 'error');
if (useMSE) {
var mediaSource = loadMediaSource(mediaFile, mediaType,
appendSourceCallbackFn);
video.src = window.URL.createObjectURL(mediaSource);
} else {
video.src = mediaFile;
}
}
function getInitDataFromKeyId(keyID) {
var init_key_id = new Uint8Array(keyID.length);
for(var i = 0; i < keyID.length; i++) {
init_key_id[i] = keyID.charCodeAt(i);
}
return init_key_id;
}
// Copyright (c) 2013 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
function loadMediaFromURL(video) {
installTitleEventHandler(video, 'error');
video.addEventListener('playing', function(event) {
console.log('Video Playing.');
});
var source = loadMediaSource(QueryString.mediafile, QueryString.mediatype);
video.src = window.URL.createObjectURL(source);
}
function loadMediaSource(mediaFiles, mediaTypes, appendSourceCallbackFn) {
mediaFiles = convertToArray(mediaFiles);
mediaTypes = convertToArray(mediaTypes);
if (!mediaFiles || !mediaTypes)
failTest('Missing parameters in loadMediaSource().');
var totalAppended = 0;
function onSourceOpen(e) {
console.log('onSourceOpen', e);
// We can load multiple media files using the same media type. However, if
// more than one media type is used, we expect to have a media type entry
// for each corresponding media file.
var srcBuffer = null;
for (var i = 0; i < mediaFiles.length; i++) {
if (i == 0 || mediaFiles.length == mediaTypes.length) {
console.log('Creating a source buffer for type ' + mediaTypes[i]);
try {
srcBuffer = mediaSource.addSourceBuffer(mediaTypes[i]);
} catch (e) {
failTest('Exception adding source buffer: ' + e.message);
return;
}
}
doAppend(mediaFiles[i], srcBuffer);
}
}
function doAppend(mediaFile, srcBuffer) {
var xhr = new XMLHttpRequest();
xhr.open('GET', mediaFile);
xhr.responseType = 'arraybuffer';
xhr.addEventListener('load', function(e) {
var onUpdateEnd = function(e) {
console.log('End of appending buffer from ' + mediaFile);
srcBuffer.removeEventListener('updateend', onUpdateEnd);
totalAppended++;
if (totalAppended == mediaFiles.length) {
if (appendSourceCallbackFn)
appendSourceCallbackFn(mediaSource);
else
mediaSource.endOfStream();
}
};
srcBuffer.addEventListener('updateend', onUpdateEnd);
srcBuffer.appendBuffer(new Uint8Array(e.target.response));
});
xhr.send();
}
var mediaSource = new MediaSource();
mediaSource.addEventListener('sourceopen', onSourceOpen);
return mediaSource;
}
// Copyright (c) 2013 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
var QueryString = function() {
// Allows access to query parameters on the URL; e.g., given a URL like:
// http://<server>/my.html?test=123&bob=123
// Parameters can then be accessed via QueryString.test or QueryString.bob.
var params = {};
// RegEx to split out values by &.
var r = /([^&=]+)=?([^&]*)/g;
// Lambda function for decoding extracted match values. Replaces '+' with
// space so decodeURIComponent functions properly.
function d(s) { return decodeURIComponent(s.replace(/\+/g, ' ')); }
var match;
while (match = r.exec(window.location.search.substring(1)))
params[d(match[1])] = d(match[2]);
return params;
}();
function failTest(msg) {
var failMessage = msg;
if (msg instanceof Event)
failMessage = msg.target + '.' + msg.type;
console.log("FAILED TEST: " + msg);
setResultInTitle('FAILED');
}
var titleChanged = false;
function setResultInTitle(title) {
// If document title is 'ENDED', then update it with new title to possibly
// mark a test as failure. Otherwise, keep the first title change in place.
if (!titleChanged || document.title.toUpperCase() == 'ENDED')
document.title = title.toUpperCase();
console.log('Set document title to: ' + title + ', updated title: ' +
document.title);
titleChanged = true;
}
function installTitleEventHandler(element, event) {
element.addEventListener(event, function(e) {
setResultInTitle(event.toString());
}, false);
}
function convertToArray(input) {
if (Array.isArray(input))
return input;
return [input];
}
<html>
<head>
<title>Test media source config changes.</title>
</head>
<body onload="runTest();">
<video controls></video>
<script src="media_utils.js" type="text/javascript"></script>
<script src="media_source_utils.js" type="text/javascript"></script>
<script src="encrypted_media_utils.js" type="text/javascript"></script>
<script type="text/javascript">
var runEncrypted = QueryString.runencrypted == 1;
var video = document.querySelector('video');
var mediaType = 'video/webm; codecs="vorbis, vp8"';
var MEDIA_1 = 'bear-320x240.webm';
var MEDIA_2 = 'bear-640x360.webm';
if (runEncrypted) {
MEDIA_1 = 'bear-320x240-av-enc_av.webm';
MEDIA_2 = 'bear-640x360-av-enc_av.webm';
}
var MEDIA_1_WIDTH = 320;
var MEDIA_1_HEIGHT = 240;
var MEDIA_2_WIDTH = 640;
var MEDIA_2_HEIGHT = 360;
var MEDIA_2_LENGTH = 2.75;
// The time in secs to append the second media source.
var APPEND_TIME = 1;
// DELTA is the time after APPEND_TIME where the second video dimensions
// are guaranteed to take effect.
var DELTA = 0.1;
// Append MEDIA_2 source at APPEND_TIME, so expected total duration is:
var TOTAL_DURATION = APPEND_TIME + MEDIA_2_LENGTH;
function appendNextSource(mediaSource) {
console.log('Appending next media source at ' + APPEND_TIME + 'sec.');
var xhr = new XMLHttpRequest();
xhr.open("GET", MEDIA_2);
xhr.responseType = 'arraybuffer';
xhr.addEventListener('load', function(e) {
var onUpdateEnd = function(e) {
console.log('Second buffer append ended.');
srcBuffer.removeEventListener('updateend', onUpdateEnd);
mediaSource.endOfStream();
if (!mediaSource.duration ||
Math.abs(mediaSource.duration - TOTAL_DURATION) > DELTA) {
failTest('Unexpected mediaSource.duration = ' +
mediaSource.duration + ', expected duration = ' +
TOTAL_DURATION);
return;
}
video.play();
};
console.log('Appending next media source at ' + APPEND_TIME + 'sec.');
var srcBuffer = mediaSource.sourceBuffers[0];
srcBuffer.addEventListener('updateend', onUpdateEnd);
srcBuffer.timestampOffset = APPEND_TIME;
srcBuffer.appendBuffer(new Uint8Array(e.target.response));
});
xhr.send();
}
function onTimeUpdate() {
// crbug.com/246308
//checkVideoProperties();
// Seek to APPEND_TIME because after a seek a timeUpdate event is fired
// before video width and height properties get updated.
if (video.currentTime < APPEND_TIME - DELTA) {
// Seek to save test execution time (about 1 secs) and to test seek
// on the first buffer.
video.currentTime = APPEND_TIME - DELTA;
} else if (video.currentTime > APPEND_TIME + DELTA) {
// Check video duration here to guarantee that second segment has been
// appended and video total duration is updated.
// Video duration is a float value so we check it within a range.
if (!video.duration ||
Math.abs(video.duration - TOTAL_DURATION) > DELTA) {
failTest('Unexpected video.duration = ' + video.duration +
', expected duration = ' + TOTAL_DURATION);
return;
}
video.removeEventListener('timeupdate', onTimeUpdate);
video.removeEventListener('ended', failTest);
installTitleEventHandler(video, 'ended');
// Seek to save test execution time and to test seek on second buffer.
video.currentTime = APPEND_TIME + MEDIA_2_LENGTH * 0.9;
}
}
function checkVideoProperties() {
if (video.currentTime <= APPEND_TIME) {
if (video.videoWidth != MEDIA_1_WIDTH ||
video.videoHeight != MEDIA_1_HEIGHT) {
logVideoDimensions();
failTest('Unexpected dimensions for first video segment.');
return;
}
} else if (video.currentTime >= APPEND_TIME + DELTA) {
if (video.videoWidth != MEDIA_2_WIDTH ||
video.videoHeight != MEDIA_2_HEIGHT) {
logVideoDimensions();
failTest('Unexpected dimensions for second video segment.');
return;
}
}
}
function logVideoDimensions() {
console.log('video.currentTime = ' + video.currentTime +
', video dimensions = ' + video.videoWidth + 'x' +
video.videoHeight + '.');
}
function runTest() {
video.addEventListener('timeupdate', onTimeUpdate);
video.addEventListener('ended', failTest);
if (runEncrypted) {
loadEncryptedMedia(video, MEDIA_1, keySystem, KEY, true,
appendNextSource);
} else {
var mediaSource = loadMediaSource(MEDIA_1, mediaType,
appendNextSource);
video.src = window.URL.createObjectURL(mediaSource);
}
}
</script>
</body>
</html>
include_rules = [ include_rules = [
"+gpu", "+gpu",
"+jni", "+jni",
"+net/test",
"+third_party/ffmpeg", "+third_party/ffmpeg",
"+third_party/libvpx", "+third_party/libvpx",
"+third_party/libyuv", "+third_party/libyuv",
......
...@@ -12,14 +12,38 @@ ...@@ -12,14 +12,38 @@
namespace media { namespace media {
const base::FilePath::CharType kTestDataPath[] =
FILE_PATH_LITERAL("media/test/data");
base::FilePath GetTestDataFilePath(const std::string& name) { base::FilePath GetTestDataFilePath(const std::string& name) {
base::FilePath file_path; base::FilePath file_path;
CHECK(PathService::Get(base::DIR_SOURCE_ROOT, &file_path)); CHECK(PathService::Get(base::DIR_SOURCE_ROOT, &file_path));
return file_path.Append(GetTestDataPath()).AppendASCII(name);
}
base::FilePath GetTestDataPath() {
return base::FilePath(kTestDataPath);
}
std::string GetURLQueryString(const QueryParams& query_params) {
std::string query = "";
QueryParams::const_iterator itr = query_params.begin();
for (; itr != query_params.end(); ++itr) {
if (itr != query_params.begin())
query.append("&");
query.append(itr->first + "=" + itr->second);
}
return query;
}
return file_path.AppendASCII("media") scoped_ptr<net::SpawnedTestServer> StartMediaHttpTestServer() {
.AppendASCII("test") scoped_ptr<net::SpawnedTestServer> http_test_server;
.AppendASCII("data") http_test_server.reset(new net::SpawnedTestServer(
.AppendASCII(name); net::SpawnedTestServer::TYPE_HTTP,
net::SpawnedTestServer::kLocalhost,
GetTestDataPath()));
CHECK(http_test_server->Start());
return http_test_server.Pass();
} }
scoped_refptr<DecoderBuffer> ReadTestDataFile(const std::string& name) { scoped_refptr<DecoderBuffer> ReadTestDataFile(const std::string& name) {
......
...@@ -6,19 +6,34 @@ ...@@ -6,19 +6,34 @@
#define MEDIA_BASE_TEST_DATA_UTIL_H_ #define MEDIA_BASE_TEST_DATA_UTIL_H_
#include <string> #include <string>
#include <utility>
#include <vector>
#include "base/basictypes.h" #include "base/basictypes.h"
#include "base/files/file_path.h" #include "base/files/file_path.h"
#include "base/memory/ref_counted.h" #include "base/memory/ref_counted.h"
#include "base/memory/scoped_ptr.h" #include "base/memory/scoped_ptr.h"
#include "net/test/spawned_test_server/spawned_test_server.h"
namespace media { namespace media {
class DecoderBuffer; class DecoderBuffer;
typedef std::vector<std::pair<std::string, std::string> > QueryParams;
// Returns a file path for a file in the media/test/data directory. // Returns a file path for a file in the media/test/data directory.
base::FilePath GetTestDataFilePath(const std::string& name); base::FilePath GetTestDataFilePath(const std::string& name);
// Returns relative path for test data folder: media/test/data.
base::FilePath GetTestDataPath();
// Starts an HTTP server serving files from media data path.
scoped_ptr<net::SpawnedTestServer> StartMediaHttpTestServer();
// Returns a string containing key value query params in the form of:
// "key_1=value_1&key_2=value2"
std::string GetURLQueryString(const QueryParams& query_params);
// Reads a test file from media/test/data directory and stores it in // Reads a test file from media/test/data directory and stores it in
// a DecoderBuffer. Use DecoderBuffer vs DataBuffer to ensure no matter // a DecoderBuffer. Use DecoderBuffer vs DataBuffer to ensure no matter
// what a test does, it's safe to use FFmpeg methods. // what a test does, it's safe to use FFmpeg methods.
......
...@@ -1356,6 +1356,7 @@ ...@@ -1356,6 +1356,7 @@
'media', 'media',
'shared_memory_support', 'shared_memory_support',
'../base/base.gyp:base', '../base/base.gyp:base',
'../net/net.gyp:net_test_support',
'../skia/skia.gyp:skia', '../skia/skia.gyp:skia',
'../testing/gmock.gyp:gmock', '../testing/gmock.gyp:gmock',
'../testing/gtest.gyp:gtest', '../testing/gtest.gyp:gtest',
......
// Copyright 2013 The Chromium Authors. All rights reserved. // Copyright 2014 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be // Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file. // found in the LICENSE file.
......
...@@ -29,3 +29,37 @@ TestConfig.prototype.loadQueryParams = function() { ...@@ -29,3 +29,37 @@ TestConfig.prototype.loadQueryParams = function() {
this.usePrefixedEME = this.usePrefixedEME =
this.usePrefixedEME == '1' || this.usePrefixedEME == 'true'; this.usePrefixedEME == '1' || this.usePrefixedEME == 'true';
}; };
TestConfig.updateDocument = function() {
this.loadQueryParams();
Utils.addOptions(KEYSYSTEM_ELEMENT_ID, KEY_SYSTEMS);
Utils.addOptions(MEDIA_TYPE_ELEMENT_ID, MEDIA_TYPES);
Utils.addOptions(USE_PREFIXED_EME_ID, EME_VERSIONS_OPTIONS,
EME_DISABLED_OPTIONS);
document.getElementById(MEDIA_FILE_ELEMENT_ID).value =
this.mediaFile || DEFAULT_MEDIA_FILE;
document.getElementById(LICENSE_SERVER_ELEMENT_ID).value =
this.licenseServerURL || DEFAULT_LICENSE_SERVER;
if (this.keySystem)
Utils.ensureOptionInList(KEYSYSTEM_ELEMENT_ID, this.keySystem);
if (this.mediaType)
Utils.ensureOptionInList(MEDIA_TYPE_ELEMENT_ID, this.mediaType);
document.getElementById(USE_MSE_ELEMENT_ID).value = this.useMSE;
if (this.usePrefixedEME)
document.getElementById(USE_PREFIXED_EME_ID).value = EME_PREFIXED_VERSION;
};
TestConfig.init = function() {
// Reload test configuration from document.
this.mediaFile = document.getElementById(MEDIA_FILE_ELEMENT_ID).value;
this.keySystem = document.getElementById(KEYSYSTEM_ELEMENT_ID).value;
this.mediaType = document.getElementById(MEDIA_TYPE_ELEMENT_ID).value;
this.useMSE = document.getElementById(USE_MSE_ELEMENT_ID).value == 'true';
this.usePrefixedEME = document.getElementById(USE_PREFIXED_EME_ID).value ==
EME_PREFIXED_VERSION;
this.licenseServerURL =
document.getElementById(LICENSE_SERVER_ELEMENT_ID).value;
};
...@@ -5,8 +5,7 @@ ...@@ -5,8 +5,7 @@
</head> </head>
<body onload="runTest();"> <body onload="runTest();">
<video controls></video> <video controls></video>
<script src="media_utils.js" type="text/javascript"></script> <script src='eme_player_js/app_loader.js' type='text/javascript'></script>
<script src="media_source_utils.js" type="text/javascript"></script>
<script type="text/javascript"> <script type="text/javascript">
var video = document.querySelector('video'); var video = document.querySelector('video');
...@@ -16,18 +15,22 @@ ...@@ -16,18 +15,22 @@
} }
function onSeeked() { function onSeeked() {
video.removeEventListener('ended', failTest); video.removeEventListener('ended', Utils.failTest);
installTitleEventHandler(video, 'ended'); Utils.installTitleEventHandler(video, 'ended');
} }
// The test completes after media starts playing, seeks to 0.9 of // The test completes after media starts playing, seeks to 0.9 of
// duration and fires the ended event. // duration and fires the ended event.
// The test stops when an error or ended event fire unexpectedly. // The test stops when an error or ended event fire unexpectedly.
function runTest() { function runTest() {
loadMediaFromURL(video); var testConfig = new TestConfig();
video.addEventListener('ended', failTest); testConfig.loadQueryParams();
Utils.installTitleEventHandler(video, 'error');
video.addEventListener('ended', Utils.failTest);
video.addEventListener('seeked', onSeeked); video.addEventListener('seeked', onSeeked);
video.addEventListener('timeupdate', onTimeUpdate); video.addEventListener('timeupdate', onTimeUpdate);
var source = MediaSourceUtils.loadMediaSourceFromTestConfig(testConfig);
video.src = window.URL.createObjectURL(source);
video.play(); video.play();
} }
</script> </script>
......
...@@ -8,7 +8,6 @@ ...@@ -8,7 +8,6 @@
<script type="text/javascript"> <script type="text/javascript">
var testConfig = new TestConfig(); var testConfig = new TestConfig();
testConfig.loadQueryParams(); testConfig.loadQueryParams();
testConfig.useMSE = '1';
var runEncrypted = testConfig.runEncrypted == 1; var runEncrypted = testConfig.runEncrypted == 1;
var video = document.querySelector('video'); var video = document.querySelector('video');
...@@ -17,8 +16,8 @@ ...@@ -17,8 +16,8 @@
var MEDIA_1 = 'bear-320x240.webm'; var MEDIA_1 = 'bear-320x240.webm';
var MEDIA_2 = 'bear-640x360.webm'; var MEDIA_2 = 'bear-640x360.webm';
if (runEncrypted) { if (runEncrypted) {
MEDIA_1 = 'bear-320x240-av-enc_av.webm'; MEDIA_1 = 'bear-320x240-av_enc-av.webm';
MEDIA_2 = 'bear-640x360-av-enc_av.webm'; MEDIA_2 = 'bear-640x360-av_enc-av.webm';
} }
var MEDIA_1_WIDTH = 320; var MEDIA_1_WIDTH = 320;
......
...@@ -3,7 +3,7 @@ ...@@ -3,7 +3,7 @@
<video controls="" name="video"> <video controls="" name="video">
<!-- This test doesn't play the video, so any file will do <!-- This test doesn't play the video, so any file will do
as long as it can be loaded. --> as long as it can be loaded. -->
<source src="bear-320x240-av-enc_a.webm" type="video/webm"> <source src="bear-320x240-av_enc-a.webm" type="video/webm">
</video> </video>
<script type="text/javascript"> <script type="text/javascript">
function testKeySystemInstantiation(keySystem) { function testKeySystemInstantiation(keySystem) {
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment