| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 "base/basictypes.h" | 5 #include "base/basictypes.h" |
| 6 #include "base/command_line.h" | 6 #include "base/command_line.h" |
| 7 #include "base/string16.h" | 7 #include "base/string16.h" |
| 8 #include "base/stringprintf.h" | 8 #include "base/stringprintf.h" |
| 9 #include "base/string_util.h" | 9 #include "base/string_util.h" |
| 10 #include "base/utf_string_conversions.h" | 10 #include "base/utf_string_conversions.h" |
| 11 #include "content/public/common/content_switches.h" | 11 #include "content/public/common/content_switches.h" |
| 12 #include "content/public/test/browser_test_utils.h" | 12 #include "content/public/test/browser_test_utils.h" |
| 13 #include "content/shell/shell.h" | 13 #include "content/shell/shell.h" |
| 14 #include "content/test/layout_browsertest.h" | 14 #include "content/test/layout_browsertest.h" |
| 15 #include "content/test/content_browser_test_utils.h" | 15 #include "content/test/content_browser_test_utils.h" |
| 16 #include "googleurl/src/gurl.h" | 16 #include "googleurl/src/gurl.h" |
| 17 | 17 |
| 18 namespace content { | |
| 19 | |
| 20 // Tests playback and seeking of an audio or video file over file or http based | 18 // Tests playback and seeking of an audio or video file over file or http based |
| 21 // on a test parameter. Test starts with playback, then, after X seconds or the | 19 // on a test parameter. Test starts with playback, then, after X seconds or the |
| 22 // ended event fires, seeks near end of file; see player.html for details. The | 20 // ended event fires, seeks near end of file; see player.html for details. The |
| 23 // test completes when either the last 'ended' or an 'error' event fires. | 21 // test completes when either the last 'ended' or an 'error' event fires. |
| 24 class MediaTest : public testing::WithParamInterface<bool>, | 22 class MediaTest |
| 25 public ContentBrowserTest { | 23 : public testing::WithParamInterface<bool>, |
| 24 public content::ContentBrowserTest { |
| 26 public: | 25 public: |
| 27 // Play specified audio over http:// or file:// depending on |http| setting. | 26 // Play specified audio over http:// or file:// depending on |http| setting. |
| 28 void PlayAudio(const char* media_file, bool http) { | 27 void PlayAudio(const char* media_file, bool http) { |
| 29 ASSERT_NO_FATAL_FAILURE(PlayMedia("audio", media_file, http)); | 28 ASSERT_NO_FATAL_FAILURE(PlayMedia("audio", media_file, http)); |
| 30 } | 29 } |
| 31 | 30 |
| 32 // Play specified video over http:// or file:// depending on |http| setting. | 31 // Play specified video over http:// or file:// depending on |http| setting. |
| 33 void PlayVideo(const char* media_file, bool http) { | 32 void PlayVideo(const char* media_file, bool http) { |
| 34 ASSERT_NO_FATAL_FAILURE(PlayMedia("video", media_file, http)); | 33 ASSERT_NO_FATAL_FAILURE(PlayMedia("video", media_file, http)); |
| 35 } | 34 } |
| 36 | 35 |
| 37 protected: | 36 protected: |
| 38 virtual void SetUpCommandLine(CommandLine* command_line) OVERRIDE { | 37 virtual void SetUpCommandLine(CommandLine* command_line) OVERRIDE { |
| 39 // TODO(dalecurtis): Not all Buildbots have viable audio devices, so disable | 38 // TODO(dalecurtis): Not all Buildbots have viable audio devices, so disable |
| 40 // audio to prevent tests from hanging; e.g., a device which is hardware | 39 // audio to prevent tests from hanging; e.g., a device which is hardware |
| 41 // muted. See http://crbug.com/120749 | 40 // muted. See http://crbug.com/120749 |
| 42 command_line->AppendSwitch(switches::kDisableAudio); | 41 command_line->AppendSwitch(switches::kDisableAudio); |
| 43 } | 42 } |
| 44 | 43 |
| 45 private: | 44 private: |
| 46 GURL GetTestURL(const char* tag, const char* media_file, bool http) { | 45 GURL GetTestURL(const char* tag, const char* media_file, bool http) { |
| 47 if (http) { | 46 if (http) { |
| 48 return test_server()->GetURL( | 47 return test_server()->GetURL( |
| 49 base::StringPrintf("files/media/player.html?%s=%s", tag, media_file)); | 48 base::StringPrintf("files/media/player.html?%s=%s", tag, media_file)); |
| 50 } | 49 } |
| 51 | 50 |
| 52 FilePath test_file_path = GetTestFilePath("media", "player.html"); | 51 FilePath test_file_path = content::GetTestFilePath("media", "player.html"); |
| 53 std::string query = base::StringPrintf("%s=%s", tag, media_file); | 52 std::string query = base::StringPrintf("%s=%s", tag, media_file); |
| 54 return GetFileUrlWithQuery(test_file_path, query); | 53 return content::GetFileUrlWithQuery(test_file_path, query); |
| 55 } | 54 } |
| 56 | 55 |
| 57 void PlayMedia(const char* tag, const char* media_file, bool http) { | 56 void PlayMedia(const char* tag, const char* media_file, bool http) { |
| 58 if (http) | 57 if (http) |
| 59 ASSERT_TRUE(test_server()->Start()); | 58 ASSERT_TRUE(test_server()->Start()); |
| 60 | 59 |
| 61 GURL player_gurl = GetTestURL(tag, media_file, http); | 60 GURL player_gurl = GetTestURL(tag, media_file, http); |
| 62 | 61 |
| 63 // Allow the media file to be loaded. | 62 // Allow the media file to be loaded. |
| 64 const string16 kEnded = ASCIIToUTF16("ENDED"); | 63 const string16 kEnded = ASCIIToUTF16("ENDED"); |
| 65 const string16 kError = ASCIIToUTF16("ERROR"); | 64 const string16 kError = ASCIIToUTF16("ERROR"); |
| 66 const string16 kFailed = ASCIIToUTF16("FAILED"); | 65 const string16 kFailed = ASCIIToUTF16("FAILED"); |
| 67 TitleWatcher title_watcher(shell()->web_contents(), kEnded); | 66 content::TitleWatcher title_watcher(shell()->web_contents(), kEnded); |
| 68 title_watcher.AlsoWaitForTitle(kFailed); | 67 title_watcher.AlsoWaitForTitle(kFailed); |
| 69 title_watcher.AlsoWaitForTitle(kError); | 68 title_watcher.AlsoWaitForTitle(kError); |
| 70 | 69 |
| 71 NavigateToURL(shell(), player_gurl); | 70 content::NavigateToURL(shell(), player_gurl); |
| 72 | 71 |
| 73 string16 final_title = title_watcher.WaitAndGetTitle(); | 72 string16 final_title = title_watcher.WaitAndGetTitle(); |
| 74 EXPECT_EQ(kEnded, final_title); | 73 EXPECT_EQ(kEnded, final_title); |
| 75 } | 74 } |
| 76 }; | 75 }; |
| 77 | 76 |
| 78 IN_PROC_BROWSER_TEST_P(MediaTest, VideoBearTheora) { | 77 IN_PROC_BROWSER_TEST_P(MediaTest, VideoBearTheora) { |
| 79 PlayVideo("bear.ogv", GetParam()); | 78 PlayVideo("bear.ogv", GetParam()); |
| 80 } | 79 } |
| 81 | 80 |
| (...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 186 RunLayoutTest("video-autoplay.html"); | 185 RunLayoutTest("video-autoplay.html"); |
| 187 } | 186 } |
| 188 | 187 |
| 189 IN_PROC_BROWSER_TEST_F(MediaLayoutTest, VideoLoopTest) { | 188 IN_PROC_BROWSER_TEST_F(MediaLayoutTest, VideoLoopTest) { |
| 190 RunLayoutTest("video-loop.html"); | 189 RunLayoutTest("video-loop.html"); |
| 191 } | 190 } |
| 192 | 191 |
| 193 IN_PROC_BROWSER_TEST_F(MediaLayoutTest, VideoNoAutoplayTest) { | 192 IN_PROC_BROWSER_TEST_F(MediaLayoutTest, VideoNoAutoplayTest) { |
| 194 RunLayoutTest("video-no-autoplay.html"); | 193 RunLayoutTest("video-no-autoplay.html"); |
| 195 } | 194 } |
| 196 | |
| 197 } // namespace content | |
| OLD | NEW |