Add the baseline implementation of :not(selectorList)
https://bugs.webkit.org/show_bug.cgi?id=137548
Reviewed by Andreas Kling.
Source/WebCore:
This patch extend the pseudo class :not() to support the new definition
in CSS Selectors level 4.
Instead of supporting a single simple selector, :not() now support
an arbitrary selector list, excepted pseudo elements.
One side effect of this change is :visited and :link are no longer supported
inside :not(). The reason has to do with complexity and performance.
Since :not() and :matches() can have arbitrary selector list, keeping track of
:visited and :link can have many combination superposing, some valid, some invalid.
Supporting :visited and :link should be possible by chaning the way we handle
them for style resolution, but given the limited use cases for such features
I'll wait to see if there is any interest before changing everything.
This patch only covers SelectorChecker to keep things simple. The CSS JIT
will come later.
Tests: fast/css/not-basics.html
fast/css/parsing-css-not-1.html
fast/css/parsing-css-not-2.html
fast/css/parsing-css-not-3.html
fast/css/parsing-css-not-4.html
fast/css/parsing-css-not-5.html
fast/css/parsing-css-not-6.html
fast/css/parsing-css-not-7.html
fast/css/parsing-css-not-8.html
fast/css/parsing-css-not-9.html
fast/css/parsing-css-nth-child-of-4.html
fast/selectors/not-basics.html
fast/selectors/not-nested.html
fast/selectors/not-selector-list.html
* css/CSSGrammar.y.in:
Rename selectorListDoesNotMatchAnyPseudoElement() to selectorListDoesNotMatchAnyPseudoElement()
since both :not() and :nth-child(An+B of selectorList) have the same requirements at the moment.
* css/CSSParserValues.cpp:
(WebCore::selectorListMatchesPseudoElement):
The patch adding :matches() introduced the possibility of putting pseudo element
arbitrary deep in a sequence of nested :matches(). Since this case is forbidded
by :not() and :nth-child(An+B of selectorList), selectorListMatchesPseudoElement()
now becomes recursive to find those pseudo elements.
* css/CSSSelector.cpp:
(WebCore::CSSSelector::selectorText):
CSSOM for the extended :not().
* css/SelectorChecker.cpp:
(WebCore::SelectorChecker::checkOne):
(WebCore::SelectorChecker::determineLinkMatchType):
* cssjit/SelectorCompiler.cpp:
(WebCore::SelectorCompiler::addPseudoClassType):
Disable the new capabilities from the JIT for now.
LayoutTests:
There are 3 big kind of changes to the tests:
1) The new implementation intentionally breaks :not() of :visited and :link.
Some test for the basic :not(:link) and :not(:visited) are consequently failing.
2) Some tests were ensuring that :not() only support simple selectors, those are
becoming irrelevant.
3) New test for the feature.
* TestExpectations:
This patch intentionally breaks :not(:link). The test fast/history/link-inside-not.html
time out since it is waiting for the link to match.
* fast/css/invalid-not-with-simple-selector-sequence-expected.txt: Removed.
* fast/css/invalid-not-with-simple-selector-sequence.html: Removed.
This test originally came from IEtestcenter. None of it is useful, all the "invalid"
cases are now fully functional selectors.
* fast/css/css-selector-text-expected.txt:
* fast/css/css-selector-text.html:
* fast/css/css-set-selector-text-expected.txt:
* fast/css/css-set-selector-text.html:
Parsing and CSS OM tests for the new :not().
* fast/css/parsing-css-matches-5-expected.txt:
* fast/css/parsing-css-matches-5.html:
* fast/css/parsing-css-matches-6-expected.txt:
* fast/css/parsing-css-matches-6.html:
* fast/css/parsing-css-matches-7-expected.txt:
* fast/css/parsing-css-matches-7.html:
* fast/css/parsing-css-matches-8-expected.txt:
* fast/css/parsing-css-matches-8.html:
Update the tests of :matches() to account for the extended :not().
* fast/dom/SelectorAPI/resig-SelectorsAPI-test-expected.txt:
Some cases covered by this test are now valid. The test is kept as is for
its historical value, but all the FAIL cover valid use cases in Level 4.
* platform/mac/css3/selectors3/html/css3-modsel-61-expected.txt:
* platform/mac/css3/selectors3/html/css3-modsel-83-expected.txt:
* platform/mac/css3/selectors3/xhtml/css3-modsel-61-expected.txt:
* platform/mac/css3/selectors3/xhtml/css3-modsel-83-expected.txt:
* platform/mac/css3/selectors3/xml/css3-modsel-61-expected.txt:
* platform/mac/css3/selectors3/xml/css3-modsel-83-expected.txt:
* platform/mac/fast/selectors/061-expected.txt:
* platform/mac/fast/selectors/083-expected.txt:
Those tests are changing because of the breakage of :link and :visited.
* fast/css/not-basics-expected.html: Added.
* fast/css/not-basics.html: Added.
Basic use cases of the extended :not() that should always style correctly.
* fast/css/parsing-css-not-1-expected.txt: Added.
* fast/css/parsing-css-not-1.html: Added.
* fast/css/parsing-css-not-2-expected.txt: Added.
* fast/css/parsing-css-not-2.html: Added.
* fast/css/parsing-css-not-3-expected.txt: Added.
* fast/css/parsing-css-not-3.html: Added.
* fast/css/parsing-css-not-4-expected.txt: Added.
* fast/css/parsing-css-not-4.html: Added.
* fast/css/parsing-css-not-5-expected.txt: Added.
* fast/css/parsing-css-not-5.html: Copied from LayoutTests/fast/css/parsing-css-matches-5.html.
* fast/css/parsing-css-not-6-expected.txt: Added.
* fast/css/parsing-css-not-6.html: Copied from LayoutTests/fast/css/parsing-css-matches-6.html.
* fast/css/parsing-css-not-7-expected.txt: Copied from LayoutTests/fast/css/parsing-css-matches-7-expected.txt.
* fast/css/parsing-css-not-7.html: Copied from LayoutTests/fast/css/parsing-css-matches-7.html.
* fast/css/parsing-css-not-8-expected.txt: Copied from LayoutTests/fast/css/parsing-css-matches-8-expected.txt.
* fast/css/parsing-css-not-8.html: Copied from LayoutTests/fast/css/parsing-css-matches-8.html.
* fast/css/parsing-css-not-9-expected.txt: Added.
* fast/css/parsing-css-not-9.html: Copied from LayoutTests/fast/css/parsing-css-matches-8.html.
Parsing of :not(). A lot of them were inspired by Yusuke Suzuki's test suite
for :matches(). A lot of test case apply to :not(), the main difference is that
pseudo elements must fail inside :not().
* fast/css/parsing-css-nth-child-of-4-expected.txt: Added.
* fast/css/parsing-css-nth-child-of-4.html: Added.
With the introduction of :matches(), it is possible to have arbitrarily deep pseudo elements.
The tests for :not() cover the case fixed with this patch, this addition covers :nth-child(of).
* fast/selectors/not-basics-expected.txt: Added.
* fast/selectors/not-basics.html: Added.
* fast/selectors/not-nested-expected.txt: Added.
* fast/selectors/not-nested.html: Added.
* fast/selectors/not-selector-list-expected.txt: Added.
* fast/selectors/not-selector-list.html: Added.
Test coverage for the new features.
Canonical link: https://commits.webkit.org/155417@main
git-svn-id: https://svn.webkit.org/repository/webkit/trunk@174535 268f45cc-cd09-0410-ab3c-d52691b4dbfc
2014-10-09 22:14:29 +00:00
|
|
|
<!doctype html>
|
|
|
|
<html>
|
|
|
|
<head>
|
|
|
|
<script src="../../resources/js-test-pre.js"></script>
|
|
|
|
<style id="style-container">
|
|
|
|
</style>
|
|
|
|
</head>
|
|
|
|
<body>
|
|
|
|
</body>
|
|
|
|
<script>
|
|
|
|
description('Test the parsing of :not(selectorList) for querySelector and style.');
|
|
|
|
|
|
|
|
function testValidSelector(selectorString, expectedSerializedSelector) {
|
Enhance shouldNotThrow()/shouldThrow() to accept functions and a descriptive message
<https://webkit.org/b/159232>
Reviewed by Brent Fulgham.
Based on a Blink change (patch by <hongchan@chromium.org>):
<https://src.chromium.org/viewvc/blink?view=revision&revision=192204>
Currently, shouldNotThrow() and shouldThrow() take the following
arguments:
shouldNotThrow(evalString)
shouldThrow(evalString, expectedExceptionString)
The challenges with this design are:
1) The 'evalString' must capture every variable that it
needs, which means the code can be long, and concatenated
into a single line. It would be really nice to be able
to use an (anonymous) function to capture variables
instead.
2) The 'evalString' is literally printed out in the test
results, which isn't always the most descriptive. A
descriptive message would make it clearer what failed.
3) When changing a shouldThrow() into a shouldNotThrow()
or copying/pasting code, it's possible to forget to
remove 'expectedExceptionString' from the function call.
This patch changes the methods to take the following arguments:
shouldNotThrow(evalString|function [, message])
shouldThrow(evalString|function, expectedExceptionString [, message])
If 'function' is passed in, then it is invoked instead of
evaluated, and 'message' replaces the literal code in the
pass/fail output.
This patch also adds the global 'didFailSomeTests' variable to
js-test.js, which already exists in js-test-pre.js. This was
added to js-test-pre.js in r153203 by Oliver Hunt to
LayoutTests/fast/js/resources/js-test-pre.js.
* fast/canvas/webgl/canvas-supports-context-expected.txt:
* fast/canvas/webgl/gl-bind-attrib-location-before-compile-test-expected.txt:
* fast/css-grid-layout/grid-element-auto-repeat-get-set-expected.txt:
* fast/dom/getElementsByClassName/ASCII-case-insensitive-expected.txt:
* storage/indexeddb/cursor-basics-expected.txt:
* storage/indexeddb/cursor-basics-private-expected.txt:
- Update expected results to include "Some tests fail." since
some subtests actually do fail during these tests.
* fast/css/parsing-css-lang.html:
* fast/css/parsing-css-matches-1.html:
* fast/css/parsing-css-matches-2.html:
* fast/css/parsing-css-matches-3.html:
* fast/css/parsing-css-matches-4.html:
* fast/css/parsing-css-not-1.html:
* fast/css/parsing-css-not-2.html:
* fast/css/parsing-css-not-3.html:
* fast/css/parsing-css-not-4.html:
* fast/css/parsing-css-nth-child-of-1.html:
* fast/css/parsing-css-nth-child-of-2.html:
* fast/css/parsing-css-nth-last-child-of-1.html:
* fast/css/parsing-css-nth-last-child-of-2.html:
* js/script-tests/arrowfunction-supercall.js:
- Remove expectedExceptionString from shouldNotThrow() calls
after they were changed from shouldThrow() calls.
* resources/js-test-pre.js:
(shouldNotThrow): Change to invoke first argument if it is a
function, else use eval() as before. Use second argurment in
place of first argument (if set) when printing results. NOTE:
Care was taken not to add any lines of code to prevent changes
to test results.
(shouldThrow): Ditto. Reformat code.
* resources/js-test.js: Declare 'didFailSomeTests'.
(testFailed): Set 'didFailSomeTests' to true when a test fails.
(shouldNotThrow): Same changes as js-test-pre.js.
(shouldThrow): Ditto.
(isSuccessfullyParsed): Output a message if 'didFailSomeTests'
is true.
Canonical link: https://commits.webkit.org/177356@main
git-svn-id: https://svn.webkit.org/repository/webkit/trunk@202609 268f45cc-cd09-0410-ab3c-d52691b4dbfc
2016-06-29 04:17:36 +00:00
|
|
|
shouldNotThrow('document.querySelector(":not(' + selectorString.replace(/\\/g, '\\\\') + ')")');
|
Add the baseline implementation of :not(selectorList)
https://bugs.webkit.org/show_bug.cgi?id=137548
Reviewed by Andreas Kling.
Source/WebCore:
This patch extend the pseudo class :not() to support the new definition
in CSS Selectors level 4.
Instead of supporting a single simple selector, :not() now support
an arbitrary selector list, excepted pseudo elements.
One side effect of this change is :visited and :link are no longer supported
inside :not(). The reason has to do with complexity and performance.
Since :not() and :matches() can have arbitrary selector list, keeping track of
:visited and :link can have many combination superposing, some valid, some invalid.
Supporting :visited and :link should be possible by chaning the way we handle
them for style resolution, but given the limited use cases for such features
I'll wait to see if there is any interest before changing everything.
This patch only covers SelectorChecker to keep things simple. The CSS JIT
will come later.
Tests: fast/css/not-basics.html
fast/css/parsing-css-not-1.html
fast/css/parsing-css-not-2.html
fast/css/parsing-css-not-3.html
fast/css/parsing-css-not-4.html
fast/css/parsing-css-not-5.html
fast/css/parsing-css-not-6.html
fast/css/parsing-css-not-7.html
fast/css/parsing-css-not-8.html
fast/css/parsing-css-not-9.html
fast/css/parsing-css-nth-child-of-4.html
fast/selectors/not-basics.html
fast/selectors/not-nested.html
fast/selectors/not-selector-list.html
* css/CSSGrammar.y.in:
Rename selectorListDoesNotMatchAnyPseudoElement() to selectorListDoesNotMatchAnyPseudoElement()
since both :not() and :nth-child(An+B of selectorList) have the same requirements at the moment.
* css/CSSParserValues.cpp:
(WebCore::selectorListMatchesPseudoElement):
The patch adding :matches() introduced the possibility of putting pseudo element
arbitrary deep in a sequence of nested :matches(). Since this case is forbidded
by :not() and :nth-child(An+B of selectorList), selectorListMatchesPseudoElement()
now becomes recursive to find those pseudo elements.
* css/CSSSelector.cpp:
(WebCore::CSSSelector::selectorText):
CSSOM for the extended :not().
* css/SelectorChecker.cpp:
(WebCore::SelectorChecker::checkOne):
(WebCore::SelectorChecker::determineLinkMatchType):
* cssjit/SelectorCompiler.cpp:
(WebCore::SelectorCompiler::addPseudoClassType):
Disable the new capabilities from the JIT for now.
LayoutTests:
There are 3 big kind of changes to the tests:
1) The new implementation intentionally breaks :not() of :visited and :link.
Some test for the basic :not(:link) and :not(:visited) are consequently failing.
2) Some tests were ensuring that :not() only support simple selectors, those are
becoming irrelevant.
3) New test for the feature.
* TestExpectations:
This patch intentionally breaks :not(:link). The test fast/history/link-inside-not.html
time out since it is waiting for the link to match.
* fast/css/invalid-not-with-simple-selector-sequence-expected.txt: Removed.
* fast/css/invalid-not-with-simple-selector-sequence.html: Removed.
This test originally came from IEtestcenter. None of it is useful, all the "invalid"
cases are now fully functional selectors.
* fast/css/css-selector-text-expected.txt:
* fast/css/css-selector-text.html:
* fast/css/css-set-selector-text-expected.txt:
* fast/css/css-set-selector-text.html:
Parsing and CSS OM tests for the new :not().
* fast/css/parsing-css-matches-5-expected.txt:
* fast/css/parsing-css-matches-5.html:
* fast/css/parsing-css-matches-6-expected.txt:
* fast/css/parsing-css-matches-6.html:
* fast/css/parsing-css-matches-7-expected.txt:
* fast/css/parsing-css-matches-7.html:
* fast/css/parsing-css-matches-8-expected.txt:
* fast/css/parsing-css-matches-8.html:
Update the tests of :matches() to account for the extended :not().
* fast/dom/SelectorAPI/resig-SelectorsAPI-test-expected.txt:
Some cases covered by this test are now valid. The test is kept as is for
its historical value, but all the FAIL cover valid use cases in Level 4.
* platform/mac/css3/selectors3/html/css3-modsel-61-expected.txt:
* platform/mac/css3/selectors3/html/css3-modsel-83-expected.txt:
* platform/mac/css3/selectors3/xhtml/css3-modsel-61-expected.txt:
* platform/mac/css3/selectors3/xhtml/css3-modsel-83-expected.txt:
* platform/mac/css3/selectors3/xml/css3-modsel-61-expected.txt:
* platform/mac/css3/selectors3/xml/css3-modsel-83-expected.txt:
* platform/mac/fast/selectors/061-expected.txt:
* platform/mac/fast/selectors/083-expected.txt:
Those tests are changing because of the breakage of :link and :visited.
* fast/css/not-basics-expected.html: Added.
* fast/css/not-basics.html: Added.
Basic use cases of the extended :not() that should always style correctly.
* fast/css/parsing-css-not-1-expected.txt: Added.
* fast/css/parsing-css-not-1.html: Added.
* fast/css/parsing-css-not-2-expected.txt: Added.
* fast/css/parsing-css-not-2.html: Added.
* fast/css/parsing-css-not-3-expected.txt: Added.
* fast/css/parsing-css-not-3.html: Added.
* fast/css/parsing-css-not-4-expected.txt: Added.
* fast/css/parsing-css-not-4.html: Added.
* fast/css/parsing-css-not-5-expected.txt: Added.
* fast/css/parsing-css-not-5.html: Copied from LayoutTests/fast/css/parsing-css-matches-5.html.
* fast/css/parsing-css-not-6-expected.txt: Added.
* fast/css/parsing-css-not-6.html: Copied from LayoutTests/fast/css/parsing-css-matches-6.html.
* fast/css/parsing-css-not-7-expected.txt: Copied from LayoutTests/fast/css/parsing-css-matches-7-expected.txt.
* fast/css/parsing-css-not-7.html: Copied from LayoutTests/fast/css/parsing-css-matches-7.html.
* fast/css/parsing-css-not-8-expected.txt: Copied from LayoutTests/fast/css/parsing-css-matches-8-expected.txt.
* fast/css/parsing-css-not-8.html: Copied from LayoutTests/fast/css/parsing-css-matches-8.html.
* fast/css/parsing-css-not-9-expected.txt: Added.
* fast/css/parsing-css-not-9.html: Copied from LayoutTests/fast/css/parsing-css-matches-8.html.
Parsing of :not(). A lot of them were inspired by Yusuke Suzuki's test suite
for :matches(). A lot of test case apply to :not(), the main difference is that
pseudo elements must fail inside :not().
* fast/css/parsing-css-nth-child-of-4-expected.txt: Added.
* fast/css/parsing-css-nth-child-of-4.html: Added.
With the introduction of :matches(), it is possible to have arbitrarily deep pseudo elements.
The tests for :not() cover the case fixed with this patch, this addition covers :nth-child(of).
* fast/selectors/not-basics-expected.txt: Added.
* fast/selectors/not-basics.html: Added.
* fast/selectors/not-nested-expected.txt: Added.
* fast/selectors/not-nested.html: Added.
* fast/selectors/not-selector-list-expected.txt: Added.
* fast/selectors/not-selector-list.html: Added.
Test coverage for the new features.
Canonical link: https://commits.webkit.org/155417@main
git-svn-id: https://svn.webkit.org/repository/webkit/trunk@174535 268f45cc-cd09-0410-ab3c-d52691b4dbfc
2014-10-09 22:14:29 +00:00
|
|
|
|
|
|
|
var styleContainer = document.getElementById('style-container');
|
|
|
|
styleContainer.innerHTML = ':not(' + selectorString + ') { }';
|
|
|
|
shouldBe("document.getElementById('style-container').sheet.cssRules.length", "1");
|
|
|
|
if (!expectedSerializedSelector)
|
|
|
|
expectedSerializedSelector = selectorString;
|
|
|
|
shouldBeEqualToString("document.getElementById('style-container').sheet.cssRules[0].selectorText", ':not(' + expectedSerializedSelector + ')');
|
|
|
|
styleContainer.innerHTML = '';
|
|
|
|
}
|
|
|
|
|
|
|
|
debug("3 valid selectors");
|
|
|
|
|
|
|
|
var validSelectorsPart1 = [
|
|
|
|
// Basic types.
|
|
|
|
"*",
|
|
|
|
"#id",
|
|
|
|
":first-child",
|
|
|
|
":visited",
|
|
|
|
|
|
|
|
// Compound selectors.
|
|
|
|
".class:not(.notclass)",
|
|
|
|
|
|
|
|
// Complex selectors.
|
|
|
|
"a > b",
|
|
|
|
"a + b",
|
|
|
|
"a + b > c ~ d e + g",
|
|
|
|
|
|
|
|
// Functional pseudo classes.
|
|
|
|
":not(:link)",
|
|
|
|
];
|
|
|
|
|
|
|
|
/* Try all combinations, each value is unique to the others. */
|
|
|
|
for (var i = 0; i < validSelectorsPart1.length; ++i) {
|
|
|
|
for (var j = i; j < validSelectorsPart1.length; ++j) {
|
|
|
|
for (var k = j; k < validSelectorsPart1.length; ++k) {
|
|
|
|
var selectorString = validSelectorsPart1[i] + ', ' + validSelectorsPart1[j] + ', ' + validSelectorsPart1[k];
|
|
|
|
testValidSelector(selectorString);
|
|
|
|
testValidSelector(selectorString + " ", selectorString);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
</script>
|
|
|
|
<script src="../../resources/js-test-post.js"></script>
|
|
|
|
</html>
|