Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(199)

Unified Diff: third_party/WebKit/Source/core/dom/StyleEngineTest.cpp

Issue 2205843003: Use weak members to cache StyleSheetContents. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Might be in cache without being used before garbage collection Created 4 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: third_party/WebKit/Source/core/dom/StyleEngineTest.cpp
diff --git a/third_party/WebKit/Source/core/dom/StyleEngineTest.cpp b/third_party/WebKit/Source/core/dom/StyleEngineTest.cpp
index 7d2bd26ac6912c3b9ece74529e701833330696be..440b7a824da5dbe648bedd182b8aeccdf7dd1506 100644
--- a/third_party/WebKit/Source/core/dom/StyleEngineTest.cpp
+++ b/third_party/WebKit/Source/core/dom/StyleEngineTest.cpp
@@ -9,7 +9,9 @@
#include "core/dom/NodeComputedStyle.h"
#include "core/frame/FrameView.h"
#include "core/html/HTMLElement.h"
+#include "core/html/HTMLStyleElement.h"
#include "core/testing/DummyPageHolder.h"
+#include "platform/heap/Heap.h"
#include "testing/gtest/include/gtest/gtest.h"
#include <memory>
@@ -67,4 +69,37 @@ TEST_F(StyleEngineTest, AnalyzedInject)
EXPECT_EQ(makeRGB(0, 128, 0), t1->computedStyle()->visitedDependentColor(CSSPropertyColor));
}
+TEST_F(StyleEngineTest, TextToSheetCache)
+{
+ HTMLStyleElement* element = HTMLStyleElement::create(document(), false);
+
+ String sheetText("div {}");
+ TextPosition minPos = TextPosition::minimumPosition();
+ StyleEngineContext context;
+
+ CSSStyleSheet* sheet1 = styleEngine().createSheet(element, sheetText, minPos, context);
+
+ // Check that the first sheet is not using a cached StyleSheetContents.
+ EXPECT_FALSE(sheet1->contents()->isUsedFromTextCache());
+
+ CSSStyleSheet* sheet2 = styleEngine().createSheet(element, sheetText, minPos, context);
+
+ // Check that the second sheet uses the cached StyleSheetContents for the first.
+ EXPECT_EQ(sheet1->contents(), sheet2->contents());
+ EXPECT_TRUE(sheet2->contents()->isUsedFromTextCache());
+
+ sheet1 = nullptr;
+ sheet2 = nullptr;
+ element = nullptr;
+
+ // Garbage collection should clear the weak reference in the StyleSheetContents cache.
+ ThreadHeap::collectAllGarbage();
+
+ element = HTMLStyleElement::create(document(), false);
+ sheet1 = styleEngine().createSheet(element, sheetText, minPos, context);
+
+ // Check that we did not use a cached StyleSheetContents after the garbage collection.
+ EXPECT_FALSE(sheet1->contents()->isUsedFromTextCache());
+}
+
} // namespace blink

Powered by Google App Engine
This is Rietveld 408576698