Stop creating a style attribute for invalid property values.

This matches all other browsers, and the spec.

Added an explicit test for this, and a test that tests what
cssstyledeclaration-mutationrecord-002.html wanted to test, which is that
changing an existing declaration doesn't generate a mutation record.

Differential Revision: https://phabricator.services.mozilla.com/D8500

bugzilla-url: https://bugzilla.mozilla.org/show_bug.cgi?id=1498445
gecko-commit: ccdfe4ca1f881fea6751d8addbd6466d106ed3dd
gecko-integration-branch: central
gecko-reviewers: smaug
diff --git a/css/cssom/cssstyledeclaration-mutationrecord-002.html b/css/cssom/cssstyledeclaration-mutationrecord-002.html
index 1cdb41a..38ce249 100644
--- a/css/cssom/cssstyledeclaration-mutationrecord-002.html
+++ b/css/cssom/cssstyledeclaration-mutationrecord-002.html
@@ -1,7 +1,7 @@
 <!doctype html>
 <meta charset="utf-8">
 <title>CSSOM: CSSStyleDeclaration.setPropertyValue doesn't queue a mutation record for invalid values</title>
-<link rel="help" href="https://drafts.csswg.org/cssom/#dom-cssstyledeclaration-setpropertyvalue">
+<link rel="help" href="https://drafts.csswg.org/cssom/#dom-cssstyledeclaration-setproperty">
 <link rel="author" title="Emilio Cobos Álvarez" href="mailto:emilio@crisal.io">
 <script src=/resources/testharness.js></script>
 <script src=/resources/testharnessreport.js></script>
diff --git a/css/cssom/cssstyledeclaration-mutationrecord-005.html b/css/cssom/cssstyledeclaration-mutationrecord-005.html
new file mode 100644
index 0000000..2657403
--- /dev/null
+++ b/css/cssom/cssstyledeclaration-mutationrecord-005.html
@@ -0,0 +1,16 @@
+<!doctype html>
+<html style="color: inherit">
+<meta charset="utf-8">
+<title>CSSOM: CSSStyleDeclaration.setPropertyValue doesn't queue a mutation record for invalid values</title>
+<link rel="help" href="https://drafts.csswg.org/cssom/#dom-cssstyledeclaration-setproperty">
+<link rel="author" title="Emilio Cobos Álvarez" href="mailto:emilio@crisal.io">
+<script src=/resources/testharness.js></script>
+<script src=/resources/testharnessreport.js></script>
+<script>
+  let test = async_test("CSSStyleDeclaration.setPropertyValue doesn't queue a mutation record when setting invalid values");
+  let m = new MutationObserver(test.unreached_func("shouldn't queue a mutation record"));
+  m.observe(document.documentElement,  { attributes: true });
+
+  document.documentElement.style.width = "-100px";
+  requestAnimationFrame(() => test.done());
+</script>
diff --git a/css/cssom/cssstyledeclaration-setter-attr.html b/css/cssom/cssstyledeclaration-setter-attr.html
new file mode 100644
index 0000000..2083705
--- /dev/null
+++ b/css/cssom/cssstyledeclaration-setter-attr.html
@@ -0,0 +1,18 @@
+<!doctype html>
+<title>CSSOM test: declaration block after setting via CSSOM</title>
+<link rel="help" href="https://drafts.csswg.org/cssom/#dom-cssstyledeclaration-setproperty">
+<script src="/resources/testharness.js"></script>
+<script src="/resources/testharnessreport.js"></script>
+<link rel="author" title="Emilio Cobos Álvarez" href="mailto:emilio@crisal.io">
+<script>
+test(function() {
+  let element = document.createElement("div");
+  element.style.setProperty("doesntexist", "0");
+  assert_false(element.hasAttribute("style"));
+}, "Setting an invalid property via the declaration setter doesn't create a declaration");
+test(function() {
+  let element = document.createElement("div");
+  element.style.setProperty("width", "-100");
+  assert_false(element.hasAttribute("style"));
+}, "Setting an invalid value via the declaration setter doesn't create a declaration");
+</script>