| OLD | NEW |
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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 <stdint.h> | 5 #include <stdint.h> |
| 6 | 6 |
| 7 #include <memory> | 7 #include <memory> |
| 8 #include <utility> | 8 #include <utility> |
| 9 | 9 |
| 10 #include "base/bind.h" | 10 #include "base/bind.h" |
| 11 #include "base/callback.h" | 11 #include "base/callback.h" |
| 12 #include "base/macros.h" | 12 #include "base/macros.h" |
| 13 #include "base/run_loop.h" | 13 #include "base/run_loop.h" |
| 14 #include "media/base/cdm_config.h" | 14 #include "media/base/cdm_config.h" |
| 15 #include "media/base/mock_filters.h" | 15 #include "media/base/mock_filters.h" |
| 16 #include "media/base/test_helpers.h" | 16 #include "media/base/test_helpers.h" |
| 17 #include "media/mojo/clients/mojo_demuxer_stream_impl.h" | 17 #include "media/mojo/clients/mojo_demuxer_stream_impl.h" |
| 18 #include "media/mojo/common/media_type_converters.h" | 18 #include "media/mojo/common/media_type_converters.h" |
| 19 #include "media/mojo/interfaces/content_decryption_module.mojom.h" | 19 #include "media/mojo/interfaces/content_decryption_module.mojom.h" |
| 20 #include "media/mojo/interfaces/decryptor.mojom.h" | 20 #include "media/mojo/interfaces/decryptor.mojom.h" |
| 21 #include "media/mojo/interfaces/interface_factory.mojom.h" | 21 #include "media/mojo/interfaces/interface_factory.mojom.h" |
| 22 #include "media/mojo/interfaces/media_service.mojom.h" |
| 22 #include "media/mojo/interfaces/renderer.mojom.h" | 23 #include "media/mojo/interfaces/renderer.mojom.h" |
| 23 #include "mojo/public/cpp/bindings/associated_binding.h" | 24 #include "mojo/public/cpp/bindings/associated_binding.h" |
| 25 #include "mojo/public/cpp/bindings/interface_request.h" |
| 26 #include "services/service_manager/public/cpp/interface_registry.h" |
| 24 #include "services/service_manager/public/cpp/service_test.h" | 27 #include "services/service_manager/public/cpp/service_test.h" |
| 25 #include "testing/gmock/include/gmock/gmock.h" | 28 #include "testing/gmock/include/gmock/gmock.h" |
| 26 | 29 |
| 27 using testing::Exactly; | 30 using testing::Exactly; |
| 28 using testing::Invoke; | 31 using testing::Invoke; |
| 29 using testing::InvokeWithoutArgs; | 32 using testing::InvokeWithoutArgs; |
| 30 using testing::StrictMock; | 33 using testing::StrictMock; |
| 31 | 34 |
| 32 namespace media { | 35 namespace media { |
| 33 namespace { | 36 namespace { |
| (...skipping 24 matching lines...) Expand all Loading... |
| 58 MOCK_METHOD0(OnWaitingForDecryptionKey, void()); | 61 MOCK_METHOD0(OnWaitingForDecryptionKey, void()); |
| 59 MOCK_METHOD1(OnDurationChange, void(base::TimeDelta duration)); | 62 MOCK_METHOD1(OnDurationChange, void(base::TimeDelta duration)); |
| 60 | 63 |
| 61 private: | 64 private: |
| 62 DISALLOW_COPY_AND_ASSIGN(MockRendererClient); | 65 DISALLOW_COPY_AND_ASSIGN(MockRendererClient); |
| 63 }; | 66 }; |
| 64 | 67 |
| 65 class MediaServiceTest : public service_manager::test::ServiceTest { | 68 class MediaServiceTest : public service_manager::test::ServiceTest { |
| 66 public: | 69 public: |
| 67 MediaServiceTest() | 70 MediaServiceTest() |
| 68 : ServiceTest("media_mojo_unittests"), | 71 : ServiceTest("media_mojo_shell_unittests"), |
| 69 renderer_client_binding_(&renderer_client_), | 72 renderer_client_binding_(&renderer_client_), |
| 70 video_stream_(DemuxerStream::VIDEO) {} | 73 video_stream_(DemuxerStream::VIDEO) {} |
| 71 ~MediaServiceTest() override {} | 74 ~MediaServiceTest() override {} |
| 72 | 75 |
| 73 void SetUp() override { | 76 void SetUp() override { |
| 74 ServiceTest::SetUp(); | 77 ServiceTest::SetUp(); |
| 75 | 78 |
| 76 connection_ = connector()->Connect("media"); | 79 connection_ = connector()->Connect("media"); |
| 77 connection_->SetConnectionLostClosure(base::Bind( | 80 media::mojom::MediaServicePtr media_service; |
| 78 &MediaServiceTest::ConnectionClosed, base::Unretained(this))); | 81 connection_->GetInterface(&media_service); |
| 79 | 82 |
| 80 connection_->GetInterface(&interface_factory_); | 83 auto registry = |
| 84 base::MakeUnique<service_manager::InterfaceRegistry>(std::string()); |
| 85 service_manager::mojom::InterfaceProviderPtr interfaces; |
| 86 registry->Bind(GetProxy(&interfaces), service_manager::Identity(), |
| 87 service_manager::InterfaceProviderSpec(), |
| 88 service_manager::Identity(), |
| 89 service_manager::InterfaceProviderSpec()); |
| 90 |
| 91 media_service->CreateInterfaceFactory(mojo::GetProxy(&interface_factory_), |
| 92 std::move(interfaces)); |
| 81 | 93 |
| 82 run_loop_.reset(new base::RunLoop()); | 94 run_loop_.reset(new base::RunLoop()); |
| 83 } | 95 } |
| 84 | 96 |
| 85 // MOCK_METHOD* doesn't support move only types. Work around this by having | 97 // MOCK_METHOD* doesn't support move only types. Work around this by having |
| 86 // an extra method. | 98 // an extra method. |
| 87 MOCK_METHOD2(OnCdmInitializedInternal, void(bool result, int cdm_id)); | 99 MOCK_METHOD2(OnCdmInitializedInternal, void(bool result, int cdm_id)); |
| 88 void OnCdmInitialized(mojom::CdmPromiseResultPtr result, | 100 void OnCdmInitialized(mojom::CdmPromiseResultPtr result, |
| 89 int cdm_id, | 101 int cdm_id, |
| 90 mojom::DecryptorPtr decryptor) { | 102 mojom::DecryptorPtr decryptor) { |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 128 renderer_->Initialize(std::move(client_ptr_info), nullptr, | 140 renderer_->Initialize(std::move(client_ptr_info), nullptr, |
| 129 std::move(video_stream_proxy), base::nullopt, | 141 std::move(video_stream_proxy), base::nullopt, |
| 130 base::nullopt, | 142 base::nullopt, |
| 131 base::Bind(&MediaServiceTest::OnRendererInitialized, | 143 base::Bind(&MediaServiceTest::OnRendererInitialized, |
| 132 base::Unretained(this))); | 144 base::Unretained(this))); |
| 133 } | 145 } |
| 134 | 146 |
| 135 MOCK_METHOD0(ConnectionClosed, void()); | 147 MOCK_METHOD0(ConnectionClosed, void()); |
| 136 | 148 |
| 137 protected: | 149 protected: |
| 150 std::unique_ptr<service_manager::Connection> connection_; |
| 138 std::unique_ptr<base::RunLoop> run_loop_; | 151 std::unique_ptr<base::RunLoop> run_loop_; |
| 139 | 152 |
| 140 mojom::InterfaceFactoryPtr interface_factory_; | 153 mojom::InterfaceFactoryPtr interface_factory_; |
| 141 mojom::ContentDecryptionModulePtr cdm_; | 154 mojom::ContentDecryptionModulePtr cdm_; |
| 142 mojom::RendererPtr renderer_; | 155 mojom::RendererPtr renderer_; |
| 143 | 156 |
| 144 StrictMock<MockRendererClient> renderer_client_; | 157 StrictMock<MockRendererClient> renderer_client_; |
| 145 mojo::AssociatedBinding<mojom::RendererClient> renderer_client_binding_; | 158 mojo::AssociatedBinding<mojom::RendererClient> renderer_client_binding_; |
| 146 | 159 |
| 147 StrictMock<MockDemuxerStream> video_stream_; | 160 StrictMock<MockDemuxerStream> video_stream_; |
| 148 std::unique_ptr<MojoDemuxerStreamImpl> mojo_video_stream_; | 161 std::unique_ptr<MojoDemuxerStreamImpl> mojo_video_stream_; |
| 149 | 162 |
| 150 private: | 163 private: |
| 151 std::unique_ptr<service_manager::Connection> connection_; | |
| 152 | |
| 153 DISALLOW_COPY_AND_ASSIGN(MediaServiceTest); | 164 DISALLOW_COPY_AND_ASSIGN(MediaServiceTest); |
| 154 }; | 165 }; |
| 155 | 166 |
| 156 } // namespace | 167 } // namespace |
| 157 | 168 |
| 158 // Note: base::RunLoop::RunUntilIdle() does not work well in these tests because | 169 // Note: base::RunLoop::RunUntilIdle() does not work well in these tests because |
| 159 // even when the loop is idle, we may still have pending events in the pipe. | 170 // even when the loop is idle, we may still have pending events in the pipe. |
| 160 | 171 |
| 161 #if defined(ENABLE_MOJO_CDM) | 172 #if defined(ENABLE_MOJO_CDM) |
| 162 TEST_F(MediaServiceTest, InitializeCdm_Success) { | 173 TEST_F(MediaServiceTest, InitializeCdm_Success) { |
| (...skipping 20 matching lines...) Expand all Loading... |
| 183 run_loop_->Run(); | 194 run_loop_->Run(); |
| 184 } | 195 } |
| 185 | 196 |
| 186 TEST_F(MediaServiceTest, InitializeRenderer_InvalidConfig) { | 197 TEST_F(MediaServiceTest, InitializeRenderer_InvalidConfig) { |
| 187 InitializeRenderer(TestVideoConfig::Invalid(), false); | 198 InitializeRenderer(TestVideoConfig::Invalid(), false); |
| 188 run_loop_->Run(); | 199 run_loop_->Run(); |
| 189 } | 200 } |
| 190 #endif // defined(ENABLE_MOJO_RENDERER) | 201 #endif // defined(ENABLE_MOJO_RENDERER) |
| 191 | 202 |
| 192 TEST_F(MediaServiceTest, Lifetime) { | 203 TEST_F(MediaServiceTest, Lifetime) { |
| 204 connection_->SetConnectionLostClosure( |
| 205 base::Bind(&MediaServiceTest::ConnectionClosed, base::Unretained(this))); |
| 206 |
| 193 // Disconnecting CDM and Renderer services doesn't terminate the app. | 207 // Disconnecting CDM and Renderer services doesn't terminate the app. |
| 194 cdm_.reset(); | 208 cdm_.reset(); |
| 195 renderer_.reset(); | 209 renderer_.reset(); |
| 196 | 210 |
| 197 // Disconnecting InterfaceFactory service should terminate the app, which will | 211 // Disconnecting InterfaceFactory service should terminate the app, which will |
| 198 // close the connection. | 212 // close the connection. |
| 199 EXPECT_CALL(*this, ConnectionClosed()) | 213 EXPECT_CALL(*this, ConnectionClosed()) |
| 200 .Times(Exactly(1)) | 214 .Times(Exactly(1)) |
| 201 .WillOnce(Invoke(run_loop_.get(), &base::RunLoop::Quit)); | 215 .WillOnce(Invoke(run_loop_.get(), &base::RunLoop::Quit)); |
| 202 interface_factory_.reset(); | 216 interface_factory_.reset(); |
| 203 | 217 |
| 204 run_loop_->Run(); | 218 run_loop_->Run(); |
| 205 } | 219 } |
| 206 | 220 |
| 207 } // namespace media | 221 } // namespace media |
| OLD | NEW |