Chromium Code Reviews| 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 "core/dom/CrossThreadTask.h" | |
| 6 | |
| 7 #include "platform/heap/Handle.h" | |
| 8 #include "testing/gtest/include/gtest/gtest.h" | |
| 9 | |
| 10 namespace blink { | |
| 11 | |
| 12 class GCObject : public GarbageCollectedFinalized<GCObject> { | |
| 13 public: | |
| 14 static int s_counter; | |
| 15 GCObject() { ++s_counter; } | |
| 16 ~GCObject() { --s_counter; } | |
| 17 DEFINE_INLINE_TRACE() { } | |
| 18 void run(GCObject*) { } | |
| 19 }; | |
| 20 | |
| 21 int GCObject::s_counter = 0; | |
| 22 | |
| 23 static void functionWithGarbageCollected(GCObject*) | |
| 24 { | |
| 25 } | |
| 26 | |
| 27 static void functionWithExecutionContext(GCObject*, ExecutionContext*) | |
| 28 { | |
| 29 } | |
| 30 | |
| 31 class CrossThreadTaskTest : public testing::Test { | |
| 32 protected: | |
| 33 void SetUp() override | |
| 34 { | |
| 35 GCObject::s_counter = 0; | |
| 36 } | |
| 37 void TearDown() override | |
| 38 { | |
| 39 ThreadHeap::collectGarbage(BlinkGC::NoHeapPointersOnStack, BlinkGC::GCWi thSweep, BlinkGC::ForcedGC); | |
| 40 ASSERT_EQ(0, GCObject::s_counter); | |
| 41 } | |
| 42 }; | |
| 43 | |
| 44 TEST_F(CrossThreadTaskTest, CreateForGarbageCollectedMethod) | |
|
haraken
2016/08/25 07:41:06
Do we want to remove tests in this file?
| |
| 45 { | |
| 46 std::unique_ptr<ExecutionContextTask> task1 = createCrossThreadTask(&GCObjec t::run, wrapCrossThreadPersistent(new GCObject), wrapCrossThreadPersistent(new G CObject)); | |
| 47 std::unique_ptr<ExecutionContextTask> task2 = createCrossThreadTask(&GCObjec t::run, wrapCrossThreadPersistent(new GCObject), wrapCrossThreadPersistent(new G CObject)); | |
| 48 ThreadHeap::collectGarbage(BlinkGC::NoHeapPointersOnStack, BlinkGC::GCWithSw eep, BlinkGC::ForcedGC); | |
| 49 EXPECT_EQ(4, GCObject::s_counter); | |
| 50 } | |
| 51 | |
| 52 TEST_F(CrossThreadTaskTest, CreateForFunctionWithGarbageCollected) | |
| 53 { | |
| 54 std::unique_ptr<ExecutionContextTask> task1 = createCrossThreadTask(&functio nWithGarbageCollected, wrapCrossThreadPersistent(new GCObject)); | |
| 55 std::unique_ptr<ExecutionContextTask> task2 = createCrossThreadTask(&functio nWithGarbageCollected, wrapCrossThreadPersistent(new GCObject)); | |
| 56 ThreadHeap::collectGarbage(BlinkGC::NoHeapPointersOnStack, BlinkGC::GCWithSw eep, BlinkGC::ForcedGC); | |
| 57 EXPECT_EQ(2, GCObject::s_counter); | |
| 58 } | |
| 59 | |
| 60 TEST_F(CrossThreadTaskTest, CreateForFunctionWithExecutionContext) | |
| 61 { | |
| 62 std::unique_ptr<ExecutionContextTask> task1 = createCrossThreadTask(&functio nWithExecutionContext, wrapCrossThreadPersistent(new GCObject)); | |
| 63 std::unique_ptr<ExecutionContextTask> task2 = createCrossThreadTask(&functio nWithExecutionContext, wrapCrossThreadPersistent(new GCObject)); | |
| 64 ThreadHeap::collectGarbage(BlinkGC::NoHeapPointersOnStack, BlinkGC::GCWithSw eep, BlinkGC::ForcedGC); | |
| 65 EXPECT_EQ(2, GCObject::s_counter); | |
| 66 } | |
| 67 | |
| 68 } // namespace blink | |
| OLD | NEW |