media_browsertest.cc revision f8ee788a64d60abd8f2d742a5fdedde054ecd910
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.
4
5#include "content/browser/media/media_browsertest.h"
6
7#include "base/strings/stringprintf.h"
8#include "base/strings/utf_string_conversions.h"
9#include "content/public/browser/web_contents.h"
10#include "content/public/common/url_constants.h"
11#include "content/public/test/browser_test_utils.h"
12#include "content/public/test/content_browser_test_utils.h"
13#include "content/shell/browser/shell.h"
14
15// TODO(wolenetz): Fix Media.YUV* tests on MSVS 2012 x64. crbug.com/180074
16#if defined(OS_WIN) && defined(ARCH_CPU_X86_64) && _MSC_VER == 1700
17#define MAYBE(x) DISABLED_##x
18#else
19#define MAYBE(x) x
20#endif
21
22namespace content {
23
24// Common test results.
25const char MediaBrowserTest::kEnded[] = "ENDED";
26const char MediaBrowserTest::kError[] = "ERROR";
27const char MediaBrowserTest::kFailed[] = "FAILED";
28
29void MediaBrowserTest::RunMediaTestPage(
30    const char* html_page, std::vector<StringPair>* query_params,
31    const char* expected, bool http) {
32  GURL gurl;
33  std::string query = "";
34  if (query_params != NULL && !query_params->empty()) {
35    std::vector<StringPair>::const_iterator itr = query_params->begin();
36    query = base::StringPrintf("%s=%s", itr->first, itr->second);
37    ++itr;
38    for (; itr != query_params->end(); ++itr) {
39      query.append(base::StringPrintf("&%s=%s", itr->first, itr->second));
40    }
41  }
42  if (http) {
43    ASSERT_TRUE(test_server()->Start());
44    gurl = test_server()->GetURL(
45        base::StringPrintf("files/media/%s?%s", html_page, query.c_str()));
46  } else {
47    base::FilePath test_file_path = GetTestFilePath("media", html_page);
48    gurl = GetFileUrlWithQuery(test_file_path, query);
49  }
50  RunTest(gurl, expected);
51}
52
53void MediaBrowserTest::RunTest(const GURL& gurl, const char* expected) {
54  const base::string16 expected_title = base::ASCIIToUTF16(expected);
55  DVLOG(1) << "Running test URL: " << gurl;
56  TitleWatcher title_watcher(shell()->web_contents(), expected_title);
57  AddWaitForTitles(&title_watcher);
58  NavigateToURL(shell(), gurl);
59
60  base::string16 final_title = title_watcher.WaitAndGetTitle();
61  EXPECT_EQ(expected_title, final_title);
62}
63
64void MediaBrowserTest::AddWaitForTitles(content::TitleWatcher* title_watcher) {
65  title_watcher->AlsoWaitForTitle(base::ASCIIToUTF16(kEnded));
66  title_watcher->AlsoWaitForTitle(base::ASCIIToUTF16(kError));
67  title_watcher->AlsoWaitForTitle(base::ASCIIToUTF16(kFailed));
68}
69
70// Tests playback and seeking of an audio or video file over file or http based
71// on a test parameter.  Test starts with playback, then, after X seconds or the
72// ended event fires, seeks near end of file; see player.html for details.  The
73// test completes when either the last 'ended' or an 'error' event fires.
74class MediaTest : public testing::WithParamInterface<bool>,
75                  public MediaBrowserTest {
76 public:
77  // Play specified audio over http:// or file:// depending on |http| setting.
78  void PlayAudio(const char* media_file, bool http) {
79    PlayMedia("audio", media_file, http);
80  }
81
82  // Play specified video over http:// or file:// depending on |http| setting.
83  void PlayVideo(const char* media_file, bool http) {
84    PlayMedia("video", media_file, http);
85  }
86
87  // Run specified color format test with the expected result.
88  void RunColorFormatTest(const char* media_file, const char* expected) {
89    base::FilePath test_file_path = GetTestFilePath("media", "blackwhite.html");
90    RunTest(GetFileUrlWithQuery(test_file_path, media_file), expected);
91  }
92
93  void PlayMedia(const char* tag, const char* media_file, bool http) {
94    std::vector<StringPair> query_params;
95    query_params.push_back(std::make_pair(tag, media_file));
96    RunMediaTestPage("player.html", &query_params, kEnded, http);
97  }
98};
99
100IN_PROC_BROWSER_TEST_P(MediaTest, VideoBearTheora) {
101  PlayVideo("bear.ogv", GetParam());
102}
103
104IN_PROC_BROWSER_TEST_P(MediaTest, VideoBearSilentTheora) {
105  PlayVideo("bear_silent.ogv", GetParam());
106}
107
108IN_PROC_BROWSER_TEST_P(MediaTest, VideoBearWebm) {
109  PlayVideo("bear.webm", GetParam());
110}
111
112IN_PROC_BROWSER_TEST_P(MediaTest, VideoBearOpusWebm) {
113  PlayVideo("bear-opus.webm", GetParam());
114}
115
116IN_PROC_BROWSER_TEST_P(MediaTest, VideoBearOpusOgg) {
117  PlayVideo("bear-opus.ogg", GetParam());
118}
119
120IN_PROC_BROWSER_TEST_P(MediaTest, VideoBearSilentWebm) {
121  PlayVideo("bear_silent.webm", GetParam());
122}
123
124#if defined(USE_PROPRIETARY_CODECS)
125IN_PROC_BROWSER_TEST_P(MediaTest, VideoBearMp4) {
126  PlayVideo("bear.mp4", GetParam());
127}
128
129IN_PROC_BROWSER_TEST_P(MediaTest, VideoBearSilentMp4) {
130  PlayVideo("bear_silent.mp4", GetParam());
131}
132
133// While we support the big endian (be) PCM codecs on Chromium, Quicktime seems
134// to be the only creator of this format and only for .mov files.
135// TODO(dalecurtis/ihf): Find or create some .wav test cases for "be" format.
136IN_PROC_BROWSER_TEST_P(MediaTest, VideoBearMovPcmS16be) {
137  PlayVideo("bear_pcm_s16be.mov", GetParam());
138}
139
140IN_PROC_BROWSER_TEST_P(MediaTest, VideoBearMovPcmS24be) {
141  PlayVideo("bear_pcm_s24be.mov", GetParam());
142}
143#endif
144
145#if defined(OS_CHROMEOS)
146#if defined(USE_PROPRIETARY_CODECS)
147IN_PROC_BROWSER_TEST_P(MediaTest, VideoBearAviMp3Mpeg4) {
148  PlayVideo("bear_mpeg4_mp3.avi", GetParam());
149}
150
151IN_PROC_BROWSER_TEST_P(MediaTest, VideoBearAviMp3Mpeg4Asp) {
152  PlayVideo("bear_mpeg4asp_mp3.avi", GetParam());
153}
154
155IN_PROC_BROWSER_TEST_P(MediaTest, VideoBearAviMp3Divx) {
156  PlayVideo("bear_divx_mp3.avi", GetParam());
157}
158
159IN_PROC_BROWSER_TEST_P(MediaTest, VideoBear3gpAacH264) {
160  PlayVideo("bear_h264_aac.3gp", GetParam());
161}
162
163IN_PROC_BROWSER_TEST_P(MediaTest, VideoBear3gpAmrnbMpeg4) {
164  PlayVideo("bear_mpeg4_amrnb.3gp", GetParam());
165}
166
167IN_PROC_BROWSER_TEST_P(MediaTest, VideoBearWavGsmms) {
168  PlayAudio("bear_gsm_ms.wav", GetParam());
169}
170
171IN_PROC_BROWSER_TEST_P(MediaTest, VideoBearFlac) {
172  PlayAudio("bear.flac", GetParam());
173}
174#endif
175#endif
176
177IN_PROC_BROWSER_TEST_P(MediaTest, VideoBearWavAlaw) {
178  PlayAudio("bear_alaw.wav", GetParam());
179}
180
181IN_PROC_BROWSER_TEST_P(MediaTest, VideoBearWavMulaw) {
182  PlayAudio("bear_mulaw.wav", GetParam());
183}
184
185IN_PROC_BROWSER_TEST_P(MediaTest, VideoBearWavPcm) {
186  PlayAudio("bear_pcm.wav", GetParam());
187}
188
189IN_PROC_BROWSER_TEST_P(MediaTest, VideoBearWavPcm3kHz) {
190  PlayAudio("bear_3kHz.wav", GetParam());
191}
192
193IN_PROC_BROWSER_TEST_P(MediaTest, VideoBearWavPcm192kHz) {
194  PlayAudio("bear_192kHz.wav", GetParam());
195}
196
197IN_PROC_BROWSER_TEST_P(MediaTest, VideoTulipWebm) {
198  PlayVideo("tulip2.webm", GetParam());
199}
200
201// Covers tear-down when navigating away as opposed to browser exiting.
202IN_PROC_BROWSER_TEST_F(MediaTest, Navigate) {
203  PlayVideo("bear.ogv", false);
204  NavigateToURL(shell(), GURL(url::kAboutBlankURL));
205  EXPECT_FALSE(shell()->web_contents()->IsCrashed());
206}
207
208INSTANTIATE_TEST_CASE_P(File, MediaTest, ::testing::Values(false));
209INSTANTIATE_TEST_CASE_P(Http, MediaTest, ::testing::Values(true));
210
211IN_PROC_BROWSER_TEST_F(MediaTest, MAYBE(Yuv420pTheora)) {
212  RunColorFormatTest("yuv420p.ogv", "ENDED");
213}
214
215IN_PROC_BROWSER_TEST_F(MediaTest, MAYBE(Yuv422pTheora)) {
216  RunColorFormatTest("yuv422p.ogv", "ENDED");
217}
218
219IN_PROC_BROWSER_TEST_F(MediaTest, MAYBE(Yuv444pTheora)) {
220  RunColorFormatTest("yuv444p.ogv", "ENDED");
221}
222
223IN_PROC_BROWSER_TEST_F(MediaTest, MAYBE(Yuv420pVp8)) {
224  RunColorFormatTest("yuv420p.webm", "ENDED");
225}
226
227IN_PROC_BROWSER_TEST_F(MediaTest, MAYBE(Yuv444pVp9)) {
228  RunColorFormatTest("yuv444p.webm", "ENDED");
229}
230
231#if defined(USE_PROPRIETARY_CODECS)
232IN_PROC_BROWSER_TEST_F(MediaTest, MAYBE(Yuv420pH264)) {
233  RunColorFormatTest("yuv420p.mp4", "ENDED");
234}
235
236IN_PROC_BROWSER_TEST_F(MediaTest, MAYBE(Yuvj420pH264)) {
237  RunColorFormatTest("yuvj420p.mp4", "ENDED");
238}
239
240IN_PROC_BROWSER_TEST_F(MediaTest, MAYBE(Yuv422pH264)) {
241  RunColorFormatTest("yuv422p.mp4", "ENDED");
242}
243
244IN_PROC_BROWSER_TEST_F(MediaTest, MAYBE(Yuv444pH264)) {
245  RunColorFormatTest("yuv444p.mp4", "ENDED");
246}
247
248#if defined(OS_CHROMEOS)
249IN_PROC_BROWSER_TEST_F(MediaTest, Yuv420pMpeg4) {
250  RunColorFormatTest("yuv420p.avi", "ENDED");
251}
252#endif  // defined(OS_CHROMEOS)
253#endif  // defined(USE_PROPRIETARY_CODECS)
254
255}  // namespace content
256