| OLD | NEW |
| (Empty) | |
| 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 |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #include "platform/heap/Persistent.h" |
| 6 |
| 7 #include "platform/ThreadSafeFunctional.h" |
| 8 #include "platform/heap/Heap.h" |
| 9 #include "testing/gtest/include/gtest/gtest.h" |
| 10 #include <memory> |
| 11 |
| 12 namespace blink { |
| 13 namespace { |
| 14 |
| 15 void preciselyCollectGarbage() |
| 16 { |
| 17 ThreadHeap::collectGarbage(BlinkGC::NoHeapPointersOnStack, BlinkGC::GCWithSw
eep, BlinkGC::ForcedGC); |
| 18 } |
| 19 |
| 20 class Receiver : public GarbageCollected<Receiver> { |
| 21 public: |
| 22 void increment(int* counter) |
| 23 { |
| 24 ++*counter; |
| 25 } |
| 26 |
| 27 DEFINE_INLINE_TRACE() {} |
| 28 }; |
| 29 |
| 30 TEST(PersistentTest, BindCancellation) |
| 31 { |
| 32 Receiver* receiver = new Receiver; |
| 33 int counter = 0; |
| 34 std::unique_ptr<SameThreadClosure> function = WTF::bind(&Receiver::increment
, wrapWeakPersistent(receiver), WTF::unretained(&counter)); |
| 35 |
| 36 (*function)(); |
| 37 EXPECT_EQ(1, counter); |
| 38 |
| 39 receiver = nullptr; |
| 40 preciselyCollectGarbage(); |
| 41 (*function)(); |
| 42 EXPECT_EQ(1, counter); |
| 43 } |
| 44 |
| 45 TEST(PersistentTest, CrossThreadBindCancellation) |
| 46 { |
| 47 Receiver* receiver = new Receiver; |
| 48 int counter = 0; |
| 49 std::unique_ptr<CrossThreadClosure> function = blink::threadSafeBind(&Receiv
er::increment, wrapCrossThreadWeakPersistent(receiver), WTF::crossThreadUnretain
ed(&counter)); |
| 50 |
| 51 (*function)(); |
| 52 EXPECT_EQ(1, counter); |
| 53 |
| 54 receiver = nullptr; |
| 55 preciselyCollectGarbage(); |
| 56 (*function)(); |
| 57 EXPECT_EQ(1, counter); |
| 58 } |
| 59 |
| 60 } // namespace |
| 61 } // namespace blink |
| OLD | NEW |