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

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

Issue 2660003003: Add MediaError.message (Closed)
Patch Set: Address dalecurtis@'s comment: undef STRINGIFY_STATUS_CASE Created 3 years, 8 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
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/command_line.h" 7 #include "base/command_line.h"
8 #include "base/strings/string_number_conversions.h" 8 #include "base/strings/string_number_conversions.h"
9 #include "base/strings/utf_string_conversions.h" 9 #include "base/strings/utf_string_conversions.h"
10 #include "build/build_config.h" 10 #include "build/build_config.h"
11 #include "content/public/browser/web_contents.h" 11 #include "content/public/browser/web_contents.h"
12 #include "content/public/common/content_switches.h" 12 #include "content/public/common/content_switches.h"
13 #include "content/public/test/browser_test_utils.h" 13 #include "content/public/test/browser_test_utils.h"
14 #include "content/public/test/content_browser_test_utils.h" 14 #include "content/public/test/content_browser_test_utils.h"
15 #include "content/shell/browser/shell.h" 15 #include "content/shell/browser/shell.h"
16 #include "media/base/media_switches.h" 16 #include "media/base/media_switches.h"
17 #include "media/base/test_data_util.h" 17 #include "media/base/test_data_util.h"
18 #include "media/media_features.h" 18 #include "media/media_features.h"
19 #include "net/test/embedded_test_server/embedded_test_server.h" 19 #include "net/test/embedded_test_server/embedded_test_server.h"
20 #include "url/url_util.h"
20 21
21 namespace content { 22 namespace content {
22 23
23 // TODO(sandersd): Change the tests to use a more unique message. 24 // TODO(sandersd): Change the tests to use a more unique message.
24 // See http://crbug.com/592067 25 // See http://crbug.com/592067
25 26
26 // Common test results. 27 // Common test results.
27 const char MediaBrowserTest::kFailed[] = "FAILED"; 28 const char MediaBrowserTest::kFailed[] = "FAILED";
28 29
29 // Upper case event name set by Utils.installTitleEventHandler(). 30 // Upper case event name set by Utils.installTitleEventHandler().
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
63 const std::string& expected_title) { 64 const std::string& expected_title) {
64 VLOG(0) << "Running test URL: " << gurl; 65 VLOG(0) << "Running test URL: " << gurl;
65 TitleWatcher title_watcher(shell()->web_contents(), 66 TitleWatcher title_watcher(shell()->web_contents(),
66 base::ASCIIToUTF16(expected_title)); 67 base::ASCIIToUTF16(expected_title));
67 AddTitlesToAwait(&title_watcher); 68 AddTitlesToAwait(&title_watcher);
68 NavigateToURL(shell(), gurl); 69 NavigateToURL(shell(), gurl);
69 base::string16 result = title_watcher.WaitAndGetTitle(); 70 base::string16 result = title_watcher.WaitAndGetTitle();
70 return base::UTF16ToASCII(result); 71 return base::UTF16ToASCII(result);
71 } 72 }
72 73
74 std::string MediaBrowserTest::EncodeErrorMessage(
75 const std::string& original_message) {
76 url::RawCanonOutputT<char> buffer;
77 url::EncodeURIComponent(original_message.data(), original_message.size(),
78 &buffer);
79 return std::string(buffer.data(), buffer.length());
80 }
81
73 void MediaBrowserTest::AddTitlesToAwait(content::TitleWatcher* title_watcher) { 82 void MediaBrowserTest::AddTitlesToAwait(content::TitleWatcher* title_watcher) {
74 title_watcher->AlsoWaitForTitle(base::ASCIIToUTF16(kEnded)); 83 title_watcher->AlsoWaitForTitle(base::ASCIIToUTF16(kEnded));
75 title_watcher->AlsoWaitForTitle(base::ASCIIToUTF16(kError)); 84 title_watcher->AlsoWaitForTitle(base::ASCIIToUTF16(kError));
76 title_watcher->AlsoWaitForTitle(base::ASCIIToUTF16(kErrorEvent)); 85 title_watcher->AlsoWaitForTitle(base::ASCIIToUTF16(kErrorEvent));
77 title_watcher->AlsoWaitForTitle(base::ASCIIToUTF16(kFailed)); 86 title_watcher->AlsoWaitForTitle(base::ASCIIToUTF16(kFailed));
78 } 87 }
79 88
80 // Tests playback and seeking of an audio or video file over file or http based 89 // Tests playback and seeking of an audio or video file over file or http based
81 // on a test parameter. Test starts with playback, then, after X seconds or the 90 // on a test parameter. Test starts with playback, then, after X seconds or the
82 // ended event fires, seeks near end of file; see player.html for details. The 91 // ended event fires, seeks near end of file; see player.html for details. The
(...skipping 12 matching lines...) Expand all
95 } 104 }
96 105
97 void PlayMedia(const std::string& tag, 106 void PlayMedia(const std::string& tag,
98 const std::string& media_file, 107 const std::string& media_file,
99 bool http) { 108 bool http) {
100 base::StringPairs query_params; 109 base::StringPairs query_params;
101 query_params.push_back(std::make_pair(tag, media_file)); 110 query_params.push_back(std::make_pair(tag, media_file));
102 RunMediaTestPage("player.html", query_params, kEnded, http); 111 RunMediaTestPage("player.html", query_params, kEnded, http);
103 } 112 }
104 113
114 void RunErrorMessageTest(const std::string& tag,
115 const std::string& media_file,
116 const std::string& expected_error_substring,
117 bool http) {
118 base::StringPairs query_params;
119 query_params.push_back(std::make_pair(tag, media_file));
120 query_params.push_back(std::make_pair(
121 "error_substr", EncodeErrorMessage(expected_error_substring)));
122 RunMediaTestPage("player.html", query_params, kErrorEvent, http);
123 }
124
105 void RunVideoSizeTest(const char* media_file, int width, int height) { 125 void RunVideoSizeTest(const char* media_file, int width, int height) {
106 std::string expected; 126 std::string expected;
107 expected += base::IntToString(width); 127 expected += base::IntToString(width);
108 expected += " "; 128 expected += " ";
109 expected += base::IntToString(height); 129 expected += base::IntToString(height);
110 base::StringPairs query_params; 130 base::StringPairs query_params;
111 query_params.push_back(std::make_pair("video", media_file)); 131 query_params.push_back(std::make_pair("video", media_file));
112 RunMediaTestPage("player.html", query_params, expected, false); 132 RunMediaTestPage("player.html", query_params, expected, false);
113 } 133 }
114 }; 134 };
(...skipping 137 matching lines...) Expand 10 before | Expand all | Expand 10 after
252 } 272 }
253 273
254 IN_PROC_BROWSER_TEST_P(MediaTest, VideoBearWavPcm192kHz) { 274 IN_PROC_BROWSER_TEST_P(MediaTest, VideoBearWavPcm192kHz) {
255 PlayAudio("bear_192kHz.wav", GetParam()); 275 PlayAudio("bear_192kHz.wav", GetParam());
256 } 276 }
257 277
258 IN_PROC_BROWSER_TEST_P(MediaTest, VideoTulipWebm) { 278 IN_PROC_BROWSER_TEST_P(MediaTest, VideoTulipWebm) {
259 PlayVideo("tulip2.webm", GetParam()); 279 PlayVideo("tulip2.webm", GetParam());
260 } 280 }
261 281
282 IN_PROC_BROWSER_TEST_P(MediaTest, VideoErrorMissingResource) {
283 RunErrorMessageTest("video", "nonexistent_file.webm",
284 "MEDIA_ELEMENT_ERROR: Format error", GetParam());
285 }
286
287 IN_PROC_BROWSER_TEST_P(MediaTest, VideoErrorEmptySrcAttribute) {
288 RunErrorMessageTest("video", "", "MEDIA_ELEMENT_ERROR: Empty src attribute",
289 GetParam());
290 }
291
292 IN_PROC_BROWSER_TEST_P(MediaTest, VideoErrorNoSupportedStreams) {
293 RunErrorMessageTest(
294 "video", "no_streams.webm",
295 "DEMUXER_ERROR_NO_SUPPORTED_STREAMS: FFmpegDemuxer: no supported streams",
296 GetParam());
297 }
298
262 // Covers tear-down when navigating away as opposed to browser exiting. 299 // Covers tear-down when navigating away as opposed to browser exiting.
263 IN_PROC_BROWSER_TEST_F(MediaTest, Navigate) { 300 IN_PROC_BROWSER_TEST_F(MediaTest, Navigate) {
264 PlayVideo("bear.webm", false); 301 PlayVideo("bear.webm", false);
265 NavigateToURL(shell(), GURL(url::kAboutBlankURL)); 302 NavigateToURL(shell(), GURL(url::kAboutBlankURL));
266 EXPECT_FALSE(shell()->web_contents()->IsCrashed()); 303 EXPECT_FALSE(shell()->web_contents()->IsCrashed());
267 } 304 }
268 305
269 INSTANTIATE_TEST_CASE_P(File, MediaTest, ::testing::Values(false)); 306 INSTANTIATE_TEST_CASE_P(File, MediaTest, ::testing::Values(false));
270 INSTANTIATE_TEST_CASE_P(Http, MediaTest, ::testing::Values(true)); 307 INSTANTIATE_TEST_CASE_P(Http, MediaTest, ::testing::Values(true));
271 308
272 } // namespace content 309 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698