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

Side by Side Diff: content/browser/renderer_host/media/video_capture_unittest.cc

Issue 2784433002: Ensures that audio tasks cannot run after AudioManager is deleted. (Closed)
Patch Set: rebase Created 3 years, 7 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 (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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 <stdint.h> 5 #include <stdint.h>
6 6
7 #include <map> 7 #include <map>
8 #include <memory> 8 #include <memory>
9 #include <string> 9 #include <string>
10 10
(...skipping 11 matching lines...) Expand all
22 #include "content/browser/renderer_host/media/media_stream_requester.h" 22 #include "content/browser/renderer_host/media/media_stream_requester.h"
23 #include "content/browser/renderer_host/media/video_capture_host.h" 23 #include "content/browser/renderer_host/media/video_capture_host.h"
24 #include "content/browser/renderer_host/media/video_capture_manager.h" 24 #include "content/browser/renderer_host/media/video_capture_manager.h"
25 #include "content/common/media/media_devices.h" 25 #include "content/common/media/media_devices.h"
26 #include "content/public/common/content_switches.h" 26 #include "content/public/common/content_switches.h"
27 #include "content/public/test/test_browser_context.h" 27 #include "content/public/test/test_browser_context.h"
28 #include "content/public/test/test_browser_thread_bundle.h" 28 #include "content/public/test/test_browser_thread_bundle.h"
29 #include "content/test/test_content_browser_client.h" 29 #include "content/test/test_content_browser_client.h"
30 #include "media/audio/audio_system_impl.h" 30 #include "media/audio/audio_system_impl.h"
31 #include "media/audio/mock_audio_manager.h" 31 #include "media/audio/mock_audio_manager.h"
32 #include "media/audio/test_audio_thread.h"
32 #include "media/base/media_switches.h" 33 #include "media/base/media_switches.h"
33 #include "media/capture/video_capture_types.h" 34 #include "media/capture/video_capture_types.h"
34 #include "mojo/public/cpp/bindings/binding.h" 35 #include "mojo/public/cpp/bindings/binding.h"
35 #include "net/url_request/url_request_context.h" 36 #include "net/url_request/url_request_context.h"
36 #include "testing/gmock/include/gmock/gmock.h" 37 #include "testing/gmock/include/gmock/gmock.h"
37 #include "testing/gtest/include/gtest/gtest.h" 38 #include "testing/gtest/include/gtest/gtest.h"
38 39
39 using ::testing::_; 40 using ::testing::_;
40 using ::testing::AnyNumber; 41 using ::testing::AnyNumber;
41 using ::testing::AtMost; 42 using ::testing::AtMost;
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after
107 } 108 }
108 109
109 // This is an integration test of VideoCaptureHost in conjunction with 110 // This is an integration test of VideoCaptureHost in conjunction with
110 // MediaStreamManager, VideoCaptureManager, VideoCaptureController, and 111 // MediaStreamManager, VideoCaptureManager, VideoCaptureController, and
111 // VideoCaptureDevice. 112 // VideoCaptureDevice.
112 class VideoCaptureTest : public testing::Test, 113 class VideoCaptureTest : public testing::Test,
113 public mojom::VideoCaptureObserver { 114 public mojom::VideoCaptureObserver {
114 public: 115 public:
115 VideoCaptureTest() 116 VideoCaptureTest()
116 : thread_bundle_(content::TestBrowserThreadBundle::IO_MAINLOOP), 117 : thread_bundle_(content::TestBrowserThreadBundle::IO_MAINLOOP),
117 audio_manager_( 118 audio_manager_(new media::MockAudioManager(
118 new media::MockAudioManager(base::ThreadTaskRunnerHandle::Get())), 119 base::MakeUnique<media::TestAudioThread>())),
119 audio_system_(media::AudioSystemImpl::Create(audio_manager_.get())), 120 audio_system_(media::AudioSystemImpl::Create(audio_manager_.get())),
120 task_runner_(base::ThreadTaskRunnerHandle::Get()), 121 task_runner_(base::ThreadTaskRunnerHandle::Get()),
121 opened_session_id_(kInvalidMediaCaptureSessionId), 122 opened_session_id_(kInvalidMediaCaptureSessionId),
122 observer_binding_(this) {} 123 observer_binding_(this) {}
124 ~VideoCaptureTest() override { audio_manager_->Shutdown(); }
123 125
124 void SetUp() override { 126 void SetUp() override {
125 SetBrowserClientForTesting(&browser_client_); 127 SetBrowserClientForTesting(&browser_client_);
126 128
127 base::CommandLine::ForCurrentProcess()->AppendSwitch( 129 base::CommandLine::ForCurrentProcess()->AppendSwitch(
128 switches::kUseFakeDeviceForMediaStream); 130 switches::kUseFakeDeviceForMediaStream);
129 base::CommandLine::ForCurrentProcess()->AppendSwitch( 131 base::CommandLine::ForCurrentProcess()->AppendSwitch(
130 switches::kUseFakeUIForMediaStream); 132 switches::kUseFakeUIForMediaStream);
131 media_stream_manager_ = 133 media_stream_manager_ =
132 base::MakeUnique<MediaStreamManager>(audio_system_.get()); 134 base::MakeUnique<MediaStreamManager>(audio_system_.get());
(...skipping 169 matching lines...) Expand 10 before | Expand all | Expand 10 after
302 host_->OnError(id); 304 host_->OnError(id);
303 base::RunLoop().RunUntilIdle(); 305 base::RunLoop().RunUntilIdle();
304 } 306 }
305 307
306 private: 308 private:
307 // |media_stream_manager_| needs to outlive |thread_bundle_| because it is a 309 // |media_stream_manager_| needs to outlive |thread_bundle_| because it is a
308 // MessageLoop::DestructionObserver. 310 // MessageLoop::DestructionObserver.
309 StrictMock<MockMediaStreamRequester> stream_requester_; 311 StrictMock<MockMediaStreamRequester> stream_requester_;
310 std::unique_ptr<MediaStreamManager> media_stream_manager_; 312 std::unique_ptr<MediaStreamManager> media_stream_manager_;
311 const content::TestBrowserThreadBundle thread_bundle_; 313 const content::TestBrowserThreadBundle thread_bundle_;
312 // |audio_manager_| needs to outlive |thread_bundle_| because it uses the 314 std::unique_ptr<media::AudioManager> audio_manager_;
313 // underlying message loop.
314 media::ScopedAudioManagerPtr audio_manager_;
315 std::unique_ptr<media::AudioSystem> audio_system_; 315 std::unique_ptr<media::AudioSystem> audio_system_;
316 content::TestBrowserContext browser_context_; 316 content::TestBrowserContext browser_context_;
317 content::TestContentBrowserClient browser_client_; 317 content::TestContentBrowserClient browser_client_;
318 const scoped_refptr<base::SingleThreadTaskRunner> task_runner_; 318 const scoped_refptr<base::SingleThreadTaskRunner> task_runner_;
319 int opened_session_id_; 319 int opened_session_id_;
320 std::string opened_device_label_; 320 std::string opened_device_label_;
321 321
322 std::unique_ptr<VideoCaptureHost> host_; 322 std::unique_ptr<VideoCaptureHost> host_;
323 mojo::Binding<mojom::VideoCaptureObserver> observer_binding_; 323 mojo::Binding<mojom::VideoCaptureObserver> observer_binding_;
324 324
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
364 StartCapture(); 364 StartCapture();
365 365
366 // When the session is closed via the stream without stopping capture, the 366 // When the session is closed via the stream without stopping capture, the
367 // ENDED event is sent. 367 // ENDED event is sent.
368 EXPECT_CALL(*this, OnStateChanged(mojom::VideoCaptureState::ENDED)); 368 EXPECT_CALL(*this, OnStateChanged(mojom::VideoCaptureState::ENDED));
369 CloseSession(); 369 CloseSession();
370 base::RunLoop().RunUntilIdle(); 370 base::RunLoop().RunUntilIdle();
371 } 371 }
372 372
373 } // namespace content 373 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698