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

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

Issue 2034663003: Remove use of deprecated MessageLoop methods in content. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: rebase Created 4 years, 6 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/run_loop.h" 10 #include "base/run_loop.h"
11 #include "base/single_thread_task_runner.h"
10 #include "base/test/simple_test_tick_clock.h" 12 #include "base/test/simple_test_tick_clock.h"
13 #include "base/threading/thread_task_runner_handle.h"
11 #include "content/common/media/media_player_delegate_messages.h" 14 #include "content/common/media/media_player_delegate_messages.h"
12 #include "content/public/renderer/render_view.h" 15 #include "content/public/renderer/render_view.h"
13 #include "content/public/test/render_view_test.h" 16 #include "content/public/test/render_view_test.h"
14 #include "content/renderer/media/renderer_webmediaplayer_delegate.h" 17 #include "content/renderer/media/renderer_webmediaplayer_delegate.h"
15 #include "content/renderer/render_process.h" 18 #include "content/renderer/render_process.h"
16 #include "testing/gmock/include/gmock/gmock.h" 19 #include "testing/gmock/include/gmock/gmock.h"
17 #include "testing/gtest/include/gtest/gtest.h" 20 #include "testing/gtest/include/gtest/gtest.h"
18 21
19 namespace media { 22 namespace media {
20 23
(...skipping 157 matching lines...) Expand 10 before | Expand all | Expand 10 after
178 EXPECT_TRUE(delegate_manager_->IsIdleCleanupTimerRunningForTesting()); 181 EXPECT_TRUE(delegate_manager_->IsIdleCleanupTimerRunningForTesting());
179 182
180 // Adding the observer should instantly queue the timeout task, once run the 183 // Adding the observer should instantly queue the timeout task, once run the
181 // second delegate should be expired while the first is kept alive. 184 // second delegate should be expired while the first is kept alive.
182 { 185 {
183 EXPECT_CALL(observer_2, OnSuspendRequested(false)) 186 EXPECT_CALL(observer_2, OnSuspendRequested(false))
184 .WillOnce(RunClosure(base::Bind( 187 .WillOnce(RunClosure(base::Bind(
185 &RendererWebMediaPlayerDelegate::PlayerGone, 188 &RendererWebMediaPlayerDelegate::PlayerGone,
186 base::Unretained(delegate_manager_.get()), delegate_id_2))); 189 base::Unretained(delegate_manager_.get()), delegate_id_2)));
187 base::RunLoop run_loop; 190 base::RunLoop run_loop;
188 base::MessageLoop::current()->PostTask(FROM_HERE, run_loop.QuitClosure()); 191 base::ThreadTaskRunnerHandle::Get()->PostTask(FROM_HERE,
192 run_loop.QuitClosure());
189 tick_clock.Advance(kIdleTimeout + base::TimeDelta::FromMicroseconds(1)); 193 tick_clock.Advance(kIdleTimeout + base::TimeDelta::FromMicroseconds(1));
190 run_loop.Run(); 194 run_loop.Run();
191 } 195 }
192 196
193 // Pausing should count as idle if playback didn't reach end of stream, but 197 // Pausing should count as idle if playback didn't reach end of stream, but
194 // in this case the player will not remove the MediaSession. 198 // in this case the player will not remove the MediaSession.
195 delegate_manager_->DidPause(delegate_id_1, false /* reached_end_of_stream */); 199 delegate_manager_->DidPause(delegate_id_1, false /* reached_end_of_stream */);
196 testing::StrictMock<MockWebMediaPlayerDelegateObserver> observer_3; 200 testing::StrictMock<MockWebMediaPlayerDelegateObserver> observer_3;
197 const int delegate_id_3 = delegate_manager_->AddObserver(&observer_3); 201 const int delegate_id_3 = delegate_manager_->AddObserver(&observer_3);
198 delegate_manager_->DidPlay(delegate_id_3, true, true, false, 202 delegate_manager_->DidPlay(delegate_id_3, true, true, false,
199 base::TimeDelta()); 203 base::TimeDelta());
200 204
201 // Adding the observer should instantly queue the timeout task, once run no 205 // Adding the observer should instantly queue the timeout task, once run no
202 // delegates should have been expired. 206 // delegates should have been expired.
203 { 207 {
204 EXPECT_CALL(observer_1, OnSuspendRequested(false)) 208 EXPECT_CALL(observer_1, OnSuspendRequested(false))
205 .Times(testing::AtLeast(1)); 209 .Times(testing::AtLeast(1));
206 base::RunLoop run_loop; 210 base::RunLoop run_loop;
207 base::MessageLoop::current()->PostTask(FROM_HERE, run_loop.QuitClosure()); 211 base::ThreadTaskRunnerHandle::Get()->PostTask(FROM_HERE,
212 run_loop.QuitClosure());
208 tick_clock.Advance(kIdleTimeout + base::TimeDelta::FromMicroseconds(1)); 213 tick_clock.Advance(kIdleTimeout + base::TimeDelta::FromMicroseconds(1));
209 run_loop.Run(); 214 run_loop.Run();
210 } 215 }
211 216
212 delegate_manager_->DidPlay(delegate_id_1, true, true, false, 217 delegate_manager_->DidPlay(delegate_id_1, true, true, false,
213 base::TimeDelta()); 218 base::TimeDelta());
214 219
215 // Pausing after reaching end of stream should count as idle. 220 // Pausing after reaching end of stream should count as idle.
216 delegate_manager_->DidPause(delegate_id_1, true /* reached_end_of_stream */); 221 delegate_manager_->DidPause(delegate_id_1, true /* reached_end_of_stream */);
217 222
218 // Once the timeout task runs the first delegate should be expired while the 223 // Once the timeout task runs the first delegate should be expired while the
219 // third is kept alive. 224 // third is kept alive.
220 { 225 {
221 EXPECT_CALL(observer_1, OnSuspendRequested(false)) 226 EXPECT_CALL(observer_1, OnSuspendRequested(false))
222 .WillOnce(RunClosure(base::Bind( 227 .WillOnce(RunClosure(base::Bind(
223 &RendererWebMediaPlayerDelegate::PlayerGone, 228 &RendererWebMediaPlayerDelegate::PlayerGone,
224 base::Unretained(delegate_manager_.get()), delegate_id_1))); 229 base::Unretained(delegate_manager_.get()), delegate_id_1)));
225 base::RunLoop run_loop; 230 base::RunLoop run_loop;
226 base::MessageLoop::current()->PostTask(FROM_HERE, run_loop.QuitClosure()); 231 base::ThreadTaskRunnerHandle::Get()->PostTask(FROM_HERE,
232 run_loop.QuitClosure());
227 tick_clock.Advance(kIdleTimeout + base::TimeDelta::FromMicroseconds(1)); 233 tick_clock.Advance(kIdleTimeout + base::TimeDelta::FromMicroseconds(1));
228 run_loop.Run(); 234 run_loop.Run();
229 } 235 }
230 236
231 delegate_manager_->RemoveObserver(delegate_id_1); 237 delegate_manager_->RemoveObserver(delegate_id_1);
232 delegate_manager_->RemoveObserver(delegate_id_2); 238 delegate_manager_->RemoveObserver(delegate_id_2);
233 delegate_manager_->RemoveObserver(delegate_id_3); 239 delegate_manager_->RemoveObserver(delegate_id_3);
234 EXPECT_FALSE(delegate_manager_->IsIdleCleanupTimerRunningForTesting()); 240 EXPECT_FALSE(delegate_manager_->IsIdleCleanupTimerRunningForTesting());
235 } 241 }
236 242
(...skipping 10 matching lines...) Expand all
247 const int delegate_id_1 = delegate_manager_->AddObserver(&observer_1); 253 const int delegate_id_1 = delegate_manager_->AddObserver(&observer_1);
248 EXPECT_FALSE(delegate_manager_->IsIdleCleanupTimerRunningForTesting()); 254 EXPECT_FALSE(delegate_manager_->IsIdleCleanupTimerRunningForTesting());
249 255
250 // Calling DidPause() should instantly queue the timeout task. 256 // Calling DidPause() should instantly queue the timeout task.
251 delegate_manager_->DidPause(delegate_id_1, false); 257 delegate_manager_->DidPause(delegate_id_1, false);
252 EXPECT_TRUE(delegate_manager_->IsIdleCleanupTimerRunningForTesting()); 258 EXPECT_TRUE(delegate_manager_->IsIdleCleanupTimerRunningForTesting());
253 259
254 // Wait for the suspend request, but don't call PlayerGone(). 260 // Wait for the suspend request, but don't call PlayerGone().
255 EXPECT_CALL(observer_1, OnSuspendRequested(false)); 261 EXPECT_CALL(observer_1, OnSuspendRequested(false));
256 base::RunLoop run_loop; 262 base::RunLoop run_loop;
257 base::MessageLoop::current()->PostTask(FROM_HERE, run_loop.QuitClosure()); 263 base::ThreadTaskRunnerHandle::Get()->PostTask(FROM_HERE,
264 run_loop.QuitClosure());
258 tick_clock.Advance(kIdleTimeout + base::TimeDelta::FromMicroseconds(1)); 265 tick_clock.Advance(kIdleTimeout + base::TimeDelta::FromMicroseconds(1));
259 run_loop.Run(); 266 run_loop.Run();
260 267
261 // Even though the player did not call PlayerGone() it should be removed from 268 // Even though the player did not call PlayerGone() it should be removed from
262 // future idle cleanup polls. 269 // future idle cleanup polls.
263 EXPECT_FALSE(delegate_manager_->IsIdleCleanupTimerRunningForTesting()); 270 EXPECT_FALSE(delegate_manager_->IsIdleCleanupTimerRunningForTesting());
264 delegate_manager_->RemoveObserver(delegate_id_1); 271 delegate_manager_->RemoveObserver(delegate_id_1);
265 } 272 }
266 273
267 } // namespace media 274 } // namespace media
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698