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

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

Issue 2550373005: Make WebTaskRunner ThreadSafeRefCounted (Closed)
Patch Set: +DISALLOW_COPY_AND_ASSIGN for win build fix Created 3 years, 11 months 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
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 bcff0c113ae43105fedd67c95a1ce46c39108309..575bd1927f6414999ecc51b2423aac3b90497425 100644
--- a/third_party/WebKit/Source/platform/WebTaskRunnerTest.cpp
+++ b/third_party/WebKit/Source/platform/WebTaskRunnerTest.cpp
@@ -38,60 +38,61 @@ class CancellationTestHelper {
} // namespace
TEST(WebTaskRunnerTest, PostCancellableTaskTest) {
- scheduler::FakeWebTaskRunner taskRunner;
+ RefPtr<scheduler::FakeWebTaskRunner> taskRunner =
+ adoptRef(new scheduler::FakeWebTaskRunner);
// Run without cancellation.
int count = 0;
- TaskHandle handle = taskRunner.postCancellableTask(
+ TaskHandle handle = taskRunner->postCancellableTask(
BLINK_FROM_HERE, WTF::bind(&increment, WTF::unretained(&count)));
EXPECT_EQ(0, count);
EXPECT_TRUE(handle.isActive());
- taskRunner.runUntilIdle();
+ taskRunner->runUntilIdle();
EXPECT_EQ(1, count);
EXPECT_FALSE(handle.isActive());
count = 0;
- handle = taskRunner.postDelayedCancellableTask(
+ handle = taskRunner->postDelayedCancellableTask(
BLINK_FROM_HERE, WTF::bind(&increment, WTF::unretained(&count)), 1);
EXPECT_EQ(0, count);
EXPECT_TRUE(handle.isActive());
- taskRunner.runUntilIdle();
+ taskRunner->runUntilIdle();
EXPECT_EQ(1, count);
EXPECT_FALSE(handle.isActive());
// Cancel a task.
count = 0;
- handle = taskRunner.postCancellableTask(
+ handle = taskRunner->postCancellableTask(
BLINK_FROM_HERE, WTF::bind(&increment, WTF::unretained(&count)));
handle.cancel();
EXPECT_EQ(0, count);
EXPECT_FALSE(handle.isActive());
- taskRunner.runUntilIdle();
+ taskRunner->runUntilIdle();
EXPECT_EQ(0, count);
// The task should be cancelled when the handle is dropped.
{
count = 0;
- TaskHandle handle2 = taskRunner.postCancellableTask(
+ TaskHandle handle2 = taskRunner->postCancellableTask(
BLINK_FROM_HERE, WTF::bind(&increment, WTF::unretained(&count)));
EXPECT_TRUE(handle2.isActive());
}
EXPECT_EQ(0, count);
- taskRunner.runUntilIdle();
+ taskRunner->runUntilIdle();
EXPECT_EQ(0, count);
// The task should be cancelled when another TaskHandle is assigned on it.
count = 0;
- handle = taskRunner.postCancellableTask(
+ handle = taskRunner->postCancellableTask(
BLINK_FROM_HERE, WTF::bind(&increment, WTF::unretained(&count)));
- handle = taskRunner.postCancellableTask(BLINK_FROM_HERE, WTF::bind([] {}));
+ handle = taskRunner->postCancellableTask(BLINK_FROM_HERE, WTF::bind([] {}));
EXPECT_EQ(0, count);
- taskRunner.runUntilIdle();
+ taskRunner->runUntilIdle();
EXPECT_EQ(0, count);
// Self assign should be nop.
count = 0;
- handle = taskRunner.postCancellableTask(
+ handle = taskRunner->postCancellableTask(
BLINK_FROM_HERE, WTF::bind(&increment, WTF::unretained(&count)));
#if COMPILER(CLANG)
#pragma GCC diagnostic push
@@ -102,30 +103,31 @@ TEST(WebTaskRunnerTest, PostCancellableTaskTest) {
handle = std::move(handle);
#endif // COMPILER(CLANG)
EXPECT_EQ(0, count);
- taskRunner.runUntilIdle();
+ taskRunner->runUntilIdle();
EXPECT_EQ(1, count);
// handle->isActive() should switch to false before the task starts running.
bool isActive = false;
- handle = taskRunner.postCancellableTask(
+ handle = taskRunner->postCancellableTask(
BLINK_FROM_HERE, WTF::bind(&getIsActive, WTF::unretained(&isActive),
WTF::unretained(&handle)));
EXPECT_TRUE(handle.isActive());
- taskRunner.runUntilIdle();
+ taskRunner->runUntilIdle();
EXPECT_FALSE(isActive);
EXPECT_FALSE(handle.isActive());
}
TEST(WebTaskRunnerTest, CancellationCheckerTest) {
- scheduler::FakeWebTaskRunner taskRunner;
+ RefPtr<scheduler::FakeWebTaskRunner> taskRunner =
+ adoptRef(new scheduler::FakeWebTaskRunner);
int count = 0;
- TaskHandle handle = taskRunner.postCancellableTask(
+ TaskHandle handle = taskRunner->postCancellableTask(
BLINK_FROM_HERE, WTF::bind(&increment, WTF::unretained(&count)));
EXPECT_EQ(0, count);
// TaskHandle::isActive should detect the deletion of posted task.
- auto queue = taskRunner.takePendingTasksForTesting();
+ auto queue = taskRunner->takePendingTasksForTesting();
ASSERT_EQ(1u, queue.size());
EXPECT_FALSE(queue[0].IsCancelled());
EXPECT_TRUE(handle.isActive());
@@ -135,13 +137,13 @@ TEST(WebTaskRunnerTest, CancellationCheckerTest) {
count = 0;
CancellationTestHelper helper;
- handle = taskRunner.postCancellableTask(
+ handle = taskRunner->postCancellableTask(
BLINK_FROM_HERE, WTF::bind(&CancellationTestHelper::incrementCounter,
helper.createWeakPtr()));
EXPECT_EQ(0, helper.counter());
// The cancellation of the posted task should be propagated to TaskHandle.
- queue = taskRunner.takePendingTasksForTesting();
+ queue = taskRunner->takePendingTasksForTesting();
ASSERT_EQ(1u, queue.size());
EXPECT_FALSE(queue[0].IsCancelled());
EXPECT_TRUE(handle.isActive());

Powered by Google App Engine
This is Rietveld 408576698