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

Side by Side Diff: media/remoting/renderer_controller_unittest.cc

Issue 2643253003: Media Remoting Clean-up: Less-redundant naming, style consistency, etc. (Closed)
Patch Set: REBASE Created 3 years, 11 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/remoting/renderer_controller.cc ('k') | media/remoting/rpc.proto » ('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 2016 The Chromium Authors. All rights reserved. 1 // Copyright 2016 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 "media/remoting/remoting_renderer_controller.h" 5 #include "media/remoting/renderer_controller.h"
6 6
7 #include "base/callback.h" 7 #include "base/callback.h"
8 #include "base/memory/ptr_util.h" 8 #include "base/memory/ptr_util.h"
9 #include "base/message_loop/message_loop.h" 9 #include "base/message_loop/message_loop.h"
10 #include "base/run_loop.h" 10 #include "base/run_loop.h"
11 #include "media/base/audio_decoder_config.h" 11 #include "media/base/audio_decoder_config.h"
12 #include "media/base/cdm_config.h" 12 #include "media/base/cdm_config.h"
13 #include "media/base/limits.h" 13 #include "media/base/limits.h"
14 #include "media/base/media_util.h" 14 #include "media/base/media_util.h"
15 #include "media/base/test_helpers.h" 15 #include "media/base/test_helpers.h"
16 #include "media/base/video_decoder_config.h" 16 #include "media/base/video_decoder_config.h"
17 #include "media/remoting/fake_remoting_controller.h" 17 #include "media/remoting/fake_remoter.h"
18 #include "media/remoting/remoting_cdm.h" 18 #include "media/remoting/remoting_cdm.h"
19 #include "mojo/public/cpp/bindings/strong_binding.h" 19 #include "mojo/public/cpp/bindings/strong_binding.h"
20 #include "testing/gtest/include/gtest/gtest.h" 20 #include "testing/gtest/include/gtest/gtest.h"
21 21
22 namespace media { 22 namespace media {
23 namespace remoting {
24
23 namespace { 25 namespace {
24 26
25 constexpr mojom::RemotingSinkCapabilities kAllCapabilities = 27 constexpr mojom::RemotingSinkCapabilities kAllCapabilities =
26 mojom::RemotingSinkCapabilities::CONTENT_DECRYPTION_AND_RENDERING; 28 mojom::RemotingSinkCapabilities::CONTENT_DECRYPTION_AND_RENDERING;
27 29
28 PipelineMetadata DefaultMetadata() { 30 PipelineMetadata DefaultMetadata() {
29 PipelineMetadata data; 31 PipelineMetadata data;
30 data.has_audio = true; 32 data.has_audio = true;
31 data.has_video = true; 33 data.has_video = true;
32 data.video_decoder_config = TestVideoConfig::Normal(); 34 data.video_decoder_config = TestVideoConfig::Normal();
33 return data; 35 return data;
34 } 36 }
35 37
36 PipelineMetadata EncryptedMetadata() { 38 PipelineMetadata EncryptedMetadata() {
37 PipelineMetadata data; 39 PipelineMetadata data;
38 data.has_audio = true; 40 data.has_audio = true;
39 data.has_video = true; 41 data.has_video = true;
40 data.video_decoder_config = TestVideoConfig::NormalEncrypted(); 42 data.video_decoder_config = TestVideoConfig::NormalEncrypted();
41 return data; 43 return data;
42 } 44 }
43 45
44 } // namespace 46 } // namespace
45 47
46 class RemotingRendererControllerTest : public ::testing::Test { 48 class RendererControllerTest : public ::testing::Test {
47 public: 49 public:
48 RemotingRendererControllerTest() {} 50 RendererControllerTest() {}
49 ~RemotingRendererControllerTest() override {} 51 ~RendererControllerTest() override {}
50 52
51 void TearDown() final { RunUntilIdle(); } 53 void TearDown() final { RunUntilIdle(); }
52 54
53 static void RunUntilIdle() { base::RunLoop().RunUntilIdle(); } 55 static void RunUntilIdle() { base::RunLoop().RunUntilIdle(); }
54 56
55 void ToggleRenderer() { 57 void ToggleRenderer() {
56 is_rendering_remotely_ = 58 is_rendering_remotely_ = controller_->remote_rendering_started();
57 remoting_renderer_controller_->remote_rendering_started();
58 } 59 }
59 60
60 void CreateCdm(bool is_remoting) { is_remoting_cdm_ = is_remoting; } 61 void CreateCdm(bool is_remoting) { is_remoting_cdm_ = is_remoting; }
61 62
62 base::MessageLoop message_loop_; 63 base::MessageLoop message_loop_;
63 64
64 protected: 65 protected:
65 std::unique_ptr<RemotingRendererController> remoting_renderer_controller_; 66 std::unique_ptr<RendererController> controller_;
66 bool is_rendering_remotely_ = false; 67 bool is_rendering_remotely_ = false;
67 bool is_remoting_cdm_ = false; 68 bool is_remoting_cdm_ = false;
68 69
69 private: 70 private:
70 DISALLOW_COPY_AND_ASSIGN(RemotingRendererControllerTest); 71 DISALLOW_COPY_AND_ASSIGN(RendererControllerTest);
71 }; 72 };
72 73
73 TEST_F(RemotingRendererControllerTest, ToggleRendererOnFullscreenChange) { 74 TEST_F(RendererControllerTest, ToggleRendererOnFullscreenChange) {
74 EXPECT_FALSE(is_rendering_remotely_); 75 EXPECT_FALSE(is_rendering_remotely_);
75 scoped_refptr<RemotingSourceImpl> remoting_source_impl = 76 const scoped_refptr<SharedSession> shared_session =
76 CreateRemotingSourceImpl(false); 77 FakeRemoterFactory::CreateSharedSession(false);
77 remoting_renderer_controller_ = 78 controller_ = base::MakeUnique<RendererController>(shared_session);
78 base::MakeUnique<RemotingRendererController>(remoting_source_impl); 79 controller_->SetSwitchRendererCallback(base::Bind(
79 remoting_renderer_controller_->SetSwitchRendererCallback(base::Bind( 80 &RendererControllerTest::ToggleRenderer, base::Unretained(this)));
80 &RemotingRendererControllerTest::ToggleRenderer, base::Unretained(this))); 81 RunUntilIdle();
81 RunUntilIdle(); 82 EXPECT_FALSE(is_rendering_remotely_);
82 EXPECT_FALSE(is_rendering_remotely_); 83 shared_session->OnSinkAvailable(kAllCapabilities);
83 remoting_source_impl->OnSinkAvailable(kAllCapabilities); 84 RunUntilIdle();
84 RunUntilIdle(); 85 EXPECT_FALSE(is_rendering_remotely_);
85 EXPECT_FALSE(is_rendering_remotely_); 86 controller_->OnEnteredFullscreen();
86 remoting_renderer_controller_->OnEnteredFullscreen(); 87 RunUntilIdle();
87 RunUntilIdle(); 88 EXPECT_FALSE(is_rendering_remotely_);
88 EXPECT_FALSE(is_rendering_remotely_); 89 controller_->OnMetadataChanged(DefaultMetadata());
89 remoting_renderer_controller_->OnMetadataChanged(DefaultMetadata()); 90 RunUntilIdle();
90 RunUntilIdle(); 91 EXPECT_FALSE(is_rendering_remotely_);
91 EXPECT_FALSE(is_rendering_remotely_); 92 controller_->OnRemotePlaybackDisabled(false);
92 remoting_renderer_controller_->OnRemotePlaybackDisabled(false); 93 RunUntilIdle();
93 RunUntilIdle(); 94 EXPECT_FALSE(is_rendering_remotely_);
94 EXPECT_FALSE(is_rendering_remotely_); 95 controller_->OnPlaying();
95 remoting_renderer_controller_->OnPlaying();
96 RunUntilIdle(); 96 RunUntilIdle();
97 EXPECT_TRUE(is_rendering_remotely_); // All requirements now satisfied. 97 EXPECT_TRUE(is_rendering_remotely_); // All requirements now satisfied.
98 98
99 // Leaving fullscreen should shut down remoting. 99 // Leaving fullscreen should shut down remoting.
100 remoting_renderer_controller_->OnExitedFullscreen(); 100 controller_->OnExitedFullscreen();
101 RunUntilIdle(); 101 RunUntilIdle();
102 EXPECT_FALSE(is_rendering_remotely_); 102 EXPECT_FALSE(is_rendering_remotely_);
103 } 103 }
104 104
105 TEST_F(RemotingRendererControllerTest, ToggleRendererOnSinkCapabilities) { 105 TEST_F(RendererControllerTest, ToggleRendererOnSinkCapabilities) {
106 EXPECT_FALSE(is_rendering_remotely_); 106 EXPECT_FALSE(is_rendering_remotely_);
107 scoped_refptr<RemotingSourceImpl> remoting_source_impl = 107 const scoped_refptr<SharedSession> shared_session =
108 CreateRemotingSourceImpl(false); 108 FakeRemoterFactory::CreateSharedSession(false);
109 remoting_renderer_controller_ = 109 controller_ = base::MakeUnique<RendererController>(shared_session);
110 base::MakeUnique<RemotingRendererController>(remoting_source_impl); 110 controller_->SetSwitchRendererCallback(base::Bind(
111 remoting_renderer_controller_->SetSwitchRendererCallback(base::Bind( 111 &RendererControllerTest::ToggleRenderer, base::Unretained(this)));
112 &RemotingRendererControllerTest::ToggleRenderer, base::Unretained(this))); 112 RunUntilIdle();
113 RunUntilIdle(); 113 EXPECT_FALSE(is_rendering_remotely_);
114 EXPECT_FALSE(is_rendering_remotely_); 114 controller_->OnMetadataChanged(DefaultMetadata());
115 remoting_renderer_controller_->OnMetadataChanged(DefaultMetadata()); 115 RunUntilIdle();
116 RunUntilIdle(); 116 EXPECT_FALSE(is_rendering_remotely_);
117 EXPECT_FALSE(is_rendering_remotely_); 117 controller_->OnRemotePlaybackDisabled(false);
118 remoting_renderer_controller_->OnRemotePlaybackDisabled(false); 118 RunUntilIdle();
119 RunUntilIdle(); 119 EXPECT_FALSE(is_rendering_remotely_);
120 EXPECT_FALSE(is_rendering_remotely_); 120 controller_->OnPlaying();
121 remoting_renderer_controller_->OnPlaying(); 121 RunUntilIdle();
122 RunUntilIdle(); 122 EXPECT_FALSE(is_rendering_remotely_);
123 EXPECT_FALSE(is_rendering_remotely_); 123 controller_->OnEnteredFullscreen();
124 remoting_renderer_controller_->OnEnteredFullscreen();
125 RunUntilIdle(); 124 RunUntilIdle();
126 EXPECT_FALSE(is_rendering_remotely_); 125 EXPECT_FALSE(is_rendering_remotely_);
127 // An available sink that does not support remote rendering should not cause 126 // An available sink that does not support remote rendering should not cause
128 // the controller to toggle remote rendering on. 127 // the controller to toggle remote rendering on.
129 remoting_source_impl->OnSinkAvailable(mojom::RemotingSinkCapabilities::NONE); 128 shared_session->OnSinkAvailable(mojom::RemotingSinkCapabilities::NONE);
130 RunUntilIdle(); 129 RunUntilIdle();
131 EXPECT_FALSE(is_rendering_remotely_); 130 EXPECT_FALSE(is_rendering_remotely_);
132 remoting_source_impl->OnSinkGone(); // Bye-bye useless sink! 131 shared_session->OnSinkGone(); // Bye-bye useless sink!
133 RunUntilIdle(); 132 RunUntilIdle();
134 EXPECT_FALSE(is_rendering_remotely_); 133 EXPECT_FALSE(is_rendering_remotely_);
135 // A sink that *does* support remote rendering *does* cause the controller to 134 // A sink that *does* support remote rendering *does* cause the controller to
136 // toggle remote rendering on. 135 // toggle remote rendering on.
137 remoting_source_impl->OnSinkAvailable(kAllCapabilities); 136 shared_session->OnSinkAvailable(kAllCapabilities);
138 RunUntilIdle(); 137 RunUntilIdle();
139 EXPECT_TRUE(is_rendering_remotely_); 138 EXPECT_TRUE(is_rendering_remotely_);
140 remoting_renderer_controller_->OnExitedFullscreen(); 139 controller_->OnExitedFullscreen();
141 RunUntilIdle(); 140 RunUntilIdle();
142 EXPECT_FALSE(is_rendering_remotely_); 141 EXPECT_FALSE(is_rendering_remotely_);
143 } 142 }
144 143
145 TEST_F(RemotingRendererControllerTest, ToggleRendererOnDisableChange) { 144 TEST_F(RendererControllerTest, ToggleRendererOnDisableChange) {
146 EXPECT_FALSE(is_rendering_remotely_); 145 EXPECT_FALSE(is_rendering_remotely_);
147 scoped_refptr<RemotingSourceImpl> remoting_source_impl = 146 const scoped_refptr<SharedSession> shared_session =
148 CreateRemotingSourceImpl(false); 147 FakeRemoterFactory::CreateSharedSession(false);
149 remoting_renderer_controller_ = 148 controller_ = base::MakeUnique<RendererController>(shared_session);
150 base::MakeUnique<RemotingRendererController>(remoting_source_impl); 149 controller_->SetSwitchRendererCallback(base::Bind(
151 remoting_renderer_controller_->SetSwitchRendererCallback(base::Bind( 150 &RendererControllerTest::ToggleRenderer, base::Unretained(this)));
152 &RemotingRendererControllerTest::ToggleRenderer, base::Unretained(this))); 151 RunUntilIdle();
153 RunUntilIdle(); 152 EXPECT_FALSE(is_rendering_remotely_);
154 EXPECT_FALSE(is_rendering_remotely_); 153 controller_->OnRemotePlaybackDisabled(true);
155 remoting_renderer_controller_->OnRemotePlaybackDisabled(true); 154 RunUntilIdle();
156 RunUntilIdle(); 155 EXPECT_FALSE(is_rendering_remotely_);
157 EXPECT_FALSE(is_rendering_remotely_); 156 shared_session->OnSinkAvailable(kAllCapabilities);
158 remoting_source_impl->OnSinkAvailable(kAllCapabilities); 157 RunUntilIdle();
159 RunUntilIdle(); 158 EXPECT_FALSE(is_rendering_remotely_);
160 EXPECT_FALSE(is_rendering_remotely_); 159 controller_->OnMetadataChanged(DefaultMetadata());
161 remoting_renderer_controller_->OnMetadataChanged(DefaultMetadata()); 160 RunUntilIdle();
162 RunUntilIdle(); 161 EXPECT_FALSE(is_rendering_remotely_);
163 EXPECT_FALSE(is_rendering_remotely_); 162 controller_->OnEnteredFullscreen();
164 remoting_renderer_controller_->OnEnteredFullscreen(); 163 RunUntilIdle();
165 RunUntilIdle(); 164 EXPECT_FALSE(is_rendering_remotely_);
166 EXPECT_FALSE(is_rendering_remotely_); 165 controller_->OnRemotePlaybackDisabled(false);
167 remoting_renderer_controller_->OnRemotePlaybackDisabled(false); 166 RunUntilIdle();
168 RunUntilIdle(); 167 EXPECT_FALSE(is_rendering_remotely_);
169 EXPECT_FALSE(is_rendering_remotely_); 168 controller_->OnPlaying();
170 remoting_renderer_controller_->OnPlaying();
171 RunUntilIdle(); 169 RunUntilIdle();
172 EXPECT_TRUE(is_rendering_remotely_); // All requirements now satisfied. 170 EXPECT_TRUE(is_rendering_remotely_); // All requirements now satisfied.
173 171
174 // If the page disables remote playback (e.g., by setting the 172 // If the page disables remote playback (e.g., by setting the
175 // disableRemotePlayback attribute), this should shut down remoting. 173 // disableRemotePlayback attribute), this should shut down remoting.
176 remoting_renderer_controller_->OnRemotePlaybackDisabled(true); 174 controller_->OnRemotePlaybackDisabled(true);
177 RunUntilIdle(); 175 RunUntilIdle();
178 EXPECT_FALSE(is_rendering_remotely_); 176 EXPECT_FALSE(is_rendering_remotely_);
179 } 177 }
180 178
181 TEST_F(RemotingRendererControllerTest, StartFailed) { 179 TEST_F(RendererControllerTest, StartFailed) {
182 EXPECT_FALSE(is_rendering_remotely_); 180 EXPECT_FALSE(is_rendering_remotely_);
183 scoped_refptr<RemotingSourceImpl> remoting_source_impl = 181 const scoped_refptr<SharedSession> shared_session =
184 CreateRemotingSourceImpl(true); 182 FakeRemoterFactory::CreateSharedSession(true);
185 remoting_renderer_controller_ = 183 controller_ = base::MakeUnique<RendererController>(shared_session);
186 base::MakeUnique<RemotingRendererController>(remoting_source_impl); 184 controller_->SetSwitchRendererCallback(base::Bind(
187 remoting_renderer_controller_->SetSwitchRendererCallback(base::Bind( 185 &RendererControllerTest::ToggleRenderer, base::Unretained(this)));
188 &RemotingRendererControllerTest::ToggleRenderer, base::Unretained(this))); 186 RunUntilIdle();
189 RunUntilIdle(); 187 EXPECT_FALSE(is_rendering_remotely_);
190 EXPECT_FALSE(is_rendering_remotely_); 188 shared_session->OnSinkAvailable(kAllCapabilities);
191 remoting_source_impl->OnSinkAvailable(kAllCapabilities); 189 RunUntilIdle();
192 RunUntilIdle(); 190 EXPECT_FALSE(is_rendering_remotely_);
193 EXPECT_FALSE(is_rendering_remotely_); 191 controller_->OnEnteredFullscreen();
194 remoting_renderer_controller_->OnEnteredFullscreen(); 192 RunUntilIdle();
195 RunUntilIdle(); 193 EXPECT_FALSE(is_rendering_remotely_);
196 EXPECT_FALSE(is_rendering_remotely_); 194 controller_->OnMetadataChanged(DefaultMetadata());
197 remoting_renderer_controller_->OnMetadataChanged(DefaultMetadata()); 195 RunUntilIdle();
198 RunUntilIdle(); 196 EXPECT_FALSE(is_rendering_remotely_);
199 EXPECT_FALSE(is_rendering_remotely_); 197 controller_->OnRemotePlaybackDisabled(false);
200 remoting_renderer_controller_->OnRemotePlaybackDisabled(false); 198 RunUntilIdle();
201 RunUntilIdle(); 199 EXPECT_FALSE(is_rendering_remotely_);
202 EXPECT_FALSE(is_rendering_remotely_); 200 controller_->OnPlaying();
203 remoting_renderer_controller_->OnPlaying(); 201 RunUntilIdle();
204 RunUntilIdle(); 202 EXPECT_FALSE(is_rendering_remotely_);
205 EXPECT_FALSE(is_rendering_remotely_); 203 }
206 } 204
207 205 TEST_F(RendererControllerTest, EncryptedWithRemotingCdm) {
208 TEST_F(RemotingRendererControllerTest, EncryptedWithRemotingCdm) { 206 EXPECT_FALSE(is_rendering_remotely_);
209 EXPECT_FALSE(is_rendering_remotely_); 207 controller_ = base::MakeUnique<RendererController>(
210 remoting_renderer_controller_ = base::MakeUnique<RemotingRendererController>( 208 FakeRemoterFactory::CreateSharedSession(false));
211 CreateRemotingSourceImpl(false)); 209 controller_->SetSwitchRendererCallback(base::Bind(
212 remoting_renderer_controller_->SetSwitchRendererCallback(base::Bind( 210 &RendererControllerTest::ToggleRenderer, base::Unretained(this)));
213 &RemotingRendererControllerTest::ToggleRenderer, base::Unretained(this))); 211 RunUntilIdle();
214 RunUntilIdle(); 212 EXPECT_FALSE(is_rendering_remotely_);
215 EXPECT_FALSE(is_rendering_remotely_); 213 controller_->OnMetadataChanged(EncryptedMetadata());
216 remoting_renderer_controller_->OnMetadataChanged(EncryptedMetadata()); 214 controller_->OnRemotePlaybackDisabled(false);
217 remoting_renderer_controller_->OnRemotePlaybackDisabled(false); 215 controller_->OnPlaying();
218 remoting_renderer_controller_->OnPlaying(); 216 RunUntilIdle();
219 RunUntilIdle(); 217 EXPECT_FALSE(is_rendering_remotely_);
220 EXPECT_FALSE(is_rendering_remotely_); 218 const scoped_refptr<SharedSession> cdm_shared_session =
221 scoped_refptr<RemotingSourceImpl> cdm_remoting_source_impl = 219 FakeRemoterFactory::CreateSharedSession(false);
222 CreateRemotingSourceImpl(false); 220 std::unique_ptr<RemotingCdmController> cdm_controller =
223 std::unique_ptr<RemotingCdmController> remoting_cdm_controller = 221 base::MakeUnique<RemotingCdmController>(cdm_shared_session);
224 base::MakeUnique<RemotingCdmController>(cdm_remoting_source_impl); 222 cdm_shared_session->OnSinkAvailable(kAllCapabilities);
225 cdm_remoting_source_impl->OnSinkAvailable(kAllCapabilities); 223 cdm_controller->ShouldCreateRemotingCdm(
226 remoting_cdm_controller->ShouldCreateRemotingCdm(base::Bind( 224 base::Bind(&RendererControllerTest::CreateCdm, base::Unretained(this)));
227 &RemotingRendererControllerTest::CreateCdm, base::Unretained(this)));
228 RunUntilIdle(); 225 RunUntilIdle();
229 EXPECT_FALSE(is_rendering_remotely_); 226 EXPECT_FALSE(is_rendering_remotely_);
230 EXPECT_TRUE(is_remoting_cdm_); 227 EXPECT_TRUE(is_remoting_cdm_);
231 228
232 // Create a RemotingCdm with |remoting_cdm_controller|. 229 // Create a RemotingCdm with |cdm_controller|.
233 scoped_refptr<RemotingCdm> remoting_cdm = new RemotingCdm( 230 const scoped_refptr<RemotingCdm> remoting_cdm = new RemotingCdm(
234 std::string(), GURL(), CdmConfig(), SessionMessageCB(), SessionClosedCB(), 231 std::string(), GURL(), CdmConfig(), SessionMessageCB(), SessionClosedCB(),
235 SessionKeysChangeCB(), SessionExpirationUpdateCB(), CdmCreatedCB(), 232 SessionKeysChangeCB(), SessionExpirationUpdateCB(), CdmCreatedCB(),
236 std::move(remoting_cdm_controller)); 233 std::move(cdm_controller));
237 std::unique_ptr<RemotingCdmContext> remoting_cdm_context = 234 std::unique_ptr<RemotingCdmContext> remoting_cdm_context =
238 base::MakeUnique<RemotingCdmContext>(remoting_cdm.get()); 235 base::MakeUnique<RemotingCdmContext>(remoting_cdm.get());
239 remoting_renderer_controller_->OnSetCdm(remoting_cdm_context.get()); 236 controller_->OnSetCdm(remoting_cdm_context.get());
240 RunUntilIdle(); 237 RunUntilIdle();
241 EXPECT_TRUE(is_rendering_remotely_); 238 EXPECT_TRUE(is_rendering_remotely_);
242 239
243 // For encrypted contents, entering/exiting full screen has no effect. 240 // For encrypted contents, entering/exiting full screen has no effect.
244 remoting_renderer_controller_->OnEnteredFullscreen(); 241 controller_->OnEnteredFullscreen();
245 RunUntilIdle(); 242 RunUntilIdle();
246 EXPECT_TRUE(is_rendering_remotely_); 243 EXPECT_TRUE(is_rendering_remotely_);
247 remoting_renderer_controller_->OnExitedFullscreen(); 244 controller_->OnExitedFullscreen();
248 RunUntilIdle(); 245 RunUntilIdle();
249 EXPECT_TRUE(is_rendering_remotely_); 246 EXPECT_TRUE(is_rendering_remotely_);
250 247
251 EXPECT_NE(RemotingSessionState::SESSION_PERMANENTLY_STOPPED, 248 EXPECT_NE(SharedSession::SESSION_PERMANENTLY_STOPPED,
252 remoting_renderer_controller_->remoting_source()->state()); 249 controller_->session()->state());
253 cdm_remoting_source_impl->OnSinkGone(); 250 cdm_shared_session->OnSinkGone();
254 RunUntilIdle(); 251 RunUntilIdle();
255 EXPECT_EQ(RemotingSessionState::SESSION_PERMANENTLY_STOPPED, 252 EXPECT_EQ(SharedSession::SESSION_PERMANENTLY_STOPPED,
256 remoting_renderer_controller_->remoting_source()->state()); 253 controller_->session()->state());
257 // Don't switch renderer in this case. Still using the remoting renderer to 254 // Don't switch renderer in this case. Still using the remoting renderer to
258 // show the failure interstitial. 255 // show the failure interstitial.
259 EXPECT_TRUE(is_rendering_remotely_); 256 EXPECT_TRUE(is_rendering_remotely_);
260 } 257 }
261 258
262 TEST_F(RemotingRendererControllerTest, EncryptedWithLocalCdm) { 259 TEST_F(RendererControllerTest, EncryptedWithLocalCdm) {
263 EXPECT_FALSE(is_rendering_remotely_); 260 EXPECT_FALSE(is_rendering_remotely_);
264 scoped_refptr<RemotingSourceImpl> renderer_remoting_source_impl = 261 const scoped_refptr<SharedSession> initial_shared_session =
265 CreateRemotingSourceImpl(false); 262 FakeRemoterFactory::CreateSharedSession(false);
266 remoting_renderer_controller_ = base::MakeUnique<RemotingRendererController>( 263 controller_ = base::MakeUnique<RendererController>(initial_shared_session);
267 renderer_remoting_source_impl); 264 controller_->SetSwitchRendererCallback(base::Bind(
268 remoting_renderer_controller_->SetSwitchRendererCallback(base::Bind( 265 &RendererControllerTest::ToggleRenderer, base::Unretained(this)));
269 &RemotingRendererControllerTest::ToggleRenderer, base::Unretained(this))); 266 RunUntilIdle();
270 RunUntilIdle(); 267 EXPECT_FALSE(is_rendering_remotely_);
271 EXPECT_FALSE(is_rendering_remotely_); 268 initial_shared_session->OnSinkAvailable(kAllCapabilities);
272 renderer_remoting_source_impl->OnSinkAvailable(kAllCapabilities); 269 RunUntilIdle();
273 RunUntilIdle(); 270 EXPECT_FALSE(is_rendering_remotely_);
274 EXPECT_FALSE(is_rendering_remotely_); 271 controller_->OnEnteredFullscreen();
275 remoting_renderer_controller_->OnEnteredFullscreen(); 272 RunUntilIdle();
276 RunUntilIdle(); 273 EXPECT_FALSE(is_rendering_remotely_);
277 EXPECT_FALSE(is_rendering_remotely_); 274 controller_->OnMetadataChanged(EncryptedMetadata());
278 remoting_renderer_controller_->OnMetadataChanged(EncryptedMetadata()); 275 RunUntilIdle();
279 RunUntilIdle(); 276 EXPECT_FALSE(is_rendering_remotely_);
280 EXPECT_FALSE(is_rendering_remotely_); 277 controller_->OnRemotePlaybackDisabled(false);
281 remoting_renderer_controller_->OnRemotePlaybackDisabled(false); 278 RunUntilIdle();
282 RunUntilIdle(); 279 EXPECT_FALSE(is_rendering_remotely_);
283 EXPECT_FALSE(is_rendering_remotely_); 280 controller_->OnPlaying();
284 remoting_renderer_controller_->OnPlaying(); 281 RunUntilIdle();
285 RunUntilIdle(); 282 EXPECT_FALSE(is_rendering_remotely_);
286 EXPECT_FALSE(is_rendering_remotely_); 283
287 284 const scoped_refptr<SharedSession> cdm_shared_session =
288 scoped_refptr<RemotingSourceImpl> cdm_remoting_source_impl = 285 FakeRemoterFactory::CreateSharedSession(true);
289 CreateRemotingSourceImpl(true); 286 std::unique_ptr<RemotingCdmController> cdm_controller =
290 std::unique_ptr<RemotingCdmController> remoting_cdm_controller = 287 base::MakeUnique<RemotingCdmController>(cdm_shared_session);
291 base::MakeUnique<RemotingCdmController>(cdm_remoting_source_impl); 288 cdm_shared_session->OnSinkAvailable(kAllCapabilities);
292 cdm_remoting_source_impl->OnSinkAvailable(kAllCapabilities); 289 cdm_controller->ShouldCreateRemotingCdm(
293 remoting_cdm_controller->ShouldCreateRemotingCdm(base::Bind( 290 base::Bind(&RendererControllerTest::CreateCdm, base::Unretained(this)));
294 &RemotingRendererControllerTest::CreateCdm, base::Unretained(this)));
295 RunUntilIdle(); 291 RunUntilIdle();
296 EXPECT_FALSE(is_rendering_remotely_); 292 EXPECT_FALSE(is_rendering_remotely_);
297 EXPECT_FALSE(is_remoting_cdm_); 293 EXPECT_FALSE(is_remoting_cdm_);
298 } 294 }
299 295
300 TEST_F(RemotingRendererControllerTest, EncryptedWithFailedRemotingCdm) { 296 TEST_F(RendererControllerTest, EncryptedWithFailedRemotingCdm) {
301 EXPECT_FALSE(is_rendering_remotely_); 297 EXPECT_FALSE(is_rendering_remotely_);
302 remoting_renderer_controller_ = base::MakeUnique<RemotingRendererController>( 298 controller_ = base::MakeUnique<RendererController>(
303 CreateRemotingSourceImpl(false)); 299 FakeRemoterFactory::CreateSharedSession(false));
304 remoting_renderer_controller_->SetSwitchRendererCallback(base::Bind( 300 controller_->SetSwitchRendererCallback(base::Bind(
305 &RemotingRendererControllerTest::ToggleRenderer, base::Unretained(this))); 301 &RendererControllerTest::ToggleRenderer, base::Unretained(this)));
306 RunUntilIdle(); 302 RunUntilIdle();
307 EXPECT_FALSE(is_rendering_remotely_); 303 EXPECT_FALSE(is_rendering_remotely_);
308 remoting_renderer_controller_->OnEnteredFullscreen(); 304 controller_->OnEnteredFullscreen();
309 RunUntilIdle(); 305 RunUntilIdle();
310 EXPECT_FALSE(is_rendering_remotely_); 306 EXPECT_FALSE(is_rendering_remotely_);
311 remoting_renderer_controller_->OnMetadataChanged(EncryptedMetadata()); 307 controller_->OnMetadataChanged(EncryptedMetadata());
312 RunUntilIdle(); 308 RunUntilIdle();
313 EXPECT_FALSE(is_rendering_remotely_); 309 EXPECT_FALSE(is_rendering_remotely_);
314 remoting_renderer_controller_->OnRemotePlaybackDisabled(false); 310 controller_->OnRemotePlaybackDisabled(false);
315 RunUntilIdle(); 311 RunUntilIdle();
316 EXPECT_FALSE(is_rendering_remotely_); 312 EXPECT_FALSE(is_rendering_remotely_);
317 remoting_renderer_controller_->OnPlaying(); 313 controller_->OnPlaying();
318 RunUntilIdle(); 314 RunUntilIdle();
319 EXPECT_FALSE(is_rendering_remotely_); 315 EXPECT_FALSE(is_rendering_remotely_);
320 316
321 scoped_refptr<RemotingSourceImpl> cdm_remoting_source_impl = 317 const scoped_refptr<SharedSession> cdm_shared_session =
322 CreateRemotingSourceImpl(false); 318 FakeRemoterFactory::CreateSharedSession(false);
323 std::unique_ptr<RemotingCdmController> remoting_cdm_controller = 319 std::unique_ptr<RemotingCdmController> cdm_controller =
324 base::MakeUnique<RemotingCdmController>(cdm_remoting_source_impl); 320 base::MakeUnique<RemotingCdmController>(cdm_shared_session);
325 cdm_remoting_source_impl->OnSinkAvailable(kAllCapabilities); 321 cdm_shared_session->OnSinkAvailable(kAllCapabilities);
326 remoting_cdm_controller->ShouldCreateRemotingCdm(base::Bind( 322 cdm_controller->ShouldCreateRemotingCdm(
327 &RemotingRendererControllerTest::CreateCdm, base::Unretained(this))); 323 base::Bind(&RendererControllerTest::CreateCdm, base::Unretained(this)));
328 RunUntilIdle(); 324 RunUntilIdle();
329 EXPECT_FALSE(is_rendering_remotely_); 325 EXPECT_FALSE(is_rendering_remotely_);
330 EXPECT_TRUE(is_remoting_cdm_); 326 EXPECT_TRUE(is_remoting_cdm_);
331 327
332 cdm_remoting_source_impl->OnSinkGone(); 328 cdm_shared_session->OnSinkGone();
333 RunUntilIdle(); 329 RunUntilIdle();
334 EXPECT_FALSE(is_rendering_remotely_); 330 EXPECT_FALSE(is_rendering_remotely_);
335 EXPECT_NE(RemotingSessionState::SESSION_PERMANENTLY_STOPPED, 331 EXPECT_NE(SharedSession::SESSION_PERMANENTLY_STOPPED,
336 remoting_renderer_controller_->remoting_source()->state()); 332 controller_->session()->state());
337 333
338 scoped_refptr<RemotingCdm> remoting_cdm = new RemotingCdm( 334 const scoped_refptr<RemotingCdm> remoting_cdm = new RemotingCdm(
339 std::string(), GURL(), CdmConfig(), SessionMessageCB(), SessionClosedCB(), 335 std::string(), GURL(), CdmConfig(), SessionMessageCB(), SessionClosedCB(),
340 SessionKeysChangeCB(), SessionExpirationUpdateCB(), CdmCreatedCB(), 336 SessionKeysChangeCB(), SessionExpirationUpdateCB(), CdmCreatedCB(),
341 std::move(remoting_cdm_controller)); 337 std::move(cdm_controller));
342 std::unique_ptr<RemotingCdmContext> remoting_cdm_context = 338 std::unique_ptr<RemotingCdmContext> remoting_cdm_context =
343 base::MakeUnique<RemotingCdmContext>(remoting_cdm.get()); 339 base::MakeUnique<RemotingCdmContext>(remoting_cdm.get());
344 remoting_renderer_controller_->OnSetCdm(remoting_cdm_context.get()); 340 controller_->OnSetCdm(remoting_cdm_context.get());
345 RunUntilIdle(); 341 RunUntilIdle();
346 // Switch to using the remoting renderer, even when the remoting CDM session 342 // Switch to using the remoting renderer, even when the remoting CDM session
347 // was already terminated, to show the failure interstitial. 343 // was already terminated, to show the failure interstitial.
348 EXPECT_TRUE(is_rendering_remotely_); 344 EXPECT_TRUE(is_rendering_remotely_);
349 EXPECT_EQ(RemotingSessionState::SESSION_PERMANENTLY_STOPPED, 345 EXPECT_EQ(SharedSession::SESSION_PERMANENTLY_STOPPED,
350 remoting_renderer_controller_->remoting_source()->state()); 346 controller_->session()->state());
351 } 347 }
352 348
349 } // namespace remoting
353 } // namespace media 350 } // namespace media
OLDNEW
« no previous file with comments | « media/remoting/renderer_controller.cc ('k') | media/remoting/rpc.proto » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698