OLD | NEW |
(Empty) | |
| 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 |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #include "config.h" |
| 6 #include "core/dom/CrossThreadTask.h" |
| 7 |
| 8 #include "platform/heap/Handle.h" |
| 9 #include <gtest/gtest.h> |
| 10 |
| 11 namespace blink { |
| 12 |
| 13 class GCObject : public GarbageCollectedFinalized<GCObject> { |
| 14 public: |
| 15 static int s_counter; |
| 16 GCObject() { ++s_counter; } |
| 17 ~GCObject() { --s_counter; } |
| 18 DEFINE_INLINE_TRACE() { } |
| 19 void run(GCObject*) { } |
| 20 }; |
| 21 |
| 22 int GCObject::s_counter = 0; |
| 23 |
| 24 static void functionWithGarbageCollected(GCObject*) |
| 25 { |
| 26 } |
| 27 |
| 28 static void functionWithExecutionContext(ExecutionContext*, GCObject*) |
| 29 { |
| 30 } |
| 31 |
| 32 class CrossThreadTaskTest : public testing::Test { |
| 33 protected: |
| 34 void SetUp() override |
| 35 { |
| 36 GCObject::s_counter = 0; |
| 37 } |
| 38 void TearDown() override |
| 39 { |
| 40 Heap::collectGarbage(ThreadState::NoHeapPointersOnStack); |
| 41 ASSERT_EQ(0, GCObject::s_counter); |
| 42 } |
| 43 }; |
| 44 |
| 45 TEST_F(CrossThreadTaskTest, CreateForGarbageCollectedMethod) |
| 46 { |
| 47 OwnPtr<ExecutionContextTask> task1 = createCrossThreadTask(&GCObject::run, n
ew GCObject, new GCObject); |
| 48 OwnPtr<ExecutionContextTask> task2 = createCrossThreadTask(&GCObject::run, R
awPtr<GCObject>(new GCObject), RawPtr<GCObject>(new GCObject)); |
| 49 Heap::collectGarbage(ThreadState::NoHeapPointersOnStack); |
| 50 EXPECT_EQ(4, GCObject::s_counter); |
| 51 } |
| 52 |
| 53 TEST_F(CrossThreadTaskTest, CreateForFunctionWithGarbageCollected) |
| 54 { |
| 55 OwnPtr<ExecutionContextTask> task1 = createCrossThreadTask(&functionWithGarb
ageCollected, new GCObject); |
| 56 OwnPtr<ExecutionContextTask> task2 = createCrossThreadTask(&functionWithGarb
ageCollected, RawPtr<GCObject>(new GCObject)); |
| 57 Heap::collectGarbage(ThreadState::NoHeapPointersOnStack); |
| 58 EXPECT_EQ(2, GCObject::s_counter); |
| 59 } |
| 60 |
| 61 TEST_F(CrossThreadTaskTest, CreateForFunctionWithExecutionContext) |
| 62 { |
| 63 OwnPtr<ExecutionContextTask> task1 = createCrossThreadTask(&functionWithExec
utionContext, new GCObject); |
| 64 OwnPtr<ExecutionContextTask> task2 = createCrossThreadTask(&functionWithExec
utionContext, RawPtr<GCObject>(new GCObject)); |
| 65 Heap::collectGarbage(ThreadState::NoHeapPointersOnStack); |
| 66 EXPECT_EQ(2, GCObject::s_counter); |
| 67 } |
| 68 |
| 69 } |
OLD | NEW |