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