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

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

Issue 10829190: Resolve the problems where we can leak the system tray UI (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: fixed testbots. Created 8 years, 4 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 | 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 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_device_settings.h" 10 #include "content/browser/renderer_host/media/media_stream_device_settings.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 "testing/gmock/include/gmock/gmock.h" 13 #include "testing/gmock/include/gmock/gmock.h"
14 #include "testing/gtest/include/gtest/gtest.h" 14 #include "testing/gtest/include/gtest/gtest.h"
15 15
16 using content::BrowserThread; 16 using content::BrowserThread;
17 using content::BrowserThreadImpl; 17 using content::BrowserThreadImpl;
18 using testing::_;
18 19
19 namespace media_stream { 20 namespace media_stream {
20 21
21 // Test class. 22 // Test class.
22 class MediaStreamDeviceSettingsTest 23 class MediaStreamDeviceSettingsTest
23 : public ::testing::Test, 24 : public ::testing::Test,
24 public SettingsRequester { 25 public SettingsRequester {
25 public: 26 public:
26 MediaStreamDeviceSettingsTest() : label_("dummy_stream") {} 27 MediaStreamDeviceSettingsTest() {}
27 28
28 // Mock implementation of SettingsRequester; 29 // Mock implementation of SettingsRequester;
29 MOCK_METHOD2(DevicesAccepted, void(const std::string&, 30 MOCK_METHOD2(DevicesAccepted, void(const std::string&,
30 const StreamDeviceInfoArray&)); 31 const StreamDeviceInfoArray&));
31 MOCK_METHOD1(SettingsError, void(const std::string&)); 32 MOCK_METHOD1(SettingsError, void(const std::string&));
32 33
33 protected: 34 protected:
34 virtual void SetUp() { 35 virtual void SetUp() {
35 message_loop_.reset(new MessageLoop(MessageLoop::TYPE_IO)); 36 message_loop_.reset(new MessageLoop(MessageLoop::TYPE_IO));
36 ui_thread_.reset(new BrowserThreadImpl(BrowserThread::UI, 37 ui_thread_.reset(new BrowserThreadImpl(BrowserThread::UI,
37 message_loop_.get())); 38 message_loop_.get()));
38 io_thread_.reset(new BrowserThreadImpl(BrowserThread::IO, 39 io_thread_.reset(new BrowserThreadImpl(BrowserThread::IO,
39 message_loop_.get())); 40 message_loop_.get()));
40 device_settings_.reset(new MediaStreamDeviceSettings(this)); 41 device_settings_.reset(new MediaStreamDeviceSettings(this));
41 } 42 }
42 43
43 virtual void TearDown() { 44 virtual void TearDown() {
44 message_loop_->RunAllPending(); 45 message_loop_->RunAllPending();
45 } 46 }
46 47
47 void CreateDummyRequest() { 48 void CreateDummyRequest(const std::string& label, bool audio, bool video) {
48 int dummy_render_process_id = 1; 49 int dummy_render_process_id = 1;
49 int dummy_render_view_id = 1; 50 int dummy_render_view_id = 1;
50 StreamOptions components(true, false); 51 StreamOptions components(audio, video);
51 GURL security_origin; 52 GURL security_origin;
52 device_settings_->RequestCaptureDeviceUsage(label_, 53 device_settings_->RequestCaptureDeviceUsage(label,
53 dummy_render_process_id, 54 dummy_render_process_id,
54 dummy_render_view_id, 55 dummy_render_view_id,
55 components, 56 components,
56 security_origin); 57 security_origin);
58 if (audio)
59 CreateAudioDeviceForRequset(label);
57 60
58 // Setup the dummy available device for the reqest. 61 if (video)
62 CreateVideoDeviceForRequset(label);
63 }
64
65 void CreateAudioDeviceForRequset(const std::string& label) {
66 // Setup the dummy available device for the request.
59 media_stream::StreamDeviceInfoArray audio_device_array(1); 67 media_stream::StreamDeviceInfoArray audio_device_array(1);
60 media_stream::StreamDeviceInfo dummy_audio_device; 68 media_stream::StreamDeviceInfo dummy_audio_device;
61 dummy_audio_device.name = "Microphone"; 69 dummy_audio_device.name = "Microphone";
62 dummy_audio_device.stream_type = 70 dummy_audio_device.stream_type =
63 content::MEDIA_STREAM_DEVICE_TYPE_AUDIO_CAPTURE; 71 content::MEDIA_STREAM_DEVICE_TYPE_AUDIO_CAPTURE;
64 dummy_audio_device.session_id = 1; 72 dummy_audio_device.session_id = 1;
65 audio_device_array[0] = dummy_audio_device; 73 audio_device_array[0] = dummy_audio_device;
66 device_settings_->AvailableDevices(label_, 74 device_settings_->AvailableDevices(label,
67 dummy_audio_device.stream_type, 75 dummy_audio_device.stream_type,
68 audio_device_array); 76 audio_device_array);
69 } 77 }
70 78
79 void CreateVideoDeviceForRequset(const std::string& label) {
80 // Setup the dummy available device for the request.
81 media_stream::StreamDeviceInfoArray video_device_array(1);
82 media_stream::StreamDeviceInfo dummy_video_device;
83 dummy_video_device.name = "camera";
84 dummy_video_device.stream_type =
85 content::MEDIA_STREAM_DEVICE_TYPE_VIDEO_CAPTURE;
86 dummy_video_device.session_id = 1;
87 video_device_array[0] = dummy_video_device;
88 device_settings_->AvailableDevices(label,
89 dummy_video_device.stream_type,
90 video_device_array);
91 }
92
71 scoped_ptr<MessageLoop> message_loop_; 93 scoped_ptr<MessageLoop> message_loop_;
72 scoped_ptr<BrowserThreadImpl> ui_thread_; 94 scoped_ptr<BrowserThreadImpl> ui_thread_;
73 scoped_ptr<BrowserThreadImpl> io_thread_; 95 scoped_ptr<BrowserThreadImpl> io_thread_;
74 scoped_ptr<MediaStreamDeviceSettings> device_settings_; 96 scoped_ptr<MediaStreamDeviceSettings> device_settings_;
75 const std::string label_;
76 97
77 private: 98 private:
78 DISALLOW_COPY_AND_ASSIGN(MediaStreamDeviceSettingsTest); 99 DISALLOW_COPY_AND_ASSIGN(MediaStreamDeviceSettingsTest);
79 }; 100 };
80 101
81 TEST_F(MediaStreamDeviceSettingsTest, GenerateRequest) { 102 TEST_F(MediaStreamDeviceSettingsTest, GenerateRequest) {
82 CreateDummyRequest(); 103 const std::string label = "dummy_label";
104 CreateDummyRequest(label, true, false);
83 105
84 // Expecting an error callback triggered by the non-existing 106 // Expecting an error callback triggered by the non-existing
85 // RenderViewHostImpl. 107 // RenderViewHostImpl.
86 EXPECT_CALL(*this, SettingsError(label_)) 108 EXPECT_CALL(*this, SettingsError(label));
87 .Times(1);
88 } 109 }
89 110
90 TEST_F(MediaStreamDeviceSettingsTest, GenerateAndRemoveRequest) { 111 TEST_F(MediaStreamDeviceSettingsTest, GenerateAndRemoveRequest) {
91 CreateDummyRequest(); 112 const std::string label = "label";
113 CreateDummyRequest(label, true, false);
92 114
93 // Remove the current request, it should not crash. 115 // Remove the current request, it should not crash.
94 device_settings_->RemovePendingCaptureRequest(label_); 116 device_settings_->RemovePendingCaptureRequest(label);
117 }
118
119 TEST_F(MediaStreamDeviceSettingsTest, HandleRequestUsingFakeUI) {
120 device_settings_->UseFakeUI();
121
122 const std::string label = "label";
123 CreateDummyRequest(label, true, true);
124
125 // Remove the current request, it should not crash.
126 EXPECT_CALL(*this, DevicesAccepted(label, _));
127 }
128
129 TEST_F(MediaStreamDeviceSettingsTest, CreateMultipleRequestsAndCancelTheFirst) {
130 device_settings_->UseFakeUI();
131
132 // Create the first audio request.
133 const std::string label_1 = "label_1";
134 CreateDummyRequest(label_1, true, false);
135
136 // Create the second video request.
137 const std::string label_2 = "label_2";
138 CreateDummyRequest(label_2, false, true);
139
140 // Create the third audio and video request.
141 const std::string label_3 = "label_3";
142 CreateDummyRequest(label_3, true, true);
143
144 // Remove the first request which has been brought to the UI.
145 device_settings_->RemovePendingCaptureRequest(label_1);
146
147 // We should get callbacks from the rest of the requests.
148 EXPECT_CALL(*this, DevicesAccepted(label_2, _));
149 EXPECT_CALL(*this, DevicesAccepted(label_3, _));
150 }
151
152 TEST_F(MediaStreamDeviceSettingsTest, CreateMultipleRequestsAndCancelTheLast) {
153 device_settings_->UseFakeUI();
154
155 // Create the first audio request.
156 const std::string label_1 = "label_1";
157 CreateDummyRequest(label_1, true, false);
158
159 // Create the second video request.
160 const std::string label_2 = "label_2";
161 CreateDummyRequest(label_2, false, true);
162
163 // Create the third audio and video request.
164 const std::string label_3 = "label_3";
165 CreateDummyRequest(label_3, true, true);
166
167 // Remove the last request which is pending in the queue.
168 device_settings_->RemovePendingCaptureRequest(label_3);
169
170 // We should get callbacks from the rest of the requests.
171 EXPECT_CALL(*this, DevicesAccepted(label_1, _));
172 EXPECT_CALL(*this, DevicesAccepted(label_2, _));
95 } 173 }
96 174
97 } // namespace media_stream 175 } // namespace media_stream
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698