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

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

Issue 16342002: Replace MediaStreamUIController with MediaStreamUIProxy. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 7 years, 6 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
(Empty)
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
3 // found in the LICENSE file.
4
5 #include "content/browser/renderer_host/media/media_stream_ui_proxy.h"
6
7 #include "base/message_loop.h"
8 #include "content/browser/renderer_host/render_view_host_delegate.h"
9 #include "content/public/common/renderer_preferences.h"
10 #include "content/public/test/test_browser_thread.h"
11 #include "testing/gmock/include/gmock/gmock.h"
12 #include "testing/gtest/include/gtest/gtest.h"
13 #include "ui/gfx/rect.h"
14
15 using testing::_;
16 using testing::SaveArg;
17
18 namespace content {
19 namespace {
20
21 class MockRenderViewHostDelegate : public RenderViewHostDelegate {
22 public:
23 MOCK_METHOD2(RequestMediaAccessPermission,
24 void(const MediaStreamRequest& request,
25 const MediaResponseCallback& callback));
26
27 // Stubs for pure virtual methods we don't care about.
28 virtual gfx::Rect GetRootWindowResizerRect() const OVERRIDE {
29 NOTREACHED();
30 return gfx::Rect();
31 }
32 virtual RendererPreferences GetRendererPrefs(
33 BrowserContext* browser_context) const OVERRIDE {
34 NOTREACHED();
35 return RendererPreferences();
36 }
37 };
38
39 class MockResponseCallback {
40 public:
41 MOCK_METHOD1(OnAccessRequestResponse,
42 void(const MediaStreamDevices& devices));
43 };
44
45 class MockMediaStreamUI : public MediaStreamUI {
46 public:
47 MOCK_METHOD1(OnStarted, void(const base::Closure& stop));
48 };
49
50 class MockStopStreamHandler {
51 public:
52 MOCK_METHOD0(OnStop, void());
53 };
54
55
56 } // namespace
57
58 class MediaStreamUIProxyTest : public testing::Test {
59 public:
60 MediaStreamUIProxyTest()
61 : ui_thread_(BrowserThread::UI, &message_loop_),
62 io_thread_(BrowserThread::IO, &message_loop_) {
63 proxy_.reset(new MediaStreamUIProxy());
miu 2013/06/06 20:03:01 Yeah, just use injection (suggested in other comme
Sergey Ulanov 2013/06/06 21:40:03 Done.
64 proxy_->SetRenderViewHostDelegateForTests(&delegate_);
65 }
66
67 ~MediaStreamUIProxyTest() {
68 proxy_.reset();
69 message_loop_.RunUntilIdle();
70 }
71
72 protected:
73 base::MessageLoop message_loop_;
74 TestBrowserThread ui_thread_;
75 TestBrowserThread io_thread_;
76
77 MockRenderViewHostDelegate delegate_;
78 MockResponseCallback response_callback_;
79 scoped_ptr<MediaStreamUIProxy> proxy_;
80 };
81
82 MATCHER_P(SameRequest, expected, "") {
83 return
miu 2013/06/06 20:03:01 Can this just be: return expected == arg; Sinc
Sergey Ulanov 2013/06/06 21:40:03 Nope, there is no implicit comparison operator for
miu 2013/06/06 23:05:23 Ah, my mistake. Not sure why I keep thinking C++
Sergey Ulanov 2013/06/07 00:37:09 I'd rather leave it as is - code style discourages
84 expected.render_process_id == arg.render_process_id &&
85 expected.render_view_id == arg.render_view_id &&
86 expected.security_origin == arg.security_origin &&
87 expected.request_type == arg.request_type &&
88 expected.requested_device_id == arg.requested_device_id &&
89 expected.audio_type == arg.audio_type &&
90 expected.video_type == arg.video_type;
91 }
92
93 TEST_F(MediaStreamUIProxyTest, Deny) {
94 MediaStreamRequest request(0, 0, GURL("http://origin/"),
95 MEDIA_GENERATE_STREAM, std::string(),
96 MEDIA_DEVICE_AUDIO_CAPTURE,
97 MEDIA_DEVICE_VIDEO_CAPTURE);
98 proxy_->RequestAccess(
99 request, base::Bind(&MockResponseCallback::OnAccessRequestResponse,
100 base::Unretained(&response_callback_)));
101 MediaResponseCallback callback;
102 EXPECT_CALL(delegate_, RequestMediaAccessPermission(SameRequest(request), _))
103 .WillOnce(SaveArg<1>(&callback));
104 message_loop_.RunUntilIdle();
105 ASSERT_FALSE(callback.is_null());
106
107 MediaStreamDevices devices;
108 callback.Run(devices, scoped_ptr<MediaStreamUI>());
109
110 MediaStreamDevices response;
111 EXPECT_CALL(response_callback_, OnAccessRequestResponse(_))
112 .WillOnce(SaveArg<0>(&response));
113 message_loop_.RunUntilIdle();
114
115 EXPECT_TRUE(response.empty());
116 }
117
118 TEST_F(MediaStreamUIProxyTest, AcceptAndStart) {
119 MediaStreamRequest request(0, 0, GURL("http://origin/"),
120 MEDIA_GENERATE_STREAM, std::string(),
121 MEDIA_DEVICE_AUDIO_CAPTURE,
122 MEDIA_DEVICE_VIDEO_CAPTURE);
123 proxy_->RequestAccess(
124 request, base::Bind(&MockResponseCallback::OnAccessRequestResponse,
125 base::Unretained(&response_callback_)));
126 MediaResponseCallback callback;
127 EXPECT_CALL(delegate_, RequestMediaAccessPermission(SameRequest(request), _))
128 .WillOnce(SaveArg<1>(&callback));
129 message_loop_.RunUntilIdle();
130 ASSERT_FALSE(callback.is_null());
131
132 MediaStreamDevices devices;
133 devices.push_back(
134 MediaStreamDevice(MEDIA_DEVICE_AUDIO_CAPTURE, "Mic", "Mic"));
135 scoped_ptr<MockMediaStreamUI> ui(new MockMediaStreamUI());
136 EXPECT_CALL(*ui, OnStarted(_));
137 callback.Run(devices, ui.PassAs<MediaStreamUI>());
138
139 MediaStreamDevices response;
140 EXPECT_CALL(response_callback_, OnAccessRequestResponse(_))
141 .WillOnce(SaveArg<0>(&response));
142 message_loop_.RunUntilIdle();
143
144 EXPECT_FALSE(response.empty());
145
146 proxy_->OnStarted(base::Closure());
147 message_loop_.RunUntilIdle();
148 }
149
150 // Verify that the proxy can be deleted before the request is processed.
151 TEST_F(MediaStreamUIProxyTest, DeleteBeforeAccepted) {
152 MediaStreamRequest request(0, 0, GURL("http://origin/"),
153 MEDIA_GENERATE_STREAM, std::string(),
154 MEDIA_DEVICE_AUDIO_CAPTURE,
155 MEDIA_DEVICE_VIDEO_CAPTURE);
156 proxy_->RequestAccess(
157 request, base::Bind(&MockResponseCallback::OnAccessRequestResponse,
158 base::Unretained(&response_callback_)));
159 MediaResponseCallback callback;
160 EXPECT_CALL(delegate_, RequestMediaAccessPermission(SameRequest(request), _))
161 .WillOnce(SaveArg<1>(&callback));
162 message_loop_.RunUntilIdle();
163 ASSERT_FALSE(callback.is_null());
164
165 proxy_.reset();
166
167 MediaStreamDevices devices;
168 scoped_ptr<MediaStreamUI> ui;
169 callback.Run(devices, ui.Pass());
170 }
171
172 TEST_F(MediaStreamUIProxyTest, StopFromUI) {
173 MediaStreamRequest request(0, 0, GURL("http://origin/"),
174 MEDIA_GENERATE_STREAM, std::string(),
175 MEDIA_DEVICE_AUDIO_CAPTURE,
176 MEDIA_DEVICE_VIDEO_CAPTURE);
177 proxy_->RequestAccess(
178 request, base::Bind(&MockResponseCallback::OnAccessRequestResponse,
179 base::Unretained(&response_callback_)));
180 MediaResponseCallback callback;
181 EXPECT_CALL(delegate_, RequestMediaAccessPermission(SameRequest(request), _))
182 .WillOnce(SaveArg<1>(&callback));
183 message_loop_.RunUntilIdle();
184 ASSERT_FALSE(callback.is_null());
185
186 base::Closure stop_callback;
187
188 MediaStreamDevices devices;
189 devices.push_back(
190 MediaStreamDevice(MEDIA_DEVICE_AUDIO_CAPTURE, "Mic", "Mic"));
191 scoped_ptr<MockMediaStreamUI> ui(new MockMediaStreamUI());
192 EXPECT_CALL(*ui, OnStarted(_))
193 .WillOnce(SaveArg<0>(&stop_callback));
194 callback.Run(devices, ui.PassAs<MediaStreamUI>());
195
196 MediaStreamDevices response;
197 EXPECT_CALL(response_callback_, OnAccessRequestResponse(_))
198 .WillOnce(SaveArg<0>(&response));
199 message_loop_.RunUntilIdle();
200
201 EXPECT_FALSE(response.empty());
202
203 MockStopStreamHandler stop_handler;
204 proxy_->OnStarted(base::Bind(&MockStopStreamHandler::OnStop,
205 base::Unretained(&stop_handler)));
206 message_loop_.RunUntilIdle();
207
208 ASSERT_FALSE(stop_callback.is_null());
209 EXPECT_CALL(stop_handler, OnStop());
210 stop_callback.Run();
211 message_loop_.RunUntilIdle();
212 }
213
214 } // content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698