mirror of
https://github.com/LadybirdBrowser/ladybird
synced 2026-04-26 17:55:07 +02:00
LibWeb: Implement CSSStyleSheet.addRule()
This is a legacy method that has been superseded by `insertRule()`, although it is supported by all modern browser engines.
This commit is contained in:
committed by
Andreas Kling
parent
87b52a1816
commit
3ea318ca8b
Notes:
sideshowbarker
2024-07-17 07:09:53 +09:00
Author: https://github.com/tcl3 Commit: https://github.com/SerenityOS/serenity/commit/3ea318ca8b Pull-request: https://github.com/SerenityOS/serenity/pull/23327 Reviewed-by: https://github.com/awesomekling
28
Tests/LibWeb/Text/input/css/CSSStyleSheet-addRule.html
Normal file
28
Tests/LibWeb/Text/input/css/CSSStyleSheet-addRule.html
Normal file
@@ -0,0 +1,28 @@
|
||||
<!DOCTYPE html>
|
||||
<script src="../include.js"></script>
|
||||
<script>
|
||||
test(() => {
|
||||
const sheet = new CSSStyleSheet();
|
||||
println(`addValue() return value: ${sheet.addRule()}`);
|
||||
println(`Rule count after calling addRule() with no arguments: ${sheet.cssRules.length}`);
|
||||
println(`Rule text: ${sheet.cssRules[0].cssText}`);
|
||||
sheet.addRule(".test", "font-size: 14px");
|
||||
println(`Rule count after calling addRule with no index: ${sheet.cssRules.length}`);
|
||||
println(`Second rule text: ${sheet.cssRules[1].cssText}`);
|
||||
sheet.addRule(".test", "padding: 100px", 0);
|
||||
println(`Rule count after calling addRule with index 0: ${sheet.cssRules.length}`);
|
||||
println(`Rule text: ${sheet.cssRules[0].cssText}`);
|
||||
try {
|
||||
sheet.addRule(".test", "padding: 10px", -1);
|
||||
println("FAIL");
|
||||
} catch (e) {
|
||||
println(`Exception thrown when given a negative index: ${e.name}`);
|
||||
}
|
||||
try {
|
||||
sheet.addRule(".test", "padding: 10px", 4);
|
||||
println("FAIL");
|
||||
} catch (e) {
|
||||
println(`Exception thrown when index out of range: ${e.name}`);
|
||||
}
|
||||
});
|
||||
</script>
|
||||
Reference in New Issue
Block a user