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 <string> | 5 #include <string> |
6 | 6 |
7 #include "base/bind.h" | 7 #include "base/bind.h" |
8 #include "base/message_loop.h" | 8 #include "base/message_loop.h" |
9 #include "content/browser/browser_thread_impl.h" | 9 #include "content/browser/browser_thread_impl.h" |
10 #include "content/browser/renderer_host/media/media_stream_ui_controller.h" | 10 #include "content/browser/renderer_host/media/media_stream_ui_controller.h" |
11 #include "content/browser/renderer_host/media/media_stream_settings_requester.h" | 11 #include "content/browser/renderer_host/media/media_stream_settings_requester.h" |
12 #include "content/common/media/media_stream_options.h" | 12 #include "content/common/media/media_stream_options.h" |
13 #include "content/public/common/media_stream_request.h" | 13 #include "content/public/common/media_stream_request.h" |
14 #include "testing/gmock/include/gmock/gmock.h" | 14 #include "testing/gmock/include/gmock/gmock.h" |
15 #include "testing/gtest/include/gtest/gtest.h" | 15 #include "testing/gtest/include/gtest/gtest.h" |
16 | 16 |
17 using content::BrowserThread; | |
18 using content::BrowserThreadImpl; | |
19 using testing::_; | 17 using testing::_; |
20 | 18 |
21 namespace content { | 19 namespace content { |
22 | 20 |
23 class MediaStreamDeviceUIControllerTest | 21 class MediaStreamDeviceUIControllerTest |
24 : public ::testing::Test, | 22 : public ::testing::Test, |
25 public media_stream::SettingsRequester { | 23 public SettingsRequester { |
26 public: | 24 public: |
27 MediaStreamDeviceUIControllerTest() {} | 25 MediaStreamDeviceUIControllerTest() {} |
28 | 26 |
29 // Mock implementation of SettingsRequester; | 27 // Mock implementation of SettingsRequester; |
30 MOCK_METHOD2(DevicesAccepted, void( | 28 MOCK_METHOD2(DevicesAccepted, void( |
31 const std::string&, const media_stream::StreamDeviceInfoArray&)); | 29 const std::string&, const StreamDeviceInfoArray&)); |
32 MOCK_METHOD1(SettingsError, void(const std::string&)); | 30 MOCK_METHOD1(SettingsError, void(const std::string&)); |
33 | 31 |
34 protected: | 32 protected: |
35 virtual void SetUp() { | 33 virtual void SetUp() { |
36 message_loop_.reset(new MessageLoop(MessageLoop::TYPE_IO)); | 34 message_loop_.reset(new MessageLoop(MessageLoop::TYPE_IO)); |
37 ui_thread_.reset(new BrowserThreadImpl(BrowserThread::UI, | 35 ui_thread_.reset(new BrowserThreadImpl(BrowserThread::UI, |
38 message_loop_.get())); | 36 message_loop_.get())); |
39 io_thread_.reset(new BrowserThreadImpl(BrowserThread::IO, | 37 io_thread_.reset(new BrowserThreadImpl(BrowserThread::IO, |
40 message_loop_.get())); | 38 message_loop_.get())); |
41 ui_controller_.reset(new content::MediaStreamUIController(this)); | 39 ui_controller_.reset(new MediaStreamUIController(this)); |
42 } | 40 } |
43 | 41 |
44 virtual void TearDown() { | 42 virtual void TearDown() { |
45 message_loop_->RunAllPending(); | 43 message_loop_->RunAllPending(); |
46 } | 44 } |
47 | 45 |
48 void CreateDummyRequest(const std::string& label, bool audio, bool video) { | 46 void CreateDummyRequest(const std::string& label, bool audio, bool video) { |
49 int dummy_render_process_id = 1; | 47 int dummy_render_process_id = 1; |
50 int dummy_render_view_id = 1; | 48 int dummy_render_view_id = 1; |
51 media_stream::StreamOptions components( | 49 StreamOptions components( |
52 audio ? content::MEDIA_DEVICE_AUDIO_CAPTURE : | 50 audio ? MEDIA_DEVICE_AUDIO_CAPTURE : MEDIA_NO_SERVICE, |
53 content::MEDIA_NO_SERVICE, | 51 video ? MEDIA_DEVICE_VIDEO_CAPTURE : MEDIA_NO_SERVICE); |
54 video ? content::MEDIA_DEVICE_VIDEO_CAPTURE : | |
55 content::MEDIA_NO_SERVICE); | |
56 GURL security_origin; | 52 GURL security_origin; |
57 ui_controller_->MakeUIRequest(label, | 53 ui_controller_->MakeUIRequest(label, |
58 dummy_render_process_id, | 54 dummy_render_process_id, |
59 dummy_render_view_id, | 55 dummy_render_view_id, |
60 components, | 56 components, |
61 security_origin); | 57 security_origin); |
62 if (audio) | 58 if (audio) |
63 CreateAudioDeviceForRequset(label); | 59 CreateAudioDeviceForRequset(label); |
64 | 60 |
65 if (video) | 61 if (video) |
66 CreateVideoDeviceForRequset(label); | 62 CreateVideoDeviceForRequset(label); |
67 } | 63 } |
68 | 64 |
69 void CreateAudioDeviceForRequset(const std::string& label) { | 65 void CreateAudioDeviceForRequset(const std::string& label) { |
70 // Setup the dummy available device for the request. | 66 // Setup the dummy available device for the request. |
71 media_stream::StreamDeviceInfoArray audio_device_array(1); | 67 StreamDeviceInfoArray audio_device_array(1); |
72 media_stream::StreamDeviceInfo dummy_audio_device; | 68 StreamDeviceInfo dummy_audio_device; |
73 dummy_audio_device.name = "Microphone"; | 69 dummy_audio_device.name = "Microphone"; |
74 dummy_audio_device.stream_type = content::MEDIA_DEVICE_AUDIO_CAPTURE; | 70 dummy_audio_device.stream_type = MEDIA_DEVICE_AUDIO_CAPTURE; |
75 dummy_audio_device.session_id = 1; | 71 dummy_audio_device.session_id = 1; |
76 audio_device_array[0] = dummy_audio_device; | 72 audio_device_array[0] = dummy_audio_device; |
77 ui_controller_->AddAvailableDevicesToRequest( | 73 ui_controller_->AddAvailableDevicesToRequest( |
78 label, | 74 label, |
79 dummy_audio_device.stream_type, | 75 dummy_audio_device.stream_type, |
80 audio_device_array); | 76 audio_device_array); |
81 } | 77 } |
82 | 78 |
83 void CreateVideoDeviceForRequset(const std::string& label) { | 79 void CreateVideoDeviceForRequset(const std::string& label) { |
84 // Setup the dummy available device for the request. | 80 // Setup the dummy available device for the request. |
85 media_stream::StreamDeviceInfoArray video_device_array(1); | 81 StreamDeviceInfoArray video_device_array(1); |
86 media_stream::StreamDeviceInfo dummy_video_device; | 82 StreamDeviceInfo dummy_video_device; |
87 dummy_video_device.name = "camera"; | 83 dummy_video_device.name = "camera"; |
88 dummy_video_device.stream_type = content::MEDIA_DEVICE_VIDEO_CAPTURE; | 84 dummy_video_device.stream_type = MEDIA_DEVICE_VIDEO_CAPTURE; |
89 dummy_video_device.session_id = 1; | 85 dummy_video_device.session_id = 1; |
90 video_device_array[0] = dummy_video_device; | 86 video_device_array[0] = dummy_video_device; |
91 ui_controller_->AddAvailableDevicesToRequest( | 87 ui_controller_->AddAvailableDevicesToRequest( |
92 label, | 88 label, |
93 dummy_video_device.stream_type, | 89 dummy_video_device.stream_type, |
94 video_device_array); | 90 video_device_array); |
95 } | 91 } |
96 | 92 |
97 scoped_ptr<MessageLoop> message_loop_; | 93 scoped_ptr<MessageLoop> message_loop_; |
98 scoped_ptr<BrowserThreadImpl> ui_thread_; | 94 scoped_ptr<BrowserThreadImpl> ui_thread_; |
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
169 CreateDummyRequest(label_3, true, true); | 165 CreateDummyRequest(label_3, true, true); |
170 | 166 |
171 // Remove the last request which is pending in the queue. | 167 // Remove the last request which is pending in the queue. |
172 ui_controller_->CancelUIRequest(label_3); | 168 ui_controller_->CancelUIRequest(label_3); |
173 | 169 |
174 // We should get callbacks from the rest of the requests. | 170 // We should get callbacks from the rest of the requests. |
175 EXPECT_CALL(*this, DevicesAccepted(label_1, _)); | 171 EXPECT_CALL(*this, DevicesAccepted(label_1, _)); |
176 EXPECT_CALL(*this, DevicesAccepted(label_2, _)); | 172 EXPECT_CALL(*this, DevicesAccepted(label_2, _)); |
177 } | 173 } |
178 | 174 |
179 } // namespace media_stream | 175 } // namespace content |
OLD | NEW |