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

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

Issue 1976433003: Remove dated NavigationScheduler TODO. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: 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
« no previous file with comments | « third_party/WebKit/Source/core/loader/NavigationScheduler.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 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 "platform/heap/Handle.h"
7 #include "testing/gtest/include/gtest/gtest.h" 8 #include "testing/gtest/include/gtest/gtest.h"
8 9
9 namespace blink { 10 namespace blink {
10 11
11 namespace { 12 namespace {
12 13
13 class TestCancellableTaskFactory final : public CancellableTaskFactory { 14 class TestCancellableTaskFactory final : public CancellableTaskFactory {
14 public: 15 public:
15 explicit TestCancellableTaskFactory(PassOwnPtr<SameThreadClosure> closure) 16 explicit TestCancellableTaskFactory(PassOwnPtr<SameThreadClosure> closure)
16 : CancellableTaskFactory(std::move(closure)) 17 : CancellableTaskFactory(std::move(closure))
(...skipping 152 matching lines...) Expand 10 before | Expand all | Expand 10 after
169 OwnPtr<WebTaskRunner::Task> taskA = adoptPtr(factory.cancelAndCreate()); 170 OwnPtr<WebTaskRunner::Task> taskA = adoptPtr(factory.cancelAndCreate());
170 OwnPtr<WebTaskRunner::Task> taskB = adoptPtr(factory.cancelAndCreate()); 171 OwnPtr<WebTaskRunner::Task> taskB = adoptPtr(factory.cancelAndCreate());
171 172
172 taskA->run(); 173 taskA->run();
173 EXPECT_EQ(0, executionCount); 174 EXPECT_EQ(0, executionCount);
174 175
175 taskB->run(); 176 taskB->run();
176 EXPECT_EQ(1, executionCount); 177 EXPECT_EQ(1, executionCount);
177 } 178 }
178 179
180 namespace {
181
182 class GCObject final : public GarbageCollectedFinalized<GCObject> {
183 public:
184 GCObject()
185 : m_factory(CancellableTaskFactory::create(this, &GCObject::run))
186 {
187 }
188
189 ~GCObject()
190 {
191 s_destructed++;
192 }
193
194 void run()
195 {
196 s_invoked++;
197 }
198
199 DEFINE_INLINE_TRACE() { }
200
201 static int s_destructed;
202 static int s_invoked;
203
204 OwnPtr<CancellableTaskFactory> m_factory;
205 };
206
207 int GCObject::s_destructed = 0;
208 int GCObject::s_invoked = 0;
209
210 } // namespace
211
212 TEST(CancellableTaskFactoryTest, GarbageCollectedWeak)
213 {
214 GCObject* object = new GCObject();
215 OwnPtr<WebTaskRunner::Task> task = adoptPtr(object->m_factory->cancelAndCrea te());
216 object = nullptr;
217 ThreadHeap::collectAllGarbage();
218 task->run();
219 // The owning object will have been GCed and the task will have
220 // lost its weak reference. Verify that it wasn't invoked.
221 EXPECT_EQ(0, GCObject::s_invoked);
222
223 // ..and just to make sure |object| was indeed destructed.
224 EXPECT_EQ(1, GCObject::s_destructed);
225 }
226
179 } // namespace blink 227 } // namespace blink
OLDNEW
« no previous file with comments | « third_party/WebKit/Source/core/loader/NavigationScheduler.cpp ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698