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

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

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

Powered by Google App Engine
This is Rietveld 408576698