• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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
3 // found in the LICENSE file.
4 
5 #include "base/task_scheduler/task.h"
6 
7 #include "base/bind.h"
8 #include "base/bind_helpers.h"
9 #include "base/location.h"
10 #include "base/task_scheduler/task_traits.h"
11 #include "base/time/time.h"
12 #include "testing/gtest/include/gtest/gtest.h"
13 
14 namespace base {
15 namespace internal {
16 
17 // Verify that the shutdown behavior of a BLOCK_SHUTDOWN delayed task is
18 // adjusted to SKIP_ON_SHUTDOWN. The shutown behavior of other delayed tasks
19 // should not change.
TEST(TaskSchedulerTaskTest,ShutdownBehaviorChangeWithDelay)20 TEST(TaskSchedulerTaskTest, ShutdownBehaviorChangeWithDelay) {
21   Task continue_on_shutdown(FROM_HERE, DoNothing(),
22                             {TaskShutdownBehavior::CONTINUE_ON_SHUTDOWN},
23                             TimeDelta::FromSeconds(1));
24   EXPECT_EQ(TaskShutdownBehavior::CONTINUE_ON_SHUTDOWN,
25             continue_on_shutdown.traits.shutdown_behavior());
26 
27   Task skip_on_shutdown(FROM_HERE, DoNothing(),
28                         {TaskShutdownBehavior::SKIP_ON_SHUTDOWN},
29                         TimeDelta::FromSeconds(1));
30   EXPECT_EQ(TaskShutdownBehavior::SKIP_ON_SHUTDOWN,
31             skip_on_shutdown.traits.shutdown_behavior());
32 
33   Task block_shutdown(FROM_HERE, DoNothing(),
34                       {TaskShutdownBehavior::BLOCK_SHUTDOWN},
35                       TimeDelta::FromSeconds(1));
36   EXPECT_EQ(TaskShutdownBehavior::SKIP_ON_SHUTDOWN,
37             block_shutdown.traits.shutdown_behavior());
38 }
39 
40 // Verify that the shutdown behavior of undelayed tasks is not adjusted.
TEST(TaskSchedulerTaskTest,NoShutdownBehaviorChangeNoDelay)41 TEST(TaskSchedulerTaskTest, NoShutdownBehaviorChangeNoDelay) {
42   Task continue_on_shutdown(FROM_HERE, DoNothing(),
43                             {TaskShutdownBehavior::CONTINUE_ON_SHUTDOWN},
44                             TimeDelta());
45   EXPECT_EQ(TaskShutdownBehavior::CONTINUE_ON_SHUTDOWN,
46             continue_on_shutdown.traits.shutdown_behavior());
47 
48   Task skip_on_shutdown(FROM_HERE, DoNothing(),
49                         {TaskShutdownBehavior::SKIP_ON_SHUTDOWN}, TimeDelta());
50   EXPECT_EQ(TaskShutdownBehavior::SKIP_ON_SHUTDOWN,
51             skip_on_shutdown.traits.shutdown_behavior());
52 
53   Task block_shutdown(FROM_HERE, DoNothing(),
54                       {TaskShutdownBehavior::BLOCK_SHUTDOWN}, TimeDelta());
55   EXPECT_EQ(TaskShutdownBehavior::BLOCK_SHUTDOWN,
56             block_shutdown.traits.shutdown_behavior());
57 }
58 
59 }  // namespace internal
60 }  // namespace base
61