OLD | NEW |
(Empty) | |
| 1 // Copyright 2017 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #include "core/css/invalidation/StyleInvalidator.h" |
| 6 |
| 7 #include "core/dom/StyleEngine.h" |
| 8 #include "core/frame/FrameView.h" |
| 9 #include "core/html/HTMLElement.h" |
| 10 #include "core/testing/DummyPageHolder.h" |
| 11 #include "testing/gtest/include/gtest/gtest.h" |
| 12 |
| 13 namespace blink { |
| 14 |
| 15 class StyleInvalidatorTest : public ::testing::Test { |
| 16 protected: |
| 17 void SetUp() override; |
| 18 |
| 19 Document& document() { return m_dummyPageHolder->document(); } |
| 20 StyleEngine& styleEngine() { return document().styleEngine(); } |
| 21 StyleInvalidator& styleInvalidator() { |
| 22 return document().styleEngine().styleInvalidator(); |
| 23 } |
| 24 |
| 25 private: |
| 26 std::unique_ptr<DummyPageHolder> m_dummyPageHolder; |
| 27 }; |
| 28 |
| 29 void StyleInvalidatorTest::SetUp() { |
| 30 m_dummyPageHolder = DummyPageHolder::create(IntSize(800, 600)); |
| 31 } |
| 32 |
| 33 TEST_F(StyleInvalidatorTest, ScheduleOnDocumentNode) { |
| 34 document().body()->setInnerHTML( |
| 35 "<div id='d'></div><i id='i'></i><span></span>"); |
| 36 document().view()->updateAllLifecyclePhases(); |
| 37 |
| 38 unsigned beforeCount = styleEngine().styleForElementCount(); |
| 39 |
| 40 RefPtr<DescendantInvalidationSet> set = DescendantInvalidationSet::create(); |
| 41 set->addTagName("div"); |
| 42 set->addTagName("span"); |
| 43 |
| 44 InvalidationLists lists; |
| 45 lists.descendants.push_back(set); |
| 46 styleInvalidator().scheduleInvalidationSetsForNode(lists, document()); |
| 47 |
| 48 EXPECT_TRUE(document().needsStyleInvalidation()); |
| 49 EXPECT_FALSE(document().childNeedsStyleInvalidation()); |
| 50 |
| 51 styleInvalidator().invalidate(document()); |
| 52 |
| 53 EXPECT_FALSE(document().needsStyleInvalidation()); |
| 54 EXPECT_FALSE(document().childNeedsStyleInvalidation()); |
| 55 EXPECT_FALSE(document().needsStyleRecalc()); |
| 56 EXPECT_TRUE(document().childNeedsStyleRecalc()); |
| 57 |
| 58 document().view()->updateAllLifecyclePhases(); |
| 59 unsigned afterCount = styleEngine().styleForElementCount(); |
| 60 EXPECT_EQ(2u, afterCount - beforeCount); |
| 61 } |
| 62 |
| 63 } // namespace blink |
OLD | NEW |