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

Side by Side Diff: third_party/WebKit/Source/core/dom/StyleEngineTest.cpp

Issue 2616093003: Make CSSParserContext be garbage collected. (Closed)
Patch Set: fix fuzzer compile again Created 3 years, 11 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/css/parser/CSSParserContext.h" 8 #include "core/css/parser/CSSParserContext.h"
9 #include "core/dom/Document.h" 9 #include "core/dom/Document.h"
10 #include "core/dom/NodeComputedStyle.h" 10 #include "core/dom/NodeComputedStyle.h"
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
42 }; 42 };
43 43
44 void StyleEngineTest::SetUp() { 44 void StyleEngineTest::SetUp() {
45 m_dummyPageHolder = DummyPageHolder::create(IntSize(800, 600)); 45 m_dummyPageHolder = DummyPageHolder::create(IntSize(800, 600));
46 } 46 }
47 47
48 StyleEngineTest::RuleSetInvalidation 48 StyleEngineTest::RuleSetInvalidation
49 StyleEngineTest::scheduleInvalidationsForRules(TreeScope& treeScope, 49 StyleEngineTest::scheduleInvalidationsForRules(TreeScope& treeScope,
50 const String& cssText) { 50 const String& cssText) {
51 StyleSheetContents* sheet = 51 StyleSheetContents* sheet =
52 StyleSheetContents::create(CSSParserContext(HTMLStandardMode, nullptr)); 52 StyleSheetContents::create(CSSParserContext::create(HTMLStandardMode));
53 sheet->parseString(cssText); 53 sheet->parseString(cssText);
54 HeapHashSet<Member<RuleSet>> ruleSets; 54 HeapHashSet<Member<RuleSet>> ruleSets;
55 RuleSet& ruleSet = sheet->ensureRuleSet(MediaQueryEvaluator(), 55 RuleSet& ruleSet = sheet->ensureRuleSet(MediaQueryEvaluator(),
56 RuleHasDocumentSecurityOrigin); 56 RuleHasDocumentSecurityOrigin);
57 ruleSet.compactRulesIfNeeded(); 57 ruleSet.compactRulesIfNeeded();
58 if (ruleSet.needsFullRecalcForRuleSetInvalidation()) 58 if (ruleSet.needsFullRecalcForRuleSetInvalidation())
59 return RuleSetInvalidationFullRecalc; 59 return RuleSetInvalidationFullRecalc;
60 ruleSets.add(&ruleSet); 60 ruleSets.add(&ruleSet);
61 styleEngine().scheduleInvalidationsForRuleSets(treeScope, ruleSets); 61 styleEngine().scheduleInvalidationsForRuleSets(treeScope, ruleSets);
62 return RuleSetInvalidationsScheduled; 62 return RuleSetInvalidationsScheduled;
63 } 63 }
64 64
65 TEST_F(StyleEngineTest, DocumentDirtyAfterInject) { 65 TEST_F(StyleEngineTest, DocumentDirtyAfterInject) {
66 StyleSheetContents* parsedSheet = 66 StyleSheetContents* parsedSheet =
67 StyleSheetContents::create(CSSParserContext(document(), nullptr)); 67 StyleSheetContents::create(CSSParserContext::create(document()));
68 parsedSheet->parseString("div {}"); 68 parsedSheet->parseString("div {}");
69 styleEngine().injectAuthorSheet(parsedSheet); 69 styleEngine().injectAuthorSheet(parsedSheet);
70 document().view()->updateAllLifecyclePhases(); 70 document().view()->updateAllLifecyclePhases();
71 71
72 EXPECT_TRUE(isDocumentStyleSheetCollectionClean()); 72 EXPECT_TRUE(isDocumentStyleSheetCollectionClean());
73 } 73 }
74 74
75 TEST_F(StyleEngineTest, AnalyzedInject) { 75 TEST_F(StyleEngineTest, AnalyzedInject) {
76 document().body()->setInnerHTML( 76 document().body()->setInnerHTML(
77 "<style>div { color: red }</style><div id='t1'>Green</div><div></div>"); 77 "<style>div { color: red }</style><div id='t1'>Green</div><div></div>");
78 document().view()->updateAllLifecyclePhases(); 78 document().view()->updateAllLifecyclePhases();
79 79
80 Element* t1 = document().getElementById("t1"); 80 Element* t1 = document().getElementById("t1");
81 ASSERT_TRUE(t1); 81 ASSERT_TRUE(t1);
82 ASSERT_TRUE(t1->computedStyle()); 82 ASSERT_TRUE(t1->computedStyle());
83 EXPECT_EQ(makeRGB(255, 0, 0), 83 EXPECT_EQ(makeRGB(255, 0, 0),
84 t1->computedStyle()->visitedDependentColor(CSSPropertyColor)); 84 t1->computedStyle()->visitedDependentColor(CSSPropertyColor));
85 85
86 unsigned beforeCount = styleEngine().styleForElementCount(); 86 unsigned beforeCount = styleEngine().styleForElementCount();
87 87
88 StyleSheetContents* parsedSheet = 88 StyleSheetContents* parsedSheet =
89 StyleSheetContents::create(CSSParserContext(document(), nullptr)); 89 StyleSheetContents::create(CSSParserContext::create(document()));
90 parsedSheet->parseString("#t1 { color: green }"); 90 parsedSheet->parseString("#t1 { color: green }");
91 styleEngine().injectAuthorSheet(parsedSheet); 91 styleEngine().injectAuthorSheet(parsedSheet);
92 document().view()->updateAllLifecyclePhases(); 92 document().view()->updateAllLifecyclePhases();
93 93
94 unsigned afterCount = styleEngine().styleForElementCount(); 94 unsigned afterCount = styleEngine().styleForElementCount();
95 EXPECT_EQ(1u, afterCount - beforeCount); 95 EXPECT_EQ(1u, afterCount - beforeCount);
96 96
97 ASSERT_TRUE(t1->computedStyle()); 97 ASSERT_TRUE(t1->computedStyle());
98 EXPECT_EQ(makeRGB(0, 128, 0), 98 EXPECT_EQ(makeRGB(0, 128, 0),
99 t1->computedStyle()->visitedDependentColor(CSSPropertyColor)); 99 t1->computedStyle()->visitedDependentColor(CSSPropertyColor));
(...skipping 267 matching lines...) Expand 10 before | Expand all | Expand 10 after
367 367
368 unsigned afterCount = styleEngine().styleForElementCount(); 368 unsigned afterCount = styleEngine().styleForElementCount();
369 EXPECT_EQ(0u, afterCount - beforeCount); 369 EXPECT_EQ(0u, afterCount - beforeCount);
370 370
371 ASSERT_TRUE(t1->computedStyle()); 371 ASSERT_TRUE(t1->computedStyle());
372 EXPECT_EQ(makeRGB(0, 128, 0), 372 EXPECT_EQ(makeRGB(0, 128, 0),
373 t1->computedStyle()->visitedDependentColor(CSSPropertyColor)); 373 t1->computedStyle()->visitedDependentColor(CSSPropertyColor));
374 } 374 }
375 375
376 } // namespace blink 376 } // namespace blink
OLDNEW
« no previous file with comments | « third_party/WebKit/Source/core/dom/StyleEngine.cpp ('k') | third_party/WebKit/Source/core/html/HTMLContentElement.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698