| OLD | NEW |
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. | 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 | 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 "modules/csspaint/PaintWorklet.h" | 5 #include "modules/csspaint/PaintWorklet.h" |
| 6 | 6 |
| 7 #include <memory> |
| 7 #include "bindings/core/v8/ScriptSourceCode.h" | 8 #include "bindings/core/v8/ScriptSourceCode.h" |
| 8 #include "bindings/core/v8/V8GCController.h" | 9 #include "bindings/core/v8/V8GCController.h" |
| 9 #include "bindings/core/v8/WorkerOrWorkletScriptController.h" | 10 #include "bindings/core/v8/WorkerOrWorkletScriptController.h" |
| 10 #include "core/frame/LocalFrame.h" | 11 #include "core/frame/LocalFrame.h" |
| 11 #include "core/testing/DummyPageHolder.h" | 12 #include "core/testing/DummyPageHolder.h" |
| 12 #include "modules/csspaint/CSSPaintDefinition.h" | 13 #include "modules/csspaint/CSSPaintDefinition.h" |
| 13 #include "modules/csspaint/PaintWorkletGlobalScope.h" | 14 #include "modules/csspaint/PaintWorkletGlobalScope.h" |
| 15 #include "modules/csspaint/PaintWorkletGlobalScopeProxy.h" |
| 14 #include "modules/csspaint/WindowPaintWorklet.h" | 16 #include "modules/csspaint/WindowPaintWorklet.h" |
| 15 #include "testing/gtest/include/gtest/gtest.h" | 17 #include "testing/gtest/include/gtest/gtest.h" |
| 16 #include <memory> | |
| 17 | 18 |
| 18 namespace blink { | 19 namespace blink { |
| 19 | 20 |
| 21 using GlobalScopeProxies = |
| 22 WTF::HashSet<std::unique_ptr<WorkletGlobalScopeProxy>>; |
| 23 |
| 20 class PaintWorkletTest : public testing::Test { | 24 class PaintWorkletTest : public testing::Test { |
| 21 public: | 25 public: |
| 22 PaintWorkletTest() : page_(DummyPageHolder::Create()) {} | 26 PaintWorkletTest() : page_(DummyPageHolder::Create()) {} |
| 23 | 27 |
| 28 void SetUp() override { GetPaintWorklet()->MayAddWorkletGlobalScopes(); } |
| 29 |
| 24 PaintWorklet* GetPaintWorklet() { | 30 PaintWorklet* GetPaintWorklet() { |
| 25 return WindowPaintWorklet::From(*page_->GetFrame().DomWindow()) | 31 return WindowPaintWorklet::From(*page_->GetFrame().DomWindow()) |
| 26 .paintWorklet(); | 32 .paintWorklet(); |
| 27 } | 33 } |
| 28 | 34 |
| 35 GlobalScopeProxies& GetGlobalScopeProxies() { |
| 36 return GetPaintWorklet()->global_scope_proxies_; |
| 37 } |
| 38 |
| 29 protected: | 39 protected: |
| 30 std::unique_ptr<DummyPageHolder> page_; | 40 std::unique_ptr<DummyPageHolder> page_; |
| 31 }; | 41 }; |
| 32 | 42 |
| 33 TEST_F(PaintWorkletTest, GarbageCollectionOfCSSPaintDefinition) { | 43 TEST_F(PaintWorkletTest, GarbageCollectionOfCSSPaintDefinition) { |
| 44 GlobalScopeProxies& proxies = GetGlobalScopeProxies(); |
| 45 EXPECT_EQ(1u, proxies.size()); |
| 46 WorkletGlobalScopeProxy* proxy = proxies.begin()->get(); |
| 34 PaintWorkletGlobalScope* global_scope = | 47 PaintWorkletGlobalScope* global_scope = |
| 35 GetPaintWorklet()->GetWorkletGlobalScopeProxy(); | 48 PaintWorkletGlobalScopeProxy::From(proxy)->global_scope(); |
| 49 |
| 36 global_scope->ScriptController()->Evaluate( | 50 global_scope->ScriptController()->Evaluate( |
| 37 ScriptSourceCode("registerPaint('foo', class { paint() { } });")); | 51 ScriptSourceCode("registerPaint('foo', class { paint() { } });")); |
| 38 | 52 |
| 39 CSSPaintDefinition* definition = global_scope->FindDefinition("foo"); | 53 CSSPaintDefinition* definition = global_scope->FindDefinition("foo"); |
| 40 ASSERT(definition); | 54 ASSERT(definition); |
| 41 | 55 |
| 42 v8::Isolate* isolate = | 56 v8::Isolate* isolate = |
| 43 global_scope->ScriptController()->GetScriptState()->GetIsolate(); | 57 global_scope->ScriptController()->GetScriptState()->GetIsolate(); |
| 44 ASSERT(isolate); | 58 ASSERT(isolate); |
| 45 | 59 |
| (...skipping 15 matching lines...) Expand all Loading... |
| 61 // Delete the page & associated objects. | 75 // Delete the page & associated objects. |
| 62 page_.reset(); | 76 page_.reset(); |
| 63 | 77 |
| 64 // Run a GC, the persistent should have been collected. | 78 // Run a GC, the persistent should have been collected. |
| 65 ThreadState::Current()->CollectAllGarbage(); | 79 ThreadState::Current()->CollectAllGarbage(); |
| 66 V8GCController::CollectAllGarbageForTesting(isolate); | 80 V8GCController::CollectAllGarbageForTesting(isolate); |
| 67 ASSERT(handle.IsEmpty()); | 81 ASSERT(handle.IsEmpty()); |
| 68 } | 82 } |
| 69 | 83 |
| 70 } // namespace blink | 84 } // namespace blink |
| OLD | NEW |