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

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

Issue 2355143002: Merge M54: "Allow suspension prior to reaching kHaveFutureData." (Closed)
Patch Set: 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 163 matching lines...) Expand 10 before | Expand all | Expand 10 after
174 174
175 TEST_F(RendererWebMediaPlayerDelegateTest, IdleDelegatesAreSuspended) { 175 TEST_F(RendererWebMediaPlayerDelegateTest, IdleDelegatesAreSuspended) {
176 // Start the tick clock off at a non-null value. 176 // Start the tick clock off at a non-null value.
177 base::SimpleTestTickClock tick_clock; 177 base::SimpleTestTickClock tick_clock;
178 tick_clock.Advance(base::TimeDelta::FromSeconds(1234)); 178 tick_clock.Advance(base::TimeDelta::FromSeconds(1234));
179 179
180 const base::TimeDelta kIdleTimeout = base::TimeDelta::FromSeconds(2); 180 const base::TimeDelta kIdleTimeout = base::TimeDelta::FromSeconds(2);
181 delegate_manager_->SetIdleCleanupParamsForTesting(kIdleTimeout, &tick_clock); 181 delegate_manager_->SetIdleCleanupParamsForTesting(kIdleTimeout, &tick_clock);
182 EXPECT_FALSE(delegate_manager_->IsIdleCleanupTimerRunningForTesting()); 182 EXPECT_FALSE(delegate_manager_->IsIdleCleanupTimerRunningForTesting());
183 183
184 // Just adding an observer should not start the idle timer. 184 // Just adding an observer should start the idle timer.
185 testing::StrictMock<MockWebMediaPlayerDelegateObserver> observer_1; 185 testing::StrictMock<MockWebMediaPlayerDelegateObserver> observer_1;
186 const int delegate_id_1 = delegate_manager_->AddObserver(&observer_1); 186 const int delegate_id_1 = delegate_manager_->AddObserver(&observer_1);
187 EXPECT_FALSE(delegate_manager_->IsIdleCleanupTimerRunningForTesting()); 187 EXPECT_TRUE(delegate_manager_->IsIdleCleanupTimerRunningForTesting());
188 188
189 // Starting playback should not have an idle timer. 189 // Starting playback should not have an idle timer.
190 delegate_manager_->DidPlay(delegate_id_1, true, true, false, 190 delegate_manager_->DidPlay(delegate_id_1, true, true, false,
191 base::TimeDelta()); 191 base::TimeDelta());
192 EXPECT_FALSE(delegate_manager_->IsIdleCleanupTimerRunningForTesting()); 192 EXPECT_FALSE(delegate_manager_->IsIdleCleanupTimerRunningForTesting());
193 193
194 // Never calling DidPlay() but calling DidPause() should count as idle. 194 // Never calling DidPlay() but calling DidPause() should count as idle.
195 testing::StrictMock<MockWebMediaPlayerDelegateObserver> observer_2; 195 testing::StrictMock<MockWebMediaPlayerDelegateObserver> observer_2;
196 const int delegate_id_2 = delegate_manager_->AddObserver(&observer_2); 196 const int delegate_id_2 = delegate_manager_->AddObserver(&observer_2);
197 delegate_manager_->DidPause(delegate_id_2, false); 197 delegate_manager_->DidPause(delegate_id_2, false);
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after
261 // Start the tick clock off at a non-null value. 261 // Start the tick clock off at a non-null value.
262 base::SimpleTestTickClock tick_clock; 262 base::SimpleTestTickClock tick_clock;
263 tick_clock.Advance(base::TimeDelta::FromSeconds(1234)); 263 tick_clock.Advance(base::TimeDelta::FromSeconds(1234));
264 264
265 const base::TimeDelta kIdleTimeout = base::TimeDelta::FromSeconds(2); 265 const base::TimeDelta kIdleTimeout = base::TimeDelta::FromSeconds(2);
266 delegate_manager_->SetIdleCleanupParamsForTesting(kIdleTimeout, &tick_clock); 266 delegate_manager_->SetIdleCleanupParamsForTesting(kIdleTimeout, &tick_clock);
267 EXPECT_FALSE(delegate_manager_->IsIdleCleanupTimerRunningForTesting()); 267 EXPECT_FALSE(delegate_manager_->IsIdleCleanupTimerRunningForTesting());
268 268
269 testing::StrictMock<MockWebMediaPlayerDelegateObserver> observer_1; 269 testing::StrictMock<MockWebMediaPlayerDelegateObserver> observer_1;
270 const int delegate_id_1 = delegate_manager_->AddObserver(&observer_1); 270 const int delegate_id_1 = delegate_manager_->AddObserver(&observer_1);
271 EXPECT_FALSE(delegate_manager_->IsIdleCleanupTimerRunningForTesting()); 271 EXPECT_TRUE(delegate_manager_->IsIdleCleanupTimerRunningForTesting());
272 272
273 // Calling DidPause() should instantly queue the timeout task. 273 // Calling DidPause() should instantly queue the timeout task.
274 delegate_manager_->DidPause(delegate_id_1, false); 274 delegate_manager_->DidPause(delegate_id_1, false);
275 EXPECT_TRUE(delegate_manager_->IsIdleCleanupTimerRunningForTesting()); 275 EXPECT_TRUE(delegate_manager_->IsIdleCleanupTimerRunningForTesting());
276 276
277 // Wait for the suspend request, but don't call PlayerGone(). 277 // Wait for the suspend request, but don't call PlayerGone().
278 EXPECT_CALL(observer_1, OnSuspendRequested(false)); 278 EXPECT_CALL(observer_1, OnSuspendRequested(false)).Times(testing::AtLeast(1));
279 base::RunLoop run_loop; 279 base::RunLoop run_loop;
280 base::ThreadTaskRunnerHandle::Get()->PostTask(FROM_HERE, 280 base::ThreadTaskRunnerHandle::Get()->PostTask(FROM_HERE,
281 run_loop.QuitClosure()); 281 run_loop.QuitClosure());
282 tick_clock.Advance(kIdleTimeout + base::TimeDelta::FromMicroseconds(1)); 282 tick_clock.Advance(kIdleTimeout + base::TimeDelta::FromMicroseconds(1));
283 run_loop.Run(); 283 run_loop.Run();
284 284
285 // Even though the player did not call PlayerGone() it should be removed from 285 // Even though the player did not call PlayerGone() it should be removed from
286 // future idle cleanup polls. 286 // future idle cleanup polls.
287 EXPECT_FALSE(delegate_manager_->IsIdleCleanupTimerRunningForTesting()); 287 EXPECT_FALSE(delegate_manager_->IsIdleCleanupTimerRunningForTesting());
288 delegate_manager_->RemoveObserver(delegate_id_1); 288 delegate_manager_->RemoveObserver(delegate_id_1);
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
325 delegate_id, false, true, false, base::TimeDelta()); 325 delegate_id, false, true, false, base::TimeDelta());
326 EXPECT_FALSE(HasPlayingVideo(delegate_id)); 326 EXPECT_FALSE(HasPlayingVideo(delegate_id));
327 327
328 // Removing the observer also removes the video from the set. 328 // Removing the observer also removes the video from the set.
329 delegate_manager_->DidPlay(delegate_id, true, true, false, base::TimeDelta()); 329 delegate_manager_->DidPlay(delegate_id, true, true, false, base::TimeDelta());
330 delegate_manager_->RemoveObserver(delegate_id); 330 delegate_manager_->RemoveObserver(delegate_id);
331 EXPECT_FALSE(HasPlayingVideo(delegate_id)); 331 EXPECT_FALSE(HasPlayingVideo(delegate_id));
332 } 332 }
333 333
334 TEST_F(RendererWebMediaPlayerDelegateTest, IsPlayingBackgroundVideo) { 334 TEST_F(RendererWebMediaPlayerDelegateTest, IsPlayingBackgroundVideo) {
335 MockWebMediaPlayerDelegateObserver observer; 335 testing::NiceMock<MockWebMediaPlayerDelegateObserver> observer;
336 int delegate_id = delegate_manager_->AddObserver(&observer); 336 int delegate_id = delegate_manager_->AddObserver(&observer);
337 EXPECT_FALSE(delegate_manager_->IsPlayingBackgroundVideo()); 337 EXPECT_FALSE(delegate_manager_->IsPlayingBackgroundVideo());
338 338
339 // Showing the frame always clears the flag. 339 // Showing the frame always clears the flag.
340 SetPlayingBackgroundVideo(true); 340 SetPlayingBackgroundVideo(true);
341 delegate_manager_->WasShown(); 341 delegate_manager_->WasShown();
342 EXPECT_FALSE(delegate_manager_->IsPlayingBackgroundVideo()); 342 EXPECT_FALSE(delegate_manager_->IsPlayingBackgroundVideo());
343 343
344 // Pausing anything other than a local playing video doesn't affect the flag. 344 // Pausing anything other than a local playing video doesn't affect the flag.
345 SetPlayingBackgroundVideo(true); 345 SetPlayingBackgroundVideo(true);
(...skipping 17 matching lines...) Expand all
363 363
364 delegate_manager_->DidPlay( 364 delegate_manager_->DidPlay(
365 delegate_id, true, true, false, base::TimeDelta()); 365 delegate_id, true, true, false, base::TimeDelta());
366 CallOnMediaDelegatePlay(delegate_id); 366 CallOnMediaDelegatePlay(delegate_id);
367 EXPECT_NE(old_value, delegate_manager_->IsPlayingBackgroundVideo()); 367 EXPECT_NE(old_value, delegate_manager_->IsPlayingBackgroundVideo());
368 } 368 }
369 369
370 #if defined(OS_ANDROID) 370 #if defined(OS_ANDROID)
371 371
372 TEST_F(RendererWebMediaPlayerDelegateTest, Histograms) { 372 TEST_F(RendererWebMediaPlayerDelegateTest, Histograms) {
373 MockWebMediaPlayerDelegateObserver observer; 373 testing::NiceMock<MockWebMediaPlayerDelegateObserver> observer;
374 int delegate_id = delegate_manager_->AddObserver(&observer); 374 int delegate_id = delegate_manager_->AddObserver(&observer);
375 base::HistogramTester histogram_tester; 375 base::HistogramTester histogram_tester;
376 histogram_tester.ExpectTotalCount("Media.Android.BackgroundVideoTime", 0); 376 histogram_tester.ExpectTotalCount("Media.Android.BackgroundVideoTime", 0);
377 377
378 // Pausing or showing doesn't record anything as background playback 378 // Pausing or showing doesn't record anything as background playback
379 // hasn't started yet. 379 // hasn't started yet.
380 delegate_manager_->DidPlay( 380 delegate_manager_->DidPlay(
381 delegate_id, true, true, false, base::TimeDelta()); 381 delegate_id, true, true, false, base::TimeDelta());
382 CallOnMediaDelegatePause(delegate_id); 382 CallOnMediaDelegatePause(delegate_id);
383 histogram_tester.ExpectTotalCount("Media.Android.BackgroundVideoTime", 0); 383 histogram_tester.ExpectTotalCount("Media.Android.BackgroundVideoTime", 0);
(...skipping 14 matching lines...) Expand all
398 delegate_manager_->DidPlay( 398 delegate_manager_->DidPlay(
399 delegate_id, true, true, false, base::TimeDelta()); 399 delegate_id, true, true, false, base::TimeDelta());
400 SetPlayingBackgroundVideo(true); 400 SetPlayingBackgroundVideo(true);
401 delegate_manager_->WasShown(); 401 delegate_manager_->WasShown();
402 histogram_tester.ExpectTotalCount("Media.Android.BackgroundVideoTime", 2); 402 histogram_tester.ExpectTotalCount("Media.Android.BackgroundVideoTime", 2);
403 } 403 }
404 404
405 #endif // OS_ANDROID 405 #endif // OS_ANDROID
406 406
407 } // namespace media 407 } // namespace media
OLDNEW
« no previous file with comments | « content/renderer/media/renderer_webmediaplayer_delegate.cc ('k') | media/blink/webmediaplayer_impl.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698