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" |
| 7 #include "base/strings/utf_string_conversions.h" |
6 #include "chromecast/browser/test/chromecast_browser_test.h" | 8 #include "chromecast/browser/test/chromecast_browser_test.h" |
| 9 #include "content/public/test/browser_test_utils.h" |
| 10 #include "media/base/test_data_util.h" |
7 #include "url/gurl.h" | 11 #include "url/gurl.h" |
8 #include "url/url_constants.h" | 12 #include "url/url_constants.h" |
9 | 13 |
10 namespace chromecast { | 14 namespace chromecast { |
11 namespace shell { | 15 namespace shell { |
| 16 namespace { |
| 17 const char kEnded[] = "ENDED"; |
| 18 const char kError[] = "ERROR"; |
| 19 const char kFailed[] = "FAILED"; |
| 20 } |
12 | 21 |
13 class ChromecastShellBrowserTest : public ChromecastBrowserTest { | 22 class ChromecastShellBrowserTest : public ChromecastBrowserTest { |
14 public: | 23 public: |
15 ChromecastShellBrowserTest() : url_(url::kAboutBlankURL) {} | 24 ChromecastShellBrowserTest() : url_(url::kAboutBlankURL) {} |
16 | 25 |
17 void SetUpOnMainThread() override { | 26 void SetUpOnMainThread() override { |
18 CreateBrowser(); | 27 CreateBrowser(); |
19 NavigateToURL(web_contents(), url_); | 28 NavigateToURL(web_contents(), url_); |
20 } | 29 } |
21 | 30 |
| 31 void PlayVideo(const std::string& media_file) { |
| 32 PlayMedia("video", media_file); |
| 33 } |
| 34 |
22 private: | 35 private: |
23 const GURL url_; | 36 const GURL url_; |
24 | 37 |
| 38 void PlayMedia(const std::string& tag, |
| 39 const std::string& media_file) { |
| 40 base::StringPairs query_params; |
| 41 query_params.push_back(std::make_pair(tag, media_file)); |
| 42 RunMediaTestPage("player.html", query_params, kEnded); |
| 43 } |
| 44 |
| 45 void RunMediaTestPage(const std::string& html_page, |
| 46 const base::StringPairs& query_params, |
| 47 const std::string& expected_title) { |
| 48 std::string query = media::GetURLQueryString(query_params); |
| 49 GURL gurl = content::GetFileUrlWithQuery( |
| 50 media::GetTestDataFilePath(html_page), |
| 51 query); |
| 52 |
| 53 std::string final_title = RunTest(gurl, expected_title); |
| 54 EXPECT_EQ(expected_title, final_title); |
| 55 } |
| 56 |
| 57 std::string RunTest(const GURL& gurl, |
| 58 const std::string& expected_title) { |
| 59 content::TitleWatcher title_watcher(web_contents(), |
| 60 base::ASCIIToUTF16(expected_title)); |
| 61 title_watcher.AlsoWaitForTitle(base::ASCIIToUTF16(kEnded)); |
| 62 title_watcher.AlsoWaitForTitle(base::ASCIIToUTF16(kError)); |
| 63 title_watcher.AlsoWaitForTitle(base::ASCIIToUTF16(kFailed)); |
| 64 |
| 65 NavigateToURL(web_contents(), gurl); |
| 66 base::string16 result = title_watcher.WaitAndGetTitle(); |
| 67 return base::UTF16ToASCII(result); |
| 68 } |
| 69 |
25 DISALLOW_COPY_AND_ASSIGN(ChromecastShellBrowserTest); | 70 DISALLOW_COPY_AND_ASSIGN(ChromecastShellBrowserTest); |
26 }; | 71 }; |
27 | 72 |
28 IN_PROC_BROWSER_TEST_F(ChromecastShellBrowserTest, EmptyTest) { | 73 IN_PROC_BROWSER_TEST_F(ChromecastShellBrowserTest, EmptyTest) { |
29 // Run an entire browser lifecycle to ensure nothing breaks. | 74 // Run an entire browser lifecycle to ensure nothing breaks. |
30 // TODO(gunsch): Remove this test case once there are actual assertions to | 75 // TODO(gunsch): Remove this test case once there are actual assertions to |
31 // test in a ChromecastBrowserTest instance. | 76 // test in a ChromecastBrowserTest instance. |
32 EXPECT_TRUE(true); | 77 EXPECT_TRUE(true); |
33 } | 78 } |
34 | 79 |
| 80 IN_PROC_BROWSER_TEST_F(ChromecastShellBrowserTest, MediaPlayback) { |
| 81 PlayVideo("bear.mp4"); |
| 82 } |
| 83 |
35 } // namespace shell | 84 } // namespace shell |
36 } // namespace chromecast | 85 } // namespace chromecast |
OLD | NEW |