OLD | NEW |
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 Loading... |
153 TEST_F(RendererWebMediaPlayerDelegateTest, IdleDelegatesAreSuspended) { | 153 TEST_F(RendererWebMediaPlayerDelegateTest, IdleDelegatesAreSuspended) { |
154 // Start the tick clock off at a non-null value. | 154 // Start the tick clock off at a non-null value. |
155 base::SimpleTestTickClock tick_clock; | 155 base::SimpleTestTickClock tick_clock; |
156 tick_clock.Advance(base::TimeDelta::FromSeconds(1234)); | 156 tick_clock.Advance(base::TimeDelta::FromSeconds(1234)); |
157 | 157 |
158 const base::TimeDelta kIdleTimeout = base::TimeDelta::FromSeconds(2); | 158 const base::TimeDelta kIdleTimeout = base::TimeDelta::FromSeconds(2); |
159 delegate_manager_->EnableInstantIdleCleanupForTesting(kIdleTimeout, | 159 delegate_manager_->EnableInstantIdleCleanupForTesting(kIdleTimeout, |
160 &tick_clock); | 160 &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, OnHidden(true)) | 182 EXPECT_CALL(observer_2, OnHidden(true)) |
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 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
220 run_loop.Run(); | 224 run_loop.Run(); |
221 } | 225 } |
222 | 226 |
223 delegate_manager_->RemoveObserver(delegate_id_1); | 227 delegate_manager_->RemoveObserver(delegate_id_1); |
224 delegate_manager_->RemoveObserver(delegate_id_2); | 228 delegate_manager_->RemoveObserver(delegate_id_2); |
225 delegate_manager_->RemoveObserver(delegate_id_3); | 229 delegate_manager_->RemoveObserver(delegate_id_3); |
226 EXPECT_FALSE(delegate_manager_->IsIdleCleanupTimerRunningForTesting()); | 230 EXPECT_FALSE(delegate_manager_->IsIdleCleanupTimerRunningForTesting()); |
227 } | 231 } |
228 | 232 |
229 } // namespace media | 233 } // namespace media |
OLD | NEW |