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

Side by Side Diff: third_party/WebKit/Source/web/tests/ShadowDOMV0Test.cpp

Issue 2647843002: Switch Shadow DOM V0 <content> FeatureSet tests to SimTest. (Closed)
Patch Set: 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
« no previous file with comments | « third_party/WebKit/Source/web/BUILD.gn ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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/dom/shadow/ElementShadow.h"
6 #include "core/dom/shadow/ElementShadowV0.h"
7 #include "core/html/HTMLBodyElement.h"
8 #include "web/tests/sim/SimDisplayItemList.h"
9 #include "web/tests/sim/SimRequest.h"
rune 2017/01/20 11:41:16 Are all of these includes needed? SimDisplayItemLi
esprehn 2017/02/03 22:31:10 BeginFrame() returns an instance of it and it's fo
10 #include "web/tests/sim/SimTest.h"
11
12 namespace blink {
13
14 namespace {
15
16 bool hasSelectorForIdInShadow(Element* host, const AtomicString& id) {
17 DCHECK(host);
rune 2017/01/20 11:41:16 Don't we typically use ASSERT_TRUE instead of DCHE
esprehn 2017/02/03 22:31:10 This was a support method so an assert looked funn
rune 2017/02/06 11:53:45 Acknowledged.
18 return host->shadow()->v0().ensureSelectFeatureSet().hasSelectorForId(id);
19 }
20
21 bool hasSelectorForClassInShadow(Element* host, const AtomicString& className) {
22 DCHECK(host);
23 return host->shadow()->v0().ensureSelectFeatureSet().hasSelectorForClass(
24 className);
25 }
26
27 bool hasSelectorForAttributeInShadow(Element* host,
28 const AtomicString& attributeName) {
29 DCHECK(host);
30 return host->shadow()->v0().ensureSelectFeatureSet().hasSelectorForAttribute(
31 attributeName);
32 }
33
34 class ShadowDOMVTest : public SimTest {};
rune 2017/01/20 11:41:16 ShadowDOMVTest -> ShadowDOMV0Test ?
esprehn 2017/02/03 22:31:10 Woops yeah
35
36 TEST_F(ShadowDOMVTest, FeatureSetId) {
37 loadURL("about:blank");
38 auto* host = document().createElement("div");
39 auto* content = document().createElement("content");
40 content->setAttribute("select", "#foo");
41 host->createShadowRoot()->appendChild(content);
42 EXPECT_TRUE(hasSelectorForIdInShadow(host, "foo"));
43 EXPECT_FALSE(hasSelectorForIdInShadow(host, "bar"));
44 EXPECT_FALSE(hasSelectorForIdInShadow(host, "host"));
45 content->setAttribute("select", "#bar");
46 EXPECT_TRUE(hasSelectorForIdInShadow(host, "bar"));
47 EXPECT_FALSE(hasSelectorForIdInShadow(host, "foo"));
48 content->setAttribute("select", "");
49 EXPECT_FALSE(hasSelectorForIdInShadow(host, "bar"));
50 EXPECT_FALSE(hasSelectorForIdInShadow(host, "foo"));
51 }
52
53 TEST_F(ShadowDOMVTest, FeatureSetClassName) {
54 loadURL("about:blank");
55 auto* host = document().createElement("div");
56 auto* content = document().createElement("content");
57 content->setAttribute("select", ".foo");
58 host->createShadowRoot()->appendChild(content);
59 EXPECT_TRUE(hasSelectorForClassInShadow(host, "foo"));
60 EXPECT_FALSE(hasSelectorForClassInShadow(host, "bar"));
61 EXPECT_FALSE(hasSelectorForClassInShadow(host, "host"));
62 content->setAttribute("select", ".bar");
63 EXPECT_TRUE(hasSelectorForClassInShadow(host, "bar"));
64 EXPECT_FALSE(hasSelectorForClassInShadow(host, "foo"));
65 content->setAttribute("select", "");
66 EXPECT_FALSE(hasSelectorForClassInShadow(host, "bar"));
67 EXPECT_FALSE(hasSelectorForClassInShadow(host, "foo"));
68 }
69
70 TEST_F(ShadowDOMVTest, FeatureSetAttributeName) {
71 loadURL("about:blank");
72 auto* host = document().createElement("div");
73 auto* content = document().createElement("content");
74 content->setAttribute("select", "div[foo]");
75 host->createShadowRoot()->appendChild(content);
76 EXPECT_TRUE(hasSelectorForAttributeInShadow(host, "foo"));
77 EXPECT_FALSE(hasSelectorForAttributeInShadow(host, "bar"));
78 EXPECT_FALSE(hasSelectorForAttributeInShadow(host, "host"));
79 content->setAttribute("select", "div[bar]");
80 EXPECT_TRUE(hasSelectorForAttributeInShadow(host, "bar"));
81 EXPECT_FALSE(hasSelectorForAttributeInShadow(host, "foo"));
82 content->setAttribute("select", "");
83 EXPECT_FALSE(hasSelectorForAttributeInShadow(host, "bar"));
84 EXPECT_FALSE(hasSelectorForAttributeInShadow(host, "foo"));
85 }
86
87 TEST_F(ShadowDOMVTest, FeatureSetMultipleSelectors) {
88 loadURL("about:blank");
89 auto* host = document().createElement("div");
90 auto* content = document().createElement("content");
91 content->setAttribute("select", "#foo,.bar,div[baz]");
92 host->createShadowRoot()->appendChild(content);
93 EXPECT_TRUE(hasSelectorForIdInShadow(host, "foo"));
94 EXPECT_FALSE(hasSelectorForIdInShadow(host, "bar"));
95 EXPECT_FALSE(hasSelectorForIdInShadow(host, "baz"));
96 EXPECT_FALSE(hasSelectorForClassInShadow(host, "foo"));
97 EXPECT_TRUE(hasSelectorForClassInShadow(host, "bar"));
98 EXPECT_FALSE(hasSelectorForClassInShadow(host, "baz"));
99 EXPECT_FALSE(hasSelectorForAttributeInShadow(host, "foo"));
100 EXPECT_FALSE(hasSelectorForAttributeInShadow(host, "bar"));
101 EXPECT_TRUE(hasSelectorForAttributeInShadow(host, "baz"));
102 }
103
104 TEST_F(ShadowDOMVTest, FeatureSetSubtree) {
105 loadURL("about:blank");
106 auto* host = document().createElement("div");
107 host->createShadowRoot()->setInnerHTML(
108 "<div>"
109 " <div></div>"
110 " <content select='*'></content>"
111 " <div>"
112 " <content select='div[foo=piyo]'></content>"
113 " </div>"
114 "</div>");
115 EXPECT_FALSE(hasSelectorForIdInShadow(host, "foo"));
116 EXPECT_FALSE(hasSelectorForClassInShadow(host, "foo"));
117 EXPECT_TRUE(hasSelectorForAttributeInShadow(host, "foo"));
118 EXPECT_FALSE(hasSelectorForAttributeInShadow(host, "piyo"));
119 }
120
121 TEST_F(ShadowDOMVTest, FeatureSetMultipleShadowRoots) {
122 loadURL("about:blank");
123 auto* host = document().createElement("div");
124 auto* hostShadow = host->createShadowRoot();
125 hostShadow->setInnerHTML("<content select='#foo'></content>");
126 auto* child = document().createElement("div");
127 auto* childRoot = child->createShadowRoot();
128 auto* childContent = document().createElement("content");
129 childContent->setAttribute("select", "#bar");
130 childRoot->appendChild(childContent);
131 hostShadow->appendChild(child);
132 EXPECT_TRUE(hasSelectorForIdInShadow(host, "foo"));
133 EXPECT_TRUE(hasSelectorForIdInShadow(host, "bar"));
134 EXPECT_FALSE(hasSelectorForIdInShadow(host, "baz"));
135 childContent->setAttribute("select", "#baz");
136 EXPECT_TRUE(hasSelectorForIdInShadow(host, "foo"));
137 EXPECT_FALSE(hasSelectorForIdInShadow(host, "bar"));
138 EXPECT_TRUE(hasSelectorForIdInShadow(host, "baz"));
139 }
140
141 } // namespace
142
143 } // namespace blink
OLDNEW
« no previous file with comments | « third_party/WebKit/Source/web/BUILD.gn ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698