Chromium Code Reviews| Index: base/task_scheduler/utils_unittest.cc |
| diff --git a/base/task_scheduler/utils_unittest.cc b/base/task_scheduler/utils_unittest.cc |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..3237a9e1e768f465ba3909c1996ff5f6ba489b23 |
| --- /dev/null |
| +++ b/base/task_scheduler/utils_unittest.cc |
| @@ -0,0 +1,71 @@ |
| +// Copyright 2016 The Chromium Authors. All rights reserved. |
|
gab
2016/03/21 19:11:54
TODO(gab): Review this file.
|
| +// Use of this source code is governed by a BSD-style license that can be |
| +// found in the LICENSE file. |
| + |
| +#include "base/task_scheduler/utils.h" |
| + |
| +#include <utility> |
| + |
| +#include "base/bind.h" |
| +#include "base/bind_helpers.h" |
| +#include "base/memory/ref_counted.h" |
| +#include "base/memory/scoped_ptr.h" |
| +#include "base/task_scheduler/priority_queue.h" |
| +#include "base/task_scheduler/sequence.h" |
| +#include "base/task_scheduler/task.h" |
| +#include "base/task_scheduler/task_tracker.h" |
| +#include "testing/gtest/include/gtest/gtest.h" |
| + |
| +namespace base { |
| +namespace internal { |
| + |
| +// Checks that when PostTaskHelper is called with an empty sequence, the task |
| +// is added to the sequence and the sequence is added to the priority queue. |
| +TEST(TaskSchedulerUtilsTest, PostTaskNowHelperEmptySequence) { |
| + scoped_ptr<Task> task(new Task(FROM_HERE, Bind(&DoNothing), TaskTraits())); |
| + const Task* task_raw = task.get(); |
| + scoped_refptr<Sequence> sequence(new Sequence); |
| + PriorityQueue priority_queue(Bind(&DoNothing)); |
| + TaskTracker task_tracker; |
| + |
| + // Post a task. |
|
gab
2016/03/21 19:11:54
s/a/the/
fdoray
2016/03/24 19:21:09
Done.
|
| + PostTaskHelper(std::move(task), sequence, &priority_queue, &task_tracker); |
| + |
| + // Expect to find the sequence in the priority queue. |
| + EXPECT_EQ(sequence, priority_queue.BeginTransaction()->Peek().sequence); |
| + |
| + // Expect to find the task in the sequence. |
|
gab
2016/03/21 19:11:53
// Expect to find the task alone in the sequence.
fdoray
2016/03/24 19:21:09
Done.
|
| + EXPECT_EQ(task_raw, sequence->PeekTask()); |
| + sequence->PopTask(); |
| + EXPECT_EQ(nullptr, sequence->PeekTask()); |
| +} |
| + |
| +// Checks that when PostTaskHelper is called with a sequence that already |
| +// contains a task, the task is added to the sequence but the sequence is not |
| +// added to the priority queue. |
| +TEST(TaskSchedulerUtilsTest, PostTaskNowHelperSequenceWithTasks) { |
| + scoped_ptr<Task> task(new Task(FROM_HERE, Bind(&DoNothing), TaskTraits())); |
| + const Task* task_raw = task.get(); |
| + scoped_refptr<Sequence> sequence(new Sequence); |
| + PriorityQueue priority_queue(Bind(&DoNothing)); |
| + TaskTracker task_tracker; |
| + |
| + // Add an initial task in |sequence|. |
| + sequence->PushTask( |
| + make_scoped_ptr(new Task(FROM_HERE, Bind(&DoNothing), TaskTraits()))); |
| + |
| + // Post a task. |
| + PostTaskHelper(std::move(task), sequence, &priority_queue, &task_tracker); |
| + |
| + // Expect to find the priority queue empty. |
| + EXPECT_TRUE(priority_queue.BeginTransaction()->Peek().is_null()); |
| + |
| + // Expect to find the task in the sequence. |
|
gab
2016/03/21 19:11:54
// Expect to find the task in the sequence behind
fdoray
2016/03/24 19:21:09
Done.
|
| + sequence->PopTask(); |
|
gab
2016/03/21 19:11:54
EXPECT_NE(task_raw, sequence->PeekTask());
before
fdoray
2016/03/24 19:21:09
Done.
|
| + EXPECT_EQ(task_raw, sequence->PeekTask()); |
| + sequence->PopTask(); |
| + EXPECT_EQ(nullptr, sequence->PeekTask()); |
| +} |
| + |
| +} // namespace internal |
| +} // namespace base |