Chromium Code Reviews| OLD | NEW |
|---|---|
| 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/renderer/media/media_stream_dispatcher.h" | 5 #include "content/renderer/media/media_stream_dispatcher.h" |
| 6 | 6 |
| 7 #include <stddef.h> | 7 #include <stddef.h> |
| 8 | 8 |
| 9 #include <memory> | 9 #include <memory> |
| 10 #include <string> | 10 #include <string> |
| (...skipping 20 matching lines...) Expand all Loading... | |
| 31 const int kRequestId4 = 40; | 31 const int kRequestId4 = 40; |
| 32 | 32 |
| 33 const MediaStreamType kAudioType = MEDIA_DEVICE_AUDIO_CAPTURE; | 33 const MediaStreamType kAudioType = MEDIA_DEVICE_AUDIO_CAPTURE; |
| 34 const MediaStreamType kVideoType = MEDIA_DEVICE_VIDEO_CAPTURE; | 34 const MediaStreamType kVideoType = MEDIA_DEVICE_VIDEO_CAPTURE; |
| 35 | 35 |
| 36 class MockMediaStreamDispatcherEventHandler | 36 class MockMediaStreamDispatcherEventHandler |
| 37 : public MediaStreamDispatcherEventHandler, | 37 : public MediaStreamDispatcherEventHandler, |
| 38 public base::SupportsWeakPtr<MockMediaStreamDispatcherEventHandler> { | 38 public base::SupportsWeakPtr<MockMediaStreamDispatcherEventHandler> { |
| 39 public: | 39 public: |
| 40 MockMediaStreamDispatcherEventHandler() | 40 MockMediaStreamDispatcherEventHandler() |
| 41 : request_id_(-1) {} | 41 : request_id_(-1), did_receive_devices_changed_(false) {} |
| 42 | 42 |
| 43 void OnStreamGenerated( | 43 void OnStreamGenerated( |
| 44 int request_id, | 44 int request_id, |
| 45 const std::string& label, | 45 const std::string& label, |
| 46 const StreamDeviceInfoArray& audio_device_array, | 46 const StreamDeviceInfoArray& audio_device_array, |
| 47 const StreamDeviceInfoArray& video_device_array) override { | 47 const StreamDeviceInfoArray& video_device_array) override { |
| 48 request_id_ = request_id; | 48 request_id_ = request_id; |
| 49 label_ = label; | 49 label_ = label; |
| 50 if (audio_device_array.size()) { | 50 if (audio_device_array.size()) { |
| 51 DCHECK(audio_device_array.size() == 1); | 51 DCHECK(audio_device_array.size() == 1); |
| (...skipping 29 matching lines...) Expand all Loading... | |
| 81 | 81 |
| 82 void OnDeviceOpened(int request_id, | 82 void OnDeviceOpened(int request_id, |
| 83 const std::string& label, | 83 const std::string& label, |
| 84 const StreamDeviceInfo& video_device) override { | 84 const StreamDeviceInfo& video_device) override { |
| 85 request_id_ = request_id; | 85 request_id_ = request_id; |
| 86 label_ = label; | 86 label_ = label; |
| 87 } | 87 } |
| 88 | 88 |
| 89 void OnDeviceOpenFailed(int request_id) override { request_id_ = request_id; } | 89 void OnDeviceOpenFailed(int request_id) override { request_id_ = request_id; } |
| 90 | 90 |
| 91 void OnDevicesChanged() override { did_receive_devices_changed_ = true; } | |
| 92 | |
| 91 void ResetStoredParameters() { | 93 void ResetStoredParameters() { |
| 92 request_id_ = -1; | 94 request_id_ = -1; |
| 93 label_ = ""; | 95 label_ = ""; |
| 94 device_stopped_label_ = ""; | 96 device_stopped_label_ = ""; |
| 95 audio_device_ = StreamDeviceInfo(); | 97 audio_device_ = StreamDeviceInfo(); |
| 96 video_device_ = StreamDeviceInfo(); | 98 video_device_ = StreamDeviceInfo(); |
| 97 } | 99 } |
| 98 | 100 |
| 99 int request_id_; | 101 int request_id_; |
| 100 std::string label_; | 102 std::string label_; |
| 101 std::string device_stopped_label_; | 103 std::string device_stopped_label_; |
| 102 StreamDeviceInfo audio_device_; | 104 StreamDeviceInfo audio_device_; |
| 103 StreamDeviceInfo video_device_; | 105 StreamDeviceInfo video_device_; |
| 106 bool did_receive_devices_changed_; | |
| 104 }; | 107 }; |
| 105 | 108 |
| 106 class MediaStreamDispatcherUnderTest : public MediaStreamDispatcher { | 109 class MediaStreamDispatcherUnderTest : public MediaStreamDispatcher { |
| 107 public: | 110 public: |
| 108 MediaStreamDispatcherUnderTest() : MediaStreamDispatcher(NULL) {} | 111 MediaStreamDispatcherUnderTest() : MediaStreamDispatcher(NULL) {} |
| 109 | 112 |
| 110 using MediaStreamDispatcher::GetNextIpcIdForTest; | 113 using MediaStreamDispatcher::GetNextIpcIdForTest; |
| 111 using RenderFrameObserver::OnMessageReceived; | 114 using RenderFrameObserver::OnMessageReceived; |
| 112 }; | 115 }; |
| 113 | 116 |
| (...skipping 288 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 402 | 405 |
| 403 dispatcher_->OnMessageReceived( | 406 dispatcher_->OnMessageReceived( |
| 404 MediaStreamMsg_DeviceStopped(kRouteId, label, handler_->video_device_)); | 407 MediaStreamMsg_DeviceStopped(kRouteId, label, handler_->video_device_)); |
| 405 // Verify that MediaStreamDispatcherEventHandler::OnDeviceStopped has been | 408 // Verify that MediaStreamDispatcherEventHandler::OnDeviceStopped has been |
| 406 // called. | 409 // called. |
| 407 EXPECT_EQ(label, handler_->device_stopped_label_); | 410 EXPECT_EQ(label, handler_->device_stopped_label_); |
| 408 EXPECT_EQ(dispatcher_->video_session_id(label, 0), | 411 EXPECT_EQ(dispatcher_->video_session_id(label, 0), |
| 409 StreamDeviceInfo::kNoId); | 412 StreamDeviceInfo::kNoId); |
| 410 } | 413 } |
| 411 | 414 |
| 415 // Test that the MediaStreamDispatcherEventHandler is notified when the message | |
| 416 // MediaStreamMsg_DevicesChanged is received. | |
| 417 TEST_F(MediaStreamDispatcherTest, DevicesChanged) { | |
| 418 std::unique_ptr<MockMediaStreamDispatcherEventHandler> handler1( | |
| 419 new MockMediaStreamDispatcherEventHandler); | |
| 420 std::unique_ptr<MockMediaStreamDispatcherEventHandler> handler2( | |
| 421 new MockMediaStreamDispatcherEventHandler); | |
| 422 dispatcher_->SubscribeToDeviceChangeNotifications(handler1->AsWeakPtr(), | |
| 423 security_origin_); | |
| 424 dispatcher_->SubscribeToDeviceChangeNotifications(handler2->AsWeakPtr(), | |
| 425 security_origin_); | |
| 426 dispatcher_->OnMessageReceived(MediaStreamMsg_DevicesChanged(kRouteId)); | |
| 427 dispatcher_->CancelDeviceChangeNotifications(handler1->AsWeakPtr()); | |
| 428 dispatcher_->CancelDeviceChangeNotifications(handler2->AsWeakPtr()); | |
|
hta - Chromium
2016/04/26 12:31:00
Do you check the error cases of adding a handler t
Guido Urdaneta
2016/04/26 13:04:19
Done.
| |
| 429 | |
| 430 EXPECT_EQ(true, handler1->did_receive_devices_changed_); | |
| 431 EXPECT_EQ(true, handler2->did_receive_devices_changed_); | |
|
hta - Chromium
2016/04/26 12:31:00
Any reason to not EXPECT_TRUE? Seems more readable
Guido Urdaneta
2016/04/26 13:04:18
Done.
| |
| 432 } | |
| 433 | |
| 412 } // namespace content | 434 } // namespace content |
| OLD | NEW |