Bug 1496085 [wpt PR 13334] - [css-properties-values-api] Proper behavior for direct CSSStyleValues., a=testonly
authorAnders Hartvoll Ruud <andruud@chromium.org>
Thu, 11 Oct 2018 09:31:35 +0000
changeset 496771 ddb8b080f0b435ea622b4a01bee5cc0c6e12058d
parent 496770 5100c6c46f28bbafc299040ca39708da6041c872
child 496772 a0482419c5d35ee353c0ffb288c30f8ba6ee6423
push id9984
push userffxbld-merge
push dateMon, 15 Oct 2018 21:07:35 +0000
treeherdermozilla-beta@183d27ea8570 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerstestonly
bugs1496085, 13334, 641877, 1257916, 597503
milestone64.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1496085 [wpt PR 13334] - [css-properties-values-api] Proper behavior for direct CSSStyleValues., a=testonly Automatic update from web-platform-tests[css-properties-values-api] Proper behavior for direct CSSStyleValues. In CSS Typed OM, types that are not yet supported by a specialized CSSStyleValue subclass are represented by "direct" CSSStyleValue objects. These objects are only valid for their associated property. For instance, you may not get a (direct) CSSStyleValue object from 'color', and then set it on 'background-color'; the (direct) CSSStyleValue acquired from 'color' is valid for 'color' only. The same should apply for registered custom properties; a direct CSSStyleValue acquired from '--x' is only valid for '--x'. To do this, blink::CSSUnsupportedStyleValue must be aware of the custom property name. This means the AtomicString with the custom property name must be passed around to almost everything. However, if the property at hand is not a custom property, I want to avoid AtomicString-ing the name of the property. Hence there are DCHECKs to make sure this is avoided. Reminder: this CL would be much less ... grotesque and perhaps less error-prone if dynamic CSSProperties (Ribbon) were in place, but because we like pain, we decided to not give that project a very high priority. R=chrishtr@chromium.org Bug: 641877 Change-Id: I99af4745d1d33365759e9fd4acef5082ab213229 Reviewed-on: https://chromium-review.googlesource.com/c/1257916 Reviewed-by: Chris Harrelson <chrishtr@chromium.org> Commit-Queue: Anders Ruud <andruud@chromium.org> Cr-Commit-Position: refs/heads/master@{#597503} -- wpt-commits: 1cefac0f876828632d234eb55f42579365664f3d wpt-pr: 13334
testing/web-platform/tests/css/css-properties-values-api/typedom.tentative.html
--- a/testing/web-platform/tests/css/css-properties-values-api/typedom.tentative.html
+++ b/testing/web-platform/tests/css/css-properties-values-api/typedom.tentative.html
@@ -532,9 +532,66 @@ test(function(){
 test(function(){
     assert_parsed_type(gen_prop('<length>+ | fail', 'fail'), '10px 20px', CSSUnitValue);
 }, 'CSSStyleValue.parse[All] returns list of CSSUnitValues for <length>+');
 
 test(function(){
     assert_parsed_type(gen_prop('<length># | fail', 'fail'), '10px, 20px', CSSUnitValue);
 }, 'CSSStyleValue.parse[All] returns list of CSSUnitValues for <length>#');
 
+// Direct CSSStyleValue objects:
+
+function gen_all_props() {
+    return [
+        gen_prop('*', 'foo'),
+        gen_prop('foo', 'foo'),
+        gen_prop('<angle>', '0deg'),
+        gen_prop('<color>', 'rgb(1, 2, 3)'),
+        gen_prop('<custom-ident>', 'thing'),
+        gen_prop('<image>', 'url(a)'),
+        gen_prop('<integer>', '0'),
+        gen_prop('<length-percentage>', 'calc(10px + 10%)'),
+        gen_prop('<length>', '0px'),
+        gen_prop('<number>', '0.5'),
+        gen_prop('<percentage>', '0%'),
+        gen_prop('<resolution>', '0dpi'),
+        gen_prop('<time>', '0s'),
+        gen_prop('<transform-function>', 'rotateX(0deg)'),
+        gen_prop('<transform-list>', 'rotateX(0deg)'),
+        gen_prop('<url>', 'url(a)')
+    ];
+}
+
+test(function(){
+    let props0 = gen_all_props();
+    let props1 = gen_all_props();
+
+    for (let i = 0; i < props0.length; i++) {
+        let prop0 = props0[i];
+        let prop1 = props1[i];
+
+        // Abuse computedStyleMap to get the initialValue (just to get some
+        // value that will parse for prop0/1's syntax).
+        let initialValue = target.computedStyleMap().get(prop0);
+
+        // We only care about direct CSSStyleValue instances in this test.
+        // Ultimately, in some future version of CSS TypedOM, we may have no
+        // direct CSSStyleValue instances at all, which is fine.
+        if (initialValue.constructor !== CSSStyleValue) {
+            continue;
+        }
+
+        let value = CSSStyleValue.parse(prop0, initialValue.toString());
+
+        // A value parsed for prop0 must be assignable to prop0.
+        target.attributeStyleMap.clear();
+        target.attributeStyleMap.set(prop0, value); // Don't throw.
+
+        // A value parsed for prop0 must not be assignable to prop1, even if
+        // the properties have compatible syntaxes.
+        assert_throws(new TypeError(), () => {
+            target.attributeStyleMap.clear();
+            target.attributeStyleMap.set(prop1, value);
+        });
+    }
+}, 'Direct CSSStyleValue instances are tied to their associated property');
+
 </script>