Chromium Code Reviews| Index: content/browser/renderer_host/media/media_stream_device_settings_unittest.cc |
| diff --git a/content/browser/renderer_host/media/media_stream_device_settings_unittest.cc b/content/browser/renderer_host/media/media_stream_device_settings_unittest.cc |
| index c8c2061361bfaf571d27b82fd48fc7ab8f29bc41..643f235f59827b7e9ed504678ee5ab5a528155e2 100644 |
| --- a/content/browser/renderer_host/media/media_stream_device_settings_unittest.cc |
| +++ b/content/browser/renderer_host/media/media_stream_device_settings_unittest.cc |
| @@ -15,6 +15,7 @@ |
| using content::BrowserThread; |
| using content::BrowserThreadImpl; |
| +using testing::_; |
| namespace media_stream { |
| @@ -23,7 +24,7 @@ class MediaStreamDeviceSettingsTest |
| : public ::testing::Test, |
| public SettingsRequester { |
| public: |
| - MediaStreamDeviceSettingsTest() : label_("dummy_stream") {} |
| + MediaStreamDeviceSettingsTest() {} |
| // Mock implementation of SettingsRequester; |
| MOCK_METHOD2(DevicesAccepted, void(const std::string&, |
| @@ -44,18 +45,25 @@ class MediaStreamDeviceSettingsTest |
| message_loop_->RunAllPending(); |
| } |
| - void CreateDummyRequest() { |
| + void CreateDummyRequest(const std::string& label, bool audio, bool video) { |
| int dummy_render_process_id = 1; |
| int dummy_render_view_id = 1; |
| - StreamOptions components(true, false); |
| + StreamOptions components(audio, video); |
| GURL security_origin; |
| - device_settings_->RequestCaptureDeviceUsage(label_, |
| + device_settings_->RequestCaptureDeviceUsage(label, |
| dummy_render_process_id, |
| dummy_render_view_id, |
| components, |
| security_origin); |
| + if (audio) |
| + CreateAudioDeviceForRequset(label); |
| - // Setup the dummy available device for the reqest. |
| + if (video) |
| + CreateVideoDeviceForRequset(label); |
| + } |
| + |
| + void CreateAudioDeviceForRequset(const std::string& label) { |
| + // Setup the dummy available device for the request. |
| media_stream::StreamDeviceInfoArray audio_device_array(1); |
| media_stream::StreamDeviceInfo dummy_audio_device; |
| dummy_audio_device.name = "Microphone"; |
| @@ -63,35 +71,105 @@ class MediaStreamDeviceSettingsTest |
| content::MEDIA_STREAM_DEVICE_TYPE_AUDIO_CAPTURE; |
| dummy_audio_device.session_id = 1; |
| audio_device_array[0] = dummy_audio_device; |
| - device_settings_->AvailableDevices(label_, |
| + device_settings_->AvailableDevices(label, |
| dummy_audio_device.stream_type, |
| audio_device_array); |
| } |
| + void CreateVideoDeviceForRequset(const std::string& label) { |
| + // Setup the dummy available device for the request. |
| + media_stream::StreamDeviceInfoArray video_device_array(1); |
| + media_stream::StreamDeviceInfo dummy_video_device; |
| + dummy_video_device.name = "camera"; |
| + dummy_video_device.stream_type = |
| + content::MEDIA_STREAM_DEVICE_TYPE_VIDEO_CAPTURE; |
| + dummy_video_device.session_id = 1; |
| + video_device_array[0] = dummy_video_device; |
| + device_settings_->AvailableDevices(label, |
| + dummy_video_device.stream_type, |
| + video_device_array); |
| + } |
| + |
| scoped_ptr<MessageLoop> message_loop_; |
| scoped_ptr<BrowserThreadImpl> ui_thread_; |
| scoped_ptr<BrowserThreadImpl> io_thread_; |
| scoped_ptr<MediaStreamDeviceSettings> device_settings_; |
| - const std::string label_; |
| private: |
| DISALLOW_COPY_AND_ASSIGN(MediaStreamDeviceSettingsTest); |
| }; |
| TEST_F(MediaStreamDeviceSettingsTest, GenerateRequest) { |
| - CreateDummyRequest(); |
| + const std::string label = "dummy_label"; |
| + CreateDummyRequest(label, true, false); |
| // Expecting an error callback triggered by the non-existing |
| // RenderViewHostImpl. |
| - EXPECT_CALL(*this, SettingsError(label_)) |
| - .Times(1); |
| + EXPECT_CALL(*this, SettingsError(label)); |
| } |
| TEST_F(MediaStreamDeviceSettingsTest, GenerateAndRemoveRequest) { |
| - CreateDummyRequest(); |
| + const std::string label = "label"; |
| + CreateDummyRequest(label, true, false); |
| // Remove the current request, it should not crash. |
| - device_settings_->RemovePendingCaptureRequest(label_); |
| + device_settings_->RemovePendingCaptureRequest(label); |
|
perkj_chrome
2012/08/10 12:26:58
anything you can check here?
no longer working on chromium
2012/08/13 11:39:53
Not really.
This test was made as a regression te
|
| +} |
| + |
| +TEST_F(MediaStreamDeviceSettingsTest, HandleRequestUsingFakeUI) { |
| + device_settings_->UseFakeUI(); |
| + |
| + const std::string label = "label"; |
| + CreateDummyRequest(label, true, true); |
| + |
| + // Remove the current request, it should not crash. |
| + EXPECT_CALL(*this, DevicesAccepted(label, _)); |
| +} |
| + |
| +TEST_F(MediaStreamDeviceSettingsTest, CreateMultipleRequestsAndCancelTheFirst) { |
| + device_settings_->UseFakeUI(); |
| + |
| + // Create the first audio request. |
| + const std::string label_1 = "label_1"; |
| + CreateDummyRequest(label_1, true, false); |
| + |
| + // Create the second video request. |
| + const std::string label_2 = "label_2"; |
| + CreateDummyRequest(label_2, false, true); |
| + |
| + // Create the third audio and video request. |
| + const std::string label_3 = "label_3"; |
| + CreateDummyRequest(label_3, true, true); |
| + |
| + // Remove the first request which has been brought to the UI. |
| + device_settings_->RemovePendingCaptureRequest(label_1); |
| + |
| + // We should get callbacks from the rest of the requests. |
| + EXPECT_CALL(*this, DevicesAccepted(label_2, _)); |
| + EXPECT_CALL(*this, DevicesAccepted(label_3, _)); |
| +} |
| + |
| +TEST_F(MediaStreamDeviceSettingsTest, CreateMultipleRequestsAndCancelTheLast) { |
| + device_settings_->UseFakeUI(); |
| + |
| + // Create the first audio request. |
| + const std::string label_1 = "label_1"; |
| + CreateDummyRequest(label_1, true, false); |
| + |
| + // Create the second video request. |
| + const std::string label_2 = "label_2"; |
| + CreateDummyRequest(label_2, false, true); |
| + |
| + // Create the third audio and video request. |
| + const std::string label_3 = "label_3"; |
| + CreateDummyRequest(label_3, true, true); |
| + |
| + // Remove the last request which is pending in the queue. |
| + device_settings_->RemovePendingCaptureRequest(label_3); |
| + |
| + // We should get callbacks from the rest of the requests. |
| + EXPECT_CALL(*this, DevicesAccepted(label_1, _)); |
| + EXPECT_CALL(*this, DevicesAccepted(label_2, _)); |
| } |
| } // namespace media_stream |