-
Notifications
You must be signed in to change notification settings - Fork 3.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
CSSOM: add CSSStyleDeclaration cssText setter tests
- Loading branch information
Showing
2 changed files
with
65 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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`); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters