Android Browser Compositor: Add ScheduleComposite() callback.
[chromium-blink-merge.git] / content / browser / media_browsertest.cc
blob20c1a5727fe5be2c415ab933a3eac6c1f026a7e6
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #include "base/basictypes.h"
6 #include "base/command_line.h"
7 #include "base/string16.h"
8 #include "base/stringprintf.h"
9 #include "base/string_util.h"
10 #include "base/utf_string_conversions.h"
11 #include "content/public/common/content_switches.h"
12 #include "content/public/test/browser_test_utils.h"
13 #include "content/shell/shell.h"
14 #include "content/test/layout_browsertest.h"
15 #include "content/test/content_browser_test_utils.h"
16 #include "googleurl/src/gurl.h"
18 // Tests playback and seeking of an audio or video file over file or http based
19 // on a test parameter. Test starts with playback, then, after X seconds or the
20 // ended event fires, seeks near end of file; see player.html for details. The
21 // test completes when either the last 'ended' or an 'error' event fires.
22 class MediaTest
23 : public testing::WithParamInterface<bool>,
24 public content::ContentBrowserTest {
25 public:
26 // Play specified audio over http:// or file:// depending on |http| setting.
27 void PlayAudio(const char* media_file, bool http) {
28 ASSERT_NO_FATAL_FAILURE(PlayMedia("audio", media_file, http));
31 // Play specified video over http:// or file:// depending on |http| setting.
32 void PlayVideo(const char* media_file, bool http) {
33 ASSERT_NO_FATAL_FAILURE(PlayMedia("video", media_file, http));
36 protected:
37 virtual void SetUpCommandLine(CommandLine* command_line) OVERRIDE {
38 // TODO(dalecurtis): Not all Buildbots have viable audio devices, so disable
39 // audio to prevent tests from hanging; e.g., a device which is hardware
40 // muted. See http://crbug.com/120749
41 command_line->AppendSwitch(switches::kDisableAudio);
44 private:
45 GURL GetTestURL(const char* tag, const char* media_file, bool http) {
46 if (http) {
47 return test_server()->GetURL(
48 base::StringPrintf("files/media/player.html?%s=%s", tag, media_file));
51 FilePath test_file_path = content::GetTestFilePath("media", "player.html");
52 std::string query = base::StringPrintf("%s=%s", tag, media_file);
53 return content::GetFileUrlWithQuery(test_file_path, query);
56 void PlayMedia(const char* tag, const char* media_file, bool http) {
57 if (http)
58 ASSERT_TRUE(test_server()->Start());
60 GURL player_gurl = GetTestURL(tag, media_file, http);
62 // Allow the media file to be loaded.
63 const string16 kEnded = ASCIIToUTF16("ENDED");
64 const string16 kError = ASCIIToUTF16("ERROR");
65 const string16 kFailed = ASCIIToUTF16("FAILED");
66 content::TitleWatcher title_watcher(shell()->web_contents(), kEnded);
67 title_watcher.AlsoWaitForTitle(kFailed);
68 title_watcher.AlsoWaitForTitle(kError);
70 content::NavigateToURL(shell(), player_gurl);
72 string16 final_title = title_watcher.WaitAndGetTitle();
73 EXPECT_EQ(kEnded, final_title);
77 IN_PROC_BROWSER_TEST_P(MediaTest, VideoBearTheora) {
78 PlayVideo("bear.ogv", GetParam());
81 IN_PROC_BROWSER_TEST_P(MediaTest, VideoBearSilentTheora) {
82 PlayVideo("bear_silent.ogv", GetParam());
85 IN_PROC_BROWSER_TEST_P(MediaTest, VideoBearWebm) {
86 PlayVideo("bear.webm", GetParam());
89 IN_PROC_BROWSER_TEST_P(MediaTest, VideoBearSilentWebm) {
90 PlayVideo("bear_silent.webm", GetParam());
93 #if defined(GOOGLE_CHROME_BUILD) || defined(USE_PROPRIETARY_CODECS)
94 IN_PROC_BROWSER_TEST_P(MediaTest, VideoBearMp4) {
95 PlayVideo("bear.mp4", GetParam());
98 IN_PROC_BROWSER_TEST_P(MediaTest, VideoBearSilentMp4) {
99 PlayVideo("bear_silent.mp4", GetParam());
102 // While we support the big endian (be) PCM codecs on Chromium, Quicktime seems
103 // to be the only creator of this format and only for .mov files.
104 // TODO(dalecurtis/ihf): Find or create some .wav test cases for "be" format.
105 IN_PROC_BROWSER_TEST_P(MediaTest, VideoBearMovPcmS16be) {
106 PlayVideo("bear_pcm_s16be.mov", GetParam());
109 IN_PROC_BROWSER_TEST_P(MediaTest, VideoBearMovPcmS24be) {
110 PlayVideo("bear_pcm_s24be.mov", GetParam());
112 #endif
114 #if defined(OS_CHROMEOS)
115 #if defined(GOOGLE_CHROME_BUILD) || defined(USE_PROPRIETARY_CODECS)
116 IN_PROC_BROWSER_TEST_P(MediaTest, VideoBearAviMp3Mpeg4) {
117 PlayVideo("bear_mpeg4_mp3.avi", GetParam());
120 IN_PROC_BROWSER_TEST_P(MediaTest, VideoBearAviMp3Divx) {
121 PlayVideo("bear_divx_mp3.avi", GetParam());
124 IN_PROC_BROWSER_TEST_P(MediaTest, VideoBear3gpAacH264) {
125 PlayVideo("bear_h264_aac.3gp", GetParam());
128 IN_PROC_BROWSER_TEST_P(MediaTest, VideoBear3gpAmrnbMpeg4) {
129 PlayVideo("bear_mpeg4_amrnb.3gp", GetParam());
132 IN_PROC_BROWSER_TEST_P(MediaTest, VideoBearWavGsmms) {
133 PlayAudio("bear_gsm_ms.wav", GetParam());
136 IN_PROC_BROWSER_TEST_P(MediaTest, VideoBearWavMulaw) {
137 PlayAudio("bear_mulaw.wav", GetParam());
140 IN_PROC_BROWSER_TEST_P(MediaTest, VideoBearFlac) {
141 PlayAudio("bear.flac", GetParam());
143 #endif
144 #endif
146 IN_PROC_BROWSER_TEST_P(MediaTest, VideoBearWavPcm) {
147 PlayAudio("bear_pcm.wav", GetParam());
150 #if defined(OS_MACOSX)
151 // TODO(dalecurtis): Flaky on Mac 10.6. http://crbug.com/142896
152 IN_PROC_BROWSER_TEST_P(MediaTest, FLAKY_VideoTulipWebm) {
153 PlayVideo("tulip2.webm", GetParam());
155 #else
156 IN_PROC_BROWSER_TEST_P(MediaTest, VideoTulipWebm) {
157 PlayVideo("tulip2.webm", GetParam());
159 #endif
161 INSTANTIATE_TEST_CASE_P(File, MediaTest, ::testing::Values(false));
162 INSTANTIATE_TEST_CASE_P(Http, MediaTest, ::testing::Values(true));
164 class MediaLayoutTest : public InProcessBrowserLayoutTest {
165 protected:
166 MediaLayoutTest() : InProcessBrowserLayoutTest(
167 FilePath(), FilePath().AppendASCII("media")) {
169 virtual ~MediaLayoutTest() {}
171 virtual void SetUpCommandLine(CommandLine* command_line) OVERRIDE {
172 InProcessBrowserLayoutTest::SetUpCommandLine(command_line);
173 // TODO(dalecurtis): Not all Buildbots have viable audio devices, so disable
174 // audio to prevent tests from hanging; e.g., a device which is hardware
175 // muted. See http://crbug.com/120749
176 command_line->AppendSwitch(switches::kDisableAudio);
180 // Each browser test can only correspond to a single layout test, otherwise the
181 // 45 second timeout per test is not long enough for N tests on debug/asan/etc
182 // builds.
184 IN_PROC_BROWSER_TEST_F(MediaLayoutTest, VideoAutoplayTest) {
185 RunLayoutTest("video-autoplay.html");
188 IN_PROC_BROWSER_TEST_F(MediaLayoutTest, VideoLoopTest) {
189 RunLayoutTest("video-loop.html");
192 IN_PROC_BROWSER_TEST_F(MediaLayoutTest, VideoNoAutoplayTest) {
193 RunLayoutTest("video-no-autoplay.html");