Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(251)

Side by Side Diff: media/mojo/services/media_mojo_unittest.cc

Issue 2444623002: media: Rename ServiceFactory to InterfaceFactory (Closed)
Patch Set: media: Rename ServiceFactory to InterfaceFactory Created 4 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « media/mojo/services/media_manifest.json ('k') | media/mojo/services/media_service.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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/renderer.mojom.h" 22 #include "media/mojo/interfaces/renderer.mojom.h"
22 #include "media/mojo/interfaces/service_factory.mojom.h"
23 #include "mojo/public/cpp/bindings/associated_binding.h" 23 #include "mojo/public/cpp/bindings/associated_binding.h"
24 #include "services/service_manager/public/cpp/service_test.h" 24 #include "services/service_manager/public/cpp/service_test.h"
25 #include "testing/gmock/include/gmock/gmock.h" 25 #include "testing/gmock/include/gmock/gmock.h"
26 26
27 using testing::Exactly; 27 using testing::Exactly;
28 using testing::Invoke; 28 using testing::Invoke;
29 using testing::InvokeWithoutArgs; 29 using testing::InvokeWithoutArgs;
30 using testing::StrictMock; 30 using testing::StrictMock;
31 31
32 namespace media { 32 namespace media {
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
70 video_stream_(DemuxerStream::VIDEO) {} 70 video_stream_(DemuxerStream::VIDEO) {}
71 ~MediaServiceTest() override {} 71 ~MediaServiceTest() override {}
72 72
73 void SetUp() override { 73 void SetUp() override {
74 ServiceTest::SetUp(); 74 ServiceTest::SetUp();
75 75
76 connection_ = connector()->Connect("service:media"); 76 connection_ = connector()->Connect("service:media");
77 connection_->SetConnectionLostClosure(base::Bind( 77 connection_->SetConnectionLostClosure(base::Bind(
78 &MediaServiceTest::ConnectionClosed, base::Unretained(this))); 78 &MediaServiceTest::ConnectionClosed, base::Unretained(this)));
79 79
80 connection_->GetInterface(&service_factory_); 80 connection_->GetInterface(&interface_factory_);
81 81
82 run_loop_.reset(new base::RunLoop()); 82 run_loop_.reset(new base::RunLoop());
83 } 83 }
84 84
85 // MOCK_METHOD* doesn't support move only types. Work around this by having 85 // MOCK_METHOD* doesn't support move only types. Work around this by having
86 // an extra method. 86 // an extra method.
87 MOCK_METHOD2(OnCdmInitializedInternal, void(bool result, int cdm_id)); 87 MOCK_METHOD2(OnCdmInitializedInternal, void(bool result, int cdm_id));
88 void OnCdmInitialized(mojom::CdmPromiseResultPtr result, 88 void OnCdmInitialized(mojom::CdmPromiseResultPtr result,
89 int cdm_id, 89 int cdm_id,
90 mojom::DecryptorPtr decryptor) { 90 mojom::DecryptorPtr decryptor) {
91 OnCdmInitializedInternal(result->success, cdm_id); 91 OnCdmInitializedInternal(result->success, cdm_id);
92 } 92 }
93 93
94 void InitializeCdm(const std::string& key_system, 94 void InitializeCdm(const std::string& key_system,
95 bool expected_result, 95 bool expected_result,
96 int cdm_id) { 96 int cdm_id) {
97 service_factory_->CreateCdm(mojo::GetProxy(&cdm_)); 97 interface_factory_->CreateCdm(mojo::GetProxy(&cdm_));
98 98
99 EXPECT_CALL(*this, OnCdmInitializedInternal(expected_result, cdm_id)) 99 EXPECT_CALL(*this, OnCdmInitializedInternal(expected_result, cdm_id))
100 .Times(Exactly(1)) 100 .Times(Exactly(1))
101 .WillOnce(InvokeWithoutArgs(run_loop_.get(), &base::RunLoop::Quit)); 101 .WillOnce(InvokeWithoutArgs(run_loop_.get(), &base::RunLoop::Quit));
102 cdm_->Initialize(key_system, kSecurityOrigin, 102 cdm_->Initialize(key_system, kSecurityOrigin,
103 mojom::CdmConfig::From(CdmConfig()), 103 mojom::CdmConfig::From(CdmConfig()),
104 base::Bind(&MediaServiceTest::OnCdmInitialized, 104 base::Bind(&MediaServiceTest::OnCdmInitialized,
105 base::Unretained(this))); 105 base::Unretained(this)));
106 } 106 }
107 107
108 MOCK_METHOD1(OnRendererInitialized, void(bool)); 108 MOCK_METHOD1(OnRendererInitialized, void(bool));
109 109
110 void InitializeRenderer(const VideoDecoderConfig& video_config, 110 void InitializeRenderer(const VideoDecoderConfig& video_config,
111 bool expected_result) { 111 bool expected_result) {
112 service_factory_->CreateRenderer(std::string(), mojo::GetProxy(&renderer_)); 112 interface_factory_->CreateRenderer(std::string(),
113 mojo::GetProxy(&renderer_));
113 114
114 video_stream_.set_video_decoder_config(video_config); 115 video_stream_.set_video_decoder_config(video_config);
115 116
116 mojom::DemuxerStreamPtr video_stream_proxy; 117 mojom::DemuxerStreamPtr video_stream_proxy;
117 mojo_video_stream_.reset(new MojoDemuxerStreamImpl( 118 mojo_video_stream_.reset(new MojoDemuxerStreamImpl(
118 &video_stream_, GetProxy(&video_stream_proxy))); 119 &video_stream_, GetProxy(&video_stream_proxy)));
119 120
120 mojom::RendererClientAssociatedPtrInfo client_ptr_info; 121 mojom::RendererClientAssociatedPtrInfo client_ptr_info;
121 renderer_client_binding_.Bind(&client_ptr_info, 122 renderer_client_binding_.Bind(&client_ptr_info,
122 renderer_.associated_group()); 123 renderer_.associated_group());
123 124
124 EXPECT_CALL(*this, OnRendererInitialized(expected_result)) 125 EXPECT_CALL(*this, OnRendererInitialized(expected_result))
125 .Times(Exactly(1)) 126 .Times(Exactly(1))
126 .WillOnce(InvokeWithoutArgs(run_loop_.get(), &base::RunLoop::Quit)); 127 .WillOnce(InvokeWithoutArgs(run_loop_.get(), &base::RunLoop::Quit));
127 renderer_->Initialize(std::move(client_ptr_info), nullptr, 128 renderer_->Initialize(std::move(client_ptr_info), nullptr,
128 std::move(video_stream_proxy), base::nullopt, 129 std::move(video_stream_proxy), base::nullopt,
129 base::Bind(&MediaServiceTest::OnRendererInitialized, 130 base::Bind(&MediaServiceTest::OnRendererInitialized,
130 base::Unretained(this))); 131 base::Unretained(this)));
131 } 132 }
132 133
133 MOCK_METHOD0(ConnectionClosed, void()); 134 MOCK_METHOD0(ConnectionClosed, void());
134 135
135 protected: 136 protected:
136 std::unique_ptr<base::RunLoop> run_loop_; 137 std::unique_ptr<base::RunLoop> run_loop_;
137 138
138 mojom::ServiceFactoryPtr service_factory_; 139 mojom::InterfaceFactoryPtr interface_factory_;
139 mojom::ContentDecryptionModulePtr cdm_; 140 mojom::ContentDecryptionModulePtr cdm_;
140 mojom::RendererPtr renderer_; 141 mojom::RendererPtr renderer_;
141 142
142 StrictMock<MockRendererClient> renderer_client_; 143 StrictMock<MockRendererClient> renderer_client_;
143 mojo::AssociatedBinding<mojom::RendererClient> renderer_client_binding_; 144 mojo::AssociatedBinding<mojom::RendererClient> renderer_client_binding_;
144 145
145 StrictMock<MockDemuxerStream> video_stream_; 146 StrictMock<MockDemuxerStream> video_stream_;
146 std::unique_ptr<MojoDemuxerStreamImpl> mojo_video_stream_; 147 std::unique_ptr<MojoDemuxerStreamImpl> mojo_video_stream_;
147 148
148 private: 149 private:
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
185 InitializeRenderer(TestVideoConfig::Invalid(), false); 186 InitializeRenderer(TestVideoConfig::Invalid(), false);
186 run_loop_->Run(); 187 run_loop_->Run();
187 } 188 }
188 #endif // defined(ENABLE_MOJO_RENDERER) 189 #endif // defined(ENABLE_MOJO_RENDERER)
189 190
190 TEST_F(MediaServiceTest, Lifetime) { 191 TEST_F(MediaServiceTest, Lifetime) {
191 // Disconnecting CDM and Renderer services doesn't terminate the app. 192 // Disconnecting CDM and Renderer services doesn't terminate the app.
192 cdm_.reset(); 193 cdm_.reset();
193 renderer_.reset(); 194 renderer_.reset();
194 195
195 // Disconnecting ServiceFactory service should terminate the app, which will 196 // Disconnecting InterfaceFactory service should terminate the app, which will
196 // close the connection. 197 // close the connection.
197 EXPECT_CALL(*this, ConnectionClosed()) 198 EXPECT_CALL(*this, ConnectionClosed())
198 .Times(Exactly(1)) 199 .Times(Exactly(1))
199 .WillOnce(Invoke(run_loop_.get(), &base::RunLoop::Quit)); 200 .WillOnce(Invoke(run_loop_.get(), &base::RunLoop::Quit));
200 service_factory_.reset(); 201 interface_factory_.reset();
201 202
202 run_loop_->Run(); 203 run_loop_->Run();
203 } 204 }
204 205
205 } // namespace media 206 } // namespace media
OLDNEW
« no previous file with comments | « media/mojo/services/media_manifest.json ('k') | media/mojo/services/media_service.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698