Skip to content

Commit

Permalink
CSSOM: add CSSStyleDeclaration cssText setter tests
Browse files Browse the repository at this point in the history
  • Loading branch information
annevk authored Mar 15, 2024
1 parent 9e1be55 commit 525ebf0
Show file tree
Hide file tree
Showing 2 changed files with 65 additions and 0 deletions.
64 changes: 64 additions & 0 deletions css/cssom/cssstyledeclaration-csstext-setter.window.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
// https://drafts.csswg.org/cssom/#dom-cssstyledeclaration-csstext

[
document.body,
document.createElement("cool-beans")
].forEach(element => {
test(t => {
t.add_cleanup(() => element.removeAttribute("style"));

element.style.background = "red";
assert_equals(element.getAttribute("style"), "background: red;");

element.style.cssText = "background:red";
assert_equals(element.getAttribute("style"), "background: red;");
}, `cssText setter should set style attribute even when there are no style changes (${element.localName})`);

test(t => {
t.add_cleanup(() => element.removeAttribute("style"));

element.setAttribute("style", "background: red");
assert_equals(element.getAttribute("style"), "background: red");

element.style.cssText = "background:red";
assert_equals(element.getAttribute("style"), "background: red;");
}, `cssText setter should set style attribute even when there are no style changes, part 2 (${element.localName})`);

test(t => {
t.add_cleanup(() => element.removeAttribute("style"));

element.setAttribute("style", "background: red");
assert_equals(element.getAttribute("style"), "background: red");

element.style.cssText = "background:red "; // trailing space
assert_equals(element.getAttribute("style"), "background: red;");
}, `cssText setter should set style attribute even when there are no style changes, part 3 (${element.localName})`);

test(t => {
t.add_cleanup(() => element.removeAttribute("style"));

element.setAttribute("style", "background: red");
assert_equals(element.getAttribute("style"), "background: red");

element.style.cssText = "background:red;";
assert_equals(element.getAttribute("style"), "background: red;");
}, `cssText setter should set style attribute even when there are no style changes, part 4 (${element.localName})`);
});

test(t => {
const style = document.createElement("style");
t.add_cleanup(() => {
document.body.removeAttribute("style");
style.remove();
});
style.textContent = `[style="background: red;"] { background:white !important; }`;
document.body.appendChild(style);

document.body.setAttribute("style", "background:red");
assert_true(document.body.matches("[style=\"background:red\"]"));
assert_equals(getComputedStyle(document.body).backgroundColor, "rgb(255, 0, 0)");

document.body.style.cssText = "background:red";
assert_equals(getComputedStyle(document.body).backgroundColor, "rgb(255, 255, 255)");
assert_true(document.body.matches("[style=\"background: red;\"]"));
}, `cssText setter and selector invalidation`);
1 change: 1 addition & 0 deletions lint.ignore
Original file line number Diff line number Diff line change
Expand Up @@ -580,6 +580,7 @@ MISSING-LINK: css/cssom-view/scrollTop-display-change.html
# TODO https://github.com/web-platform-tests/wpt/issues/5770
MISSING-LINK: css/css-highlight-api/idlharness.window.js
MISSING-LINK: css/css-highlight-api/historical.window.js
MISSING-LINK: css/cssom/cssstyledeclaration-csstext-setter.window.js
MISSING-LINK: css/geometry/*.worker.js
MISSING-LINK: css/geometry/*.any.js
MISSING-LINK: css/filter-effects/*.any.js
Expand Down

0 comments on commit 525ebf0

Please sign in to comment.