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

Side by Side Diff: base/task/cancelable_task_tracker_unittest.cc

Issue 2791243002: Rewrite base::Bind into base::BindOnce on trivial cases in base (Closed)
Patch Set: rebase Created 3 years, 8 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 | « base/task/cancelable_task_tracker.cc ('k') | base/task_runner_util.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 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/task/cancelable_task_tracker.h" 5 #include "base/task/cancelable_task_tracker.h"
6 6
7 #include <cstddef> 7 #include <cstddef>
8 #include <deque> 8 #include <deque>
9 9
10 #include "base/bind.h" 10 #include "base/bind.h"
(...skipping 176 matching lines...) Expand 10 before | Expand all | Expand 10 after
187 TEST_F(CancelableTaskTrackerTest, NewTrackedTaskIdDifferentThread) { 187 TEST_F(CancelableTaskTrackerTest, NewTrackedTaskIdDifferentThread) {
188 CancelableTaskTracker::IsCanceledCallback is_canceled; 188 CancelableTaskTracker::IsCanceledCallback is_canceled;
189 CancelableTaskTracker::TaskId task_id = 189 CancelableTaskTracker::TaskId task_id =
190 task_tracker_.NewTrackedTaskId(&is_canceled); 190 task_tracker_.NewTrackedTaskId(&is_canceled);
191 191
192 EXPECT_FALSE(is_canceled.Run()); 192 EXPECT_FALSE(is_canceled.Run());
193 193
194 Thread other_thread("other thread"); 194 Thread other_thread("other thread");
195 ASSERT_TRUE(other_thread.Start()); 195 ASSERT_TRUE(other_thread.Start());
196 other_thread.task_runner()->PostTask( 196 other_thread.task_runner()->PostTask(
197 FROM_HERE, Bind(&ExpectIsCanceled, is_canceled, false)); 197 FROM_HERE, BindOnce(&ExpectIsCanceled, is_canceled, false));
198 other_thread.Stop(); 198 other_thread.Stop();
199 199
200 task_tracker_.TryCancel(task_id); 200 task_tracker_.TryCancel(task_id);
201 201
202 ASSERT_TRUE(other_thread.Start()); 202 ASSERT_TRUE(other_thread.Start());
203 other_thread.task_runner()->PostTask( 203 other_thread.task_runner()->PostTask(
204 FROM_HERE, Bind(&ExpectIsCanceled, is_canceled, true)); 204 FROM_HERE, BindOnce(&ExpectIsCanceled, is_canceled, true));
205 other_thread.Stop(); 205 other_thread.Stop();
206 } 206 }
207 207
208 // With the task tracker, post a task, a task with a reply, get a new 208 // With the task tracker, post a task, a task with a reply, get a new
209 // task id, and then cancel all of them. None of the tasks nor the 209 // task id, and then cancel all of them. None of the tasks nor the
210 // reply should run and the "is canceled" callback should return 210 // reply should run and the "is canceled" callback should return
211 // true. 211 // true.
212 TEST_F(CancelableTaskTrackerTest, CancelAll) { 212 TEST_F(CancelableTaskTrackerTest, CancelAll) {
213 scoped_refptr<TestSimpleTaskRunner> test_task_runner( 213 scoped_refptr<TestSimpleTaskRunner> test_task_runner(
214 new TestSimpleTaskRunner()); 214 new TestSimpleTaskRunner());
(...skipping 142 matching lines...) Expand 10 before | Expand all | Expand 10 after
357 scoped_refptr<TestSimpleTaskRunner>(new TestSimpleTaskRunner()).get(), 357 scoped_refptr<TestSimpleTaskRunner>(new TestSimpleTaskRunner()).get(),
358 FROM_HERE, 358 FROM_HERE,
359 Bind(&DoNothing))); 359 Bind(&DoNothing)));
360 } 360 }
361 361
362 TEST_F(CancelableTaskTrackerDeathTest, PostFromDifferentThread) { 362 TEST_F(CancelableTaskTrackerDeathTest, PostFromDifferentThread) {
363 Thread bad_thread("bad thread"); 363 Thread bad_thread("bad thread");
364 ASSERT_TRUE(bad_thread.Start()); 364 ASSERT_TRUE(bad_thread.Start());
365 365
366 bad_thread.task_runner()->PostTask( 366 bad_thread.task_runner()->PostTask(
367 FROM_HERE, Bind(&MaybeRunDeadlyTaskTrackerMemberFunction, 367 FROM_HERE,
368 Unretained(&task_tracker_), Bind(&PostDoNothingTask))); 368 BindOnce(&MaybeRunDeadlyTaskTrackerMemberFunction,
369 Unretained(&task_tracker_), Bind(&PostDoNothingTask)));
369 } 370 }
370 371
371 void TryCancel(CancelableTaskTracker::TaskId task_id, 372 void TryCancel(CancelableTaskTracker::TaskId task_id,
372 CancelableTaskTracker* task_tracker) { 373 CancelableTaskTracker* task_tracker) {
373 task_tracker->TryCancel(task_id); 374 task_tracker->TryCancel(task_id);
374 } 375 }
375 376
376 TEST_F(CancelableTaskTrackerDeathTest, CancelOnDifferentThread) { 377 TEST_F(CancelableTaskTrackerDeathTest, CancelOnDifferentThread) {
377 scoped_refptr<TestSimpleTaskRunner> test_task_runner( 378 scoped_refptr<TestSimpleTaskRunner> test_task_runner(
378 new TestSimpleTaskRunner()); 379 new TestSimpleTaskRunner());
379 380
380 Thread bad_thread("bad thread"); 381 Thread bad_thread("bad thread");
381 ASSERT_TRUE(bad_thread.Start()); 382 ASSERT_TRUE(bad_thread.Start());
382 383
383 CancelableTaskTracker::TaskId task_id = task_tracker_.PostTask( 384 CancelableTaskTracker::TaskId task_id = task_tracker_.PostTask(
384 test_task_runner.get(), FROM_HERE, Bind(&DoNothing)); 385 test_task_runner.get(), FROM_HERE, Bind(&DoNothing));
385 EXPECT_NE(CancelableTaskTracker::kBadTaskId, task_id); 386 EXPECT_NE(CancelableTaskTracker::kBadTaskId, task_id);
386 387
387 bad_thread.task_runner()->PostTask( 388 bad_thread.task_runner()->PostTask(
388 FROM_HERE, Bind(&MaybeRunDeadlyTaskTrackerMemberFunction, 389 FROM_HERE,
389 Unretained(&task_tracker_), Bind(&TryCancel, task_id))); 390 BindOnce(&MaybeRunDeadlyTaskTrackerMemberFunction,
391 Unretained(&task_tracker_), Bind(&TryCancel, task_id)));
390 392
391 test_task_runner->RunUntilIdle(); 393 test_task_runner->RunUntilIdle();
392 } 394 }
393 395
394 TEST_F(CancelableTaskTrackerDeathTest, CancelAllOnDifferentThread) { 396 TEST_F(CancelableTaskTrackerDeathTest, CancelAllOnDifferentThread) {
395 scoped_refptr<TestSimpleTaskRunner> test_task_runner( 397 scoped_refptr<TestSimpleTaskRunner> test_task_runner(
396 new TestSimpleTaskRunner()); 398 new TestSimpleTaskRunner());
397 399
398 Thread bad_thread("bad thread"); 400 Thread bad_thread("bad thread");
399 ASSERT_TRUE(bad_thread.Start()); 401 ASSERT_TRUE(bad_thread.Start());
400 402
401 CancelableTaskTracker::TaskId task_id = task_tracker_.PostTask( 403 CancelableTaskTracker::TaskId task_id = task_tracker_.PostTask(
402 test_task_runner.get(), FROM_HERE, Bind(&DoNothing)); 404 test_task_runner.get(), FROM_HERE, Bind(&DoNothing));
403 EXPECT_NE(CancelableTaskTracker::kBadTaskId, task_id); 405 EXPECT_NE(CancelableTaskTracker::kBadTaskId, task_id);
404 406
405 bad_thread.task_runner()->PostTask( 407 bad_thread.task_runner()->PostTask(
406 FROM_HERE, 408 FROM_HERE, BindOnce(&MaybeRunDeadlyTaskTrackerMemberFunction,
407 Bind(&MaybeRunDeadlyTaskTrackerMemberFunction, Unretained(&task_tracker_), 409 Unretained(&task_tracker_),
408 Bind(&CancelableTaskTracker::TryCancelAll))); 410 Bind(&CancelableTaskTracker::TryCancelAll)));
409 411
410 test_task_runner->RunUntilIdle(); 412 test_task_runner->RunUntilIdle();
411 } 413 }
412 414
413 } // namespace base 415 } // namespace base
OLDNEW
« no previous file with comments | « base/task/cancelable_task_tracker.cc ('k') | base/task_runner_util.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698