| 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/task_scheduler/task_tracker_posix.h" | 5 #include "base/task_scheduler/task_tracker_posix.h" |
| 6 | 6 |
| 7 #include <unistd.h> | 7 #include <unistd.h> |
| 8 | 8 |
| 9 #include <utility> | 9 #include <utility> |
| 10 | 10 |
| (...skipping 13 matching lines...) Expand all Loading... |
| 24 namespace internal { | 24 namespace internal { |
| 25 | 25 |
| 26 // Verify that TaskTrackerPosix runs a Task it receives. | 26 // Verify that TaskTrackerPosix runs a Task it receives. |
| 27 TEST(TaskSchedulerTaskTrackerPosixTest, RunTask) { | 27 TEST(TaskSchedulerTaskTrackerPosixTest, RunTask) { |
| 28 MessageLoopForIO message_loop; | 28 MessageLoopForIO message_loop; |
| 29 bool did_run = false; | 29 bool did_run = false; |
| 30 auto task = MakeUnique<Task>( | 30 auto task = MakeUnique<Task>( |
| 31 FROM_HERE, | 31 FROM_HERE, |
| 32 Bind([](bool* did_run) { *did_run = true; }, Unretained(&did_run)), | 32 Bind([](bool* did_run) { *did_run = true; }, Unretained(&did_run)), |
| 33 TaskTraits(), TimeDelta()); | 33 TaskTraits(), TimeDelta()); |
| 34 TaskTrackerPosix tracker(&message_loop); | 34 TaskTrackerPosix tracker; |
| 35 tracker.set_watch_file_descriptor_message_loop(&message_loop); |
| 35 | 36 |
| 36 EXPECT_TRUE(tracker.WillPostTask(task.get())); | 37 EXPECT_TRUE(tracker.WillPostTask(task.get())); |
| 37 EXPECT_TRUE(tracker.RunTask(std::move(task), SequenceToken::Create())); | 38 EXPECT_TRUE(tracker.RunTask(std::move(task), SequenceToken::Create())); |
| 38 EXPECT_TRUE(did_run); | 39 EXPECT_TRUE(did_run); |
| 39 } | 40 } |
| 40 | 41 |
| 41 // Verify that FileDescriptorWatcher::WatchReadable() can be called from a task | 42 // Verify that FileDescriptorWatcher::WatchReadable() can be called from a task |
| 42 // running in TaskTrackerPosix without a crash. | 43 // running in TaskTrackerPosix without a crash. |
| 43 TEST(TaskSchedulerTaskTrackerPosixTest, FileDescriptorWatcher) { | 44 TEST(TaskSchedulerTaskTrackerPosixTest, FileDescriptorWatcher) { |
| 44 MessageLoopForIO message_loop; | 45 MessageLoopForIO message_loop; |
| 45 int fds[2]; | 46 int fds[2]; |
| 46 ASSERT_EQ(0, pipe(fds)); | 47 ASSERT_EQ(0, pipe(fds)); |
| 47 auto task = MakeUnique<Task>( | 48 auto task = MakeUnique<Task>( |
| 48 FROM_HERE, Bind(IgnoreResult(&FileDescriptorWatcher::WatchReadable), | 49 FROM_HERE, Bind(IgnoreResult(&FileDescriptorWatcher::WatchReadable), |
| 49 fds[0], Bind(&DoNothing)), | 50 fds[0], Bind(&DoNothing)), |
| 50 TaskTraits(), TimeDelta()); | 51 TaskTraits(), TimeDelta()); |
| 51 TaskTrackerPosix tracker(&message_loop); | 52 TaskTrackerPosix tracker; |
| 53 tracker.set_watch_file_descriptor_message_loop(&message_loop); |
| 52 | 54 |
| 53 EXPECT_TRUE(tracker.WillPostTask(task.get())); | 55 EXPECT_TRUE(tracker.WillPostTask(task.get())); |
| 54 EXPECT_TRUE(tracker.RunTask(std::move(task), SequenceToken::Create())); | 56 EXPECT_TRUE(tracker.RunTask(std::move(task), SequenceToken::Create())); |
| 55 | 57 |
| 56 // Run the MessageLoop to allow the read watch to be registered and | 58 // Run the MessageLoop to allow the read watch to be registered and |
| 57 // unregistered. This prevents a memory leak. | 59 // unregistered. This prevents a memory leak. |
| 58 RunLoop().RunUntilIdle(); | 60 RunLoop().RunUntilIdle(); |
| 59 | 61 |
| 60 EXPECT_EQ(0, IGNORE_EINTR(close(fds[0]))); | 62 EXPECT_EQ(0, IGNORE_EINTR(close(fds[0]))); |
| 61 EXPECT_EQ(0, IGNORE_EINTR(close(fds[1]))); | 63 EXPECT_EQ(0, IGNORE_EINTR(close(fds[1]))); |
| 62 } | 64 } |
| 63 | 65 |
| 64 } // namespace internal | 66 } // namespace internal |
| 65 } // namespace base | 67 } // namespace base |
| OLD | NEW |