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

Side by Side Diff: content/renderer/media/renderer_webmediaplayer_delegate_browsertest.cc

Issue 2333983002: Reduce number of active codecs on low end devices. (Closed)
Patch Set: Fix windows. Created 4 years, 3 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
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 <tuple> 5 #include <tuple>
6 6
7 #include "base/bind.h" 7 #include "base/bind.h"
8 #include "base/bind_helpers.h" 8 #include "base/bind_helpers.h"
9 #include "base/location.h" 9 #include "base/location.h"
10 #include "base/run_loop.h" 10 #include "base/run_loop.h"
(...skipping 155 matching lines...) Expand 10 before | Expand all | Expand 10 after
166 kTestMultiplier); 166 kTestMultiplier);
167 delegate_manager_->OnMessageReceived(volume_msg); 167 delegate_manager_->OnMessageReceived(volume_msg);
168 168
169 EXPECT_CALL(observer, OnSuspendRequested(true)); 169 EXPECT_CALL(observer, OnSuspendRequested(true));
170 MediaPlayerDelegateMsg_SuspendAllMediaPlayers suspend_msg(0); 170 MediaPlayerDelegateMsg_SuspendAllMediaPlayers suspend_msg(0);
171 delegate_manager_->OnMessageReceived(suspend_msg); 171 delegate_manager_->OnMessageReceived(suspend_msg);
172 172
173 delegate_manager_->RemoveObserver(delegate_id); 173 delegate_manager_->RemoveObserver(delegate_id);
174 } 174 }
175 175
176 TEST_F(RendererWebMediaPlayerDelegateTest, PlaySuspendsLowEndIdleDelegates) {
177 // Start the tick clock off at a non-null value.
178 base::SimpleTestTickClock tick_clock;
179 tick_clock.Advance(base::TimeDelta::FromSeconds(1234));
180
181 const base::TimeDelta kIdleTimeout = base::TimeDelta::FromSeconds(10);
182 delegate_manager_->SetIdleCleanupParamsForTesting(kIdleTimeout, &tick_clock,
183 true);
184 EXPECT_FALSE(delegate_manager_->IsIdleCleanupTimerRunningForTesting());
185
186 // Add two observers, both of which should keep the idle timer running.
187 testing::StrictMock<MockWebMediaPlayerDelegateObserver> observer_1;
188 const int delegate_id_1 = delegate_manager_->AddObserver(&observer_1);
189 EXPECT_TRUE(delegate_manager_->IsIdleCleanupTimerRunningForTesting());
190
191 testing::StrictMock<MockWebMediaPlayerDelegateObserver> observer_2;
192 const int delegate_id_2 = delegate_manager_->AddObserver(&observer_2);
193 EXPECT_TRUE(delegate_manager_->IsIdleCleanupTimerRunningForTesting());
194
195 // Calling play on the first player should suspend the other idle player.
196 EXPECT_CALL(observer_2, OnSuspendRequested(false))
197 .WillOnce(RunClosure(base::Bind(
198 &RendererWebMediaPlayerDelegate::PlayerGone,
199 base::Unretained(delegate_manager_.get()), delegate_id_2)));
200 base::RunLoop run_loop;
201 base::ThreadTaskRunnerHandle::Get()->PostTask(FROM_HERE,
202 run_loop.QuitClosure());
203 tick_clock.Advance(base::TimeDelta::FromMicroseconds(1));
204 delegate_manager_->DidPlay(delegate_id_1, true, true, false,
205 media::MediaContentType::Persistent);
206 run_loop.Run();
207 }
208
209 TEST_F(RendererWebMediaPlayerDelegateTest, MaxLowEndIdleDelegates) {
210 // Start the tick clock off at a non-null value.
211 base::SimpleTestTickClock tick_clock;
212 tick_clock.Advance(base::TimeDelta::FromSeconds(1234));
213
214 const base::TimeDelta kIdleTimeout = base::TimeDelta::FromSeconds(10);
215 delegate_manager_->SetIdleCleanupParamsForTesting(kIdleTimeout, &tick_clock,
216 true);
217 EXPECT_FALSE(delegate_manager_->IsIdleCleanupTimerRunningForTesting());
218
219 // Add two observers, both of which should keep the idle timer running.
220 testing::StrictMock<MockWebMediaPlayerDelegateObserver> observer_1;
221 const int delegate_id_1 = delegate_manager_->AddObserver(&observer_1);
222 EXPECT_TRUE(delegate_manager_->IsIdleCleanupTimerRunningForTesting());
223
224 testing::StrictMock<MockWebMediaPlayerDelegateObserver> observer_2;
225 const int delegate_id_2 = delegate_manager_->AddObserver(&observer_2);
226 EXPECT_TRUE(delegate_manager_->IsIdleCleanupTimerRunningForTesting());
227
228 tick_clock.Advance(base::TimeDelta::FromMicroseconds(1));
229
230 // Just adding a third idle observer should suspend the others.
231 EXPECT_CALL(observer_1, OnSuspendRequested(false))
232 .WillOnce(RunClosure(base::Bind(
233 &RendererWebMediaPlayerDelegate::PlayerGone,
234 base::Unretained(delegate_manager_.get()), delegate_id_1)));
235 EXPECT_CALL(observer_2, OnSuspendRequested(false))
236 .WillOnce(RunClosure(base::Bind(
237 &RendererWebMediaPlayerDelegate::PlayerGone,
238 base::Unretained(delegate_manager_.get()), delegate_id_2)));
239
240 base::RunLoop run_loop;
241 base::ThreadTaskRunnerHandle::Get()->PostTask(FROM_HERE,
242 run_loop.QuitClosure());
243
244 testing::StrictMock<MockWebMediaPlayerDelegateObserver> observer_3;
245 delegate_manager_->AddObserver(&observer_3);
246 EXPECT_TRUE(delegate_manager_->IsIdleCleanupTimerRunningForTesting());
247
248 run_loop.Run();
249 }
250
176 TEST_F(RendererWebMediaPlayerDelegateTest, IdleDelegatesAreSuspended) { 251 TEST_F(RendererWebMediaPlayerDelegateTest, IdleDelegatesAreSuspended) {
177 // Start the tick clock off at a non-null value. 252 // Start the tick clock off at a non-null value.
178 base::SimpleTestTickClock tick_clock; 253 base::SimpleTestTickClock tick_clock;
179 tick_clock.Advance(base::TimeDelta::FromSeconds(1234)); 254 tick_clock.Advance(base::TimeDelta::FromSeconds(1234));
180 255
181 const base::TimeDelta kIdleTimeout = base::TimeDelta::FromSeconds(2); 256 const base::TimeDelta kIdleTimeout = base::TimeDelta::FromSeconds(2);
182 delegate_manager_->SetIdleCleanupParamsForTesting(kIdleTimeout, &tick_clock); 257 delegate_manager_->SetIdleCleanupParamsForTesting(kIdleTimeout, &tick_clock,
258 false);
183 EXPECT_FALSE(delegate_manager_->IsIdleCleanupTimerRunningForTesting()); 259 EXPECT_FALSE(delegate_manager_->IsIdleCleanupTimerRunningForTesting());
184 260
185 // Just adding an observer should start the idle timer. 261 // Just adding an observer should start the idle timer.
186 testing::StrictMock<MockWebMediaPlayerDelegateObserver> observer_1; 262 testing::StrictMock<MockWebMediaPlayerDelegateObserver> observer_1;
187 const int delegate_id_1 = delegate_manager_->AddObserver(&observer_1); 263 const int delegate_id_1 = delegate_manager_->AddObserver(&observer_1);
188 EXPECT_TRUE(delegate_manager_->IsIdleCleanupTimerRunningForTesting()); 264 EXPECT_TRUE(delegate_manager_->IsIdleCleanupTimerRunningForTesting());
189 265
190 // Starting playback should not have an idle timer. 266 // Starting playback should not have an idle timer.
191 delegate_manager_->DidPlay(delegate_id_1, true, true, false, 267 delegate_manager_->DidPlay(delegate_id_1, true, true, false,
192 media::MediaContentType::Persistent); 268 media::MediaContentType::Persistent);
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after
257 delegate_manager_->RemoveObserver(delegate_id_3); 333 delegate_manager_->RemoveObserver(delegate_id_3);
258 EXPECT_FALSE(delegate_manager_->IsIdleCleanupTimerRunningForTesting()); 334 EXPECT_FALSE(delegate_manager_->IsIdleCleanupTimerRunningForTesting());
259 } 335 }
260 336
261 TEST_F(RendererWebMediaPlayerDelegateTest, IdleDelegatesIgnoresSuspendRequest) { 337 TEST_F(RendererWebMediaPlayerDelegateTest, IdleDelegatesIgnoresSuspendRequest) {
262 // Start the tick clock off at a non-null value. 338 // Start the tick clock off at a non-null value.
263 base::SimpleTestTickClock tick_clock; 339 base::SimpleTestTickClock tick_clock;
264 tick_clock.Advance(base::TimeDelta::FromSeconds(1234)); 340 tick_clock.Advance(base::TimeDelta::FromSeconds(1234));
265 341
266 const base::TimeDelta kIdleTimeout = base::TimeDelta::FromSeconds(2); 342 const base::TimeDelta kIdleTimeout = base::TimeDelta::FromSeconds(2);
267 delegate_manager_->SetIdleCleanupParamsForTesting(kIdleTimeout, &tick_clock); 343 delegate_manager_->SetIdleCleanupParamsForTesting(kIdleTimeout, &tick_clock,
344 false);
268 EXPECT_FALSE(delegate_manager_->IsIdleCleanupTimerRunningForTesting()); 345 EXPECT_FALSE(delegate_manager_->IsIdleCleanupTimerRunningForTesting());
269 346
270 testing::StrictMock<MockWebMediaPlayerDelegateObserver> observer_1; 347 testing::StrictMock<MockWebMediaPlayerDelegateObserver> observer_1;
271 const int delegate_id_1 = delegate_manager_->AddObserver(&observer_1); 348 const int delegate_id_1 = delegate_manager_->AddObserver(&observer_1);
272 EXPECT_TRUE(delegate_manager_->IsIdleCleanupTimerRunningForTesting()); 349 EXPECT_TRUE(delegate_manager_->IsIdleCleanupTimerRunningForTesting());
273 350
274 // Calling DidPause() should instantly queue the timeout task. 351 // Calling DidPause() should instantly queue the timeout task.
275 delegate_manager_->DidPause(delegate_id_1, false); 352 delegate_manager_->DidPause(delegate_id_1, false);
276 EXPECT_TRUE(delegate_manager_->IsIdleCleanupTimerRunningForTesting()); 353 EXPECT_TRUE(delegate_manager_->IsIdleCleanupTimerRunningForTesting());
277 354
(...skipping 126 matching lines...) Expand 10 before | Expand all | Expand 10 after
404 delegate_manager_->DidPlay(delegate_id, true, true, false, 481 delegate_manager_->DidPlay(delegate_id, true, true, false,
405 MediaContentType::Persistent); 482 MediaContentType::Persistent);
406 SetPlayingBackgroundVideo(true); 483 SetPlayingBackgroundVideo(true);
407 delegate_manager_->WasShown(); 484 delegate_manager_->WasShown();
408 histogram_tester.ExpectTotalCount("Media.Android.BackgroundVideoTime", 2); 485 histogram_tester.ExpectTotalCount("Media.Android.BackgroundVideoTime", 2);
409 } 486 }
410 487
411 #endif // OS_ANDROID 488 #endif // OS_ANDROID
412 489
413 } // namespace media 490 } // namespace media
OLDNEW
« no previous file with comments | « content/renderer/media/renderer_webmediaplayer_delegate.cc ('k') | media/blink/webmediaplayer_impl.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698