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

Side by Side 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 unified diff | Download patch
« no previous file with comments | « third_party/WebKit/Source/platform/WebTaskRunner.cpp ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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
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
OLDNEW
« 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