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

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

Issue 2831883003: Do not inherit TaskPriority in TaskTraits. (Closed)
Patch Set: self-review Created 3 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
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/task.h" 5 #include "base/task_scheduler/task.h"
6 6
7 #include "base/bind.h" 7 #include "base/bind.h"
8 #include "base/location.h" 8 #include "base/location.h"
9 #include "base/task_scheduler/task_traits.h" 9 #include "base/task_scheduler/task_traits.h"
10 #include "base/task_scheduler/test_utils.h"
10 #include "base/time/time.h" 11 #include "base/time/time.h"
11 #include "testing/gtest/include/gtest/gtest.h" 12 #include "testing/gtest/include/gtest/gtest.h"
12 13
13 namespace base { 14 namespace base {
14 namespace internal { 15 namespace internal {
15 16
16 // Verify that the shutdown behavior of a BLOCK_SHUTDOWN delayed task is 17 // Verify that the shutdown behavior of a BLOCK_SHUTDOWN delayed task is
17 // adjusted to SKIP_ON_SHUTDOWN. The shutown behavior of other delayed tasks 18 // adjusted to SKIP_ON_SHUTDOWN. The shutown behavior of other delayed tasks
18 // should not change. 19 // should not change.
19 TEST(TaskSchedulerTaskTest, ShutdownBehaviorChangeWithDelay) { 20 TEST(TaskSchedulerTaskTest, ShutdownBehaviorChangeWithDelay) {
20 Task continue_on_shutdown(FROM_HERE, BindOnce(&DoNothing), 21 Task continue_on_shutdown(FROM_HERE, BindOnce(&DoNothing),
21 TaskTraits().WithShutdownBehavior( 22 test::CreateTaskTraits().WithShutdownBehavior(
22 TaskShutdownBehavior::CONTINUE_ON_SHUTDOWN), 23 TaskShutdownBehavior::CONTINUE_ON_SHUTDOWN),
23 TimeDelta::FromSeconds(1)); 24 TimeDelta::FromSeconds(1));
24 EXPECT_EQ(TaskShutdownBehavior::CONTINUE_ON_SHUTDOWN, 25 EXPECT_EQ(TaskShutdownBehavior::CONTINUE_ON_SHUTDOWN,
25 continue_on_shutdown.traits.shutdown_behavior()); 26 continue_on_shutdown.traits.shutdown_behavior());
26 27
27 Task skip_on_shutdown( 28 Task skip_on_shutdown(FROM_HERE, BindOnce(&DoNothing),
28 FROM_HERE, BindOnce(&DoNothing), 29 test::CreateTaskTraits().WithShutdownBehavior(
29 TaskTraits().WithShutdownBehavior(TaskShutdownBehavior::SKIP_ON_SHUTDOWN), 30 TaskShutdownBehavior::SKIP_ON_SHUTDOWN),
30 TimeDelta::FromSeconds(1)); 31 TimeDelta::FromSeconds(1));
31 EXPECT_EQ(TaskShutdownBehavior::SKIP_ON_SHUTDOWN, 32 EXPECT_EQ(TaskShutdownBehavior::SKIP_ON_SHUTDOWN,
32 skip_on_shutdown.traits.shutdown_behavior()); 33 skip_on_shutdown.traits.shutdown_behavior());
33 34
34 Task block_shutdown( 35 Task block_shutdown(FROM_HERE, BindOnce(&DoNothing),
35 FROM_HERE, BindOnce(&DoNothing), 36 test::CreateTaskTraits().WithShutdownBehavior(
36 TaskTraits().WithShutdownBehavior(TaskShutdownBehavior::BLOCK_SHUTDOWN), 37 TaskShutdownBehavior::BLOCK_SHUTDOWN),
37 TimeDelta::FromSeconds(1)); 38 TimeDelta::FromSeconds(1));
38 EXPECT_EQ(TaskShutdownBehavior::SKIP_ON_SHUTDOWN, 39 EXPECT_EQ(TaskShutdownBehavior::SKIP_ON_SHUTDOWN,
39 block_shutdown.traits.shutdown_behavior()); 40 block_shutdown.traits.shutdown_behavior());
40 } 41 }
41 42
42 // Verify that the shutdown behavior of undelayed tasks is not adjusted. 43 // Verify that the shutdown behavior of undelayed tasks is not adjusted.
43 TEST(TaskSchedulerTaskTest, NoShutdownBehaviorChangeNoDelay) { 44 TEST(TaskSchedulerTaskTest, NoShutdownBehaviorChangeNoDelay) {
44 Task continue_on_shutdown(FROM_HERE, BindOnce(&DoNothing), 45 Task continue_on_shutdown(FROM_HERE, BindOnce(&DoNothing),
45 TaskTraits().WithShutdownBehavior( 46 test::CreateTaskTraits().WithShutdownBehavior(
46 TaskShutdownBehavior::CONTINUE_ON_SHUTDOWN), 47 TaskShutdownBehavior::CONTINUE_ON_SHUTDOWN),
47 TimeDelta()); 48 TimeDelta());
48 EXPECT_EQ(TaskShutdownBehavior::CONTINUE_ON_SHUTDOWN, 49 EXPECT_EQ(TaskShutdownBehavior::CONTINUE_ON_SHUTDOWN,
49 continue_on_shutdown.traits.shutdown_behavior()); 50 continue_on_shutdown.traits.shutdown_behavior());
50 51
51 Task skip_on_shutdown( 52 Task skip_on_shutdown(FROM_HERE, BindOnce(&DoNothing),
52 FROM_HERE, BindOnce(&DoNothing), 53 test::CreateTaskTraits().WithShutdownBehavior(
53 TaskTraits().WithShutdownBehavior(TaskShutdownBehavior::SKIP_ON_SHUTDOWN), 54 TaskShutdownBehavior::SKIP_ON_SHUTDOWN),
54 TimeDelta()); 55 TimeDelta());
55 EXPECT_EQ(TaskShutdownBehavior::SKIP_ON_SHUTDOWN, 56 EXPECT_EQ(TaskShutdownBehavior::SKIP_ON_SHUTDOWN,
56 skip_on_shutdown.traits.shutdown_behavior()); 57 skip_on_shutdown.traits.shutdown_behavior());
57 58
58 Task block_shutdown( 59 Task block_shutdown(FROM_HERE, BindOnce(&DoNothing),
59 FROM_HERE, BindOnce(&DoNothing), 60 test::CreateTaskTraits().WithShutdownBehavior(
60 TaskTraits().WithShutdownBehavior(TaskShutdownBehavior::BLOCK_SHUTDOWN), 61 TaskShutdownBehavior::BLOCK_SHUTDOWN),
61 TimeDelta()); 62 TimeDelta());
62 EXPECT_EQ(TaskShutdownBehavior::BLOCK_SHUTDOWN, 63 EXPECT_EQ(TaskShutdownBehavior::BLOCK_SHUTDOWN,
63 block_shutdown.traits.shutdown_behavior()); 64 block_shutdown.traits.shutdown_behavior());
64 } 65 }
65 66
66 } // namespace internal 67 } // namespace internal
67 } // namespace base 68 } // namespace base
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698