Chromium Code Reviews| 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/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 Loading... | |
| 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( | |
|
mlamouri (slow - plz ping)
2017/04/12 15:56:41
Where is this called?
wolenetz
2017/04/13 23:59:10
Oops! :) Especially with newlines in the message,
| |
| 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 Loading... | |
| 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 TestErrorMessage(const std::string& tag, | |
|
sandersd (OOO until July 31)
2017/04/12 01:09:37
Rename as RunErrorMessageTest to match other varia
wolenetz
2017/04/13 23:59:10
Done.
| |
| 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( | |
| 121 std::make_pair("error_substr", 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 Loading... | |
| 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 TestErrorMessage("video", "nonexistent_file.webm", | |
| 284 "{\"MediaElementError\":[\"Format error\"]}", GetParam()); | |
| 285 } | |
| 286 | |
| 287 IN_PROC_BROWSER_TEST_P(MediaTest, VideoErrorEmptySrcAttribute) { | |
| 288 TestErrorMessage("video", "", | |
| 289 "{\"MediaElementError\":[\"Empty src attribute\"]}", | |
| 290 GetParam()); | |
| 291 } | |
| 292 | |
| 293 IN_PROC_BROWSER_TEST_P(MediaTest, VideoNoSupportedStreams) { | |
| 294 TestErrorMessage("video", "no_streams.webm", | |
| 295 "{\"MEDIA_ERROR_LOG_ENTRY\":[\"{\\\"error\\\":" | |
| 296 "\\\"FFmpegDemuxer: no supported " | |
| 297 "streams\\\"}\"],\"PIPELINE_ERROR\":[\"demuxer: no " | |
| 298 "supported streams\"]}", | |
|
sandersd (OOO until July 31)
2017/04/12 01:09:37
This format seems overly complex and exposes rathe
wolenetz
2017/04/13 23:59:10
Done. See related discussion thread https://codere
| |
| 299 GetParam()); | |
| 300 } | |
| 301 | |
| 262 // Covers tear-down when navigating away as opposed to browser exiting. | 302 // Covers tear-down when navigating away as opposed to browser exiting. |
| 263 IN_PROC_BROWSER_TEST_F(MediaTest, Navigate) { | 303 IN_PROC_BROWSER_TEST_F(MediaTest, Navigate) { |
| 264 PlayVideo("bear.webm", false); | 304 PlayVideo("bear.webm", false); |
| 265 NavigateToURL(shell(), GURL(url::kAboutBlankURL)); | 305 NavigateToURL(shell(), GURL(url::kAboutBlankURL)); |
| 266 EXPECT_FALSE(shell()->web_contents()->IsCrashed()); | 306 EXPECT_FALSE(shell()->web_contents()->IsCrashed()); |
| 267 } | 307 } |
| 268 | 308 |
| 269 INSTANTIATE_TEST_CASE_P(File, MediaTest, ::testing::Values(false)); | 309 INSTANTIATE_TEST_CASE_P(File, MediaTest, ::testing::Values(false)); |
| 270 INSTANTIATE_TEST_CASE_P(Http, MediaTest, ::testing::Values(true)); | 310 INSTANTIATE_TEST_CASE_P(Http, MediaTest, ::testing::Values(true)); |
| 271 | 311 |
| 272 } // namespace content | 312 } // namespace content |
| OLD | NEW |