1 // Copyright (c) 2013 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 "content/browser/media/media_browsertest.h"
7 #include "base/strings/string_number_conversions.h"
8 #include "base/strings/utf_string_conversions.h"
9 #include "content/public/browser/web_contents.h"
10 #include "content/public/test/browser_test_utils.h"
11 #include "content/public/test/content_browser_test_utils.h"
12 #include "content/shell/browser/shell.h"
13 #include "media/base/test_data_util.h"
14 #include "net/test/spawned_test_server/spawned_test_server.h"
16 // TODO(wolenetz): Fix Media.YUV* tests on MSVS 2012 x64. crbug.com/180074
17 #if defined(OS_WIN) && defined(ARCH_CPU_X86_64) && _MSC_VER == 1700
18 #define MAYBE(x) DISABLED_##x
25 // Common test results.
26 const char MediaBrowserTest::kEnded
[] = "ENDED";
27 const char MediaBrowserTest::kError
[] = "ERROR";
28 const char MediaBrowserTest::kFailed
[] = "FAILED";
30 void MediaBrowserTest::RunMediaTestPage(const std::string
& html_page
,
31 const media::QueryParams
& query_params
,
32 const std::string
& expected_title
,
35 std::string query
= media::GetURLQueryString(query_params
);
36 scoped_ptr
<net::SpawnedTestServer
> http_test_server
;
38 http_test_server
.reset(
39 new net::SpawnedTestServer(net::SpawnedTestServer::TYPE_HTTP
,
40 net::SpawnedTestServer::kLocalhost
,
41 media::GetTestDataPath()));
42 CHECK(http_test_server
->Start());
43 gurl
= http_test_server
->GetURL("files/" + html_page
+ "?" + query
);
45 gurl
= content::GetFileUrlWithQuery(media::GetTestDataFilePath(html_page
),
48 std::string final_title
= RunTest(gurl
, expected_title
);
49 EXPECT_EQ(expected_title
, final_title
);
52 std::string
MediaBrowserTest::RunTest(const GURL
& gurl
,
53 const std::string
& expected_title
) {
54 VLOG(0) << "Running test URL: " << gurl
;
55 TitleWatcher
title_watcher(shell()->web_contents(),
56 base::ASCIIToUTF16(expected_title
));
57 AddWaitForTitles(&title_watcher
);
58 NavigateToURL(shell(), gurl
);
59 base::string16 result
= title_watcher
.WaitAndGetTitle();
60 return base::UTF16ToASCII(result
);
63 void MediaBrowserTest::AddWaitForTitles(content::TitleWatcher
* title_watcher
) {
64 title_watcher
->AlsoWaitForTitle(base::ASCIIToUTF16(kEnded
));
65 title_watcher
->AlsoWaitForTitle(base::ASCIIToUTF16(kError
));
66 title_watcher
->AlsoWaitForTitle(base::ASCIIToUTF16(kFailed
));
69 // Tests playback and seeking of an audio or video file over file or http based
70 // on a test parameter. Test starts with playback, then, after X seconds or the
71 // ended event fires, seeks near end of file; see player.html for details. The
72 // test completes when either the last 'ended' or an 'error' event fires.
73 class MediaTest
: public testing::WithParamInterface
<bool>,
74 public MediaBrowserTest
{
76 // Play specified audio over http:// or file:// depending on |http| setting.
77 void PlayAudio(const std::string
& media_file
, bool http
) {
78 PlayMedia("audio", media_file
, http
);
81 // Play specified video over http:// or file:// depending on |http| setting.
82 void PlayVideo(const std::string
& media_file
, bool http
) {
83 PlayMedia("video", media_file
, http
);
86 // Run specified color format test with the expected result.
87 void RunColorFormatTest(const std::string
& media_file
,
88 const std::string
& expected
) {
89 base::FilePath test_file_path
=
90 media::GetTestDataFilePath("blackwhite.html");
91 RunTest(GetFileUrlWithQuery(test_file_path
, media_file
), expected
);
94 void PlayMedia(const std::string
& tag
,
95 const std::string
& media_file
,
97 media::QueryParams query_params
;
98 query_params
.push_back(std::make_pair(tag
, media_file
));
99 RunMediaTestPage("player.html", query_params
, kEnded
, http
);
102 void RunVideoSizeTest(const char* media_file
, int width
, int height
) {
103 std::string expected
;
104 expected
+= base::IntToString(width
);
106 expected
+= base::IntToString(height
);
107 media::QueryParams query_params
;
108 query_params
.push_back(std::make_pair("video", media_file
));
109 RunMediaTestPage("player.html", query_params
, expected
, false);
113 IN_PROC_BROWSER_TEST_P(MediaTest
, VideoBearTheora
) {
114 PlayVideo("bear.ogv", GetParam());
117 IN_PROC_BROWSER_TEST_P(MediaTest
, VideoBearSilentTheora
) {
118 PlayVideo("bear_silent.ogv", GetParam());
121 IN_PROC_BROWSER_TEST_P(MediaTest
, VideoBearWebm
) {
122 PlayVideo("bear.webm", GetParam());
125 IN_PROC_BROWSER_TEST_P(MediaTest
, VideoBearOpusWebm
) {
126 PlayVideo("bear-opus.webm", GetParam());
129 IN_PROC_BROWSER_TEST_P(MediaTest
, VideoBearOpusOgg
) {
130 PlayVideo("bear-opus.ogg", GetParam());
133 IN_PROC_BROWSER_TEST_P(MediaTest
, VideoBearSilentWebm
) {
134 PlayVideo("bear_silent.webm", GetParam());
137 #if defined(USE_PROPRIETARY_CODECS)
138 IN_PROC_BROWSER_TEST_P(MediaTest
, VideoBearMp4
) {
139 PlayVideo("bear.mp4", GetParam());
142 IN_PROC_BROWSER_TEST_P(MediaTest
, VideoBearSilentMp4
) {
143 PlayVideo("bear_silent.mp4", GetParam());
146 // While we support the big endian (be) PCM codecs on Chromium, Quicktime seems
147 // to be the only creator of this format and only for .mov files.
148 // TODO(dalecurtis/ihf): Find or create some .wav test cases for "be" format.
149 IN_PROC_BROWSER_TEST_P(MediaTest
, VideoBearMovPcmS16be
) {
150 PlayVideo("bear_pcm_s16be.mov", GetParam());
153 IN_PROC_BROWSER_TEST_P(MediaTest
, VideoBearMovPcmS24be
) {
154 PlayVideo("bear_pcm_s24be.mov", GetParam());
157 IN_PROC_BROWSER_TEST_F(MediaTest
, VideoBearRotated0
) {
158 RunVideoSizeTest("bear_rotate_0.mp4", 1280, 720);
161 IN_PROC_BROWSER_TEST_F(MediaTest
, VideoBearRotated90
) {
162 RunVideoSizeTest("bear_rotate_90.mp4", 720, 1280);
165 IN_PROC_BROWSER_TEST_F(MediaTest
, VideoBearRotated180
) {
166 RunVideoSizeTest("bear_rotate_180.mp4", 1280, 720);
169 IN_PROC_BROWSER_TEST_F(MediaTest
, VideoBearRotated270
) {
170 RunVideoSizeTest("bear_rotate_270.mp4", 720, 1280);
172 #endif // defined(USE_PROPRIETARY_CODECS)
174 #if defined(OS_CHROMEOS)
175 #if defined(USE_PROPRIETARY_CODECS)
176 IN_PROC_BROWSER_TEST_P(MediaTest
, VideoBearAviMp3Mpeg4
) {
177 PlayVideo("bear_mpeg4_mp3.avi", GetParam());
180 IN_PROC_BROWSER_TEST_P(MediaTest
, VideoBearAviMp3Mpeg4Asp
) {
181 PlayVideo("bear_mpeg4asp_mp3.avi", GetParam());
184 IN_PROC_BROWSER_TEST_P(MediaTest
, VideoBearAviMp3Divx
) {
185 PlayVideo("bear_divx_mp3.avi", GetParam());
188 IN_PROC_BROWSER_TEST_P(MediaTest
, VideoBear3gpAacH264
) {
189 PlayVideo("bear_h264_aac.3gp", GetParam());
192 IN_PROC_BROWSER_TEST_P(MediaTest
, VideoBear3gpAmrnbMpeg4
) {
193 PlayVideo("bear_mpeg4_amrnb.3gp", GetParam());
196 IN_PROC_BROWSER_TEST_P(MediaTest
, VideoBearWavGsmms
) {
197 PlayAudio("bear_gsm_ms.wav", GetParam());
200 IN_PROC_BROWSER_TEST_P(MediaTest
, VideoBearFlac
) {
201 PlayAudio("bear.flac", GetParam());
203 #endif // defined(USE_PROPRIETARY_CODECS)
204 #endif // defined(OS_CHROMEOS)
207 IN_PROC_BROWSER_TEST_P(MediaTest
, VideoBearWavAlaw
) {
208 PlayAudio("bear_alaw.wav", GetParam());
211 IN_PROC_BROWSER_TEST_P(MediaTest
, VideoBearWavMulaw
) {
212 PlayAudio("bear_mulaw.wav", GetParam());
215 IN_PROC_BROWSER_TEST_P(MediaTest
, VideoBearWavPcm
) {
216 PlayAudio("bear_pcm.wav", GetParam());
219 IN_PROC_BROWSER_TEST_P(MediaTest
, VideoBearWavPcm3kHz
) {
220 PlayAudio("bear_3kHz.wav", GetParam());
223 IN_PROC_BROWSER_TEST_P(MediaTest
, VideoBearWavPcm192kHz
) {
224 PlayAudio("bear_192kHz.wav", GetParam());
227 IN_PROC_BROWSER_TEST_P(MediaTest
, VideoTulipWebm
) {
228 PlayVideo("tulip2.webm", GetParam());
231 // Covers tear-down when navigating away as opposed to browser exiting.
232 IN_PROC_BROWSER_TEST_F(MediaTest
, Navigate
) {
233 PlayVideo("bear.ogv", false);
234 NavigateToURL(shell(), GURL(url::kAboutBlankURL
));
235 EXPECT_FALSE(shell()->web_contents()->IsCrashed());
238 INSTANTIATE_TEST_CASE_P(File
, MediaTest
, ::testing::Values(false));
239 INSTANTIATE_TEST_CASE_P(Http
, MediaTest
, ::testing::Values(true));
241 IN_PROC_BROWSER_TEST_F(MediaTest
, MAYBE(Yuv420pTheora
)) {
242 RunColorFormatTest("yuv420p.ogv", kEnded
);
245 IN_PROC_BROWSER_TEST_F(MediaTest
, MAYBE(Yuv422pTheora
)) {
246 RunColorFormatTest("yuv422p.ogv", kEnded
);
249 IN_PROC_BROWSER_TEST_F(MediaTest
, MAYBE(Yuv444pTheora
)) {
250 RunColorFormatTest("yuv444p.ogv", kEnded
);
253 IN_PROC_BROWSER_TEST_F(MediaTest
, MAYBE(Yuv420pVp8
)) {
254 RunColorFormatTest("yuv420p.webm", kEnded
);
257 IN_PROC_BROWSER_TEST_F(MediaTest
, MAYBE(Yuv444pVp9
)) {
258 RunColorFormatTest("yuv444p.webm", "ENDED");
261 #if defined(USE_PROPRIETARY_CODECS)
262 IN_PROC_BROWSER_TEST_F(MediaTest
, MAYBE(Yuv420pH264
)) {
263 RunColorFormatTest("yuv420p.mp4", kEnded
);
266 IN_PROC_BROWSER_TEST_F(MediaTest
, MAYBE(Yuvj420pH264
)) {
267 RunColorFormatTest("yuvj420p.mp4", kEnded
);
270 IN_PROC_BROWSER_TEST_F(MediaTest
, MAYBE(Yuv422pH264
)) {
271 RunColorFormatTest("yuv422p.mp4", kEnded
);
274 IN_PROC_BROWSER_TEST_F(MediaTest
, MAYBE(Yuv444pH264
)) {
275 RunColorFormatTest("yuv444p.mp4", kEnded
);
278 #if defined(OS_CHROMEOS)
279 IN_PROC_BROWSER_TEST_F(MediaTest
, Yuv420pMpeg4
) {
280 RunColorFormatTest("yuv420p.avi", kEnded
);
282 #endif // defined(OS_CHROMEOS)
283 #endif // defined(USE_PROPRIETARY_CODECS)
285 } // namespace content