OLD | NEW |
1 // Copyright 2017 The Chromium Authors. All rights reserved. | 1 // Copyright 2017 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_traits.h" | 5 #include "base/task_scheduler/task_traits.h" |
6 | 6 |
7 #include "testing/gtest/include/gtest/gtest.h" | 7 #include "testing/gtest/include/gtest/gtest.h" |
8 | 8 |
9 namespace base { | 9 namespace base { |
10 | 10 |
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
71 constexpr TaskTraits traits_copy(traits); | 71 constexpr TaskTraits traits_copy(traits); |
72 EXPECT_EQ(traits.priority_set_explicitly(), | 72 EXPECT_EQ(traits.priority_set_explicitly(), |
73 traits_copy.priority_set_explicitly()); | 73 traits_copy.priority_set_explicitly()); |
74 EXPECT_EQ(traits.priority(), traits_copy.priority()); | 74 EXPECT_EQ(traits.priority(), traits_copy.priority()); |
75 EXPECT_EQ(traits.shutdown_behavior(), traits_copy.shutdown_behavior()); | 75 EXPECT_EQ(traits.shutdown_behavior(), traits_copy.shutdown_behavior()); |
76 EXPECT_EQ(traits.may_block(), traits_copy.may_block()); | 76 EXPECT_EQ(traits.may_block(), traits_copy.may_block()); |
77 EXPECT_EQ(traits.with_base_sync_primitives(), | 77 EXPECT_EQ(traits.with_base_sync_primitives(), |
78 traits_copy.with_base_sync_primitives()); | 78 traits_copy.with_base_sync_primitives()); |
79 } | 79 } |
80 | 80 |
| 81 TEST(TaskSchedulerTaskTraitsTest, OverridePriority) { |
| 82 constexpr TaskTraits left = {TaskPriority::BACKGROUND}; |
| 83 constexpr TaskTraits right = {TaskPriority::USER_BLOCKING}; |
| 84 constexpr TaskTraits overridden = TaskTraits::Override(left, right); |
| 85 EXPECT_TRUE(overridden.priority_set_explicitly()); |
| 86 EXPECT_EQ(TaskPriority::USER_BLOCKING, overridden.priority()); |
| 87 EXPECT_FALSE(overridden.shutdown_behavior_set_explicitly()); |
| 88 EXPECT_EQ(TaskShutdownBehavior::SKIP_ON_SHUTDOWN, |
| 89 overridden.shutdown_behavior()); |
| 90 EXPECT_FALSE(overridden.may_block()); |
| 91 EXPECT_FALSE(overridden.with_base_sync_primitives()); |
| 92 } |
| 93 |
| 94 TEST(TaskSchedulerTaskTraitsTest, OverrideShutdownBehavior) { |
| 95 constexpr TaskTraits left = {TaskShutdownBehavior::CONTINUE_ON_SHUTDOWN}; |
| 96 constexpr TaskTraits right = {TaskShutdownBehavior::BLOCK_SHUTDOWN}; |
| 97 constexpr TaskTraits overridden = TaskTraits::Override(left, right); |
| 98 EXPECT_FALSE(overridden.priority_set_explicitly()); |
| 99 EXPECT_EQ(TaskPriority::USER_VISIBLE, overridden.priority()); |
| 100 EXPECT_TRUE(overridden.shutdown_behavior_set_explicitly()); |
| 101 EXPECT_EQ(TaskShutdownBehavior::BLOCK_SHUTDOWN, |
| 102 overridden.shutdown_behavior()); |
| 103 EXPECT_FALSE(overridden.may_block()); |
| 104 EXPECT_FALSE(overridden.with_base_sync_primitives()); |
| 105 } |
| 106 |
| 107 TEST(TaskSchedulerTaskTraitsTest, OverrideMayBlock) { |
| 108 { |
| 109 constexpr TaskTraits left = {MayBlock()}; |
| 110 constexpr TaskTraits right = {}; |
| 111 constexpr TaskTraits overridden = TaskTraits::Override(left, right); |
| 112 EXPECT_FALSE(overridden.priority_set_explicitly()); |
| 113 EXPECT_EQ(TaskPriority::USER_VISIBLE, overridden.priority()); |
| 114 EXPECT_FALSE(overridden.shutdown_behavior_set_explicitly()); |
| 115 EXPECT_EQ(TaskShutdownBehavior::SKIP_ON_SHUTDOWN, |
| 116 overridden.shutdown_behavior()); |
| 117 EXPECT_TRUE(overridden.may_block()); |
| 118 EXPECT_FALSE(overridden.with_base_sync_primitives()); |
| 119 } |
| 120 { |
| 121 constexpr TaskTraits left = {}; |
| 122 constexpr TaskTraits right = {MayBlock()}; |
| 123 constexpr TaskTraits overridden = TaskTraits::Override(left, right); |
| 124 EXPECT_FALSE(overridden.priority_set_explicitly()); |
| 125 EXPECT_EQ(TaskPriority::USER_VISIBLE, overridden.priority()); |
| 126 EXPECT_FALSE(overridden.shutdown_behavior_set_explicitly()); |
| 127 EXPECT_EQ(TaskShutdownBehavior::SKIP_ON_SHUTDOWN, |
| 128 overridden.shutdown_behavior()); |
| 129 EXPECT_TRUE(overridden.may_block()); |
| 130 EXPECT_FALSE(overridden.with_base_sync_primitives()); |
| 131 } |
| 132 } |
| 133 |
| 134 TEST(TaskSchedulerTaskTraitsTest, OverrideWithBaseSyncPrimitives) { |
| 135 { |
| 136 constexpr TaskTraits left = {WithBaseSyncPrimitives()}; |
| 137 constexpr TaskTraits right = {}; |
| 138 constexpr TaskTraits overridden = TaskTraits::Override(left, right); |
| 139 EXPECT_FALSE(overridden.priority_set_explicitly()); |
| 140 EXPECT_EQ(TaskPriority::USER_VISIBLE, overridden.priority()); |
| 141 EXPECT_FALSE(overridden.shutdown_behavior_set_explicitly()); |
| 142 EXPECT_EQ(TaskShutdownBehavior::SKIP_ON_SHUTDOWN, |
| 143 overridden.shutdown_behavior()); |
| 144 EXPECT_FALSE(overridden.may_block()); |
| 145 EXPECT_TRUE(overridden.with_base_sync_primitives()); |
| 146 } |
| 147 { |
| 148 constexpr TaskTraits left = {}; |
| 149 constexpr TaskTraits right = {WithBaseSyncPrimitives()}; |
| 150 constexpr TaskTraits overridden = TaskTraits::Override(left, right); |
| 151 EXPECT_FALSE(overridden.priority_set_explicitly()); |
| 152 EXPECT_EQ(TaskPriority::USER_VISIBLE, overridden.priority()); |
| 153 EXPECT_FALSE(overridden.shutdown_behavior_set_explicitly()); |
| 154 EXPECT_EQ(TaskShutdownBehavior::SKIP_ON_SHUTDOWN, |
| 155 overridden.shutdown_behavior()); |
| 156 EXPECT_FALSE(overridden.may_block()); |
| 157 EXPECT_TRUE(overridden.with_base_sync_primitives()); |
| 158 } |
| 159 } |
| 160 |
| 161 TEST(TaskSchedulerTaskTraitsTest, OverrideMultipleTraits) { |
| 162 constexpr TaskTraits left = {MayBlock(), TaskPriority::BACKGROUND, |
| 163 TaskShutdownBehavior::CONTINUE_ON_SHUTDOWN}; |
| 164 constexpr TaskTraits right = {WithBaseSyncPrimitives(), |
| 165 TaskPriority::USER_BLOCKING}; |
| 166 constexpr TaskTraits overridden = TaskTraits::Override(left, right); |
| 167 EXPECT_TRUE(overridden.priority_set_explicitly()); |
| 168 EXPECT_EQ(right.priority(), overridden.priority()); |
| 169 EXPECT_TRUE(overridden.shutdown_behavior_set_explicitly()); |
| 170 EXPECT_EQ(left.shutdown_behavior(), overridden.shutdown_behavior()); |
| 171 EXPECT_TRUE(overridden.may_block()); |
| 172 EXPECT_TRUE(overridden.with_base_sync_primitives()); |
| 173 } |
| 174 |
81 } // namespace base | 175 } // namespace base |
OLD | NEW |