OLD | NEW |
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 "content/browser/renderer_host/media/media_stream_dispatcher_host.h" | 5 #include "content/browser/renderer_host/media/media_stream_dispatcher_host.h" |
6 | 6 |
7 #include <stddef.h> | 7 #include <stddef.h> |
8 #include <memory> | 8 #include <memory> |
9 #include <queue> | 9 #include <queue> |
10 #include <string> | 10 #include <string> |
(...skipping 215 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
226 opened_device_ = device; | 226 opened_device_ = device; |
227 } | 227 } |
228 | 228 |
229 const scoped_refptr<base::SingleThreadTaskRunner> task_runner_; | 229 const scoped_refptr<base::SingleThreadTaskRunner> task_runner_; |
230 IPC::Message* current_ipc_; | 230 IPC::Message* current_ipc_; |
231 std::queue<base::Closure> quit_closures_; | 231 std::queue<base::Closure> quit_closures_; |
232 }; | 232 }; |
233 | 233 |
234 class MockMediaStreamUIProxy : public FakeMediaStreamUIProxy { | 234 class MockMediaStreamUIProxy : public FakeMediaStreamUIProxy { |
235 public: | 235 public: |
236 MOCK_METHOD2( | 236 void OnStarted( |
237 OnStarted, | 237 base::OnceClosure stop, |
238 void(const base::Closure& stop, | 238 MediaStreamUIProxy::WindowIdCallback window_id_callback) override { |
239 const MediaStreamUIProxy::WindowIdCallback& window_id_callback)); | 239 // gmock cannot handle move-only types: |
| 240 MockOnStarted(base::AdaptCallbackForRepeating(std::move(stop))); |
| 241 } |
| 242 |
| 243 MOCK_METHOD1(MockOnStarted, void(base::Closure stop)); |
240 }; | 244 }; |
241 | 245 |
242 class MediaStreamDispatcherHostTest : public testing::Test { | 246 class MediaStreamDispatcherHostTest : public testing::Test { |
243 public: | 247 public: |
244 MediaStreamDispatcherHostTest() | 248 MediaStreamDispatcherHostTest() |
245 : thread_bundle_(content::TestBrowserThreadBundle::IO_MAINLOOP), | 249 : thread_bundle_(content::TestBrowserThreadBundle::IO_MAINLOOP), |
246 old_browser_client_(NULL), | 250 old_browser_client_(NULL), |
247 origin_(GURL("https://test.com")) { | 251 origin_(GURL("https://test.com")) { |
248 audio_manager_.reset(new media::MockAudioManager( | 252 audio_manager_.reset(new media::MockAudioManager( |
249 base::MakeUnique<media::TestAudioThread>())); | 253 base::MakeUnique<media::TestAudioThread>())); |
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
318 | 322 |
319 ASSERT_GT(audio_device_descriptions_.size(), 0u); | 323 ASSERT_GT(audio_device_descriptions_.size(), 0u); |
320 } | 324 } |
321 | 325 |
322 void TearDown() override { host_->OnChannelClosing(); } | 326 void TearDown() override { host_->OnChannelClosing(); } |
323 | 327 |
324 protected: | 328 protected: |
325 virtual void SetupFakeUI(bool expect_started) { | 329 virtual void SetupFakeUI(bool expect_started) { |
326 stream_ui_ = new MockMediaStreamUIProxy(); | 330 stream_ui_ = new MockMediaStreamUIProxy(); |
327 if (expect_started) { | 331 if (expect_started) { |
328 EXPECT_CALL(*stream_ui_, OnStarted(_, _)); | 332 EXPECT_CALL(*stream_ui_, MockOnStarted(_)); |
329 } | 333 } |
330 media_stream_manager_->UseFakeUIForTests( | 334 media_stream_manager_->UseFakeUIForTests( |
331 std::unique_ptr<FakeMediaStreamUIProxy>(stream_ui_)); | 335 std::unique_ptr<FakeMediaStreamUIProxy>(stream_ui_)); |
332 } | 336 } |
333 | 337 |
334 void GenerateStreamAndWaitForResult(int render_frame_id, | 338 void GenerateStreamAndWaitForResult(int render_frame_id, |
335 int page_request_id, | 339 int page_request_id, |
336 const StreamControls& controls) { | 340 const StreamControls& controls) { |
337 base::RunLoop run_loop; | 341 base::RunLoop run_loop; |
338 int expected_audio_array_size = | 342 int expected_audio_array_size = |
(...skipping 485 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
824 host_->OnChannelClosing(); | 828 host_->OnChannelClosing(); |
825 base::RunLoop().RunUntilIdle(); | 829 base::RunLoop().RunUntilIdle(); |
826 } | 830 } |
827 | 831 |
828 TEST_F(MediaStreamDispatcherHostTest, CloseFromUI) { | 832 TEST_F(MediaStreamDispatcherHostTest, CloseFromUI) { |
829 StreamControls controls(false, true); | 833 StreamControls controls(false, true); |
830 | 834 |
831 base::Closure close_callback; | 835 base::Closure close_callback; |
832 std::unique_ptr<MockMediaStreamUIProxy> stream_ui( | 836 std::unique_ptr<MockMediaStreamUIProxy> stream_ui( |
833 new MockMediaStreamUIProxy()); | 837 new MockMediaStreamUIProxy()); |
834 EXPECT_CALL(*stream_ui, OnStarted(_, _)) | 838 EXPECT_CALL(*stream_ui, MockOnStarted(_)) |
835 .WillOnce(SaveArg<0>(&close_callback)); | 839 .WillOnce(SaveArg<0>(&close_callback)); |
836 media_stream_manager_->UseFakeUIForTests(std::move(stream_ui)); | 840 media_stream_manager_->UseFakeUIForTests(std::move(stream_ui)); |
837 | 841 |
838 GenerateStreamAndWaitForResult(kRenderId, kPageRequestId, controls); | 842 GenerateStreamAndWaitForResult(kRenderId, kPageRequestId, controls); |
839 | 843 |
840 EXPECT_EQ(host_->audio_devices_.size(), 0u); | 844 EXPECT_EQ(host_->audio_devices_.size(), 0u); |
841 EXPECT_EQ(host_->video_devices_.size(), 1u); | 845 EXPECT_EQ(host_->video_devices_.size(), 1u); |
842 | 846 |
843 ASSERT_FALSE(close_callback.is_null()); | 847 ASSERT_FALSE(close_callback.is_null()); |
844 EXPECT_CALL(*host_.get(), OnDeviceStopped(kRenderId)); | 848 EXPECT_CALL(*host_.get(), OnDeviceStopped(kRenderId)); |
(...skipping 15 matching lines...) Expand all Loading... |
860 base::RunLoop run_loop; | 864 base::RunLoop run_loop; |
861 EXPECT_CALL(*host_.get(), OnDeviceStopped(kRenderId)) | 865 EXPECT_CALL(*host_.get(), OnDeviceStopped(kRenderId)) |
862 .WillOnce(testing::InvokeWithoutArgs(&run_loop, &base::RunLoop::Quit)); | 866 .WillOnce(testing::InvokeWithoutArgs(&run_loop, &base::RunLoop::Quit)); |
863 media_stream_manager_->media_devices_manager()->OnDevicesChanged( | 867 media_stream_manager_->media_devices_manager()->OnDevicesChanged( |
864 base::SystemMonitor::DEVTYPE_VIDEO_CAPTURE); | 868 base::SystemMonitor::DEVTYPE_VIDEO_CAPTURE); |
865 | 869 |
866 run_loop.Run(); | 870 run_loop.Run(); |
867 } | 871 } |
868 | 872 |
869 }; // namespace content | 873 }; // namespace content |
OLD | NEW |