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

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

Issue 1796403002: Don't mark a WebMediaPlayer as idle until it has size and first frame. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 9 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 "base/bind.h" 5 #include "base/bind.h"
6 #include "base/bind_helpers.h" 6 #include "base/bind_helpers.h"
7 #include "base/run_loop.h" 7 #include "base/run_loop.h"
8 #include "base/test/simple_test_tick_clock.h" 8 #include "base/test/simple_test_tick_clock.h"
9 #include "base/tuple.h" 9 #include "base/tuple.h"
10 #include "content/common/media/media_player_delegate_messages.h" 10 #include "content/common/media/media_player_delegate_messages.h"
(...skipping 142 matching lines...) Expand 10 before | Expand all | Expand 10 after
153 153
154 TEST_F(RendererWebMediaPlayerDelegateTest, IdleDelegatesAreSuspended) { 154 TEST_F(RendererWebMediaPlayerDelegateTest, IdleDelegatesAreSuspended) {
155 // Start the tick clock off at a non-null value. 155 // Start the tick clock off at a non-null value.
156 base::SimpleTestTickClock tick_clock; 156 base::SimpleTestTickClock tick_clock;
157 tick_clock.Advance(base::TimeDelta::FromSeconds(1234)); 157 tick_clock.Advance(base::TimeDelta::FromSeconds(1234));
158 158
159 const base::TimeDelta kIdleTimeout = base::TimeDelta::FromSeconds(2); 159 const base::TimeDelta kIdleTimeout = base::TimeDelta::FromSeconds(2);
160 delegate_manager_->SetIdleCleanupParamsForTesting(kIdleTimeout, &tick_clock); 160 delegate_manager_->SetIdleCleanupParamsForTesting(kIdleTimeout, &tick_clock);
161 EXPECT_FALSE(delegate_manager_->IsIdleCleanupTimerRunningForTesting()); 161 EXPECT_FALSE(delegate_manager_->IsIdleCleanupTimerRunningForTesting());
162 162
163 // Just adding an observer should not start the idle timer.
163 testing::StrictMock<MockWebMediaPlayerDelegateObserver> observer_1; 164 testing::StrictMock<MockWebMediaPlayerDelegateObserver> observer_1;
164 const int delegate_id_1 = delegate_manager_->AddObserver(&observer_1); 165 const int delegate_id_1 = delegate_manager_->AddObserver(&observer_1);
165 EXPECT_TRUE(delegate_manager_->IsIdleCleanupTimerRunningForTesting()); 166 EXPECT_FALSE(delegate_manager_->IsIdleCleanupTimerRunningForTesting());
167
168 // Starting playback should not have an idle timer.
166 delegate_manager_->DidPlay(delegate_id_1, true, true, false, 169 delegate_manager_->DidPlay(delegate_id_1, true, true, false,
167 base::TimeDelta()); 170 base::TimeDelta());
168 EXPECT_FALSE(delegate_manager_->IsIdleCleanupTimerRunningForTesting()); 171 EXPECT_FALSE(delegate_manager_->IsIdleCleanupTimerRunningForTesting());
169 172
170 // Never playing should count as idle. 173 // Never calling DidPlay() but calling DidPause() should count as idle.
171 testing::StrictMock<MockWebMediaPlayerDelegateObserver> observer_2; 174 testing::StrictMock<MockWebMediaPlayerDelegateObserver> observer_2;
172 const int delegate_id_2 = delegate_manager_->AddObserver(&observer_2); 175 const int delegate_id_2 = delegate_manager_->AddObserver(&observer_2);
176 delegate_manager_->DidPause(delegate_id_2, false);
173 EXPECT_TRUE(delegate_manager_->IsIdleCleanupTimerRunningForTesting()); 177 EXPECT_TRUE(delegate_manager_->IsIdleCleanupTimerRunningForTesting());
174 178
175 // Adding the observer should instantly queue the timeout task, once run the 179 // Adding the observer should instantly queue the timeout task, once run the
176 // second delegate should be expired while the first is kept alive. 180 // second delegate should be expired while the first is kept alive.
177 { 181 {
178 EXPECT_CALL(observer_2, OnSuspendRequested(false)) 182 EXPECT_CALL(observer_2, OnSuspendRequested(false))
179 .WillOnce(RunClosure(base::Bind( 183 .WillOnce(RunClosure(base::Bind(
180 &RendererWebMediaPlayerDelegate::PlayerGone, 184 &RendererWebMediaPlayerDelegate::PlayerGone,
181 base::Unretained(delegate_manager_.get()), delegate_id_2))); 185 base::Unretained(delegate_manager_.get()), delegate_id_2)));
182 base::RunLoop run_loop; 186 base::RunLoop run_loop;
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after
233 // Start the tick clock off at a non-null value. 237 // Start the tick clock off at a non-null value.
234 base::SimpleTestTickClock tick_clock; 238 base::SimpleTestTickClock tick_clock;
235 tick_clock.Advance(base::TimeDelta::FromSeconds(1234)); 239 tick_clock.Advance(base::TimeDelta::FromSeconds(1234));
236 240
237 const base::TimeDelta kIdleTimeout = base::TimeDelta::FromSeconds(2); 241 const base::TimeDelta kIdleTimeout = base::TimeDelta::FromSeconds(2);
238 delegate_manager_->SetIdleCleanupParamsForTesting(kIdleTimeout, &tick_clock); 242 delegate_manager_->SetIdleCleanupParamsForTesting(kIdleTimeout, &tick_clock);
239 EXPECT_FALSE(delegate_manager_->IsIdleCleanupTimerRunningForTesting()); 243 EXPECT_FALSE(delegate_manager_->IsIdleCleanupTimerRunningForTesting());
240 244
241 testing::StrictMock<MockWebMediaPlayerDelegateObserver> observer_1; 245 testing::StrictMock<MockWebMediaPlayerDelegateObserver> observer_1;
242 const int delegate_id_1 = delegate_manager_->AddObserver(&observer_1); 246 const int delegate_id_1 = delegate_manager_->AddObserver(&observer_1);
247 EXPECT_FALSE(delegate_manager_->IsIdleCleanupTimerRunningForTesting());
248
249 // Calling DidPause() should instantly queue the timeout task.
250 delegate_manager_->DidPause(delegate_id_1, false);
243 EXPECT_TRUE(delegate_manager_->IsIdleCleanupTimerRunningForTesting()); 251 EXPECT_TRUE(delegate_manager_->IsIdleCleanupTimerRunningForTesting());
244 252
245 // Adding the observer should instantly queue the timeout task, once run the 253 // Wait for the suspend request, but don't call PlayerGone().
246 // second delegate should be expired while the first is kept alive.
247 EXPECT_CALL(observer_1, OnSuspendRequested(false)); 254 EXPECT_CALL(observer_1, OnSuspendRequested(false));
248 base::RunLoop run_loop; 255 base::RunLoop run_loop;
249 base::MessageLoop::current()->PostTask(FROM_HERE, run_loop.QuitClosure()); 256 base::MessageLoop::current()->PostTask(FROM_HERE, run_loop.QuitClosure());
250 tick_clock.Advance(kIdleTimeout + base::TimeDelta::FromMicroseconds(1)); 257 tick_clock.Advance(kIdleTimeout + base::TimeDelta::FromMicroseconds(1));
251 run_loop.Run(); 258 run_loop.Run();
252 259
253 // Even though the player did not call PlayerGone() it should be removed from 260 // Even though the player did not call PlayerGone() it should be removed from
254 // future idle cleanup polls. 261 // future idle cleanup polls.
255 EXPECT_FALSE(delegate_manager_->IsIdleCleanupTimerRunningForTesting()); 262 EXPECT_FALSE(delegate_manager_->IsIdleCleanupTimerRunningForTesting());
256 delegate_manager_->RemoveObserver(delegate_id_1); 263 delegate_manager_->RemoveObserver(delegate_id_1);
257 } 264 }
258 265
259 } // namespace media 266 } // namespace media
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698