Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(290)

Side by Side Diff: chromecast/browser/test/chromecast_shell_media_blocking_browser_test.cc

Issue 2360443002: [Chromecast] Add CastMediaBlocker and BrowserTest (Closed)
Patch Set: use [] for optional query param Created 4 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(Empty)
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
3 // found in the LICENSE file.
4
5 #include "base/macros.h"
6 #include "base/run_loop.h"
7 #include "base/threading/platform_thread.h"
8 #include "base/threading/thread_task_runner_handle.h"
9 #include "chromecast/browser/test/chromecast_browser_test.h"
10 #include "chromecast/browser/test/chromecast_browser_test_helper.h"
11 #include "chromecast/chromecast_features.h"
12 #include "content/public/browser/web_contents.h"
13 #include "content/public/test/browser_test_utils.h"
14 #include "media/base/test_data_util.h"
15 #include "url/gurl.h"
16 #include "url/url_constants.h"
17
18 namespace chromecast {
19 namespace shell {
20
21 class ChromecastShellMediaBlockingBrowserTest : public ChromecastBrowserTest {
22 public:
23 ChromecastShellMediaBlockingBrowserTest() {}
24
25 protected:
26 void PlayMedia(const std::string& tag, const std::string& media_file) {
27 base::StringPairs query_params;
28 query_params.push_back(std::make_pair(tag, media_file));
29 query_params.push_back(std::make_pair("loop", "true"));
30
31 std::string query = media::GetURLQueryString(query_params);
32 GURL gurl = content::GetFileUrlWithQuery(
33 media::GetTestDataFilePath("player.html"), query);
34
35 web_contents_ = helper_->NavigateToURL(gurl);
36 WaitForLoadStop(web_contents_);
37 }
38
39 void BlockAndTestPlayerState(const std::string& media_type, bool blocked) {
40 helper_->BlockMediaLoading(blocked);
41
42 // Changing states is not instant, but should be timely (< 0.5s).
43 for (size_t i = 0; i < 5; i++) {
44 base::RunLoop run_loop;
45 base::ThreadTaskRunnerHandle::Get()->PostDelayedTask(
46 FROM_HERE, run_loop.QuitClosure(),
47 base::TimeDelta::FromMilliseconds(50));
48 base::MessageLoop::ScopedNestableTaskAllower allow_nested(
49 base::MessageLoop::current());
50 run_loop.Run();
51
52 const std::string command =
53 "document.getElementsByTagName(\"" + media_type + "\")[0].paused";
54 const std::string js =
55 "window.domAutomationController.send(" + command + ");";
56
57 bool paused;
58 ASSERT_TRUE(ExecuteScriptAndExtractBool(web_contents_, js, &paused));
59
60 if (paused == blocked) {
61 SUCCEED() << "Media element has been successfullly "
62 << (blocked ? "blocked" : "unblocked");
63 return;
64 }
65 }
66
67 FAIL() << "Could not successfullly " << (blocked ? "block" : "unblock")
68 << " media element";
69 }
70
71 content::WebContents* web_contents_;
72
73 private:
74 DISALLOW_COPY_AND_ASSIGN(ChromecastShellMediaBlockingBrowserTest);
75 };
76
77 IN_PROC_BROWSER_TEST_F(ChromecastShellMediaBlockingBrowserTest,
78 Audio_BlockUnblock) {
79 PlayMedia("audio", "bear-audio-10s-CBR-has-TOC.mp3");
80
81 BlockAndTestPlayerState("audio", true);
82 BlockAndTestPlayerState("audio", false);
83 }
84
85 #if !BUILDFLAG(IS_CAST_AUDIO_ONLY)
86 IN_PROC_BROWSER_TEST_F(ChromecastShellMediaBlockingBrowserTest,
87 Video_BlockUnblock) {
88 PlayMedia("video", "tulip2.webm");
89
90 BlockAndTestPlayerState("video", true);
91 BlockAndTestPlayerState("video", false);
92 }
93 #endif
94
95 } // namespace shell
96 } // namespace chromecast
OLDNEW
« no previous file with comments | « chromecast/browser/test/chromecast_browser_test_helper_default.cc ('k') | media/test/data/player.html » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698