| OLD | NEW |
| 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 "platform/WebTaskRunner.h" | 5 #include "platform/WebTaskRunner.h" |
| 6 | 6 |
| 7 #include "platform/scheduler/test/fake_web_task_runner.h" | 7 #include "platform/scheduler/test/fake_web_task_runner.h" |
| 8 #include "testing/gtest/include/gtest/gtest.h" | 8 #include "testing/gtest/include/gtest/gtest.h" |
| 9 | 9 |
| 10 namespace blink { | 10 namespace blink { |
| (...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 56 { | 56 { |
| 57 count = 0; | 57 count = 0; |
| 58 TaskHandle handle2 = taskRunner.postCancellableTask( | 58 TaskHandle handle2 = taskRunner.postCancellableTask( |
| 59 BLINK_FROM_HERE, WTF::bind(&increment, WTF::unretained(&count))); | 59 BLINK_FROM_HERE, WTF::bind(&increment, WTF::unretained(&count))); |
| 60 EXPECT_TRUE(handle2.isActive()); | 60 EXPECT_TRUE(handle2.isActive()); |
| 61 } | 61 } |
| 62 EXPECT_EQ(0, count); | 62 EXPECT_EQ(0, count); |
| 63 taskRunner.runUntilIdle(); | 63 taskRunner.runUntilIdle(); |
| 64 EXPECT_EQ(0, count); | 64 EXPECT_EQ(0, count); |
| 65 | 65 |
| 66 // The task should be cancelled when another TaskHandle is assigned on it. |
| 67 count = 0; |
| 68 handle = taskRunner.postCancellableTask( |
| 69 BLINK_FROM_HERE, WTF::bind(&increment, WTF::unretained(&count))); |
| 70 handle = taskRunner.postCancellableTask(BLINK_FROM_HERE, WTF::bind([] {})); |
| 71 EXPECT_EQ(0, count); |
| 72 taskRunner.runUntilIdle(); |
| 73 EXPECT_EQ(0, count); |
| 74 |
| 75 // Self assign should be nop. |
| 76 count = 0; |
| 77 handle = taskRunner.postCancellableTask( |
| 78 BLINK_FROM_HERE, WTF::bind(&increment, WTF::unretained(&count))); |
| 79 #if COMPILER(CLANG) |
| 80 #pragma GCC diagnostic push |
| 81 #pragma GCC diagnostic ignored "-Wself-move" |
| 82 handle = std::move(handle); |
| 83 #pragma GCC diagnostic pop |
| 84 #else |
| 85 handle = std::move(handle); |
| 86 #endif // COMPILER(CLANG) |
| 87 EXPECT_EQ(0, count); |
| 88 taskRunner.runUntilIdle(); |
| 89 EXPECT_EQ(1, count); |
| 90 |
| 66 // handle->isActive() should switch to false before the task starts running. | 91 // handle->isActive() should switch to false before the task starts running. |
| 67 bool isActive = false; | 92 bool isActive = false; |
| 68 handle = taskRunner.postCancellableTask( | 93 handle = taskRunner.postCancellableTask( |
| 69 BLINK_FROM_HERE, WTF::bind(&getIsActive, WTF::unretained(&isActive), | 94 BLINK_FROM_HERE, WTF::bind(&getIsActive, WTF::unretained(&isActive), |
| 70 WTF::unretained(&handle))); | 95 WTF::unretained(&handle))); |
| 71 EXPECT_TRUE(handle.isActive()); | 96 EXPECT_TRUE(handle.isActive()); |
| 72 taskRunner.runUntilIdle(); | 97 taskRunner.runUntilIdle(); |
| 73 EXPECT_FALSE(isActive); | 98 EXPECT_FALSE(isActive); |
| 74 EXPECT_FALSE(handle.isActive()); | 99 EXPECT_FALSE(handle.isActive()); |
| 75 } | 100 } |
| 76 | 101 |
| 77 } // namespace blink | 102 } // namespace blink |
| OLD | NEW |