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 "base/bind.h" | 5 #include "base/bind.h" |
6 #include "base/callback.h" | 6 #include "base/callback.h" |
7 #include "base/macros.h" | 7 #include "base/macros.h" |
8 #include "base/memory/scoped_ptr.h" | 8 #include "base/memory/scoped_ptr.h" |
9 #include "base/run_loop.h" | 9 #include "base/run_loop.h" |
10 #include "media/base/mock_filters.h" | 10 #include "media/base/mock_filters.h" |
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
50 : media_renderer_client_binding_(&media_renderer_client_), | 50 : media_renderer_client_binding_(&media_renderer_client_), |
51 video_demuxer_stream_(DemuxerStream::VIDEO) {} | 51 video_demuxer_stream_(DemuxerStream::VIDEO) {} |
52 ~MediaAppTest() override {} | 52 ~MediaAppTest() override {} |
53 | 53 |
54 void SetUp() override { | 54 void SetUp() override { |
55 ApplicationTestBase::SetUp(); | 55 ApplicationTestBase::SetUp(); |
56 | 56 |
57 mojo::URLRequestPtr request = mojo::URLRequest::New(); | 57 mojo::URLRequestPtr request = mojo::URLRequest::New(); |
58 request->url = "mojo:media"; | 58 request->url = "mojo:media"; |
59 mojo::ApplicationConnection* connection = | 59 mojo::ApplicationConnection* connection = |
60 application_impl()->ConnectToApplication(request.Pass()); | 60 application_impl()->ConnectToApplication( |
| 61 request.Pass(), |
| 62 base::Bind(&MediaAppTest::OnAppTerminated, base::Unretained(this))); |
61 | 63 |
62 connection->ConnectToService(&cdm_); | 64 connection->ConnectToService(&cdm_); |
63 connection->ConnectToService(&media_renderer_); | 65 connection->ConnectToService(&media_renderer_); |
64 | 66 |
65 run_loop_.reset(new base::RunLoop()); | 67 run_loop_.reset(new base::RunLoop()); |
66 } | 68 } |
67 | 69 |
68 // MOCK_METHOD* doesn't support move only types. Work around this by having | 70 // MOCK_METHOD* doesn't support move only types. Work around this by having |
69 // an extra method. | 71 // an extra method. |
70 MOCK_METHOD1(OnCdmInitializedInternal, void(bool result)); | 72 MOCK_METHOD1(OnCdmInitializedInternal, void(bool result)); |
(...skipping 22 matching lines...) Expand all Loading... |
93 media_renderer_client_binding_.Bind(GetProxy(&client_ptr)); | 95 media_renderer_client_binding_.Bind(GetProxy(&client_ptr)); |
94 | 96 |
95 EXPECT_CALL(*this, OnRendererInitialized()) | 97 EXPECT_CALL(*this, OnRendererInitialized()) |
96 .Times(Exactly(1)) | 98 .Times(Exactly(1)) |
97 .WillOnce(Invoke(run_loop_.get(), &base::RunLoop::Quit)); | 99 .WillOnce(Invoke(run_loop_.get(), &base::RunLoop::Quit)); |
98 media_renderer_->Initialize(client_ptr.Pass(), nullptr, video_stream.Pass(), | 100 media_renderer_->Initialize(client_ptr.Pass(), nullptr, video_stream.Pass(), |
99 base::Bind(&MediaAppTest::OnRendererInitialized, | 101 base::Bind(&MediaAppTest::OnRendererInitialized, |
100 base::Unretained(this))); | 102 base::Unretained(this))); |
101 } | 103 } |
102 | 104 |
| 105 MOCK_METHOD0(OnAppTerminated, void()); |
| 106 |
103 protected: | 107 protected: |
104 scoped_ptr<base::RunLoop> run_loop_; | 108 scoped_ptr<base::RunLoop> run_loop_; |
105 | 109 |
106 mojo::ContentDecryptionModulePtr cdm_; | 110 mojo::ContentDecryptionModulePtr cdm_; |
107 mojo::MediaRendererPtr media_renderer_; | 111 mojo::MediaRendererPtr media_renderer_; |
108 | 112 |
109 StrictMock<MockMediaRendererClient> media_renderer_client_; | 113 StrictMock<MockMediaRendererClient> media_renderer_client_; |
110 mojo::Binding<mojo::MediaRendererClient> media_renderer_client_binding_; | 114 mojo::Binding<mojo::MediaRendererClient> media_renderer_client_binding_; |
111 | 115 |
112 StrictMock<MockDemuxerStream> video_demuxer_stream_; | 116 StrictMock<MockDemuxerStream> video_demuxer_stream_; |
(...skipping 21 matching lines...) Expand all Loading... |
134 InitializeRenderer(TestVideoConfig::Normal()); | 138 InitializeRenderer(TestVideoConfig::Normal()); |
135 run_loop_->Run(); | 139 run_loop_->Run(); |
136 } | 140 } |
137 | 141 |
138 TEST_F(MediaAppTest, InitializeRenderer_InvalidConfig) { | 142 TEST_F(MediaAppTest, InitializeRenderer_InvalidConfig) { |
139 EXPECT_CALL(media_renderer_client_, OnError()); | 143 EXPECT_CALL(media_renderer_client_, OnError()); |
140 InitializeRenderer(TestVideoConfig::Invalid()); | 144 InitializeRenderer(TestVideoConfig::Invalid()); |
141 run_loop_->Run(); | 145 run_loop_->Run(); |
142 } | 146 } |
143 | 147 |
| 148 TEST_F(MediaAppTest, Lifetime) { |
| 149 // Disconnect one service doesn't terminate the app. |
| 150 cdm_.reset(); |
| 151 |
| 152 // Disconnect all services should terminate the app. |
| 153 EXPECT_CALL(*this, OnAppTerminated()) |
| 154 .Times(Exactly(1)) |
| 155 .WillOnce(Invoke(run_loop_.get(), &base::RunLoop::Quit)); |
| 156 media_renderer_.reset(); |
| 157 |
| 158 run_loop_->Run(); |
| 159 } |
| 160 |
144 } // namespace media | 161 } // namespace media |
OLD | NEW |