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

Side by Side Diff: content/browser/renderer_host/render_process_host_browsertest.cc

Issue 2655413004: Strip out stream counting from AudioRendererHost. (Closed)
Patch Set: Add moar DCHECKs. Created 3 years, 10 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
1 // Copyright 2013 The Chromium Authors. All rights reserved. 1 // Copyright 2013 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/bind.h" 5 #include "base/bind.h"
6 #include "base/command_line.h" 6 #include "base/command_line.h"
7 #include "base/run_loop.h" 7 #include "base/run_loop.h"
8 #include "build/build_config.h" 8 #include "build/build_config.h"
9 #include "content/browser/renderer_host/render_process_host_impl.h" 9 #include "content/browser/renderer_host/render_process_host_impl.h"
10 #include "content/common/child_process_messages.h" 10 #include "content/common/child_process_messages.h"
11 #include "content/public/browser/render_frame_host.h" 11 #include "content/public/browser/render_frame_host.h"
12 #include "content/public/browser/render_process_host.h" 12 #include "content/public/browser/render_process_host.h"
13 #include "content/public/browser/render_process_host_observer.h" 13 #include "content/public/browser/render_process_host_observer.h"
14 #include "content/public/browser/web_contents.h" 14 #include "content/public/browser/web_contents.h"
15 #include "content/public/common/content_switches.h" 15 #include "content/public/common/content_switches.h"
16 #include "content/public/common/url_constants.h" 16 #include "content/public/common/url_constants.h"
17 #include "content/public/test/content_browser_test.h" 17 #include "content/public/test/content_browser_test.h"
18 #include "content/public/test/content_browser_test_utils.h" 18 #include "content/public/test/content_browser_test_utils.h"
19 #include "content/public/test/test_service.mojom.h" 19 #include "content/public/test/test_service.mojom.h"
20 #include "content/shell/browser/shell.h" 20 #include "content/shell/browser/shell.h"
21 #include "media/base/test_data_util.h"
21 #include "net/test/embedded_test_server/embedded_test_server.h" 22 #include "net/test/embedded_test_server/embedded_test_server.h"
22 #include "services/service_manager/public/cpp/interface_provider.h" 23 #include "services/service_manager/public/cpp/interface_provider.h"
23 #include "services/service_manager/public/cpp/interface_registry.h" 24 #include "services/service_manager/public/cpp/interface_registry.h"
24 25
25 #if defined(OS_WIN) 26 #if defined(OS_WIN)
26 #include "base/win/windows_version.h" 27 #include "base/win/windows_version.h"
27 #endif 28 #endif
28 29
29 namespace content { 30 namespace content {
30 namespace { 31 namespace {
31 32
32 int RenderProcessHostCount() { 33 int RenderProcessHostCount() {
33 content::RenderProcessHost::iterator hosts = 34 content::RenderProcessHost::iterator hosts =
34 content::RenderProcessHost::AllHostsIterator(); 35 content::RenderProcessHost::AllHostsIterator();
35 int count = 0; 36 int count = 0;
36 while (!hosts.IsAtEnd()) { 37 while (!hosts.IsAtEnd()) {
37 if (hosts.GetCurrentValue()->HasConnection()) 38 if (hosts.GetCurrentValue()->HasConnection())
38 count++; 39 count++;
39 hosts.Advance(); 40 hosts.Advance();
40 } 41 }
41 return count; 42 return count;
42 } 43 }
43 44
44 class RenderProcessHostTest : public ContentBrowserTest, 45 class RenderProcessHostTest : public ContentBrowserTest,
45 public RenderProcessHostObserver { 46 public RenderProcessHostObserver {
46 public: 47 public:
47 RenderProcessHostTest() : process_exits_(0), host_destructions_(0) {} 48 RenderProcessHostTest() : process_exits_(0), host_destructions_(0) {}
48 49
50 void SetUpCommandLine(base::CommandLine* command_line) override {
51 command_line->AppendSwitch(
52 switches::kDisableGestureRequirementForMediaPlayback);
53 }
54
49 protected: 55 protected:
50 void set_process_exit_callback(const base::Closure& callback) { 56 void set_process_exit_callback(const base::Closure& callback) {
51 process_exit_callback_ = callback; 57 process_exit_callback_ = callback;
52 } 58 }
53 59
54 // RenderProcessHostObserver: 60 // RenderProcessHostObserver:
55 void RenderProcessExited(RenderProcessHost* host, 61 void RenderProcessExited(RenderProcessHost* host,
56 base::TerminationStatus status, 62 base::TerminationStatus status,
57 int exit_code) override { 63 int exit_code) override {
58 ++process_exits_; 64 ++process_exits_;
(...skipping 173 matching lines...) Expand 10 before | Expand all | Expand 10 after
232 service->DoSomething(base::Bind(&base::DoNothing)); 238 service->DoSomething(base::Bind(&base::DoNothing));
233 239
234 run_loop.Run(); 240 run_loop.Run();
235 241
236 EXPECT_EQ(1, process_exits_); 242 EXPECT_EQ(1, process_exits_);
237 EXPECT_EQ(0, host_destructions_); 243 EXPECT_EQ(0, host_destructions_);
238 if (!host_destructions_) 244 if (!host_destructions_)
239 rph->RemoveObserver(this); 245 rph->RemoveObserver(this);
240 } 246 }
241 247
248 class MediaStopObserver : public WebContentsObserver {
249 public:
250 MediaStopObserver(WebContents* web_contents, base::Closure quit_closure)
251 : WebContentsObserver(web_contents),
252 quit_closure_(std::move(quit_closure)) {}
253 ~MediaStopObserver() override {}
254
255 void MediaStoppedPlaying(
256 const WebContentsObserver::MediaPlayerInfo& media_info,
257 const WebContentsObserver::MediaPlayerId& id) override {
258 quit_closure_.Run();
259 }
260
261 private:
262 base::Closure quit_closure_;
263 };
264
265 // Tests that audio stream counts (used for process priority calculations) are
266 // properly set and cleared during media playback and renderer terminations.
267 //
268 // Note: This test can't run when the Mojo Renderer is used since it does not
269 // create audio streams through the normal audio pathways; at present this is
270 // only used by Chromecast.
271 #if defined(ENABLE_MOJO_RENDERER)
272 #define KillProcessZerosAudioStreams DISABLED_KillProcessZerosAudioStreams
273 #endif
274 IN_PROC_BROWSER_TEST_F(RenderProcessHostTest, KillProcessZerosAudioStreams) {
275 embedded_test_server()->ServeFilesFromSourceDirectory(
276 media::GetTestDataPath());
277 ASSERT_TRUE(embedded_test_server()->Start());
278 NavigateToURL(shell(), embedded_test_server()->GetURL("/sfx_s16le.wav"));
279 RenderProcessHostImpl* rph = static_cast<RenderProcessHostImpl*>(
280 shell()->web_contents()->GetMainFrame()->GetProcess());
281
282 {
283 // Wait for media playback to complete. We use the stop signal instead of
284 // the start signal here since the start signal does not mean the audio
285 // has actually started playing yet. Whereas the stop signal is sent before
286 // the audio device is actually torn down.
287 base::RunLoop run_loop;
288 MediaStopObserver stop_observer(shell()->web_contents(),
289 run_loop.QuitClosure());
290 run_loop.Run();
291
292 // No point in running the rest of the test if this is wrong.
293 ASSERT_EQ(1, rph->get_audio_stream_count_for_testing());
294 }
295
296 host_destructions_ = 0;
297 process_exits_ = 0;
298 rph->AddObserver(this);
299
300 mojom::TestServicePtr service;
301 rph->GetRemoteInterfaces()->GetInterface(&service);
302
303 {
304 // Force a bad message event to occur which will terminate the renderer.
305 base::RunLoop run_loop;
306 set_process_exit_callback(run_loop.QuitClosure());
307 service->DoSomething(base::Bind(&base::DoNothing));
308 run_loop.Run();
309 }
310
311 {
312 // Cycle UI loop once to ensure audio stream notifications are sent.
313 base::RunLoop run_loop;
314 BrowserThread::PostTask(BrowserThread::UI, FROM_HERE,
315 run_loop.QuitClosure());
316 run_loop.Run();
317 }
318
319 // Verify shutdown went as expected.
320 EXPECT_EQ(0, rph->get_audio_stream_count_for_testing());
321 EXPECT_EQ(1, process_exits_);
322 EXPECT_EQ(0, host_destructions_);
323 if (!host_destructions_)
324 rph->RemoveObserver(this);
325 }
326
242 } // namespace 327 } // namespace
243 } // namespace content 328 } // namespace content
OLDNEW
« no previous file with comments | « content/browser/renderer_host/media/audio_renderer_host.cc ('k') | content/browser/renderer_host/render_process_host_impl.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698