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

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

Issue 2824853004: Scopeless matching of :host rules for style sharing. (Closed)
Patch Set: Created 3 years, 8 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
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/css/resolver/SharedStyleFinder.h" 5 #include "core/css/resolver/SharedStyleFinder.h"
6 6
7 #include <memory> 7 #include <memory>
8 #include "bindings/core/v8/V8Binding.h" 8 #include "bindings/core/v8/V8Binding.h"
9 #include "core/css/RuleFeature.h" 9 #include "core/css/RuleFeature.h"
10 #include "core/css/RuleSet.h" 10 #include "core/css/RuleSet.h"
(...skipping 216 matching lines...) Expand 10 before | Expand all | Expand 10 after
227 Element* a = GetDocument().GetElementById("a"); 227 Element* a = GetDocument().GetElementById("a");
228 Element* b = GetDocument().GetElementById("b"); 228 Element* b = GetDocument().GetElementById("b");
229 229
230 EXPECT_TRUE(a->AssignedSlot()); 230 EXPECT_TRUE(a->AssignedSlot());
231 EXPECT_TRUE(b->AssignedSlot()); 231 EXPECT_TRUE(b->AssignedSlot());
232 232
233 EXPECT_FALSE(MatchesUncommonAttributeRuleSet(*a)); 233 EXPECT_FALSE(MatchesUncommonAttributeRuleSet(*a));
234 EXPECT_TRUE(MatchesUncommonAttributeRuleSet(*b)); 234 EXPECT_TRUE(MatchesUncommonAttributeRuleSet(*b));
235 } 235 }
236 236
237 TEST_F(SharedStyleFinderTest, HostWithAttribute) {
238 SetBodyContent("<div id=host attr></div>");
239 Element* host = GetDocument().GetElementById("host");
240 ShadowRoot& root = AttachShadow(*host);
241 root.setInnerHTML("<slot></slot>");
242 GetDocument().UpdateDistribution();
243
244 AddSelector(":host([attr])");
245 FinishAddingSelectors();
246
247 EXPECT_TRUE(MatchesUncommonAttributeRuleSet(*host));
248 }
249
250 TEST_F(SharedStyleFinderTest, HostAncestorWithAttribute) {
251 SetBodyContent("<div id=host attr></div>");
252 Element* host = GetDocument().GetElementById("host");
253 ShadowRoot& root = AttachShadow(*host);
254 root.setInnerHTML("<div id=inner></div>");
255 Element* inner = root.getElementById("inner");
256 GetDocument().UpdateDistribution();
257
258 AddSelector(":host([attr]) div");
259 FinishAddingSelectors();
260
261 EXPECT_TRUE(MatchesUncommonAttributeRuleSet(*inner));
262 }
263
264 TEST_F(SharedStyleFinderTest, HostContextAncestorWithAttribute) {
265 SetBodyContent("<div id=host attr></div>");
266 Element* host = GetDocument().GetElementById("host");
267 ShadowRoot& root = AttachShadow(*host);
268 root.setInnerHTML("<div id=inner></div>");
269 Element* inner = root.getElementById("inner");
270 GetDocument().UpdateDistribution();
271
272 AddSelector(":host-context([attr]) div");
273 FinishAddingSelectors();
274
275 EXPECT_TRUE(MatchesUncommonAttributeRuleSet(*inner));
276 }
277
278 TEST_F(SharedStyleFinderTest, HostParentWithAttribute) {
279 SetBodyContent("<div id=host attr></div>");
280 Element* host = GetDocument().GetElementById("host");
281 ShadowRoot& root = AttachShadow(*host);
282 root.setInnerHTML("<div id=inner></div>");
283 Element* inner = root.getElementById("inner");
284 GetDocument().UpdateDistribution();
285
286 AddSelector(":host([attr]) > div");
287 FinishAddingSelectors();
288
289 EXPECT_TRUE(MatchesUncommonAttributeRuleSet(*inner));
290 }
291
292 TEST_F(SharedStyleFinderTest, HostContextParentWithAttribute) {
293 SetBodyContent("<div id=host attr></div>");
294 Element* host = GetDocument().GetElementById("host");
295 ShadowRoot& root = AttachShadow(*host);
296 root.setInnerHTML("<div id=inner></div>");
297 Element* inner = root.getElementById("inner");
298 GetDocument().UpdateDistribution();
299
300 AddSelector(":host-context([attr]) > div");
301 FinishAddingSelectors();
302
303 EXPECT_TRUE(MatchesUncommonAttributeRuleSet(*inner));
304 }
305
306 TEST_F(SharedStyleFinderTest, AncestorWithAttributeInParentScope) {
307 SetBodyContent("<div id=host attr></div>");
308 Element* host = GetDocument().GetElementById("host");
309 ShadowRoot& root = AttachShadow(*host);
310 root.setInnerHTML("<div id=inner></div>");
311 Element* inner = root.getElementById("inner");
312 GetDocument().UpdateDistribution();
313
314 AddSelector("div[attr] div");
315 FinishAddingSelectors();
316
317 EXPECT_FALSE(MatchesUncommonAttributeRuleSet(*inner));
318 }
319
237 } // namespace blink 320 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698