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 <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 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
67 DISALLOW_COPY_AND_ASSIGN(RendererWebMediaPlayerDelegateTest); | 67 DISALLOW_COPY_AND_ASSIGN(RendererWebMediaPlayerDelegateTest); |
68 }; | 68 }; |
69 | 69 |
70 TEST_F(RendererWebMediaPlayerDelegateTest, SendsMessagesCorrectly) { | 70 TEST_F(RendererWebMediaPlayerDelegateTest, SendsMessagesCorrectly) { |
71 testing::StrictMock<MockWebMediaPlayerDelegateObserver> observer; | 71 testing::StrictMock<MockWebMediaPlayerDelegateObserver> observer; |
72 const int delegate_id = delegate_manager_->AddObserver(&observer); | 72 const int delegate_id = delegate_manager_->AddObserver(&observer); |
73 | 73 |
74 // Verify the playing message. | 74 // Verify the playing message. |
75 { | 75 { |
76 const bool kHasVideo = true, kHasAudio = false, kIsRemote = false; | 76 const bool kHasVideo = true, kHasAudio = false, kIsRemote = false; |
77 const base::TimeDelta kDuration = base::TimeDelta::FromSeconds(5); | 77 const media::MediaContentType kMediaContentType = |
| 78 media::MediaContentType::Transient; |
78 delegate_manager_->DidPlay(delegate_id, kHasVideo, kHasAudio, kIsRemote, | 79 delegate_manager_->DidPlay(delegate_id, kHasVideo, kHasAudio, kIsRemote, |
79 kDuration); | 80 kMediaContentType); |
80 | 81 |
81 const IPC::Message* msg = test_sink().GetUniqueMessageMatching( | 82 const IPC::Message* msg = test_sink().GetUniqueMessageMatching( |
82 MediaPlayerDelegateHostMsg_OnMediaPlaying::ID); | 83 MediaPlayerDelegateHostMsg_OnMediaPlaying::ID); |
83 ASSERT_TRUE(msg); | 84 ASSERT_TRUE(msg); |
84 | 85 |
85 std::tuple<int, bool, bool, bool, base::TimeDelta> result; | 86 std::tuple<int, bool, bool, bool, media::MediaContentType> result; |
86 ASSERT_TRUE(MediaPlayerDelegateHostMsg_OnMediaPlaying::Read(msg, &result)); | 87 ASSERT_TRUE(MediaPlayerDelegateHostMsg_OnMediaPlaying::Read(msg, &result)); |
87 EXPECT_EQ(delegate_id, std::get<0>(result)); | 88 EXPECT_EQ(delegate_id, std::get<0>(result)); |
88 EXPECT_EQ(kHasVideo, std::get<1>(result)); | 89 EXPECT_EQ(kHasVideo, std::get<1>(result)); |
89 EXPECT_EQ(kHasAudio, std::get<2>(result)); | 90 EXPECT_EQ(kHasAudio, std::get<2>(result)); |
90 EXPECT_EQ(kIsRemote, std::get<3>(result)); | 91 EXPECT_EQ(kIsRemote, std::get<3>(result)); |
91 EXPECT_EQ(kDuration, std::get<4>(result)); | 92 EXPECT_EQ(kMediaContentType, std::get<4>(result)); |
92 } | 93 } |
93 | 94 |
94 // Verify the paused message. | 95 // Verify the paused message. |
95 { | 96 { |
96 test_sink().ClearMessages(); | 97 test_sink().ClearMessages(); |
97 const bool kReachedEndOfStream = true; | 98 const bool kReachedEndOfStream = true; |
98 delegate_manager_->DidPause(delegate_id, kReachedEndOfStream); | 99 delegate_manager_->DidPause(delegate_id, kReachedEndOfStream); |
99 | 100 |
100 const IPC::Message* msg = test_sink().GetUniqueMessageMatching( | 101 const IPC::Message* msg = test_sink().GetUniqueMessageMatching( |
101 MediaPlayerDelegateHostMsg_OnMediaPaused::ID); | 102 MediaPlayerDelegateHostMsg_OnMediaPaused::ID); |
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
164 delegate_manager_->SetIdleCleanupParamsForTesting(kIdleTimeout, &tick_clock); | 165 delegate_manager_->SetIdleCleanupParamsForTesting(kIdleTimeout, &tick_clock); |
165 EXPECT_FALSE(delegate_manager_->IsIdleCleanupTimerRunningForTesting()); | 166 EXPECT_FALSE(delegate_manager_->IsIdleCleanupTimerRunningForTesting()); |
166 | 167 |
167 // Just adding an observer should not start the idle timer. | 168 // Just adding an observer should not start the idle timer. |
168 testing::StrictMock<MockWebMediaPlayerDelegateObserver> observer_1; | 169 testing::StrictMock<MockWebMediaPlayerDelegateObserver> observer_1; |
169 const int delegate_id_1 = delegate_manager_->AddObserver(&observer_1); | 170 const int delegate_id_1 = delegate_manager_->AddObserver(&observer_1); |
170 EXPECT_FALSE(delegate_manager_->IsIdleCleanupTimerRunningForTesting()); | 171 EXPECT_FALSE(delegate_manager_->IsIdleCleanupTimerRunningForTesting()); |
171 | 172 |
172 // Starting playback should not have an idle timer. | 173 // Starting playback should not have an idle timer. |
173 delegate_manager_->DidPlay(delegate_id_1, true, true, false, | 174 delegate_manager_->DidPlay(delegate_id_1, true, true, false, |
174 base::TimeDelta()); | 175 media::MediaContentType::Transient); |
175 EXPECT_FALSE(delegate_manager_->IsIdleCleanupTimerRunningForTesting()); | 176 EXPECT_FALSE(delegate_manager_->IsIdleCleanupTimerRunningForTesting()); |
176 | 177 |
177 // Never calling DidPlay() but calling DidPause() should count as idle. | 178 // Never calling DidPlay() but calling DidPause() should count as idle. |
178 testing::StrictMock<MockWebMediaPlayerDelegateObserver> observer_2; | 179 testing::StrictMock<MockWebMediaPlayerDelegateObserver> observer_2; |
179 const int delegate_id_2 = delegate_manager_->AddObserver(&observer_2); | 180 const int delegate_id_2 = delegate_manager_->AddObserver(&observer_2); |
180 delegate_manager_->DidPause(delegate_id_2, false); | 181 delegate_manager_->DidPause(delegate_id_2, false); |
181 EXPECT_TRUE(delegate_manager_->IsIdleCleanupTimerRunningForTesting()); | 182 EXPECT_TRUE(delegate_manager_->IsIdleCleanupTimerRunningForTesting()); |
182 | 183 |
183 // Adding the observer should instantly queue the timeout task, once run the | 184 // Adding the observer should instantly queue the timeout task, once run the |
184 // second delegate should be expired while the first is kept alive. | 185 // second delegate should be expired while the first is kept alive. |
185 { | 186 { |
186 EXPECT_CALL(observer_2, OnSuspendRequested(false)) | 187 EXPECT_CALL(observer_2, OnSuspendRequested(false)) |
187 .WillOnce(RunClosure(base::Bind( | 188 .WillOnce(RunClosure(base::Bind( |
188 &RendererWebMediaPlayerDelegate::PlayerGone, | 189 &RendererWebMediaPlayerDelegate::PlayerGone, |
189 base::Unretained(delegate_manager_.get()), delegate_id_2))); | 190 base::Unretained(delegate_manager_.get()), delegate_id_2))); |
190 base::RunLoop run_loop; | 191 base::RunLoop run_loop; |
191 base::ThreadTaskRunnerHandle::Get()->PostTask(FROM_HERE, | 192 base::ThreadTaskRunnerHandle::Get()->PostTask(FROM_HERE, |
192 run_loop.QuitClosure()); | 193 run_loop.QuitClosure()); |
193 tick_clock.Advance(kIdleTimeout + base::TimeDelta::FromMicroseconds(1)); | 194 tick_clock.Advance(kIdleTimeout + base::TimeDelta::FromMicroseconds(1)); |
194 run_loop.Run(); | 195 run_loop.Run(); |
195 } | 196 } |
196 | 197 |
197 // Pausing should count as idle if playback didn't reach end of stream, but | 198 // Pausing should count as idle if playback didn't reach end of stream, but |
198 // in this case the player will not remove the MediaSession. | 199 // in this case the player will not remove the MediaSession. |
199 delegate_manager_->DidPause(delegate_id_1, false /* reached_end_of_stream */); | 200 delegate_manager_->DidPause(delegate_id_1, false /* reached_end_of_stream */); |
200 testing::StrictMock<MockWebMediaPlayerDelegateObserver> observer_3; | 201 testing::StrictMock<MockWebMediaPlayerDelegateObserver> observer_3; |
201 const int delegate_id_3 = delegate_manager_->AddObserver(&observer_3); | 202 const int delegate_id_3 = delegate_manager_->AddObserver(&observer_3); |
202 delegate_manager_->DidPlay(delegate_id_3, true, true, false, | 203 delegate_manager_->DidPlay(delegate_id_3, true, true, false, |
203 base::TimeDelta()); | 204 media::MediaContentType::Transient); |
204 | 205 |
205 // Adding the observer should instantly queue the timeout task, once run no | 206 // Adding the observer should instantly queue the timeout task, once run no |
206 // delegates should have been expired. | 207 // delegates should have been expired. |
207 { | 208 { |
208 EXPECT_CALL(observer_1, OnSuspendRequested(false)) | 209 EXPECT_CALL(observer_1, OnSuspendRequested(false)) |
209 .Times(testing::AtLeast(1)); | 210 .Times(testing::AtLeast(1)); |
210 base::RunLoop run_loop; | 211 base::RunLoop run_loop; |
211 base::ThreadTaskRunnerHandle::Get()->PostTask(FROM_HERE, | 212 base::ThreadTaskRunnerHandle::Get()->PostTask(FROM_HERE, |
212 run_loop.QuitClosure()); | 213 run_loop.QuitClosure()); |
213 tick_clock.Advance(kIdleTimeout + base::TimeDelta::FromMicroseconds(1)); | 214 tick_clock.Advance(kIdleTimeout + base::TimeDelta::FromMicroseconds(1)); |
214 run_loop.Run(); | 215 run_loop.Run(); |
215 } | 216 } |
216 | 217 |
217 delegate_manager_->DidPlay(delegate_id_1, true, true, false, | 218 delegate_manager_->DidPlay(delegate_id_1, true, true, false, |
218 base::TimeDelta()); | 219 media::MediaContentType::Transient); |
219 | 220 |
220 // Pausing after reaching end of stream should count as idle. | 221 // Pausing after reaching end of stream should count as idle. |
221 delegate_manager_->DidPause(delegate_id_1, true /* reached_end_of_stream */); | 222 delegate_manager_->DidPause(delegate_id_1, true /* reached_end_of_stream */); |
222 | 223 |
223 // Once the timeout task runs the first delegate should be expired while the | 224 // Once the timeout task runs the first delegate should be expired while the |
224 // third is kept alive. | 225 // third is kept alive. |
225 { | 226 { |
226 EXPECT_CALL(observer_1, OnSuspendRequested(false)) | 227 EXPECT_CALL(observer_1, OnSuspendRequested(false)) |
227 .WillOnce(RunClosure(base::Bind( | 228 .WillOnce(RunClosure(base::Bind( |
228 &RendererWebMediaPlayerDelegate::PlayerGone, | 229 &RendererWebMediaPlayerDelegate::PlayerGone, |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
265 tick_clock.Advance(kIdleTimeout + base::TimeDelta::FromMicroseconds(1)); | 266 tick_clock.Advance(kIdleTimeout + base::TimeDelta::FromMicroseconds(1)); |
266 run_loop.Run(); | 267 run_loop.Run(); |
267 | 268 |
268 // Even though the player did not call PlayerGone() it should be removed from | 269 // Even though the player did not call PlayerGone() it should be removed from |
269 // future idle cleanup polls. | 270 // future idle cleanup polls. |
270 EXPECT_FALSE(delegate_manager_->IsIdleCleanupTimerRunningForTesting()); | 271 EXPECT_FALSE(delegate_manager_->IsIdleCleanupTimerRunningForTesting()); |
271 delegate_manager_->RemoveObserver(delegate_id_1); | 272 delegate_manager_->RemoveObserver(delegate_id_1); |
272 } | 273 } |
273 | 274 |
274 } // namespace media | 275 } // namespace media |
OLD | NEW |