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