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

Unified Diff: third_party/WebKit/Source/platform/WebTaskRunnerTest.cpp

Issue 2482813002: Cancel a task associated to TaskHandle when the TaskHandle is overridden (Closed)
Patch Set: Created 4 years, 1 month 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « third_party/WebKit/Source/platform/WebTaskRunner.cpp ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: third_party/WebKit/Source/platform/WebTaskRunnerTest.cpp
diff --git a/third_party/WebKit/Source/platform/WebTaskRunnerTest.cpp b/third_party/WebKit/Source/platform/WebTaskRunnerTest.cpp
index 7ce3b618b94dddc15def5926feaddae799961337..022a649a53e2ac5b9ca23fb21a2ef320fc8faba3 100644
--- a/third_party/WebKit/Source/platform/WebTaskRunnerTest.cpp
+++ b/third_party/WebKit/Source/platform/WebTaskRunnerTest.cpp
@@ -63,6 +63,31 @@ TEST(WebTaskRunnerTest, PostCancellableTaskTest) {
taskRunner.runUntilIdle();
EXPECT_EQ(0, count);
+ // The task should be cancelled when another TaskHandle is assigned on it.
+ count = 0;
+ handle = taskRunner.postCancellableTask(
+ BLINK_FROM_HERE, WTF::bind(&increment, WTF::unretained(&count)));
+ handle = taskRunner.postCancellableTask(BLINK_FROM_HERE, WTF::bind([] {}));
+ EXPECT_EQ(0, count);
+ taskRunner.runUntilIdle();
+ EXPECT_EQ(0, count);
+
+ // Self assign should be nop.
+ count = 0;
+ handle = taskRunner.postCancellableTask(
+ BLINK_FROM_HERE, WTF::bind(&increment, WTF::unretained(&count)));
+#if COMPILER(CLANG)
+#pragma GCC diagnostic push
+#pragma GCC diagnostic ignored "-Wself-move"
+ handle = std::move(handle);
+#pragma GCC diagnostic pop
+#else
+ handle = std::move(handle);
+#endif // COMPILER(CLANG)
+ EXPECT_EQ(0, count);
+ taskRunner.runUntilIdle();
+ EXPECT_EQ(1, count);
+
// handle->isActive() should switch to false before the task starts running.
bool isActive = false;
handle = taskRunner.postCancellableTask(
« no previous file with comments | « third_party/WebKit/Source/platform/WebTaskRunner.cpp ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698