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

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

Issue 2367253007: Prevent reentrant cleanup events for idle delegates. (Closed)
Patch Set: Comments. Created 4 years, 2 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 | « content/renderer/media/renderer_webmediaplayer_delegate.cc ('k') | no next file » | 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 <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 230 matching lines...) Expand 10 before | Expand all | Expand 10 after
241 base::ThreadTaskRunnerHandle::Get()->PostTask(FROM_HERE, 241 base::ThreadTaskRunnerHandle::Get()->PostTask(FROM_HERE,
242 run_loop.QuitClosure()); 242 run_loop.QuitClosure());
243 243
244 testing::StrictMock<MockWebMediaPlayerDelegateObserver> observer_3; 244 testing::StrictMock<MockWebMediaPlayerDelegateObserver> observer_3;
245 delegate_manager_->AddObserver(&observer_3); 245 delegate_manager_->AddObserver(&observer_3);
246 EXPECT_TRUE(delegate_manager_->IsIdleCleanupTimerRunningForTesting()); 246 EXPECT_TRUE(delegate_manager_->IsIdleCleanupTimerRunningForTesting());
247 247
248 run_loop.Run(); 248 run_loop.Run();
249 } 249 }
250 250
251 TEST_F(RendererWebMediaPlayerDelegateTest, ReentrantIdleDelegates) {
252 // Start the tick clock off at a non-null value.
253 base::SimpleTestTickClock tick_clock;
254 tick_clock.Advance(base::TimeDelta::FromSeconds(1234));
255
256 const base::TimeDelta kIdleTimeout = base::TimeDelta::FromSeconds(10);
257 delegate_manager_->SetIdleCleanupParamsForTesting(kIdleTimeout, &tick_clock,
258 true);
259 EXPECT_FALSE(delegate_manager_->IsIdleCleanupTimerRunningForTesting());
260
261 // Add two observers, both of which should keep the idle timer running.
262 testing::StrictMock<MockWebMediaPlayerDelegateObserver> observer_1;
263 const int delegate_id_1 = delegate_manager_->AddObserver(&observer_1);
264 EXPECT_TRUE(delegate_manager_->IsIdleCleanupTimerRunningForTesting());
265
266 testing::StrictMock<MockWebMediaPlayerDelegateObserver> observer_2;
267 const int delegate_id_2 = delegate_manager_->AddObserver(&observer_2);
268 EXPECT_TRUE(delegate_manager_->IsIdleCleanupTimerRunningForTesting());
269
270 testing::StrictMock<MockWebMediaPlayerDelegateObserver> observer_3;
271 EXPECT_CALL(observer_1, OnSuspendRequested(false))
272 .WillOnce(RunClosure(base::Bind(&RendererWebMediaPlayerDelegate::DidPause,
273 base::Unretained(delegate_manager_.get()),
274 delegate_id_1, false)));
275 EXPECT_CALL(observer_2, OnSuspendRequested(false))
276 .WillOnce(RunClosure(base::Bind(&RendererWebMediaPlayerDelegate::DidPause,
277 base::Unretained(delegate_manager_.get()),
278 delegate_id_2, false)));
279 base::RunLoop run_loop;
280 base::ThreadTaskRunnerHandle::Get()->PostTask(FROM_HERE,
281 run_loop.QuitClosure());
282 tick_clock.Advance(base::TimeDelta::FromMicroseconds(1));
283 // Adding the third observer should force idle cleanup.
284 delegate_manager_->AddObserver(&observer_3);
285 EXPECT_TRUE(delegate_manager_->IsIdleCleanupTimerRunningForTesting());
286 run_loop.Run();
287 }
288
251 TEST_F(RendererWebMediaPlayerDelegateTest, IdleDelegatesAreSuspended) { 289 TEST_F(RendererWebMediaPlayerDelegateTest, IdleDelegatesAreSuspended) {
252 // Start the tick clock off at a non-null value. 290 // Start the tick clock off at a non-null value.
253 base::SimpleTestTickClock tick_clock; 291 base::SimpleTestTickClock tick_clock;
254 tick_clock.Advance(base::TimeDelta::FromSeconds(1234)); 292 tick_clock.Advance(base::TimeDelta::FromSeconds(1234));
255 293
256 const base::TimeDelta kIdleTimeout = base::TimeDelta::FromSeconds(2); 294 const base::TimeDelta kIdleTimeout = base::TimeDelta::FromSeconds(2);
257 delegate_manager_->SetIdleCleanupParamsForTesting(kIdleTimeout, &tick_clock, 295 delegate_manager_->SetIdleCleanupParamsForTesting(kIdleTimeout, &tick_clock,
258 false); 296 false);
259 EXPECT_FALSE(delegate_manager_->IsIdleCleanupTimerRunningForTesting()); 297 EXPECT_FALSE(delegate_manager_->IsIdleCleanupTimerRunningForTesting());
260 298
(...skipping 220 matching lines...) Expand 10 before | Expand all | Expand 10 after
481 delegate_manager_->DidPlay(delegate_id, true, true, false, 519 delegate_manager_->DidPlay(delegate_id, true, true, false,
482 MediaContentType::Persistent); 520 MediaContentType::Persistent);
483 SetPlayingBackgroundVideo(true); 521 SetPlayingBackgroundVideo(true);
484 delegate_manager_->WasShown(); 522 delegate_manager_->WasShown();
485 histogram_tester.ExpectTotalCount("Media.Android.BackgroundVideoTime", 2); 523 histogram_tester.ExpectTotalCount("Media.Android.BackgroundVideoTime", 2);
486 } 524 }
487 525
488 #endif // OS_ANDROID 526 #endif // OS_ANDROID
489 527
490 } // namespace media 528 } // namespace media
OLDNEW
« no previous file with comments | « content/renderer/media/renderer_webmediaplayer_delegate.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698