Add ICU message format support
[chromium-blink-merge.git] / content / browser / media / media_browsertest.cc
blobf47c4a506a96769b690649e0de1e995f91daff8d
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 namespace content {
18 // Common test results.
19 const char MediaBrowserTest::kEnded[] = "ENDED";
20 const char MediaBrowserTest::kError[] = "ERROR";
21 const char MediaBrowserTest::kFailed[] = "FAILED";
23 void MediaBrowserTest::RunMediaTestPage(const std::string& html_page,
24 const base::StringPairs& query_params,
25 const std::string& expected_title,
26 bool http) {
27 GURL gurl;
28 std::string query = media::GetURLQueryString(query_params);
29 scoped_ptr<net::SpawnedTestServer> http_test_server;
30 if (http) {
31 http_test_server.reset(
32 new net::SpawnedTestServer(net::SpawnedTestServer::TYPE_HTTP,
33 net::SpawnedTestServer::kLocalhost,
34 media::GetTestDataPath()));
35 CHECK(http_test_server->Start());
36 gurl = http_test_server->GetURL("files/" + html_page + "?" + query);
37 } else {
38 gurl = content::GetFileUrlWithQuery(media::GetTestDataFilePath(html_page),
39 query);
41 std::string final_title = RunTest(gurl, expected_title);
42 EXPECT_EQ(expected_title, final_title);
45 std::string MediaBrowserTest::RunTest(const GURL& gurl,
46 const std::string& expected_title) {
47 VLOG(0) << "Running test URL: " << gurl;
48 TitleWatcher title_watcher(shell()->web_contents(),
49 base::ASCIIToUTF16(expected_title));
50 AddWaitForTitles(&title_watcher);
51 NavigateToURL(shell(), gurl);
52 base::string16 result = title_watcher.WaitAndGetTitle();
53 return base::UTF16ToASCII(result);
56 void MediaBrowserTest::AddWaitForTitles(content::TitleWatcher* title_watcher) {
57 title_watcher->AlsoWaitForTitle(base::ASCIIToUTF16(kEnded));
58 title_watcher->AlsoWaitForTitle(base::ASCIIToUTF16(kError));
59 title_watcher->AlsoWaitForTitle(base::ASCIIToUTF16(kFailed));
62 // Tests playback and seeking of an audio or video file over file or http based
63 // on a test parameter. Test starts with playback, then, after X seconds or the
64 // ended event fires, seeks near end of file; see player.html for details. The
65 // test completes when either the last 'ended' or an 'error' event fires.
66 class MediaTest : public testing::WithParamInterface<bool>,
67 public MediaBrowserTest {
68 public:
69 // Play specified audio over http:// or file:// depending on |http| setting.
70 void PlayAudio(const std::string& media_file, bool http) {
71 PlayMedia("audio", media_file, http);
74 // Play specified video over http:// or file:// depending on |http| setting.
75 void PlayVideo(const std::string& media_file, bool http) {
76 PlayMedia("video", media_file, http);
79 // Run specified color format test with the expected result.
80 void RunColorFormatTest(const std::string& media_file,
81 const std::string& expected) {
82 base::FilePath test_file_path =
83 media::GetTestDataFilePath("blackwhite.html");
84 RunTest(GetFileUrlWithQuery(test_file_path, media_file), expected);
87 void PlayMedia(const std::string& tag,
88 const std::string& media_file,
89 bool http) {
90 base::StringPairs query_params;
91 query_params.push_back(std::make_pair(tag, media_file));
92 RunMediaTestPage("player.html", query_params, kEnded, http);
95 void RunVideoSizeTest(const char* media_file, int width, int height) {
96 std::string expected;
97 expected += base::IntToString(width);
98 expected += " ";
99 expected += base::IntToString(height);
100 base::StringPairs query_params;
101 query_params.push_back(std::make_pair("video", media_file));
102 RunMediaTestPage("player.html", query_params, expected, false);
106 IN_PROC_BROWSER_TEST_P(MediaTest, VideoBearTheora) {
107 PlayVideo("bear.ogv", GetParam());
110 IN_PROC_BROWSER_TEST_P(MediaTest, VideoBearSilentTheora) {
111 PlayVideo("bear_silent.ogv", GetParam());
114 IN_PROC_BROWSER_TEST_P(MediaTest, VideoBearWebm) {
115 PlayVideo("bear.webm", GetParam());
118 IN_PROC_BROWSER_TEST_P(MediaTest, VideoBearOpusWebm) {
119 PlayVideo("bear-opus.webm", GetParam());
122 IN_PROC_BROWSER_TEST_P(MediaTest, VideoBearOpusOgg) {
123 PlayVideo("bear-opus.ogg", GetParam());
126 IN_PROC_BROWSER_TEST_P(MediaTest, VideoBearSilentWebm) {
127 PlayVideo("bear_silent.webm", GetParam());
130 #if defined(USE_PROPRIETARY_CODECS)
131 IN_PROC_BROWSER_TEST_P(MediaTest, VideoBearMp4) {
132 PlayVideo("bear.mp4", GetParam());
135 IN_PROC_BROWSER_TEST_P(MediaTest, VideoBearSilentMp4) {
136 PlayVideo("bear_silent.mp4", GetParam());
139 // While we support the big endian (be) PCM codecs on Chromium, Quicktime seems
140 // to be the only creator of this format and only for .mov files.
141 // TODO(dalecurtis/ihf): Find or create some .wav test cases for "be" format.
142 IN_PROC_BROWSER_TEST_P(MediaTest, VideoBearMovPcmS16be) {
143 PlayVideo("bear_pcm_s16be.mov", GetParam());
146 IN_PROC_BROWSER_TEST_P(MediaTest, VideoBearMovPcmS24be) {
147 PlayVideo("bear_pcm_s24be.mov", GetParam());
150 IN_PROC_BROWSER_TEST_F(MediaTest, VideoBearRotated0) {
151 RunVideoSizeTest("bear_rotate_0.mp4", 1280, 720);
154 IN_PROC_BROWSER_TEST_F(MediaTest, VideoBearRotated90) {
155 RunVideoSizeTest("bear_rotate_90.mp4", 720, 1280);
158 IN_PROC_BROWSER_TEST_F(MediaTest, VideoBearRotated180) {
159 RunVideoSizeTest("bear_rotate_180.mp4", 1280, 720);
162 IN_PROC_BROWSER_TEST_F(MediaTest, VideoBearRotated270) {
163 RunVideoSizeTest("bear_rotate_270.mp4", 720, 1280);
165 #endif // defined(USE_PROPRIETARY_CODECS)
167 #if defined(OS_CHROMEOS)
168 #if defined(USE_PROPRIETARY_CODECS)
169 IN_PROC_BROWSER_TEST_P(MediaTest, VideoBearAviMp3Mpeg4) {
170 PlayVideo("bear_mpeg4_mp3.avi", GetParam());
173 IN_PROC_BROWSER_TEST_P(MediaTest, VideoBearAviMp3Mpeg4Asp) {
174 PlayVideo("bear_mpeg4asp_mp3.avi", GetParam());
177 IN_PROC_BROWSER_TEST_P(MediaTest, VideoBearAviMp3Divx) {
178 PlayVideo("bear_divx_mp3.avi", GetParam());
181 IN_PROC_BROWSER_TEST_P(MediaTest, VideoBear3gpAacH264) {
182 PlayVideo("bear_h264_aac.3gp", GetParam());
185 IN_PROC_BROWSER_TEST_P(MediaTest, VideoBear3gpAmrnbMpeg4) {
186 PlayVideo("bear_mpeg4_amrnb.3gp", GetParam());
189 IN_PROC_BROWSER_TEST_P(MediaTest, VideoBearWavGsmms) {
190 PlayAudio("bear_gsm_ms.wav", GetParam());
193 IN_PROC_BROWSER_TEST_P(MediaTest, VideoBearFlac) {
194 PlayAudio("bear.flac", GetParam());
196 #endif // defined(USE_PROPRIETARY_CODECS)
197 #endif // defined(OS_CHROMEOS)
200 IN_PROC_BROWSER_TEST_P(MediaTest, VideoBearWavAlaw) {
201 PlayAudio("bear_alaw.wav", GetParam());
204 IN_PROC_BROWSER_TEST_P(MediaTest, VideoBearWavMulaw) {
205 PlayAudio("bear_mulaw.wav", GetParam());
208 IN_PROC_BROWSER_TEST_P(MediaTest, VideoBearWavPcm) {
209 PlayAudio("bear_pcm.wav", GetParam());
212 IN_PROC_BROWSER_TEST_P(MediaTest, VideoBearWavPcm3kHz) {
213 PlayAudio("bear_3kHz.wav", GetParam());
216 IN_PROC_BROWSER_TEST_P(MediaTest, VideoBearWavPcm192kHz) {
217 PlayAudio("bear_192kHz.wav", GetParam());
220 IN_PROC_BROWSER_TEST_P(MediaTest, VideoTulipWebm) {
221 PlayVideo("tulip2.webm", GetParam());
224 // Covers tear-down when navigating away as opposed to browser exiting.
225 IN_PROC_BROWSER_TEST_F(MediaTest, Navigate) {
226 PlayVideo("bear.ogv", false);
227 NavigateToURL(shell(), GURL(url::kAboutBlankURL));
228 EXPECT_FALSE(shell()->web_contents()->IsCrashed());
231 INSTANTIATE_TEST_CASE_P(File, MediaTest, ::testing::Values(false));
232 INSTANTIATE_TEST_CASE_P(Http, MediaTest, ::testing::Values(true));
234 IN_PROC_BROWSER_TEST_F(MediaTest, Yuv420pTheora) {
235 RunColorFormatTest("yuv420p.ogv", kEnded);
238 IN_PROC_BROWSER_TEST_F(MediaTest, Yuv422pTheora) {
239 RunColorFormatTest("yuv422p.ogv", kEnded);
242 IN_PROC_BROWSER_TEST_F(MediaTest, Yuv444pTheora) {
243 RunColorFormatTest("yuv444p.ogv", kEnded);
246 IN_PROC_BROWSER_TEST_F(MediaTest, Yuv420pVp8) {
247 RunColorFormatTest("yuv420p.webm", kEnded);
250 IN_PROC_BROWSER_TEST_F(MediaTest, Yuv444pVp9) {
251 RunColorFormatTest("yuv444p.webm", "ENDED");
254 #if defined(USE_PROPRIETARY_CODECS)
255 IN_PROC_BROWSER_TEST_F(MediaTest, Yuv420pH264) {
256 RunColorFormatTest("yuv420p.mp4", kEnded);
259 IN_PROC_BROWSER_TEST_F(MediaTest, Yuv420pRec709H264) {
260 RunColorFormatTest("yuv420p_rec709.mp4", kEnded);
263 IN_PROC_BROWSER_TEST_F(MediaTest, Yuvj420pH264) {
264 RunColorFormatTest("yuvj420p.mp4", kEnded);
267 IN_PROC_BROWSER_TEST_F(MediaTest, Yuv422pH264) {
268 RunColorFormatTest("yuv422p.mp4", kEnded);
271 IN_PROC_BROWSER_TEST_F(MediaTest, Yuv444pH264) {
272 RunColorFormatTest("yuv444p.mp4", kEnded);
275 #if defined(OS_CHROMEOS)
276 IN_PROC_BROWSER_TEST_F(MediaTest, Yuv420pMpeg4) {
277 RunColorFormatTest("yuv420p.avi", kEnded);
279 #endif // defined(OS_CHROMEOS)
280 #endif // defined(USE_PROPRIETARY_CODECS)
282 } // namespace content