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/string16.h" | 7 #include "base/string16.h" |
7 #include "base/stringprintf.h" | 8 #include "base/stringprintf.h" |
8 #include "base/string_util.h" | 9 #include "base/string_util.h" |
9 #include "base/utf_string_conversions.h" | 10 #include "base/utf_string_conversions.h" |
| 11 #include "content/public/common/content_switches.h" |
10 #include "content/public/test/browser_test_utils.h" | 12 #include "content/public/test/browser_test_utils.h" |
11 #include "content/shell/shell.h" | 13 #include "content/shell/shell.h" |
12 #include "content/test/layout_browsertest.h" | 14 #include "content/test/layout_browsertest.h" |
13 #include "content/test/content_browser_test_utils.h" | 15 #include "content/test/content_browser_test_utils.h" |
14 #include "googleurl/src/gurl.h" | 16 #include "googleurl/src/gurl.h" |
15 | 17 |
16 class MediaTest : public content::ContentBrowserTest { | 18 // 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 |
| 20 // 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. |
| 22 class MediaTest |
| 23 : public testing::WithParamInterface<bool>, |
| 24 public content::ContentBrowserTest { |
| 25 public: |
| 26 // Play specified audio over http:// or file:// depending on |http| setting. |
| 27 void PlayAudio(const char* media_file, bool http) { |
| 28 ASSERT_NO_FATAL_FAILURE(PlayMedia("audio", media_file, http)); |
| 29 } |
| 30 |
| 31 // Play specified video over http:// or file:// depending on |http| setting. |
| 32 void PlayVideo(const char* media_file, bool http) { |
| 33 ASSERT_NO_FATAL_FAILURE(PlayMedia("video", media_file, http)); |
| 34 } |
| 35 |
17 protected: | 36 protected: |
18 GURL GetTestURL(const char* tag, const char* media_file) { | 37 virtual void SetUpCommandLine(CommandLine* command_line) OVERRIDE { |
| 38 // 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 // muted. See http://crbug.com/120749 |
| 41 command_line->AppendSwitch(switches::kDisableAudio); |
| 42 } |
| 43 |
| 44 private: |
| 45 GURL GetTestURL(const char* tag, const char* media_file, bool http) { |
| 46 if (http) { |
| 47 return test_server()->GetURL( |
| 48 base::StringPrintf("files/media/player.html?%s=%s", tag, media_file)); |
| 49 } |
| 50 |
19 FilePath test_file_path = content::GetTestFilePath("media", "player.html"); | 51 FilePath test_file_path = content::GetTestFilePath("media", "player.html"); |
20 std::string query = base::StringPrintf("%s=%s", tag, media_file); | 52 std::string query = base::StringPrintf("%s=%s", tag, media_file); |
21 return content::GetFileUrlWithQuery(test_file_path, query); | 53 return content::GetFileUrlWithQuery(test_file_path, query); |
22 } | 54 } |
23 | 55 |
24 void PlayMedia(const char* tag, const char* media_file) { | 56 void PlayMedia(const char* tag, const char* media_file, bool http) { |
25 GURL player_gurl = GetTestURL(tag, media_file); | 57 if (http) |
| 58 ASSERT_TRUE(test_server()->Start()); |
| 59 |
| 60 GURL player_gurl = GetTestURL(tag, media_file, http); |
26 | 61 |
27 // Allow the media file to be loaded. | 62 // Allow the media file to be loaded. |
28 const string16 kPlaying = ASCIIToUTF16("PLAYING"); | 63 const string16 kEnded = ASCIIToUTF16("ENDED"); |
| 64 const string16 kError = ASCIIToUTF16("ERROR"); |
29 const string16 kFailed = ASCIIToUTF16("FAILED"); | 65 const string16 kFailed = ASCIIToUTF16("FAILED"); |
30 const string16 kError = ASCIIToUTF16("ERROR"); | 66 content::TitleWatcher title_watcher(shell()->web_contents(), kEnded); |
31 content::TitleWatcher title_watcher(shell()->web_contents(), kPlaying); | |
32 title_watcher.AlsoWaitForTitle(kFailed); | 67 title_watcher.AlsoWaitForTitle(kFailed); |
33 title_watcher.AlsoWaitForTitle(kError); | 68 title_watcher.AlsoWaitForTitle(kError); |
34 | 69 |
35 content::NavigateToURL(shell(), player_gurl); | 70 content::NavigateToURL(shell(), player_gurl); |
36 | 71 |
37 string16 final_title = title_watcher.WaitAndGetTitle(); | 72 string16 final_title = title_watcher.WaitAndGetTitle(); |
38 EXPECT_EQ(kPlaying, final_title); | 73 EXPECT_EQ(kEnded, final_title); |
39 } | |
40 | |
41 void PlayAudio(const char* url) { | |
42 PlayMedia("audio", url); | |
43 } | |
44 | |
45 void PlayVideo(const char* url) { | |
46 PlayMedia("video", url); | |
47 } | 74 } |
48 }; | 75 }; |
49 | 76 |
50 IN_PROC_BROWSER_TEST_F(MediaTest, VideoBearTheora) { | 77 IN_PROC_BROWSER_TEST_P(MediaTest, VideoBearTheora) { |
51 PlayVideo("bear.ogv"); | 78 PlayVideo("bear.ogv", GetParam()); |
52 } | 79 } |
53 | 80 |
54 IN_PROC_BROWSER_TEST_F(MediaTest, VideoBearSilentTheora) { | 81 IN_PROC_BROWSER_TEST_P(MediaTest, VideoBearSilentTheora) { |
55 PlayVideo("bear_silent.ogv"); | 82 PlayVideo("bear_silent.ogv", GetParam()); |
56 } | 83 } |
57 | 84 |
58 IN_PROC_BROWSER_TEST_F(MediaTest, VideoBearWebm) { | 85 IN_PROC_BROWSER_TEST_P(MediaTest, VideoBearWebm) { |
59 PlayVideo("bear.webm"); | 86 PlayVideo("bear.webm", GetParam()); |
60 } | 87 } |
61 | 88 |
62 IN_PROC_BROWSER_TEST_F(MediaTest, VideoBearSilentWebm) { | 89 IN_PROC_BROWSER_TEST_P(MediaTest, VideoBearSilentWebm) { |
63 PlayVideo("bear_silent.webm"); | 90 PlayVideo("bear_silent.webm", GetParam()); |
64 } | 91 } |
65 | 92 |
66 #if defined(GOOGLE_CHROME_BUILD) || defined(USE_PROPRIETARY_CODECS) | 93 #if defined(GOOGLE_CHROME_BUILD) || defined(USE_PROPRIETARY_CODECS) |
67 IN_PROC_BROWSER_TEST_F(MediaTest, VideoBearMp4) { | 94 IN_PROC_BROWSER_TEST_P(MediaTest, VideoBearMp4) { |
68 PlayVideo("bear.mp4"); | 95 PlayVideo("bear.mp4", GetParam()); |
69 } | 96 } |
70 | 97 |
71 IN_PROC_BROWSER_TEST_F(MediaTest, VideoBearSilentMp4) { | 98 IN_PROC_BROWSER_TEST_P(MediaTest, VideoBearSilentMp4) { |
72 PlayVideo("bear_silent.mp4"); | 99 PlayVideo("bear_silent.mp4", GetParam()); |
| 100 } |
| 101 |
| 102 // While we support the big endian (be) PCM codecs on Chromium, Quicktime seems |
| 103 // to be the only creator of this format and only for .mov files. |
| 104 // TODO(dalecurtis/ihf): Find or create some .wav test cases for "be" format. |
| 105 IN_PROC_BROWSER_TEST_P(MediaTest, VideoBearMovPcmS16be) { |
| 106 PlayVideo("bear_pcm_s16be.mov", GetParam()); |
| 107 } |
| 108 |
| 109 IN_PROC_BROWSER_TEST_P(MediaTest, VideoBearMovPcmS24be) { |
| 110 PlayVideo("bear_pcm_s24be.mov", GetParam()); |
73 } | 111 } |
74 #endif | 112 #endif |
75 | 113 |
76 #if defined(OS_CHROMEOS) | 114 #if defined(OS_CHROMEOS) |
77 #if defined(GOOGLE_CHROME_BUILD) || defined(USE_PROPRIETARY_CODECS) | 115 #if defined(GOOGLE_CHROME_BUILD) || defined(USE_PROPRIETARY_CODECS) |
78 IN_PROC_BROWSER_TEST_F(MediaTest, VideoBearAviMp3Mpeg4) { | 116 IN_PROC_BROWSER_TEST_P(MediaTest, VideoBearAviMp3Mpeg4) { |
79 PlayVideo("bear_mpeg4_mp3.avi"); | 117 PlayVideo("bear_mpeg4_mp3.avi", GetParam()); |
80 } | 118 } |
81 | 119 |
82 IN_PROC_BROWSER_TEST_F(MediaTest, VideoBearAviMp3Divx) { | 120 IN_PROC_BROWSER_TEST_P(MediaTest, VideoBearAviMp3Divx) { |
83 PlayVideo("bear_divx_mp3.avi"); | 121 PlayVideo("bear_divx_mp3.avi", GetParam()); |
84 } | 122 } |
85 | 123 |
86 IN_PROC_BROWSER_TEST_F(MediaTest, VideoBear3gpAacH264) { | 124 IN_PROC_BROWSER_TEST_P(MediaTest, VideoBear3gpAacH264) { |
87 PlayVideo("bear_h264_aac.3gp"); | 125 PlayVideo("bear_h264_aac.3gp", GetParam()); |
88 } | 126 } |
89 | 127 |
90 IN_PROC_BROWSER_TEST_F(MediaTest, VideoBear3gpAmrnbMpeg4) { | 128 IN_PROC_BROWSER_TEST_P(MediaTest, VideoBear3gpAmrnbMpeg4) { |
91 PlayVideo("bear_mpeg4_amrnb.3gp"); | 129 PlayVideo("bear_mpeg4_amrnb.3gp", GetParam()); |
92 } | 130 } |
93 | 131 |
94 IN_PROC_BROWSER_TEST_F(MediaTest, VideoBearWavGsmms) { | 132 IN_PROC_BROWSER_TEST_F(MediaTest, VideoBearWavGsmms) { |
95 PlayAudio("bear_gsm_ms.wav"); | 133 PlayAudio("bear_gsm_ms.wav", GetParam()); |
96 } | 134 } |
97 | 135 |
98 IN_PROC_BROWSER_TEST_F(MediaTest, VideoBearWavMulaw) { | 136 IN_PROC_BROWSER_TEST_P(MediaTest, VideoBearWavMulaw) { |
99 PlayAudio("bear_mulaw.wav"); | 137 PlayAudio("bear_mulaw.wav", GetParam()); |
100 } | 138 } |
101 | 139 |
102 IN_PROC_BROWSER_TEST_F(MediaTest, VideoBearMovPcmS16be) { | 140 IN_PROC_BROWSER_TEST_P(MediaTest, VideoBearFlac) { |
103 PlayVideo("bear_pcm_s16be.mov"); | 141 PlayAudio("bear.flac", GetParam()); |
104 } | |
105 | |
106 IN_PROC_BROWSER_TEST_F(MediaTest, VideoBearMovPcmS24be) { | |
107 PlayVideo("bear_pcm_s24be.mov"); | |
108 } | |
109 | |
110 IN_PROC_BROWSER_TEST_F(MediaTest, VideoBearFlac) { | |
111 PlayAudio("bear.flac"); | |
112 } | 142 } |
113 #endif | 143 #endif |
114 #endif | 144 #endif |
115 | 145 |
116 IN_PROC_BROWSER_TEST_F(MediaTest, VideoBearWavPcm) { | 146 IN_PROC_BROWSER_TEST_P(MediaTest, VideoBearWavPcm) { |
117 PlayAudio("bear_pcm.wav"); | 147 PlayAudio("bear_pcm.wav", GetParam()); |
118 } | 148 } |
119 | 149 |
| 150 IN_PROC_BROWSER_TEST_P(MediaTest, VideoTulipWebm) { |
| 151 PlayVideo("tulip2.webm", GetParam()); |
| 152 } |
| 153 |
| 154 INSTANTIATE_TEST_CASE_P(File, MediaTest, ::testing::Values(false)); |
| 155 INSTANTIATE_TEST_CASE_P(Http, MediaTest, ::testing::Values(true)); |
| 156 |
120 class MediaLayoutTest : public InProcessBrowserLayoutTest { | 157 class MediaLayoutTest : public InProcessBrowserLayoutTest { |
121 protected: | 158 protected: |
122 MediaLayoutTest() : InProcessBrowserLayoutTest( | 159 MediaLayoutTest() : InProcessBrowserLayoutTest( |
123 FilePath(), FilePath().AppendASCII("media")) { | 160 FilePath(), FilePath().AppendASCII("media")) { |
124 } | 161 } |
125 virtual ~MediaLayoutTest() {} | 162 virtual ~MediaLayoutTest() {} |
126 | 163 |
| 164 virtual void SetUpCommandLine(CommandLine* command_line) OVERRIDE { |
| 165 // TODO(dalecurtis): Not all Buildbots have viable audio devices, so disable |
| 166 // audio to prevent tests from hanging; e.g., a device which is hardware |
| 167 // muted. See http://crbug.com/120749 |
| 168 command_line->AppendSwitch(switches::kDisableAudio); |
| 169 } |
| 170 |
127 virtual void SetUpInProcessBrowserTestFixture() OVERRIDE { | 171 virtual void SetUpInProcessBrowserTestFixture() OVERRIDE { |
128 InProcessBrowserLayoutTest::SetUpInProcessBrowserTestFixture(); | 172 InProcessBrowserLayoutTest::SetUpInProcessBrowserTestFixture(); |
129 AddResourceForLayoutTest(FilePath().AppendASCII("media"), | 173 AddResourceForLayoutTest(FilePath().AppendASCII("media"), |
130 FilePath().AppendASCII("content")); | 174 FilePath().AppendASCII("content")); |
131 AddResourceForLayoutTest(FilePath().AppendASCII("media"), | 175 AddResourceForLayoutTest(FilePath().AppendASCII("media"), |
132 FilePath().AppendASCII("media-file.js")); | 176 FilePath().AppendASCII("media-file.js")); |
133 AddResourceForLayoutTest(FilePath().AppendASCII("media"), | 177 AddResourceForLayoutTest(FilePath().AppendASCII("media"), |
134 FilePath().AppendASCII("media-fullscreen.js")); | 178 FilePath().AppendASCII("media-fullscreen.js")); |
135 AddResourceForLayoutTest(FilePath().AppendASCII("media"), | 179 AddResourceForLayoutTest(FilePath().AppendASCII("media"), |
136 FilePath().AppendASCII("video-paint-test.js")); | 180 FilePath().AppendASCII("video-paint-test.js")); |
137 AddResourceForLayoutTest(FilePath().AppendASCII("media"), | 181 AddResourceForLayoutTest(FilePath().AppendASCII("media"), |
138 FilePath().AppendASCII("video-played.js")); | 182 FilePath().AppendASCII("video-played.js")); |
139 AddResourceForLayoutTest(FilePath().AppendASCII("media"), | 183 AddResourceForLayoutTest(FilePath().AppendASCII("media"), |
140 FilePath().AppendASCII("video-test.js")); | 184 FilePath().AppendASCII("video-test.js")); |
141 } | 185 } |
142 }; | 186 }; |
143 | 187 |
144 // Each browser test can only correspond to a single layout test, otherwise the | 188 // Each browser test can only correspond to a single layout test, otherwise the |
145 // 45 second timeout per test is not long enough for N tests on debug/asan/etc | 189 // 45 second timeout per test is not long enough for N tests on debug/asan/etc |
146 // builds. | 190 // builds. |
147 | 191 |
148 IN_PROC_BROWSER_TEST_F(MediaLayoutTest, VideoAutoplayTest) { | 192 IN_PROC_BROWSER_TEST_F(MediaLayoutTest, VideoAutoplayTest) { |
149 RunLayoutTest("video-autoplay.html"); | 193 RunLayoutTest("video-autoplay.html"); |
150 } | 194 } |
151 | 195 |
152 // TODO(dalecurtis): Disabled because loop is flaky. http://crbug.com/134021 | 196 IN_PROC_BROWSER_TEST_F(MediaLayoutTest, VideoLoopTest) { |
153 // IN_PROC_BROWSER_TEST_F(MediaLayoutTest, VideoLoopTest) { | 197 RunLayoutTest("video-loop.html"); |
154 // RunLayoutTest("video-loop.html"); | 198 } |
155 // } | |
156 | 199 |
157 IN_PROC_BROWSER_TEST_F(MediaLayoutTest, VideoNoAutoplayTest) { | 200 IN_PROC_BROWSER_TEST_F(MediaLayoutTest, VideoNoAutoplayTest) { |
158 RunLayoutTest("video-no-autoplay.html"); | 201 RunLayoutTest("video-no-autoplay.html"); |
159 } | 202 } |
OLD | NEW |