| Index: third_party/WebKit/Source/platform/heap/PersistentTest.cpp
|
| diff --git a/third_party/WebKit/Source/platform/heap/PersistentTest.cpp b/third_party/WebKit/Source/platform/heap/PersistentTest.cpp
|
| new file mode 100644
|
| index 0000000000000000000000000000000000000000..2e43a20798aee9798100c81cbf5cbf977e5949b5
|
| --- /dev/null
|
| +++ b/third_party/WebKit/Source/platform/heap/PersistentTest.cpp
|
| @@ -0,0 +1,61 @@
|
| +// Copyright 2016 The Chromium Authors. All rights reserved.
|
| +// Use of this source code is governed by a BSD-style license that can be
|
| +// found in the LICENSE file.
|
| +
|
| +#include "platform/heap/Persistent.h"
|
| +
|
| +#include "platform/ThreadSafeFunctional.h"
|
| +#include "platform/heap/Heap.h"
|
| +#include "testing/gtest/include/gtest/gtest.h"
|
| +#include <memory>
|
| +
|
| +namespace blink {
|
| +namespace {
|
| +
|
| +void preciselyCollectGarbage()
|
| +{
|
| + ThreadHeap::collectGarbage(BlinkGC::NoHeapPointersOnStack, BlinkGC::GCWithSweep, BlinkGC::ForcedGC);
|
| +}
|
| +
|
| +class Receiver : public GarbageCollected<Receiver> {
|
| +public:
|
| + void increment(int* counter)
|
| + {
|
| + ++*counter;
|
| + }
|
| +
|
| + DEFINE_INLINE_TRACE() {}
|
| +};
|
| +
|
| +TEST(PersistentTest, BindCancellation)
|
| +{
|
| + Receiver* receiver = new Receiver;
|
| + int counter = 0;
|
| + std::unique_ptr<SameThreadClosure> function = WTF::bind(&Receiver::increment, wrapWeakPersistent(receiver), WTF::unretained(&counter));
|
| +
|
| + (*function)();
|
| + EXPECT_EQ(1, counter);
|
| +
|
| + receiver = nullptr;
|
| + preciselyCollectGarbage();
|
| + (*function)();
|
| + EXPECT_EQ(1, counter);
|
| +}
|
| +
|
| +TEST(PersistentTest, CrossThreadBindCancellation)
|
| +{
|
| + Receiver* receiver = new Receiver;
|
| + int counter = 0;
|
| + std::unique_ptr<CrossThreadClosure> function = blink::threadSafeBind(&Receiver::increment, wrapCrossThreadWeakPersistent(receiver), WTF::crossThreadUnretained(&counter));
|
| +
|
| + (*function)();
|
| + EXPECT_EQ(1, counter);
|
| +
|
| + receiver = nullptr;
|
| + preciselyCollectGarbage();
|
| + (*function)();
|
| + EXPECT_EQ(1, counter);
|
| +}
|
| +
|
| +} // namespace
|
| +} // namespace blink
|
|
|