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

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

Issue 2869733005: Convert some audio code to OnceCallback. (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 "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
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(base::AdaptCallbackForRepeating(std::move(stop)));
240 }
241
242 MOCK_METHOD1(MockOnStarted, void(base::Closure stop));
239 }; 243 };
240 244
241 class MediaStreamDispatcherHostTest : public testing::Test { 245 class MediaStreamDispatcherHostTest : public testing::Test {
242 public: 246 public:
243 MediaStreamDispatcherHostTest() 247 MediaStreamDispatcherHostTest()
244 : thread_bundle_(content::TestBrowserThreadBundle::IO_MAINLOOP), 248 : thread_bundle_(content::TestBrowserThreadBundle::IO_MAINLOOP),
245 old_browser_client_(NULL), 249 old_browser_client_(NULL),
246 origin_(GURL("https://test.com")) { 250 origin_(GURL("https://test.com")) {
247 audio_manager_.reset( 251 audio_manager_.reset(
248 new media::MockAudioManager(base::ThreadTaskRunnerHandle::Get())); 252 new media::MockAudioManager(base::ThreadTaskRunnerHandle::Get()));
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after
316 320
317 ASSERT_GT(audio_device_descriptions_.size(), 0u); 321 ASSERT_GT(audio_device_descriptions_.size(), 0u);
318 } 322 }
319 323
320 void TearDown() override { host_->OnChannelClosing(); } 324 void TearDown() override { host_->OnChannelClosing(); }
321 325
322 protected: 326 protected:
323 virtual void SetupFakeUI(bool expect_started) { 327 virtual void SetupFakeUI(bool expect_started) {
324 stream_ui_ = new MockMediaStreamUIProxy(); 328 stream_ui_ = new MockMediaStreamUIProxy();
325 if (expect_started) { 329 if (expect_started) {
326 EXPECT_CALL(*stream_ui_, OnStarted(_, _)); 330 EXPECT_CALL(*stream_ui_, MockOnStarted(_));
327 } 331 }
328 media_stream_manager_->UseFakeUIForTests( 332 media_stream_manager_->UseFakeUIForTests(
329 std::unique_ptr<FakeMediaStreamUIProxy>(stream_ui_)); 333 std::unique_ptr<FakeMediaStreamUIProxy>(stream_ui_));
330 } 334 }
331 335
332 void GenerateStreamAndWaitForResult(int render_frame_id, 336 void GenerateStreamAndWaitForResult(int render_frame_id,
333 int page_request_id, 337 int page_request_id,
334 const StreamControls& controls) { 338 const StreamControls& controls) {
335 base::RunLoop run_loop; 339 base::RunLoop run_loop;
336 int expected_audio_array_size = 340 int expected_audio_array_size =
(...skipping 486 matching lines...) Expand 10 before | Expand all | Expand 10 after
823 host_->OnChannelClosing(); 827 host_->OnChannelClosing();
824 base::RunLoop().RunUntilIdle(); 828 base::RunLoop().RunUntilIdle();
825 } 829 }
826 830
827 TEST_F(MediaStreamDispatcherHostTest, CloseFromUI) { 831 TEST_F(MediaStreamDispatcherHostTest, CloseFromUI) {
828 StreamControls controls(false, true); 832 StreamControls controls(false, true);
829 833
830 base::Closure close_callback; 834 base::Closure close_callback;
831 std::unique_ptr<MockMediaStreamUIProxy> stream_ui( 835 std::unique_ptr<MockMediaStreamUIProxy> stream_ui(
832 new MockMediaStreamUIProxy()); 836 new MockMediaStreamUIProxy());
833 EXPECT_CALL(*stream_ui, OnStarted(_, _)) 837 EXPECT_CALL(*stream_ui, MockOnStarted(_))
834 .WillOnce(SaveArg<0>(&close_callback)); 838 .WillOnce(SaveArg<0>(&close_callback));
835 media_stream_manager_->UseFakeUIForTests(std::move(stream_ui)); 839 media_stream_manager_->UseFakeUIForTests(std::move(stream_ui));
836 840
837 GenerateStreamAndWaitForResult(kRenderId, kPageRequestId, controls); 841 GenerateStreamAndWaitForResult(kRenderId, kPageRequestId, controls);
838 842
839 EXPECT_EQ(host_->audio_devices_.size(), 0u); 843 EXPECT_EQ(host_->audio_devices_.size(), 0u);
840 EXPECT_EQ(host_->video_devices_.size(), 1u); 844 EXPECT_EQ(host_->video_devices_.size(), 1u);
841 845
842 ASSERT_FALSE(close_callback.is_null()); 846 ASSERT_FALSE(close_callback.is_null());
843 EXPECT_CALL(*host_.get(), OnDeviceStopped(kRenderId)); 847 EXPECT_CALL(*host_.get(), OnDeviceStopped(kRenderId));
(...skipping 15 matching lines...) Expand all
859 base::RunLoop run_loop; 863 base::RunLoop run_loop;
860 EXPECT_CALL(*host_.get(), OnDeviceStopped(kRenderId)) 864 EXPECT_CALL(*host_.get(), OnDeviceStopped(kRenderId))
861 .WillOnce(testing::InvokeWithoutArgs(&run_loop, &base::RunLoop::Quit)); 865 .WillOnce(testing::InvokeWithoutArgs(&run_loop, &base::RunLoop::Quit));
862 media_stream_manager_->media_devices_manager()->OnDevicesChanged( 866 media_stream_manager_->media_devices_manager()->OnDevicesChanged(
863 base::SystemMonitor::DEVTYPE_VIDEO_CAPTURE); 867 base::SystemMonitor::DEVTYPE_VIDEO_CAPTURE);
864 868
865 run_loop.Run(); 869 run_loop.Run();
866 } 870 }
867 871
868 }; // namespace content 872 }; // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698