OLD | NEW |
(Empty) | |
| 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/location.h" |
| 9 #include "base/task_scheduler/task_traits.h" |
| 10 #include "base/time/time.h" |
| 11 #include "testing/gtest/include/gtest/gtest.h" |
| 12 |
| 13 namespace base { |
| 14 namespace internal { |
| 15 |
| 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 |
| 18 // should not change. |
| 19 TEST(TaskSchedulerTaskTest, ShutdownBehaviorChangeWithDelay) { |
| 20 Task continue_on_shutdown(FROM_HERE, Bind(&DoNothing), |
| 21 TaskTraits().WithShutdownBehavior( |
| 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( |
| 28 FROM_HERE, Bind(&DoNothing), |
| 29 TaskTraits().WithShutdownBehavior(TaskShutdownBehavior::SKIP_ON_SHUTDOWN), |
| 30 TimeDelta::FromSeconds(1)); |
| 31 EXPECT_EQ(TaskShutdownBehavior::SKIP_ON_SHUTDOWN, |
| 32 skip_on_shutdown.traits.shutdown_behavior()); |
| 33 |
| 34 Task block_shutdown( |
| 35 FROM_HERE, Bind(&DoNothing), |
| 36 TaskTraits().WithShutdownBehavior(TaskShutdownBehavior::BLOCK_SHUTDOWN), |
| 37 TimeDelta::FromSeconds(1)); |
| 38 EXPECT_EQ(TaskShutdownBehavior::SKIP_ON_SHUTDOWN, |
| 39 block_shutdown.traits.shutdown_behavior()); |
| 40 } |
| 41 |
| 42 // Verify that the shutdown behavior of undelayed tasks is not adjusted. |
| 43 TEST(TaskSchedulerTaskTest, NoShutdownBehaviorChangeNoDelay) { |
| 44 Task continue_on_shutdown(FROM_HERE, Bind(&DoNothing), |
| 45 TaskTraits().WithShutdownBehavior( |
| 46 TaskShutdownBehavior::CONTINUE_ON_SHUTDOWN), |
| 47 TimeDelta()); |
| 48 EXPECT_EQ(TaskShutdownBehavior::CONTINUE_ON_SHUTDOWN, |
| 49 continue_on_shutdown.traits.shutdown_behavior()); |
| 50 |
| 51 Task skip_on_shutdown( |
| 52 FROM_HERE, Bind(&DoNothing), |
| 53 TaskTraits().WithShutdownBehavior(TaskShutdownBehavior::SKIP_ON_SHUTDOWN), |
| 54 TimeDelta()); |
| 55 EXPECT_EQ(TaskShutdownBehavior::SKIP_ON_SHUTDOWN, |
| 56 skip_on_shutdown.traits.shutdown_behavior()); |
| 57 |
| 58 Task block_shutdown( |
| 59 FROM_HERE, Bind(&DoNothing), |
| 60 TaskTraits().WithShutdownBehavior(TaskShutdownBehavior::BLOCK_SHUTDOWN), |
| 61 TimeDelta()); |
| 62 EXPECT_EQ(TaskShutdownBehavior::BLOCK_SHUTDOWN, |
| 63 block_shutdown.traits.shutdown_behavior()); |
| 64 } |
| 65 |
| 66 } // namespace internal |
| 67 } // namespace base |
OLD | NEW |