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

Side by Side Diff: base/task_scheduler/utils_unittest.cc

Issue 1890163003: TaskScheduler: Add delayed run time to the constructor of Task. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@7_sequenced
Patch Set: self review Created 4 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_scheduler/utils.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 "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
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
OLDNEW
« no previous file with comments | « base/task_scheduler/utils.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698