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

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

Issue 180633008: Add different error codes for getUserMedia. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Fixed comments Created 6 years, 9 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 2013 The Chromium Authors. All rights reserved. 1 // Copyright 2013 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_ui_proxy.h" 5 #include "content/browser/renderer_host/media/media_stream_ui_proxy.h"
6 6
7 #include "base/message_loop/message_loop.h" 7 #include "base/message_loop/message_loop.h"
8 #include "content/browser/renderer_host/render_view_host_delegate.h" 8 #include "content/browser/renderer_host/render_view_host_delegate.h"
9 #include "content/public/common/renderer_preferences.h" 9 #include "content/public/common/renderer_preferences.h"
10 #include "content/public/test/test_browser_thread.h" 10 #include "content/public/test/test_browser_thread.h"
(...skipping 20 matching lines...) Expand all
31 } 31 }
32 virtual RendererPreferences GetRendererPrefs( 32 virtual RendererPreferences GetRendererPrefs(
33 BrowserContext* browser_context) const OVERRIDE { 33 BrowserContext* browser_context) const OVERRIDE {
34 NOTREACHED(); 34 NOTREACHED();
35 return RendererPreferences(); 35 return RendererPreferences();
36 } 36 }
37 }; 37 };
38 38
39 class MockResponseCallback { 39 class MockResponseCallback {
40 public: 40 public:
41 MOCK_METHOD1(OnAccessRequestResponse, 41 MOCK_METHOD2(OnAccessRequestResponse,
42 void(const MediaStreamDevices& devices)); 42 void(const MediaStreamDevices& devices,
43 content::MediaStreamRequestResult result));
43 }; 44 };
44 45
45 class MockMediaStreamUI : public MediaStreamUI { 46 class MockMediaStreamUI : public MediaStreamUI {
46 public: 47 public:
47 MOCK_METHOD1(OnStarted, void(const base::Closure& stop)); 48 MOCK_METHOD1(OnStarted, void(const base::Closure& stop));
48 }; 49 };
49 50
50 class MockStopStreamHandler { 51 class MockStopStreamHandler {
51 public: 52 public:
52 MOCK_METHOD0(OnStop, void()); 53 MOCK_METHOD0(OnStop, void());
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after
100 proxy_->RequestAccess( 101 proxy_->RequestAccess(
101 request, base::Bind(&MockResponseCallback::OnAccessRequestResponse, 102 request, base::Bind(&MockResponseCallback::OnAccessRequestResponse,
102 base::Unretained(&response_callback_))); 103 base::Unretained(&response_callback_)));
103 MediaResponseCallback callback; 104 MediaResponseCallback callback;
104 EXPECT_CALL(delegate_, RequestMediaAccessPermission(SameRequest(request), _)) 105 EXPECT_CALL(delegate_, RequestMediaAccessPermission(SameRequest(request), _))
105 .WillOnce(SaveArg<1>(&callback)); 106 .WillOnce(SaveArg<1>(&callback));
106 message_loop_.RunUntilIdle(); 107 message_loop_.RunUntilIdle();
107 ASSERT_FALSE(callback.is_null()); 108 ASSERT_FALSE(callback.is_null());
108 109
109 MediaStreamDevices devices; 110 MediaStreamDevices devices;
110 callback.Run(devices, scoped_ptr<MediaStreamUI>()); 111 callback.Run(devices, MEDIA_DEVICE_OK, scoped_ptr<MediaStreamUI>());
111 112
112 MediaStreamDevices response; 113 MediaStreamDevices response;
113 EXPECT_CALL(response_callback_, OnAccessRequestResponse(_)) 114 EXPECT_CALL(response_callback_, OnAccessRequestResponse(_, _))
114 .WillOnce(SaveArg<0>(&response)); 115 .WillOnce(SaveArg<0>(&response));
115 message_loop_.RunUntilIdle(); 116 message_loop_.RunUntilIdle();
116 117
117 EXPECT_TRUE(response.empty()); 118 EXPECT_TRUE(response.empty());
118 } 119 }
119 120
120 TEST_F(MediaStreamUIProxyTest, AcceptAndStart) { 121 TEST_F(MediaStreamUIProxyTest, AcceptAndStart) {
121 MediaStreamRequest request(0, 0, 0, GURL("http://origin/"), 122 MediaStreamRequest request(0, 0, 0, GURL("http://origin/"),
122 MEDIA_GENERATE_STREAM, std::string(), 123 MEDIA_GENERATE_STREAM, std::string(),
123 std::string(), 124 std::string(),
124 MEDIA_DEVICE_AUDIO_CAPTURE, 125 MEDIA_DEVICE_AUDIO_CAPTURE,
125 MEDIA_DEVICE_VIDEO_CAPTURE); 126 MEDIA_DEVICE_VIDEO_CAPTURE);
126 proxy_->RequestAccess( 127 proxy_->RequestAccess(
127 request, base::Bind(&MockResponseCallback::OnAccessRequestResponse, 128 request, base::Bind(&MockResponseCallback::OnAccessRequestResponse,
128 base::Unretained(&response_callback_))); 129 base::Unretained(&response_callback_)));
129 MediaResponseCallback callback; 130 MediaResponseCallback callback;
130 EXPECT_CALL(delegate_, RequestMediaAccessPermission(SameRequest(request), _)) 131 EXPECT_CALL(delegate_, RequestMediaAccessPermission(SameRequest(request), _))
131 .WillOnce(SaveArg<1>(&callback)); 132 .WillOnce(SaveArg<1>(&callback));
132 message_loop_.RunUntilIdle(); 133 message_loop_.RunUntilIdle();
133 ASSERT_FALSE(callback.is_null()); 134 ASSERT_FALSE(callback.is_null());
134 135
135 MediaStreamDevices devices; 136 MediaStreamDevices devices;
136 devices.push_back( 137 devices.push_back(
137 MediaStreamDevice(MEDIA_DEVICE_AUDIO_CAPTURE, "Mic", "Mic")); 138 MediaStreamDevice(MEDIA_DEVICE_AUDIO_CAPTURE, "Mic", "Mic"));
138 scoped_ptr<MockMediaStreamUI> ui(new MockMediaStreamUI()); 139 scoped_ptr<MockMediaStreamUI> ui(new MockMediaStreamUI());
139 EXPECT_CALL(*ui, OnStarted(_)); 140 EXPECT_CALL(*ui, OnStarted(_));
140 callback.Run(devices, ui.PassAs<MediaStreamUI>()); 141 callback.Run(devices, MEDIA_DEVICE_OK, ui.PassAs<MediaStreamUI>());
141 142
142 MediaStreamDevices response; 143 MediaStreamDevices response;
143 EXPECT_CALL(response_callback_, OnAccessRequestResponse(_)) 144 EXPECT_CALL(response_callback_, OnAccessRequestResponse(_, _))
144 .WillOnce(SaveArg<0>(&response)); 145 .WillOnce(SaveArg<0>(&response));
145 message_loop_.RunUntilIdle(); 146 message_loop_.RunUntilIdle();
146 147
147 EXPECT_FALSE(response.empty()); 148 EXPECT_FALSE(response.empty());
148 149
149 proxy_->OnStarted(base::Closure()); 150 proxy_->OnStarted(base::Closure());
150 message_loop_.RunUntilIdle(); 151 message_loop_.RunUntilIdle();
151 } 152 }
152 153
153 // Verify that the proxy can be deleted before the request is processed. 154 // Verify that the proxy can be deleted before the request is processed.
154 TEST_F(MediaStreamUIProxyTest, DeleteBeforeAccepted) { 155 TEST_F(MediaStreamUIProxyTest, DeleteBeforeAccepted) {
155 MediaStreamRequest request(0, 0, 0, GURL("http://origin/"), 156 MediaStreamRequest request(0, 0, 0, GURL("http://origin/"),
156 MEDIA_GENERATE_STREAM, std::string(), 157 MEDIA_GENERATE_STREAM, std::string(),
157 std::string(), 158 std::string(),
158 MEDIA_DEVICE_AUDIO_CAPTURE, 159 MEDIA_DEVICE_AUDIO_CAPTURE,
159 MEDIA_DEVICE_VIDEO_CAPTURE); 160 MEDIA_DEVICE_VIDEO_CAPTURE);
160 proxy_->RequestAccess( 161 proxy_->RequestAccess(
161 request, base::Bind(&MockResponseCallback::OnAccessRequestResponse, 162 request, base::Bind(&MockResponseCallback::OnAccessRequestResponse,
162 base::Unretained(&response_callback_))); 163 base::Unretained(&response_callback_)));
163 MediaResponseCallback callback; 164 MediaResponseCallback callback;
164 EXPECT_CALL(delegate_, RequestMediaAccessPermission(SameRequest(request), _)) 165 EXPECT_CALL(delegate_, RequestMediaAccessPermission(SameRequest(request), _))
165 .WillOnce(SaveArg<1>(&callback)); 166 .WillOnce(SaveArg<1>(&callback));
166 message_loop_.RunUntilIdle(); 167 message_loop_.RunUntilIdle();
167 ASSERT_FALSE(callback.is_null()); 168 ASSERT_FALSE(callback.is_null());
168 169
169 proxy_.reset(); 170 proxy_.reset();
170 171
171 MediaStreamDevices devices; 172 MediaStreamDevices devices;
172 scoped_ptr<MediaStreamUI> ui; 173 scoped_ptr<MediaStreamUI> ui;
173 callback.Run(devices, ui.Pass()); 174 callback.Run(devices, MEDIA_DEVICE_OK, ui.Pass());
174 } 175 }
175 176
176 TEST_F(MediaStreamUIProxyTest, StopFromUI) { 177 TEST_F(MediaStreamUIProxyTest, StopFromUI) {
177 MediaStreamRequest request(0, 0, 0, GURL("http://origin/"), 178 MediaStreamRequest request(0, 0, 0, GURL("http://origin/"),
178 MEDIA_GENERATE_STREAM, std::string(), 179 MEDIA_GENERATE_STREAM, std::string(),
179 std::string(), 180 std::string(),
180 MEDIA_DEVICE_AUDIO_CAPTURE, 181 MEDIA_DEVICE_AUDIO_CAPTURE,
181 MEDIA_DEVICE_VIDEO_CAPTURE); 182 MEDIA_DEVICE_VIDEO_CAPTURE);
182 proxy_->RequestAccess( 183 proxy_->RequestAccess(
183 request, base::Bind(&MockResponseCallback::OnAccessRequestResponse, 184 request, base::Bind(&MockResponseCallback::OnAccessRequestResponse,
184 base::Unretained(&response_callback_))); 185 base::Unretained(&response_callback_)));
185 MediaResponseCallback callback; 186 MediaResponseCallback callback;
186 EXPECT_CALL(delegate_, RequestMediaAccessPermission(SameRequest(request), _)) 187 EXPECT_CALL(delegate_, RequestMediaAccessPermission(SameRequest(request), _))
187 .WillOnce(SaveArg<1>(&callback)); 188 .WillOnce(SaveArg<1>(&callback));
188 message_loop_.RunUntilIdle(); 189 message_loop_.RunUntilIdle();
189 ASSERT_FALSE(callback.is_null()); 190 ASSERT_FALSE(callback.is_null());
190 191
191 base::Closure stop_callback; 192 base::Closure stop_callback;
192 193
193 MediaStreamDevices devices; 194 MediaStreamDevices devices;
194 devices.push_back( 195 devices.push_back(
195 MediaStreamDevice(MEDIA_DEVICE_AUDIO_CAPTURE, "Mic", "Mic")); 196 MediaStreamDevice(MEDIA_DEVICE_AUDIO_CAPTURE, "Mic", "Mic"));
196 scoped_ptr<MockMediaStreamUI> ui(new MockMediaStreamUI()); 197 scoped_ptr<MockMediaStreamUI> ui(new MockMediaStreamUI());
197 EXPECT_CALL(*ui, OnStarted(_)) 198 EXPECT_CALL(*ui, OnStarted(_))
198 .WillOnce(SaveArg<0>(&stop_callback)); 199 .WillOnce(SaveArg<0>(&stop_callback));
199 callback.Run(devices, ui.PassAs<MediaStreamUI>()); 200 callback.Run(devices, MEDIA_DEVICE_OK, ui.PassAs<MediaStreamUI>());
200 201
201 MediaStreamDevices response; 202 MediaStreamDevices response;
202 EXPECT_CALL(response_callback_, OnAccessRequestResponse(_)) 203 EXPECT_CALL(response_callback_, OnAccessRequestResponse(_, _))
203 .WillOnce(SaveArg<0>(&response)); 204 .WillOnce(SaveArg<0>(&response));
204 message_loop_.RunUntilIdle(); 205 message_loop_.RunUntilIdle();
205 206
206 EXPECT_FALSE(response.empty()); 207 EXPECT_FALSE(response.empty());
207 208
208 MockStopStreamHandler stop_handler; 209 MockStopStreamHandler stop_handler;
209 proxy_->OnStarted(base::Bind(&MockStopStreamHandler::OnStop, 210 proxy_->OnStarted(base::Bind(&MockStopStreamHandler::OnStop,
210 base::Unretained(&stop_handler))); 211 base::Unretained(&stop_handler)));
211 message_loop_.RunUntilIdle(); 212 message_loop_.RunUntilIdle();
212 213
213 ASSERT_FALSE(stop_callback.is_null()); 214 ASSERT_FALSE(stop_callback.is_null());
214 EXPECT_CALL(stop_handler, OnStop()); 215 EXPECT_CALL(stop_handler, OnStop());
215 stop_callback.Run(); 216 stop_callback.Run();
216 message_loop_.RunUntilIdle(); 217 message_loop_.RunUntilIdle();
217 } 218 }
218 219
219 } // content 220 } // content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698