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

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

Issue 2123363002: ShellTest -> ServiceTest (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: . Created 4 years, 5 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/BUILD.gn ('k') | media/test/BUILD.gn » ('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/renderer.mojom.h" 21 #include "media/mojo/interfaces/renderer.mojom.h"
22 #include "media/mojo/interfaces/service_factory.mojom.h" 22 #include "media/mojo/interfaces/service_factory.mojom.h"
23 #include "services/shell/public/cpp/shell_test.h" 23 #include "services/shell/public/cpp/service_test.h"
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
(...skipping 13 matching lines...) Expand all
47 MOCK_METHOD1(OnBufferingStateChange, void(mojom::BufferingState state)); 47 MOCK_METHOD1(OnBufferingStateChange, void(mojom::BufferingState state));
48 MOCK_METHOD0(OnEnded, void()); 48 MOCK_METHOD0(OnEnded, void());
49 MOCK_METHOD0(OnError, void()); 49 MOCK_METHOD0(OnError, void());
50 MOCK_METHOD1(OnVideoOpacityChange, void(bool opaque)); 50 MOCK_METHOD1(OnVideoOpacityChange, void(bool opaque));
51 MOCK_METHOD1(OnVideoNaturalSizeChange, void(const gfx::Size& size)); 51 MOCK_METHOD1(OnVideoNaturalSizeChange, void(const gfx::Size& size));
52 52
53 private: 53 private:
54 DISALLOW_COPY_AND_ASSIGN(MockRendererClient); 54 DISALLOW_COPY_AND_ASSIGN(MockRendererClient);
55 }; 55 };
56 56
57 class MediaShellTest : public shell::test::ShellTest { 57 class MediaServiceTest : public shell::test::ServiceTest {
58 public: 58 public:
59 MediaShellTest() 59 MediaServiceTest()
60 : ShellTest("exe:media_mojo_unittests"), 60 : ServiceTest("exe:media_mojo_unittests"),
61 renderer_client_binding_(&renderer_client_), 61 renderer_client_binding_(&renderer_client_),
62 video_stream_(DemuxerStream::VIDEO) {} 62 video_stream_(DemuxerStream::VIDEO) {}
63 ~MediaShellTest() override {} 63 ~MediaServiceTest() override {}
64 64
65 void SetUp() override { 65 void SetUp() override {
66 ShellTest::SetUp(); 66 ServiceTest::SetUp();
67 67
68 connection_ = connector()->Connect("mojo:media"); 68 connection_ = connector()->Connect("mojo:media");
69 connection_->SetConnectionLostClosure( 69 connection_->SetConnectionLostClosure(base::Bind(
70 base::Bind(&MediaShellTest::ConnectionClosed, base::Unretained(this))); 70 &MediaServiceTest::ConnectionClosed, base::Unretained(this)));
71 71
72 connection_->GetInterface(&service_factory_); 72 connection_->GetInterface(&service_factory_);
73 73
74 run_loop_.reset(new base::RunLoop()); 74 run_loop_.reset(new base::RunLoop());
75 } 75 }
76 76
77 // MOCK_METHOD* doesn't support move only types. Work around this by having 77 // MOCK_METHOD* doesn't support move only types. Work around this by having
78 // an extra method. 78 // an extra method.
79 MOCK_METHOD2(OnCdmInitializedInternal, void(bool result, int cdm_id)); 79 MOCK_METHOD2(OnCdmInitializedInternal, void(bool result, int cdm_id));
80 void OnCdmInitialized(mojom::CdmPromiseResultPtr result, 80 void OnCdmInitialized(mojom::CdmPromiseResultPtr result,
81 int cdm_id, 81 int cdm_id,
82 mojom::DecryptorPtr decryptor) { 82 mojom::DecryptorPtr decryptor) {
83 OnCdmInitializedInternal(result->success, cdm_id); 83 OnCdmInitializedInternal(result->success, cdm_id);
84 } 84 }
85 85
86 void InitializeCdm(const std::string& key_system, 86 void InitializeCdm(const std::string& key_system,
87 bool expected_result, 87 bool expected_result,
88 int cdm_id) { 88 int cdm_id) {
89 service_factory_->CreateCdm(mojo::GetProxy(&cdm_)); 89 service_factory_->CreateCdm(mojo::GetProxy(&cdm_));
90 90
91 EXPECT_CALL(*this, OnCdmInitializedInternal(expected_result, cdm_id)) 91 EXPECT_CALL(*this, OnCdmInitializedInternal(expected_result, cdm_id))
92 .Times(Exactly(1)) 92 .Times(Exactly(1))
93 .WillOnce(InvokeWithoutArgs(run_loop_.get(), &base::RunLoop::Quit)); 93 .WillOnce(InvokeWithoutArgs(run_loop_.get(), &base::RunLoop::Quit));
94 cdm_->Initialize( 94 cdm_->Initialize(key_system, kSecurityOrigin,
95 key_system, kSecurityOrigin, mojom::CdmConfig::From(CdmConfig()), 95 mojom::CdmConfig::From(CdmConfig()),
96 base::Bind(&MediaShellTest::OnCdmInitialized, base::Unretained(this))); 96 base::Bind(&MediaServiceTest::OnCdmInitialized,
97 base::Unretained(this)));
97 } 98 }
98 99
99 MOCK_METHOD1(OnRendererInitialized, void(bool)); 100 MOCK_METHOD1(OnRendererInitialized, void(bool));
100 101
101 void InitializeRenderer(const VideoDecoderConfig& video_config, 102 void InitializeRenderer(const VideoDecoderConfig& video_config,
102 bool expected_result) { 103 bool expected_result) {
103 service_factory_->CreateRenderer(mojo::GetProxy(&renderer_)); 104 service_factory_->CreateRenderer(mojo::GetProxy(&renderer_));
104 105
105 video_stream_.set_video_decoder_config(video_config); 106 video_stream_.set_video_decoder_config(video_config);
106 107
107 mojom::DemuxerStreamPtr video_stream_proxy; 108 mojom::DemuxerStreamPtr video_stream_proxy;
108 mojo_video_stream_.reset(new MojoDemuxerStreamImpl( 109 mojo_video_stream_.reset(new MojoDemuxerStreamImpl(
109 &video_stream_, GetProxy(&video_stream_proxy))); 110 &video_stream_, GetProxy(&video_stream_proxy)));
110 111
111 EXPECT_CALL(*this, OnRendererInitialized(expected_result)) 112 EXPECT_CALL(*this, OnRendererInitialized(expected_result))
112 .Times(Exactly(1)) 113 .Times(Exactly(1))
113 .WillOnce(InvokeWithoutArgs(run_loop_.get(), &base::RunLoop::Quit)); 114 .WillOnce(InvokeWithoutArgs(run_loop_.get(), &base::RunLoop::Quit));
114 renderer_->Initialize(renderer_client_binding_.CreateInterfacePtrAndBind(), 115 renderer_->Initialize(renderer_client_binding_.CreateInterfacePtrAndBind(),
115 nullptr, std::move(video_stream_proxy), 116 nullptr, std::move(video_stream_proxy),
116 base::Bind(&MediaShellTest::OnRendererInitialized, 117 base::Bind(&MediaServiceTest::OnRendererInitialized,
117 base::Unretained(this))); 118 base::Unretained(this)));
118 } 119 }
119 120
120 MOCK_METHOD0(ConnectionClosed, void()); 121 MOCK_METHOD0(ConnectionClosed, void());
121 122
122 protected: 123 protected:
123 std::unique_ptr<base::RunLoop> run_loop_; 124 std::unique_ptr<base::RunLoop> run_loop_;
124 125
125 mojom::ServiceFactoryPtr service_factory_; 126 mojom::ServiceFactoryPtr service_factory_;
126 mojom::ContentDecryptionModulePtr cdm_; 127 mojom::ContentDecryptionModulePtr cdm_;
127 mojom::RendererPtr renderer_; 128 mojom::RendererPtr renderer_;
128 129
129 StrictMock<MockRendererClient> renderer_client_; 130 StrictMock<MockRendererClient> renderer_client_;
130 mojo::Binding<mojom::RendererClient> renderer_client_binding_; 131 mojo::Binding<mojom::RendererClient> renderer_client_binding_;
131 132
132 StrictMock<MockDemuxerStream> video_stream_; 133 StrictMock<MockDemuxerStream> video_stream_;
133 std::unique_ptr<MojoDemuxerStreamImpl> mojo_video_stream_; 134 std::unique_ptr<MojoDemuxerStreamImpl> mojo_video_stream_;
134 135
135 private: 136 private:
136 std::unique_ptr<shell::Connection> connection_; 137 std::unique_ptr<shell::Connection> connection_;
137 138
138 DISALLOW_COPY_AND_ASSIGN(MediaShellTest); 139 DISALLOW_COPY_AND_ASSIGN(MediaServiceTest);
139 }; 140 };
140 141
141 } // namespace 142 } // namespace
142 143
143 // Note: base::RunLoop::RunUntilIdle() does not work well in these tests because 144 // Note: base::RunLoop::RunUntilIdle() does not work well in these tests because
144 // even when the loop is idle, we may still have pending events in the pipe. 145 // even when the loop is idle, we may still have pending events in the pipe.
145 146
146 #if defined(ENABLE_MOJO_CDM) 147 #if defined(ENABLE_MOJO_CDM)
147 TEST_F(MediaShellTest, InitializeCdm_Success) { 148 TEST_F(MediaServiceTest, InitializeCdm_Success) {
148 InitializeCdm(kClearKeyKeySystem, true, 1); 149 InitializeCdm(kClearKeyKeySystem, true, 1);
149 run_loop_->Run(); 150 run_loop_->Run();
150 } 151 }
151 152
152 TEST_F(MediaShellTest, InitializeCdm_InvalidKeySystem) { 153 TEST_F(MediaServiceTest, InitializeCdm_InvalidKeySystem) {
153 InitializeCdm(kInvalidKeySystem, false, 0); 154 InitializeCdm(kInvalidKeySystem, false, 0);
154 run_loop_->Run(); 155 run_loop_->Run();
155 } 156 }
156 #endif // defined(ENABLE_MOJO_CDM) 157 #endif // defined(ENABLE_MOJO_CDM)
157 158
158 #if defined(ENABLE_MOJO_RENDERER) 159 #if defined(ENABLE_MOJO_RENDERER)
159 // Sometimes fails on Linux. http://crbug.com/594977 160 // Sometimes fails on Linux. http://crbug.com/594977
160 #if defined(OS_LINUX) 161 #if defined(OS_LINUX)
161 #define MAYBE_InitializeRenderer_Success DISABLED_InitializeRenderer_Success 162 #define MAYBE_InitializeRenderer_Success DISABLED_InitializeRenderer_Success
162 #else 163 #else
163 #define MAYBE_InitializeRenderer_Success InitializeRenderer_Success 164 #define MAYBE_InitializeRenderer_Success InitializeRenderer_Success
164 #endif 165 #endif
165 166
166 TEST_F(MediaShellTest, MAYBE_InitializeRenderer_Success) { 167 TEST_F(MediaServiceTest, MAYBE_InitializeRenderer_Success) {
167 InitializeRenderer(TestVideoConfig::Normal(), true); 168 InitializeRenderer(TestVideoConfig::Normal(), true);
168 run_loop_->Run(); 169 run_loop_->Run();
169 } 170 }
170 171
171 TEST_F(MediaShellTest, InitializeRenderer_InvalidConfig) { 172 TEST_F(MediaServiceTest, InitializeRenderer_InvalidConfig) {
172 InitializeRenderer(TestVideoConfig::Invalid(), false); 173 InitializeRenderer(TestVideoConfig::Invalid(), false);
173 run_loop_->Run(); 174 run_loop_->Run();
174 } 175 }
175 #endif // defined(ENABLE_MOJO_RENDERER) 176 #endif // defined(ENABLE_MOJO_RENDERER)
176 177
177 TEST_F(MediaShellTest, Lifetime) { 178 TEST_F(MediaServiceTest, Lifetime) {
178 // Disconnecting CDM and Renderer services doesn't terminate the app. 179 // Disconnecting CDM and Renderer services doesn't terminate the app.
179 cdm_.reset(); 180 cdm_.reset();
180 renderer_.reset(); 181 renderer_.reset();
181 182
182 // Disconnecting ServiceFactory service should terminate the app, which will 183 // Disconnecting ServiceFactory service should terminate the app, which will
183 // close the connection. 184 // close the connection.
184 EXPECT_CALL(*this, ConnectionClosed()) 185 EXPECT_CALL(*this, ConnectionClosed())
185 .Times(Exactly(1)) 186 .Times(Exactly(1))
186 .WillOnce(Invoke(run_loop_.get(), &base::RunLoop::Quit)); 187 .WillOnce(Invoke(run_loop_.get(), &base::RunLoop::Quit));
187 service_factory_.reset(); 188 service_factory_.reset();
188 189
189 run_loop_->Run(); 190 run_loop_->Run();
190 } 191 }
191 192
192 } // namespace media 193 } // namespace media
OLDNEW
« no previous file with comments | « media/mojo/services/BUILD.gn ('k') | media/test/BUILD.gn » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698