Commit a1f1a940 authored by shadi@google.com's avatar shadi@google.com

Revert 282795 "Have media content and chrome browser tests load ..."

It broke browser tests. Probably need to update isolate files to fix it...

> Have media content and chrome browser tests load data from media/test/data
> 
> With media files copied over to media/test/data, this CL makes media related content browser tests and chrome browser tests load test data from one location. 
> 
> The location is common with media unit tests data forder;  managed in one place in media/base/test_data_util.h 
> 
> BUG=379314
> 
> Review URL: https://codereview.chromium.org/357413002

TBR=shadi@chromium.org

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

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@282812 0039d316-1c4b-4281-b951-d872f2087c98
parent e2ec579c
......@@ -115,14 +115,12 @@ class EncryptedMediaTestBase : public MediaBrowserTest {
}
#endif // defined(WIDEVINE_CDM_AVAILABLE)
void RunEncryptedMediaTestPage(
const std::string& html_page,
const std::string& key_system,
const media::QueryParams& query_params,
const std::string& expected_title) {
media::QueryParams new_query_params = query_params;
StartLicenseServerIfNeeded(key_system, &new_query_params);
RunMediaTestPage(html_page, new_query_params, expected_title, true);
void RunEncryptedMediaTestPage(const std::string& html_page,
const std::string& key_system,
std::vector<StringPair>* query_params,
const std::string& expected_title) {
StartLicenseServerIfNeeded(key_system, query_params);
RunMediaTestPage(html_page, query_params, expected_title, true);
}
// Tests |html_page| using |media_file| (with |media_type|) and |key_system|.
......@@ -146,7 +144,7 @@ class EncryptedMediaTestBase : public MediaBrowserTest {
VLOG(0) << "Skipping test - MSE not supported.";
return;
}
media::QueryParams query_params;
std::vector<StringPair> query_params;
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("keySystem", key_system));
......@@ -158,7 +156,7 @@ class EncryptedMediaTestBase : public MediaBrowserTest {
query_params.push_back(std::make_pair("forceInvalidResponse", "1"));
if (!session_to_load.empty())
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);
}
......@@ -190,17 +188,16 @@ class EncryptedMediaTestBase : public MediaBrowserTest {
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,
media::QueryParams* query_params) {
std::vector<StringPair>* query_params) {
scoped_ptr<TestLicenseServerConfig> config = GetServerConfig(key_system);
if (!config)
return;
license_server_.reset(new TestLicenseServer(config.Pass()));
EXPECT_TRUE(license_server_->Start());
query_params->push_back(
std::make_pair("licenseServerURL", license_server_->GetServerURL()));
query_params->push_back(std::make_pair("licenseServerURL",
license_server_->GetServerURL()));
}
bool IsPlayBackPossible(const std::string& key_system) {
......@@ -315,7 +312,7 @@ class ECKEncryptedMediaTest : public EncryptedMediaTestBase {
// Since we do not test playback, arbitrarily choose a test file and source
// type.
RunEncryptedMediaTest(kDefaultEmePlayer,
"bear-a_enc-a.webm",
"bear-a-enc_a.webm",
kWebMAudioOnly,
key_system,
SRC,
......@@ -382,7 +379,7 @@ class EncryptedMediaTest
void RunInvalidResponseTest() {
RunEncryptedMediaTest(kDefaultEmePlayer,
"bear-320x240-av_enc-av.webm",
"bear-320x240-av-enc_av.webm",
kWebMAudioVideo,
CurrentKeySystem(),
CurrentSourceType(),
......@@ -394,7 +391,7 @@ class EncryptedMediaTest
void TestFrameSizeChange() {
RunEncryptedMediaTest("encrypted_frame_size_change.html",
"frame_size_change-av_enc-v.webm",
"frame_size_change-av-enc-v.webm",
kWebMAudioVideo,
CurrentKeySystem(),
CurrentSourceType(),
......@@ -406,14 +403,14 @@ class EncryptedMediaTest
void TestConfigChange() {
DCHECK(IsMSESupported());
media::QueryParams query_params;
std::vector<StringPair> query_params;
query_params.push_back(std::make_pair("keySystem", CurrentKeySystem()));
query_params.push_back(std::make_pair("runEncrypted", "1"));
if (CurrentEmeVersion() == PREFIXED)
query_params.push_back(std::make_pair("usePrefixedEME", "1"));
RunEncryptedMediaTestPage("mse_config_change.html",
CurrentKeySystem(),
query_params,
&query_params,
kEnded);
}
......@@ -491,7 +488,7 @@ INSTANTIATE_TEST_CASE_P(MSE_ExternalClearKeyDecryptOnly,
Combine(Values(kExternalClearKeyDecryptOnlyKeySystem),
Values(MSE),
Values(UNPREFIXED)));
#endif // defined(ENABLE_PEPPER_CDMS)
#endif // defined(ENABLE_PEPPER_CDMS)
#if defined(WIDEVINE_CDM_AVAILABLE)
// This test doesn't fully test playback with Widevine. So we only run Widevine
......@@ -514,27 +511,27 @@ INSTANTIATE_TEST_CASE_P(MSE_Widevine,
#endif // defined(WIDEVINE_CDM_AVAILABLE)
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) {
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) {
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) {
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) {
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) {
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) {
......@@ -590,7 +587,7 @@ IN_PROC_BROWSER_TEST_P(EncryptedMediaTest, Playback_AudioOnly_MP4) {
// The parent key system cannot be used in generateKeyRequest.
IN_PROC_BROWSER_TEST_F(WVEncryptedMediaTest, ParentThrowsException_Prefixed) {
RunEncryptedMediaTest(kDefaultEmePlayer,
"bear-a_enc-a.webm",
"bear-a-enc_a.webm",
kWebMAudioOnly,
"com.widevine",
MSE,
......@@ -604,7 +601,7 @@ IN_PROC_BROWSER_TEST_F(WVEncryptedMediaTest, ParentThrowsException_Prefixed) {
// The parent key system cannot be used when creating MediaKeys.
IN_PROC_BROWSER_TEST_F(WVEncryptedMediaTest, ParentThrowsException) {
RunEncryptedMediaTest(kDefaultEmePlayer,
"bear-a_enc-a.webm",
"bear-a-enc_a.webm",
kWebMAudioOnly,
"com.widevine",
MSE,
......@@ -643,7 +640,7 @@ IN_PROC_BROWSER_TEST_F(ECKEncryptedMediaTest, FileIOTest) {
IN_PROC_BROWSER_TEST_F(ECKEncryptedMediaTest, LoadLoadableSession) {
RunEncryptedMediaTest(kDefaultEmePlayer,
"bear-320x240-v_enc-v.webm",
"bear-320x240-v-enc_v.webm",
kWebMVideoOnly,
kExternalClearKeyKeySystem,
SRC,
......@@ -656,7 +653,7 @@ IN_PROC_BROWSER_TEST_F(ECKEncryptedMediaTest, LoadLoadableSession) {
IN_PROC_BROWSER_TEST_F(ECKEncryptedMediaTest, LoadUnknownSession) {
// TODO(xhwang): Add a specific error for this failure, e.g. kSessionNotFound.
RunEncryptedMediaTest(kDefaultEmePlayer,
"bear-320x240-v_enc-v.webm",
"bear-320x240-v-enc_v.webm",
kWebMVideoOnly,
kExternalClearKeyKeySystem,
SRC,
......
......@@ -17,7 +17,6 @@
#include "chrome/test/base/ui_test_utils.h"
#include "content/public/common/content_switches.h"
#include "content/public/test/browser_test_utils.h"
#include "media/base/test_data_util.h"
#include "url/gurl.h"
#include "widevine_cdm_version.h" // In SHARED_INTERMEDIATE_DIR.
......@@ -225,10 +224,9 @@ class EncryptedMediaIsTypeSupportedTest : public InProcessBrowserTest {
// Load the test page needed. IsConcreteSupportedKeySystem() needs some
// JavaScript and a video loaded in order to work.
if (!is_test_page_loaded_) {
scoped_ptr<net::SpawnedTestServer> http_test_server =
media::StartMediaHttpTestServer();
GURL gurl = http_test_server->GetURL(
"files/test_key_system_instantiation.html");
ASSERT_TRUE(test_server()->Start());
GURL gurl = test_server()->GetURL(
"files/media/test_key_system_instantiation.html");
ui_test_utils::NavigateToURL(browser(), gurl);
is_test_page_loaded_ = true;
}
......
......@@ -4,9 +4,12 @@
#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 "chrome/browser/ui/browser.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 "content/public/browser/navigation_controller.h"
#include "content/public/browser/navigation_entry.h"
......@@ -25,27 +28,37 @@ MediaBrowserTest::MediaBrowserTest() : ignore_plugin_crash_(false) {
MediaBrowserTest::~MediaBrowserTest() {
}
void MediaBrowserTest::RunMediaTestPage(const std::string& html_page,
const media::QueryParams& query_params,
const std::string& expected_title,
bool http) {
void MediaBrowserTest::RunMediaTestPage(
const std::string& html_page, std::vector<StringPair>* query_params,
const std::string& expected_title, bool http) {
GURL gurl;
std::string query = media::GetURLQueryString(query_params);
scoped_ptr<net::SpawnedTestServer> http_test_server;
std::string query = "";
if (query_params != NULL && !query_params->empty()) {
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) {
http_test_server = media::StartMediaHttpTestServer();
gurl = http_test_server->GetURL("files/" + html_page + "?" + query);
ASSERT_TRUE(test_server()->Start());
gurl = test_server()->GetURL("files/media/" + html_page + "?" + query);
} else {
gurl = content::GetFileUrlWithQuery(media::GetTestDataFilePath(html_page),
query);
base::FilePath test_file_path;
PathService::Get(chrome::DIR_TEST_DATA, &test_file_path);
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);
EXPECT_EQ(expected_title, final_title);
base::string16 final_title = RunTest(gurl, expected_title);
EXPECT_EQ(base::ASCIIToUTF16(expected_title), final_title);
}
std::string MediaBrowserTest::RunTest(const GURL& gurl,
const std::string& expected_title) {
DVLOG(0) << "Running test URL: " << gurl;
base::string16 MediaBrowserTest::RunTest(const GURL& gurl,
const std::string& expected_title) {
VLOG(0) << "Running test URL: " << gurl;
// Observe the web contents for plugin crashes.
Observe(browser()->tab_strip_model()->GetActiveWebContents());
content::TitleWatcher title_watcher(
......@@ -53,8 +66,8 @@ std::string MediaBrowserTest::RunTest(const GURL& gurl,
base::ASCIIToUTF16(expected_title));
AddWaitForTitles(&title_watcher);
ui_test_utils::NavigateToURL(browser(), gurl);
base::string16 result = title_watcher.WaitAndGetTitle();
return base::UTF16ToASCII(result);
return title_watcher.WaitAndGetTitle();
}
void MediaBrowserTest::AddWaitForTitles(content::TitleWatcher* title_watcher) {
......
......@@ -5,11 +5,11 @@
#ifndef CHROME_BROWSER_MEDIA_MEDIA_BROWSERTEST_H_
#define CHROME_BROWSER_MEDIA_MEDIA_BROWSERTEST_H_
#include <string>
#include <utility>
#include <vector>
#include "chrome/test/base/in_process_browser_test.h"
#include "content/public/browser/web_contents_observer.h"
#include "media/base/test_data_util.h"
namespace content {
class TitleWatcher;
......@@ -21,6 +21,8 @@ class TitleWatcher;
class MediaBrowserTest : public InProcessBrowserTest,
public content::WebContentsObserver {
protected:
typedef std::pair<std::string, std::string> StringPair;
// Common test results.
static const char kEnded[];
// TODO(xhwang): Report detailed errors, e.g. "ERROR-3".
......@@ -36,13 +38,12 @@ class MediaBrowserTest : public InProcessBrowserTest,
// page, otherwise a local file URL is loaded inside the content shell.
// It uses RunTest() to check for expected test output.
void RunMediaTestPage(const std::string& html_page,
const media::QueryParams& query_params,
const std::string& expected,
bool http);
std::vector<StringPair>* query_params,
const std::string& expected, bool http);
// Opens a URL and waits for the document title to match either one of the
// default strings or the expected string. Returns the matching title value.
std::string RunTest(const GURL& gurl, const std::string& expected);
// default strings or the expected string.
base::string16 RunTest(const GURL& gurl, const std::string& expected);
virtual void AddWaitForTitles(content::TitleWatcher* title_watcher);
......
// Copyright 2014 The Chromium Authors. All rights reserved.
// Copyright 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.
......
......@@ -29,37 +29,3 @@ TestConfig.prototype.loadQueryParams = function() {
this.usePrefixedEME =
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;
};
......@@ -8,6 +8,7 @@
<script type="text/javascript">
var testConfig = new TestConfig();
testConfig.loadQueryParams();
testConfig.useMSE = '1';
var runEncrypted = testConfig.runEncrypted == 1;
var video = document.querySelector('video');
......@@ -16,8 +17,8 @@
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';
MEDIA_1 = 'bear-320x240-av-enc_av.webm';
MEDIA_2 = 'bear-640x360-av-enc_av.webm';
}
var MEDIA_1_WIDTH = 320;
......
......@@ -3,7 +3,7 @@
<video controls="" name="video">
<!-- This test doesn't play the video, so any file will do
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>
<script type="text/javascript">
function testKeySystemInstantiation(keySystem) {
......
......@@ -3,6 +3,7 @@
// found in the LICENSE file.
#include "base/command_line.h"
#include "base/path_service.h"
#include "base/strings/utf_string_conversions.h"
#include "base/win/windows_version.h"
#include "content/browser/media/media_browsertest.h"
......@@ -25,8 +26,6 @@ const char kWebMAudioVideo[] = "video/webm; codecs=\"vorbis, vp8\"";
const char kEmeKeyError[] = "KEYERROR";
const char kEmeNotSupportedError[] = "NOTSUPPORTEDERROR";
const char kDefaultEmePlayer[] = "eme_player.html";
// The type of video src used to load media.
enum SrcType {
SRC,
......@@ -53,7 +52,7 @@ class EncryptedMediaTest : public content::MediaBrowserTest,
public testing::WithParamInterface<std::tr1::tuple<const char*, SrcType> > {
public:
// Can only be used in parameterized (*_P) tests.
const std::string CurrentKeySystem() {
const char* CurrentKeySystem() {
return std::tr1::get<0>(GetParam());
}
......@@ -62,15 +61,14 @@ class EncryptedMediaTest : public content::MediaBrowserTest,
return std::tr1::get<1>(GetParam());
}
void TestSimplePlayback(const std::string& encrypted_media,
const std::string& media_type) {
void TestSimplePlayback(const char* encrypted_media, const char* media_type) {
RunSimpleEncryptedMediaTest(
encrypted_media, media_type, CurrentKeySystem(), CurrentSourceType());
}
void TestFrameSizeChange() {
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);
}
......@@ -80,42 +78,38 @@ class EncryptedMediaTest : public content::MediaBrowserTest,
return;
}
media::QueryParams query_params;
query_params.push_back(std::make_pair("keySystem", CurrentKeySystem()));
query_params.push_back(std::make_pair("runEncrypted", "1"));
RunMediaTestPage("mse_config_change.html", query_params, kEnded, true);
std::vector<StringPair> query_params;
query_params.push_back(std::make_pair("keysystem", CurrentKeySystem()));
query_params.push_back(std::make_pair("runencrypted", "1"));
RunMediaTestPage("mse_config_change.html", &query_params, kEnded, true);
}
void RunEncryptedMediaTest(const std::string& html_page,
const std::string& media_file,
const std::string& media_type,
const std::string& key_system,
void RunEncryptedMediaTest(const char* html_page,
const char* media_file,
const char* media_type,
const char* key_system,
SrcType src_type,
const std::string& expectation) {
const char* expectation) {
if (src_type == MSE && !IsMSESupported()) {
VLOG(0) << "Skipping test - MSE not supported.";
return;
}
media::QueryParams query_params;
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("keySystem", key_system));
std::vector<StringPair> query_params;
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("keysystem", key_system));
if (src_type == MSE)
query_params.push_back(std::make_pair("useMSE", "1"));
RunMediaTestPage(html_page, query_params, expectation, true);
query_params.push_back(std::make_pair("usemse", "1"));
RunMediaTestPage(html_page, &query_params, expectation, true);
}
void RunSimpleEncryptedMediaTest(const std::string& media_file,
const std::string& media_type,
const std::string& key_system,
void RunSimpleEncryptedMediaTest(const char* media_file,
const char* media_type,
const char* key_system,
SrcType src_type) {
RunEncryptedMediaTest(kDefaultEmePlayer,
media_file,
media_type,
key_system,
src_type,
kEnded);
RunEncryptedMediaTest("encrypted_media_player.html", media_file,
media_type, key_system, src_type, kEnded);
}
protected:
......@@ -147,23 +141,23 @@ INSTANTIATE_TEST_CASE_P(MSE_ClearKey, EncryptedMediaTest,
Combine(Values(kClearKeyKeySystem), Values(MSE)));
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) {
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) {
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) {
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) {
TestSimplePlayback("bear-320x240-av_enc-v.webm", kWebMAudioVideo);
TestSimplePlayback("bear-320x240-av-enc_v.webm", kWebMAudioVideo);
}
IN_PROC_BROWSER_TEST_P(EncryptedMediaTest, ConfigChangeVideo) {
......@@ -180,11 +174,8 @@ IN_PROC_BROWSER_TEST_P(EncryptedMediaTest, FrameSizeChangeVideo) {
}
IN_PROC_BROWSER_TEST_F(EncryptedMediaTest, UnknownKeySystemThrowsException) {
RunEncryptedMediaTest(kDefaultEmePlayer,
"bear-a_enc-a.webm",
kWebMAudioOnly,
"com.example.foo",
MSE,
RunEncryptedMediaTest("encrypted_media_player.html", "bear-a-enc_a.webm",
kWebMAudioOnly, "com.example.foo", MSE,
kEmeNotSupportedError);
}
......
......@@ -4,8 +4,10 @@
#include "content/browser/media/media_browsertest.h"
#include "base/strings/stringprintf.h"
#include "base/strings/utf_string_conversions.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/content_browser_test_utils.h"
#include "content/shell/browser/shell.h"
......@@ -24,33 +26,39 @@ const char MediaBrowserTest::kEnded[] = "ENDED";
const char MediaBrowserTest::kError[] = "ERROR";
const char MediaBrowserTest::kFailed[] = "FAILED";
void MediaBrowserTest::RunMediaTestPage(const std::string& html_page,
const media::QueryParams& query_params,
const std::string& expected_title,
bool http) {
void MediaBrowserTest::RunMediaTestPage(
const char* html_page, std::vector<StringPair>* query_params,
const char* expected, bool http) {
GURL gurl;
std::string query = media::GetURLQueryString(query_params);
scoped_ptr<net::SpawnedTestServer> http_test_server;
std::string query = "";
if (query_params != NULL && !query_params->empty()) {
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) {
http_test_server = media::StartMediaHttpTestServer();
gurl = http_test_server->GetURL("files/" + html_page + "?" + query);
ASSERT_TRUE(test_server()->Start());
gurl = test_server()->GetURL(
base::StringPrintf("files/media/%s?%s", html_page, query.c_str()));
} else {
gurl = content::GetFileUrlWithQuery(media::GetTestDataFilePath(html_page),
query);
base::FilePath test_file_path = GetTestFilePath("media", html_page);
gurl = GetFileUrlWithQuery(test_file_path, query);
}
std::string final_title = RunTest(gurl, expected_title);
EXPECT_EQ(expected_title, final_title);
RunTest(gurl, expected);
}
std::string MediaBrowserTest::RunTest(const GURL& gurl,
const std::string& expected_title) {
VLOG(0) << "Running test URL: " << gurl;
TitleWatcher title_watcher(shell()->web_contents(),
base::ASCIIToUTF16(expected_title));
void MediaBrowserTest::RunTest(const GURL& gurl, const char* expected) {
const base::string16 expected_title = base::ASCIIToUTF16(expected);
DVLOG(1) << "Running test URL: " << gurl;
TitleWatcher title_watcher(shell()->web_contents(), expected_title);
AddWaitForTitles(&title_watcher);
NavigateToURL(shell(), gurl);
base::string16 result = title_watcher.WaitAndGetTitle();
return base::UTF16ToASCII(result);
base::string16 final_title = title_watcher.WaitAndGetTitle();
EXPECT_EQ(expected_title, final_title);
}
void MediaBrowserTest::AddWaitForTitles(content::TitleWatcher* title_watcher) {
......@@ -67,29 +75,25 @@ class MediaTest : public testing::WithParamInterface<bool>,
public MediaBrowserTest {
public:
// Play specified audio over http:// or file:// depending on |http| setting.
void PlayAudio(const std::string& media_file, bool http) {
void PlayAudio(const char* media_file, bool http) {
PlayMedia("audio", media_file, http);
}
// Play specified video over http:// or file:// depending on |http| setting.
void PlayVideo(const std::string& media_file, bool http) {
void PlayVideo(const char* media_file, bool http) {
PlayMedia("video", media_file, http);
}
// Run specified color format test with the expected result.
void RunColorFormatTest(const std::string& media_file,
const std::string& expected) {
base::FilePath test_file_path =
media::GetTestDataFilePath("blackwhite.html");
void RunColorFormatTest(const char* media_file, const char* expected) {
base::FilePath test_file_path = GetTestFilePath("media", "blackwhite.html");
RunTest(GetFileUrlWithQuery(test_file_path, media_file), expected);
}
void PlayMedia(const std::string& tag,
const std::string& media_file,
bool http) {
media::QueryParams query_params;
void PlayMedia(const char* tag, const char* media_file, bool http) {
std::vector<StringPair> query_params;
query_params.push_back(std::make_pair(tag, media_file));
RunMediaTestPage("player.html", query_params, kEnded, http);
RunMediaTestPage("player.html", &query_params, kEnded, http);
}
};
......@@ -136,7 +140,7 @@ IN_PROC_BROWSER_TEST_P(MediaTest, VideoBearMovPcmS16be) {
IN_PROC_BROWSER_TEST_P(MediaTest, VideoBearMovPcmS24be) {
PlayVideo("bear_pcm_s24be.mov", GetParam());
}
#endif // defined(USE_PROPRIETARY_CODECS)
#endif
#if defined(OS_CHROMEOS)
#if defined(USE_PROPRIETARY_CODECS)
......@@ -167,9 +171,8 @@ IN_PROC_BROWSER_TEST_P(MediaTest, VideoBearWavGsmms) {
IN_PROC_BROWSER_TEST_P(MediaTest, VideoBearFlac) {
PlayAudio("bear.flac", GetParam());
}
#endif // defined(USE_PROPRIETARY_CODECS)
#endif // defined(OS_CHROMEOS)
#endif
#endif
IN_PROC_BROWSER_TEST_P(MediaTest, VideoBearWavAlaw) {
PlayAudio("bear_alaw.wav", GetParam());
......@@ -206,19 +209,19 @@ INSTANTIATE_TEST_CASE_P(File, MediaTest, ::testing::Values(false));
INSTANTIATE_TEST_CASE_P(Http, MediaTest, ::testing::Values(true));
IN_PROC_BROWSER_TEST_F(MediaTest, MAYBE(Yuv420pTheora)) {
RunColorFormatTest("yuv420p.ogv", kEnded);
RunColorFormatTest("yuv420p.ogv", "ENDED");
}
IN_PROC_BROWSER_TEST_F(MediaTest, MAYBE(Yuv422pTheora)) {
RunColorFormatTest("yuv422p.ogv", kEnded);
RunColorFormatTest("yuv422p.ogv", "ENDED");
}
IN_PROC_BROWSER_TEST_F(MediaTest, MAYBE(Yuv444pTheora)) {
RunColorFormatTest("yuv444p.ogv", kEnded);
RunColorFormatTest("yuv444p.ogv", "ENDED");
}
IN_PROC_BROWSER_TEST_F(MediaTest, MAYBE(Yuv420pVp8)) {
RunColorFormatTest("yuv420p.webm", kEnded);
RunColorFormatTest("yuv420p.webm", "ENDED");
}
// TODO(johannkoenig): Reenable after landing libvpx roll
......@@ -229,24 +232,24 @@ IN_PROC_BROWSER_TEST_F(MediaTest, DISABLED_Yuv444pVp9) {
#if defined(USE_PROPRIETARY_CODECS)
IN_PROC_BROWSER_TEST_F(MediaTest, MAYBE(Yuv420pH264)) {
RunColorFormatTest("yuv420p.mp4", kEnded);
RunColorFormatTest("yuv420p.mp4", "ENDED");
}
IN_PROC_BROWSER_TEST_F(MediaTest, MAYBE(Yuvj420pH264)) {
RunColorFormatTest("yuvj420p.mp4", kEnded);
RunColorFormatTest("yuvj420p.mp4", "ENDED");
}
IN_PROC_BROWSER_TEST_F(MediaTest, MAYBE(Yuv422pH264)) {
RunColorFormatTest("yuv422p.mp4", kEnded);
RunColorFormatTest("yuv422p.mp4", "ENDED");
}
IN_PROC_BROWSER_TEST_F(MediaTest, MAYBE(Yuv444pH264)) {
RunColorFormatTest("yuv444p.mp4", kEnded);
RunColorFormatTest("yuv444p.mp4", "ENDED");
}
#if defined(OS_CHROMEOS)
IN_PROC_BROWSER_TEST_F(MediaTest, Yuv420pMpeg4) {
RunColorFormatTest("yuv420p.avi", kEnded);
RunColorFormatTest("yuv420p.avi", "ENDED");
}
#endif // defined(OS_CHROMEOS)
#endif // defined(USE_PROPRIETARY_CODECS)
......
......@@ -5,10 +5,10 @@
#ifndef CONTENT_BROWSER_MEDIA_MEDIA_BROWSERTEST_H_
#define CONTENT_BROWSER_MEDIA_MEDIA_BROWSERTEST_H_
#include <string>
#include <utility>
#include <vector>
#include "content/public/test/content_browser_test.h"
#include "media/base/test_data_util.h"
namespace content {
......@@ -19,6 +19,8 @@ class TitleWatcher;
// the test http server.
class MediaBrowserTest : public ContentBrowserTest {
public:
typedef std::pair<const char*, const char*> StringPair;
// Common test results.
static const char kEnded[];
static const char kError[];
......@@ -28,18 +30,17 @@ class MediaBrowserTest : public ContentBrowserTest {
// 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.
// It uses RunTest() to check for expected test output.
void RunMediaTestPage(const std::string& html_page,
const media::QueryParams& query_params,
const std::string& expected,
bool http);
void RunMediaTestPage(const char* html_page,
std::vector<StringPair>* query_params,
const char* expected, bool http);
// Opens a URL and waits for the document title to match either one of the
// default strings or the expected string. Returns the matching title value.
std::string RunTest(const GURL& gurl, const std::string& expected);
// default strings or the expected string.
void RunTest(const GURL& gurl, const char* expected);
virtual void AddWaitForTitles(content::TitleWatcher* title_watcher);
};
} // namespace content
} // namespace content
#endif // CONTENT_BROWSER_MEDIA_MEDIA_BROWSERTEST_H_
......@@ -32,18 +32,17 @@ static bool IsMSESupported() {
class MediaSourceTest : public content::MediaBrowserTest {
public:
void TestSimplePlayback(const std::string& media_file,
const std::string& media_type,
const std::string& expectation) {
void TestSimplePlayback(const char* media_file, const char* media_type,
const char* expectation) {
if (!IsMSESupported()) {
VLOG(0) << "Skipping test - MSE not supported.";
return;
}
media::QueryParams query_params;
query_params.push_back(std::make_pair("mediaFile", media_file));
query_params.push_back(std::make_pair("mediaType", media_type));
RunMediaTestPage("media_source_player.html", query_params, expectation,
std::vector<StringPair> query_params;
query_params.push_back(std::make_pair("mediafile", media_file));
query_params.push_back(std::make_pair("mediatype", media_type));
RunMediaTestPage("media_source_player.html", &query_params, expectation,
true);
}
......@@ -85,10 +84,7 @@ IN_PROC_BROWSER_TEST_F(MediaSourceTest, ConfigChangeVideo) {
VLOG(0) << "Skipping test - MSE not supported.";
return;
}
RunMediaTestPage("mse_config_change.html",
media::QueryParams(),
kEnded,
true);
RunMediaTestPage("mse_config_change.html", NULL, kEnded, true);
}
} // 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;
}
......@@ -5,7 +5,8 @@
</head>
<body onload="runTest();">
<video controls></video>
<script src='eme_player_js/app_loader.js' type='text/javascript'></script>
<script src="media_utils.js" type="text/javascript"></script>
<script src="media_source_utils.js" type="text/javascript"></script>
<script type="text/javascript">
var video = document.querySelector('video');
......@@ -15,22 +16,18 @@
}
function onSeeked() {
video.removeEventListener('ended', Utils.failTest);
Utils.installTitleEventHandler(video, 'ended');
video.removeEventListener('ended', failTest);
installTitleEventHandler(video, 'ended');
}
// The test completes after media starts playing, seeks to 0.9 of
// duration and fires the ended event.
// The test stops when an error or ended event fire unexpectedly.
function runTest() {
var testConfig = new TestConfig();
testConfig.loadQueryParams();
Utils.installTitleEventHandler(video, 'error');
video.addEventListener('ended', Utils.failTest);
loadMediaFromURL(video);
video.addEventListener('ended', failTest);
video.addEventListener('seeked', onSeeked);
video.addEventListener('timeupdate', onTimeUpdate);
var source = MediaSourceUtils.loadMediaSourceFromTestConfig(testConfig);
video.src = window.URL.createObjectURL(source);
video.play();
}
</script>
......
// 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 = [
"+gpu",
"+jni",
"+net/test",
"+third_party/ffmpeg",
"+third_party/libvpx",
"+third_party/libyuv",
......
......@@ -12,38 +12,14 @@
namespace media {
const base::FilePath::CharType kTestDataPath[] =
FILE_PATH_LITERAL("media/test/data");
base::FilePath GetTestDataFilePath(const std::string& name) {
base::FilePath 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;
}
scoped_ptr<net::SpawnedTestServer> StartMediaHttpTestServer() {
scoped_ptr<net::SpawnedTestServer> http_test_server;
http_test_server.reset(new net::SpawnedTestServer(
net::SpawnedTestServer::TYPE_HTTP,
net::SpawnedTestServer::kLocalhost,
GetTestDataPath()));
CHECK(http_test_server->Start());
return http_test_server.Pass();
return file_path.AppendASCII("media")
.AppendASCII("test")
.AppendASCII("data")
.AppendASCII(name);
}
scoped_refptr<DecoderBuffer> ReadTestDataFile(const std::string& name) {
......
......@@ -6,34 +6,19 @@
#define MEDIA_BASE_TEST_DATA_UTIL_H_
#include <string>
#include <utility>
#include <vector>
#include "base/basictypes.h"
#include "base/files/file_path.h"
#include "base/memory/ref_counted.h"
#include "base/memory/scoped_ptr.h"
#include "net/test/spawned_test_server/spawned_test_server.h"
namespace media {
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.
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
// a DecoderBuffer. Use DecoderBuffer vs DataBuffer to ensure no matter
// what a test does, it's safe to use FFmpeg methods.
......
......@@ -1349,7 +1349,6 @@
'media',
'shared_memory_support',
'../base/base.gyp:base',
'../net/net.gyp:net_test_support',
'../skia/skia.gyp:skia',
'../testing/gmock.gyp:gmock',
'../testing/gtest.gyp:gtest',
......
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