| 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 "content/browser/renderer_host/media/video_capture_host.h" | 5 #include "content/browser/renderer_host/media/video_capture_host.h" |
| 6 | 6 |
| 7 #include <stdint.h> | 7 #include <stdint.h> |
| 8 | 8 |
| 9 #include <map> | 9 #include <map> |
| 10 #include <memory> | 10 #include <memory> |
| 11 #include <string> | 11 #include <string> |
| 12 | 12 |
| 13 #include "base/bind.h" | 13 #include "base/bind.h" |
| 14 #include "base/command_line.h" | 14 #include "base/command_line.h" |
| 15 #include "base/location.h" | 15 #include "base/location.h" |
| 16 #include "base/macros.h" | 16 #include "base/macros.h" |
| 17 #include "base/memory/ptr_util.h" | 17 #include "base/memory/ptr_util.h" |
| 18 #include "base/run_loop.h" | 18 #include "base/run_loop.h" |
| 19 #include "base/single_thread_task_runner.h" | 19 #include "base/single_thread_task_runner.h" |
| 20 #include "base/threading/thread_task_runner_handle.h" | 20 #include "base/threading/thread_task_runner_handle.h" |
| 21 #include "build/build_config.h" | 21 #include "build/build_config.h" |
| 22 #include "content/browser/browser_thread_impl.h" | 22 #include "content/browser/browser_thread_impl.h" |
| 23 #include "content/browser/renderer_host/media/media_stream_manager.h" | 23 #include "content/browser/renderer_host/media/media_stream_manager.h" |
| 24 #include "content/browser/renderer_host/media/media_stream_requester.h" | 24 #include "content/browser/renderer_host/media/media_stream_requester.h" |
| 25 #include "content/browser/renderer_host/media/video_capture_manager.h" | 25 #include "content/browser/renderer_host/media/video_capture_manager.h" |
| 26 #include "content/common/media/video_capture_messages.h" | |
| 27 #include "content/public/common/content_switches.h" | 26 #include "content/public/common/content_switches.h" |
| 28 #include "content/public/test/mock_resource_context.h" | 27 #include "content/public/test/mock_resource_context.h" |
| 29 #include "content/public/test/test_browser_context.h" | 28 #include "content/public/test/test_browser_context.h" |
| 30 #include "content/public/test/test_browser_thread_bundle.h" | 29 #include "content/public/test/test_browser_thread_bundle.h" |
| 31 #include "content/test/test_content_browser_client.h" | 30 #include "content/test/test_content_browser_client.h" |
| 32 #include "media/audio/mock_audio_manager.h" | 31 #include "media/audio/mock_audio_manager.h" |
| 33 #include "media/base/media_switches.h" | 32 #include "media/base/media_switches.h" |
| 34 #include "media/base/video_capture_types.h" | 33 #include "media/base/video_capture_types.h" |
| 34 #include "mojo/public/cpp/bindings/binding.h" |
| 35 #include "net/url_request/url_request_context.h" | 35 #include "net/url_request/url_request_context.h" |
| 36 #include "testing/gmock/include/gmock/gmock.h" | 36 #include "testing/gmock/include/gmock/gmock.h" |
| 37 #include "testing/gtest/include/gtest/gtest.h" | 37 #include "testing/gtest/include/gtest/gtest.h" |
| 38 | 38 |
| 39 using ::testing::_; | 39 using ::testing::_; |
| 40 using ::testing::AnyNumber; | 40 using ::testing::AnyNumber; |
| 41 using ::testing::DoAll; | 41 using ::testing::DoAll; |
| 42 using ::testing::InSequence; | 42 using ::testing::InSequence; |
| 43 using ::testing::Mock; | 43 using ::testing::Mock; |
| 44 using ::testing::Return; | 44 using ::testing::Return; |
| (...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 105 void SetUp() override { | 105 void SetUp() override { |
| 106 SetBrowserClientForTesting(&browser_client_); | 106 SetBrowserClientForTesting(&browser_client_); |
| 107 | 107 |
| 108 base::CommandLine::ForCurrentProcess()->AppendSwitch( | 108 base::CommandLine::ForCurrentProcess()->AppendSwitch( |
| 109 switches::kUseFakeDeviceForMediaStream); | 109 switches::kUseFakeDeviceForMediaStream); |
| 110 base::CommandLine::ForCurrentProcess()->AppendSwitch( | 110 base::CommandLine::ForCurrentProcess()->AppendSwitch( |
| 111 switches::kUseFakeUIForMediaStream); | 111 switches::kUseFakeUIForMediaStream); |
| 112 media_stream_manager_.reset(new MediaStreamManager(audio_manager_.get())); | 112 media_stream_manager_.reset(new MediaStreamManager(audio_manager_.get())); |
| 113 | 113 |
| 114 // Create a Host and connect it to a simulated IPC channel. | 114 // Create a Host and connect it to a simulated IPC channel. |
| 115 host_ = new VideoCaptureHost(media_stream_manager_.get()); | 115 host_.reset(new VideoCaptureHost(media_stream_manager_.get())); |
| 116 host_->OnChannelConnected(base::GetCurrentProcId()); | |
| 117 | 116 |
| 118 OpenSession(); | 117 OpenSession(); |
| 119 } | 118 } |
| 120 | 119 |
| 121 void TearDown() override { | 120 void TearDown() override { |
| 122 Mock::VerifyAndClearExpectations(host_.get()); | 121 Mock::VerifyAndClearExpectations(host_.get()); |
| 123 EXPECT_TRUE(host_->controllers_.empty()); | 122 EXPECT_TRUE(host_->controllers_.empty()); |
| 124 | 123 |
| 125 CloseSession(); | 124 CloseSession(); |
| 126 | 125 |
| 127 // Simulate closing the IPC sender. | |
| 128 host_->OnChannelClosing(); | |
| 129 | |
| 130 // Release the reference to the mock object. The object will be destructed | 126 // Release the reference to the mock object. The object will be destructed |
| 131 // on the current message loop. | 127 // on the current message loop. |
| 132 host_ = nullptr; | 128 host_ = nullptr; |
| 133 } | 129 } |
| 134 | 130 |
| 135 void OpenSession() { | 131 void OpenSession() { |
| 136 const int render_process_id = 1; | 132 const int render_process_id = 1; |
| 137 const int render_frame_id = 1; | 133 const int render_frame_id = 1; |
| 138 const int page_request_id = 1; | 134 const int page_request_id = 1; |
| 139 const url::Origin security_origin(GURL("http://test.com")); | 135 const url::Origin security_origin(GURL("http://test.com")); |
| (...skipping 165 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 305 const content::TestBrowserThreadBundle thread_bundle_; | 301 const content::TestBrowserThreadBundle thread_bundle_; |
| 306 // |audio_manager_| needs to outlive |thread_bundle_| because it uses the | 302 // |audio_manager_| needs to outlive |thread_bundle_| because it uses the |
| 307 // underlying message loop. | 303 // underlying message loop. |
| 308 media::ScopedAudioManagerPtr audio_manager_; | 304 media::ScopedAudioManagerPtr audio_manager_; |
| 309 content::TestBrowserContext browser_context_; | 305 content::TestBrowserContext browser_context_; |
| 310 content::TestContentBrowserClient browser_client_; | 306 content::TestContentBrowserClient browser_client_; |
| 311 const scoped_refptr<base::SingleThreadTaskRunner> task_runner_; | 307 const scoped_refptr<base::SingleThreadTaskRunner> task_runner_; |
| 312 int opened_session_id_; | 308 int opened_session_id_; |
| 313 std::string opened_device_label_; | 309 std::string opened_device_label_; |
| 314 | 310 |
| 315 scoped_refptr<VideoCaptureHost> host_; | 311 std::unique_ptr<VideoCaptureHost> host_; |
| 316 mojo::Binding<mojom::VideoCaptureObserver> observer_binding_; | 312 mojo::Binding<mojom::VideoCaptureObserver> observer_binding_; |
| 317 | 313 |
| 318 DISALLOW_COPY_AND_ASSIGN(VideoCaptureHostTest); | 314 DISALLOW_COPY_AND_ASSIGN(VideoCaptureHostTest); |
| 319 }; | 315 }; |
| 320 | 316 |
| 321 // Construct and destruct all objects. This is a non trivial sequence. | 317 // Construct and destruct all objects. This is a non trivial sequence. |
| 322 TEST_F(VideoCaptureHostTest, ConstructAndDestruct) {} | 318 TEST_F(VideoCaptureHostTest, ConstructAndDestruct) {} |
| 323 | 319 |
| 324 TEST_F(VideoCaptureHostTest, StartAndImmediateStop) { | 320 TEST_F(VideoCaptureHostTest, StartAndImmediateStop) { |
| 325 StartAndImmediateStopCapture(); | 321 StartAndImmediateStopCapture(); |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 357 StartCapture(); | 353 StartCapture(); |
| 358 | 354 |
| 359 // When the session is closed via the stream without stopping capture, the | 355 // When the session is closed via the stream without stopping capture, the |
| 360 // ENDED event is sent. | 356 // ENDED event is sent. |
| 361 EXPECT_CALL(*this, OnStateChanged(mojom::VideoCaptureState::ENDED)); | 357 EXPECT_CALL(*this, OnStateChanged(mojom::VideoCaptureState::ENDED)); |
| 362 CloseSession(); | 358 CloseSession(); |
| 363 base::RunLoop().RunUntilIdle(); | 359 base::RunLoop().RunUntilIdle(); |
| 364 } | 360 } |
| 365 | 361 |
| 366 } // namespace content | 362 } // namespace content |
| OLD | NEW |