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

Side by Side Diff: third_party/WebKit/Source/core/css/resolver/ScopedStyleResolverTest.cpp

Issue 2610513003: Avoid unnecessary updateActiveStyle comparing shadow styles. (Closed)
Patch Set: Added documentation. 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
(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/resolver/ScopedStyleResolver.h"
6
7 #include "core/dom/shadow/ShadowRoot.h"
8 #include "core/dom/shadow/ShadowRootInit.h"
9 #include "core/frame/FrameView.h"
10 #include "core/html/HTMLElement.h"
11 #include "core/testing/DummyPageHolder.h"
12 #include "testing/gtest/include/gtest/gtest.h"
13
14 namespace blink {
15
16 class ScopedStyleResolverTest : public ::testing::Test {
17 protected:
18 void SetUp() override {
19 m_dummyPageHolder = DummyPageHolder::create(IntSize(800, 600));
20 }
21
22 Document& document() { return m_dummyPageHolder->document(); }
23 StyleEngine& styleEngine() { return document().styleEngine(); }
24 ShadowRoot& attachShadow(Element& host);
25
26 private:
27 std::unique_ptr<DummyPageHolder> m_dummyPageHolder;
28 };
29
30 ShadowRoot& ScopedStyleResolverTest::attachShadow(Element& host) {
31 ShadowRootInit init;
32 init.setMode("open");
33 ShadowRoot* shadowRoot = host.attachShadow(
34 ScriptState::forMainWorld(document().frame()), init, ASSERT_NO_EXCEPTION);
35 EXPECT_TRUE(shadowRoot);
36 return *shadowRoot;
37 }
38
39 TEST_F(ScopedStyleResolverTest, HasSameStylesNullNull) {
40 EXPECT_TRUE(ScopedStyleResolver::haveSameStyles(nullptr, nullptr));
41 }
42
43 TEST_F(ScopedStyleResolverTest, HasSameStylesNullEmpty) {
44 ScopedStyleResolver& resolver = document().ensureScopedStyleResolver();
45 EXPECT_TRUE(ScopedStyleResolver::haveSameStyles(nullptr, &resolver));
46 EXPECT_TRUE(ScopedStyleResolver::haveSameStyles(&resolver, nullptr));
47 }
48
49 TEST_F(ScopedStyleResolverTest, HasSameStylesEmptyEmpty) {
50 ScopedStyleResolver& resolver = document().ensureScopedStyleResolver();
51 EXPECT_TRUE(ScopedStyleResolver::haveSameStyles(&resolver, &resolver));
52 }
53
54 TEST_F(ScopedStyleResolverTest, HasSameStylesNonEmpty) {
55 document().body()->setInnerHTML("<div id=host1></div><div id=host2></div>");
56 Element* host1 = document().getElementById("host1");
57 Element* host2 = document().getElementById("host2");
58 ASSERT_TRUE(host1);
59 ASSERT_TRUE(host2);
60 ShadowRoot& root1 = attachShadow(*host1);
61 ShadowRoot& root2 = attachShadow(*host2);
62 root1.setInnerHTML("<style>::slotted(#dummy){color:pink}</style>");
63 root2.setInnerHTML("<style>::slotted(#dummy){color:pink}</style>");
64 document().view()->updateAllLifecyclePhases();
65 EXPECT_TRUE(ScopedStyleResolver::haveSameStyles(
66 &root1.ensureScopedStyleResolver(), &root2.ensureScopedStyleResolver()));
67 }
68
69 TEST_F(ScopedStyleResolverTest, HasSameStylesDifferentSheetCount) {
70 document().body()->setInnerHTML("<div id=host1></div><div id=host2></div>");
71 Element* host1 = document().getElementById("host1");
72 Element* host2 = document().getElementById("host2");
73 ASSERT_TRUE(host1);
74 ASSERT_TRUE(host2);
75 ShadowRoot& root1 = attachShadow(*host1);
76 ShadowRoot& root2 = attachShadow(*host2);
77 root1.setInnerHTML(
78 "<style>::slotted(#dummy){color:pink}</style><style>div{}</style>");
79 root2.setInnerHTML("<style>::slotted(#dummy){color:pink}</style>");
80 document().view()->updateAllLifecyclePhases();
81 EXPECT_FALSE(ScopedStyleResolver::haveSameStyles(
82 &root1.ensureScopedStyleResolver(), &root2.ensureScopedStyleResolver()));
83 }
84
85 TEST_F(ScopedStyleResolverTest, HasSameStylesCacheMiss) {
86 document().body()->setInnerHTML("<div id=host1></div><div id=host2></div>");
87 Element* host1 = document().getElementById("host1");
88 Element* host2 = document().getElementById("host2");
89 ASSERT_TRUE(host1);
90 ASSERT_TRUE(host2);
91 ShadowRoot& root1 = attachShadow(*host1);
92 ShadowRoot& root2 = attachShadow(*host2);
93 // Style equality is detected when StyleSheetContents is shared. That is only
94 // the case when the source text is the same. The comparison will fail when
95 // adding an extra space to one of the sheets.
96 root1.setInnerHTML("<style>::slotted(#dummy){color:pink}</style>");
97 root2.setInnerHTML("<style>::slotted(#dummy){ color:pink}</style>");
98 document().view()->updateAllLifecyclePhases();
99 EXPECT_FALSE(ScopedStyleResolver::haveSameStyles(
100 &root1.ensureScopedStyleResolver(), &root2.ensureScopedStyleResolver()));
101 }
102
103 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698