| 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/utils.h" | 5 #include "base/task_scheduler/utils.h" |
| 6 | 6 |
| 7 #include <memory> | 7 #include <memory> |
| 8 | 8 |
| 9 #include "base/bind.h" | 9 #include "base/bind.h" |
| 10 #include "base/bind_helpers.h" | 10 #include "base/bind_helpers.h" |
| (...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 68 TaskTraits().WithShutdownBehavior(TaskShutdownBehavior::SKIP_ON_SHUTDOWN), | 68 TaskTraits().WithShutdownBehavior(TaskShutdownBehavior::SKIP_ON_SHUTDOWN), |
| 69 TimeDelta(), make_scoped_refptr(new Sequence), &executor, &task_tracker); | 69 TimeDelta(), make_scoped_refptr(new Sequence), &executor, &task_tracker); |
| 70 } | 70 } |
| 71 | 71 |
| 72 // Verifies that when AddTaskToSequenceAndPriorityQueue is called with an empty | 72 // Verifies that when AddTaskToSequenceAndPriorityQueue is called with an empty |
| 73 // sequence, the task is added to the sequence and the sequence is added to the | 73 // sequence, the task is added to the sequence and the sequence is added to the |
| 74 // priority queue. | 74 // priority queue. |
| 75 TEST(TaskSchedulerAddTaskToSequenceAndPriorityQueueTest, | 75 TEST(TaskSchedulerAddTaskToSequenceAndPriorityQueueTest, |
| 76 PostTaskInEmptySequence) { | 76 PostTaskInEmptySequence) { |
| 77 std::unique_ptr<Task> task( | 77 std::unique_ptr<Task> task( |
| 78 new Task(FROM_HERE, Bind(&DoNothing), TaskTraits())); | 78 new Task(FROM_HERE, Bind(&DoNothing), TaskTraits(), TimeTicks())); |
| 79 const Task* task_raw = task.get(); | 79 const Task* task_raw = task.get(); |
| 80 scoped_refptr<Sequence> sequence(new Sequence); | 80 scoped_refptr<Sequence> sequence(new Sequence); |
| 81 PriorityQueue priority_queue; | 81 PriorityQueue priority_queue; |
| 82 | 82 |
| 83 // Post |task|. | 83 // Post |task|. |
| 84 EXPECT_TRUE(AddTaskToSequenceAndPriorityQueue(std::move(task), sequence, | 84 EXPECT_TRUE(AddTaskToSequenceAndPriorityQueue(std::move(task), sequence, |
| 85 &priority_queue)); | 85 &priority_queue)); |
| 86 | 86 |
| 87 // Expect to find the sequence in the priority queue. | 87 // Expect to find the sequence in the priority queue. |
| 88 EXPECT_EQ(sequence, priority_queue.BeginTransaction()->Peek().sequence); | 88 EXPECT_EQ(sequence, priority_queue.BeginTransaction()->Peek().sequence); |
| 89 | 89 |
| 90 // Expect to find |task| alone in |sequence|. | 90 // Expect to find |task| alone in |sequence|. |
| 91 EXPECT_EQ(task_raw, sequence->PeekTask()); | 91 EXPECT_EQ(task_raw, sequence->PeekTask()); |
| 92 sequence->PopTask(); | 92 sequence->PopTask(); |
| 93 EXPECT_EQ(nullptr, sequence->PeekTask()); | 93 EXPECT_EQ(nullptr, sequence->PeekTask()); |
| 94 } | 94 } |
| 95 | 95 |
| 96 // Verifies that when AddTaskToSequenceAndPriorityQueue is called with a | 96 // Verifies that when AddTaskToSequenceAndPriorityQueue is called with a |
| 97 // sequence that already contains a task, the task is added to the sequence but | 97 // sequence that already contains a task, the task is added to the sequence but |
| 98 // the sequence is not added to the priority queue. | 98 // the sequence is not added to the priority queue. |
| 99 TEST(TaskSchedulerAddTaskToSequenceAndPriorityQueueTest, | 99 TEST(TaskSchedulerAddTaskToSequenceAndPriorityQueueTest, |
| 100 PostTaskInNonEmptySequence) { | 100 PostTaskInNonEmptySequence) { |
| 101 std::unique_ptr<Task> task( | 101 std::unique_ptr<Task> task( |
| 102 new Task(FROM_HERE, Bind(&DoNothing), TaskTraits())); | 102 new Task(FROM_HERE, Bind(&DoNothing), TaskTraits(), TimeTicks())); |
| 103 const Task* task_raw = task.get(); | 103 const Task* task_raw = task.get(); |
| 104 scoped_refptr<Sequence> sequence(new Sequence); | 104 scoped_refptr<Sequence> sequence(new Sequence); |
| 105 PriorityQueue priority_queue; | 105 PriorityQueue priority_queue; |
| 106 | 106 |
| 107 // Add an initial task in |sequence|. | 107 // Add an initial task in |sequence|. |
| 108 sequence->PushTask( | 108 sequence->PushTask(WrapUnique( |
| 109 WrapUnique(new Task(FROM_HERE, Bind(&DoNothing), TaskTraits()))); | 109 new Task(FROM_HERE, Bind(&DoNothing), TaskTraits(), TimeTicks()))); |
| 110 | 110 |
| 111 // Post |task|. | 111 // Post |task|. |
| 112 EXPECT_FALSE(AddTaskToSequenceAndPriorityQueue(std::move(task), sequence, | 112 EXPECT_FALSE(AddTaskToSequenceAndPriorityQueue(std::move(task), sequence, |
| 113 &priority_queue)); | 113 &priority_queue)); |
| 114 | 114 |
| 115 // Expect to find the priority queue empty. | 115 // Expect to find the priority queue empty. |
| 116 EXPECT_TRUE(priority_queue.BeginTransaction()->Peek().is_null()); | 116 EXPECT_TRUE(priority_queue.BeginTransaction()->Peek().is_null()); |
| 117 | 117 |
| 118 // Expect to find |task| in |sequence| behind the initial task. | 118 // Expect to find |task| in |sequence| behind the initial task. |
| 119 EXPECT_NE(task_raw, sequence->PeekTask()); | 119 EXPECT_NE(task_raw, sequence->PeekTask()); |
| 120 sequence->PopTask(); | 120 sequence->PopTask(); |
| 121 EXPECT_EQ(task_raw, sequence->PeekTask()); | 121 EXPECT_EQ(task_raw, sequence->PeekTask()); |
| 122 sequence->PopTask(); | 122 sequence->PopTask(); |
| 123 EXPECT_EQ(nullptr, sequence->PeekTask()); | 123 EXPECT_EQ(nullptr, sequence->PeekTask()); |
| 124 } | 124 } |
| 125 | 125 |
| 126 } // namespace | 126 } // namespace |
| 127 } // namespace internal | 127 } // namespace internal |
| 128 } // namespace base | 128 } // namespace base |
| OLD | NEW |