| OLD | NEW |
| 1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "content/browser/media/media_browsertest.h" | 5 #include "content/browser/media/media_browsertest.h" |
| 6 | 6 |
| 7 #include "base/strings/stringprintf.h" | |
| 8 #include "base/strings/utf_string_conversions.h" | 7 #include "base/strings/utf_string_conversions.h" |
| 9 #include "content/public/browser/web_contents.h" | 8 #include "content/public/browser/web_contents.h" |
| 10 #include "content/public/common/url_constants.h" | |
| 11 #include "content/public/test/browser_test_utils.h" | 9 #include "content/public/test/browser_test_utils.h" |
| 12 #include "content/public/test/content_browser_test_utils.h" | 10 #include "content/public/test/content_browser_test_utils.h" |
| 13 #include "content/shell/browser/shell.h" | 11 #include "content/shell/browser/shell.h" |
| 14 | 12 |
| 15 // TODO(wolenetz): Fix Media.YUV* tests on MSVS 2012 x64. crbug.com/180074 | 13 // 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 | 14 #if defined(OS_WIN) && defined(ARCH_CPU_X86_64) && _MSC_VER == 1700 |
| 17 #define MAYBE(x) DISABLED_##x | 15 #define MAYBE(x) DISABLED_##x |
| 18 #else | 16 #else |
| 19 #define MAYBE(x) x | 17 #define MAYBE(x) x |
| 20 #endif | 18 #endif |
| 21 | 19 |
| 22 namespace content { | 20 namespace content { |
| 23 | 21 |
| 24 // Common test results. | 22 // Common test results. |
| 25 const char MediaBrowserTest::kEnded[] = "ENDED"; | 23 const char MediaBrowserTest::kEnded[] = "ENDED"; |
| 26 const char MediaBrowserTest::kError[] = "ERROR"; | 24 const char MediaBrowserTest::kError[] = "ERROR"; |
| 27 const char MediaBrowserTest::kFailed[] = "FAILED"; | 25 const char MediaBrowserTest::kFailed[] = "FAILED"; |
| 28 | 26 |
| 29 void MediaBrowserTest::RunMediaTestPage( | 27 void MediaBrowserTest::RunMediaTestPage( |
| 30 const char* html_page, std::vector<StringPair>* query_params, | 28 const std::string& html_page, |
| 31 const char* expected, bool http) { | 29 std::vector<media::StringPair>* query_params, |
| 30 const std::string& expected_title, |
| 31 bool http) { |
| 32 GURL gurl; | 32 GURL gurl; |
| 33 std::string query = ""; | 33 std::string query = media::GetURLQueryString(query_params); |
| 34 if (query_params != NULL && !query_params->empty()) { | 34 scoped_ptr<net::SpawnedTestServer> http_test_server; |
| 35 std::vector<StringPair>::const_iterator itr = query_params->begin(); | 35 if (http) { |
| 36 query = base::StringPrintf("%s=%s", itr->first, itr->second); | 36 http_test_server = media::StartMediaHttpTestServer(); |
| 37 ++itr; | 37 gurl = http_test_server->GetURL("files/" + html_page + "?" + query); |
| 38 for (; itr != query_params->end(); ++itr) { | 38 } else { |
| 39 query.append(base::StringPrintf("&%s=%s", itr->first, itr->second)); | 39 gurl = content::GetFileUrlWithQuery(media::GetTestDataFilePath(html_page), |
| 40 } | 40 query); |
| 41 } | 41 } |
| 42 if (http) { | 42 std::string final_title = RunTest(gurl, expected_title); |
| 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 | |
| 53 void 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); | 43 EXPECT_EQ(expected_title, final_title); |
| 62 } | 44 } |
| 63 | 45 |
| 46 std::string MediaBrowserTest::RunTest(const GURL& gurl, |
| 47 const std::string& expected_title) { |
| 48 VLOG(0) << "Running test URL: " << gurl; |
| 49 TitleWatcher title_watcher(shell()->web_contents(), |
| 50 base::ASCIIToUTF16(expected_title)); |
| 51 AddWaitForTitles(&title_watcher); |
| 52 NavigateToURL(shell(), gurl); |
| 53 base::string16 result = title_watcher.WaitAndGetTitle(); |
| 54 return base::UTF16ToASCII(result); |
| 55 } |
| 56 |
| 64 void MediaBrowserTest::AddWaitForTitles(content::TitleWatcher* title_watcher) { | 57 void MediaBrowserTest::AddWaitForTitles(content::TitleWatcher* title_watcher) { |
| 65 title_watcher->AlsoWaitForTitle(base::ASCIIToUTF16(kEnded)); | 58 title_watcher->AlsoWaitForTitle(base::ASCIIToUTF16(kEnded)); |
| 66 title_watcher->AlsoWaitForTitle(base::ASCIIToUTF16(kError)); | 59 title_watcher->AlsoWaitForTitle(base::ASCIIToUTF16(kError)); |
| 67 title_watcher->AlsoWaitForTitle(base::ASCIIToUTF16(kFailed)); | 60 title_watcher->AlsoWaitForTitle(base::ASCIIToUTF16(kFailed)); |
| 68 } | 61 } |
| 69 | 62 |
| 70 // Tests playback and seeking of an audio or video file over file or http based | 63 // 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 | 64 // 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 | 65 // 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. | 66 // test completes when either the last 'ended' or an 'error' event fires. |
| 74 class MediaTest : public testing::WithParamInterface<bool>, | 67 class MediaTest : public testing::WithParamInterface<bool>, |
| 75 public MediaBrowserTest { | 68 public MediaBrowserTest { |
| 76 public: | 69 public: |
| 77 // Play specified audio over http:// or file:// depending on |http| setting. | 70 // Play specified audio over http:// or file:// depending on |http| setting. |
| 78 void PlayAudio(const char* media_file, bool http) { | 71 void PlayAudio(const std::string& media_file, bool http) { |
| 79 PlayMedia("audio", media_file, http); | 72 PlayMedia("audio", media_file, http); |
| 80 } | 73 } |
| 81 | 74 |
| 82 // Play specified video over http:// or file:// depending on |http| setting. | 75 // Play specified video over http:// or file:// depending on |http| setting. |
| 83 void PlayVideo(const char* media_file, bool http) { | 76 void PlayVideo(const std::string& media_file, bool http) { |
| 84 PlayMedia("video", media_file, http); | 77 PlayMedia("video", media_file, http); |
| 85 } | 78 } |
| 86 | 79 |
| 87 // Run specified color format test with the expected result. | 80 // Run specified color format test with the expected result. |
| 88 void RunColorFormatTest(const char* media_file, const char* expected) { | 81 void RunColorFormatTest(const std::string& media_file, |
| 89 base::FilePath test_file_path = GetTestFilePath("media", "blackwhite.html"); | 82 const std::string& expected) { |
| 83 base::FilePath test_file_path = |
| 84 media::GetTestDataFilePath("blackwhite.html"); |
| 90 RunTest(GetFileUrlWithQuery(test_file_path, media_file), expected); | 85 RunTest(GetFileUrlWithQuery(test_file_path, media_file), expected); |
| 91 } | 86 } |
| 92 | 87 |
| 93 void PlayMedia(const char* tag, const char* media_file, bool http) { | 88 void PlayMedia(const std::string& tag, |
| 94 std::vector<StringPair> query_params; | 89 const std::string& media_file, |
| 90 bool http) { |
| 91 std::vector<media::StringPair> query_params; |
| 95 query_params.push_back(std::make_pair(tag, media_file)); | 92 query_params.push_back(std::make_pair(tag, media_file)); |
| 96 RunMediaTestPage("player.html", &query_params, kEnded, http); | 93 RunMediaTestPage("player.html", &query_params, kEnded, http); |
| 97 } | 94 } |
| 98 }; | 95 }; |
| 99 | 96 |
| 100 IN_PROC_BROWSER_TEST_P(MediaTest, VideoBearTheora) { | 97 IN_PROC_BROWSER_TEST_P(MediaTest, VideoBearTheora) { |
| 101 PlayVideo("bear.ogv", GetParam()); | 98 PlayVideo("bear.ogv", GetParam()); |
| 102 } | 99 } |
| 103 | 100 |
| 104 IN_PROC_BROWSER_TEST_P(MediaTest, VideoBearSilentTheora) { | 101 IN_PROC_BROWSER_TEST_P(MediaTest, VideoBearSilentTheora) { |
| (...skipping 28 matching lines...) Expand all Loading... |
| 133 // While we support the big endian (be) PCM codecs on Chromium, Quicktime seems | 130 // 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. | 131 // 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. | 132 // TODO(dalecurtis/ihf): Find or create some .wav test cases for "be" format. |
| 136 IN_PROC_BROWSER_TEST_P(MediaTest, VideoBearMovPcmS16be) { | 133 IN_PROC_BROWSER_TEST_P(MediaTest, VideoBearMovPcmS16be) { |
| 137 PlayVideo("bear_pcm_s16be.mov", GetParam()); | 134 PlayVideo("bear_pcm_s16be.mov", GetParam()); |
| 138 } | 135 } |
| 139 | 136 |
| 140 IN_PROC_BROWSER_TEST_P(MediaTest, VideoBearMovPcmS24be) { | 137 IN_PROC_BROWSER_TEST_P(MediaTest, VideoBearMovPcmS24be) { |
| 141 PlayVideo("bear_pcm_s24be.mov", GetParam()); | 138 PlayVideo("bear_pcm_s24be.mov", GetParam()); |
| 142 } | 139 } |
| 143 #endif | 140 #endif // defined(USE_PROPRIETARY_CODECS) |
| 144 | 141 |
| 145 #if defined(OS_CHROMEOS) | 142 #if defined(OS_CHROMEOS) |
| 146 #if defined(USE_PROPRIETARY_CODECS) | 143 #if defined(USE_PROPRIETARY_CODECS) |
| 147 IN_PROC_BROWSER_TEST_P(MediaTest, VideoBearAviMp3Mpeg4) { | 144 IN_PROC_BROWSER_TEST_P(MediaTest, VideoBearAviMp3Mpeg4) { |
| 148 PlayVideo("bear_mpeg4_mp3.avi", GetParam()); | 145 PlayVideo("bear_mpeg4_mp3.avi", GetParam()); |
| 149 } | 146 } |
| 150 | 147 |
| 151 IN_PROC_BROWSER_TEST_P(MediaTest, VideoBearAviMp3Mpeg4Asp) { | 148 IN_PROC_BROWSER_TEST_P(MediaTest, VideoBearAviMp3Mpeg4Asp) { |
| 152 PlayVideo("bear_mpeg4asp_mp3.avi", GetParam()); | 149 PlayVideo("bear_mpeg4asp_mp3.avi", GetParam()); |
| 153 } | 150 } |
| (...skipping 10 matching lines...) Expand all Loading... |
| 164 PlayVideo("bear_mpeg4_amrnb.3gp", GetParam()); | 161 PlayVideo("bear_mpeg4_amrnb.3gp", GetParam()); |
| 165 } | 162 } |
| 166 | 163 |
| 167 IN_PROC_BROWSER_TEST_P(MediaTest, VideoBearWavGsmms) { | 164 IN_PROC_BROWSER_TEST_P(MediaTest, VideoBearWavGsmms) { |
| 168 PlayAudio("bear_gsm_ms.wav", GetParam()); | 165 PlayAudio("bear_gsm_ms.wav", GetParam()); |
| 169 } | 166 } |
| 170 | 167 |
| 171 IN_PROC_BROWSER_TEST_P(MediaTest, VideoBearFlac) { | 168 IN_PROC_BROWSER_TEST_P(MediaTest, VideoBearFlac) { |
| 172 PlayAudio("bear.flac", GetParam()); | 169 PlayAudio("bear.flac", GetParam()); |
| 173 } | 170 } |
| 174 #endif | 171 #endif // defined(USE_PROPRIETARY_CODECS) |
| 175 #endif | 172 #endif // defined(OS_CHROMEOS) |
| 173 |
| 176 | 174 |
| 177 IN_PROC_BROWSER_TEST_P(MediaTest, VideoBearWavAlaw) { | 175 IN_PROC_BROWSER_TEST_P(MediaTest, VideoBearWavAlaw) { |
| 178 PlayAudio("bear_alaw.wav", GetParam()); | 176 PlayAudio("bear_alaw.wav", GetParam()); |
| 179 } | 177 } |
| 180 | 178 |
| 181 IN_PROC_BROWSER_TEST_P(MediaTest, VideoBearWavMulaw) { | 179 IN_PROC_BROWSER_TEST_P(MediaTest, VideoBearWavMulaw) { |
| 182 PlayAudio("bear_mulaw.wav", GetParam()); | 180 PlayAudio("bear_mulaw.wav", GetParam()); |
| 183 } | 181 } |
| 184 | 182 |
| 185 IN_PROC_BROWSER_TEST_P(MediaTest, VideoBearWavPcm) { | 183 IN_PROC_BROWSER_TEST_P(MediaTest, VideoBearWavPcm) { |
| (...skipping 16 matching lines...) Expand all Loading... |
| 202 IN_PROC_BROWSER_TEST_F(MediaTest, Navigate) { | 200 IN_PROC_BROWSER_TEST_F(MediaTest, Navigate) { |
| 203 PlayVideo("bear.ogv", false); | 201 PlayVideo("bear.ogv", false); |
| 204 NavigateToURL(shell(), GURL(url::kAboutBlankURL)); | 202 NavigateToURL(shell(), GURL(url::kAboutBlankURL)); |
| 205 EXPECT_FALSE(shell()->web_contents()->IsCrashed()); | 203 EXPECT_FALSE(shell()->web_contents()->IsCrashed()); |
| 206 } | 204 } |
| 207 | 205 |
| 208 INSTANTIATE_TEST_CASE_P(File, MediaTest, ::testing::Values(false)); | 206 INSTANTIATE_TEST_CASE_P(File, MediaTest, ::testing::Values(false)); |
| 209 INSTANTIATE_TEST_CASE_P(Http, MediaTest, ::testing::Values(true)); | 207 INSTANTIATE_TEST_CASE_P(Http, MediaTest, ::testing::Values(true)); |
| 210 | 208 |
| 211 IN_PROC_BROWSER_TEST_F(MediaTest, MAYBE(Yuv420pTheora)) { | 209 IN_PROC_BROWSER_TEST_F(MediaTest, MAYBE(Yuv420pTheora)) { |
| 212 RunColorFormatTest("yuv420p.ogv", "ENDED"); | 210 RunColorFormatTest("yuv420p.ogv", kEnded); |
| 213 } | 211 } |
| 214 | 212 |
| 215 IN_PROC_BROWSER_TEST_F(MediaTest, MAYBE(Yuv422pTheora)) { | 213 IN_PROC_BROWSER_TEST_F(MediaTest, MAYBE(Yuv422pTheora)) { |
| 216 RunColorFormatTest("yuv422p.ogv", "ENDED"); | 214 RunColorFormatTest("yuv422p.ogv", kEnded); |
| 217 } | 215 } |
| 218 | 216 |
| 219 IN_PROC_BROWSER_TEST_F(MediaTest, MAYBE(Yuv444pTheora)) { | 217 IN_PROC_BROWSER_TEST_F(MediaTest, MAYBE(Yuv444pTheora)) { |
| 220 RunColorFormatTest("yuv444p.ogv", "ENDED"); | 218 RunColorFormatTest("yuv444p.ogv", kEnded); |
| 221 } | 219 } |
| 222 | 220 |
| 223 IN_PROC_BROWSER_TEST_F(MediaTest, MAYBE(Yuv420pVp8)) { | 221 IN_PROC_BROWSER_TEST_F(MediaTest, MAYBE(Yuv420pVp8)) { |
| 224 RunColorFormatTest("yuv420p.webm", "ENDED"); | 222 RunColorFormatTest("yuv420p.webm", kEnded); |
| 225 } | 223 } |
| 226 | 224 |
| 227 IN_PROC_BROWSER_TEST_F(MediaTest, MAYBE(Yuv444pVp9)) { | 225 IN_PROC_BROWSER_TEST_F(MediaTest, MAYBE(Yuv444pVp9)) { |
| 228 RunColorFormatTest("yuv444p.webm", "ENDED"); | 226 RunColorFormatTest("yuv444p.webm", kEnded); |
| 229 } | 227 } |
| 230 | 228 |
| 231 #if defined(USE_PROPRIETARY_CODECS) | 229 #if defined(USE_PROPRIETARY_CODECS) |
| 232 IN_PROC_BROWSER_TEST_F(MediaTest, MAYBE(Yuv420pH264)) { | 230 IN_PROC_BROWSER_TEST_F(MediaTest, MAYBE(Yuv420pH264)) { |
| 233 RunColorFormatTest("yuv420p.mp4", "ENDED"); | 231 RunColorFormatTest("yuv420p.mp4", kEnded); |
| 234 } | 232 } |
| 235 | 233 |
| 236 IN_PROC_BROWSER_TEST_F(MediaTest, MAYBE(Yuvj420pH264)) { | 234 IN_PROC_BROWSER_TEST_F(MediaTest, MAYBE(Yuvj420pH264)) { |
| 237 RunColorFormatTest("yuvj420p.mp4", "ENDED"); | 235 RunColorFormatTest("yuvj420p.mp4", kEnded); |
| 238 } | 236 } |
| 239 | 237 |
| 240 IN_PROC_BROWSER_TEST_F(MediaTest, MAYBE(Yuv422pH264)) { | 238 IN_PROC_BROWSER_TEST_F(MediaTest, MAYBE(Yuv422pH264)) { |
| 241 RunColorFormatTest("yuv422p.mp4", "ENDED"); | 239 RunColorFormatTest("yuv422p.mp4", kEnded); |
| 242 } | 240 } |
| 243 | 241 |
| 244 IN_PROC_BROWSER_TEST_F(MediaTest, MAYBE(Yuv444pH264)) { | 242 IN_PROC_BROWSER_TEST_F(MediaTest, MAYBE(Yuv444pH264)) { |
| 245 RunColorFormatTest("yuv444p.mp4", "ENDED"); | 243 RunColorFormatTest("yuv444p.mp4", kEnded); |
| 246 } | 244 } |
| 247 | 245 |
| 248 #if defined(OS_CHROMEOS) | 246 #if defined(OS_CHROMEOS) |
| 249 IN_PROC_BROWSER_TEST_F(MediaTest, Yuv420pMpeg4) { | 247 IN_PROC_BROWSER_TEST_F(MediaTest, Yuv420pMpeg4) { |
| 250 RunColorFormatTest("yuv420p.avi", "ENDED"); | 248 RunColorFormatTest("yuv420p.avi", kEnded); |
| 251 } | 249 } |
| 252 #endif // defined(OS_CHROMEOS) | 250 #endif // defined(OS_CHROMEOS) |
| 253 #endif // defined(USE_PROPRIETARY_CODECS) | 251 #endif // defined(USE_PROPRIETARY_CODECS) |
| 254 | 252 |
| 255 } // namespace content | 253 } // namespace content |
| OLD | NEW |