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

Side by Side Diff: third_party/WebKit/Source/platform/WebTaskRunnerTest.cpp

Issue 2701993002: DO NOT COMMIT: Results of running new (proposed) clang-format on Blink (Closed)
Patch Set: Created 3 years, 10 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 unified diff | Download patch
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 91 matching lines...) Expand 10 before | Expand all | Expand 10 after
102 #else 102 #else
103 handle = std::move(handle); 103 handle = std::move(handle);
104 #endif // COMPILER(CLANG) 104 #endif // COMPILER(CLANG)
105 EXPECT_EQ(0, count); 105 EXPECT_EQ(0, count);
106 taskRunner->runUntilIdle(); 106 taskRunner->runUntilIdle();
107 EXPECT_EQ(1, count); 107 EXPECT_EQ(1, count);
108 108
109 // handle->isActive() should switch to false before the task starts running. 109 // handle->isActive() should switch to false before the task starts running.
110 bool isActive = false; 110 bool isActive = false;
111 handle = taskRunner->postCancellableTask( 111 handle = taskRunner->postCancellableTask(
112 BLINK_FROM_HERE, WTF::bind(&getIsActive, WTF::unretained(&isActive), 112 BLINK_FROM_HERE,
113 WTF::unretained(&handle))); 113 WTF::bind(&getIsActive, WTF::unretained(&isActive),
114 WTF::unretained(&handle)));
114 EXPECT_TRUE(handle.isActive()); 115 EXPECT_TRUE(handle.isActive());
115 taskRunner->runUntilIdle(); 116 taskRunner->runUntilIdle();
116 EXPECT_FALSE(isActive); 117 EXPECT_FALSE(isActive);
117 EXPECT_FALSE(handle.isActive()); 118 EXPECT_FALSE(handle.isActive());
118 } 119 }
119 120
120 TEST(WebTaskRunnerTest, CancellationCheckerTest) { 121 TEST(WebTaskRunnerTest, CancellationCheckerTest) {
121 RefPtr<scheduler::FakeWebTaskRunner> taskRunner = 122 RefPtr<scheduler::FakeWebTaskRunner> taskRunner =
122 adoptRef(new scheduler::FakeWebTaskRunner); 123 adoptRef(new scheduler::FakeWebTaskRunner);
123 124
124 int count = 0; 125 int count = 0;
125 TaskHandle handle = taskRunner->postCancellableTask( 126 TaskHandle handle = taskRunner->postCancellableTask(
126 BLINK_FROM_HERE, WTF::bind(&increment, WTF::unretained(&count))); 127 BLINK_FROM_HERE, WTF::bind(&increment, WTF::unretained(&count)));
127 EXPECT_EQ(0, count); 128 EXPECT_EQ(0, count);
128 129
129 // TaskHandle::isActive should detect the deletion of posted task. 130 // TaskHandle::isActive should detect the deletion of posted task.
130 auto queue = taskRunner->takePendingTasksForTesting(); 131 auto queue = taskRunner->takePendingTasksForTesting();
131 ASSERT_EQ(1u, queue.size()); 132 ASSERT_EQ(1u, queue.size());
132 EXPECT_FALSE(queue[0].IsCancelled()); 133 EXPECT_FALSE(queue[0].IsCancelled());
133 EXPECT_TRUE(handle.isActive()); 134 EXPECT_TRUE(handle.isActive());
134 queue.clear(); 135 queue.clear();
135 EXPECT_FALSE(handle.isActive()); 136 EXPECT_FALSE(handle.isActive());
136 EXPECT_EQ(0, count); 137 EXPECT_EQ(0, count);
137 138
138 count = 0; 139 count = 0;
139 CancellationTestHelper helper; 140 CancellationTestHelper helper;
140 handle = taskRunner->postCancellableTask( 141 handle = taskRunner->postCancellableTask(
141 BLINK_FROM_HERE, WTF::bind(&CancellationTestHelper::incrementCounter, 142 BLINK_FROM_HERE,
142 helper.createWeakPtr())); 143 WTF::bind(&CancellationTestHelper::incrementCounter,
144 helper.createWeakPtr()));
143 EXPECT_EQ(0, helper.counter()); 145 EXPECT_EQ(0, helper.counter());
144 146
145 // The cancellation of the posted task should be propagated to TaskHandle. 147 // The cancellation of the posted task should be propagated to TaskHandle.
146 queue = taskRunner->takePendingTasksForTesting(); 148 queue = taskRunner->takePendingTasksForTesting();
147 ASSERT_EQ(1u, queue.size()); 149 ASSERT_EQ(1u, queue.size());
148 EXPECT_FALSE(queue[0].IsCancelled()); 150 EXPECT_FALSE(queue[0].IsCancelled());
149 EXPECT_TRUE(handle.isActive()); 151 EXPECT_TRUE(handle.isActive());
150 helper.revokeWeakPtrs(); 152 helper.revokeWeakPtrs();
151 EXPECT_TRUE(queue[0].IsCancelled()); 153 EXPECT_TRUE(queue[0].IsCancelled());
152 EXPECT_FALSE(handle.isActive()); 154 EXPECT_FALSE(handle.isActive());
153 } 155 }
154 156
155 } // namespace blink 157 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698