| 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 #include <utility> | 6 #include <utility> |
| 7 | 7 |
| 8 #include "base/bind.h" | 8 #include "base/bind.h" |
| 9 #include "base/callback.h" | 9 #include "base/callback.h" |
| 10 #include "base/macros.h" | 10 #include "base/macros.h" |
| (...skipping 13 matching lines...) Expand all Loading... |
| 24 #include "testing/gmock/include/gmock/gmock.h" | 24 #include "testing/gmock/include/gmock/gmock.h" |
| 25 | 25 |
| 26 using testing::Exactly; | 26 using testing::Exactly; |
| 27 using testing::Invoke; | 27 using testing::Invoke; |
| 28 using testing::InvokeWithoutArgs; | 28 using testing::InvokeWithoutArgs; |
| 29 using testing::StrictMock; | 29 using testing::StrictMock; |
| 30 | 30 |
| 31 namespace media { | 31 namespace media { |
| 32 namespace { | 32 namespace { |
| 33 | 33 |
| 34 #if defined(ENABLE_MOJO_CDM) |
| 34 const char kInvalidKeySystem[] = "invalid.key.system"; | 35 const char kInvalidKeySystem[] = "invalid.key.system"; |
| 36 #endif |
| 35 const char kSecurityOrigin[] = "http://foo.com"; | 37 const char kSecurityOrigin[] = "http://foo.com"; |
| 36 | 38 |
| 37 class MockRendererClient : public interfaces::RendererClient { | 39 class MockRendererClient : public interfaces::RendererClient { |
| 38 public: | 40 public: |
| 39 MockRendererClient(){}; | 41 MockRendererClient(){}; |
| 40 ~MockRendererClient() override{}; | 42 ~MockRendererClient() override{}; |
| 41 | 43 |
| 42 // interfaces::RendererClient implementation. | 44 // interfaces::RendererClient implementation. |
| 43 MOCK_METHOD2(OnTimeUpdate, void(int64_t time_usec, int64_t max_time_usec)); | 45 MOCK_METHOD2(OnTimeUpdate, void(int64_t time_usec, int64_t max_time_usec)); |
| 44 MOCK_METHOD1(OnBufferingStateChange, void(interfaces::BufferingState state)); | 46 MOCK_METHOD1(OnBufferingStateChange, void(interfaces::BufferingState state)); |
| (...skipping 12 matching lines...) Expand all Loading... |
| 57 ~MediaAppTest() override {} | 59 ~MediaAppTest() override {} |
| 58 | 60 |
| 59 void SetUp() override { | 61 void SetUp() override { |
| 60 ApplicationTestBase::SetUp(); | 62 ApplicationTestBase::SetUp(); |
| 61 | 63 |
| 62 connection_ = connector()->Connect("mojo:media"); | 64 connection_ = connector()->Connect("mojo:media"); |
| 63 connection_->SetConnectionLostClosure( | 65 connection_->SetConnectionLostClosure( |
| 64 base::Bind(&MediaAppTest::ConnectionClosed, base::Unretained(this))); | 66 base::Bind(&MediaAppTest::ConnectionClosed, base::Unretained(this))); |
| 65 | 67 |
| 66 connection_->GetInterface(&service_factory_); | 68 connection_->GetInterface(&service_factory_); |
| 67 service_factory_->CreateCdm(mojo::GetProxy(&cdm_)); | |
| 68 service_factory_->CreateRenderer(mojo::GetProxy(&renderer_)); | |
| 69 | 69 |
| 70 run_loop_.reset(new base::RunLoop()); | 70 run_loop_.reset(new base::RunLoop()); |
| 71 } | 71 } |
| 72 | 72 |
| 73 // MOCK_METHOD* doesn't support move only types. Work around this by having | 73 // MOCK_METHOD* doesn't support move only types. Work around this by having |
| 74 // an extra method. | 74 // an extra method. |
| 75 MOCK_METHOD2(OnCdmInitializedInternal, void(bool result, int cdm_id)); | 75 MOCK_METHOD2(OnCdmInitializedInternal, void(bool result, int cdm_id)); |
| 76 void OnCdmInitialized(interfaces::CdmPromiseResultPtr result, | 76 void OnCdmInitialized(interfaces::CdmPromiseResultPtr result, |
| 77 int cdm_id, | 77 int cdm_id, |
| 78 interfaces::DecryptorPtr decryptor) { | 78 interfaces::DecryptorPtr decryptor) { |
| 79 OnCdmInitializedInternal(result->success, cdm_id); | 79 OnCdmInitializedInternal(result->success, cdm_id); |
| 80 } | 80 } |
| 81 | 81 |
| 82 void InitializeCdm(const std::string& key_system, | 82 void InitializeCdm(const std::string& key_system, |
| 83 bool expected_result, | 83 bool expected_result, |
| 84 int cdm_id) { | 84 int cdm_id) { |
| 85 service_factory_->CreateCdm(mojo::GetProxy(&cdm_)); |
| 86 |
| 85 EXPECT_CALL(*this, OnCdmInitializedInternal(expected_result, cdm_id)) | 87 EXPECT_CALL(*this, OnCdmInitializedInternal(expected_result, cdm_id)) |
| 86 .Times(Exactly(1)) | 88 .Times(Exactly(1)) |
| 87 .WillOnce(InvokeWithoutArgs(run_loop_.get(), &base::RunLoop::Quit)); | 89 .WillOnce(InvokeWithoutArgs(run_loop_.get(), &base::RunLoop::Quit)); |
| 88 cdm_->Initialize( | 90 cdm_->Initialize( |
| 89 key_system, kSecurityOrigin, interfaces::CdmConfig::From(CdmConfig()), | 91 key_system, kSecurityOrigin, interfaces::CdmConfig::From(CdmConfig()), |
| 90 base::Bind(&MediaAppTest::OnCdmInitialized, base::Unretained(this))); | 92 base::Bind(&MediaAppTest::OnCdmInitialized, base::Unretained(this))); |
| 91 } | 93 } |
| 92 | 94 |
| 93 MOCK_METHOD1(OnRendererInitialized, void(bool)); | 95 MOCK_METHOD1(OnRendererInitialized, void(bool)); |
| 94 | 96 |
| 95 void InitializeRenderer(const VideoDecoderConfig& video_config, | 97 void InitializeRenderer(const VideoDecoderConfig& video_config, |
| 96 bool expected_result) { | 98 bool expected_result) { |
| 99 service_factory_->CreateRenderer(mojo::GetProxy(&renderer_)); |
| 100 |
| 97 video_demuxer_stream_.set_video_decoder_config(video_config); | 101 video_demuxer_stream_.set_video_decoder_config(video_config); |
| 98 | 102 |
| 99 interfaces::DemuxerStreamPtr video_stream; | 103 interfaces::DemuxerStreamPtr video_stream; |
| 100 new MojoDemuxerStreamImpl(&video_demuxer_stream_, GetProxy(&video_stream)); | 104 new MojoDemuxerStreamImpl(&video_demuxer_stream_, GetProxy(&video_stream)); |
| 101 | 105 |
| 102 EXPECT_CALL(*this, OnRendererInitialized(expected_result)) | 106 EXPECT_CALL(*this, OnRendererInitialized(expected_result)) |
| 103 .Times(Exactly(1)) | 107 .Times(Exactly(1)) |
| 104 .WillOnce(InvokeWithoutArgs(run_loop_.get(), &base::RunLoop::Quit)); | 108 .WillOnce(InvokeWithoutArgs(run_loop_.get(), &base::RunLoop::Quit)); |
| 105 renderer_->Initialize(renderer_client_binding_.CreateInterfacePtrAndBind(), | 109 renderer_->Initialize(renderer_client_binding_.CreateInterfacePtrAndBind(), |
| 106 nullptr, std::move(video_stream), | 110 nullptr, std::move(video_stream), |
| (...skipping 19 matching lines...) Expand all Loading... |
| 126 scoped_ptr<mojo::Connection> connection_; | 130 scoped_ptr<mojo::Connection> connection_; |
| 127 | 131 |
| 128 DISALLOW_COPY_AND_ASSIGN(MediaAppTest); | 132 DISALLOW_COPY_AND_ASSIGN(MediaAppTest); |
| 129 }; | 133 }; |
| 130 | 134 |
| 131 } // namespace | 135 } // namespace |
| 132 | 136 |
| 133 // Note: base::RunLoop::RunUntilIdle() does not work well in these tests because | 137 // Note: base::RunLoop::RunUntilIdle() does not work well in these tests because |
| 134 // even when the loop is idle, we may still have pending events in the pipe. | 138 // even when the loop is idle, we may still have pending events in the pipe. |
| 135 | 139 |
| 140 #if defined(ENABLE_MOJO_CDM) |
| 136 TEST_F(MediaAppTest, InitializeCdm_Success) { | 141 TEST_F(MediaAppTest, InitializeCdm_Success) { |
| 137 InitializeCdm(kClearKey, true, 1); | 142 InitializeCdm(kClearKey, true, 1); |
| 138 run_loop_->Run(); | 143 run_loop_->Run(); |
| 139 } | 144 } |
| 140 | 145 |
| 141 TEST_F(MediaAppTest, InitializeCdm_InvalidKeySystem) { | 146 TEST_F(MediaAppTest, InitializeCdm_InvalidKeySystem) { |
| 142 InitializeCdm(kInvalidKeySystem, false, 0); | 147 InitializeCdm(kInvalidKeySystem, false, 0); |
| 143 run_loop_->Run(); | 148 run_loop_->Run(); |
| 144 } | 149 } |
| 150 #endif // defined(ENABLE_MOJO_CDM) |
| 145 | 151 |
| 152 #if defined(ENABLE_MOJO_RENDERER) |
| 146 // Sometimes fails on Linux. http://crbug.com/594977 | 153 // Sometimes fails on Linux. http://crbug.com/594977 |
| 147 #if defined(OS_LINUX) | 154 #if defined(OS_LINUX) |
| 148 #define MAYBE_InitializeRenderer_Success DISABLED_InitializeRenderer_Success | 155 #define MAYBE_InitializeRenderer_Success DISABLED_InitializeRenderer_Success |
| 149 #else | 156 #else |
| 150 #define MAYBE_InitializeRenderer_Success InitializeRenderer_Success | 157 #define MAYBE_InitializeRenderer_Success InitializeRenderer_Success |
| 151 #endif | 158 #endif |
| 152 | 159 |
| 153 TEST_F(MediaAppTest, MAYBE_InitializeRenderer_Success) { | 160 TEST_F(MediaAppTest, MAYBE_InitializeRenderer_Success) { |
| 154 InitializeRenderer(TestVideoConfig::Normal(), true); | 161 InitializeRenderer(TestVideoConfig::Normal(), true); |
| 155 run_loop_->Run(); | 162 run_loop_->Run(); |
| 156 } | 163 } |
| 157 | 164 |
| 158 TEST_F(MediaAppTest, InitializeRenderer_InvalidConfig) { | 165 TEST_F(MediaAppTest, InitializeRenderer_InvalidConfig) { |
| 159 InitializeRenderer(TestVideoConfig::Invalid(), false); | 166 InitializeRenderer(TestVideoConfig::Invalid(), false); |
| 160 run_loop_->Run(); | 167 run_loop_->Run(); |
| 161 } | 168 } |
| 169 #endif // defined(ENABLE_MOJO_RENDERER) |
| 162 | 170 |
| 163 TEST_F(MediaAppTest, Lifetime) { | 171 TEST_F(MediaAppTest, Lifetime) { |
| 164 // Disconnecting CDM and Renderer services doesn't terminate the app. | 172 // Disconnecting CDM and Renderer services doesn't terminate the app. |
| 165 cdm_.reset(); | 173 cdm_.reset(); |
| 166 renderer_.reset(); | 174 renderer_.reset(); |
| 167 | 175 |
| 168 // Disconnecting ServiceFactory service should terminate the app, which will | 176 // Disconnecting ServiceFactory service should terminate the app, which will |
| 169 // close the connection. | 177 // close the connection. |
| 170 EXPECT_CALL(*this, ConnectionClosed()) | 178 EXPECT_CALL(*this, ConnectionClosed()) |
| 171 .Times(Exactly(1)) | 179 .Times(Exactly(1)) |
| 172 .WillOnce(Invoke(run_loop_.get(), &base::RunLoop::Quit)); | 180 .WillOnce(Invoke(run_loop_.get(), &base::RunLoop::Quit)); |
| 173 service_factory_.reset(); | 181 service_factory_.reset(); |
| 174 | 182 |
| 175 run_loop_->Run(); | 183 run_loop_->Run(); |
| 176 } | 184 } |
| 177 | 185 |
| 178 } // namespace media | 186 } // namespace media |
| OLD | NEW |