| 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/frame/FrameView.h" | 10 #include "core/frame/FrameView.h" |
| (...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 70 } | 70 } |
| 71 | 71 |
| 72 TEST_F(StyleEngineTest, TextToSheetCache) | 72 TEST_F(StyleEngineTest, TextToSheetCache) |
| 73 { | 73 { |
| 74 HTMLStyleElement* element = HTMLStyleElement::create(document(), false); | 74 HTMLStyleElement* element = HTMLStyleElement::create(document(), false); |
| 75 | 75 |
| 76 String sheetText("div {}"); | 76 String sheetText("div {}"); |
| 77 TextPosition minPos = TextPosition::minimumPosition(); | 77 TextPosition minPos = TextPosition::minimumPosition(); |
| 78 StyleEngineContext context; | 78 StyleEngineContext context; |
| 79 | 79 |
| 80 CSSStyleSheet* sheet1 = styleEngine().createSheet(element, sheetText, minPos
, context); | 80 CSSStyleSheet* sheet1 = styleEngine().createSheet(*element, sheetText, minPo
s, context); |
| 81 | 81 |
| 82 // Check that the first sheet is not using a cached StyleSheetContents. | 82 // Check that the first sheet is not using a cached StyleSheetContents. |
| 83 EXPECT_FALSE(sheet1->contents()->isUsedFromTextCache()); | 83 EXPECT_FALSE(sheet1->contents()->isUsedFromTextCache()); |
| 84 | 84 |
| 85 CSSStyleSheet* sheet2 = styleEngine().createSheet(element, sheetText, minPos
, context); | 85 CSSStyleSheet* sheet2 = styleEngine().createSheet(*element, sheetText, minPo
s, context); |
| 86 | 86 |
| 87 // Check that the second sheet uses the cached StyleSheetContents for the fi
rst. | 87 // Check that the second sheet uses the cached StyleSheetContents for the fi
rst. |
| 88 EXPECT_EQ(sheet1->contents(), sheet2->contents()); | 88 EXPECT_EQ(sheet1->contents(), sheet2->contents()); |
| 89 EXPECT_TRUE(sheet2->contents()->isUsedFromTextCache()); | 89 EXPECT_TRUE(sheet2->contents()->isUsedFromTextCache()); |
| 90 | 90 |
| 91 sheet1 = nullptr; | 91 sheet1 = nullptr; |
| 92 sheet2 = nullptr; | 92 sheet2 = nullptr; |
| 93 element = nullptr; | 93 element = nullptr; |
| 94 | 94 |
| 95 // Garbage collection should clear the weak reference in the StyleSheetConte
nts cache. | 95 // Garbage collection should clear the weak reference in the StyleSheetConte
nts cache. |
| 96 ThreadState::current()-> collectAllGarbage(); | 96 ThreadState::current()-> collectAllGarbage(); |
| 97 | 97 |
| 98 element = HTMLStyleElement::create(document(), false); | 98 element = HTMLStyleElement::create(document(), false); |
| 99 sheet1 = styleEngine().createSheet(element, sheetText, minPos, context); | 99 sheet1 = styleEngine().createSheet(*element, sheetText, minPos, context); |
| 100 | 100 |
| 101 // Check that we did not use a cached StyleSheetContents after the garbage c
ollection. | 101 // Check that we did not use a cached StyleSheetContents after the garbage c
ollection. |
| 102 EXPECT_FALSE(sheet1->contents()->isUsedFromTextCache()); | 102 EXPECT_FALSE(sheet1->contents()->isUsedFromTextCache()); |
| 103 } | 103 } |
| 104 | 104 |
| 105 } // namespace blink | 105 } // namespace blink |
| OLD | NEW |