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

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

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

Powered by Google App Engine
This is Rietveld 408576698