| 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/file_path.h" | 6 #include "base/string16.h" |
| 7 #include "base/stringprintf.h" | 7 #include "base/stringprintf.h" |
| 8 #include "base/string_util.h" | 8 #include "base/string_util.h" |
| 9 #include "base/test/test_timeouts.h" | 9 #include "base/utf_string_conversions.h" |
| 10 #include "base/threading/platform_thread.h" | 10 #include "chrome/browser/ui/browser.h" |
| 11 #include "chrome/common/chrome_switches.h" | 11 #include "chrome/test/base/ui_test_utils.h" |
| 12 #include "chrome/test/base/test_launcher_utils.h" | 12 #include "content/test/layout_browsertest.h" |
| 13 #include "chrome/test/ui/ui_layout_test.h" | 13 #include "googleurl/src/gurl.h" |
| 14 #include "chrome/test/ui/ui_test.h" | |
| 15 #include "net/base/net_util.h" | |
| 16 #include "ui/gfx/gl/gl_implementation.h" | |
| 17 | 14 |
| 18 class MediaTest : public UITest { | 15 class MediaTest : public InProcessBrowserTest { |
| 19 protected: | 16 protected: |
| 17 GURL GetTestURL(const char* tag, const char* media_file) { |
| 18 FilePath test_file_path = ui_test_utils::GetTestFilePath( |
| 19 FilePath(FILE_PATH_LITERAL("media")), |
| 20 FilePath(FILE_PATH_LITERAL("player.html"))); |
| 21 std::string query = base::StringPrintf("%s=%s", tag, media_file); |
| 22 return ui_test_utils::GetFileUrlWithQuery(test_file_path, query); |
| 23 } |
| 24 |
| 20 void PlayMedia(const char* tag, const char* media_file) { | 25 void PlayMedia(const char* tag, const char* media_file) { |
| 21 FilePath test_file(test_data_directory_); | 26 GURL player_gurl = GetTestURL(tag, media_file); |
| 22 test_file = test_file.AppendASCII("media/player.html"); | |
| 23 | |
| 24 GURL player_gurl = net::FilePathToFileURL(test_file); | |
| 25 std::string url = base::StringPrintf( | |
| 26 "%s?%s=%s", player_gurl.spec().c_str(), tag, media_file); | |
| 27 | |
| 28 NavigateToURL(GURL(url)); | |
| 29 | 27 |
| 30 // Allow the media file to be loaded. | 28 // Allow the media file to be loaded. |
| 31 const std::wstring kPlaying = L"PLAYING"; | 29 const string16 kPlaying = ASCIIToUTF16("PLAYING"); |
| 32 const std::wstring kFailed = L"FAILED"; | 30 const string16 kFailed = ASCIIToUTF16("FAILED"); |
| 33 const std::wstring kError = L"ERROR"; | 31 const string16 kError = ASCIIToUTF16("ERROR"); |
| 34 const base::TimeDelta kSleepInterval = | 32 ui_test_utils::TitleWatcher title_watcher( |
| 35 base::TimeDelta::FromMilliseconds(250); | 33 browser()->GetSelectedWebContents(), kPlaying); |
| 36 const int kNumIntervals = | 34 title_watcher.AlsoWaitForTitle(kFailed); |
| 37 TestTimeouts::action_timeout() / kSleepInterval; | 35 title_watcher.AlsoWaitForTitle(kError); |
| 38 for (int i = 0; i < kNumIntervals; ++i) { | |
| 39 const std::wstring& title = GetActiveTabTitle(); | |
| 40 if (title == kPlaying || title == kFailed || | |
| 41 StartsWith(title, kError, true)) | |
| 42 break; | |
| 43 base::PlatformThread::Sleep(kSleepInterval); | |
| 44 } | |
| 45 | 36 |
| 46 EXPECT_EQ(kPlaying, GetActiveTabTitle()); | 37 ui_test_utils::NavigateToURL(browser(), player_gurl); |
| 38 |
| 39 string16 final_title = title_watcher.WaitAndGetTitle(); |
| 40 EXPECT_EQ(kPlaying, final_title); |
| 47 } | 41 } |
| 48 | 42 |
| 49 void PlayAudio(const char* url) { | 43 void PlayAudio(const char* url) { |
| 50 PlayMedia("audio", url); | 44 PlayMedia("audio", url); |
| 51 } | 45 } |
| 52 | 46 |
| 53 void PlayVideo(const char* url) { | 47 void PlayVideo(const char* url) { |
| 54 PlayMedia("video", url); | 48 PlayMedia("video", url); |
| 55 } | 49 } |
| 56 }; | 50 }; |
| 57 | 51 |
| 58 #if defined(OS_MACOSX) | 52 #if defined(OS_MACOSX) |
| 59 // http://crbug.com/88834 - VideoBearTheora, VideoBearWav and VideoBearWebm | 53 // http://crbug.com/88834 - VideoBearTheora, VideoBearWav and VideoBearWebm |
| 60 // are flaky on Mac. | 54 // are flaky on Mac. |
| 61 #define MAYBE_VideoBearTheora DISABLED_VideoBearTheora | 55 #define MAYBE_VideoBearTheora DISABLED_VideoBearTheora |
| 62 #define MAYBE_VideoBearWavPcm DISABLED_VideoBearWavPcm | 56 #define MAYBE_VideoBearWavPcm DISABLED_VideoBearWavPcm |
| 63 #define MAYBE_VideoBearWebm DISABLED_VideoBearWebm | 57 #define MAYBE_VideoBearWebm DISABLED_VideoBearWebm |
| 64 #else | 58 #else |
| 65 #define MAYBE_VideoBearTheora VideoBearTheora | 59 #define MAYBE_VideoBearTheora VideoBearTheora |
| 66 #define MAYBE_VideoBearWavPcm VideoBearWavPcm | 60 #define MAYBE_VideoBearWavPcm VideoBearWavPcm |
| 67 #define MAYBE_VideoBearWebm VideoBearWebm | 61 #define MAYBE_VideoBearWebm VideoBearWebm |
| 68 #endif | 62 #endif |
| 69 | 63 |
| 70 TEST_F(MediaTest, MAYBE_VideoBearTheora) { | 64 IN_PROC_BROWSER_TEST_F(MediaTest, MAYBE_VideoBearTheora) { |
| 71 PlayVideo("bear.ogv"); | 65 PlayVideo("bear.ogv"); |
| 72 } | 66 } |
| 73 | 67 |
| 74 TEST_F(MediaTest, VideoBearSilentTheora) { | 68 IN_PROC_BROWSER_TEST_F(MediaTest, VideoBearSilentTheora) { |
| 75 PlayVideo("bear_silent.ogv"); | 69 PlayVideo("bear_silent.ogv"); |
| 76 } | 70 } |
| 77 | 71 |
| 78 TEST_F(MediaTest, MAYBE_VideoBearWebm) { | 72 IN_PROC_BROWSER_TEST_F(MediaTest, MAYBE_VideoBearWebm) { |
| 79 PlayVideo("bear.webm"); | 73 PlayVideo("bear.webm"); |
| 80 } | 74 } |
| 81 | 75 |
| 82 TEST_F(MediaTest, VideoBearSilentWebm) { | 76 IN_PROC_BROWSER_TEST_F(MediaTest, VideoBearSilentWebm) { |
| 83 PlayVideo("bear_silent.webm"); | 77 PlayVideo("bear_silent.webm"); |
| 84 } | 78 } |
| 85 | 79 |
| 86 #if defined(GOOGLE_CHROME_BUILD) || defined(USE_PROPRIETARY_CODECS) | 80 #if defined(GOOGLE_CHROME_BUILD) || defined(USE_PROPRIETARY_CODECS) |
| 87 TEST_F(MediaTest, VideoBearMp4) { | 81 IN_PROC_BROWSER_TEST_F(MediaTest, VideoBearMp4) { |
| 88 PlayVideo("bear.mp4"); | 82 PlayVideo("bear.mp4"); |
| 89 } | 83 } |
| 90 | 84 |
| 91 TEST_F(MediaTest, VideoBearSilentMp4) { | 85 IN_PROC_BROWSER_TEST_F(MediaTest, VideoBearSilentMp4) { |
| 92 PlayVideo("bear_silent.mp4"); | 86 PlayVideo("bear_silent.mp4"); |
| 93 } | 87 } |
| 94 #endif | 88 #endif |
| 95 | 89 |
| 96 #if defined(OS_CHROMEOS) | 90 #if defined(OS_CHROMEOS) |
| 97 #if defined(GOOGLE_CHROME_BUILD) || defined(USE_PROPRIETARY_CODECS) | 91 #if defined(GOOGLE_CHROME_BUILD) || defined(USE_PROPRIETARY_CODECS) |
| 98 TEST_F(MediaTest, VideoBearAviMp3Mpeg4) { | 92 IN_PROC_BROWSER_TEST_F(MediaTest, VideoBearAviMp3Mpeg4) { |
| 99 PlayVideo("bear_mpeg4_mp3.avi"); | 93 PlayVideo("bear_mpeg4_mp3.avi"); |
| 100 } | 94 } |
| 101 | 95 |
| 102 TEST_F(MediaTest, VideoBearAviMp3Divx) { | 96 IN_PROC_BROWSER_TEST_F(MediaTest, VideoBearAviMp3Divx) { |
| 103 PlayVideo("bear_divx_mp3.avi"); | 97 PlayVideo("bear_divx_mp3.avi"); |
| 104 } | 98 } |
| 105 | 99 |
| 106 TEST_F(MediaTest, VideoBear3gpAacH264) { | 100 IN_PROC_BROWSER_TEST_F(MediaTest, VideoBear3gpAacH264) { |
| 107 PlayVideo("bear_h264_aac.3gp"); | 101 PlayVideo("bear_h264_aac.3gp"); |
| 108 } | 102 } |
| 109 | 103 |
| 110 TEST_F(MediaTest, VideoBear3gpAmrnbMpeg4) { | 104 IN_PROC_BROWSER_TEST_F(MediaTest, VideoBear3gpAmrnbMpeg4) { |
| 111 PlayVideo("bear_mpeg4_amrnb.3gp"); | 105 PlayVideo("bear_mpeg4_amrnb.3gp"); |
| 112 } | 106 } |
| 113 | 107 |
| 114 // TODO(ihf): Enable these audio codecs for CrOS. | 108 // TODO(ihf): Enable these audio codecs for CrOS. |
| 115 // TEST_F(MediaTest, VideoBearWavAlaw) { | 109 // IN_PROC_BROWSER_TEST_F(MediaTest, VideoBearWavAlaw) { |
| 116 // PlayVideo("bear_alaw.wav"); | 110 // PlayVideo("bear_alaw.wav"); |
| 117 // } | 111 // } |
| 118 // TEST_F(MediaTest, VideoBearWavGsmms) { | 112 // IN_PROC_BROWSER_TEST_F(MediaTest, VideoBearWavGsmms) { |
| 119 // PlayVideo("bear_gsmms.wav"); | 113 // PlayVideo("bear_gsmms.wav"); |
| 120 // } | 114 // } |
| 121 | 115 |
| 122 TEST_F(MediaTest, VideoBearWavMulaw) { | 116 IN_PROC_BROWSER_TEST_F(MediaTest, VideoBearWavMulaw) { |
| 123 PlayVideo("bear_mulaw.wav"); | 117 PlayVideo("bear_mulaw.wav"); |
| 124 } | 118 } |
| 125 | 119 |
| 126 TEST_F(MediaTest, VideoBearFlac) { | 120 IN_PROC_BROWSER_TEST_F(MediaTest, VideoBearFlac) { |
| 127 PlayVideo("bear.flac"); | 121 PlayVideo("bear.flac"); |
| 128 } | 122 } |
| 129 #endif | 123 #endif |
| 130 #endif | 124 #endif |
| 131 | 125 |
| 132 TEST_F(MediaTest, MAYBE_VideoBearWavPcm) { | 126 IN_PROC_BROWSER_TEST_F(MediaTest, MAYBE_VideoBearWavPcm) { |
| 133 PlayVideo("bear_pcm.wav"); | 127 PlayVideo("bear_pcm.wav"); |
| 134 } | 128 } |
| 135 | 129 |
| 136 TEST_F(UILayoutTest, MediaUILayoutTest) { | 130 class MediaLayoutTest : public InProcessBrowserLayoutTest { |
| 137 static const char* kResources[] = { | 131 protected: |
| 138 "content", | 132 MediaLayoutTest() : InProcessBrowserLayoutTest( |
| 139 "media-file.js", | 133 FilePath(), FilePath().AppendASCII("media")) { |
| 140 "media-fullscreen.js", | 134 } |
| 141 "video-paint-test.js", | 135 virtual ~MediaLayoutTest() {} |
| 142 "video-played.js", | |
| 143 "video-test.js", | |
| 144 }; | |
| 145 | 136 |
| 137 virtual void SetUpInProcessBrowserTestFixture() OVERRIDE { |
| 138 InProcessBrowserLayoutTest::SetUpInProcessBrowserTestFixture(); |
| 139 AddResourceForLayoutTest(FilePath().AppendASCII("media"), |
| 140 FilePath().AppendASCII("content")); |
| 141 AddResourceForLayoutTest(FilePath().AppendASCII("media"), |
| 142 FilePath().AppendASCII("media-file.js")); |
| 143 AddResourceForLayoutTest(FilePath().AppendASCII("media"), |
| 144 FilePath().AppendASCII("media-fullscreen.js")); |
| 145 AddResourceForLayoutTest(FilePath().AppendASCII("media"), |
| 146 FilePath().AppendASCII("video-paint-test.js")); |
| 147 AddResourceForLayoutTest(FilePath().AppendASCII("media"), |
| 148 FilePath().AppendASCII("video-played.js")); |
| 149 AddResourceForLayoutTest(FilePath().AppendASCII("media"), |
| 150 FilePath().AppendASCII("video-test.js")); |
| 151 } |
| 152 }; |
| 153 |
| 154 IN_PROC_BROWSER_TEST_F(MediaLayoutTest, Tests) { |
| 146 static const char* kMediaTests[] = { | 155 static const char* kMediaTests[] = { |
| 147 "video-autoplay.html", | 156 "video-autoplay.html", |
| 148 // "video-loop.html", disabled due to 52887. | 157 // "video-loop.html", disabled due to 52887. |
| 149 "video-no-autoplay.html", | 158 "video-no-autoplay.html", |
| 150 // TODO(sergeyu): Add more tests here. | 159 // TODO(sergeyu): Add more tests here. |
| 151 }; | 160 }; |
| 152 | 161 |
| 153 FilePath test_dir; | |
| 154 FilePath media_test_dir; | |
| 155 media_test_dir = media_test_dir.AppendASCII("media"); | |
| 156 InitializeForLayoutTest(test_dir, media_test_dir, kNoHttpPort); | |
| 157 | |
| 158 // Copy resources first. | |
| 159 for (size_t i = 0; i < arraysize(kResources); ++i) | |
| 160 AddResourceForLayoutTest( | |
| 161 test_dir, media_test_dir.AppendASCII(kResources[i])); | |
| 162 | |
| 163 for (size_t i = 0; i < arraysize(kMediaTests); ++i) | 162 for (size_t i = 0; i < arraysize(kMediaTests); ++i) |
| 164 RunLayoutTest(kMediaTests[i], kNoHttpPort); | 163 RunLayoutTest(kMediaTests[i]); |
| 165 } | 164 } |
| OLD | NEW |