| OLD | NEW |
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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/RuleFeature.h" | 5 #include "core/css/RuleFeature.h" |
| 6 | 6 |
| 7 #include "core/css/CSSSelectorList.h" | 7 #include "core/css/CSSSelectorList.h" |
| 8 #include "core/css/RuleSet.h" | 8 #include "core/css/RuleSet.h" |
| 9 #include "core/css/StylePropertySet.h" | 9 #include "core/css/StylePropertySet.h" |
| 10 #include "core/css/StyleRule.h" | 10 #include "core/css/StyleRule.h" |
| (...skipping 17 matching lines...) Expand all Loading... |
| 28 void SetUp() | 28 void SetUp() |
| 29 { | 29 { |
| 30 m_document = HTMLDocument::create(); | 30 m_document = HTMLDocument::create(); |
| 31 RefPtrWillBeRawPtr<HTMLHtmlElement> html = HTMLHtmlElement::create(*m_do
cument); | 31 RefPtrWillBeRawPtr<HTMLHtmlElement> html = HTMLHtmlElement::create(*m_do
cument); |
| 32 html->appendChild(HTMLBodyElement::create(*m_document)); | 32 html->appendChild(HTMLBodyElement::create(*m_document)); |
| 33 m_document->appendChild(html.release()); | 33 m_document->appendChild(html.release()); |
| 34 | 34 |
| 35 m_document->body()->setInnerHTML("<b><i></i></b>", ASSERT_NO_EXCEPTION); | 35 m_document->body()->setInnerHTML("<b><i></i></b>", ASSERT_NO_EXCEPTION); |
| 36 } | 36 } |
| 37 | 37 |
| 38 void updateInvalidationSets(const String& selectorText) | 38 RuleFeatureSet::SelectorPreMatch collectFeatures(const String& selectorText) |
| 39 { | 39 { |
| 40 CSSSelectorList selectorList = CSSParser::parseSelector(strictCSSParserC
ontext(), nullptr, selectorText); | 40 CSSSelectorList selectorList = CSSParser::parseSelector(strictCSSParserC
ontext(), nullptr, selectorText); |
| 41 | 41 |
| 42 RefPtrWillBeRawPtr<StyleRule> styleRule = StyleRule::create(std::move(se
lectorList), MutableStylePropertySet::create(HTMLStandardMode)); | 42 RefPtrWillBeRawPtr<StyleRule> styleRule = StyleRule::create(std::move(se
lectorList), MutableStylePropertySet::create(HTMLStandardMode)); |
| 43 RuleData ruleData(styleRule.get(), 0, 0, RuleHasNoSpecialState); | 43 RuleData ruleData(styleRule.get(), 0, 0, RuleHasNoSpecialState); |
| 44 m_ruleFeatureSet.updateInvalidationSets(ruleData); | 44 return m_ruleFeatureSet.collectFeaturesFromRuleData(ruleData); |
| 45 } | |
| 46 | |
| 47 void collectFeatures(const String& selectorText) | |
| 48 { | |
| 49 CSSSelectorList selectorList = CSSParser::parseSelector(strictCSSParserC
ontext(), nullptr, selectorText); | |
| 50 | |
| 51 RefPtrWillBeRawPtr<StyleRule> styleRule = StyleRule::create(std::move(se
lectorList), MutableStylePropertySet::create(HTMLStandardMode)); | |
| 52 RuleData ruleData(styleRule.get(), 0, 0, RuleHasNoSpecialState); | |
| 53 m_ruleFeatureSet.collectFeaturesFromRuleData(ruleData); | |
| 54 } | 45 } |
| 55 | 46 |
| 56 void collectInvalidationSetsForClass(InvalidationLists& invalidationLists, c
onst AtomicString& className) const | 47 void collectInvalidationSetsForClass(InvalidationLists& invalidationLists, c
onst AtomicString& className) const |
| 57 { | 48 { |
| 58 Element* element = Traversal<HTMLElement>::firstChild(*Traversal<HTMLEle
ment>::firstChild(*m_document->body())); | 49 Element* element = Traversal<HTMLElement>::firstChild(*Traversal<HTMLEle
ment>::firstChild(*m_document->body())); |
| 59 m_ruleFeatureSet.collectInvalidationSetsForClass(invalidationLists, *ele
ment, className); | 50 m_ruleFeatureSet.collectInvalidationSetsForClass(invalidationLists, *ele
ment, className); |
| 60 } | 51 } |
| 61 | 52 |
| 62 void collectInvalidationSetsForId(InvalidationLists& invalidationLists, cons
t AtomicString& id) const | 53 void collectInvalidationSetsForId(InvalidationLists& invalidationLists, cons
t AtomicString& id) const |
| 63 { | 54 { |
| (...skipping 133 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 197 #endif | 188 #endif |
| 198 } | 189 } |
| 199 | 190 |
| 200 private: | 191 private: |
| 201 RuleFeatureSet m_ruleFeatureSet; | 192 RuleFeatureSet m_ruleFeatureSet; |
| 202 RefPtrWillBePersistent<Document> m_document; | 193 RefPtrWillBePersistent<Document> m_document; |
| 203 }; | 194 }; |
| 204 | 195 |
| 205 TEST_F(RuleFeatureSetTest, interleavedDescendantSibling1) | 196 TEST_F(RuleFeatureSetTest, interleavedDescendantSibling1) |
| 206 { | 197 { |
| 207 updateInvalidationSets(".p"); | 198 EXPECT_EQ(RuleFeatureSet::SelectorMayMatch, collectFeatures(".p")); |
| 208 | 199 |
| 209 InvalidationLists invalidationLists; | 200 InvalidationLists invalidationLists; |
| 210 collectInvalidationSetsForClass(invalidationLists, "p"); | 201 collectInvalidationSetsForClass(invalidationLists, "p"); |
| 211 expectSelfInvalidation(invalidationLists.descendants); | 202 expectSelfInvalidation(invalidationLists.descendants); |
| 212 expectNoInvalidation(invalidationLists.siblings); | 203 expectNoInvalidation(invalidationLists.siblings); |
| 213 } | 204 } |
| 214 | 205 |
| 215 TEST_F(RuleFeatureSetTest, interleavedDescendantSibling2) | 206 TEST_F(RuleFeatureSetTest, interleavedDescendantSibling2) |
| 216 { | 207 { |
| 217 updateInvalidationSets(".o + .p"); | 208 EXPECT_EQ(RuleFeatureSet::SelectorMayMatch, collectFeatures(".o + .p")); |
| 218 | 209 |
| 219 InvalidationLists invalidationLists; | 210 InvalidationLists invalidationLists; |
| 220 collectInvalidationSetsForClass(invalidationLists, "o"); | 211 collectInvalidationSetsForClass(invalidationLists, "o"); |
| 221 expectNoInvalidation(invalidationLists.descendants); | 212 expectNoInvalidation(invalidationLists.descendants); |
| 222 expectSiblingInvalidation(1, "p", invalidationLists.siblings); | 213 expectSiblingInvalidation(1, "p", invalidationLists.siblings); |
| 223 } | 214 } |
| 224 | 215 |
| 225 TEST_F(RuleFeatureSetTest, interleavedDescendantSibling3) | 216 TEST_F(RuleFeatureSetTest, interleavedDescendantSibling3) |
| 226 { | 217 { |
| 227 updateInvalidationSets(".m + .n .o + .p"); | 218 EXPECT_EQ(RuleFeatureSet::SelectorMayMatch, collectFeatures(".m + .n .o + .p
")); |
| 228 | 219 |
| 229 InvalidationLists invalidationLists; | 220 InvalidationLists invalidationLists; |
| 230 collectInvalidationSetsForClass(invalidationLists, "n"); | 221 collectInvalidationSetsForClass(invalidationLists, "n"); |
| 231 expectNoSelfInvalidation(invalidationLists.descendants); | 222 expectNoSelfInvalidation(invalidationLists.descendants); |
| 232 expectClassInvalidation("p", invalidationLists.descendants); | 223 expectClassInvalidation("p", invalidationLists.descendants); |
| 233 expectNoInvalidation(invalidationLists.siblings); | 224 expectNoInvalidation(invalidationLists.siblings); |
| 234 } | 225 } |
| 235 | 226 |
| 236 TEST_F(RuleFeatureSetTest, interleavedDescendantSibling4) | 227 TEST_F(RuleFeatureSetTest, interleavedDescendantSibling4) |
| 237 { | 228 { |
| 238 updateInvalidationSets(".m + .n .o + .p"); | 229 EXPECT_EQ(RuleFeatureSet::SelectorMayMatch, collectFeatures(".m + .n .o + .p
")); |
| 239 | 230 |
| 240 InvalidationLists invalidationLists; | 231 InvalidationLists invalidationLists; |
| 241 collectInvalidationSetsForClass(invalidationLists, "m"); | 232 collectInvalidationSetsForClass(invalidationLists, "m"); |
| 242 expectNoInvalidation(invalidationLists.descendants); | 233 expectNoInvalidation(invalidationLists.descendants); |
| 243 expectSiblingDescendantInvalidation(1, "n", "p", invalidationLists.siblings)
; | 234 expectSiblingDescendantInvalidation(1, "n", "p", invalidationLists.siblings)
; |
| 244 } | 235 } |
| 245 | 236 |
| 246 TEST_F(RuleFeatureSetTest, interleavedDescendantSibling5) | 237 TEST_F(RuleFeatureSetTest, interleavedDescendantSibling5) |
| 247 { | 238 { |
| 248 updateInvalidationSets(".l ~ .m + .n .o + .p"); | 239 EXPECT_EQ(RuleFeatureSet::SelectorMayMatch, collectFeatures(".l ~ .m + .n .o
+ .p")); |
| 249 | 240 |
| 250 InvalidationLists invalidationLists; | 241 InvalidationLists invalidationLists; |
| 251 collectInvalidationSetsForClass(invalidationLists, "l"); | 242 collectInvalidationSetsForClass(invalidationLists, "l"); |
| 252 expectNoInvalidation(invalidationLists.descendants); | 243 expectNoInvalidation(invalidationLists.descendants); |
| 253 expectSiblingDescendantInvalidation(UINT_MAX, "n", "p", invalidationLists.si
blings); | 244 expectSiblingDescendantInvalidation(UINT_MAX, "n", "p", invalidationLists.si
blings); |
| 254 } | 245 } |
| 255 | 246 |
| 256 TEST_F(RuleFeatureSetTest, interleavedDescendantSibling6) | 247 TEST_F(RuleFeatureSetTest, interleavedDescendantSibling6) |
| 257 { | 248 { |
| 258 updateInvalidationSets(".k > .l ~ .m + .n .o + .p"); | 249 EXPECT_EQ(RuleFeatureSet::SelectorMayMatch, collectFeatures(".k > .l ~ .m +
.n .o + .p")); |
| 259 | 250 |
| 260 InvalidationLists invalidationLists; | 251 InvalidationLists invalidationLists; |
| 261 collectInvalidationSetsForClass(invalidationLists, "k"); | 252 collectInvalidationSetsForClass(invalidationLists, "k"); |
| 262 expectClassInvalidation("p", invalidationLists.descendants); | 253 expectClassInvalidation("p", invalidationLists.descendants); |
| 263 expectNoInvalidation(invalidationLists.siblings); | 254 expectNoInvalidation(invalidationLists.siblings); |
| 264 } | 255 } |
| 265 | 256 |
| 266 | 257 |
| 267 TEST_F(RuleFeatureSetTest, anySibling) | 258 TEST_F(RuleFeatureSetTest, anySibling) |
| 268 { | 259 { |
| 269 updateInvalidationSets(":-webkit-any(.q, .r) ~ .s .t"); | 260 EXPECT_EQ(RuleFeatureSet::SelectorMayMatch, collectFeatures(":-webkit-any(.q
, .r) ~ .s .t")); |
| 270 | 261 |
| 271 InvalidationLists invalidationLists; | 262 InvalidationLists invalidationLists; |
| 272 collectInvalidationSetsForClass(invalidationLists, "q"); | 263 collectInvalidationSetsForClass(invalidationLists, "q"); |
| 273 expectNoInvalidation(invalidationLists.descendants); | 264 expectNoInvalidation(invalidationLists.descendants); |
| 274 expectSiblingDescendantInvalidation(UINT_MAX, "s", "t", invalidationLists.si
blings); | 265 expectSiblingDescendantInvalidation(UINT_MAX, "s", "t", invalidationLists.si
blings); |
| 275 } | 266 } |
| 276 | 267 |
| 277 TEST_F(RuleFeatureSetTest, any) | 268 TEST_F(RuleFeatureSetTest, any) |
| 278 { | 269 { |
| 279 updateInvalidationSets(":-webkit-any(.w, .x)"); | 270 EXPECT_EQ(RuleFeatureSet::SelectorMayMatch, collectFeatures(":-webkit-any(.w
, .x)")); |
| 280 | 271 |
| 281 InvalidationLists invalidationLists; | 272 InvalidationLists invalidationLists; |
| 282 collectInvalidationSetsForClass(invalidationLists, "w"); | 273 collectInvalidationSetsForClass(invalidationLists, "w"); |
| 283 expectSelfInvalidation(invalidationLists.descendants); | 274 expectSelfInvalidation(invalidationLists.descendants); |
| 284 expectNoInvalidation(invalidationLists.siblings); | 275 expectNoInvalidation(invalidationLists.siblings); |
| 285 } | 276 } |
| 286 | 277 |
| 287 TEST_F(RuleFeatureSetTest, siblingAny) | 278 TEST_F(RuleFeatureSetTest, siblingAny) |
| 288 { | 279 { |
| 289 updateInvalidationSets(".v ~ :-webkit-any(.w, .x)"); | 280 EXPECT_EQ(RuleFeatureSet::SelectorMayMatch, collectFeatures(".v ~ :-webkit-a
ny(.w, .x)")); |
| 290 | 281 |
| 291 InvalidationLists invalidationLists; | 282 InvalidationLists invalidationLists; |
| 292 collectInvalidationSetsForClass(invalidationLists, "v"); | 283 collectInvalidationSetsForClass(invalidationLists, "v"); |
| 293 expectNoInvalidation(invalidationLists.descendants); | 284 expectNoInvalidation(invalidationLists.descendants); |
| 294 expectClassesInvalidation("w", "x", invalidationLists.siblings); | 285 expectClassesInvalidation("w", "x", invalidationLists.siblings); |
| 295 } | 286 } |
| 296 | 287 |
| 297 TEST_F(RuleFeatureSetTest, descendantSiblingAny) | 288 TEST_F(RuleFeatureSetTest, descendantSiblingAny) |
| 298 { | 289 { |
| 299 updateInvalidationSets(".u .v ~ :-webkit-any(.w, .x)"); | 290 EXPECT_EQ(RuleFeatureSet::SelectorMayMatch, collectFeatures(".u .v ~ :-webki
t-any(.w, .x)")); |
| 300 | 291 |
| 301 InvalidationLists invalidationLists; | 292 InvalidationLists invalidationLists; |
| 302 collectInvalidationSetsForClass(invalidationLists, "u"); | 293 collectInvalidationSetsForClass(invalidationLists, "u"); |
| 303 expectClassesInvalidation("w", "x", invalidationLists.descendants); | 294 expectClassesInvalidation("w", "x", invalidationLists.descendants); |
| 304 expectNoInvalidation(invalidationLists.siblings); | 295 expectNoInvalidation(invalidationLists.siblings); |
| 305 } | 296 } |
| 306 | 297 |
| 307 TEST_F(RuleFeatureSetTest, id) | 298 TEST_F(RuleFeatureSetTest, id) |
| 308 { | 299 { |
| 309 updateInvalidationSets("#a #b"); | 300 EXPECT_EQ(RuleFeatureSet::SelectorMayMatch, collectFeatures("#a #b")); |
| 310 | 301 |
| 311 InvalidationLists invalidationLists; | 302 InvalidationLists invalidationLists; |
| 312 collectInvalidationSetsForId(invalidationLists, "a"); | 303 collectInvalidationSetsForId(invalidationLists, "a"); |
| 313 expectIdInvalidation("b", invalidationLists.descendants); | 304 expectIdInvalidation("b", invalidationLists.descendants); |
| 314 } | 305 } |
| 315 | 306 |
| 316 TEST_F(RuleFeatureSetTest, attribute) | 307 TEST_F(RuleFeatureSetTest, attribute) |
| 317 { | 308 { |
| 318 updateInvalidationSets("[c] [d]"); | 309 EXPECT_EQ(RuleFeatureSet::SelectorMayMatch, collectFeatures("[c] [d]")); |
| 319 | 310 |
| 320 InvalidationLists invalidationLists; | 311 InvalidationLists invalidationLists; |
| 321 collectInvalidationSetsForAttribute(invalidationLists, QualifiedName("", "c"
, "")); | 312 collectInvalidationSetsForAttribute(invalidationLists, QualifiedName("", "c"
, "")); |
| 322 expectAttributeInvalidation("d", invalidationLists.descendants); | 313 expectAttributeInvalidation("d", invalidationLists.descendants); |
| 323 } | 314 } |
| 324 | 315 |
| 325 TEST_F(RuleFeatureSetTest, pseudoClass) | 316 TEST_F(RuleFeatureSetTest, pseudoClass) |
| 326 { | 317 { |
| 327 updateInvalidationSets(":valid"); | 318 EXPECT_EQ(RuleFeatureSet::SelectorMayMatch, collectFeatures(":valid")); |
| 328 | 319 |
| 329 InvalidationLists invalidationLists; | 320 InvalidationLists invalidationLists; |
| 330 collectInvalidationSetsForPseudoClass(invalidationLists, CSSSelector::Pseudo
Valid); | 321 collectInvalidationSetsForPseudoClass(invalidationLists, CSSSelector::Pseudo
Valid); |
| 331 expectSelfInvalidation(invalidationLists.descendants); | 322 expectSelfInvalidation(invalidationLists.descendants); |
| 332 } | 323 } |
| 333 | 324 |
| 334 TEST_F(RuleFeatureSetTest, tagName) | 325 TEST_F(RuleFeatureSetTest, tagName) |
| 335 { | 326 { |
| 336 updateInvalidationSets(":valid e"); | 327 EXPECT_EQ(RuleFeatureSet::SelectorMayMatch, collectFeatures(":valid e")); |
| 337 | 328 |
| 338 InvalidationLists invalidationLists; | 329 InvalidationLists invalidationLists; |
| 339 collectInvalidationSetsForPseudoClass(invalidationLists, CSSSelector::Pseudo
Valid); | 330 collectInvalidationSetsForPseudoClass(invalidationLists, CSSSelector::Pseudo
Valid); |
| 340 expectTagNameInvalidation("e", invalidationLists.descendants); | 331 expectTagNameInvalidation("e", invalidationLists.descendants); |
| 341 } | 332 } |
| 342 | 333 |
| 343 TEST_F(RuleFeatureSetTest, contentPseudo) | 334 TEST_F(RuleFeatureSetTest, contentPseudo) |
| 344 { | 335 { |
| 345 updateInvalidationSets(".a ::content .b"); | 336 EXPECT_EQ(RuleFeatureSet::SelectorMayMatch, collectFeatures(".a ::content .b
")); |
| 346 updateInvalidationSets(".a .c"); | 337 EXPECT_EQ(RuleFeatureSet::SelectorMayMatch, collectFeatures(".a .c")); |
| 347 | 338 |
| 348 InvalidationLists invalidationLists; | 339 InvalidationLists invalidationLists; |
| 349 collectInvalidationSetsForClass(invalidationLists, "a"); | 340 collectInvalidationSetsForClass(invalidationLists, "a"); |
| 350 expectClassInvalidation("c", invalidationLists.descendants); | 341 expectClassInvalidation("c", invalidationLists.descendants); |
| 351 | 342 |
| 352 updateInvalidationSets(".a .b"); | 343 EXPECT_EQ(RuleFeatureSet::SelectorMayMatch, collectFeatures(".a .b")); |
| 353 | 344 |
| 354 invalidationLists.descendants.clear(); | 345 invalidationLists.descendants.clear(); |
| 355 collectInvalidationSetsForClass(invalidationLists, "a"); | 346 collectInvalidationSetsForClass(invalidationLists, "a"); |
| 356 expectClassesInvalidation("b", "c", invalidationLists.descendants); | 347 expectClassesInvalidation("b", "c", invalidationLists.descendants); |
| 357 } | 348 } |
| 358 | 349 |
| 350 TEST_F(RuleFeatureSetTest, nonMatchingHost) |
| 351 { |
| 352 EXPECT_EQ(RuleFeatureSet::SelectorNeverMatches, collectFeatures(".a:host")); |
| 353 EXPECT_EQ(RuleFeatureSet::SelectorNeverMatches, collectFeatures("*:host(.a)"
)); |
| 354 EXPECT_EQ(RuleFeatureSet::SelectorNeverMatches, collectFeatures("*:host .a")
); |
| 355 EXPECT_EQ(RuleFeatureSet::SelectorNeverMatches, collectFeatures("div :host .
a")); |
| 356 EXPECT_EQ(RuleFeatureSet::SelectorNeverMatches, collectFeatures(":host:hover
.a")); |
| 357 |
| 358 InvalidationLists invalidationLists; |
| 359 collectInvalidationSetsForClass(invalidationLists, "a"); |
| 360 expectNoInvalidation(invalidationLists.descendants); |
| 361 } |
| 362 |
| 363 TEST_F(RuleFeatureSetTest, nonMatchingHostContext) |
| 364 { |
| 365 EXPECT_EQ(RuleFeatureSet::SelectorNeverMatches, collectFeatures(".a:host-con
text(*)")); |
| 366 EXPECT_EQ(RuleFeatureSet::SelectorNeverMatches, collectFeatures("*:host-cont
ext(.a)")); |
| 367 EXPECT_EQ(RuleFeatureSet::SelectorNeverMatches, collectFeatures("*:host-cont
ext(*) .a")); |
| 368 EXPECT_EQ(RuleFeatureSet::SelectorNeverMatches, collectFeatures("div :host-c
ontext(div) .a")); |
| 369 EXPECT_EQ(RuleFeatureSet::SelectorNeverMatches, collectFeatures(":host-conte
xt(div):hover .a")); |
| 370 |
| 371 InvalidationLists invalidationLists; |
| 372 collectInvalidationSetsForClass(invalidationLists, "a"); |
| 373 expectNoInvalidation(invalidationLists.descendants); |
| 374 } |
| 375 |
| 359 TEST_F(RuleFeatureSetTest, siblingRulesBeforeContentPseudo) | 376 TEST_F(RuleFeatureSetTest, siblingRulesBeforeContentPseudo) |
| 360 { | 377 { |
| 361 collectFeatures("a + b ::content .c"); | 378 EXPECT_EQ(RuleFeatureSet::SelectorMayMatch, collectFeatures("a + b ::content
.c")); |
| 362 expectSiblingRuleCount(0); | 379 expectSiblingRuleCount(0); |
| 363 } | 380 } |
| 364 | 381 |
| 365 TEST_F(RuleFeatureSetTest, siblingRulesBeforeContentPseudo2) | 382 TEST_F(RuleFeatureSetTest, siblingRulesBeforeContentPseudo2) |
| 366 { | 383 { |
| 367 collectFeatures("a + ::content .b"); | 384 EXPECT_EQ(RuleFeatureSet::SelectorMayMatch, collectFeatures("a + ::content .
b")); |
| 368 expectSiblingRuleCount(0); | 385 expectSiblingRuleCount(0); |
| 369 } | 386 } |
| 370 | 387 |
| 371 TEST_F(RuleFeatureSetTest, siblingRulesAfterContentPseudo) | 388 TEST_F(RuleFeatureSetTest, siblingRulesAfterContentPseudo) |
| 372 { | 389 { |
| 373 collectFeatures(".a ::content .b + .c"); | 390 EXPECT_EQ(RuleFeatureSet::SelectorMayMatch, collectFeatures(".a ::content .b
+ .c")); |
| 374 expectSiblingRuleCount(1); | 391 expectSiblingRuleCount(1); |
| 375 } | 392 } |
| 376 | 393 |
| 377 TEST_F(RuleFeatureSetTest, siblingRulesNthBeforeContentPseudo) | 394 TEST_F(RuleFeatureSetTest, siblingRulesNthBeforeContentPseudo) |
| 378 { | 395 { |
| 379 collectFeatures(":nth-child(2) ::content .a"); | 396 EXPECT_EQ(RuleFeatureSet::SelectorMayMatch, collectFeatures(":nth-child(2) :
:content .a")); |
| 380 expectSiblingRuleCount(0); | 397 expectSiblingRuleCount(0); |
| 381 } | 398 } |
| 382 | 399 |
| 383 TEST_F(RuleFeatureSetTest, siblingRulesNthAfterContentPseudo) | 400 TEST_F(RuleFeatureSetTest, siblingRulesNthAfterContentPseudo) |
| 384 { | 401 { |
| 385 collectFeatures(".a ::content :nth-child(2)"); | 402 EXPECT_EQ(RuleFeatureSet::SelectorMayMatch, collectFeatures(".a ::content :n
th-child(2)")); |
| 386 expectSiblingRuleCount(1); | 403 expectSiblingRuleCount(1); |
| 387 } | 404 } |
| 388 | 405 |
| 389 TEST_F(RuleFeatureSetTest, siblingRulesBeforeDeep) | 406 TEST_F(RuleFeatureSetTest, siblingRulesBeforeDeep) |
| 390 { | 407 { |
| 391 collectFeatures("a + b /deep/ .c"); | 408 EXPECT_EQ(RuleFeatureSet::SelectorMayMatch, collectFeatures("a + b /deep/ .c
")); |
| 392 expectSiblingRuleCount(1); | 409 expectSiblingRuleCount(1); |
| 393 } | 410 } |
| 394 | 411 |
| 395 TEST_F(RuleFeatureSetTest, siblingRulesAfterDeep) | 412 TEST_F(RuleFeatureSetTest, siblingRulesAfterDeep) |
| 396 { | 413 { |
| 397 collectFeatures(".a /deep/ .b + .c"); | 414 EXPECT_EQ(RuleFeatureSet::SelectorMayMatch, collectFeatures(".a /deep/ .b +
.c")); |
| 398 expectSiblingRuleCount(1); | 415 expectSiblingRuleCount(1); |
| 399 } | 416 } |
| 400 | 417 |
| 401 TEST_F(RuleFeatureSetTest, siblingRulesBeforeShadow) | 418 TEST_F(RuleFeatureSetTest, siblingRulesBeforeShadow) |
| 402 { | 419 { |
| 403 collectFeatures(".a + .b::shadow .c"); | 420 EXPECT_EQ(RuleFeatureSet::SelectorMayMatch, collectFeatures(".a + .b::shadow
.c")); |
| 404 expectSiblingRuleCount(1); | 421 expectSiblingRuleCount(1); |
| 405 } | 422 } |
| 406 | 423 |
| 407 TEST_F(RuleFeatureSetTest, siblingRulesAfterShadow) | 424 TEST_F(RuleFeatureSetTest, siblingRulesAfterShadow) |
| 408 { | 425 { |
| 409 collectFeatures(".a ::shadow .b + .c"); | 426 EXPECT_EQ(RuleFeatureSet::SelectorMayMatch, collectFeatures(".a ::shadow .b
+ .c")); |
| 410 expectSiblingRuleCount(1); | 427 expectSiblingRuleCount(1); |
| 411 } | 428 } |
| 412 | 429 |
| 413 TEST_F(RuleFeatureSetTest, siblingRulesBeforeSlotted) | 430 TEST_F(RuleFeatureSetTest, siblingRulesBeforeSlotted) |
| 414 { | 431 { |
| 415 collectFeatures(".a + ::slotted(.b)"); | 432 EXPECT_EQ(RuleFeatureSet::SelectorMayMatch, collectFeatures(".a + ::slotted(
.b)")); |
| 416 expectSiblingRuleCount(0); | 433 expectSiblingRuleCount(0); |
| 417 } | 434 } |
| 418 | 435 |
| 419 TEST_F(RuleFeatureSetTest, siblingRulesBeforeHost) | 436 TEST_F(RuleFeatureSetTest, siblingRulesBeforeHost) |
| 420 { | 437 { |
| 421 collectFeatures(".a + :host(.b)"); | 438 EXPECT_EQ(RuleFeatureSet::SelectorNeverMatches, collectFeatures(".a + :host(
.b)")); |
| 422 expectSiblingRuleCount(0); | 439 expectSiblingRuleCount(0); |
| 423 } | 440 } |
| 424 | 441 |
| 425 TEST_F(RuleFeatureSetTest, siblingRulesBeforeHostContext) | 442 TEST_F(RuleFeatureSetTest, siblingRulesBeforeHostContext) |
| 426 { | 443 { |
| 427 collectFeatures(".a + :host-context(.b)"); | 444 EXPECT_EQ(RuleFeatureSet::SelectorNeverMatches, collectFeatures(".a + :host-
context(.b)")); |
| 428 expectSiblingRuleCount(0); | 445 expectSiblingRuleCount(0); |
| 429 } | 446 } |
| 430 | 447 |
| 431 TEST_F(RuleFeatureSetTest, uncommonAttributeRulesAfterContentPseudo) | 448 TEST_F(RuleFeatureSetTest, uncommonAttributeRulesAfterContentPseudo) |
| 432 { | 449 { |
| 433 collectFeatures("div ::content [attr]"); | 450 EXPECT_EQ(RuleFeatureSet::SelectorMayMatch, collectFeatures("div ::content [
attr]")); |
| 434 expectUncommonAttributeRuleCount(1); | 451 expectUncommonAttributeRuleCount(1); |
| 435 } | 452 } |
| 436 | 453 |
| 437 TEST_F(RuleFeatureSetTest, uncommonAttributeRulesBeforeContentPseudo) | 454 TEST_F(RuleFeatureSetTest, uncommonAttributeRulesBeforeContentPseudo) |
| 438 { | 455 { |
| 439 collectFeatures("[attr] ::content div"); | 456 EXPECT_EQ(RuleFeatureSet::SelectorMayMatch, collectFeatures("[attr] ::conten
t div")); |
| 440 expectUncommonAttributeRuleCount(0); | 457 expectUncommonAttributeRuleCount(0); |
| 441 } | 458 } |
| 442 | 459 |
| 443 TEST_F(RuleFeatureSetTest, uncommonAttributeRulesSlotted) | 460 TEST_F(RuleFeatureSetTest, uncommonAttributeRulesSlotted) |
| 444 { | 461 { |
| 445 collectFeatures("::slotted([attr])"); | 462 EXPECT_EQ(RuleFeatureSet::SelectorMayMatch, collectFeatures("::slotted([attr
])")); |
| 446 expectUncommonAttributeRuleCount(1); | 463 expectUncommonAttributeRuleCount(1); |
| 447 } | 464 } |
| 448 | 465 |
| 449 TEST_F(RuleFeatureSetTest, uncommonAttributeRulesBeforeSlotted) | 466 TEST_F(RuleFeatureSetTest, uncommonAttributeRulesBeforeSlotted) |
| 450 { | 467 { |
| 451 collectFeatures("[attr]::slotted(*)"); | 468 EXPECT_EQ(RuleFeatureSet::SelectorMayMatch, collectFeatures("[attr]::slotted
(*)")); |
| 452 expectUncommonAttributeRuleCount(0); | 469 expectUncommonAttributeRuleCount(0); |
| 453 } | 470 } |
| 454 | 471 |
| 455 TEST_F(RuleFeatureSetTest, uncommonAttributeRulesHost) | 472 TEST_F(RuleFeatureSetTest, uncommonAttributeRulesHost) |
| 456 { | 473 { |
| 457 collectFeatures(":host([attr])"); | 474 EXPECT_EQ(RuleFeatureSet::SelectorMayMatch, collectFeatures(":host([attr])")
); |
| 458 expectUncommonAttributeRuleCount(1); | 475 expectUncommonAttributeRuleCount(1); |
| 459 } | 476 } |
| 460 | 477 |
| 461 TEST_F(RuleFeatureSetTest, uncommonAttributeRulesBeforeHost) | 478 TEST_F(RuleFeatureSetTest, uncommonAttributeRulesBeforeHost) |
| 462 { | 479 { |
| 463 collectFeatures("[attr] :host"); | 480 EXPECT_EQ(RuleFeatureSet::SelectorNeverMatches, collectFeatures("[attr] :hos
t")); |
| 464 expectUncommonAttributeRuleCount(0); | 481 expectUncommonAttributeRuleCount(0); |
| 482 } |
| 483 |
| 484 TEST_F(RuleFeatureSetTest, uncommonAttributeRulesAfterHost) |
| 485 { |
| 486 EXPECT_EQ(RuleFeatureSet::SelectorNeverMatches, collectFeatures(":host[attr]
")); |
| 487 expectUncommonAttributeRuleCount(0); |
| 488 } |
| 489 |
| 490 TEST_F(RuleFeatureSetTest, uncommonAttributeRulesAfterHost2) |
| 491 { |
| 492 EXPECT_EQ(RuleFeatureSet::SelectorMayMatch, collectFeatures(":host [attr]"))
; |
| 493 expectUncommonAttributeRuleCount(1); |
| 494 } |
| 495 |
| 496 TEST_F(RuleFeatureSetTest, uncommonAttributeRulesHostBeforePseudo) |
| 497 { |
| 498 EXPECT_EQ(RuleFeatureSet::SelectorMayMatch, collectFeatures(":host([attr])::
before")); |
| 499 expectUncommonAttributeRuleCount(1); |
| 465 } | 500 } |
| 466 | 501 |
| 467 TEST_F(RuleFeatureSetTest, uncommonAttributeRulesHostContext) | 502 TEST_F(RuleFeatureSetTest, uncommonAttributeRulesHostContext) |
| 468 { | 503 { |
| 469 collectFeatures(":host-context([attr])"); | 504 EXPECT_EQ(RuleFeatureSet::SelectorMayMatch, collectFeatures(":host-context([
attr])")); |
| 470 expectUncommonAttributeRuleCount(1); | 505 expectUncommonAttributeRuleCount(1); |
| 471 } | 506 } |
| 472 | 507 |
| 473 TEST_F(RuleFeatureSetTest, uncommonAttributeRulesBeforeHostContext) | 508 TEST_F(RuleFeatureSetTest, uncommonAttributeRulesBeforeHostContext) |
| 474 { | 509 { |
| 475 collectFeatures("[attr] :host-context(div)"); | 510 EXPECT_EQ(RuleFeatureSet::SelectorNeverMatches, collectFeatures("[attr] :hos
t-context(div)")); |
| 476 expectUncommonAttributeRuleCount(0); | 511 expectUncommonAttributeRuleCount(0); |
| 512 } |
| 513 |
| 514 TEST_F(RuleFeatureSetTest, uncommonAttributeRulesBeforeHostContext2) |
| 515 { |
| 516 EXPECT_EQ(RuleFeatureSet::SelectorNeverMatches, collectFeatures("[attr]:host
-context(div)")); |
| 517 expectUncommonAttributeRuleCount(0); |
| 518 } |
| 519 |
| 520 TEST_F(RuleFeatureSetTest, uncommonAttributeRulesAfterHostContext) |
| 521 { |
| 522 EXPECT_EQ(RuleFeatureSet::SelectorNeverMatches, collectFeatures(":host-conte
xt(*)[attr]")); |
| 523 expectUncommonAttributeRuleCount(0); |
| 524 } |
| 525 |
| 526 TEST_F(RuleFeatureSetTest, uncommonAttributeRulesAfterHostContext2) |
| 527 { |
| 528 EXPECT_EQ(RuleFeatureSet::SelectorMayMatch, collectFeatures(":host-context(*
) [attr]")); |
| 529 expectUncommonAttributeRuleCount(1); |
| 530 } |
| 531 |
| 532 TEST_F(RuleFeatureSetTest, uncommonAttributeRulesAfterHostContextBeforePseudo) |
| 533 { |
| 534 EXPECT_EQ(RuleFeatureSet::SelectorMayMatch, collectFeatures(":host-context([
attr])::before")); |
| 535 expectUncommonAttributeRuleCount(1); |
| 477 } | 536 } |
| 478 | 537 |
| 479 } // namespace blink | 538 } // namespace blink |
| OLD | NEW |