ladybird/Tests/LibWeb/Text/input/css/CSSStyleSheet-removeRule.html
Tim Ledbetter 1d825f17c0 LibWeb: Remove first rule if no argument is given for remove_rule()
While this isn't explicitly mentioned in the specification, there is a
WPT test that checks for this behavior.
2024-02-24 21:59:28 +01:00

41 lines
1.4 KiB
HTML

<!DOCTYPE html>
<script src="../include.js"></script>
<script>
test(() => {
const sheet = new CSSStyleSheet();
try {
sheet.removeRule();
println("FAIL");
} catch (e) {
println(`Exception thrown when removeRule() called on empty sheet: ${e.name}`);
}
sheet.addRule(".test", "padding: 10px");
sheet.addRule(".test", "margin: 5px");
sheet.addRule(".test", "font-size: 14px");
println(`Rule count after adding 3 rules: ${sheet.cssRules.length}`);
for (const rule of sheet.cssRules) {
println(`Rule text: ${rule.cssText}`);
}
sheet.removeRule();
println(`Rule count after calling removeRule with no arguments: ${sheet.cssRules.length}`);
for (const rule of sheet.cssRules) {
println(`Rule text: ${rule.cssText}`);
}
sheet.removeRule(1);
println(`Rule count after calling removeRule with explicit index: ${sheet.cssRules.length}`);
println(`Rule text: ${sheet.cssRules[0].cssText}`);
try {
sheet.removeRule(-1);
println("FAIL");
} catch (e) {
println(`Exception thrown when given a negative index: ${e.name}`);
}
try {
sheet.removeRule(1);
println("FAIL");
} catch (e) {
println(`Exception thrown when index out of range: ${e.name}`);
}
});
</script>