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 "base/command_line.h"
6 #include "content/browser/media/media_browsertest.h"
7 #include "content/public/common/content_switches.h"
8 #if defined(OS_ANDROID)
9 #include "base/android/build_info.h"
12 // Common media types.
13 #if defined(USE_PROPRIETARY_CODECS) && !defined(OS_ANDROID)
14 const char kAAC_ADTS_AudioOnly
[] = "audio/aac";
16 const char kWebMAudioOnly
[] = "audio/webm; codecs=\"vorbis\"";
17 #if !defined(OS_ANDROID)
18 const char kWebMOpusAudioOnly
[] = "audio/webm; codecs=\"opus\"";
20 const char kWebMVideoOnly
[] = "video/webm; codecs=\"vp8\"";
21 const char kWebMAudioVideo
[] = "video/webm; codecs=\"vorbis, vp8\"";
23 #if defined(USE_PROPRIETARY_CODECS) && defined(ENABLE_MPEG2TS_STREAM_PARSER)
24 const char kMp2tAudioVideo
[] = "video/mp2t; codecs=\"mp4a.40.2, avc1.42E01E\"";
29 // MSE is available on all desktop platforms and on Android 4.1 and later.
30 static bool IsMSESupported() {
31 #if defined(OS_ANDROID)
32 if (base::android::BuildInfo::GetInstance()->sdk_int() < 16) {
33 VLOG(0) << "MSE is only supported in Android 4.1 and later.";
36 #endif // defined(OS_ANDROID)
40 class MediaSourceTest
: public content::MediaBrowserTest
{
42 void TestSimplePlayback(const std::string
& media_file
,
43 const std::string
& media_type
,
44 const std::string
& expectation
) {
45 if (!IsMSESupported()) {
46 VLOG(0) << "Skipping test - MSE not supported.";
50 base::StringPairs query_params
;
51 query_params
.push_back(std::make_pair("mediaFile", media_file
));
52 query_params
.push_back(std::make_pair("mediaType", media_type
));
53 RunMediaTestPage("media_source_player.html", query_params
, expectation
,
57 #if defined(OS_ANDROID)
58 void SetUpCommandLine(base::CommandLine
* command_line
) override
{
59 command_line
->AppendSwitch(
60 switches::kDisableGestureRequirementForMediaPlayback
);
65 IN_PROC_BROWSER_TEST_F(MediaSourceTest
, Playback_VideoAudio_WebM
) {
66 TestSimplePlayback("bear-320x240.webm", kWebMAudioVideo
, kEnded
);
69 IN_PROC_BROWSER_TEST_F(MediaSourceTest
, Playback_VideoOnly_WebM
) {
70 TestSimplePlayback("bear-320x240-video-only.webm", kWebMVideoOnly
, kEnded
);
73 // TODO(servolk): Android is supposed to support AAC in ADTS container with
74 // 'audio/aac' mime type, but for some reason playback fails on trybots due to
75 // some issue in OMX AAC decoder (crbug.com/528361)
76 #if defined(USE_PROPRIETARY_CODECS) && !defined(OS_ANDROID)
77 IN_PROC_BROWSER_TEST_F(MediaSourceTest
, Playback_AudioOnly_AAC_ADTS
) {
78 TestSimplePlayback("sfx.adts", kAAC_ADTS_AudioOnly
, kEnded
);
82 // Opus is not supported in Android as of now.
83 #if !defined(OS_ANDROID)
84 IN_PROC_BROWSER_TEST_F(MediaSourceTest
, Playback_AudioOnly_Opus_WebM
) {
85 TestSimplePlayback("bear-opus.webm", kWebMOpusAudioOnly
, kEnded
);
89 IN_PROC_BROWSER_TEST_F(MediaSourceTest
, Playback_AudioOnly_WebM
) {
90 TestSimplePlayback("bear-320x240-audio-only.webm", kWebMAudioOnly
, kEnded
);
93 IN_PROC_BROWSER_TEST_F(MediaSourceTest
, Playback_Type_Error
) {
94 TestSimplePlayback("bear-320x240-video-only.webm", kWebMAudioOnly
, kError
);
97 // Flaky test crbug.com/246308
98 // Test changed to skip checks resulting in flakiness. Proper fix still needed.
99 IN_PROC_BROWSER_TEST_F(MediaSourceTest
, ConfigChangeVideo
) {
100 if (!IsMSESupported()) {
101 VLOG(0) << "Skipping test - MSE not supported.";
104 RunMediaTestPage("mse_config_change.html", base::StringPairs(), kEnded
, true);
107 #if defined(USE_PROPRIETARY_CODECS)
108 IN_PROC_BROWSER_TEST_F(MediaSourceTest
, Playback_Video_MP4_Audio_WEBM
) {
109 if (!IsMSESupported()) {
110 VLOG(0) << "Skipping test - MSE not supported.";
113 base::StringPairs query_params
;
114 query_params
.push_back(std::make_pair("videoFormat", "CLEAR_MP4"));
115 query_params
.push_back(std::make_pair("audioFormat", "CLEAR_WEBM"));
116 RunMediaTestPage("mse_different_containers.html", query_params
, kEnded
, true);
119 IN_PROC_BROWSER_TEST_F(MediaSourceTest
, Playback_Video_WEBM_Audio_MP4
) {
120 if (!IsMSESupported()) {
121 VLOG(0) << "Skipping test - MSE not supported.";
124 base::StringPairs query_params
;
125 query_params
.push_back(std::make_pair("videoFormat", "CLEAR_WEBM"));
126 query_params
.push_back(std::make_pair("audioFormat", "CLEAR_MP4"));
127 RunMediaTestPage("mse_different_containers.html", query_params
, kEnded
, true);
131 #if defined(USE_PROPRIETARY_CODECS) && defined(ENABLE_MPEG2TS_STREAM_PARSER)
132 IN_PROC_BROWSER_TEST_F(MediaSourceTest
, Playback_AudioVideo_Mp2t
) {
133 TestSimplePlayback("bear-1280x720.ts", kMp2tAudioVideo
, kEnded
);
136 } // namespace content