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