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

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

Issue 54863002: Implement a salt for MediaSource IDs that can be cleared by a user. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Addressed willchans comments. Created 7 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 | Annotate | Revision Log
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 <string>
6 #include <queue> 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/message_loop/message_loop.h" 10 #include "base/message_loop/message_loop.h"
11 #include "base/run_loop.h" 11 #include "base/run_loop.h"
12 #include "content/browser/browser_thread_impl.h" 12 #include "content/browser/browser_thread_impl.h"
13 #include "content/browser/renderer_host/media/media_stream_dispatcher_host.h" 13 #include "content/browser/renderer_host/media/media_stream_dispatcher_host.h"
14 #include "content/browser/renderer_host/media/media_stream_manager.h" 14 #include "content/browser/renderer_host/media/media_stream_manager.h"
15 #include "content/browser/renderer_host/media/media_stream_ui_proxy.h" 15 #include "content/browser/renderer_host/media/media_stream_ui_proxy.h"
16 #include "content/common/media/media_stream_messages.h" 16 #include "content/common/media/media_stream_messages.h"
17 #include "content/common/media/media_stream_options.h" 17 #include "content/common/media/media_stream_options.h"
18 #include "content/public/browser/media_device_id.h" 18 #include "content/public/browser/media_device_id.h"
19 #include "content/public/test/mock_resource_context.h" 19 #include "content/public/test/mock_resource_context.h"
20 #include "content/public/test/test_browser_context.h"
20 #include "content/public/test/test_browser_thread_bundle.h" 21 #include "content/public/test/test_browser_thread_bundle.h"
21 #include "content/test/test_content_browser_client.h" 22 #include "content/test/test_content_browser_client.h"
22 #include "content/test/test_content_client.h" 23 #include "content/test/test_content_client.h"
23 #include "ipc/ipc_message_macros.h" 24 #include "ipc/ipc_message_macros.h"
24 #include "media/audio/mock_audio_manager.h" 25 #include "media/audio/mock_audio_manager.h"
25 #include "media/video/capture/fake_video_capture_device.h" 26 #include "media/video/capture/fake_video_capture_device.h"
26 #include "net/url_request/url_request_context.h" 27 #include "net/url_request/url_request_context.h"
27 #include "testing/gmock/include/gmock/gmock.h" 28 #include "testing/gmock/include/gmock/gmock.h"
28 #include "testing/gtest/include/gtest/gtest.h" 29 #include "testing/gtest/include/gtest/gtest.h"
29 30
30 using ::testing::_; 31 using ::testing::_;
31 using ::testing::DeleteArg; 32 using ::testing::DeleteArg;
32 using ::testing::DoAll; 33 using ::testing::DoAll;
33 using ::testing::Return; 34 using ::testing::Return;
34 using ::testing::SaveArg; 35 using ::testing::SaveArg;
35 36
36 const int kProcessId = 5; 37 const int kProcessId = 5;
37 const int kRenderId = 6; 38 const int kRenderId = 6;
38 const int kPageRequestId = 7; 39 const int kPageRequestId = 7;
39 40
40 namespace content { 41 namespace content {
41 42
42 class MockMediaStreamDispatcherHost : public MediaStreamDispatcherHost, 43 class MockMediaStreamDispatcherHost : public MediaStreamDispatcherHost,
43 public TestContentBrowserClient { 44 public TestContentBrowserClient {
44 public: 45 public:
45 MockMediaStreamDispatcherHost( 46 MockMediaStreamDispatcherHost(
47 ResourceContext* resource_context,
46 const scoped_refptr<base::MessageLoopProxy>& message_loop, 48 const scoped_refptr<base::MessageLoopProxy>& message_loop,
47 MediaStreamManager* manager) 49 MediaStreamManager* manager)
48 : MediaStreamDispatcherHost(kProcessId, manager), 50 : MediaStreamDispatcherHost(kProcessId, resource_context, manager),
49 message_loop_(message_loop) {} 51 message_loop_(message_loop) {}
50 52
51 // A list of mock methods. 53 // A list of mock methods.
52 MOCK_METHOD4(OnStreamGenerated, 54 MOCK_METHOD4(OnStreamGenerated,
53 void(int routing_id, int request_id, int audio_array_size, 55 void(int routing_id, int request_id, int audio_array_size,
54 int video_array_size)); 56 int video_array_size));
55 MOCK_METHOD2(OnStreamGenerationFailed, void(int routing_id, int request_id)); 57 MOCK_METHOD2(OnStreamGenerationFailed, void(int routing_id, int request_id));
56 MOCK_METHOD1(OnStopGeneratedStreamFromBrowser, 58 MOCK_METHOD1(OnStopGeneratedStreamFromBrowser,
57 void(int routing_id)); 59 void(int routing_id));
58 MOCK_METHOD2(OnDeviceOpened, 60 MOCK_METHOD2(OnDeviceOpened,
(...skipping 151 matching lines...) Expand 10 before | Expand all | Expand 10 after
210 : old_browser_client_(NULL), 212 : old_browser_client_(NULL),
211 thread_bundle_(content::TestBrowserThreadBundle::IO_MAINLOOP), 213 thread_bundle_(content::TestBrowserThreadBundle::IO_MAINLOOP),
212 origin_("https://test.com") { 214 origin_("https://test.com") {
213 audio_manager_.reset( 215 audio_manager_.reset(
214 new media::MockAudioManager(base::MessageLoopProxy::current())); 216 new media::MockAudioManager(base::MessageLoopProxy::current()));
215 // Create our own MediaStreamManager. 217 // Create our own MediaStreamManager.
216 media_stream_manager_.reset(new MediaStreamManager(audio_manager_.get())); 218 media_stream_manager_.reset(new MediaStreamManager(audio_manager_.get()));
217 // Make sure we use fake devices to avoid long delays. 219 // Make sure we use fake devices to avoid long delays.
218 media_stream_manager_->UseFakeDevice(); 220 media_stream_manager_->UseFakeDevice();
219 221
220 host_ = new MockMediaStreamDispatcherHost(base::MessageLoopProxy::current(), 222 host_ = new MockMediaStreamDispatcherHost(
221 media_stream_manager_.get()); 223 browser_context_.GetResourceContext(),
224 base::MessageLoopProxy::current(),
225 media_stream_manager_.get());
222 226
223 // Use the fake content client and browser. 227 // Use the fake content client and browser.
224 content_client_.reset(new TestContentClient()); 228 content_client_.reset(new TestContentClient());
225 SetContentClient(content_client_.get()); 229 SetContentClient(content_client_.get());
226 old_browser_client_ = SetBrowserClientForTesting(host_.get()); 230 old_browser_client_ = SetBrowserClientForTesting(host_.get());
227 } 231 }
228 232
229 virtual ~MediaStreamDispatcherHostTest() { 233 virtual ~MediaStreamDispatcherHostTest() {
230 } 234 }
231 235
(...skipping 113 matching lines...) Expand 10 before | Expand all | Expand 10 after
345 } 349 }
346 350
347 bool DoesEveryDeviceMapToRawId(const StreamDeviceInfoArray& devices, 351 bool DoesEveryDeviceMapToRawId(const StreamDeviceInfoArray& devices,
348 const GURL& origin) { 352 const GURL& origin) {
349 for (size_t i = 0; i < devices.size(); ++i) { 353 for (size_t i = 0; i < devices.size(); ++i) {
350 bool found_match = false; 354 bool found_match = false;
351 media::AudioDeviceNames::const_iterator audio_it = 355 media::AudioDeviceNames::const_iterator audio_it =
352 physical_audio_devices_.begin(); 356 physical_audio_devices_.begin();
353 for (; audio_it != physical_audio_devices_.end(); ++audio_it) { 357 for (; audio_it != physical_audio_devices_.end(); ++audio_it) {
354 if (content::DoesMediaDeviceIDMatchHMAC( 358 if (content::DoesMediaDeviceIDMatchHMAC(
359 browser_context_.GetResourceContext(),
355 origin, 360 origin,
356 devices[i].device.id, 361 devices[i].device.id,
357 audio_it->unique_id)) { 362 audio_it->unique_id)) {
358 EXPECT_FALSE(found_match); 363 EXPECT_FALSE(found_match);
359 found_match = true; 364 found_match = true;
360 } 365 }
361 } 366 }
362 media::VideoCaptureDevice::Names::const_iterator video_it = 367 media::VideoCaptureDevice::Names::const_iterator video_it =
363 physical_video_devices_.begin(); 368 physical_video_devices_.begin();
364 for (; video_it != physical_video_devices_.end(); ++video_it) { 369 for (; video_it != physical_video_devices_.end(); ++video_it) {
365 if (content::DoesMediaDeviceIDMatchHMAC( 370 if (content::DoesMediaDeviceIDMatchHMAC(
371 browser_context_.GetResourceContext(),
366 origin, 372 origin,
367 devices[i].device.id, 373 devices[i].device.id,
368 video_it->id())) { 374 video_it->id())) {
369 EXPECT_FALSE(found_match); 375 EXPECT_FALSE(found_match);
370 found_match = true; 376 found_match = true;
371 } 377 }
372 } 378 }
373 if (!found_match) 379 if (!found_match)
374 return false; 380 return false;
375 } 381 }
376 return true; 382 return true;
377 } 383 }
378 384
379 scoped_refptr<MockMediaStreamDispatcherHost> host_; 385 scoped_refptr<MockMediaStreamDispatcherHost> host_;
380 scoped_ptr<media::AudioManager> audio_manager_; 386 scoped_ptr<media::AudioManager> audio_manager_;
381 scoped_ptr<MediaStreamManager> media_stream_manager_; 387 scoped_ptr<MediaStreamManager> media_stream_manager_;
382 ContentBrowserClient* old_browser_client_; 388 ContentBrowserClient* old_browser_client_;
383 scoped_ptr<ContentClient> content_client_; 389 scoped_ptr<ContentClient> content_client_;
384 content::TestBrowserThreadBundle thread_bundle_; 390 content::TestBrowserThreadBundle thread_bundle_;
391 content::TestBrowserContext browser_context_;
385 media::AudioDeviceNames physical_audio_devices_; 392 media::AudioDeviceNames physical_audio_devices_;
386 media::VideoCaptureDevice::Names physical_video_devices_; 393 media::VideoCaptureDevice::Names physical_video_devices_;
387 GURL origin_; 394 GURL origin_;
388 }; 395 };
389 396
390 TEST_F(MediaStreamDispatcherHostTest, GenerateStreamWithVideoOnly) { 397 TEST_F(MediaStreamDispatcherHostTest, GenerateStreamWithVideoOnly) {
391 StreamOptions options(MEDIA_NO_SERVICE, MEDIA_DEVICE_VIDEO_CAPTURE); 398 StreamOptions options(MEDIA_NO_SERVICE, MEDIA_DEVICE_VIDEO_CAPTURE);
392 399
393 SetupFakeUI(true); 400 SetupFakeUI(true);
394 GenerateStreamAndWaitForResult(kRenderId, kPageRequestId, options); 401 GenerateStreamAndWaitForResult(kRenderId, kPageRequestId, options);
(...skipping 132 matching lines...) Expand 10 before | Expand all | Expand 10 after
527 TEST_F(MediaStreamDispatcherHostTest, GenerateStreamsWithSourceId) { 534 TEST_F(MediaStreamDispatcherHostTest, GenerateStreamsWithSourceId) {
528 ASSERT_GE(physical_audio_devices_.size(), 1u); 535 ASSERT_GE(physical_audio_devices_.size(), 1u);
529 ASSERT_GE(physical_video_devices_.size(), 1u); 536 ASSERT_GE(physical_video_devices_.size(), 1u);
530 537
531 media::AudioDeviceNames::const_iterator audio_it = 538 media::AudioDeviceNames::const_iterator audio_it =
532 physical_audio_devices_.begin(); 539 physical_audio_devices_.begin();
533 for (; audio_it != physical_audio_devices_.end(); ++audio_it) { 540 for (; audio_it != physical_audio_devices_.end(); ++audio_it) {
534 StreamOptions options(MEDIA_DEVICE_AUDIO_CAPTURE, 541 StreamOptions options(MEDIA_DEVICE_AUDIO_CAPTURE,
535 MEDIA_DEVICE_VIDEO_CAPTURE); 542 MEDIA_DEVICE_VIDEO_CAPTURE);
536 options.audio_device_id = content::GetHMACForMediaDeviceID( 543 options.audio_device_id = content::GetHMACForMediaDeviceID(
544 browser_context_.GetResourceContext(),
537 origin_, 545 origin_,
538 audio_it->unique_id); 546 audio_it->unique_id);
539 ASSERT_FALSE(options.audio_device_id.empty()); 547 ASSERT_FALSE(options.audio_device_id.empty());
540 548
541 // Generate first stream. 549 // Generate first stream.
542 SetupFakeUI(true); 550 SetupFakeUI(true);
543 GenerateStreamAndWaitForResult(kRenderId, kPageRequestId, options); 551 GenerateStreamAndWaitForResult(kRenderId, kPageRequestId, options);
544 EXPECT_EQ(host_->audio_devices_[0].device.id, options.audio_device_id); 552 EXPECT_EQ(host_->audio_devices_[0].device.id, options.audio_device_id);
545 } 553 }
546 554
547 media::VideoCaptureDevice::Names::const_iterator video_it = 555 media::VideoCaptureDevice::Names::const_iterator video_it =
548 physical_video_devices_.begin(); 556 physical_video_devices_.begin();
549 for (; video_it != physical_video_devices_.end(); ++video_it) { 557 for (; video_it != physical_video_devices_.end(); ++video_it) {
550 StreamOptions options(MEDIA_DEVICE_AUDIO_CAPTURE, 558 StreamOptions options(MEDIA_DEVICE_AUDIO_CAPTURE,
551 MEDIA_DEVICE_VIDEO_CAPTURE); 559 MEDIA_DEVICE_VIDEO_CAPTURE);
552 options.video_device_id = content::GetHMACForMediaDeviceID( 560 options.video_device_id = content::GetHMACForMediaDeviceID(
553 origin_, 561 browser_context_.GetResourceContext(),
554 video_it->id()); 562 origin_,
563 video_it->id());
555 ASSERT_FALSE(options.video_device_id.empty()); 564 ASSERT_FALSE(options.video_device_id.empty());
556 565
557 // Generate first stream. 566 // Generate first stream.
558 SetupFakeUI(true); 567 SetupFakeUI(true);
559 GenerateStreamAndWaitForResult(kRenderId, kPageRequestId, options); 568 GenerateStreamAndWaitForResult(kRenderId, kPageRequestId, options);
560 EXPECT_EQ(host_->video_devices_[0].device.id, options.video_device_id); 569 EXPECT_EQ(host_->video_devices_[0].device.id, options.video_device_id);
561 } 570 }
562 } 571 }
563 572
564 // Test that generating a stream with an invalid video source id fail. 573 // Test that generating a stream with an invalid video source id fail.
(...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after
661 MEDIA_DEVICE_AUDIO_CAPTURE); 670 MEDIA_DEVICE_AUDIO_CAPTURE);
662 } 671 }
663 672
664 TEST_F(MediaStreamDispatcherHostTest, EnumerateVideoDevices) { 673 TEST_F(MediaStreamDispatcherHostTest, EnumerateVideoDevices) {
665 EnumerateDevicesAndWaitForResult(kRenderId, kPageRequestId, 674 EnumerateDevicesAndWaitForResult(kRenderId, kPageRequestId,
666 MEDIA_DEVICE_VIDEO_CAPTURE); 675 MEDIA_DEVICE_VIDEO_CAPTURE);
667 } 676 }
668 677
669 678
670 }; // namespace content 679 }; // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698