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

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

Issue 2289543005: Allow suspension prior to reaching kHaveFutureData. (Closed)
Patch Set: Fix pause timer. 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 164 matching lines...) Expand 10 before | Expand all | Expand 10 after
175 175
176 TEST_F(RendererWebMediaPlayerDelegateTest, IdleDelegatesAreSuspended) { 176 TEST_F(RendererWebMediaPlayerDelegateTest, IdleDelegatesAreSuspended) {
177 // Start the tick clock off at a non-null value. 177 // Start the tick clock off at a non-null value.
178 base::SimpleTestTickClock tick_clock; 178 base::SimpleTestTickClock tick_clock;
179 tick_clock.Advance(base::TimeDelta::FromSeconds(1234)); 179 tick_clock.Advance(base::TimeDelta::FromSeconds(1234));
180 180
181 const base::TimeDelta kIdleTimeout = base::TimeDelta::FromSeconds(2); 181 const base::TimeDelta kIdleTimeout = base::TimeDelta::FromSeconds(2);
182 delegate_manager_->SetIdleCleanupParamsForTesting(kIdleTimeout, &tick_clock); 182 delegate_manager_->SetIdleCleanupParamsForTesting(kIdleTimeout, &tick_clock);
183 EXPECT_FALSE(delegate_manager_->IsIdleCleanupTimerRunningForTesting()); 183 EXPECT_FALSE(delegate_manager_->IsIdleCleanupTimerRunningForTesting());
184 184
185 // Just adding an observer should not start the idle timer. 185 // Just adding an observer should start the idle timer.
186 testing::StrictMock<MockWebMediaPlayerDelegateObserver> observer_1; 186 testing::StrictMock<MockWebMediaPlayerDelegateObserver> observer_1;
187 const int delegate_id_1 = delegate_manager_->AddObserver(&observer_1); 187 const int delegate_id_1 = delegate_manager_->AddObserver(&observer_1);
188 EXPECT_FALSE(delegate_manager_->IsIdleCleanupTimerRunningForTesting()); 188 EXPECT_TRUE(delegate_manager_->IsIdleCleanupTimerRunningForTesting());
189 189
190 // Starting playback should not have an idle timer. 190 // Starting playback should not have an idle timer.
191 delegate_manager_->DidPlay(delegate_id_1, true, true, false, 191 delegate_manager_->DidPlay(delegate_id_1, true, true, false,
192 media::MediaContentType::Persistent); 192 media::MediaContentType::Persistent);
193 EXPECT_FALSE(delegate_manager_->IsIdleCleanupTimerRunningForTesting()); 193 EXPECT_FALSE(delegate_manager_->IsIdleCleanupTimerRunningForTesting());
194 194
195 // Never calling DidPlay() but calling DidPause() should count as idle. 195 // Never calling DidPlay() but calling DidPause() should count as idle.
196 testing::StrictMock<MockWebMediaPlayerDelegateObserver> observer_2; 196 testing::StrictMock<MockWebMediaPlayerDelegateObserver> observer_2;
197 const int delegate_id_2 = delegate_manager_->AddObserver(&observer_2); 197 const int delegate_id_2 = delegate_manager_->AddObserver(&observer_2);
198 delegate_manager_->DidPause(delegate_id_2, false); 198 delegate_manager_->DidPause(delegate_id_2, false);
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after
262 // Start the tick clock off at a non-null value. 262 // Start the tick clock off at a non-null value.
263 base::SimpleTestTickClock tick_clock; 263 base::SimpleTestTickClock tick_clock;
264 tick_clock.Advance(base::TimeDelta::FromSeconds(1234)); 264 tick_clock.Advance(base::TimeDelta::FromSeconds(1234));
265 265
266 const base::TimeDelta kIdleTimeout = base::TimeDelta::FromSeconds(2); 266 const base::TimeDelta kIdleTimeout = base::TimeDelta::FromSeconds(2);
267 delegate_manager_->SetIdleCleanupParamsForTesting(kIdleTimeout, &tick_clock); 267 delegate_manager_->SetIdleCleanupParamsForTesting(kIdleTimeout, &tick_clock);
268 EXPECT_FALSE(delegate_manager_->IsIdleCleanupTimerRunningForTesting()); 268 EXPECT_FALSE(delegate_manager_->IsIdleCleanupTimerRunningForTesting());
269 269
270 testing::StrictMock<MockWebMediaPlayerDelegateObserver> observer_1; 270 testing::StrictMock<MockWebMediaPlayerDelegateObserver> observer_1;
271 const int delegate_id_1 = delegate_manager_->AddObserver(&observer_1); 271 const int delegate_id_1 = delegate_manager_->AddObserver(&observer_1);
272 EXPECT_FALSE(delegate_manager_->IsIdleCleanupTimerRunningForTesting()); 272 EXPECT_TRUE(delegate_manager_->IsIdleCleanupTimerRunningForTesting());
273 273
274 // Calling DidPause() should instantly queue the timeout task. 274 // Calling DidPause() should instantly queue the timeout task.
275 delegate_manager_->DidPause(delegate_id_1, false); 275 delegate_manager_->DidPause(delegate_id_1, false);
276 EXPECT_TRUE(delegate_manager_->IsIdleCleanupTimerRunningForTesting()); 276 EXPECT_TRUE(delegate_manager_->IsIdleCleanupTimerRunningForTesting());
277 277
278 // Wait for the suspend request, but don't call PlayerGone(). 278 // Wait for the suspend request, but don't call PlayerGone().
279 EXPECT_CALL(observer_1, OnSuspendRequested(false)); 279 EXPECT_CALL(observer_1, OnSuspendRequested(false)).Times(testing::AtLeast(1));
280 base::RunLoop run_loop; 280 base::RunLoop run_loop;
281 base::ThreadTaskRunnerHandle::Get()->PostTask(FROM_HERE, 281 base::ThreadTaskRunnerHandle::Get()->PostTask(FROM_HERE,
282 run_loop.QuitClosure()); 282 run_loop.QuitClosure());
283 tick_clock.Advance(kIdleTimeout + base::TimeDelta::FromMicroseconds(1)); 283 tick_clock.Advance(kIdleTimeout + base::TimeDelta::FromMicroseconds(1));
284 run_loop.Run(); 284 run_loop.Run();
285 285
286 // Even though the player did not call PlayerGone() it should be removed from 286 // Even though the player did not call PlayerGone() it should be removed from
287 // future idle cleanup polls. 287 // future idle cleanup polls.
288 EXPECT_FALSE(delegate_manager_->IsIdleCleanupTimerRunningForTesting()); 288 EXPECT_FALSE(delegate_manager_->IsIdleCleanupTimerRunningForTesting());
289 delegate_manager_->RemoveObserver(delegate_id_1); 289 delegate_manager_->RemoveObserver(delegate_id_1);
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
331 EXPECT_FALSE(HasPlayingVideo(delegate_id)); 331 EXPECT_FALSE(HasPlayingVideo(delegate_id));
332 332
333 // Removing the observer also removes the video from the set. 333 // Removing the observer also removes the video from the set.
334 delegate_manager_->DidPlay(delegate_id, true, true, false, 334 delegate_manager_->DidPlay(delegate_id, true, true, false,
335 MediaContentType::Persistent); 335 MediaContentType::Persistent);
336 delegate_manager_->RemoveObserver(delegate_id); 336 delegate_manager_->RemoveObserver(delegate_id);
337 EXPECT_FALSE(HasPlayingVideo(delegate_id)); 337 EXPECT_FALSE(HasPlayingVideo(delegate_id));
338 } 338 }
339 339
340 TEST_F(RendererWebMediaPlayerDelegateTest, IsPlayingBackgroundVideo) { 340 TEST_F(RendererWebMediaPlayerDelegateTest, IsPlayingBackgroundVideo) {
341 MockWebMediaPlayerDelegateObserver observer; 341 testing::NiceMock<MockWebMediaPlayerDelegateObserver> observer;
342 int delegate_id = delegate_manager_->AddObserver(&observer); 342 int delegate_id = delegate_manager_->AddObserver(&observer);
343 EXPECT_FALSE(delegate_manager_->IsPlayingBackgroundVideo()); 343 EXPECT_FALSE(delegate_manager_->IsPlayingBackgroundVideo());
344 344
345 // Showing the frame always clears the flag. 345 // Showing the frame always clears the flag.
346 SetPlayingBackgroundVideo(true); 346 SetPlayingBackgroundVideo(true);
347 delegate_manager_->WasShown(); 347 delegate_manager_->WasShown();
348 EXPECT_FALSE(delegate_manager_->IsPlayingBackgroundVideo()); 348 EXPECT_FALSE(delegate_manager_->IsPlayingBackgroundVideo());
349 349
350 // Pausing anything other than a local playing video doesn't affect the flag. 350 // Pausing anything other than a local playing video doesn't affect the flag.
351 SetPlayingBackgroundVideo(true); 351 SetPlayingBackgroundVideo(true);
(...skipping 17 matching lines...) Expand all
369 369
370 delegate_manager_->DidPlay(delegate_id, true, true, false, 370 delegate_manager_->DidPlay(delegate_id, true, true, false,
371 MediaContentType::Persistent); 371 MediaContentType::Persistent);
372 CallOnMediaDelegatePlay(delegate_id); 372 CallOnMediaDelegatePlay(delegate_id);
373 EXPECT_NE(old_value, delegate_manager_->IsPlayingBackgroundVideo()); 373 EXPECT_NE(old_value, delegate_manager_->IsPlayingBackgroundVideo());
374 } 374 }
375 375
376 #if defined(OS_ANDROID) 376 #if defined(OS_ANDROID)
377 377
378 TEST_F(RendererWebMediaPlayerDelegateTest, Histograms) { 378 TEST_F(RendererWebMediaPlayerDelegateTest, Histograms) {
379 MockWebMediaPlayerDelegateObserver observer; 379 testing::NiceMock<MockWebMediaPlayerDelegateObserver> observer;
380 int delegate_id = delegate_manager_->AddObserver(&observer); 380 int delegate_id = delegate_manager_->AddObserver(&observer);
381 base::HistogramTester histogram_tester; 381 base::HistogramTester histogram_tester;
382 histogram_tester.ExpectTotalCount("Media.Android.BackgroundVideoTime", 0); 382 histogram_tester.ExpectTotalCount("Media.Android.BackgroundVideoTime", 0);
383 383
384 // Pausing or showing doesn't record anything as background playback 384 // Pausing or showing doesn't record anything as background playback
385 // hasn't started yet. 385 // hasn't started yet.
386 delegate_manager_->DidPlay(delegate_id, true, true, false, 386 delegate_manager_->DidPlay(delegate_id, true, true, false,
387 MediaContentType::Persistent); 387 MediaContentType::Persistent);
388 CallOnMediaDelegatePause(delegate_id); 388 CallOnMediaDelegatePause(delegate_id);
389 histogram_tester.ExpectTotalCount("Media.Android.BackgroundVideoTime", 0); 389 histogram_tester.ExpectTotalCount("Media.Android.BackgroundVideoTime", 0);
(...skipping 14 matching lines...) Expand all
404 delegate_manager_->DidPlay(delegate_id, true, true, false, 404 delegate_manager_->DidPlay(delegate_id, true, true, false,
405 MediaContentType::Persistent); 405 MediaContentType::Persistent);
406 SetPlayingBackgroundVideo(true); 406 SetPlayingBackgroundVideo(true);
407 delegate_manager_->WasShown(); 407 delegate_manager_->WasShown();
408 histogram_tester.ExpectTotalCount("Media.Android.BackgroundVideoTime", 2); 408 histogram_tester.ExpectTotalCount("Media.Android.BackgroundVideoTime", 2);
409 } 409 }
410 410
411 #endif // OS_ANDROID 411 #endif // OS_ANDROID
412 412
413 } // namespace media 413 } // 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