gecko-dev/testing/web-platform/tests/css/cssom/selectorSerialize.html
Chris Nardi b73182a3b9 Bug 1442493 [wpt PR 9739] - Upstream some CSSOM tests, a=testonly
Automatic update from web-platform-testsUpstream some CSSOM tests

Tests that were duplicates of those already existing in
web-platform-tests were deleted. Other tests were either moved to the
CSSOM directory in WPT, or appended to already existing tests. The
README was also deleted, as it is no longer accurate.

Change-Id: I0acb41c6102a572a1fc2401630732a8ff1c5263d
Reviewed-on: https://chromium-review.googlesource.com/945135
Reviewed-by: Robert Ma <robertma@chromium.org>
Reviewed-by: Darren Shen <shend@chromium.org>
Commit-Queue: Chris Nardi <cnardi@chromium.org>
Cr-Commit-Position: refs/heads/master@{#541716}

wpt-commits: 8ef3fed7cdd966fbbd831215cedc0ee4b8ea8d6e
wpt-pr: 9739
wpt-commits: 8ef3fed7cdd966fbbd831215cedc0ee4b8ea8d6e
wpt-pr: 9739
2018-03-31 22:32:51 +01:00

120 lines
6.6 KiB
HTML

<!DOCTYPE html>
<html>
<head>
<title>CSSOM Test: test serialized selector which is only one simple selector in the sequence of simple selectors</title>
<link rel="author" title="T.Nishitani" href="mailto:lequinharay@gmail.com">
<link rel="reviewer" title="L. David Baron" href="https://dbaron.org/">
<link rel="help" href="https://drafts.csswg.org/cssom-1/#serializing-selectors">
<meta name="flags" content="dom">
<meta charset="utf-8">
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<style id="teststyles">
</style>
</head>
<body>
<div id="log"></div>
<script>
function assert_selector_serializes_to(source, expected_result) {
var style_element = document.getElementById("teststyles");
style_element.firstChild.data = source + "{ font-size: 1em; }";
var sheet = style_element.sheet;
assert_equals(sheet.cssRules[sheet.cssRules.length - 1].selectorText, expected_result);
}
function run_tests_on_anplusb_selector(source) {
assert_selector_serializes_to(source + '( even )', source + '(2n)');
assert_selector_serializes_to(source + '( odd )', source + '(2n+1)');
assert_selector_serializes_to(source + '( +10 )', source + '(10)');
assert_selector_serializes_to(source + '( -10 )', source + '(-10)');
assert_selector_serializes_to(source + '( +4n )', source + '(4n)');
assert_selector_serializes_to(source + '( -3n )', source + '(-3n)');
assert_selector_serializes_to(source + '( 1n + 5 )', source + '(n+5)');
assert_selector_serializes_to(source + '( -1n + 5 )', source + '(-n+5)');
assert_selector_serializes_to(source + '( -1n - 5 )', source + '(-n-5)');
}
test(function() {
assert_selector_serializes_to(":nth-child( 3n - 0)", ":nth-child(3n)");
assert_selector_serializes_to(":nth-child( 1n - 0)", ":nth-child(n)");
}, ":nth-child serialization produces canonical form");
/* for universal selecter with default namespace */
test(function(){
/* this is single universal selector */
assert_selector_serializes_to('*', '*');
assert_selector_serializes_to(' * ', '*');
}, 'single universal selector shows \'*\' when serialized.')
test(function(){
assert_selector_serializes_to('div', 'div');
assert_selector_serializes_to(' div ', 'div');
}, 'single type (simple) selector in the sequence of simple selectors that is not a universal selector')
test(function(){
assert_selector_serializes_to('.class', '.class');
assert_selector_serializes_to(' .class ', '.class');
}, 'single class (simple) selector in the sequence of simple selectors that is not a universal selector')
test(function(){
assert_selector_serializes_to('#id', '#id');
assert_selector_serializes_to(' #id ', '#id');
}, 'single id (simple) selector in the sequence of simple selectors that is not a universal selector')
test(function(){
assert_selector_serializes_to(':hover', ':hover');
assert_selector_serializes_to(' :hover ', ':hover');
}, 'single pseudo (simple) selector which does not accept arguments in the sequence of simple selectors that is not a universal selector')
test(function(){
assert_selector_serializes_to(':lang(ja)', ':lang(ja)');
assert_selector_serializes_to(':lang( ja )', ':lang(ja)');
}, 'single pseudo (simple) selector "lang" which accepts arguments in the sequence of simple selectors that is not a universal selector')
test(function(){
run_tests_on_anplusb_selector(':nth-child');
}, 'single pseudo (simple) selector "nth-child" which accepts arguments in the sequence of simple selectors that is not a universal selector')
test(function(){
run_tests_on_anplusb_selector(':nth-last-child');
}, 'single pseudo (simple) selector "nth-last-child" which accepts arguments in the sequence of simple selectors that is not a universal selector')
test(function(){
run_tests_on_anplusb_selector(':nth-of-type');
}, 'single pseudo (simple) selector "nth-of-child" which accepts arguments in the sequence of simple selectors that is not a universal selector')
test(function(){
run_tests_on_anplusb_selector(':nth-last-of-type');
}, 'single pseudo (simple) selector ":nth-last-of-type" which accepts arguments in the sequence of simple selectors that is not a universal selector')
test(function(){
assert_selector_serializes_to(' :not( abc ) ', ':not(abc)');
assert_selector_serializes_to(' :not( .head ) ', ':not(.head)');
assert_selector_serializes_to(' :not( #head ) ', ':not(#head)');
assert_selector_serializes_to(' :not( :hover ) ', ':not(:hover)');
}, 'single pseudo (simple) selector ":not" which accepts arguments in the sequence of simple selectors that is not a universal selector')
var escaped_ns_rule = "@namespace ns\\:odd url(ns);";
test(function() {
assert_selector_serializes_to("[ns\\:foo]", "[ns\\:foo]");
}, "escaped character in attribute name");
test(function() {
assert_selector_serializes_to("[\\30zonk]", "[\\30 zonk]");
}, "escaped character as code point in attribute name");
test(function() {
assert_selector_serializes_to("[\\@]", "[\\@]");
}, "escaped character (@) in attribute name");
test(function() {
assert_selector_serializes_to("[*|ns\\:foo]", "[*|ns\\:foo]");
}, "escaped character in attribute name with any namespace");
test(function() {
assert_selector_serializes_to(escaped_ns_rule + "[ns\\:odd|foo]", "[ns\\:odd|foo]");
}, "escaped character in attribute prefix");
test(function() {
assert_selector_serializes_to(escaped_ns_rule + "[ns\\:odd|odd\\:name]", "[ns\\:odd|odd\\:name]");
}, "escaped character in both attribute prefix and name");
</script>
</body>
</html>