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 const char kWebMAudioOnly
[] = "audio/webm; codecs=\"vorbis\"";
14 #if !defined(OS_ANDROID)
15 const char kWebMOpusAudioOnly
[] = "audio/webm; codecs=\"opus\"";
17 const char kWebMVideoOnly
[] = "video/webm; codecs=\"vp8\"";
18 const char kWebMAudioVideo
[] = "video/webm; codecs=\"vorbis, vp8\"";
20 #if defined(USE_PROPRIETARY_CODECS) && defined(ENABLE_MPEG2TS_STREAM_PARSER)
21 const char kMp2tAudioVideo
[] = "video/mp2t; codecs=\"mp4a.40.2, avc1.42E01E\"";
26 // MSE is available on all desktop platforms and on Android 4.1 and later.
27 static bool IsMSESupported() {
28 #if defined(OS_ANDROID)
29 if (base::android::BuildInfo::GetInstance()->sdk_int() < 16) {
30 VLOG(0) << "MSE is only supported in Android 4.1 and later.";
33 #endif // defined(OS_ANDROID)
37 class MediaSourceTest
: public content::MediaBrowserTest
{
39 void TestSimplePlayback(const std::string
& media_file
,
40 const std::string
& media_type
,
41 const std::string
& expectation
) {
42 if (!IsMSESupported()) {
43 VLOG(0) << "Skipping test - MSE not supported.";
47 base::StringPairs query_params
;
48 query_params
.push_back(std::make_pair("mediaFile", media_file
));
49 query_params
.push_back(std::make_pair("mediaType", media_type
));
50 RunMediaTestPage("media_source_player.html", query_params
, expectation
,
54 #if defined(OS_ANDROID)
55 void SetUpCommandLine(base::CommandLine
* command_line
) override
{
56 command_line
->AppendSwitch(
57 switches::kDisableGestureRequirementForMediaPlayback
);
62 IN_PROC_BROWSER_TEST_F(MediaSourceTest
, Playback_VideoAudio_WebM
) {
63 TestSimplePlayback("bear-320x240.webm", kWebMAudioVideo
, kEnded
);
66 IN_PROC_BROWSER_TEST_F(MediaSourceTest
, Playback_VideoOnly_WebM
) {
67 TestSimplePlayback("bear-320x240-video-only.webm", kWebMVideoOnly
, kEnded
);
70 // Opus is not supported in Android as of now.
71 #if !defined(OS_ANDROID)
72 IN_PROC_BROWSER_TEST_F(MediaSourceTest
, Playback_AudioOnly_Opus_WebM
) {
73 TestSimplePlayback("bear-opus.webm", kWebMOpusAudioOnly
, kEnded
);
77 IN_PROC_BROWSER_TEST_F(MediaSourceTest
, Playback_AudioOnly_WebM
) {
78 TestSimplePlayback("bear-320x240-audio-only.webm", kWebMAudioOnly
, kEnded
);
81 IN_PROC_BROWSER_TEST_F(MediaSourceTest
, Playback_Type_Error
) {
82 TestSimplePlayback("bear-320x240-video-only.webm", kWebMAudioOnly
, kError
);
85 // Flaky test crbug.com/246308
86 // Test changed to skip checks resulting in flakiness. Proper fix still needed.
87 IN_PROC_BROWSER_TEST_F(MediaSourceTest
, ConfigChangeVideo
) {
88 if (!IsMSESupported()) {
89 VLOG(0) << "Skipping test - MSE not supported.";
92 RunMediaTestPage("mse_config_change.html", base::StringPairs(), kEnded
, true);
95 #if defined(USE_PROPRIETARY_CODECS)
96 IN_PROC_BROWSER_TEST_F(MediaSourceTest
, Playback_Video_MP4_Audio_WEBM
) {
97 if (!IsMSESupported()) {
98 VLOG(0) << "Skipping test - MSE not supported.";
101 base::StringPairs query_params
;
102 query_params
.push_back(std::make_pair("videoFormat", "CLEAR_MP4"));
103 query_params
.push_back(std::make_pair("audioFormat", "CLEAR_WEBM"));
104 RunMediaTestPage("mse_different_containers.html", query_params
, kEnded
, true);
107 IN_PROC_BROWSER_TEST_F(MediaSourceTest
, Playback_Video_WEBM_Audio_MP4
) {
108 if (!IsMSESupported()) {
109 VLOG(0) << "Skipping test - MSE not supported.";
112 base::StringPairs query_params
;
113 query_params
.push_back(std::make_pair("videoFormat", "CLEAR_WEBM"));
114 query_params
.push_back(std::make_pair("audioFormat", "CLEAR_MP4"));
115 RunMediaTestPage("mse_different_containers.html", query_params
, kEnded
, true);
119 #if defined(USE_PROPRIETARY_CODECS) && defined(ENABLE_MPEG2TS_STREAM_PARSER)
120 IN_PROC_BROWSER_TEST_F(MediaSourceTest
, Playback_AudioVideo_Mp2t
) {
121 TestSimplePlayback("bear-1280x720.ts", kMp2tAudioVideo
, kEnded
);
124 } // namespace content