Tests: Import WPT CSSOM and parsing tests for @page

This commit is contained in:
Sam Atkins 2025-05-13 11:50:49 +01:00
commit 1002464322
Notes: github-actions[bot] 2025-05-15 08:54:59 +00:00
10 changed files with 295 additions and 0 deletions

View file

@ -0,0 +1,9 @@
Harness status: OK
Found 4 tests
4 Fail
Fail There should be 3 @page rules.
Fail Rule #0
Fail Rule #1
Fail Rule #2

View file

@ -0,0 +1,3 @@
Harness status: Error
Found 0 tests

View file

@ -0,0 +1,6 @@
Harness status: OK
Found 1 tests
1 Fail
Fail nested-rules-001

View file

@ -0,0 +1,14 @@
Harness status: OK
Found 8 tests
4 Pass
4 Fail
Pass page-rules-001
Pass @page , { } should be an invalid rule
Fail @page { } should be a valid rule
Fail @page a { } should be a valid rule
Fail @page page1 { } should be a valid rule
Fail @page name1, name2 { } should be a valid rule
Pass @page a, { } should be an invalid rule
Pass @page ,a { } should be an invalid rule

View file

@ -0,0 +1,20 @@
Harness status: OK
Found 15 tests
15 Fail
Fail Test setup
Fail size: 640px 480px
Fail size: 8.5in 11in
Fail size: 3in 10in
Fail size: auto
Fail size: a5
Fail size: a4
Fail size: a3
Fail size: b5
Fail size: b4
Fail size: jis-b5
Fail size: jis-b4
Fail size: landscape
Fail size: letter
Fail size: legal landscape

View file

@ -0,0 +1,41 @@
<!DOCTYPE html>
<link rel="author" title="Morten Stenshorne" href="mailto:mstensho@chromium.org">
<link rel="help" href="https://drafts.csswg.org/cssom/#the-csspagerule-interface">
<title>Basic CSSPageRule CSSOM test</title>
<style id="sheet">
@page {}
@page :left {}
@page named { margin: 10px 20px; }
</style>
<script src="../../../resources/testharness.js"></script>
<script src="../../../resources/testharnessreport.js"></script>
<script>
var sheet = document.getElementById("sheet").sheet;
test(()=> {
assert_not_equals(sheet, null);
assert_equals(sheet.rules.length, 3);
}, "There should be 3 @page rules.");
test(()=> {
assert_equals(sheet.rules[0].constructor.name, "CSSPageRule");
assert_equals(sheet.rules[0].selectorText, "");
assert_equals(sheet.rules[0].style.length, 0);
}, "Rule #0");
test(()=> {
assert_equals(sheet.rules[1].constructor.name, "CSSPageRule");
assert_equals(sheet.rules[1].selectorText, ":left");
assert_equals(sheet.rules[1].style.length, 0);
}, "Rule #1");
test(()=> {
assert_equals(sheet.rules[2].constructor.name, "CSSPageRule");
assert_equals(sheet.rules[2].selectorText, "named");
var style = sheet.rules[2].style;
assert_equals(style.length, 4);
assert_equals(style.marginTop, "10px");
assert_equals(style.marginRight, "20px");
assert_equals(style.marginBottom, "10px");
assert_equals(style.marginLeft, "20px");
}, "Rule #2");
</script>

View file

@ -0,0 +1,32 @@
<!DOCTYPE html>
<link rel="author" title="Morten Stenshorne" href="mailto:mstensho@chromium.org">
<link rel="help" href="https://drafts.csswg.org/cssom/#the-csspagerule-interface">
<title>Add / remove declarations inside CSSPageRule</title>
<style id="sheet">
@page {}
</style>
<script src="../../../resources/testharness.js"></script>
<script src="../../../resources/testharnessreport.js"></script>
<script>
var sheet = document.getElementById("sheet").sheet;
var pageRule = sheet.rules[0];
var style = pageRule.style;
test(()=> {
assert_equals(style.length, 0);
style.setProperty("margin-left", "50%");
assert_equals(style.length, 1);
assert_equals(style.marginLeft, "50%");
style.setProperty("margin-left", "100px");
assert_equals(style.length, 1);
assert_equals(style.marginLeft, "100px");
style.setProperty("margin", "auto");
assert_equals(style.length, 4);
assert_equals(style.marginLeft, "auto");
}, "Add declarations");
test(()=> {
assert_equals(style.length, 4);
style.removeProperty("margin");
assert_equals(style.length, 0);
}, "Remove declarations");
</script>

