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

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

Issue 2350693002: Remove device enumeration, caching and monitoring from MediaStreamManager. (Closed)
Patch Set: latest hta@ comments Created 4 years, 3 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/audio_input_device_manager.h" 5 #include "content/browser/renderer_host/media/audio_input_device_manager.h"
6 6
7 #include <stddef.h> 7 #include <stddef.h>
8 8
9 #include <memory> 9 #include <memory>
10 #include <string> 10 #include <string>
11 11
12 #include "base/bind.h" 12 #include "base/bind.h"
13 #include "base/command_line.h"
13 #include "base/location.h" 14 #include "base/location.h"
14 #include "base/macros.h" 15 #include "base/macros.h"
15 #include "base/memory/ref_counted.h" 16 #include "base/memory/ref_counted.h"
16 #include "base/run_loop.h" 17 #include "base/run_loop.h"
17 #include "base/single_thread_task_runner.h" 18 #include "base/single_thread_task_runner.h"
18 #include "base/threading/thread_task_runner_handle.h" 19 #include "base/threading/thread_task_runner_handle.h"
19 #include "build/build_config.h" 20 #include "build/build_config.h"
20 #include "content/public/common/media_stream_request.h" 21 #include "content/public/common/media_stream_request.h"
21 #include "content/public/test/test_browser_thread_bundle.h" 22 #include "content/public/test/test_browser_thread_bundle.h"
22 #include "media/audio/audio_manager_base.h" 23 #include "media/audio/audio_manager_base.h"
24 #include "media/base/media_switches.h"
23 #include "testing/gmock/include/gmock/gmock.h" 25 #include "testing/gmock/include/gmock/gmock.h"
24 #include "testing/gtest/include/gtest/gtest.h" 26 #include "testing/gtest/include/gtest/gtest.h"
25 27
26 using testing::_;
27 using testing::InSequence; 28 using testing::InSequence;
28 using testing::SaveArg;
29 using testing::Return;
30 29
31 namespace content { 30 namespace content {
32 31
33 class MockAudioInputDeviceManagerListener 32 class MockAudioInputDeviceManagerListener
34 : public MediaStreamProviderListener { 33 : public MediaStreamProviderListener {
35 public: 34 public:
36 MockAudioInputDeviceManagerListener() {} 35 MockAudioInputDeviceManagerListener() {}
37 virtual ~MockAudioInputDeviceManagerListener() {} 36 virtual ~MockAudioInputDeviceManagerListener() {}
38 37
39 MOCK_METHOD2(Opened, void(MediaStreamType, const int)); 38 MOCK_METHOD2(Opened, void(MediaStreamType, const int));
(...skipping 16 matching lines...) Expand all
56 #else 55 #else
57 #define MAYBE_AudioInputDeviceManagerTest AudioInputDeviceManagerTest 56 #define MAYBE_AudioInputDeviceManagerTest AudioInputDeviceManagerTest
58 #endif 57 #endif
59 58
60 class MAYBE_AudioInputDeviceManagerTest : public testing::Test { 59 class MAYBE_AudioInputDeviceManagerTest : public testing::Test {
61 public: 60 public:
62 MAYBE_AudioInputDeviceManagerTest() {} 61 MAYBE_AudioInputDeviceManagerTest() {}
63 62
64 protected: 63 protected:
65 void SetUp() override { 64 void SetUp() override {
65 base::CommandLine::ForCurrentProcess()->AppendSwitch(
66 switches::kUseFakeDeviceForMediaStream);
66 audio_manager_ = media::AudioManager::CreateForTesting( 67 audio_manager_ = media::AudioManager::CreateForTesting(
67 base::ThreadTaskRunnerHandle::Get()); 68 base::ThreadTaskRunnerHandle::Get());
68 // Flush the message loop to ensure proper initialization of AudioManager. 69 // Flush the message loop to ensure proper initialization of AudioManager.
69 base::RunLoop().RunUntilIdle(); 70 base::RunLoop().RunUntilIdle();
70 71
71 manager_ = new AudioInputDeviceManager(audio_manager_.get()); 72 manager_ = new AudioInputDeviceManager(audio_manager_.get());
72 manager_->UseFakeDevice();
73 audio_input_listener_.reset(new MockAudioInputDeviceManagerListener()); 73 audio_input_listener_.reset(new MockAudioInputDeviceManagerListener());
74 manager_->Register(audio_input_listener_.get(), 74 manager_->Register(audio_input_listener_.get(),
75 audio_manager_->GetTaskRunner()); 75 audio_manager_->GetTaskRunner());
76 76
77 // Gets the enumerated device list from the AudioInputDeviceManager. 77 // Use fake devices.
78 manager_->EnumerateDevices(MEDIA_DEVICE_AUDIO_CAPTURE); 78 devices_.emplace_back(MEDIA_DEVICE_AUDIO_CAPTURE, "Fake Device 1",
79 EXPECT_CALL(*audio_input_listener_, 79 "fake_device_1");
80 DevicesEnumerated(MEDIA_DEVICE_AUDIO_CAPTURE, _)) 80 devices_.emplace_back(MEDIA_DEVICE_AUDIO_CAPTURE, "Fake Device 2",
81 .Times(1) 81 "fake_device_2");
82 .WillOnce(SaveArg<1>(&devices_));
83 82
84 // Wait until we get the list. 83 // Wait until we get the list.
85 base::RunLoop().RunUntilIdle(); 84 base::RunLoop().RunUntilIdle();
86 } 85 }
87 86
88 void TearDown() override { 87 void TearDown() override {
89 manager_->Unregister(); 88 manager_->Unregister();
90 } 89 }
91 90
92 TestBrowserThreadBundle thread_bundle_; 91 TestBrowserThreadBundle thread_bundle_;
93 scoped_refptr<AudioInputDeviceManager> manager_; 92 scoped_refptr<AudioInputDeviceManager> manager_;
94 std::unique_ptr<MockAudioInputDeviceManagerListener> audio_input_listener_; 93 std::unique_ptr<MockAudioInputDeviceManagerListener> audio_input_listener_;
95 media::ScopedAudioManagerPtr audio_manager_; 94 media::ScopedAudioManagerPtr audio_manager_;
96 StreamDeviceInfoArray devices_; 95 StreamDeviceInfoArray devices_;
97 96
98 private: 97 private:
99 DISALLOW_COPY_AND_ASSIGN(MAYBE_AudioInputDeviceManagerTest); 98 DISALLOW_COPY_AND_ASSIGN(MAYBE_AudioInputDeviceManagerTest);
100 }; 99 };
101 100
102 // Opens and closes the devices. 101 // Opens and closes the devices.
103 TEST_F(MAYBE_AudioInputDeviceManagerTest, OpenAndCloseDevice) { 102 TEST_F(MAYBE_AudioInputDeviceManagerTest, OpenAndCloseDevice) {
104
105 ASSERT_FALSE(devices_.empty()); 103 ASSERT_FALSE(devices_.empty());
106 104
107 InSequence s; 105 InSequence s;
108 106
109 for (StreamDeviceInfoArray::const_iterator iter = devices_.begin(); 107 for (StreamDeviceInfoArray::const_iterator iter = devices_.begin();
110 iter != devices_.end(); ++iter) { 108 iter != devices_.end(); ++iter) {
111 // Opens/closes the devices. 109 // Opens/closes the devices.
112 int session_id = manager_->Open(*iter); 110 int session_id = manager_->Open(*iter);
113 111
114 // Expected mock call with expected return value. 112 // Expected mock call with expected return value.
(...skipping 164 matching lines...) Expand 10 before | Expand all | Expand 10 after
279 DCHECK(!info); 277 DCHECK(!info);
280 278
281 manager_->Close(session_id); 279 manager_->Close(session_id);
282 EXPECT_CALL(*audio_input_listener_, 280 EXPECT_CALL(*audio_input_listener_,
283 Closed(MEDIA_DEVICE_AUDIO_CAPTURE, session_id)) 281 Closed(MEDIA_DEVICE_AUDIO_CAPTURE, session_id))
284 .Times(1); 282 .Times(1);
285 base::RunLoop().RunUntilIdle(); 283 base::RunLoop().RunUntilIdle();
286 } 284 }
287 285
288 } // namespace content 286 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698