Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 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/run_loop.h" | 6 #include "base/run_loop.h" |
| 7 #include "base/threading/platform_thread.h" | 7 #include "base/threading/platform_thread.h" |
| 8 #include "base/threading/thread_task_runner_handle.h" | 8 #include "base/threading/thread_task_runner_handle.h" |
| 9 #include "chromecast/browser/cast_media_blocker.h" | |
| 9 #include "chromecast/browser/test/chromecast_browser_test.h" | 10 #include "chromecast/browser/test/chromecast_browser_test.h" |
| 10 #include "chromecast/browser/test/chromecast_browser_test_helper.h" | |
| 11 #include "chromecast/chromecast_features.h" | 11 #include "chromecast/chromecast_features.h" |
| 12 #include "content/public/browser/media_session.h" | |
| 12 #include "content/public/browser/web_contents.h" | 13 #include "content/public/browser/web_contents.h" |
| 13 #include "content/public/test/browser_test_utils.h" | 14 #include "content/public/test/browser_test_utils.h" |
| 14 #include "media/base/test_data_util.h" | 15 #include "media/base/test_data_util.h" |
| 15 #include "url/gurl.h" | 16 #include "url/gurl.h" |
| 16 #include "url/url_constants.h" | 17 #include "url/url_constants.h" |
| 17 | 18 |
| 18 namespace chromecast { | 19 namespace chromecast { |
| 19 namespace shell { | 20 namespace shell { |
| 20 | 21 |
| 21 class ChromecastShellMediaBlockingBrowserTest : public ChromecastBrowserTest { | 22 class ChromecastShellMediaBlockingBrowserTest : public ChromecastBrowserTest { |
| 22 public: | 23 public: |
| 23 ChromecastShellMediaBlockingBrowserTest() {} | 24 ChromecastShellMediaBlockingBrowserTest() {} |
| 24 | 25 |
| 25 protected: | 26 protected: |
| 27 // ChromecastBrowserTest overrides. | |
|
derekjchow1
2016/11/08 19:06:37
// ChromecastBrowserTest implementation:
To be co
alokp
2016/11/08 19:34:00
Done.
| |
| 28 void TearDownOnMainThread() override { | |
| 29 blocker_.reset(); | |
| 30 | |
| 31 ChromecastBrowserTest::TearDownOnMainThread(); | |
| 32 } | |
| 33 | |
| 26 void PlayMedia(const std::string& tag, const std::string& media_file) { | 34 void PlayMedia(const std::string& tag, const std::string& media_file) { |
| 27 base::StringPairs query_params; | 35 base::StringPairs query_params; |
| 28 query_params.push_back(std::make_pair(tag, media_file)); | 36 query_params.push_back(std::make_pair(tag, media_file)); |
| 29 query_params.push_back(std::make_pair("loop", "true")); | 37 query_params.push_back(std::make_pair("loop", "true")); |
| 30 | 38 |
| 31 std::string query = media::GetURLQueryString(query_params); | 39 std::string query = media::GetURLQueryString(query_params); |
| 32 GURL gurl = content::GetFileUrlWithQuery( | 40 GURL gurl = content::GetFileUrlWithQuery( |
| 33 media::GetTestDataFilePath("player.html"), query); | 41 media::GetTestDataFilePath("player.html"), query); |
| 34 | 42 |
| 35 web_contents_ = helper_->NavigateToURL(gurl); | 43 web_contents_ = NavigateToURL(gurl); |
| 36 WaitForLoadStop(web_contents_); | 44 WaitForLoadStop(web_contents_); |
| 45 | |
| 46 blocker_ = base::MakeUnique<CastMediaBlocker>( | |
| 47 content::MediaSession::Get(web_contents_), web_contents_); | |
| 37 } | 48 } |
| 38 | 49 |
| 39 void BlockAndTestPlayerState(const std::string& media_type, bool blocked) { | 50 void BlockAndTestPlayerState(const std::string& media_type, bool blocked) { |
| 40 helper_->BlockMediaLoading(blocked); | 51 blocker_->BlockMediaLoading(blocked); |
| 41 | 52 |
| 42 // Changing states is not instant, but should be timely (< 0.5s). | 53 // Changing states is not instant, but should be timely (< 0.5s). |
| 43 for (size_t i = 0; i < 5; i++) { | 54 for (size_t i = 0; i < 5; i++) { |
| 44 base::RunLoop run_loop; | 55 base::RunLoop run_loop; |
| 45 base::ThreadTaskRunnerHandle::Get()->PostDelayedTask( | 56 base::ThreadTaskRunnerHandle::Get()->PostDelayedTask( |
| 46 FROM_HERE, run_loop.QuitClosure(), | 57 FROM_HERE, run_loop.QuitClosure(), |
| 47 base::TimeDelta::FromMilliseconds(50)); | 58 base::TimeDelta::FromMilliseconds(50)); |
| 48 base::MessageLoop::ScopedNestableTaskAllower allow_nested( | 59 base::MessageLoop::ScopedNestableTaskAllower allow_nested( |
| 49 base::MessageLoop::current()); | 60 base::MessageLoop::current()); |
| 50 run_loop.Run(); | 61 run_loop.Run(); |
| (...skipping 10 matching lines...) Expand all Loading... | |
| 61 SUCCEED() << "Media element has been successfullly " | 72 SUCCEED() << "Media element has been successfullly " |
| 62 << (blocked ? "blocked" : "unblocked"); | 73 << (blocked ? "blocked" : "unblocked"); |
| 63 return; | 74 return; |
| 64 } | 75 } |
| 65 } | 76 } |
| 66 | 77 |
| 67 FAIL() << "Could not successfullly " << (blocked ? "block" : "unblock") | 78 FAIL() << "Could not successfullly " << (blocked ? "block" : "unblock") |
| 68 << " media element"; | 79 << " media element"; |
| 69 } | 80 } |
| 70 | 81 |
| 82 private: | |
| 71 content::WebContents* web_contents_; | 83 content::WebContents* web_contents_; |
| 84 std::unique_ptr<CastMediaBlocker> blocker_; | |
| 72 | 85 |
| 73 private: | |
| 74 DISALLOW_COPY_AND_ASSIGN(ChromecastShellMediaBlockingBrowserTest); | 86 DISALLOW_COPY_AND_ASSIGN(ChromecastShellMediaBlockingBrowserTest); |
| 75 }; | 87 }; |
| 76 | 88 |
| 77 IN_PROC_BROWSER_TEST_F(ChromecastShellMediaBlockingBrowserTest, | 89 IN_PROC_BROWSER_TEST_F(ChromecastShellMediaBlockingBrowserTest, |
| 78 Audio_BlockUnblock) { | 90 Audio_BlockUnblock) { |
| 79 PlayMedia("audio", "bear-audio-10s-CBR-has-TOC.mp3"); | 91 PlayMedia("audio", "bear-audio-10s-CBR-has-TOC.mp3"); |
| 80 | 92 |
| 81 BlockAndTestPlayerState("audio", true); | 93 BlockAndTestPlayerState("audio", true); |
| 82 BlockAndTestPlayerState("audio", false); | 94 BlockAndTestPlayerState("audio", false); |
| 83 } | 95 } |
| 84 | 96 |
| 85 #if !BUILDFLAG(IS_CAST_AUDIO_ONLY) | 97 #if !BUILDFLAG(IS_CAST_AUDIO_ONLY) |
| 86 IN_PROC_BROWSER_TEST_F(ChromecastShellMediaBlockingBrowserTest, | 98 IN_PROC_BROWSER_TEST_F(ChromecastShellMediaBlockingBrowserTest, |
| 87 Video_BlockUnblock) { | 99 Video_BlockUnblock) { |
| 88 PlayMedia("video", "tulip2.webm"); | 100 PlayMedia("video", "tulip2.webm"); |
| 89 | 101 |
| 90 BlockAndTestPlayerState("video", true); | 102 BlockAndTestPlayerState("video", true); |
| 91 BlockAndTestPlayerState("video", false); | 103 BlockAndTestPlayerState("video", false); |
| 92 } | 104 } |
| 93 #endif | 105 #endif |
| 94 | 106 |
| 95 } // namespace shell | 107 } // namespace shell |
| 96 } // namespace chromecast | 108 } // namespace chromecast |
| OLD | NEW |