| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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/macros.h" | 5 #include "base/macros.h" |
| 6 #include "base/strings/string_split.h" | 6 #include "base/strings/string_split.h" |
| 7 #include "base/strings/utf_string_conversions.h" | 7 #include "base/strings/utf_string_conversions.h" |
| 8 #include "chromecast/browser/test/chromecast_browser_test.h" | 8 #include "chromecast/browser/test/cast_browser_test.h" |
| 9 #include "chromecast/chromecast_features.h" | 9 #include "chromecast/chromecast_features.h" |
| 10 #include "content/public/test/browser_test_utils.h" | 10 #include "content/public/test/browser_test_utils.h" |
| 11 #include "media/base/test_data_util.h" | 11 #include "media/base/test_data_util.h" |
| 12 #include "url/gurl.h" | 12 #include "url/gurl.h" |
| 13 #include "url/url_constants.h" | 13 #include "url/url_constants.h" |
| 14 | 14 |
| 15 namespace chromecast { | 15 namespace chromecast { |
| 16 namespace shell { | 16 namespace shell { |
| 17 namespace { | 17 namespace { |
| 18 const char kEnded[] = "ENDED"; | 18 const char kEnded[] = "ENDED"; |
| 19 const char kError[] = "ERROR"; | 19 const char kError[] = "ERROR"; |
| 20 const char kFailed[] = "FAILED"; | 20 const char kFailed[] = "FAILED"; |
| 21 } | 21 } |
| 22 | 22 |
| 23 class ChromecastShellBrowserTest : public ChromecastBrowserTest { | 23 class CastNavigationBrowserTest : public CastBrowserTest { |
| 24 public: | 24 public: |
| 25 ChromecastShellBrowserTest() {} | 25 CastNavigationBrowserTest() {} |
| 26 | 26 |
| 27 void LoadAboutBlank() { | 27 void LoadAboutBlank() { |
| 28 content::WebContents* web_contents = | 28 content::WebContents* web_contents = |
| 29 NavigateToURL(GURL(url::kAboutBlankURL)); | 29 NavigateToURL(GURL(url::kAboutBlankURL)); |
| 30 content::TitleWatcher title_watcher( | 30 content::TitleWatcher title_watcher( |
| 31 web_contents, base::ASCIIToUTF16(url::kAboutBlankURL)); | 31 web_contents, base::ASCIIToUTF16(url::kAboutBlankURL)); |
| 32 base::string16 result = title_watcher.WaitAndGetTitle(); | 32 base::string16 result = title_watcher.WaitAndGetTitle(); |
| 33 EXPECT_EQ(url::kAboutBlankURL, base::UTF16ToASCII(result)); | 33 EXPECT_EQ(url::kAboutBlankURL, base::UTF16ToASCII(result)); |
| 34 } | 34 } |
| 35 void PlayAudio(const std::string& media_file) { | 35 void PlayAudio(const std::string& media_file) { |
| 36 PlayMedia("audio", media_file); | 36 PlayMedia("audio", media_file); |
| 37 } | 37 } |
| 38 void PlayVideo(const std::string& media_file) { | 38 void PlayVideo(const std::string& media_file) { |
| 39 PlayMedia("video", media_file); | 39 PlayMedia("video", media_file); |
| 40 } | 40 } |
| 41 | 41 |
| 42 private: | 42 private: |
| 43 void PlayMedia(const std::string& tag, | 43 void PlayMedia(const std::string& tag, const std::string& media_file) { |
| 44 const std::string& media_file) { | |
| 45 base::StringPairs query_params; | 44 base::StringPairs query_params; |
| 46 query_params.push_back(std::make_pair(tag, media_file)); | 45 query_params.push_back(std::make_pair(tag, media_file)); |
| 47 RunMediaTestPage("player.html", query_params, kEnded); | 46 RunMediaTestPage("player.html", query_params, kEnded); |
| 48 } | 47 } |
| 49 | 48 |
| 50 void RunMediaTestPage(const std::string& html_page, | 49 void RunMediaTestPage(const std::string& html_page, |
| 51 const base::StringPairs& query_params, | 50 const base::StringPairs& query_params, |
| 52 const std::string& expected_title) { | 51 const std::string& expected_title) { |
| 53 std::string query = media::GetURLQueryString(query_params); | 52 std::string query = media::GetURLQueryString(query_params); |
| 54 GURL gurl = content::GetFileUrlWithQuery( | 53 GURL gurl = content::GetFileUrlWithQuery( |
| 55 media::GetTestDataFilePath(html_page), | 54 media::GetTestDataFilePath(html_page), query); |
| 56 query); | |
| 57 | 55 |
| 58 std::string final_title = RunTest(gurl, expected_title); | 56 std::string final_title = RunTest(gurl, expected_title); |
| 59 EXPECT_EQ(expected_title, final_title); | 57 EXPECT_EQ(expected_title, final_title); |
| 60 } | 58 } |
| 61 | 59 |
| 62 std::string RunTest(const GURL& gurl, | 60 std::string RunTest(const GURL& gurl, const std::string& expected_title) { |
| 63 const std::string& expected_title) { | |
| 64 content::WebContents* web_contents = NavigateToURL(gurl); | 61 content::WebContents* web_contents = NavigateToURL(gurl); |
| 65 content::TitleWatcher title_watcher(web_contents, | 62 content::TitleWatcher title_watcher(web_contents, |
| 66 base::ASCIIToUTF16(expected_title)); | 63 base::ASCIIToUTF16(expected_title)); |
| 67 title_watcher.AlsoWaitForTitle(base::ASCIIToUTF16(kEnded)); | 64 title_watcher.AlsoWaitForTitle(base::ASCIIToUTF16(kEnded)); |
| 68 title_watcher.AlsoWaitForTitle(base::ASCIIToUTF16(kError)); | 65 title_watcher.AlsoWaitForTitle(base::ASCIIToUTF16(kError)); |
| 69 title_watcher.AlsoWaitForTitle(base::ASCIIToUTF16(kFailed)); | 66 title_watcher.AlsoWaitForTitle(base::ASCIIToUTF16(kFailed)); |
| 70 base::string16 result = title_watcher.WaitAndGetTitle(); | 67 base::string16 result = title_watcher.WaitAndGetTitle(); |
| 71 return base::UTF16ToASCII(result); | 68 return base::UTF16ToASCII(result); |
| 72 } | 69 } |
| 73 | 70 |
| 74 DISALLOW_COPY_AND_ASSIGN(ChromecastShellBrowserTest); | 71 DISALLOW_COPY_AND_ASSIGN(CastNavigationBrowserTest); |
| 75 }; | 72 }; |
| 76 | 73 |
| 77 IN_PROC_BROWSER_TEST_F(ChromecastShellBrowserTest, EmptyTest) { | 74 IN_PROC_BROWSER_TEST_F(CastNavigationBrowserTest, EmptyTest) { |
| 78 // Run an entire browser lifecycle to ensure nothing breaks. | 75 // Run an entire browser lifecycle to ensure nothing breaks. |
| 79 LoadAboutBlank(); | 76 LoadAboutBlank(); |
| 80 } | 77 } |
| 81 | 78 |
| 82 IN_PROC_BROWSER_TEST_F(ChromecastShellBrowserTest, AudioPlaybackWavPcm) { | 79 IN_PROC_BROWSER_TEST_F(CastNavigationBrowserTest, AudioPlaybackWavPcm) { |
| 83 PlayAudio("bear_pcm.wav"); | 80 PlayAudio("bear_pcm.wav"); |
| 84 } | 81 } |
| 85 | 82 |
| 86 #if !BUILDFLAG(IS_CAST_AUDIO_ONLY) | 83 #if !BUILDFLAG(IS_CAST_AUDIO_ONLY) |
| 87 IN_PROC_BROWSER_TEST_F(ChromecastShellBrowserTest, VideoPlaybackMp4) { | 84 IN_PROC_BROWSER_TEST_F(CastNavigationBrowserTest, VideoPlaybackMp4) { |
| 88 PlayVideo("bear.mp4"); | 85 PlayVideo("bear.mp4"); |
| 89 } | 86 } |
| 90 #endif | 87 #endif |
| 91 | 88 |
| 92 } // namespace shell | 89 } // namespace shell |
| 93 } // namespace chromecast | 90 } // namespace chromecast |
| OLD | NEW |