LibWeb/CSS: Implement CSSPageRule.setSelectorText()
Some checks are pending
CI / Lagom (arm64, Sanitizer_CI, false, macos-15, macOS, Clang) (push) Waiting to run
CI / Lagom (x86_64, Fuzzers_CI, false, ubuntu-24.04, Linux, Clang) (push) Waiting to run
CI / Lagom (x86_64, Sanitizer_CI, false, ubuntu-24.04, Linux, GNU) (push) Waiting to run
CI / Lagom (x86_64, Sanitizer_CI, true, ubuntu-24.04, Linux, Clang) (push) Waiting to run
Package the js repl as a binary artifact / build-and-package (arm64, macos-15, macOS, macOS-universal2) (push) Waiting to run
Package the js repl as a binary artifact / build-and-package (x86_64, ubuntu-24.04, Linux, Linux-x86_64) (push) Waiting to run
Run test262 and test-wasm / run_and_update_results (push) Waiting to run
Lint Code / lint (push) Waiting to run
Label PRs with merge conflicts / auto-labeler (push) Waiting to run
Push notes / build (push) Waiting to run

Gets us 12 WPT subtest passes.
This commit is contained in:
Sam Atkins 2025-05-16 11:41:56 +01:00
commit c9484e279f
Notes: github-actions[bot] 2025-05-16 15:45:04 +00:00
3 changed files with 168 additions and 5 deletions

View file

@ -8,6 +8,7 @@
#include <LibWeb/Bindings/Intrinsics.h>
#include <LibWeb/CSS/CSSPageRule.h>
#include <LibWeb/CSS/DescriptorID.h>
#include <LibWeb/CSS/Parser/Parser.h>
#include <LibWeb/CSS/Serialize.h>
#include <LibWeb/WebIDL/ExceptionOr.h>
@ -45,11 +46,16 @@ String CSSPageRule::selector_text() const
}
// https://drafts.csswg.org/cssom/#dom-csspagerule-selectortext
void CSSPageRule::set_selector_text(StringView)
void CSSPageRule::set_selector_text(StringView text)
{
// FIXME: On setting the selectorText attribute these steps must be run:
// On setting the selectorText attribute these steps must be run:
// 1. Run the parse a list of CSS page selectors algorithm on the given value.
auto page_selector_list = parse_page_selector_list(Parser::ParsingParams {}, text);
// 2. If the algorithm returns a non-null value replace the associated selector list with the returned value.
if (page_selector_list.has_value())
m_selectors = page_selector_list.release_value();
// 3. Otherwise, if the algorithm returns a null value, do nothing.
}

View file

@ -0,0 +1,27 @@
Harness status: OK
Found 22 tests
22 Pass
Pass Sanity checks
Pass Page selector is initially the empty string
Pass Page selector 'cssText' is initially the @page { }
Pass Set selectorText to :left pseudo page
Pass Set cssText to :left pseudo page
Pass Set selectorText to named page
Pass Set cssText to named page
Pass Set selectorText to named page with :first pseudo page
Pass Set cssText to named page with :first pseudo page
Pass Set selectorText to named page with case insensitive :first pseudo page
Pass Set cssText to named page with case insensitive :first pseudo page
Pass Set selectorText to named page with two :first pseudo page
Pass Set cssText to named page with two :first pseudo page
Pass Set selectorText to named page with pseudo pages of :first, :left, :right, :first in order.
Pass Set cssText to named page with pseudo pages of :first, :left, :right, :first in order.
Pass Cannot set selectorText to named page with pseudo, whitespace between
Pass Cannot set cssText to named page with pseudo, whitespace between - return default @page { }
Pass Cannot set selectorText to two pseudos, whitespace between
Pass Cannot set cssText to two pseudos, whitespace between - return default @page { }
Pass Cannot set selectorText to invalid pseudo page
Pass Cannot set cssText to invalid pseudo page - return default @page { }
Pass Set selectorText to named page after rule was removed

View file