View file

@ -0,0 +1,66 @@
<!DOCTYPE html>
<link rel="author" title="Mozilla" href="https://mozilla.org">
<link rel="help" href="https://drafts.csswg.org/css-page-3/#syntax-page-selector">
<script src="../../../resources/testharness.js"></script>
<script src="../../../resources/testharnessreport.js"></script>
<style>
@page p0{
@page a{ size: letter; }
}
@page p1{
@namespace svg url(http://www.w3.org/2000/svg);
}
@page p2{
@font-face{}
}
@page p3{
@font-feature-values font one{}
}
@page p4{
@font-palette-values --alternate{}
}
@page p5{
@counter-style x{}
}
@page p6{
@keyframes y{}
}
@page p7{
@property z{
syntax: "<color>";
inherits: false;
initial-value: #c0ffee;
}
}
@page p8{
@import url("style.css") screen;
}
</style>
<script>
'use strict';
test(t => {
assert_equals(document.styleSheets.length, 1);
let styleSheet = document.styleSheets[0];
const ruleTypes = [
"page",
"namespace",
"font-face",
"font-feature-values",
"font-palette-values",
"counter-style",
"keyframes",
"property",
"import"
];
assert_equals(styleSheet.rules.length, ruleTypes.length);
for(let i = 0; i < styleSheet.rules.length; i++){
// Just test that this is the right rule first.
assert_equals(styleSheet.rules[i].selectorText, "p" + i,
"@page p" + i + " was not parsed at all");
// Test that the nested rule was not valid.
assert_equals(styleSheet.rules[i].cssText, "@page p" + i + " { }",
"@" + ruleTypes[i] + " rules should not be allowed in @page rules");
}
}, "nested-rules-001");
</script>

View file

@ -0,0 +1,19 @@
<!DOCTYPE html>
<link rel="author" title="Mozilla" href="https://mozilla.org">
<link rel="help" href="https://drafts.csswg.org/css-page-3/#at-page-rules">
<script src="../../../resources/testharness.js"></script>
<script src="../../../resources/testharnessreport.js"></script>
<script src="../../../css/support/parsing-testcommon.js"></script>
<script>
test(t => {
// At least check that empty selectors are not allowed.
test_invalid_rule("@page , { }");
test_valid_rule("@page { }");
// Some basic name tests.
test_valid_rule("@page a { }");
test_valid_rule("@page page1 { }");
test_valid_rule("@page name1, name2 { }");
test_invalid_rule("@page a, { }");
test_invalid_rule("@page ,a { }");
}, "page-rules-001");
</script>

View file

@ -0,0 +1,85 @@
<!DOCTYPE html>
<link rel="author" title="Mozilla" href="https://mozilla.org">
<link rel="help" href="https://drafts.csswg.org/css-page-3/#page-size-prop">
<script src="../../../resources/testharness.js"></script>
<script src="../../../resources/testharnessreport.js"></script>
<style>
@page {
size: 640px 480px;
}
@page {
size: 8.5in 11in;
}
@page {
size: 3in 10in;
}
@page {
size: auto;
}
@page {
size: A5;
}
@page {
size: A4;
}
@page {
size: A3;
}
@page {
size: B5;
}
@page {
size: B4;
}
@page {
size: jis-B5;
}
@page {
size: jis-B4;
}
@page {
size: landscape;
}
@page {
size: letter portrait;
}
@page {
size: legal landscape;
}
</style>
<script>
"use strict";
const expectedSizes = [
"640px 480px",
"8.5in 11in",
"3in 10in",
"auto",
"a5",
"a4",
"a3",
"b5",
"b4",
"jis-b5",
"jis-b4",
"landscape",
"letter",
"legal landscape"
];
const sizePrefix = "size: ";
test(() => {
assert_equals(document.styleSheets.length, 1);
assert_equals(document.styleSheets[0].rules.length, expectedSizes.length);
}, "Test setup");
for (let i = 0; i < expectedSizes.length; i++) {
test(() => {
let cssText = document.styleSheets[0].cssRules[i].style.cssText;
assert_true(cssText.startsWith(sizePrefix));
cssText = cssText.slice(sizePrefix.length);
assert_equals(cssText, expectedSizes[i] + ";", "for rule " + i);
}, "size: " + expectedSizes[i]);
}
</script>