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