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

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

Issue 1159623009: content: Remove use of MessageLoopProxy and deprecated MessageLoop APIs (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Test build fix. Created 5 years, 6 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 <queue>
5 #include <string> 6 #include <string>
6 #include <queue>
7 7
8 #include "base/bind.h" 8 #include "base/bind.h"
9 #include "base/callback_helpers.h" 9 #include "base/callback_helpers.h"
10 #include "base/command_line.h" 10 #include "base/command_line.h"
11 #include "base/message_loop/message_loop.h" 11 #include "base/location.h"
12 #include "base/run_loop.h" 12 #include "base/run_loop.h"
13 #include "base/single_thread_task_runner.h"
14 #include "base/thread_task_runner_handle.h"
13 #include "content/browser/browser_thread_impl.h" 15 #include "content/browser/browser_thread_impl.h"
14 #include "content/browser/renderer_host/media/audio_input_device_manager.h" 16 #include "content/browser/renderer_host/media/audio_input_device_manager.h"
15 #include "content/browser/renderer_host/media/media_stream_dispatcher_host.h" 17 #include "content/browser/renderer_host/media/media_stream_dispatcher_host.h"
16 #include "content/browser/renderer_host/media/media_stream_manager.h" 18 #include "content/browser/renderer_host/media/media_stream_manager.h"
17 #include "content/browser/renderer_host/media/media_stream_ui_proxy.h" 19 #include "content/browser/renderer_host/media/media_stream_ui_proxy.h"
18 #include "content/browser/renderer_host/media/video_capture_manager.h" 20 #include "content/browser/renderer_host/media/video_capture_manager.h"
19 #include "content/common/media/media_stream_messages.h" 21 #include "content/common/media/media_stream_messages.h"
20 #include "content/common/media/media_stream_options.h" 22 #include "content/common/media/media_stream_options.h"
21 #include "content/public/browser/media_device_id.h" 23 #include "content/public/browser/media_device_id.h"
22 #include "content/public/common/content_switches.h" 24 #include "content/public/common/content_switches.h"
(...skipping 25 matching lines...) Expand all
48 const int kRenderId = 6; 50 const int kRenderId = 6;
49 const int kPageRequestId = 7; 51 const int kPageRequestId = 7;
50 52
51 namespace content { 53 namespace content {
52 54
53 class MockMediaStreamDispatcherHost : public MediaStreamDispatcherHost, 55 class MockMediaStreamDispatcherHost : public MediaStreamDispatcherHost,
54 public TestContentBrowserClient { 56 public TestContentBrowserClient {
55 public: 57 public:
56 MockMediaStreamDispatcherHost( 58 MockMediaStreamDispatcherHost(
57 const ResourceContext::SaltCallback salt_callback, 59 const ResourceContext::SaltCallback salt_callback,
58 const scoped_refptr<base::MessageLoopProxy>& message_loop, 60 const scoped_refptr<base::SingleThreadTaskRunner>& task_runner,
59 MediaStreamManager* manager) 61 MediaStreamManager* manager)
60 : MediaStreamDispatcherHost(kProcessId, salt_callback, manager), 62 : MediaStreamDispatcherHost(kProcessId, salt_callback, manager),
61 message_loop_(message_loop), 63 task_runner_(task_runner),
62 current_ipc_(NULL) {} 64 current_ipc_(NULL) {}
63 65
64 // A list of mock methods. 66 // A list of mock methods.
65 MOCK_METHOD4(OnStreamGenerated, 67 MOCK_METHOD4(OnStreamGenerated,
66 void(int routing_id, int request_id, int audio_array_size, 68 void(int routing_id, int request_id, int audio_array_size,
67 int video_array_size)); 69 int video_array_size));
68 MOCK_METHOD3(OnStreamGenerationFailed, void(int routing_id, 70 MOCK_METHOD3(OnStreamGenerationFailed, void(int routing_id,
69 int request_id, 71 int request_id,
70 MediaStreamRequestResult result)); 72 MediaStreamRequestResult result));
71 MOCK_METHOD1(OnDeviceStopped, void(int routing_id)); 73 MOCK_METHOD1(OnDeviceStopped, void(int routing_id));
(...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after
148 void OnStreamGeneratedInternal( 150 void OnStreamGeneratedInternal(
149 int request_id, 151 int request_id,
150 std::string label, 152 std::string label,
151 StreamDeviceInfoArray audio_device_list, 153 StreamDeviceInfoArray audio_device_list,
152 StreamDeviceInfoArray video_device_list) { 154 StreamDeviceInfoArray video_device_list) {
153 OnStreamGenerated(current_ipc_->routing_id(), request_id, 155 OnStreamGenerated(current_ipc_->routing_id(), request_id,
154 audio_device_list.size(), video_device_list.size()); 156 audio_device_list.size(), video_device_list.size());
155 // Notify that the event have occurred. 157 // Notify that the event have occurred.
156 base::Closure quit_closure = quit_closures_.front(); 158 base::Closure quit_closure = quit_closures_.front();
157 quit_closures_.pop(); 159 quit_closures_.pop();
158 message_loop_->PostTask(FROM_HERE, base::ResetAndReturn(&quit_closure)); 160 task_runner_->PostTask(FROM_HERE, base::ResetAndReturn(&quit_closure));
159 161
160 label_ = label; 162 label_ = label;
161 audio_devices_ = audio_device_list; 163 audio_devices_ = audio_device_list;
162 video_devices_ = video_device_list; 164 video_devices_ = video_device_list;
163 } 165 }
164 166
165 void OnStreamGenerationFailedInternal( 167 void OnStreamGenerationFailedInternal(
166 int request_id, 168 int request_id,
167 content::MediaStreamRequestResult result) { 169 content::MediaStreamRequestResult result) {
168 OnStreamGenerationFailed(current_ipc_->routing_id(), request_id, result); 170 OnStreamGenerationFailed(current_ipc_->routing_id(), request_id, result);
169 if (!quit_closures_.empty()) { 171 if (!quit_closures_.empty()) {
170 base::Closure quit_closure = quit_closures_.front(); 172 base::Closure quit_closure = quit_closures_.front();
171 quit_closures_.pop(); 173 quit_closures_.pop();
172 message_loop_->PostTask(FROM_HERE, base::ResetAndReturn(&quit_closure)); 174 task_runner_->PostTask(FROM_HERE, base::ResetAndReturn(&quit_closure));
173 } 175 }
174 176
175 label_= ""; 177 label_= "";
176 } 178 }
177 179
178 void OnDeviceStoppedInternal(const std::string& label, 180 void OnDeviceStoppedInternal(const std::string& label,
179 const content::StreamDeviceInfo& device) { 181 const content::StreamDeviceInfo& device) {
180 if (IsVideoMediaType(device.device.type)) 182 if (IsVideoMediaType(device.device.type))
181 EXPECT_TRUE(StreamDeviceInfo::IsEqual(device, video_devices_[0])); 183 EXPECT_TRUE(StreamDeviceInfo::IsEqual(device, video_devices_[0]));
182 if (IsAudioInputMediaType(device.device.type)) 184 if (IsAudioInputMediaType(device.device.type))
183 EXPECT_TRUE(StreamDeviceInfo::IsEqual(device, audio_devices_[0])); 185 EXPECT_TRUE(StreamDeviceInfo::IsEqual(device, audio_devices_[0]));
184 186
185 OnDeviceStopped(current_ipc_->routing_id()); 187 OnDeviceStopped(current_ipc_->routing_id());
186 } 188 }
187 189
188 void OnDeviceOpenedInternal(int request_id, 190 void OnDeviceOpenedInternal(int request_id,
189 const std::string& label, 191 const std::string& label,
190 const StreamDeviceInfo& device) { 192 const StreamDeviceInfo& device) {
191 base::Closure quit_closure = quit_closures_.front(); 193 base::Closure quit_closure = quit_closures_.front();
192 quit_closures_.pop(); 194 quit_closures_.pop();
193 message_loop_->PostTask(FROM_HERE, base::ResetAndReturn(&quit_closure)); 195 task_runner_->PostTask(FROM_HERE, base::ResetAndReturn(&quit_closure));
194 label_ = label; 196 label_ = label;
195 opened_device_ = device; 197 opened_device_ = device;
196 } 198 }
197 199
198 void OnDevicesEnumerated(int request_id, 200 void OnDevicesEnumerated(int request_id,
199 const StreamDeviceInfoArray& devices) { 201 const StreamDeviceInfoArray& devices) {
200 base::Closure quit_closure = quit_closures_.front(); 202 base::Closure quit_closure = quit_closures_.front();
201 quit_closures_.pop(); 203 quit_closures_.pop();
202 message_loop_->PostTask(FROM_HERE, base::ResetAndReturn(&quit_closure)); 204 task_runner_->PostTask(FROM_HERE, base::ResetAndReturn(&quit_closure));
203 enumerated_devices_ = devices; 205 enumerated_devices_ = devices;
204 } 206 }
205 207
206 scoped_refptr<base::MessageLoopProxy> message_loop_; 208 scoped_refptr<base::SingleThreadTaskRunner> task_runner_;
207 IPC::Message* current_ipc_; 209 IPC::Message* current_ipc_;
208 std::queue<base::Closure> quit_closures_; 210 std::queue<base::Closure> quit_closures_;
209 }; 211 };
210 212
211 class MockMediaStreamUIProxy : public FakeMediaStreamUIProxy { 213 class MockMediaStreamUIProxy : public FakeMediaStreamUIProxy {
212 public: 214 public:
213 MOCK_METHOD2( 215 MOCK_METHOD2(
214 OnStarted, 216 OnStarted,
215 void(const base::Closure& stop, 217 void(const base::Closure& stop,
216 const MediaStreamUIProxy::WindowIdCallback& window_id_callback)); 218 const MediaStreamUIProxy::WindowIdCallback& window_id_callback));
217 }; 219 };
218 220
219 class MediaStreamDispatcherHostTest : public testing::Test { 221 class MediaStreamDispatcherHostTest : public testing::Test {
220 public: 222 public:
221 MediaStreamDispatcherHostTest() 223 MediaStreamDispatcherHostTest()
222 : old_browser_client_(NULL), 224 : old_browser_client_(NULL),
223 thread_bundle_(content::TestBrowserThreadBundle::IO_MAINLOOP), 225 thread_bundle_(content::TestBrowserThreadBundle::IO_MAINLOOP),
224 origin_("https://test.com") { 226 origin_("https://test.com") {
225 audio_manager_.reset( 227 audio_manager_.reset(
226 new media::MockAudioManager(base::MessageLoopProxy::current())); 228 new media::MockAudioManager(base::ThreadTaskRunnerHandle::Get()));
227 // Make sure we use fake devices to avoid long delays. 229 // Make sure we use fake devices to avoid long delays.
228 base::CommandLine::ForCurrentProcess()->AppendSwitch( 230 base::CommandLine::ForCurrentProcess()->AppendSwitch(
229 switches::kUseFakeDeviceForMediaStream); 231 switches::kUseFakeDeviceForMediaStream);
230 // Create our own MediaStreamManager. 232 // Create our own MediaStreamManager.
231 media_stream_manager_.reset(new MediaStreamManager(audio_manager_.get())); 233 media_stream_manager_.reset(new MediaStreamManager(audio_manager_.get()));
232 video_capture_device_factory_ = 234 video_capture_device_factory_ =
233 static_cast<media::FakeVideoCaptureDeviceFactory*>( 235 static_cast<media::FakeVideoCaptureDeviceFactory*>(
234 media_stream_manager_->video_capture_manager() 236 media_stream_manager_->video_capture_manager()
235 ->video_capture_device_factory()); 237 ->video_capture_device_factory());
236 DCHECK(video_capture_device_factory_); 238 DCHECK(video_capture_device_factory_);
237 #if defined(OS_WIN) 239 #if defined(OS_WIN)
238 // Override the Video Capture Thread that MediaStreamManager constructs. 240 // Override the Video Capture Thread that MediaStreamManager constructs.
239 media_stream_manager_->video_capture_manager()->set_device_task_runner( 241 media_stream_manager_->video_capture_manager()->set_device_task_runner(
240 base::MessageLoopProxy::current()); 242 base::ThreadTaskRunnerHandle::Get());
241 #endif 243 #endif
242 244
243 MockResourceContext* mock_resource_context = 245 MockResourceContext* mock_resource_context =
244 static_cast<MockResourceContext*>( 246 static_cast<MockResourceContext*>(
245 browser_context_.GetResourceContext()); 247 browser_context_.GetResourceContext());
246 248
247 host_ = new MockMediaStreamDispatcherHost( 249 host_ = new MockMediaStreamDispatcherHost(
248 mock_resource_context->GetMediaDeviceIDSalt(), 250 mock_resource_context->GetMediaDeviceIDSalt(),
249 base::MessageLoopProxy::current(), 251 base::ThreadTaskRunnerHandle::Get(), media_stream_manager_.get());
250 media_stream_manager_.get());
251 252
252 // Use the fake content client and browser. 253 // Use the fake content client and browser.
253 content_client_.reset(new TestContentClient()); 254 content_client_.reset(new TestContentClient());
254 SetContentClient(content_client_.get()); 255 SetContentClient(content_client_.get());
255 old_browser_client_ = SetBrowserClientForTesting(host_.get()); 256 old_browser_client_ = SetBrowserClientForTesting(host_.get());
256 257
257 #if defined(OS_CHROMEOS) 258 #if defined(OS_CHROMEOS)
258 chromeos::CrasAudioHandler::InitializeForTesting(); 259 chromeos::CrasAudioHandler::InitializeForTesting();
259 #endif 260 #endif
260 } 261 }
(...skipping 657 matching lines...) Expand 10 before | Expand all | Expand 10 after
918 919
919 TEST_F(MediaStreamDispatcherHostTest, EnumerateVideoDevicesNoAccess) { 920 TEST_F(MediaStreamDispatcherHostTest, EnumerateVideoDevicesNoAccess) {
920 SetupFakeUI(false); 921 SetupFakeUI(false);
921 stream_ui_->SetCameraAccess(false); 922 stream_ui_->SetCameraAccess(false);
922 EnumerateDevicesAndWaitForResult(kRenderId, kPageRequestId, 923 EnumerateDevicesAndWaitForResult(kRenderId, kPageRequestId,
923 MEDIA_DEVICE_VIDEO_CAPTURE); 924 MEDIA_DEVICE_VIDEO_CAPTURE);
924 EXPECT_TRUE(DoesNotContainLabels(host_->enumerated_devices_)); 925 EXPECT_TRUE(DoesNotContainLabels(host_->enumerated_devices_));
925 } 926 }
926 927
927 }; // namespace content 928 }; // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698