@ -0,0 +1,130 @@
<!DOCTYPE html>
<title>CSSOM: CSSPageRule tests</title>
<link rel="help" href="https://drafts.csswg.org/cssom/#the-csspagerule-interface" />
<script src="../../resources/testharness.js"></script>
<script src="../../resources/testharnessreport.js"></script>
<style>
@page {}
</style>
<script>
const sheet = document.styleSheets[0];
const rule = sheet.cssRules[0];
test(() => {
assert_true(!!rule);
assert_equals(rule.type, CSSRule.PAGE_RULE);
}, "Sanity checks");
test(() => {
assert_equals(rule.selectorText, "");
}, "Page selector is initially the empty string");
test(() => {
assert_equals(rule.cssText, "@page { }");
}, "Page selector 'cssText' is initially the @page { }");
test(() => {
rule.selectorText = ":left";
assert_equals(rule.selectorText, ":left");
}, "Set selectorText to :left pseudo page");
test(() => {
rule.selectorText = ":left";
assert_equals(rule.cssText, "@page :left { }");
}, "Set cssText to :left pseudo page");
test(() => {
rule.selectorText = "named";
assert_equals(rule.selectorText, "named");
}, "Set selectorText to named page");
test(() => {
rule.selectorText = "named";
assert_equals(rule.cssText, "@page named { }");
}, "Set cssText to named page");
test(() => {
rule.selectorText = "named:first";
assert_equals(rule.selectorText, "named:first");
}, "Set selectorText to named page with :first pseudo page");
test(() => {
rule.selectorText = "named:first";
assert_equals(rule.cssText, "@page named:first { }");
}, "Set cssText to named page with :first pseudo page");
test(() => {
rule.selectorText = "named:First";
assert_equals(rule.selectorText, "named:first");
}, "Set selectorText to named page with case insensitive :first pseudo page");
test(() => {
rule.selectorText = "named:First";
assert_equals(rule.cssText, "@page named:first { }");
}, "Set cssText to named page with case insensitive :first pseudo page");
test(() => {
rule.selectorText = "named:first:first";
assert_equals(rule.selectorText, "named:first:first");
}, "Set selectorText to named page with two :first pseudo page");
test(() => {
rule.selectorText = "named:first:first";
assert_equals(rule.cssText, "@page named:first:first { }");
}, "Set cssText to named page with two :first pseudo page");
test(() => {
rule.selectorText = "named:first:left:right:first";
assert_equals(rule.selectorText, "named:first:left:right:first");
}, "Set selectorText to named page with pseudo pages of " +
":first, :left, :right, :first in order.");
test(() => {
rule.selectorText = "named:first:left:right:first";
assert_equals(rule.cssText, "@page named:first:left:right:first { }");
}, "Set cssText to named page with pseudo pages of " +
":first, :left, :right, :first in order.");
test(() => {
rule.selectorText = "";
rule.selectorText = "named :first";
assert_equals(rule.selectorText, "");
}, "Cannot set selectorText to named page with pseudo, whitespace between");
test(() => {
rule.selectorText = "";
rule.selectorText = "named :first";
assert_equals(rule.cssText, "@page { }");
}, "Cannot set cssText to named page with pseudo, whitespace between - return default @page { }");
test(() => {
rule.selectorText = "";
rule.selectorText = ":first :left";
assert_equals(rule.selectorText, "");
}, "Cannot set selectorText to two pseudos, whitespace between");
test(() => {
rule.selectorText = "";
rule.selectorText = ":first :left";
assert_equals(rule.cssText, "@page { }");
}, "Cannot set cssText to two pseudos, whitespace between - return default @page { }");
test(() => {
rule.selectorText = "";
rule.selectorText = ":notapagepseudo";
assert_equals(rule.selectorText, "");
}, "Cannot set selectorText to invalid pseudo page");
test(() => {
rule.selectorText = "";
rule.selectorText = ":notapagepseudo";
assert_equals(rule.cssText, "@page { }");
}, "Cannot set cssText to invalid pseudo page - return default @page { }");
test(() => {
assert_equals(rule.parentStyleSheet, sheet);
sheet.deleteRule(0);
assert_equals(rule.parentStyleSheet, null);
rule.selectorText = "pagename";
}, "Set selectorText to named page after rule was removed");
</script>