| 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" |
| (...skipping 22 matching lines...) Expand all Loading... |
| 33 | 33 |
| 34 namespace media_stream { | 34 namespace media_stream { |
| 35 | 35 |
| 36 class MockMediaStreamDispatcherHost : public MediaStreamDispatcherHost { | 36 class MockMediaStreamDispatcherHost : public MediaStreamDispatcherHost { |
| 37 public: | 37 public: |
| 38 MockMediaStreamDispatcherHost(content::ResourceContext* resource_context, | 38 MockMediaStreamDispatcherHost(content::ResourceContext* resource_context, |
| 39 MessageLoop* message_loop, | 39 MessageLoop* message_loop, |
| 40 media::AudioManager* audio_manager) | 40 media::AudioManager* audio_manager) |
| 41 : MediaStreamDispatcherHost(resource_context, kProcessId, audio_manager), | 41 : MediaStreamDispatcherHost(resource_context, kProcessId, audio_manager), |
| 42 message_loop_(message_loop) {} | 42 message_loop_(message_loop) {} |
| 43 virtual ~MockMediaStreamDispatcherHost() {} | |
| 44 | 43 |
| 45 // A list of mock methods. | 44 // A list of mock methods. |
| 46 MOCK_METHOD4(OnStreamGenerated, | 45 MOCK_METHOD4(OnStreamGenerated, |
| 47 void(int routing_id, int request_id, int audio_array_size, | 46 void(int routing_id, int request_id, int audio_array_size, |
| 48 int video_array_size)); | 47 int video_array_size)); |
| 49 MOCK_METHOD2(OnStreamGenerationFailed, void(int routing_id, int request_id)); | 48 MOCK_METHOD2(OnStreamGenerationFailed, void(int routing_id, int request_id)); |
| 50 MOCK_METHOD2(OnAudioDeviceFailed, void(int routing_id, int index)); | 49 MOCK_METHOD2(OnAudioDeviceFailed, void(int routing_id, int index)); |
| 51 MOCK_METHOD2(OnVideoDeviceFailed, void(int routing_id, int index)); | 50 MOCK_METHOD2(OnVideoDeviceFailed, void(int routing_id, int index)); |
| 52 | 51 |
| 53 // Accessor to private functions. | 52 // Accessor to private functions. |
| (...skipping 10 matching lines...) Expand all Loading... |
| 64 // Return the number of streams that have been opened or is being open. | 63 // Return the number of streams that have been opened or is being open. |
| 65 size_t NumberOfStreams() { | 64 size_t NumberOfStreams() { |
| 66 return streams_.size(); | 65 return streams_.size(); |
| 67 } | 66 } |
| 68 | 67 |
| 69 std::string label_; | 68 std::string label_; |
| 70 StreamDeviceInfoArray audio_devices_; | 69 StreamDeviceInfoArray audio_devices_; |
| 71 StreamDeviceInfoArray video_devices_; | 70 StreamDeviceInfoArray video_devices_; |
| 72 | 71 |
| 73 private: | 72 private: |
| 73 virtual ~MockMediaStreamDispatcherHost() {} |
| 74 |
| 74 // This method is used to dispatch IPC messages to the renderer. We intercept | 75 // This method is used to dispatch IPC messages to the renderer. We intercept |
| 75 // these messages here and dispatch to our mock methods to verify the | 76 // these messages here and dispatch to our mock methods to verify the |
| 76 // conversation between this object and the renderer. | 77 // conversation between this object and the renderer. |
| 77 virtual bool Send(IPC::Message* message) { | 78 virtual bool Send(IPC::Message* message) { |
| 78 CHECK(message); | 79 CHECK(message); |
| 79 | 80 |
| 80 // In this method we dispatch the messages to the according handlers as if | 81 // In this method we dispatch the messages to the according handlers as if |
| 81 // we are the renderer. | 82 // we are the renderer. |
| 82 bool handled = true; | 83 bool handled = true; |
| 83 IPC_BEGIN_MESSAGE_MAP(MockMediaStreamDispatcherHost, *message) | 84 IPC_BEGIN_MESSAGE_MAP(MockMediaStreamDispatcherHost, *message) |
| (...skipping 223 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 307 EXPECT_EQ(host_->video_devices_.size(), 0u); | 308 EXPECT_EQ(host_->video_devices_.size(), 0u); |
| 308 EXPECT_EQ(host_->NumberOfStreams(), 1u); | 309 EXPECT_EQ(host_->NumberOfStreams(), 1u); |
| 309 | 310 |
| 310 // TODO(perkj): test audio device failure? | 311 // TODO(perkj): test audio device failure? |
| 311 | 312 |
| 312 host_->OnStopGeneratedStream(label); | 313 host_->OnStopGeneratedStream(label); |
| 313 EXPECT_EQ(host_->NumberOfStreams(), 0u); | 314 EXPECT_EQ(host_->NumberOfStreams(), 0u); |
| 314 } | 315 } |
| 315 | 316 |
| 316 }; // namespace media_stream | 317 }; // namespace media_stream |
| OLD | NEW |