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

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

Issue 1704113002: TaskScheduler [6] SchedulerWorkerThread (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@s_4_shutdown
Patch Set: CR from robliao Created 4 years, 9 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
OLDNEW
(Empty)
1 // Copyright 2016 The Chromium Authors. All rights reserved.
gab 2016/03/21 19:11:54 TODO(gab): Review this file.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #include "base/task_scheduler/utils.h"
6
7 #include <utility>
8
9 #include "base/bind.h"
10 #include "base/bind_helpers.h"
11 #include "base/memory/ref_counted.h"
12 #include "base/memory/scoped_ptr.h"
13 #include "base/task_scheduler/priority_queue.h"
14 #include "base/task_scheduler/sequence.h"
15 #include "base/task_scheduler/task.h"
16 #include "base/task_scheduler/task_tracker.h"
17 #include "testing/gtest/include/gtest/gtest.h"
18
19 namespace base {
20 namespace internal {
21
22 // Checks that when PostTaskHelper is called with an empty sequence, the task
23 // is added to the sequence and the sequence is added to the priority queue.
24 TEST(TaskSchedulerUtilsTest, PostTaskNowHelperEmptySequence) {
25 scoped_ptr<Task> task(new Task(FROM_HERE, Bind(&DoNothing), TaskTraits()));
26 const Task* task_raw = task.get();
27 scoped_refptr<Sequence> sequence(new Sequence);
28 PriorityQueue priority_queue(Bind(&DoNothing));
29 TaskTracker task_tracker;
30
31 // Post a task.
gab 2016/03/21 19:11:54 s/a/the/
fdoray 2016/03/24 19:21:09 Done.
32 PostTaskHelper(std::move(task), sequence, &priority_queue, &task_tracker);
33
34 // Expect to find the sequence in the priority queue.
35 EXPECT_EQ(sequence, priority_queue.BeginTransaction()->Peek().sequence);
36
37 // 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.
38 EXPECT_EQ(task_raw, sequence->PeekTask());
39 sequence->PopTask();
40 EXPECT_EQ(nullptr, sequence->PeekTask());
41 }
42
43 // Checks that when PostTaskHelper is called with a sequence that already
44 // contains a task, the task is added to the sequence but the sequence is not
45 // added to the priority queue.
46 TEST(TaskSchedulerUtilsTest, PostTaskNowHelperSequenceWithTasks) {
47 scoped_ptr<Task> task(new Task(FROM_HERE, Bind(&DoNothing), TaskTraits()));
48 const Task* task_raw = task.get();
49 scoped_refptr<Sequence> sequence(new Sequence);
50 PriorityQueue priority_queue(Bind(&DoNothing));
51 TaskTracker task_tracker;
52
53 // Add an initial task in |sequence|.
54 sequence->PushTask(
55 make_scoped_ptr(new Task(FROM_HERE, Bind(&DoNothing), TaskTraits())));
56
57 // Post a task.
58 PostTaskHelper(std::move(task), sequence, &priority_queue, &task_tracker);
59
60 // Expect to find the priority queue empty.
61 EXPECT_TRUE(priority_queue.BeginTransaction()->Peek().is_null());
62
63 // 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.
64 sequence->PopTask();
gab 2016/03/21 19:11:54 EXPECT_NE(task_raw, sequence->PeekTask()); before
fdoray 2016/03/24 19:21:09 Done.
65 EXPECT_EQ(task_raw, sequence->PeekTask());
66 sequence->PopTask();
67 EXPECT_EQ(nullptr, sequence->PeekTask());
68 }
69
70 } // namespace internal
71 } // namespace base
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698