gecko-dev/testing/web-platform/tests/css/cssom/css-style-reparse.html
Kris Maglione 2475362f04 Bug 1451940: Don't reparse stylesheets when assigning empty string to empty element. r=bz
Per spec, assinging an empty string to textContent or innerHTML should not
trigger any mutation observers, and therefore should not trigger a stylesheet
reparse, when the element is already empty.

Since we need to apply some special handling to innerHTML and textContent
assignments to <style> nodes, and therefore re-parse directly in the setter
rather than in response to mutation observers, we need to special-case this
scenario.

MozReview-Commit-ID: KdOYFs8ayT7

--HG--
extra : rebase_source : 67b85174d08028c5200964800b657950aa2bffa2
2018-04-10 11:06:26 -07:00

59 lines
1.9 KiB
HTML

<!doctype html>
<html>
<head>
<meta charset=utf-8>
<title>CSS Test: DOM modification re-parsing test</title>
<link rel="help" href="https://drafts.csswg.org/cssom/">
<link rel="help" href="http://www.w3.org/TR/cssom-1/#the-cssrule-interface">
<script src=/resources/testharness.js></script>
<script src=/resources/testharnessreport.js></script>
<style>div { min-width: 0px; }</style>
<style id="style-element"></style>
</head>
<body>
<div id="test-div"></div>
<script type="text/javascript">
var style = document.getElementById("style-element");
var div = document.getElementById("test-div");
function testProperty(prop) {
// Assigning an empty string to textContent or innerHTML should trigger a
// reparse only if the element is not empty.
style.sheet.insertRule("#test-div { min-width: 42px; }");
assert_equals(getComputedStyle(div).minWidth, "42px");
style[prop] = "";
assert_equals(getComputedStyle(div).minWidth, "42px");
style[prop] = " ";
assert_equals(getComputedStyle(div).minWidth, "0px");
style.sheet.insertRule("#test-div { min-width: 42px; }");
assert_equals(getComputedStyle(div).minWidth, "42px");
style[prop] = "";
assert_equals(getComputedStyle(div).minWidth, "0px");
style.sheet.insertRule("#test-div { min-width: 42px; }");
assert_equals(getComputedStyle(div).minWidth, "42px");
style.appendChild(document.createTextNode(""));
assert_equals(getComputedStyle(div).minWidth, "0px");
style.sheet.insertRule("#test-div { min-width: 42px; }");
assert_equals(getComputedStyle(div).minWidth, "42px");
style[prop] = "";
assert_equals(getComputedStyle(div).minWidth, "0px");
}
test(function() {
testProperty("textContent");
}, "style.textContent modification");
test(function() {
testProperty("innerHTML");
}, "style.innerHTML modification");
</script>
</body>
</html>