| 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/mock_content_browser_client.h" | |
| 11 #include "content/browser/renderer_host/media/media_stream_dispatcher_host.h" | 10 #include "content/browser/renderer_host/media/media_stream_dispatcher_host.h" |
| 12 #include "content/browser/renderer_host/media/media_stream_manager.h" | 11 #include "content/browser/renderer_host/media/media_stream_manager.h" |
| 13 #include "content/browser/renderer_host/media/mock_media_observer.h" | 12 #include "content/browser/renderer_host/media/mock_media_observer.h" |
| 14 #include "content/browser/renderer_host/media/video_capture_manager.h" | 13 #include "content/browser/renderer_host/media/video_capture_manager.h" |
| 15 #include "content/common/media/media_stream_messages.h" | 14 #include "content/common/media/media_stream_messages.h" |
| 16 #include "content/common/media/media_stream_options.h" | 15 #include "content/common/media/media_stream_options.h" |
| 17 #include "content/public/test/mock_resource_context.h" | 16 #include "content/public/test/mock_resource_context.h" |
| 17 #include "content/test/test_content_browser_client.h" |
| 18 #include "content/test/test_content_client.h" | 18 #include "content/test/test_content_client.h" |
| 19 #include "ipc/ipc_message_macros.h" | 19 #include "ipc/ipc_message_macros.h" |
| 20 #include "media/audio/audio_manager.h" | 20 #include "media/audio/audio_manager.h" |
| 21 #include "net/url_request/url_request_context.h" | 21 #include "net/url_request/url_request_context.h" |
| 22 #include "testing/gmock/include/gmock/gmock.h" | 22 #include "testing/gmock/include/gmock/gmock.h" |
| 23 #include "testing/gtest/include/gtest/gtest.h" | 23 #include "testing/gtest/include/gtest/gtest.h" |
| 24 | 24 |
| 25 using ::testing::_; | 25 using ::testing::_; |
| 26 using ::testing::DeleteArg; | 26 using ::testing::DeleteArg; |
| 27 using ::testing::DoAll; | 27 using ::testing::DoAll; |
| 28 using ::testing::Return; | 28 using ::testing::Return; |
| 29 | 29 |
| 30 using content::BrowserThread; | 30 using content::BrowserThread; |
| 31 using content::BrowserThreadImpl; | 31 using content::BrowserThreadImpl; |
| 32 | 32 |
| 33 const int kProcessId = 5; | 33 const int kProcessId = 5; |
| 34 const int kRenderId = 6; | 34 const int kRenderId = 6; |
| 35 const int kPageRequestId = 7; | 35 const int kPageRequestId = 7; |
| 36 | 36 |
| 37 namespace media_stream { | 37 namespace media_stream { |
| 38 | 38 |
| 39 class MockMediaStreamDispatcherHost : public MediaStreamDispatcherHost, | 39 class MockMediaStreamDispatcherHost : public MediaStreamDispatcherHost, |
| 40 public content::MockContentBrowserClient { | 40 public content::TestContentBrowserClient { |
| 41 public: | 41 public: |
| 42 MockMediaStreamDispatcherHost(content::ResourceContext* resource_context, | 42 MockMediaStreamDispatcherHost(content::ResourceContext* resource_context, |
| 43 MessageLoop* message_loop, | 43 MessageLoop* message_loop, |
| 44 media::AudioManager* audio_manager) | 44 media::AudioManager* audio_manager) |
| 45 : MediaStreamDispatcherHost(resource_context, kProcessId, audio_manager), | 45 : MediaStreamDispatcherHost(resource_context, kProcessId, audio_manager), |
| 46 message_loop_(message_loop) {} | 46 message_loop_(message_loop) {} |
| 47 | 47 |
| 48 // A list of mock methods. | 48 // A list of mock methods. |
| 49 MOCK_METHOD4(OnStreamGenerated, | 49 MOCK_METHOD4(OnStreamGenerated, |
| 50 void(int routing_id, int request_id, int audio_array_size, | 50 void(int routing_id, int request_id, int audio_array_size, |
| (...skipping 121 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 172 &resource_context_, audio_manager_.get())->UseFakeDevice(); | 172 &resource_context_, audio_manager_.get())->UseFakeDevice(); |
| 173 | 173 |
| 174 host_ = new MockMediaStreamDispatcherHost( | 174 host_ = new MockMediaStreamDispatcherHost( |
| 175 &resource_context_, message_loop_.get(), audio_manager_.get()); | 175 &resource_context_, message_loop_.get(), audio_manager_.get()); |
| 176 | 176 |
| 177 // Use the fake content client and browser. | 177 // Use the fake content client and browser. |
| 178 old_client_ = content::GetContentClient(); | 178 old_client_ = content::GetContentClient(); |
| 179 old_browser_client_ = content::GetContentClient()->browser(); | 179 old_browser_client_ = content::GetContentClient()->browser(); |
| 180 content_client_.reset(new TestContentClient); | 180 content_client_.reset(new TestContentClient); |
| 181 content::SetContentClient(content_client_.get()); | 181 content::SetContentClient(content_client_.get()); |
| 182 content_client_->set_browser(host_); | 182 content_client_->set_browser_for_testing(host_); |
| 183 } | 183 } |
| 184 | 184 |
| 185 virtual void TearDown() { | 185 virtual void TearDown() { |
| 186 // Needed to make sure the manager finishes all tasks on its own thread. | 186 // Needed to make sure the manager finishes all tasks on its own thread. |
| 187 SyncWithVideoCaptureManagerThread(); | 187 SyncWithVideoCaptureManagerThread(); |
| 188 | 188 |
| 189 // Recover the old browser client and content client. | 189 // Recover the old browser client and content client. |
| 190 content::GetContentClient()->set_browser(old_browser_client_); | 190 content::GetContentClient()->set_browser_for_testing(old_browser_client_); |
| 191 content::SetContentClient(old_client_); | 191 content::SetContentClient(old_client_); |
| 192 content_client_.reset(); | 192 content_client_.reset(); |
| 193 } | 193 } |
| 194 | 194 |
| 195 // Called on the VideoCaptureManager thread. | 195 // Called on the VideoCaptureManager thread. |
| 196 static void PostQuitMessageLoop(MessageLoop* message_loop) { | 196 static void PostQuitMessageLoop(MessageLoop* message_loop) { |
| 197 message_loop->PostTask(FROM_HERE, MessageLoop::QuitClosure()); | 197 message_loop->PostTask(FROM_HERE, MessageLoop::QuitClosure()); |
| 198 } | 198 } |
| 199 | 199 |
| 200 // Called on the main thread. | 200 // Called on the main thread. |
| (...skipping 152 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 353 EXPECT_EQ(host_->video_devices_.size(), 0u); | 353 EXPECT_EQ(host_->video_devices_.size(), 0u); |
| 354 EXPECT_EQ(host_->NumberOfStreams(), 1u); | 354 EXPECT_EQ(host_->NumberOfStreams(), 1u); |
| 355 | 355 |
| 356 // TODO(perkj): test audio device failure? | 356 // TODO(perkj): test audio device failure? |
| 357 | 357 |
| 358 host_->OnStopGeneratedStream(label); | 358 host_->OnStopGeneratedStream(label); |
| 359 EXPECT_EQ(host_->NumberOfStreams(), 0u); | 359 EXPECT_EQ(host_->NumberOfStreams(), 0u); |
| 360 } | 360 } |
| 361 | 361 |
| 362 }; // namespace media_stream | 362 }; // namespace media_stream |
| OLD | NEW |