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

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

Issue 1928493002: Use url::Origin to represent security origins in MediaStream-related code. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: rebase Created 4 years, 7 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/media_stream_dispatcher_host.h" 5 #include "content/browser/renderer_host/media/media_stream_dispatcher_host.h"
6 6
7 #include <stddef.h> 7 #include <stddef.h>
8 #include <queue> 8 #include <queue>
9 #include <string> 9 #include <string>
10 #include <utility> 10 #include <utility>
(...skipping 20 matching lines...) Expand all
31 #include "content/public/test/test_browser_thread_bundle.h" 31 #include "content/public/test/test_browser_thread_bundle.h"
32 #include "content/test/test_content_browser_client.h" 32 #include "content/test/test_content_browser_client.h"
33 #include "content/test/test_content_client.h" 33 #include "content/test/test_content_client.h"
34 #include "ipc/ipc_message_macros.h" 34 #include "ipc/ipc_message_macros.h"
35 #include "media/audio/mock_audio_manager.h" 35 #include "media/audio/mock_audio_manager.h"
36 #include "media/base/media_switches.h" 36 #include "media/base/media_switches.h"
37 #include "media/capture/video/fake_video_capture_device_factory.h" 37 #include "media/capture/video/fake_video_capture_device_factory.h"
38 #include "net/url_request/url_request_context.h" 38 #include "net/url_request/url_request_context.h"
39 #include "testing/gmock/include/gmock/gmock.h" 39 #include "testing/gmock/include/gmock/gmock.h"
40 #include "testing/gtest/include/gtest/gtest.h" 40 #include "testing/gtest/include/gtest/gtest.h"
41 #include "url/gurl.h"
42 #include "url/origin.h"
41 43
42 #if defined(OS_CHROMEOS) 44 #if defined(OS_CHROMEOS)
43 #include "chromeos/audio/cras_audio_handler.h" 45 #include "chromeos/audio/cras_audio_handler.h"
44 #endif 46 #endif
45 47
46 using ::testing::_; 48 using ::testing::_;
47 using ::testing::DeleteArg; 49 using ::testing::DeleteArg;
48 using ::testing::DoAll; 50 using ::testing::DoAll;
49 using ::testing::InSequence; 51 using ::testing::InSequence;
50 using ::testing::Return; 52 using ::testing::Return;
(...skipping 23 matching lines...) Expand all
74 MOCK_METHOD3(OnStreamGenerationFailed, void(int routing_id, 76 MOCK_METHOD3(OnStreamGenerationFailed, void(int routing_id,
75 int request_id, 77 int request_id,
76 MediaStreamRequestResult result)); 78 MediaStreamRequestResult result));
77 MOCK_METHOD1(OnDeviceStopped, void(int routing_id)); 79 MOCK_METHOD1(OnDeviceStopped, void(int routing_id));
78 MOCK_METHOD2(OnDeviceOpened, void(int routing_id, int request_id)); 80 MOCK_METHOD2(OnDeviceOpened, void(int routing_id, int request_id));
79 81
80 // Accessor to private functions. 82 // Accessor to private functions.
81 void OnGenerateStream(int render_frame_id, 83 void OnGenerateStream(int render_frame_id,
82 int page_request_id, 84 int page_request_id,
83 const StreamControls& controls, 85 const StreamControls& controls,
84 const GURL& security_origin, 86 const url::Origin& security_origin,
85 const base::Closure& quit_closure) { 87 const base::Closure& quit_closure) {
86 quit_closures_.push(quit_closure); 88 quit_closures_.push(quit_closure);
87 MediaStreamDispatcherHost::OnGenerateStream( 89 MediaStreamDispatcherHost::OnGenerateStream(
88 render_frame_id, page_request_id, controls, security_origin, false); 90 render_frame_id, page_request_id, controls, security_origin, false);
89 } 91 }
90 92
91 void OnStopStreamDevice(int render_frame_id, 93 void OnStopStreamDevice(int render_frame_id,
92 const std::string& device_id) { 94 const std::string& device_id) {
93 MediaStreamDispatcherHost::OnStopStreamDevice(render_frame_id, device_id); 95 MediaStreamDispatcherHost::OnStopStreamDevice(render_frame_id, device_id);
94 } 96 }
95 97
96 void OnOpenDevice(int render_frame_id, 98 void OnOpenDevice(int render_frame_id,
97 int page_request_id, 99 int page_request_id,
98 const std::string& device_id, 100 const std::string& device_id,
99 MediaStreamType type, 101 MediaStreamType type,
100 const GURL& security_origin, 102 const url::Origin& security_origin,
101 const base::Closure& quit_closure) { 103 const base::Closure& quit_closure) {
102 quit_closures_.push(quit_closure); 104 quit_closures_.push(quit_closure);
103 MediaStreamDispatcherHost::OnOpenDevice( 105 MediaStreamDispatcherHost::OnOpenDevice(
104 render_frame_id, page_request_id, device_id, type, security_origin); 106 render_frame_id, page_request_id, device_id, type, security_origin);
105 } 107 }
106 108
107 void OnEnumerateDevices(int render_frame_id, 109 void OnEnumerateDevices(int render_frame_id,
108 int page_request_id, 110 int page_request_id,
109 MediaStreamType type, 111 MediaStreamType type,
110 const GURL& security_origin, 112 const url::Origin& security_origin,
111 const base::Closure& quit_closure) { 113 const base::Closure& quit_closure) {
112 quit_closures_.push(quit_closure); 114 quit_closures_.push(quit_closure);
113 MediaStreamDispatcherHost::OnEnumerateDevices( 115 MediaStreamDispatcherHost::OnEnumerateDevices(
114 render_frame_id, page_request_id, type, security_origin); 116 render_frame_id, page_request_id, type, security_origin);
115 } 117 }
116 118
117 std::string label_; 119 std::string label_;
118 StreamDeviceInfoArray audio_devices_; 120 StreamDeviceInfoArray audio_devices_;
119 StreamDeviceInfoArray video_devices_; 121 StreamDeviceInfoArray video_devices_;
120 StreamDeviceInfo opened_device_; 122 StreamDeviceInfo opened_device_;
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after
171 void OnStreamGenerationFailedInternal( 173 void OnStreamGenerationFailedInternal(
172 int request_id, 174 int request_id,
173 content::MediaStreamRequestResult result) { 175 content::MediaStreamRequestResult result) {
174 OnStreamGenerationFailed(current_ipc_->routing_id(), request_id, result); 176 OnStreamGenerationFailed(current_ipc_->routing_id(), request_id, result);
175 if (!quit_closures_.empty()) { 177 if (!quit_closures_.empty()) {
176 base::Closure quit_closure = quit_closures_.front(); 178 base::Closure quit_closure = quit_closures_.front();
177 quit_closures_.pop(); 179 quit_closures_.pop();
178 task_runner_->PostTask(FROM_HERE, base::ResetAndReturn(&quit_closure)); 180 task_runner_->PostTask(FROM_HERE, base::ResetAndReturn(&quit_closure));
179 } 181 }
180 182
181 label_= ""; 183 label_ = "";
182 } 184 }
183 185
184 void OnDeviceStoppedInternal(const std::string& label, 186 void OnDeviceStoppedInternal(const std::string& label,
185 const content::StreamDeviceInfo& device) { 187 const content::StreamDeviceInfo& device) {
186 if (IsVideoMediaType(device.device.type)) 188 if (IsVideoMediaType(device.device.type))
187 EXPECT_TRUE(StreamDeviceInfo::IsEqual(device, video_devices_[0])); 189 EXPECT_TRUE(StreamDeviceInfo::IsEqual(device, video_devices_[0]));
188 if (IsAudioInputMediaType(device.device.type)) 190 if (IsAudioInputMediaType(device.device.type))
189 EXPECT_TRUE(StreamDeviceInfo::IsEqual(device, audio_devices_[0])); 191 EXPECT_TRUE(StreamDeviceInfo::IsEqual(device, audio_devices_[0]));
190 192
191 OnDeviceStopped(current_ipc_->routing_id()); 193 OnDeviceStopped(current_ipc_->routing_id());
(...skipping 28 matching lines...) Expand all
220 OnStarted, 222 OnStarted,
221 void(const base::Closure& stop, 223 void(const base::Closure& stop,
222 const MediaStreamUIProxy::WindowIdCallback& window_id_callback)); 224 const MediaStreamUIProxy::WindowIdCallback& window_id_callback));
223 }; 225 };
224 226
225 class MediaStreamDispatcherHostTest : public testing::Test { 227 class MediaStreamDispatcherHostTest : public testing::Test {
226 public: 228 public:
227 MediaStreamDispatcherHostTest() 229 MediaStreamDispatcherHostTest()
228 : thread_bundle_(content::TestBrowserThreadBundle::IO_MAINLOOP), 230 : thread_bundle_(content::TestBrowserThreadBundle::IO_MAINLOOP),
229 old_browser_client_(NULL), 231 old_browser_client_(NULL),
230 origin_("https://test.com") { 232 origin_(GURL("https://test.com")) {
231 audio_manager_.reset( 233 audio_manager_.reset(
232 new media::MockAudioManager(base::ThreadTaskRunnerHandle::Get())); 234 new media::MockAudioManager(base::ThreadTaskRunnerHandle::Get()));
233 // Make sure we use fake devices to avoid long delays. 235 // Make sure we use fake devices to avoid long delays.
234 base::CommandLine::ForCurrentProcess()->AppendSwitch( 236 base::CommandLine::ForCurrentProcess()->AppendSwitch(
235 switches::kUseFakeDeviceForMediaStream); 237 switches::kUseFakeDeviceForMediaStream);
236 // Create our own MediaStreamManager. 238 // Create our own MediaStreamManager.
237 media_stream_manager_.reset(new MediaStreamManager(audio_manager_.get())); 239 media_stream_manager_.reset(new MediaStreamManager(audio_manager_.get()));
238 video_capture_device_factory_ = 240 video_capture_device_factory_ =
239 static_cast<media::FakeVideoCaptureDeviceFactory*>( 241 static_cast<media::FakeVideoCaptureDeviceFactory*>(
240 media_stream_manager_->video_capture_manager() 242 media_stream_manager_->video_capture_manager()
(...skipping 122 matching lines...) Expand 10 before | Expand all | Expand 10 after
363 physical_video_devices_.begin(); 365 physical_video_devices_.begin();
364 for (; video_it != physical_video_devices_.end(); ++video_it) { 366 for (; video_it != physical_video_devices_.end(); ++video_it) {
365 if (video_it->id() == devices[i].device.id) 367 if (video_it->id() == devices[i].device.id)
366 return true; 368 return true;
367 } 369 }
368 } 370 }
369 return false; 371 return false;
370 } 372 }
371 373
372 bool DoesEveryDeviceMapToRawId(const StreamDeviceInfoArray& devices, 374 bool DoesEveryDeviceMapToRawId(const StreamDeviceInfoArray& devices,
373 const GURL& origin) { 375 const url::Origin& origin) {
374 for (size_t i = 0; i < devices.size(); ++i) { 376 for (size_t i = 0; i < devices.size(); ++i) {
375 bool found_match = false; 377 bool found_match = false;
376 media::AudioDeviceNames::const_iterator audio_it = 378 media::AudioDeviceNames::const_iterator audio_it =
377 physical_audio_devices_.begin(); 379 physical_audio_devices_.begin();
378 for (; audio_it != physical_audio_devices_.end(); ++audio_it) { 380 for (; audio_it != physical_audio_devices_.end(); ++audio_it) {
379 if (content::DoesMediaDeviceIDMatchHMAC( 381 if (content::DoesMediaDeviceIDMatchHMAC(
380 browser_context_.GetResourceContext()->GetMediaDeviceIDSalt(), 382 browser_context_.GetResourceContext()->GetMediaDeviceIDSalt(),
381 origin, 383 origin,
382 devices[i].device.id, 384 devices[i].device.id,
383 audio_it->unique_id)) { 385 audio_it->unique_id)) {
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
425 std::unique_ptr<MediaStreamManager> media_stream_manager_; 427 std::unique_ptr<MediaStreamManager> media_stream_manager_;
426 content::TestBrowserThreadBundle thread_bundle_; 428 content::TestBrowserThreadBundle thread_bundle_;
427 std::unique_ptr<media::AudioManager, media::AudioManagerDeleter> 429 std::unique_ptr<media::AudioManager, media::AudioManagerDeleter>
428 audio_manager_; 430 audio_manager_;
429 MockMediaStreamUIProxy* stream_ui_; 431 MockMediaStreamUIProxy* stream_ui_;
430 ContentBrowserClient* old_browser_client_; 432 ContentBrowserClient* old_browser_client_;
431 std::unique_ptr<ContentClient> content_client_; 433 std::unique_ptr<ContentClient> content_client_;
432 content::TestBrowserContext browser_context_; 434 content::TestBrowserContext browser_context_;
433 media::AudioDeviceNames physical_audio_devices_; 435 media::AudioDeviceNames physical_audio_devices_;
434 media::VideoCaptureDevice::Names physical_video_devices_; 436 media::VideoCaptureDevice::Names physical_video_devices_;
435 GURL origin_; 437 url::Origin origin_;
436 media::FakeVideoCaptureDeviceFactory* video_capture_device_factory_; 438 media::FakeVideoCaptureDeviceFactory* video_capture_device_factory_;
437 }; 439 };
438 440
439 TEST_F(MediaStreamDispatcherHostTest, GenerateStreamWithVideoOnly) { 441 TEST_F(MediaStreamDispatcherHostTest, GenerateStreamWithVideoOnly) {
440 StreamControls controls(false, true); 442 StreamControls controls(false, true);
441 443
442 SetupFakeUI(true); 444 SetupFakeUI(true);
443 GenerateStreamAndWaitForResult(kRenderId, kPageRequestId, controls); 445 GenerateStreamAndWaitForResult(kRenderId, kPageRequestId, controls);
444 446
445 EXPECT_EQ(host_->audio_devices_.size(), 0u); 447 EXPECT_EQ(host_->audio_devices_.size(), 0u);
(...skipping 462 matching lines...) Expand 10 before | Expand all | Expand 10 after
908 910
909 TEST_F(MediaStreamDispatcherHostTest, EnumerateVideoDevicesNoAccess) { 911 TEST_F(MediaStreamDispatcherHostTest, EnumerateVideoDevicesNoAccess) {
910 SetupFakeUI(false); 912 SetupFakeUI(false);
911 stream_ui_->SetCameraAccess(false); 913 stream_ui_->SetCameraAccess(false);
912 EnumerateDevicesAndWaitForResult(kRenderId, kPageRequestId, 914 EnumerateDevicesAndWaitForResult(kRenderId, kPageRequestId,
913 MEDIA_DEVICE_VIDEO_CAPTURE); 915 MEDIA_DEVICE_VIDEO_CAPTURE);
914 EXPECT_TRUE(DoesNotContainLabels(host_->enumerated_devices_)); 916 EXPECT_TRUE(DoesNotContainLabels(host_->enumerated_devices_));
915 } 917 }
916 918
917 }; // namespace content 919 }; // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698