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

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

Issue 2487133003: Remove dead code related to media device enumerations and monitoring. (Closed)
Patch Set: rebase Created 4 years, 1 month 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 <stddef.h> 5 #include <stddef.h>
6 6
7 #include <string> 7 #include <string>
8 8
9 #include "base/bind.h" 9 #include "base/bind.h"
10 #include "base/command_line.h" 10 #include "base/command_line.h"
(...skipping 114 matching lines...) Expand 10 before | Expand all | Expand 10 after
125 125
126 private: 126 private:
127 media::FakeAudioLogFactory fake_audio_log_factory_; 127 media::FakeAudioLogFactory fake_audio_log_factory_;
128 size_t num_output_devices_; 128 size_t num_output_devices_;
129 size_t num_input_devices_; 129 size_t num_input_devices_;
130 DISALLOW_COPY_AND_ASSIGN(MockAudioManager); 130 DISALLOW_COPY_AND_ASSIGN(MockAudioManager);
131 }; 131 };
132 132
133 class MockMediaStreamRequester : public MediaStreamRequester { 133 class MockMediaStreamRequester : public MediaStreamRequester {
134 public: 134 public:
135 MockMediaStreamRequester(MediaStreamManager* media_stream_manager, 135 virtual ~MockMediaStreamRequester() {}
136 base::RunLoop* run_loop_enumeration,
137 size_t num_expected_devices,
138 base::RunLoop* run_loop_devices_changed)
139 : media_stream_manager_(media_stream_manager),
140 run_loop_enumeration_(run_loop_enumeration),
141 num_expected_devices_(num_expected_devices),
142 run_loop_devices_changed_(run_loop_devices_changed),
143 is_device_change_subscriber_(false) {}
144 virtual ~MockMediaStreamRequester() {
145 if (is_device_change_subscriber_)
146 media_stream_manager_->CancelDeviceChangeNotifications(this);
147 }
148 136
149 // MediaStreamRequester implementation. 137 // MediaStreamRequester implementation.
150 MOCK_METHOD5(StreamGenerated, 138 MOCK_METHOD5(StreamGenerated,
151 void(int render_frame_id, 139 void(int render_frame_id,
152 int page_request_id, 140 int page_request_id,
153 const std::string& label, 141 const std::string& label,
154 const StreamDeviceInfoArray& audio_devices, 142 const StreamDeviceInfoArray& audio_devices,
155 const StreamDeviceInfoArray& video_devices)); 143 const StreamDeviceInfoArray& video_devices));
156 MOCK_METHOD3(StreamGenerationFailed, 144 MOCK_METHOD3(StreamGenerationFailed,
157 void(int render_frame_id, 145 void(int render_frame_id,
158 int page_request_id, 146 int page_request_id,
159 content::MediaStreamRequestResult result)); 147 content::MediaStreamRequestResult result));
160 MOCK_METHOD3(DeviceStopped, 148 MOCK_METHOD3(DeviceStopped,
161 void(int render_frame_id, 149 void(int render_frame_id,
162 const std::string& label, 150 const std::string& label,
163 const StreamDeviceInfo& device)); 151 const StreamDeviceInfo& device));
164 void DevicesEnumerated(int render_frame_id,
165 int page_request_id,
166 const std::string& label,
167 const StreamDeviceInfoArray& devices) override {
168 MockDevicesEnumerated(render_frame_id, page_request_id, label, devices);
169 EXPECT_EQ(num_expected_devices_, devices.size());
170
171 if (run_loop_enumeration_)
172 run_loop_enumeration_->Quit();
173 }
174 MOCK_METHOD4(MockDevicesEnumerated,
175 void(int render_frame_id,
176 int page_request_id,
177 const std::string& label,
178 const StreamDeviceInfoArray& devices));
179 MOCK_METHOD4(DeviceOpened, 152 MOCK_METHOD4(DeviceOpened,
180 void(int render_frame_id, 153 void(int render_frame_id,
181 int page_request_id, 154 int page_request_id,
182 const std::string& label, 155 const std::string& label,
183 const StreamDeviceInfo& device_info)); 156 const StreamDeviceInfo& device_info));
184 void DevicesChanged(MediaStreamType type) override {
185 MockDevicesChanged(type);
186 if (run_loop_devices_changed_)
187 run_loop_devices_changed_->Quit();
188 }
189 MOCK_METHOD1(MockDevicesChanged, void(MediaStreamType type));
190
191 void SubscribeToDeviceChangeNotifications() {
192 if (is_device_change_subscriber_)
193 return;
194
195 media_stream_manager_->SubscribeToDeviceChangeNotifications(this);
196 is_device_change_subscriber_ = true;
197 }
198 157
199 private: 158 private:
200 MediaStreamManager* media_stream_manager_;
201 base::RunLoop* run_loop_enumeration_;
202 size_t num_expected_devices_;
203 base::RunLoop* run_loop_devices_changed_;
204 bool is_device_change_subscriber_;
205 DISALLOW_COPY_AND_ASSIGN(MockMediaStreamRequester); 159 DISALLOW_COPY_AND_ASSIGN(MockMediaStreamRequester);
206 }; 160 };
207 161
208 } // namespace 162 } // namespace
209 163
210 class MediaStreamManagerTest : public ::testing::Test { 164 class MediaStreamManagerTest : public ::testing::Test {
211 public: 165 public:
212 MediaStreamManagerTest() 166 MediaStreamManagerTest()
213 : thread_bundle_(content::TestBrowserThreadBundle::IO_MAINLOOP) { 167 : thread_bundle_(content::TestBrowserThreadBundle::IO_MAINLOOP) {
214 audio_manager_.reset(new MockAudioManager()); 168 audio_manager_.reset(new MockAudioManager());
(...skipping 116 matching lines...) Expand 10 before | Expand all | Expand 10 after
331 MediaStreamManager::GetHMACForMediaDeviceID(kMockSalt, security_origin, 285 MediaStreamManager::GetHMACForMediaDeviceID(kMockSalt, security_origin,
332 unique_other_id); 286 unique_other_id);
333 EXPECT_TRUE(MediaStreamManager::DoesMediaDeviceIDMatchHMAC( 287 EXPECT_TRUE(MediaStreamManager::DoesMediaDeviceIDMatchHMAC(
334 kMockSalt, security_origin, hashed_other_id, unique_other_id)); 288 kMockSalt, security_origin, hashed_other_id, unique_other_id));
335 EXPECT_NE(unique_other_id, hashed_other_id); 289 EXPECT_NE(unique_other_id, hashed_other_id);
336 EXPECT_EQ(hashed_other_id.size(), 64U); 290 EXPECT_EQ(hashed_other_id.size(), 64U);
337 for (const char& c : hashed_other_id) 291 for (const char& c : hashed_other_id)
338 EXPECT_TRUE(base::IsAsciiDigit(c) || (c >= 'a' && c <= 'f')); 292 EXPECT_TRUE(base::IsAsciiDigit(c) || (c >= 'a' && c <= 'f'));
339 } 293 }
340 294
341 TEST_F(MediaStreamManagerTest, EnumerationOutputDevices) {
342 for (size_t num_devices = 0; num_devices < 3; num_devices++) {
343 audio_manager_->SetNumAudioOutputDevices(num_devices);
344 base::RunLoop run_loop;
345 MockMediaStreamRequester requester(media_stream_manager_.get(), &run_loop,
346 num_devices == 0 ? 0 : num_devices + 1,
347 nullptr);
348 const int render_process_id = 1;
349 const int render_frame_id = 1;
350 const int page_request_id = 1;
351 const url::Origin security_origin(GURL("http://localhost"));
352 EXPECT_CALL(requester,
353 MockDevicesEnumerated(render_frame_id, page_request_id, _, _));
354 std::string label = media_stream_manager_->EnumerateDevices(
355 &requester, render_process_id, render_frame_id, kMockSalt,
356 page_request_id, MEDIA_DEVICE_AUDIO_OUTPUT, security_origin);
357 run_loop.Run();
358 // CancelRequest is necessary for enumeration requests.
359 media_stream_manager_->CancelRequest(label);
360 }
361 }
362
363 TEST_F(MediaStreamManagerTest, NotifyDeviceChanges) {
364 const int render_process_id = 1;
365 const int render_frame_id = 1;
366 const int page_request_id = 1;
367 const url::Origin security_origin(GURL("http://localhost"));
368
369 // Check that device change notifications are received
370 {
371 // First run an enumeration to warm up the cache
372 base::RunLoop run_loop_enumeration;
373 base::RunLoop run_loop_device_change;
374 MockMediaStreamRequester requester(media_stream_manager_.get(),
375 &run_loop_enumeration, 3,
376 &run_loop_device_change);
377 audio_manager_->SetNumAudioInputDevices(2);
378 requester.SubscribeToDeviceChangeNotifications();
379
380 EXPECT_CALL(requester,
381 MockDevicesEnumerated(render_frame_id, page_request_id, _, _));
382 EXPECT_CALL(requester, MockDevicesChanged(_)).Times(0);
383 std::string label = media_stream_manager_->EnumerateDevices(
384 &requester, render_process_id, render_frame_id, kMockSalt,
385 page_request_id, MEDIA_DEVICE_AUDIO_CAPTURE, security_origin);
386 run_loop_enumeration.Run();
387 media_stream_manager_->CancelRequest(label);
388
389 // Simulate device change
390 EXPECT_CALL(requester, MockDevicesChanged(_));
391 audio_manager_->SetNumAudioInputDevices(3);
392 media_stream_manager_->media_devices_manager()->OnDevicesChanged(
393 base::SystemMonitor::DEVTYPE_AUDIO);
394 run_loop_device_change.Run();
395 }
396
397 // Check that bogus device changes where devices have not changed
398 // do not trigger a notification.
399 {
400 base::RunLoop run_loop;
401 MockMediaStreamRequester requester(media_stream_manager_.get(), &run_loop,
402 4, &run_loop);
403 requester.SubscribeToDeviceChangeNotifications();
404
405 // Bogus OnDeviceChange, as devices have not changed. Should not trigger
406 // notification.
407 EXPECT_CALL(requester, MockDevicesChanged(_)).Times(0);
408 media_stream_manager_->media_devices_manager()->OnDevicesChanged(
409 base::SystemMonitor::DEVTYPE_AUDIO);
410
411 // Do enumeration to be able to quit the RunLoop.
412 EXPECT_CALL(requester,
413 MockDevicesEnumerated(render_frame_id, page_request_id, _, _));
414 std::string label = media_stream_manager_->EnumerateDevices(
415 &requester, render_process_id, render_frame_id, kMockSalt,
416 page_request_id, MEDIA_DEVICE_AUDIO_CAPTURE, security_origin);
417 run_loop.Run();
418 media_stream_manager_->CancelRequest(label);
419 }
420 }
421
422 } // namespace content 295 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698