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

Side by Side Diff: third_party/WebKit/Source/platform/scheduler/CancellableTaskFactoryTest.cpp

Issue 1915153004: [K5] Replace bind() + non-GC pointers with unretained() (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@Kuroneko_4
Patch Set: Rebase Created 4 years, 7 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 2015 The Chromium Authors. All rights reserved. 1 // Copyright 2015 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/scheduler/CancellableTaskFactory.h" 5 #include "platform/scheduler/CancellableTaskFactory.h"
6 6
7 #include "testing/gtest/include/gtest/gtest.h" 7 #include "testing/gtest/include/gtest/gtest.h"
8 8
9 namespace blink { 9 namespace blink {
10 10
(...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after
92 } 92 }
93 93
94 void AddOne(int* ptr) 94 void AddOne(int* ptr)
95 { 95 {
96 *ptr += 1; 96 *ptr += 1;
97 } 97 }
98 98
99 TEST_F(CancellableTaskFactoryTest, Run_ClosureIsExecuted) 99 TEST_F(CancellableTaskFactoryTest, Run_ClosureIsExecuted)
100 { 100 {
101 int executionCount = 0; 101 int executionCount = 0;
102 TestCancellableTaskFactory factory(WTF::bind(&AddOne, &executionCount)); 102 TestCancellableTaskFactory factory(WTF::bind(&AddOne, unretained(&executionC ount)));
103 OwnPtr<WebTaskRunner::Task> task = adoptPtr(factory.cancelAndCreate()); 103 OwnPtr<WebTaskRunner::Task> task = adoptPtr(factory.cancelAndCreate());
104 task->run(); 104 task->run();
105 105
106 EXPECT_EQ(1, executionCount); 106 EXPECT_EQ(1, executionCount);
107 } 107 }
108 108
109 TEST_F(CancellableTaskFactoryTest, Run_ClosureIsExecutedOnlyOnce) 109 TEST_F(CancellableTaskFactoryTest, Run_ClosureIsExecutedOnlyOnce)
110 { 110 {
111 int executionCount = 0; 111 int executionCount = 0;
112 TestCancellableTaskFactory factory(WTF::bind(&AddOne, &executionCount)); 112 TestCancellableTaskFactory factory(WTF::bind(&AddOne, unretained(&executionC ount)));
113 OwnPtr<WebTaskRunner::Task> task = adoptPtr(factory.cancelAndCreate()); 113 OwnPtr<WebTaskRunner::Task> task = adoptPtr(factory.cancelAndCreate());
114 task->run(); 114 task->run();
115 task->run(); 115 task->run();
116 task->run(); 116 task->run();
117 task->run(); 117 task->run();
118 118
119 EXPECT_EQ(1, executionCount); 119 EXPECT_EQ(1, executionCount);
120 } 120 }
121 121
122 TEST_F(CancellableTaskFactoryTest, Run_FactoryDestructionPreventsExecution) 122 TEST_F(CancellableTaskFactoryTest, Run_FactoryDestructionPreventsExecution)
123 { 123 {
124 int executionCount = 0; 124 int executionCount = 0;
125 OwnPtr<WebTaskRunner::Task> task; 125 OwnPtr<WebTaskRunner::Task> task;
126 { 126 {
127 TestCancellableTaskFactory factory(WTF::bind(&AddOne, &executionCount)); 127 TestCancellableTaskFactory factory(WTF::bind(&AddOne, unretained(&execut ionCount)));
128 task = adoptPtr(factory.cancelAndCreate()); 128 task = adoptPtr(factory.cancelAndCreate());
129 } 129 }
130 task->run(); 130 task->run();
131 131
132 EXPECT_EQ(0, executionCount); 132 EXPECT_EQ(0, executionCount);
133 } 133 }
134 134
135 TEST_F(CancellableTaskFactoryTest, Run_TasksInSequence) 135 TEST_F(CancellableTaskFactoryTest, Run_TasksInSequence)
136 { 136 {
137 int executionCount = 0; 137 int executionCount = 0;
138 TestCancellableTaskFactory factory(WTF::bind(&AddOne, &executionCount)); 138 TestCancellableTaskFactory factory(WTF::bind(&AddOne, unretained(&executionC ount)));
139 139
140 OwnPtr<WebTaskRunner::Task> taskA = adoptPtr(factory.cancelAndCreate()); 140 OwnPtr<WebTaskRunner::Task> taskA = adoptPtr(factory.cancelAndCreate());
141 taskA->run(); 141 taskA->run();
142 EXPECT_EQ(1, executionCount); 142 EXPECT_EQ(1, executionCount);
143 143
144 OwnPtr<WebTaskRunner::Task> taskB = adoptPtr(factory.cancelAndCreate()); 144 OwnPtr<WebTaskRunner::Task> taskB = adoptPtr(factory.cancelAndCreate());
145 taskB->run(); 145 taskB->run();
146 EXPECT_EQ(2, executionCount); 146 EXPECT_EQ(2, executionCount);
147 147
148 OwnPtr<WebTaskRunner::Task> taskC = adoptPtr(factory.cancelAndCreate()); 148 OwnPtr<WebTaskRunner::Task> taskC = adoptPtr(factory.cancelAndCreate());
149 taskC->run(); 149 taskC->run();
150 EXPECT_EQ(3, executionCount); 150 EXPECT_EQ(3, executionCount);
151 } 151 }
152 152
153 TEST_F(CancellableTaskFactoryTest, Cancel) 153 TEST_F(CancellableTaskFactoryTest, Cancel)
154 { 154 {
155 int executionCount = 0; 155 int executionCount = 0;
156 TestCancellableTaskFactory factory(WTF::bind(&AddOne, &executionCount)); 156 TestCancellableTaskFactory factory(WTF::bind(&AddOne, unretained(&executionC ount)));
157 OwnPtr<WebTaskRunner::Task> task = adoptPtr(factory.cancelAndCreate()); 157 OwnPtr<WebTaskRunner::Task> task = adoptPtr(factory.cancelAndCreate());
158 factory.cancel(); 158 factory.cancel();
159 task->run(); 159 task->run();
160 160
161 EXPECT_EQ(0, executionCount); 161 EXPECT_EQ(0, executionCount);
162 } 162 }
163 163
164 TEST_F(CancellableTaskFactoryTest, CreatingANewTaskCancelsPreviousOnes) 164 TEST_F(CancellableTaskFactoryTest, CreatingANewTaskCancelsPreviousOnes)
165 { 165 {
166 int executionCount = 0; 166 int executionCount = 0;
167 TestCancellableTaskFactory factory(WTF::bind(&AddOne, &executionCount)); 167 TestCancellableTaskFactory factory(WTF::bind(&AddOne, unretained(&executionC ount)));
168 168
169 OwnPtr<WebTaskRunner::Task> taskA = adoptPtr(factory.cancelAndCreate()); 169 OwnPtr<WebTaskRunner::Task> taskA = adoptPtr(factory.cancelAndCreate());
170 OwnPtr<WebTaskRunner::Task> taskB = adoptPtr(factory.cancelAndCreate()); 170 OwnPtr<WebTaskRunner::Task> taskB = adoptPtr(factory.cancelAndCreate());
171 171
172 taskA->run(); 172 taskA->run();
173 EXPECT_EQ(0, executionCount); 173 EXPECT_EQ(0, executionCount);
174 174
175 taskB->run(); 175 taskB->run();
176 EXPECT_EQ(1, executionCount); 176 EXPECT_EQ(1, executionCount);
177 } 177 }
178 178
179 } // namespace blink 179 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698