| 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 "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/dom/shadow/ShadowRootInit.h" | 10 #include "core/dom/shadow/ShadowRootInit.h" |
| (...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 109 | 109 |
| 110 CSSStyleSheet* sheet1 = | 110 CSSStyleSheet* sheet1 = |
| 111 styleEngine().createSheet(*element, sheetText, minPos, context); | 111 styleEngine().createSheet(*element, sheetText, minPos, context); |
| 112 | 112 |
| 113 // Check that the first sheet is not using a cached StyleSheetContents. | 113 // Check that the first sheet is not using a cached StyleSheetContents. |
| 114 EXPECT_FALSE(sheet1->contents()->isUsedFromTextCache()); | 114 EXPECT_FALSE(sheet1->contents()->isUsedFromTextCache()); |
| 115 | 115 |
| 116 CSSStyleSheet* sheet2 = | 116 CSSStyleSheet* sheet2 = |
| 117 styleEngine().createSheet(*element, sheetText, minPos, context); | 117 styleEngine().createSheet(*element, sheetText, minPos, context); |
| 118 | 118 |
| 119 // Check that the second sheet uses the cached StyleSheetContents for the firs
t. | 119 // Check that the second sheet uses the cached StyleSheetContents for the |
| 120 // first. |
| 120 EXPECT_EQ(sheet1->contents(), sheet2->contents()); | 121 EXPECT_EQ(sheet1->contents(), sheet2->contents()); |
| 121 EXPECT_TRUE(sheet2->contents()->isUsedFromTextCache()); | 122 EXPECT_TRUE(sheet2->contents()->isUsedFromTextCache()); |
| 122 | 123 |
| 123 sheet1 = nullptr; | 124 sheet1 = nullptr; |
| 124 sheet2 = nullptr; | 125 sheet2 = nullptr; |
| 125 element = nullptr; | 126 element = nullptr; |
| 126 | 127 |
| 127 // Garbage collection should clear the weak reference in the StyleSheetContent
s cache. | 128 // Garbage collection should clear the weak reference in the |
| 129 // StyleSheetContents cache. |
| 128 ThreadState::current()->collectAllGarbage(); | 130 ThreadState::current()->collectAllGarbage(); |
| 129 | 131 |
| 130 element = HTMLStyleElement::create(document(), false); | 132 element = HTMLStyleElement::create(document(), false); |
| 131 sheet1 = styleEngine().createSheet(*element, sheetText, minPos, context); | 133 sheet1 = styleEngine().createSheet(*element, sheetText, minPos, context); |
| 132 | 134 |
| 133 // Check that we did not use a cached StyleSheetContents after the garbage col
lection. | 135 // Check that we did not use a cached StyleSheetContents after the garbage |
| 136 // collection. |
| 134 EXPECT_FALSE(sheet1->contents()->isUsedFromTextCache()); | 137 EXPECT_FALSE(sheet1->contents()->isUsedFromTextCache()); |
| 135 } | 138 } |
| 136 | 139 |
| 137 TEST_F(StyleEngineTest, RuleSetInvalidationTypeSelectors) { | 140 TEST_F(StyleEngineTest, RuleSetInvalidationTypeSelectors) { |
| 138 document().body()->setInnerHTML( | 141 document().body()->setInnerHTML( |
| 139 "<div>" | 142 "<div>" |
| 140 " <span></span>" | 143 " <span></span>" |
| 141 " <div></div>" | 144 " <div></div>" |
| 142 "</div>", | 145 "</div>", |
| 143 ASSERT_NO_EXCEPTION); | 146 ASSERT_NO_EXCEPTION); |
| (...skipping 152 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 296 RuleSetInvalidationFullRecalc); | 299 RuleSetInvalidationFullRecalc); |
| 297 EXPECT_EQ(scheduleInvalidationsForRules( | 300 EXPECT_EQ(scheduleInvalidationsForRules( |
| 298 *shadowRoot, ".a /deep/ span { background: green}"), | 301 *shadowRoot, ".a /deep/ span { background: green}"), |
| 299 RuleSetInvalidationFullRecalc); | 302 RuleSetInvalidationFullRecalc); |
| 300 EXPECT_EQ(scheduleInvalidationsForRules( | 303 EXPECT_EQ(scheduleInvalidationsForRules( |
| 301 *shadowRoot, ".a::shadow span { background: green}"), | 304 *shadowRoot, ".a::shadow span { background: green}"), |
| 302 RuleSetInvalidationFullRecalc); | 305 RuleSetInvalidationFullRecalc); |
| 303 } | 306 } |
| 304 | 307 |
| 305 } // namespace blink | 308 } // namespace blink |
| OLD | NEW |