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_dispatcher_host.h" | 10 #include "content/browser/renderer_host/media/media_stream_dispatcher_host.h" |
11 #include "content/browser/renderer_host/media/media_stream_manager.h" | 11 #include "content/browser/renderer_host/media/media_stream_manager.h" |
| 12 #include "content/browser/renderer_host/media/media_stream_ui_proxy.h" |
12 #include "content/browser/renderer_host/media/video_capture_manager.h" | 13 #include "content/browser/renderer_host/media/video_capture_manager.h" |
13 #include "content/common/media/media_stream_messages.h" | 14 #include "content/common/media/media_stream_messages.h" |
14 #include "content/common/media/media_stream_options.h" | 15 #include "content/common/media/media_stream_options.h" |
15 #include "content/public/test/mock_resource_context.h" | 16 #include "content/public/test/mock_resource_context.h" |
16 #include "content/public/test/test_browser_thread.h" | 17 #include "content/public/test/test_browser_thread.h" |
17 #include "content/test/test_content_browser_client.h" | 18 #include "content/test/test_content_browser_client.h" |
18 #include "content/test/test_content_client.h" | 19 #include "content/test/test_content_client.h" |
19 #include "ipc/ipc_message_macros.h" | 20 #include "ipc/ipc_message_macros.h" |
20 #include "media/audio/audio_manager.h" | 21 #include "media/audio/audio_manager.h" |
21 #include "media/video/capture/fake_video_capture_device.h" | 22 #include "media/video/capture/fake_video_capture_device.h" |
(...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
118 void OnStreamGenerationFailed(const IPC::Message& msg, int request_id) { | 119 void OnStreamGenerationFailed(const IPC::Message& msg, int request_id) { |
119 OnStreamGenerationFailed(msg.routing_id(), request_id); | 120 OnStreamGenerationFailed(msg.routing_id(), request_id); |
120 message_loop_->PostTask(FROM_HERE, base::MessageLoop::QuitClosure()); | 121 message_loop_->PostTask(FROM_HERE, base::MessageLoop::QuitClosure()); |
121 label_= ""; | 122 label_= ""; |
122 } | 123 } |
123 | 124 |
124 base::MessageLoop* message_loop_; | 125 base::MessageLoop* message_loop_; |
125 MediaStreamManager* manager_; | 126 MediaStreamManager* manager_; |
126 }; | 127 }; |
127 | 128 |
128 class MockMediaStreamUI : public MediaStreamUI { | 129 class MockMediaStreamUIProxy : public FakeMediaStreamUIProxy { |
129 public: | 130 public: |
130 MOCK_METHOD1(OnStarted, void(const base::Closure& stop)); | 131 MOCK_METHOD1(OnStarted, void(const base::Closure& stop)); |
131 }; | 132 }; |
132 | 133 |
133 class MediaStreamDispatcherHostTest : public testing::Test { | 134 class MediaStreamDispatcherHostTest : public testing::Test { |
134 public: | 135 public: |
135 MediaStreamDispatcherHostTest() : old_browser_client_(NULL) {} | 136 MediaStreamDispatcherHostTest() : old_browser_client_(NULL) {} |
136 virtual ~MediaStreamDispatcherHostTest() {} | 137 virtual ~MediaStreamDispatcherHostTest() {} |
137 | 138 |
138 void WaitForResult() { | 139 void WaitForResult() { |
(...skipping 18 matching lines...) Expand all Loading... |
157 host_ = new MockMediaStreamDispatcherHost(message_loop_.get(), | 158 host_ = new MockMediaStreamDispatcherHost(message_loop_.get(), |
158 media_stream_manager_.get()); | 159 media_stream_manager_.get()); |
159 | 160 |
160 // Use the fake content client and browser. | 161 // Use the fake content client and browser. |
161 content_client_.reset(new TestContentClient); | 162 content_client_.reset(new TestContentClient); |
162 SetContentClient(content_client_.get()); | 163 SetContentClient(content_client_.get()); |
163 old_browser_client_ = SetBrowserClientForTesting(host_); | 164 old_browser_client_ = SetBrowserClientForTesting(host_); |
164 } | 165 } |
165 | 166 |
166 virtual void SetupFakeUI(bool expect_started) { | 167 virtual void SetupFakeUI(bool expect_started) { |
167 scoped_ptr<MockMediaStreamUI> stream_ui(new MockMediaStreamUI()); | 168 scoped_ptr<MockMediaStreamUIProxy> stream_ui(new MockMediaStreamUIProxy()); |
168 if (expect_started) { | 169 if (expect_started) { |
169 EXPECT_CALL(*stream_ui, OnStarted(_)); | 170 EXPECT_CALL(*stream_ui, OnStarted(_)); |
170 } | 171 } |
171 media_stream_manager_->UseFakeUI(stream_ui.PassAs<MediaStreamUI>()); | 172 media_stream_manager_->UseFakeUI(stream_ui.PassAs<MediaStreamUIProxy>()); |
172 } | 173 } |
173 | 174 |
174 virtual void TearDown() OVERRIDE { | 175 virtual void TearDown() OVERRIDE { |
175 message_loop_->RunUntilIdle(); | 176 message_loop_->RunUntilIdle(); |
176 | 177 |
177 // Recover the old browser client and content client. | 178 // Recover the old browser client and content client. |
178 SetBrowserClientForTesting(old_browser_client_); | 179 SetBrowserClientForTesting(old_browser_client_); |
179 content_client_.reset(); | 180 content_client_.reset(); |
180 | 181 |
181 // Delete the IO message loop to delete the device thread, | 182 // Delete the IO message loop to delete the device thread, |
(...skipping 144 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
326 message_loop_->RunUntilIdle(); | 327 message_loop_->RunUntilIdle(); |
327 | 328 |
328 // Streams should have been cleaned up. | 329 // Streams should have been cleaned up. |
329 EXPECT_EQ(host_->NumberOfStreams(), 0u); | 330 EXPECT_EQ(host_->NumberOfStreams(), 0u); |
330 } | 331 } |
331 | 332 |
332 TEST_F(MediaStreamDispatcherHostTest, CloseFromUI) { | 333 TEST_F(MediaStreamDispatcherHostTest, CloseFromUI) { |
333 StreamOptions options(MEDIA_NO_SERVICE, MEDIA_DEVICE_VIDEO_CAPTURE); | 334 StreamOptions options(MEDIA_NO_SERVICE, MEDIA_DEVICE_VIDEO_CAPTURE); |
334 | 335 |
335 base::Closure close_callback; | 336 base::Closure close_callback; |
336 scoped_ptr<MockMediaStreamUI> stream_ui(new MockMediaStreamUI()); | 337 scoped_ptr<MockMediaStreamUIProxy> stream_ui(new MockMediaStreamUIProxy()); |
337 EXPECT_CALL(*stream_ui, OnStarted(_)) | 338 EXPECT_CALL(*stream_ui, OnStarted(_)) |
338 .WillOnce(SaveArg<0>(&close_callback)); | 339 .WillOnce(SaveArg<0>(&close_callback)); |
339 media_stream_manager_->UseFakeUI(stream_ui.PassAs<MediaStreamUI>()); | 340 media_stream_manager_->UseFakeUI(stream_ui.PassAs<MediaStreamUIProxy>()); |
340 | 341 |
341 EXPECT_CALL(*host_, OnStreamGenerated(kRenderId, kPageRequestId, 0, 1)); | 342 EXPECT_CALL(*host_, OnStreamGenerated(kRenderId, kPageRequestId, 0, 1)); |
342 EXPECT_CALL(*host_, OnStreamGenerationFailed(kRenderId, kPageRequestId)); | 343 EXPECT_CALL(*host_, OnStreamGenerationFailed(kRenderId, kPageRequestId)); |
343 host_->OnGenerateStream(kPageRequestId, options); | 344 host_->OnGenerateStream(kPageRequestId, options); |
344 | 345 |
345 WaitForResult(); | 346 WaitForResult(); |
346 | 347 |
347 EXPECT_EQ(host_->audio_devices_.size(), 0u); | 348 EXPECT_EQ(host_->audio_devices_.size(), 0u); |
348 EXPECT_EQ(host_->video_devices_.size(), 1u); | 349 EXPECT_EQ(host_->video_devices_.size(), 1u); |
349 EXPECT_EQ(host_->NumberOfStreams(), 1u); | 350 EXPECT_EQ(host_->NumberOfStreams(), 1u); |
350 | 351 |
351 ASSERT_FALSE(close_callback.is_null()); | 352 ASSERT_FALSE(close_callback.is_null()); |
352 close_callback.Run(); | 353 close_callback.Run(); |
353 message_loop_->RunUntilIdle(); | 354 message_loop_->RunUntilIdle(); |
354 | 355 |
355 EXPECT_EQ(host_->NumberOfStreams(), 0u); | 356 EXPECT_EQ(host_->NumberOfStreams(), 0u); |
356 } | 357 } |
357 | 358 |
358 }; // namespace content | 359 }; // namespace content |
OLD | NEW |