Add http based media browser tests.

In response to the recent media failure (http://crbug.com/133808) we need
tests which actually run over http and request enough data to trigger the
more complex behaviors of our http loader.

In this CL I've modified all the existing tests to wait for playthrough
over both file:// and http:// protocols.  Additionally I've checked in a
large (~4.2MB) test file (with nsylvain's approval) for triggering the
buffering issue in the bug mentioned above.

BUG=134034
TEST=These tests. Eventually try bots.


Review URL: https://chromiumcodereview.appspot.com/10647007

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@150208 0039d316-1c4b-4281-b951-d872f2087c98
parent f42ad8a2
...@@ -3,119 +3,156 @@ ...@@ -3,119 +3,156 @@
// found in the LICENSE file. // found in the LICENSE file.
#include "base/basictypes.h" #include "base/basictypes.h"
#include "base/command_line.h"
#include "base/string16.h" #include "base/string16.h"
#include "base/stringprintf.h" #include "base/stringprintf.h"
#include "base/string_util.h" #include "base/string_util.h"
#include "base/utf_string_conversions.h" #include "base/utf_string_conversions.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 "content/shell/shell.h" #include "content/shell/shell.h"
#include "content/test/layout_browsertest.h" #include "content/test/layout_browsertest.h"
#include "content/test/content_browser_test_utils.h" #include "content/test/content_browser_test_utils.h"
#include "googleurl/src/gurl.h" #include "googleurl/src/gurl.h"
class MediaTest : public content::ContentBrowserTest { // Tests playback and seeking of an audio or video file over file or http based
// on a test parameter. Test starts with playback, then, after X seconds or the
// ended event fires, seeks near end of file; see player.html for details. The
// test completes when either the last 'ended' or an 'error' event fires.
class MediaTest
: public testing::WithParamInterface<bool>,
public content::ContentBrowserTest {
public:
// Play specified audio over http:// or file:// depending on |http| setting.
void PlayAudio(const char* media_file, bool http) {
ASSERT_NO_FATAL_FAILURE(PlayMedia("audio", media_file, http));
}
// Play specified video over http:// or file:// depending on |http| setting.
void PlayVideo(const char* media_file, bool http) {
ASSERT_NO_FATAL_FAILURE(PlayMedia("video", media_file, http));
}
protected: protected:
GURL GetTestURL(const char* tag, const char* media_file) { virtual void SetUpCommandLine(CommandLine* command_line) OVERRIDE {
// TODO(dalecurtis): Not all Buildbots have viable audio devices, so disable
// audio to prevent tests from hanging; e.g., a device which is hardware
// muted. See http://crbug.com/120749
command_line->AppendSwitch(switches::kDisableAudio);
}
private:
GURL GetTestURL(const char* tag, const char* media_file, bool http) {
if (http) {
return test_server()->GetURL(
base::StringPrintf("files/media/player.html?%s=%s", tag, media_file));
}
FilePath test_file_path = content::GetTestFilePath("media", "player.html"); FilePath test_file_path = content::GetTestFilePath("media", "player.html");
std::string query = base::StringPrintf("%s=%s", tag, media_file); std::string query = base::StringPrintf("%s=%s", tag, media_file);
return content::GetFileUrlWithQuery(test_file_path, query); return content::GetFileUrlWithQuery(test_file_path, query);
} }
void PlayMedia(const char* tag, const char* media_file) { void PlayMedia(const char* tag, const char* media_file, bool http) {
GURL player_gurl = GetTestURL(tag, media_file); if (http)
ASSERT_TRUE(test_server()->Start());
GURL player_gurl = GetTestURL(tag, media_file, http);
// Allow the media file to be loaded. // Allow the media file to be loaded.
const string16 kPlaying = ASCIIToUTF16("PLAYING"); const string16 kEnded = ASCIIToUTF16("ENDED");
const string16 kFailed = ASCIIToUTF16("FAILED");
const string16 kError = ASCIIToUTF16("ERROR"); const string16 kError = ASCIIToUTF16("ERROR");
content::TitleWatcher title_watcher(shell()->web_contents(), kPlaying); const string16 kFailed = ASCIIToUTF16("FAILED");
content::TitleWatcher title_watcher(shell()->web_contents(), kEnded);
title_watcher.AlsoWaitForTitle(kFailed); title_watcher.AlsoWaitForTitle(kFailed);
title_watcher.AlsoWaitForTitle(kError); title_watcher.AlsoWaitForTitle(kError);
content::NavigateToURL(shell(), player_gurl); content::NavigateToURL(shell(), player_gurl);
string16 final_title = title_watcher.WaitAndGetTitle(); string16 final_title = title_watcher.WaitAndGetTitle();
EXPECT_EQ(kPlaying, final_title); EXPECT_EQ(kEnded, final_title);
}
void PlayAudio(const char* url) {
PlayMedia("audio", url);
}
void PlayVideo(const char* url) {
PlayMedia("video", url);
} }
}; };
IN_PROC_BROWSER_TEST_F(MediaTest, VideoBearTheora) { IN_PROC_BROWSER_TEST_P(MediaTest, VideoBearTheora) {
PlayVideo("bear.ogv"); PlayVideo("bear.ogv", GetParam());
} }
IN_PROC_BROWSER_TEST_F(MediaTest, VideoBearSilentTheora) { IN_PROC_BROWSER_TEST_P(MediaTest, VideoBearSilentTheora) {
PlayVideo("bear_silent.ogv"); PlayVideo("bear_silent.ogv", GetParam());
} }
IN_PROC_BROWSER_TEST_F(MediaTest, VideoBearWebm) { IN_PROC_BROWSER_TEST_P(MediaTest, VideoBearWebm) {
PlayVideo("bear.webm"); PlayVideo("bear.webm", GetParam());
} }
IN_PROC_BROWSER_TEST_F(MediaTest, VideoBearSilentWebm) { IN_PROC_BROWSER_TEST_P(MediaTest, VideoBearSilentWebm) {
PlayVideo("bear_silent.webm"); PlayVideo("bear_silent.webm", GetParam());
} }
#if defined(GOOGLE_CHROME_BUILD) || defined(USE_PROPRIETARY_CODECS) #if defined(GOOGLE_CHROME_BUILD) || defined(USE_PROPRIETARY_CODECS)
IN_PROC_BROWSER_TEST_F(MediaTest, VideoBearMp4) { IN_PROC_BROWSER_TEST_P(MediaTest, VideoBearMp4) {
PlayVideo("bear.mp4"); PlayVideo("bear.mp4", GetParam());
}
IN_PROC_BROWSER_TEST_P(MediaTest, VideoBearSilentMp4) {
PlayVideo("bear_silent.mp4", GetParam());
} }
IN_PROC_BROWSER_TEST_F(MediaTest, VideoBearSilentMp4) { // While we support the big endian (be) PCM codecs on Chromium, Quicktime seems
PlayVideo("bear_silent.mp4"); // to be the only creator of this format and only for .mov files.
// TODO(dalecurtis/ihf): Find or create some .wav test cases for "be" format.
IN_PROC_BROWSER_TEST_P(MediaTest, VideoBearMovPcmS16be) {
PlayVideo("bear_pcm_s16be.mov", GetParam());
}
IN_PROC_BROWSER_TEST_P(MediaTest, VideoBearMovPcmS24be) {
PlayVideo("bear_pcm_s24be.mov", GetParam());
} }
#endif #endif
#if defined(OS_CHROMEOS) #if defined(OS_CHROMEOS)
#if defined(GOOGLE_CHROME_BUILD) || defined(USE_PROPRIETARY_CODECS) #if defined(GOOGLE_CHROME_BUILD) || defined(USE_PROPRIETARY_CODECS)
IN_PROC_BROWSER_TEST_F(MediaTest, VideoBearAviMp3Mpeg4) { IN_PROC_BROWSER_TEST_P(MediaTest, VideoBearAviMp3Mpeg4) {
PlayVideo("bear_mpeg4_mp3.avi"); PlayVideo("bear_mpeg4_mp3.avi", GetParam());
} }
IN_PROC_BROWSER_TEST_F(MediaTest, VideoBearAviMp3Divx) { IN_PROC_BROWSER_TEST_P(MediaTest, VideoBearAviMp3Divx) {
PlayVideo("bear_divx_mp3.avi"); PlayVideo("bear_divx_mp3.avi", GetParam());
} }
IN_PROC_BROWSER_TEST_F(MediaTest, VideoBear3gpAacH264) { IN_PROC_BROWSER_TEST_P(MediaTest, VideoBear3gpAacH264) {
PlayVideo("bear_h264_aac.3gp"); PlayVideo("bear_h264_aac.3gp", GetParam());
} }
IN_PROC_BROWSER_TEST_F(MediaTest, VideoBear3gpAmrnbMpeg4) { IN_PROC_BROWSER_TEST_P(MediaTest, VideoBear3gpAmrnbMpeg4) {
PlayVideo("bear_mpeg4_amrnb.3gp"); PlayVideo("bear_mpeg4_amrnb.3gp", GetParam());
} }
IN_PROC_BROWSER_TEST_F(MediaTest, VideoBearWavGsmms) { IN_PROC_BROWSER_TEST_F(MediaTest, VideoBearWavGsmms) {
PlayAudio("bear_gsm_ms.wav"); PlayAudio("bear_gsm_ms.wav", GetParam());
} }
IN_PROC_BROWSER_TEST_F(MediaTest, VideoBearWavMulaw) { IN_PROC_BROWSER_TEST_P(MediaTest, VideoBearWavMulaw) {
PlayAudio("bear_mulaw.wav"); PlayAudio("bear_mulaw.wav", GetParam());
} }
IN_PROC_BROWSER_TEST_F(MediaTest, VideoBearMovPcmS16be) { IN_PROC_BROWSER_TEST_P(MediaTest, VideoBearFlac) {
PlayVideo("bear_pcm_s16be.mov"); PlayAudio("bear.flac", GetParam());
} }
#endif
#endif
IN_PROC_BROWSER_TEST_F(MediaTest, VideoBearMovPcmS24be) { IN_PROC_BROWSER_TEST_P(MediaTest, VideoBearWavPcm) {
PlayVideo("bear_pcm_s24be.mov"); PlayAudio("bear_pcm.wav", GetParam());
} }
IN_PROC_BROWSER_TEST_F(MediaTest, VideoBearFlac) { IN_PROC_BROWSER_TEST_P(MediaTest, VideoTulipWebm) {
PlayAudio("bear.flac"); PlayVideo("tulip2.webm", GetParam());
} }
#endif
#endif
IN_PROC_BROWSER_TEST_F(MediaTest, VideoBearWavPcm) { INSTANTIATE_TEST_CASE_P(File, MediaTest, ::testing::Values(false));
PlayAudio("bear_pcm.wav"); INSTANTIATE_TEST_CASE_P(Http, MediaTest, ::testing::Values(true));
}
class MediaLayoutTest : public InProcessBrowserLayoutTest { class MediaLayoutTest : public InProcessBrowserLayoutTest {
protected: protected:
...@@ -124,6 +161,13 @@ class MediaLayoutTest : public InProcessBrowserLayoutTest { ...@@ -124,6 +161,13 @@ class MediaLayoutTest : public InProcessBrowserLayoutTest {
} }
virtual ~MediaLayoutTest() {} virtual ~MediaLayoutTest() {}
virtual void SetUpCommandLine(CommandLine* command_line) OVERRIDE {
// TODO(dalecurtis): Not all Buildbots have viable audio devices, so disable
// audio to prevent tests from hanging; e.g., a device which is hardware
// muted. See http://crbug.com/120749
command_line->AppendSwitch(switches::kDisableAudio);
}
virtual void SetUpInProcessBrowserTestFixture() OVERRIDE { virtual void SetUpInProcessBrowserTestFixture() OVERRIDE {
InProcessBrowserLayoutTest::SetUpInProcessBrowserTestFixture(); InProcessBrowserLayoutTest::SetUpInProcessBrowserTestFixture();
AddResourceForLayoutTest(FilePath().AppendASCII("media"), AddResourceForLayoutTest(FilePath().AppendASCII("media"),
...@@ -149,10 +193,9 @@ IN_PROC_BROWSER_TEST_F(MediaLayoutTest, VideoAutoplayTest) { ...@@ -149,10 +193,9 @@ IN_PROC_BROWSER_TEST_F(MediaLayoutTest, VideoAutoplayTest) {
RunLayoutTest("video-autoplay.html"); RunLayoutTest("video-autoplay.html");
} }
// TODO(dalecurtis): Disabled because loop is flaky. http://crbug.com/134021 IN_PROC_BROWSER_TEST_F(MediaLayoutTest, VideoLoopTest) {
// IN_PROC_BROWSER_TEST_F(MediaLayoutTest, VideoLoopTest) { RunLayoutTest("video-loop.html");
// RunLayoutTest("video-loop.html"); }
// }
IN_PROC_BROWSER_TEST_F(MediaLayoutTest, VideoNoAutoplayTest) { IN_PROC_BROWSER_TEST_F(MediaLayoutTest, VideoNoAutoplayTest) {
RunLayoutTest("video-no-autoplay.html"); RunLayoutTest("video-no-autoplay.html");
......
...@@ -30,7 +30,7 @@ CONTENT_EXPORT extern const char kDisableAcceleratedPlugins[]; ...@@ -30,7 +30,7 @@ CONTENT_EXPORT extern const char kDisableAcceleratedPlugins[];
CONTENT_EXPORT extern const char kDisableAcceleratedVideo[]; CONTENT_EXPORT extern const char kDisableAcceleratedVideo[];
CONTENT_EXPORT extern const char kDisableAltWinstation[]; CONTENT_EXPORT extern const char kDisableAltWinstation[];
CONTENT_EXPORT extern const char kDisableApplicationCache[]; CONTENT_EXPORT extern const char kDisableApplicationCache[];
extern const char kDisableAudio[]; CONTENT_EXPORT extern const char kDisableAudio[];
extern const char kDisableBackingStoreLimit[]; extern const char kDisableBackingStoreLimit[];
CONTENT_EXPORT extern const char kDisableDatabases[]; CONTENT_EXPORT extern const char kDisableDatabases[];
extern const char kDisableDataTransferItems[]; extern const char kDisableDataTransferItems[];
......
<html> <html>
<body> <body onload="RunTest();">
<div id="player_container"></div> <div id="player_container"></div>
<script> </body>
var player = null;
function InstallEventHandler(event, action) { <script type="text/javascript">
player.addEventListener(event, function(e) { // <audio> or <video> player element.
eval(action); var player;
// Listen for |event| from |element|, set document.title = |event| upon event.
function InstallTitleEventHandler(element, event) {
element.addEventListener(event, function(e) {
document.title = event.toUpperCase();
}, false); }, false);
} }
// Parse the location and load the media file accordingly. function Failed() {
var url = window.location.href;
var url_parts = url.split('?');
// Make sure the URL is of the form "player.html?query".
var ok = false;
if (url_parts.length > 1) {
var query = url_parts[1];
var query_parts = query.split('=');
if (query_parts.length == 2) {
var tag = query_parts[0];
var media_url = query_parts[1];
if (tag == 'audio' || tag == 'video') {
ok = true;
var container = document.getElementById('player_container');
container.innerHTML = '<' + tag + ' controls id="player"></' + tag + '>';
player = document.getElementById('player');
// Install event handlers.
InstallEventHandler('error', 'document.title = "ERROR"');
InstallEventHandler('playing', 'document.title = "PLAYING"');
// Starts the player.
player.src = media_url;
player.play();
}
}
}
if (!ok) {
document.title = 'FAILED'; document.title = 'FAILED';
return false;
}
function SeekTestStep(e) {
player.removeEventListener('ended', SeekTestStep, false);
// Test completes on the next ended event.
InstallTitleEventHandler(player, 'ended');
player.currentTime = 0.9 * player.duration;
player.play();
}
function SeekTestTimeoutSetup() {
if (player.currentTime < 2)
return;
player.removeEventListener('timeupdate', SeekTestTimeoutSetup, false);
SeekTestStep();
}
// Uses URL query parameters to create an audio or video element using a given
// source. URL must be of the form "player.html?[tag]=[media_url]". Plays the
// media and waits for X seconds of playback or the ended event, at which point
// the test seeks near the end of the file and resumes playback. Test completes
// when the second ended event occurs or an error event occurs at any time.
function RunTest() {
var url_parts = window.location.href.split('?');
if (url_parts.length != 2)
return Failed();
var query_parts = url_parts[1].split('=');
if (query_parts.length != 2)
return Failed();
var tag = query_parts[0];
var media_url = query_parts[1];
if (tag != 'audio' && tag != 'video')
return Failed();
// Create player and insert into DOM.
player = document.createElement(tag);
player.controls = true;
document.getElementById('player_container').appendChild(player);
// Transition to the seek test after X seconds of playback or when the ended
// event occurs, whichever happens first.
player.addEventListener('ended', SeekTestStep, false);
player.addEventListener('timeupdate', SeekTestTimeoutSetup, false);
// Ensure we percolate up any error events.
InstallTitleEventHandler(player, 'error');
// Starts the player.
player.src = media_url;
player.play();
} }
</script> </script>
</body>
</html> </html>
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