| 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_.get()); | 164 old_browser_client_ = SetBrowserClientForTesting(host_.get()); |
| 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( |
| 173 stream_ui.PassAs<FakeMediaStreamUIProxy>()); |
| 172 } | 174 } |
| 173 | 175 |
| 174 virtual void TearDown() OVERRIDE { | 176 virtual void TearDown() OVERRIDE { |
| 175 message_loop_->RunUntilIdle(); | 177 message_loop_->RunUntilIdle(); |
| 176 | 178 |
| 177 // Recover the old browser client and content client. | 179 // Recover the old browser client and content client. |
| 178 SetBrowserClientForTesting(old_browser_client_); | 180 SetBrowserClientForTesting(old_browser_client_); |
| 179 content_client_.reset(); | 181 content_client_.reset(); |
| 180 | 182 |
| 181 // Delete the IO message loop to delete the device thread, | 183 // Delete the IO message loop to delete the device thread, |
| (...skipping 147 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 329 message_loop_->RunUntilIdle(); | 331 message_loop_->RunUntilIdle(); |
| 330 | 332 |
| 331 // Streams should have been cleaned up. | 333 // Streams should have been cleaned up. |
| 332 EXPECT_EQ(host_->NumberOfStreams(), 0u); | 334 EXPECT_EQ(host_->NumberOfStreams(), 0u); |
| 333 } | 335 } |
| 334 | 336 |
| 335 TEST_F(MediaStreamDispatcherHostTest, CloseFromUI) { | 337 TEST_F(MediaStreamDispatcherHostTest, CloseFromUI) { |
| 336 StreamOptions options(MEDIA_NO_SERVICE, MEDIA_DEVICE_VIDEO_CAPTURE); | 338 StreamOptions options(MEDIA_NO_SERVICE, MEDIA_DEVICE_VIDEO_CAPTURE); |
| 337 | 339 |
| 338 base::Closure close_callback; | 340 base::Closure close_callback; |
| 339 scoped_ptr<MockMediaStreamUI> stream_ui(new MockMediaStreamUI()); | 341 scoped_ptr<MockMediaStreamUIProxy> stream_ui(new MockMediaStreamUIProxy()); |
| 340 EXPECT_CALL(*stream_ui, OnStarted(_)) | 342 EXPECT_CALL(*stream_ui, OnStarted(_)) |
| 341 .WillOnce(SaveArg<0>(&close_callback)); | 343 .WillOnce(SaveArg<0>(&close_callback)); |
| 342 media_stream_manager_->UseFakeUI(stream_ui.PassAs<MediaStreamUI>()); | 344 media_stream_manager_->UseFakeUI(stream_ui.PassAs<FakeMediaStreamUIProxy>()); |
| 343 | 345 |
| 344 EXPECT_CALL(*host_.get(), OnStreamGenerated(kRenderId, kPageRequestId, 0, 1)); | 346 EXPECT_CALL(*host_.get(), OnStreamGenerated(kRenderId, kPageRequestId, 0, 1)); |
| 345 EXPECT_CALL(*host_.get(), | 347 EXPECT_CALL(*host_.get(), |
| 346 OnStreamGenerationFailed(kRenderId, kPageRequestId)); | 348 OnStreamGenerationFailed(kRenderId, kPageRequestId)); |
| 347 host_->OnGenerateStream(kPageRequestId, options); | 349 host_->OnGenerateStream(kPageRequestId, options); |
| 348 | 350 |
| 349 WaitForResult(); | 351 WaitForResult(); |
| 350 | 352 |
| 351 EXPECT_EQ(host_->audio_devices_.size(), 0u); | 353 EXPECT_EQ(host_->audio_devices_.size(), 0u); |
| 352 EXPECT_EQ(host_->video_devices_.size(), 1u); | 354 EXPECT_EQ(host_->video_devices_.size(), 1u); |
| 353 EXPECT_EQ(host_->NumberOfStreams(), 1u); | 355 EXPECT_EQ(host_->NumberOfStreams(), 1u); |
| 354 | 356 |
| 355 ASSERT_FALSE(close_callback.is_null()); | 357 ASSERT_FALSE(close_callback.is_null()); |
| 356 close_callback.Run(); | 358 close_callback.Run(); |
| 357 message_loop_->RunUntilIdle(); | 359 message_loop_->RunUntilIdle(); |
| 358 | 360 |
| 359 EXPECT_EQ(host_->NumberOfStreams(), 0u); | 361 EXPECT_EQ(host_->NumberOfStreams(), 0u); |
| 360 } | 362 } |
| 361 | 363 |
| 362 }; // namespace content | 364 }; // namespace content |
| OLD | NEW |