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

Side by Side 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 unified diff | Download patch
OLDNEW
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 "core/dom/StyleEngine.h" 5 #include "core/dom/StyleEngine.h"
6 6
7 #include "core/css/StyleSheetContents.h" 7 #include "core/css/StyleSheetContents.h"
8 #include "core/dom/Document.h" 8 #include "core/dom/Document.h"
9 #include "core/dom/NodeComputedStyle.h" 9 #include "core/dom/NodeComputedStyle.h"
10 #include "core/frame/FrameView.h" 10 #include "core/frame/FrameView.h"
11 #include "core/html/HTMLElement.h" 11 #include "core/html/HTMLElement.h"
12 #include "core/html/HTMLStyleElement.h"
12 #include "core/testing/DummyPageHolder.h" 13 #include "core/testing/DummyPageHolder.h"
14 #include "platform/heap/Heap.h"
13 #include "testing/gtest/include/gtest/gtest.h" 15 #include "testing/gtest/include/gtest/gtest.h"
14 #include <memory> 16 #include <memory>
15 17
16 namespace blink { 18 namespace blink {
17 19
18 class StyleEngineTest : public ::testing::Test { 20 class StyleEngineTest : public ::testing::Test {
19 protected: 21 protected:
20 void SetUp() override; 22 void SetUp() override;
21 23
22 Document& document() { return m_dummyPageHolder->document(); } 24 Document& document() { return m_dummyPageHolder->document(); }
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
60 styleEngine().injectAuthorSheet(parsedSheet); 62 styleEngine().injectAuthorSheet(parsedSheet);
61 document().view()->updateAllLifecyclePhases(); 63 document().view()->updateAllLifecyclePhases();
62 64
63 unsigned afterCount = styleEngine().styleForElementCount(); 65 unsigned afterCount = styleEngine().styleForElementCount();
64 EXPECT_EQ(1u, afterCount - beforeCount); 66 EXPECT_EQ(1u, afterCount - beforeCount);
65 67
66 ASSERT_TRUE(t1->computedStyle()); 68 ASSERT_TRUE(t1->computedStyle());
67 EXPECT_EQ(makeRGB(0, 128, 0), t1->computedStyle()->visitedDependentColor(CSS PropertyColor)); 69 EXPECT_EQ(makeRGB(0, 128, 0), t1->computedStyle()->visitedDependentColor(CSS PropertyColor));
68 } 70 }
69 71
72 TEST_F(StyleEngineTest, TextToSheetCache)
73 {
74 HTMLStyleElement* element = HTMLStyleElement::create(document(), false);
75
76 String sheetText("div {}");
77 TextPosition minPos = TextPosition::minimumPosition();
78 StyleEngineContext context;
79
80 CSSStyleSheet* sheet1 = styleEngine().createSheet(element, sheetText, minPos , context);
81
82 // Check that the first sheet is not using a cached StyleSheetContents.
83 EXPECT_FALSE(sheet1->contents()->isUsedFromTextCache());
84
85 CSSStyleSheet* sheet2 = styleEngine().createSheet(element, sheetText, minPos , context);
86
87 // Check that the second sheet uses the cached StyleSheetContents for the fi rst.
88 EXPECT_EQ(sheet1->contents(), sheet2->contents());
89 EXPECT_TRUE(sheet2->contents()->isUsedFromTextCache());
90
91 sheet1 = nullptr;
92 sheet2 = nullptr;
93 element = nullptr;
94
95 // Garbage collection should clear the weak reference in the StyleSheetConte nts cache.
96 ThreadHeap::collectAllGarbage();
97
98 element = HTMLStyleElement::create(document(), false);
99 sheet1 = styleEngine().createSheet(element, sheetText, minPos, context);
100
101 // Check that we did not use a cached StyleSheetContents after the garbage c ollection.
102 EXPECT_FALSE(sheet1->contents()->isUsedFromTextCache());
103 }
104
70 } // namespace blink 105 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698