| OLD | NEW |
| 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 "platform/heap/Handle.h" |
| 8 #include "testing/gtest/include/gtest/gtest.h" | 8 #include "testing/gtest/include/gtest/gtest.h" |
| 9 #include "wtf/PtrUtil.h" | 9 #include "wtf/PtrUtil.h" |
| 10 #include <memory> | 10 #include <memory> |
| (...skipping 198 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 209 int GCObject::s_destructed = 0; | 209 int GCObject::s_destructed = 0; |
| 210 int GCObject::s_invoked = 0; | 210 int GCObject::s_invoked = 0; |
| 211 | 211 |
| 212 } // namespace | 212 } // namespace |
| 213 | 213 |
| 214 TEST(CancellableTaskFactoryTest, GarbageCollectedWeak) | 214 TEST(CancellableTaskFactoryTest, GarbageCollectedWeak) |
| 215 { | 215 { |
| 216 GCObject* object = new GCObject(); | 216 GCObject* object = new GCObject(); |
| 217 std::unique_ptr<WebTaskRunner::Task> task = wrapUnique(object->m_factory->ca
ncelAndCreate()); | 217 std::unique_ptr<WebTaskRunner::Task> task = wrapUnique(object->m_factory->ca
ncelAndCreate()); |
| 218 object = nullptr; | 218 object = nullptr; |
| 219 ThreadState::current()-> collectAllGarbage(); | 219 ThreadHeap::collectAllGarbage(); |
| 220 task->run(); | 220 task->run(); |
| 221 // The owning object will have been GCed and the task will have | 221 // The owning object will have been GCed and the task will have |
| 222 // lost its weak reference. Verify that it wasn't invoked. | 222 // lost its weak reference. Verify that it wasn't invoked. |
| 223 EXPECT_EQ(0, GCObject::s_invoked); | 223 EXPECT_EQ(0, GCObject::s_invoked); |
| 224 | 224 |
| 225 // ..and just to make sure |object| was indeed destructed. | 225 // ..and just to make sure |object| was indeed destructed. |
| 226 EXPECT_EQ(1, GCObject::s_destructed); | 226 EXPECT_EQ(1, GCObject::s_destructed); |
| 227 } | 227 } |
| 228 | 228 |
| 229 } // namespace blink | 229 } // namespace blink |
| OLD | NEW |