Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(110)

Side by Side Diff: content/browser/media/media_browsertest.cc

Issue 357413002: Have media content and chrome browser tests load data from media/test/data (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: few merge fixes Created 6 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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" 7 #include "base/path_service.h"
8 #include "base/strings/utf_string_conversions.h" 8 #include "base/strings/utf_string_conversions.h"
9 #include "content/public/browser/web_contents.h" 9 #include "content/public/browser/web_contents.h"
10 #include "content/public/common/url_constants.h" 10 #include "content/public/common/url_constants.h"
11 #include "content/public/test/browser_test_utils.h" 11 #include "content/public/test/browser_test_utils.h"
12 #include "content/public/test/content_browser_test_utils.h" 12 #include "content/public/test/content_browser_test_utils.h"
13 #include "content/shell/browser/shell.h" 13 #include "content/shell/browser/shell.h"
14 #include "media/base/test_data_util.h"
14 15
15 // TODO(wolenetz): Fix Media.YUV* tests on MSVS 2012 x64. crbug.com/180074 16 // 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 #if defined(OS_WIN) && defined(ARCH_CPU_X86_64) && _MSC_VER == 1700
17 #define MAYBE(x) DISABLED_##x 18 #define MAYBE(x) DISABLED_##x
18 #else 19 #else
19 #define MAYBE(x) x 20 #define MAYBE(x) x
20 #endif 21 #endif
21 22
22 namespace content { 23 namespace content {
23 24
24 // Common test results. 25 // Common test results.
25 const char MediaBrowserTest::kEnded[] = "ENDED"; 26 const char MediaBrowserTest::kEnded[] = "ENDED";
26 const char MediaBrowserTest::kError[] = "ERROR"; 27 const char MediaBrowserTest::kError[] = "ERROR";
27 const char MediaBrowserTest::kFailed[] = "FAILED"; 28 const char MediaBrowserTest::kFailed[] = "FAILED";
28 29
29 void MediaBrowserTest::RunMediaTestPage( 30 void MediaBrowserTest::RunMediaTestPage(
30 const char* html_page, std::vector<StringPair>* query_params, 31 const std::string& html_page,
31 const char* expected, bool http) { 32 std::vector<StringPair>* query_params,
33 const std::string& expected_title,
34 bool http) {
32 GURL gurl; 35 GURL gurl;
33 std::string query = ""; 36 std::string query = "";
34 if (query_params != NULL && !query_params->empty()) { 37 if (query_params != NULL && !query_params->empty()) {
jrummell 2014/07/02 00:33:40 Should query_params -> query be a helper function?
shadi 2014/07/02 19:23:36 Done.
35 std::vector<StringPair>::const_iterator itr = query_params->begin(); 38 std::vector<StringPair>::const_iterator itr = query_params->begin();
36 query = base::StringPrintf("%s=%s", itr->first, itr->second); 39 query = itr->first + "=" + itr->second;
37 ++itr; 40 ++itr;
38 for (; itr != query_params->end(); ++itr) { 41 for (; itr != query_params->end(); ++itr) {
39 query.append(base::StringPrintf("&%s=%s", itr->first, itr->second)); 42 query.append("&" + itr->first + "=" + itr->second);
40 } 43 }
41 } 44 }
45 scoped_ptr<net::SpawnedTestServer> http_test_server_;
jrummell 2014/07/02 00:33:40 local variables shouldn't end in _.
shadi 2014/07/02 19:23:36 Done.
42 if (http) { 46 if (http) {
43 ASSERT_TRUE(test_server()->Start()); 47 http_test_server_.reset(new net::SpawnedTestServer(
44 gurl = test_server()->GetURL( 48 net::SpawnedTestServer::TYPE_HTTP,
45 base::StringPrintf("files/media/%s?%s", html_page, query.c_str())); 49 net::SpawnedTestServer::kLocalhost,
50 media::GetTestDataPath()));
51 ASSERT_TRUE(http_test_server_.get()->Start());
jrummell 2014/07/02 00:33:40 ditto on .get(). Could this be refactored out into
shadi 2014/07/02 19:23:36 Done.
52 gurl = http_test_server_.get()->GetURL("files/" + html_page + "?" + query);
46 } else { 53 } else {
47 base::FilePath test_file_path = GetTestFilePath("media", html_page); 54 gurl = content::GetFileUrlWithQuery(media::GetTestDataFilePath(html_page),
48 gurl = GetFileUrlWithQuery(test_file_path, query); 55 query);
49 } 56 }
50 RunTest(gurl, expected); 57 base::string16 final_title = RunTest(gurl, expected_title);
58 EXPECT_EQ(base::ASCIIToUTF16(expected_title), final_title);
51 } 59 }
52 60
53 void MediaBrowserTest::RunTest(const GURL& gurl, const char* expected) { 61 base::string16 MediaBrowserTest::RunTest(const GURL& gurl,
54 const base::string16 expected_title = base::ASCIIToUTF16(expected); 62 const std::string& expected_title) {
55 DVLOG(1) << "Running test URL: " << gurl; 63 VLOG(0) << "Running test URL: " << gurl;
56 TitleWatcher title_watcher(shell()->web_contents(), expected_title); 64 TitleWatcher title_watcher(shell()->web_contents(),
65 base::ASCIIToUTF16(expected_title));
57 AddWaitForTitles(&title_watcher); 66 AddWaitForTitles(&title_watcher);
58 NavigateToURL(shell(), gurl); 67 NavigateToURL(shell(), gurl);
59 68 return title_watcher.WaitAndGetTitle();
60 base::string16 final_title = title_watcher.WaitAndGetTitle();
61 EXPECT_EQ(expected_title, final_title);
62 } 69 }
63 70
64 void MediaBrowserTest::AddWaitForTitles(content::TitleWatcher* title_watcher) { 71 void MediaBrowserTest::AddWaitForTitles(content::TitleWatcher* title_watcher) {
65 title_watcher->AlsoWaitForTitle(base::ASCIIToUTF16(kEnded)); 72 title_watcher->AlsoWaitForTitle(base::ASCIIToUTF16(kEnded));
66 title_watcher->AlsoWaitForTitle(base::ASCIIToUTF16(kError)); 73 title_watcher->AlsoWaitForTitle(base::ASCIIToUTF16(kError));
67 title_watcher->AlsoWaitForTitle(base::ASCIIToUTF16(kFailed)); 74 title_watcher->AlsoWaitForTitle(base::ASCIIToUTF16(kFailed));
68 } 75 }
69 76
70 // Tests playback and seeking of an audio or video file over file or http based 77 // 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 78 // 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 79 // 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. 80 // test completes when either the last 'ended' or an 'error' event fires.
74 class MediaTest : public testing::WithParamInterface<bool>, 81 class MediaTest : public testing::WithParamInterface<bool>,
75 public MediaBrowserTest { 82 public MediaBrowserTest {
76 public: 83 public:
77 // Play specified audio over http:// or file:// depending on |http| setting. 84 // Play specified audio over http:// or file:// depending on |http| setting.
78 void PlayAudio(const char* media_file, bool http) { 85 void PlayAudio(const std::string& media_file, bool http) {
79 PlayMedia("audio", media_file, http); 86 PlayMedia("audio", media_file, http);
80 } 87 }
81 88
82 // Play specified video over http:// or file:// depending on |http| setting. 89 // Play specified video over http:// or file:// depending on |http| setting.
83 void PlayVideo(const char* media_file, bool http) { 90 void PlayVideo(const std::string& media_file, bool http) {
84 PlayMedia("video", media_file, http); 91 PlayMedia("video", media_file, http);
85 } 92 }
86 93
87 // Run specified color format test with the expected result. 94 // Run specified color format test with the expected result.
88 void RunColorFormatTest(const char* media_file, const char* expected) { 95 void RunColorFormatTest(const std::string& media_file,
89 base::FilePath test_file_path = GetTestFilePath("media", "blackwhite.html"); 96 const std::string& expected) {
97 base::FilePath test_file_path =
98 media::GetTestDataFilePath("blackwhite.html");
90 RunTest(GetFileUrlWithQuery(test_file_path, media_file), expected); 99 RunTest(GetFileUrlWithQuery(test_file_path, media_file), expected);
91 } 100 }
92 101
93 void PlayMedia(const char* tag, const char* media_file, bool http) { 102 void PlayMedia(const std::string& tag,
103 const std::string& media_file,
104 bool http) {
94 std::vector<StringPair> query_params; 105 std::vector<StringPair> query_params;
95 query_params.push_back(std::make_pair(tag, media_file)); 106 query_params.push_back(std::make_pair(tag, media_file));
96 RunMediaTestPage("player.html", &query_params, kEnded, http); 107 RunMediaTestPage("player.html", &query_params, kEnded, http);
97 } 108 }
98 }; 109 };
99 110
100 IN_PROC_BROWSER_TEST_P(MediaTest, VideoBearTheora) { 111 IN_PROC_BROWSER_TEST_P(MediaTest, VideoBearTheora) {
101 PlayVideo("bear.ogv", GetParam()); 112 PlayVideo("bear.ogv", GetParam());
102 } 113 }
103 114
(...skipping 29 matching lines...) Expand all
133 // While we support the big endian (be) PCM codecs on Chromium, Quicktime seems 144 // 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. 145 // 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. 146 // TODO(dalecurtis/ihf): Find or create some .wav test cases for "be" format.
136 IN_PROC_BROWSER_TEST_P(MediaTest, VideoBearMovPcmS16be) { 147 IN_PROC_BROWSER_TEST_P(MediaTest, VideoBearMovPcmS16be) {
137 PlayVideo("bear_pcm_s16be.mov", GetParam()); 148 PlayVideo("bear_pcm_s16be.mov", GetParam());
138 } 149 }
139 150
140 IN_PROC_BROWSER_TEST_P(MediaTest, VideoBearMovPcmS24be) { 151 IN_PROC_BROWSER_TEST_P(MediaTest, VideoBearMovPcmS24be) {
141 PlayVideo("bear_pcm_s24be.mov", GetParam()); 152 PlayVideo("bear_pcm_s24be.mov", GetParam());
142 } 153 }
143 #endif 154 #endif // defined(USE_PROPRIETARY_CODECS)
144 155
145 #if defined(OS_CHROMEOS) 156 #if defined(OS_CHROMEOS)
146 #if defined(USE_PROPRIETARY_CODECS) 157 #if defined(USE_PROPRIETARY_CODECS)
147 IN_PROC_BROWSER_TEST_P(MediaTest, VideoBearAviMp3Mpeg4) { 158 IN_PROC_BROWSER_TEST_P(MediaTest, VideoBearAviMp3Mpeg4) {
148 PlayVideo("bear_mpeg4_mp3.avi", GetParam()); 159 PlayVideo("bear_mpeg4_mp3.avi", GetParam());
149 } 160 }
150 161
151 IN_PROC_BROWSER_TEST_P(MediaTest, VideoBearAviMp3Mpeg4Asp) { 162 IN_PROC_BROWSER_TEST_P(MediaTest, VideoBearAviMp3Mpeg4Asp) {
152 PlayVideo("bear_mpeg4asp_mp3.avi", GetParam()); 163 PlayVideo("bear_mpeg4asp_mp3.avi", GetParam());
153 } 164 }
(...skipping 10 matching lines...) Expand all
164 PlayVideo("bear_mpeg4_amrnb.3gp", GetParam()); 175 PlayVideo("bear_mpeg4_amrnb.3gp", GetParam());
165 } 176 }
166 177
167 IN_PROC_BROWSER_TEST_P(MediaTest, VideoBearWavGsmms) { 178 IN_PROC_BROWSER_TEST_P(MediaTest, VideoBearWavGsmms) {
168 PlayAudio("bear_gsm_ms.wav", GetParam()); 179 PlayAudio("bear_gsm_ms.wav", GetParam());
169 } 180 }
170 181
171 IN_PROC_BROWSER_TEST_P(MediaTest, VideoBearFlac) { 182 IN_PROC_BROWSER_TEST_P(MediaTest, VideoBearFlac) {
172 PlayAudio("bear.flac", GetParam()); 183 PlayAudio("bear.flac", GetParam());
173 } 184 }
174 #endif 185 #endif // defined(USE_PROPRIETARY_CODECS)
175 #endif 186 #endif // defined(OS_CHROMEOS)
187
176 188
177 IN_PROC_BROWSER_TEST_P(MediaTest, VideoBearWavAlaw) { 189 IN_PROC_BROWSER_TEST_P(MediaTest, VideoBearWavAlaw) {
178 PlayAudio("bear_alaw.wav", GetParam()); 190 PlayAudio("bear_alaw.wav", GetParam());
179 } 191 }
180 192
181 IN_PROC_BROWSER_TEST_P(MediaTest, VideoBearWavMulaw) { 193 IN_PROC_BROWSER_TEST_P(MediaTest, VideoBearWavMulaw) {
182 PlayAudio("bear_mulaw.wav", GetParam()); 194 PlayAudio("bear_mulaw.wav", GetParam());
183 } 195 }
184 196
185 IN_PROC_BROWSER_TEST_P(MediaTest, VideoBearWavPcm) { 197 IN_PROC_BROWSER_TEST_P(MediaTest, VideoBearWavPcm) {
(...skipping 16 matching lines...) Expand all
202 IN_PROC_BROWSER_TEST_F(MediaTest, Navigate) { 214 IN_PROC_BROWSER_TEST_F(MediaTest, Navigate) {
203 PlayVideo("bear.ogv", false); 215 PlayVideo("bear.ogv", false);
204 NavigateToURL(shell(), GURL(url::kAboutBlankURL)); 216 NavigateToURL(shell(), GURL(url::kAboutBlankURL));
205 EXPECT_FALSE(shell()->web_contents()->IsCrashed()); 217 EXPECT_FALSE(shell()->web_contents()->IsCrashed());
206 } 218 }
207 219
208 INSTANTIATE_TEST_CASE_P(File, MediaTest, ::testing::Values(false)); 220 INSTANTIATE_TEST_CASE_P(File, MediaTest, ::testing::Values(false));
209 INSTANTIATE_TEST_CASE_P(Http, MediaTest, ::testing::Values(true)); 221 INSTANTIATE_TEST_CASE_P(Http, MediaTest, ::testing::Values(true));
210 222
211 IN_PROC_BROWSER_TEST_F(MediaTest, MAYBE(Yuv420pTheora)) { 223 IN_PROC_BROWSER_TEST_F(MediaTest, MAYBE(Yuv420pTheora)) {
212 RunColorFormatTest("yuv420p.ogv", "ENDED"); 224 RunColorFormatTest("yuv420p.ogv", "ENDED");
jrummell 2014/07/02 00:33:40 Shouldn't "ENDED" be kEnded? I know you didn't cha
shadi 2014/07/02 19:23:36 Done.
213 } 225 }
214 226
215 IN_PROC_BROWSER_TEST_F(MediaTest, MAYBE(Yuv422pTheora)) { 227 IN_PROC_BROWSER_TEST_F(MediaTest, MAYBE(Yuv422pTheora)) {
216 RunColorFormatTest("yuv422p.ogv", "ENDED"); 228 RunColorFormatTest("yuv422p.ogv", "ENDED");
217 } 229 }
218 230
219 IN_PROC_BROWSER_TEST_F(MediaTest, MAYBE(Yuv444pTheora)) { 231 IN_PROC_BROWSER_TEST_F(MediaTest, MAYBE(Yuv444pTheora)) {
220 RunColorFormatTest("yuv444p.ogv", "ENDED"); 232 RunColorFormatTest("yuv444p.ogv", "ENDED");
221 } 233 }
222 234
(...skipping 23 matching lines...) Expand all
246 } 258 }
247 259
248 #if defined(OS_CHROMEOS) 260 #if defined(OS_CHROMEOS)
249 IN_PROC_BROWSER_TEST_F(MediaTest, Yuv420pMpeg4) { 261 IN_PROC_BROWSER_TEST_F(MediaTest, Yuv420pMpeg4) {
250 RunColorFormatTest("yuv420p.avi", "ENDED"); 262 RunColorFormatTest("yuv420p.avi", "ENDED");
251 } 263 }
252 #endif // defined(OS_CHROMEOS) 264 #endif // defined(OS_CHROMEOS)
253 #endif // defined(USE_PROPRIETARY_CODECS) 265 #endif // defined(USE_PROPRIETARY_CODECS)
254 266
255 } // namespace content 267 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698